summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--src/compositor/global/qwaylandquickextension.h36
-rw-r--r--src/imports/compositor/qwaylandquickcompositorplugin.cpp24
2 files changed, 52 insertions, 8 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*/
diff --git a/src/imports/compositor/qwaylandquickcompositorplugin.cpp b/src/imports/compositor/qwaylandquickcompositorplugin.cpp
index e877f6927..9f3bf5d43 100644
--- a/src/imports/compositor/qwaylandquickcompositorplugin.cpp
+++ b/src/imports/compositor/qwaylandquickcompositorplugin.cpp
@@ -72,11 +72,19 @@
QT_BEGIN_NAMESPACE
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CONTAINER_CLASS(QWaylandQuickCompositor)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandQuickOutput)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandQuickSurface)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandKeymap)
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandQtWindowManager)
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandIviApplication)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandIviSurface)
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandWlShell)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandWlShellSurface)
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgShellV5)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandXdgSurfaceV5)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandXdgPopupV5)
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgShellV6)
+Q_COMPOSITOR_DECLARE_QUICK_PARENT_CLASS(QWaylandXdgSurfaceV6)
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandTextInputManager)
class QmlUrlResolver
@@ -128,9 +136,9 @@ public:
qmlRegisterType<QWaylandQuickItem>(uri, 1, 0, "WaylandQuickItem");
qmlRegisterType<QWaylandQuickHardwareLayer>(uri, 1, 2, "WaylandHardwareLayer");
qmlRegisterType<QWaylandMouseTracker>(uri, 1, 0, "WaylandMouseTracker");
- qmlRegisterType<QWaylandQuickOutput>(uri, 1, 0, "WaylandOutput");
- qmlRegisterType<QWaylandQuickSurface>(uri, 1, 0, "WaylandSurface");
- qmlRegisterType<QWaylandKeymap>(uri, 1, 0, "WaylandKeymap");
+ qmlRegisterType<QWaylandQuickOutputQuickParent>(uri, 1, 0, "WaylandOutput");
+ qmlRegisterType<QWaylandQuickSurfaceQuickParent>(uri, 1, 0, "WaylandSurface");
+ qmlRegisterType<QWaylandKeymapQuickParent>(uri, 1, 0, "WaylandKeymap");
qmlRegisterUncreatableType<QWaylandCompositorExtension>(uri, 1, 0, "WaylandExtension", QObject::tr("Cannot create instance of WaylandExtension"));
qmlRegisterUncreatableType<QWaylandClient>(uri, 1, 0, "WaylandClient", QObject::tr("Cannot create instance of WaylandClient"));
@@ -148,18 +156,18 @@ public:
//This should probably be somewhere else
qmlRegisterType<QWaylandQtWindowManagerQuickExtension>(uri, 1, 0, "QtWindowManager");
qmlRegisterType<QWaylandIviApplicationQuickExtension>(uri, 1, 0, "IviApplication");
- qmlRegisterType<QWaylandIviSurface>(uri, 1, 0, "IviSurface");
+ qmlRegisterType<QWaylandIviSurfaceQuickParent>(uri, 1, 0, "IviSurface");
qmlRegisterType<QWaylandWlShellQuickExtension>(uri, 1, 0, "WlShell");
- qmlRegisterType<QWaylandWlShellSurface>(uri, 1, 0, "WlShellSurface");
+ qmlRegisterType<QWaylandWlShellSurfaceQuickParent>(uri, 1, 0, "WlShellSurface");
qmlRegisterType<QWaylandQuickShellSurfaceItem>(uri, 1, 0, "ShellSurfaceItem");
qmlRegisterUncreatableType<QWaylandXdgShellV5>(uri, 1, 0, "XdgShellV5Base", QObject::tr("Cannot create instance of XdgShellV5Base"));
qmlRegisterType<QWaylandXdgShellV5QuickExtension>(uri, 1, 0, "XdgShellV5");
- qmlRegisterType<QWaylandXdgSurfaceV5>(uri, 1, 0, "XdgSurfaceV5");
- qmlRegisterType<QWaylandXdgPopupV5>(uri, 1, 0, "XdgPopupV5");
+ qmlRegisterType<QWaylandXdgSurfaceV5QuickParent>(uri, 1, 0, "XdgSurfaceV5");
+ qmlRegisterType<QWaylandXdgPopupV5QuickParent>(uri, 1, 0, "XdgPopupV5");
qmlRegisterType<QWaylandTextInputManagerQuickExtension>(uri, 1, 0, "TextInputManager");
qmlRegisterType<QWaylandXdgShellV6QuickExtension>(uri, 1, 1, "XdgShellV6");
- qmlRegisterType<QWaylandXdgSurfaceV6>(uri, 1, 1, "XdgSurfaceV6");
+ qmlRegisterType<QWaylandXdgSurfaceV6QuickParent>(uri, 1, 1, "XdgSurfaceV6");
qmlRegisterUncreatableType<QWaylandXdgToplevelV6>(uri, 1, 1, "XdgToplevelV6", QObject::tr("Cannot create instance of XdgShellToplevelV6"));
qmlRegisterUncreatableType<QWaylandXdgPopupV6>(uri, 1, 1, "XdgPopupV6", QObject::tr("Cannot create instance of XdgShellPopupV6"));
}