diff options
Diffstat (limited to 'framework/actions')
-rw-r--r-- | framework/actions/actionhandler.cpp | 20 | ||||
-rw-r--r-- | framework/actions/actionhandler.h | 17 |
2 files changed, 37 insertions, 0 deletions
diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp index 748c2303..d4b01734 100644 --- a/framework/actions/actionhandler.cpp +++ b/framework/actions/actionhandler.cpp | |||
@@ -68,3 +68,23 @@ QByteArray ActionHandler::actionId() const | |||
68 | { | 68 | { |
69 | return mActionId; | 69 | return mActionId; |
70 | } | 70 | } |
71 | |||
72 | |||
73 | |||
74 | ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const Handler &handler) | ||
75 | : ActionHandler(nullptr), | ||
76 | isReadyFunction(isReady), | ||
77 | handlerFunction(handler) | ||
78 | { | ||
79 | setActionId(actionId); | ||
80 | } | ||
81 | |||
82 | bool ActionHandlerHelper::isActionReady(Context *context) | ||
83 | { | ||
84 | return isReadyFunction(context); | ||
85 | } | ||
86 | |||
87 | void ActionHandlerHelper::execute(Context *context) | ||
88 | { | ||
89 | handlerFunction(context); | ||
90 | } | ||
diff --git a/framework/actions/actionhandler.h b/framework/actions/actionhandler.h index cfcfddd7..1820bfd4 100644 --- a/framework/actions/actionhandler.h +++ b/framework/actions/actionhandler.h | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <QObject> | 21 | #include <QObject> |
22 | #include <QMultiMap> | 22 | #include <QMultiMap> |
23 | #include <functional> | ||
23 | 24 | ||
24 | namespace Kube { | 25 | namespace Kube { |
25 | class Context; | 26 | class Context; |
@@ -45,4 +46,20 @@ private: | |||
45 | QByteArray mActionId; | 46 | QByteArray mActionId; |
46 | }; | 47 | }; |
47 | 48 | ||
49 | class ActionHandlerHelper : public ActionHandler | ||
50 | { | ||
51 | Q_OBJECT | ||
52 | public: | ||
53 | typedef std::function<bool(Context*)> IsReadyFunction; | ||
54 | typedef std::function<void(Context*)> Handler; | ||
55 | |||
56 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const Handler &); | ||
57 | |||
58 | bool isActionReady(Context *context) Q_DECL_OVERRIDE; | ||
59 | void execute(Context *context) Q_DECL_OVERRIDE; | ||
60 | private: | ||
61 | const std::function<bool(Context*)> isReadyFunction; | ||
62 | const std::function<void(Context*)> handlerFunction; | ||
63 | }; | ||
64 | |||
48 | } | 65 | } |