summaryrefslogtreecommitdiffstats
path: root/framework/actions
diff options
context:
space:
mode:
Diffstat (limited to 'framework/actions')
-rw-r--r--framework/actions/context.cpp14
-rw-r--r--framework/actions/context.h13
2 files changed, 26 insertions, 1 deletions
diff --git a/framework/actions/context.cpp b/framework/actions/context.cpp
index 205b1606..8f370a0b 100644
--- a/framework/actions/context.cpp
+++ b/framework/actions/context.cpp
@@ -29,10 +29,22 @@ Context::Context(QObject *parent)
29 29
30} 30}
31 31
32void Context::clear()
33{
34 auto meta = metaObject();
35 for (auto i = meta->propertyOffset(); i < meta->propertyCount(); i++) {
36 auto property = meta->property(i);
37 setProperty(property.name(), QVariant());
38 }
39 for (const auto &p : dynamicPropertyNames()) {
40 setProperty(p, QVariant());
41 }
42}
43
32QDebug operator<<(QDebug dbg, const Kube::Context &context) 44QDebug operator<<(QDebug dbg, const Kube::Context &context)
33{ 45{
34 dbg << "Kube::Context {\n"; 46 dbg << "Kube::Context {\n";
35 auto metaObject = context.QObject::metaObject(); 47 auto metaObject = context.metaObject();
36 for (auto i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) { 48 for (auto i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) {
37 auto property = metaObject->property(i); 49 auto property = metaObject->property(i);
38 dbg << property.name() << context.property(property.name()) << "\n"; 50 dbg << property.name() << context.property(property.name()) << "\n";
diff --git a/framework/actions/context.h b/framework/actions/context.h
index 562e110e..42ae3a93 100644
--- a/framework/actions/context.h
+++ b/framework/actions/context.h
@@ -20,6 +20,18 @@
20 20
21#include <QObject> 21#include <QObject>
22 22
23#define KUBE_CONTEXT_PROPERTY(TYPE, NAME, LOWERCASENAME) \
24 public: Q_PROPERTY(TYPE LOWERCASENAME MEMBER m##NAME NOTIFY LOWERCASENAME##Changed) \
25 struct NAME { \
26 static constexpr const char *name = #LOWERCASENAME; \
27 typedef TYPE Type; \
28 }; \
29 void set##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \
30 TYPE get##NAME() const { return m##NAME; } \
31 Q_SIGNALS: void LOWERCASENAME##Changed(); \
32 private: TYPE m##NAME;
33
34
23namespace Kube { 35namespace Kube {
24 36
25class Context : public QObject { 37class Context : public QObject {
@@ -27,6 +39,7 @@ class Context : public QObject {
27public: 39public:
28 Context(QObject *parent = 0); 40 Context(QObject *parent = 0);
29 virtual ~Context(){}; 41 virtual ~Context(){};
42 virtual void clear();
30}; 43};
31 44
32} 45}