summaryrefslogtreecommitdiffstats
path: root/src/compositor/global
diff options
context:
space:
mode:
authorPier Luigi Fiorini <pierluigi.fiorini@liri.io>2016-12-29 12:03:04 +0100
committerPier Luigi Fiorini <pierluigi.fiorini@liri.io>2018-06-23 05:49:29 +0000
commit9ebba7c3a74a42a9c765113c26c986c1497bfac1 (patch)
tree6263fab0436d5026db59101f151a73d8ba6e2244 /src/compositor/global
parent591fadfdd6cb98d3898e9e60d9cb0b4145e436c8 (diff)
Macro for QML items with data property boilerplate
This macro gives items the ability to hold children. Use the new macro on various types to let compositors declare children from QML. Change-Id: I291cc69fc11653bc3d677d148e002330a3245173 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/compositor/global')
-rw-r--r--src/compositor/global/qwaylandquickextension.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/compositor/global/qwaylandquickextension.h b/src/compositor/global/qwaylandquickextension.h
index c721bcb97..a0e07dad3 100644
--- a/src/compositor/global/qwaylandquickextension.h
+++ b/src/compositor/global/qwaylandquickextension.h
@@ -107,6 +107,42 @@ QT_BEGIN_NAMESPACE
QList<QObject *> m_objects; \
};
+#define Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(className) \
+ class Q_WAYLAND_COMPOSITOR_EXPORT className##QuickParent : public className \
+ { \
+/* qmake ignore Q_OBJECT */ \
+ Q_OBJECT \
+ Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \
+ Q_CLASSINFO("DefaultProperty", "data") \
+ public: \
+ QQmlListProperty<QObject> data() \
+ { \
+ return QQmlListProperty<QObject>(this, this, \
+ &className##QuickParent::appendFunction, \
+ &className##QuickParent::countFunction, \
+ &className##QuickParent::atFunction, \
+ &className##QuickParent::clearFunction); \
+ } \
+ static void appendFunction(QQmlListProperty<QObject> *list, QObject *object) \
+ { \
+ static_cast<className##QuickParent *>(list->data)->m_children.append(object); \
+ } \
+ static int countFunction(QQmlListProperty<QObject> *list) \
+ { \
+ return static_cast<className##QuickParent *>(list->data)->m_children.size(); \
+ } \
+ static QObject *atFunction(QQmlListProperty<QObject> *list, int index) \
+ { \
+ return static_cast<className##QuickParent *>(list->data)->m_children.at(index); \
+ } \
+ static void clearFunction(QQmlListProperty<QObject> *list) \
+ { \
+ static_cast<className##QuickParent *>(list->data)->m_children.clear(); \
+ } \
+ private: \
+ QVector<QObject *> m_children; \
+ };
+
QT_END_NAMESPACE
#endif /*QWAYLANDQUICKEXTENSION_H*/