diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-13 16:24:31 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 14:54:14 +0100 |
commit | 630f45719a527f8ee739b03bc62f886badea6df3 (patch) | |
tree | b9d859cbfedb30ad8a9570e3b87a419bf24ba6c7 /framework/actions/action.cpp | |
parent | b1a2e2de201985a00980bead5272977cda4ef637 (diff) | |
download | kube-630f45719a527f8ee739b03bc62f886badea6df3.tar.gz kube-630f45719a527f8ee739b03bc62f886badea6df3.zip |
Revamp of composercontroller to use actions more.
Instead of setting all properties individually we directly assign all
properties to a context that we assign to the actions.
This way actions can automatically update themselves as new data becomes
available, and we avoid the setter/getter boilerplate, at the cost of a
less explicit interface (But that could be improved by allowing to
define the required properties of a context in c++).
By relying on prehandler/posthandler to execute certain actions we
simplify the control flow and enable the future extension with handlers
that i.e. do encryption etc.
Diffstat (limited to 'framework/actions/action.cpp')
-rw-r--r-- | framework/actions/action.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/framework/actions/action.cpp b/framework/actions/action.cpp index f41feb66..1344d112 100644 --- a/framework/actions/action.cpp +++ b/framework/actions/action.cpp | |||
@@ -42,7 +42,11 @@ Action::Action(const QByteArray &actionId, Context &context, QObject *parent) | |||
42 | mContext(&context), | 42 | mContext(&context), |
43 | mActionId(actionId) | 43 | mActionId(actionId) |
44 | { | 44 | { |
45 | setContext(&context); | ||
46 | } | ||
45 | 47 | ||
48 | Action::~Action() | ||
49 | { | ||
46 | } | 50 | } |
47 | 51 | ||
48 | void Action::setContext(Context *context) | 52 | void Action::setContext(Context *context) |
@@ -61,6 +65,16 @@ void Action::setContext(Context *context) | |||
61 | emit readyChanged(); | 65 | emit readyChanged(); |
62 | } | 66 | } |
63 | 67 | ||
68 | bool Action::eventFilter(QObject *obj, QEvent *e) | ||
69 | { | ||
70 | if (obj == mContext) { | ||
71 | if (e->type() == QEvent::DynamicPropertyChange) { | ||
72 | contextChanged(); | ||
73 | } | ||
74 | } | ||
75 | return QObject::eventFilter(obj, e); | ||
76 | } | ||
77 | |||
64 | void Action::contextChanged() | 78 | void Action::contextChanged() |
65 | { | 79 | { |
66 | emit readyChanged(); | 80 | emit readyChanged(); |
@@ -84,7 +98,7 @@ QByteArray Action::actionId() const | |||
84 | 98 | ||
85 | bool Action::ready() const | 99 | bool Action::ready() const |
86 | { | 100 | { |
87 | return ActionBroker::instance().isActionReady(mActionId, mContext); | 101 | return ActionBroker::instance().isActionReady(mActionId, mContext, mPreHandler); |
88 | } | 102 | } |
89 | 103 | ||
90 | void Action::execute() | 104 | void Action::execute() |
@@ -99,11 +113,15 @@ ActionResult Action::executeWithResult() | |||
99 | 113 | ||
100 | void Action::addPreHandler(ActionHandler *handler) | 114 | void Action::addPreHandler(ActionHandler *handler) |
101 | { | 115 | { |
116 | //For cleanup | ||
117 | handler->setParent(this); | ||
102 | mPreHandler << handler; | 118 | mPreHandler << handler; |
103 | } | 119 | } |
104 | 120 | ||
105 | void Action::addPostHandler(ActionHandler *handler) | 121 | void Action::addPostHandler(ActionHandler *handler) |
106 | { | 122 | { |
123 | //For cleanup | ||
124 | handler->setParent(this); | ||
107 | mPostHandler << handler; | 125 | mPostHandler << handler; |
108 | } | 126 | } |
109 | 127 | ||