From 630f45719a527f8ee739b03bc62f886badea6df3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 13 Dec 2016 16:24:31 +0100 Subject: 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. --- framework/actions/action.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'framework/actions/action.cpp') 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) mContext(&context), mActionId(actionId) { + setContext(&context); +} +Action::~Action() +{ } void Action::setContext(Context *context) @@ -61,6 +65,16 @@ void Action::setContext(Context *context) emit readyChanged(); } +bool Action::eventFilter(QObject *obj, QEvent *e) +{ + if (obj == mContext) { + if (e->type() == QEvent::DynamicPropertyChange) { + contextChanged(); + } + } + return QObject::eventFilter(obj, e); +} + void Action::contextChanged() { emit readyChanged(); @@ -84,7 +98,7 @@ QByteArray Action::actionId() const bool Action::ready() const { - return ActionBroker::instance().isActionReady(mActionId, mContext); + return ActionBroker::instance().isActionReady(mActionId, mContext, mPreHandler); } void Action::execute() @@ -99,11 +113,15 @@ ActionResult Action::executeWithResult() void Action::addPreHandler(ActionHandler *handler) { + //For cleanup + handler->setParent(this); mPreHandler << handler; } void Action::addPostHandler(ActionHandler *handler) { + //For cleanup + handler->setParent(this); mPostHandler << handler; } -- cgit v1.2.3