From 9ebba7c3a74a42a9c765113c26c986c1497bfac1 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Thu, 29 Dec 2016 12:03:04 +0100 Subject: 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 --- src/compositor/global/qwaylandquickextension.h | 36 ++++++++++++++++++++++ .../compositor/qwaylandquickcompositorplugin.cpp | 24 ++++++++++----- 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 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 data READ data DESIGNABLE false) \ + Q_CLASSINFO("DefaultProperty", "data") \ + public: \ + QQmlListProperty data() \ + { \ + return QQmlListProperty(this, this, \ + &className##QuickParent::appendFunction, \ + &className##QuickParent::countFunction, \ + &className##QuickParent::atFunction, \ + &className##QuickParent::clearFunction); \ + } \ + static void appendFunction(QQmlListProperty *list, QObject *object) \ + { \ + static_cast(list->data)->m_children.append(object); \ + } \ + static int countFunction(QQmlListProperty *list) \ + { \ + return static_cast(list->data)->m_children.size(); \ + } \ + static QObject *atFunction(QQmlListProperty *list, int index) \ + { \ + return static_cast(list->data)->m_children.at(index); \ + } \ + static void clearFunction(QQmlListProperty *list) \ + { \ + static_cast(list->data)->m_children.clear(); \ + } \ + private: \ + QVector 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(uri, 1, 0, "WaylandQuickItem"); qmlRegisterType(uri, 1, 2, "WaylandHardwareLayer"); qmlRegisterType(uri, 1, 0, "WaylandMouseTracker"); - qmlRegisterType(uri, 1, 0, "WaylandOutput"); - qmlRegisterType(uri, 1, 0, "WaylandSurface"); - qmlRegisterType(uri, 1, 0, "WaylandKeymap"); + qmlRegisterType(uri, 1, 0, "WaylandOutput"); + qmlRegisterType(uri, 1, 0, "WaylandSurface"); + qmlRegisterType(uri, 1, 0, "WaylandKeymap"); qmlRegisterUncreatableType(uri, 1, 0, "WaylandExtension", QObject::tr("Cannot create instance of WaylandExtension")); qmlRegisterUncreatableType(uri, 1, 0, "WaylandClient", QObject::tr("Cannot create instance of WaylandClient")); @@ -148,18 +156,18 @@ public: //This should probably be somewhere else qmlRegisterType(uri, 1, 0, "QtWindowManager"); qmlRegisterType(uri, 1, 0, "IviApplication"); - qmlRegisterType(uri, 1, 0, "IviSurface"); + qmlRegisterType(uri, 1, 0, "IviSurface"); qmlRegisterType(uri, 1, 0, "WlShell"); - qmlRegisterType(uri, 1, 0, "WlShellSurface"); + qmlRegisterType(uri, 1, 0, "WlShellSurface"); qmlRegisterType(uri, 1, 0, "ShellSurfaceItem"); qmlRegisterUncreatableType(uri, 1, 0, "XdgShellV5Base", QObject::tr("Cannot create instance of XdgShellV5Base")); qmlRegisterType(uri, 1, 0, "XdgShellV5"); - qmlRegisterType(uri, 1, 0, "XdgSurfaceV5"); - qmlRegisterType(uri, 1, 0, "XdgPopupV5"); + qmlRegisterType(uri, 1, 0, "XdgSurfaceV5"); + qmlRegisterType(uri, 1, 0, "XdgPopupV5"); qmlRegisterType(uri, 1, 0, "TextInputManager"); qmlRegisterType(uri, 1, 1, "XdgShellV6"); - qmlRegisterType(uri, 1, 1, "XdgSurfaceV6"); + qmlRegisterType(uri, 1, 1, "XdgSurfaceV6"); qmlRegisterUncreatableType(uri, 1, 1, "XdgToplevelV6", QObject::tr("Cannot create instance of XdgShellToplevelV6")); qmlRegisterUncreatableType(uri, 1, 1, "XdgPopupV6", QObject::tr("Cannot create instance of XdgShellPopupV6")); } -- cgit v1.2.3