1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWAYLANDQUICKEXTENSION_H
5#define QWAYLANDQUICKEXTENSION_H
6
7#if 0
8#pragma qt_class(QWaylandQuickExtension)
9#endif
10
11#include <QtWaylandCompositor/QWaylandCompositorExtension>
12#include <QtQml/QQmlParserStatus>
13#include <QtQml/QQmlListProperty>
14
15QT_REQUIRE_CONFIG(wayland_compositor_quick);
16
17QT_BEGIN_NAMESPACE
18
19#define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(className) \
20 class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtension : public className, public QQmlParserStatus \
21 { \
22/* qmake ignore Q_OBJECT */ \
23 Q_OBJECT \
24 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \
25 Q_CLASSINFO("DefaultProperty", "data") \
26 Q_INTERFACES(QQmlParserStatus) \
27 public: \
28 QQmlListProperty<QObject> data() \
29 { \
30 return QQmlListProperty<QObject>(this, &m_objects); \
31 } \
32 void classBegin() override {} \
33 void componentComplete() override { if (!isInitialized()) initialize(); } \
34 private: \
35 QList<QObject *> m_objects; \
36 };
37
38#define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CONTAINER_CLASS(className) \
39 class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtensionContainer : public className \
40 { \
41/* qmake ignore Q_OBJECT */ \
42 Q_OBJECT \
43 Q_PROPERTY(QQmlListProperty<QWaylandCompositorExtension> extensions READ extensions) \
44 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \
45 Q_CLASSINFO("DefaultProperty", "data") \
46 public: \
47 QQmlListProperty<QObject> data() \
48 { \
49 return QQmlListProperty<QObject>(this, &m_objects); \
50 } \
51 QQmlListProperty<QWaylandCompositorExtension> extensions() \
52 { \
53 return QQmlListProperty<QWaylandCompositorExtension>(this, this, \
54 &className##QuickExtensionContainer::append_extension, \
55 &className##QuickExtensionContainer::countFunction, \
56 &className##QuickExtensionContainer::atFunction, \
57 &className##QuickExtensionContainer::clearFunction); \
58 } \
59 static int countFunction(QQmlListProperty<QWaylandCompositorExtension> *list) \
60 { \
61 return static_cast<className##QuickExtensionContainer *>(list->data)->extension_vector.size(); \
62 } \
63 static QWaylandCompositorExtension *atFunction(QQmlListProperty<QWaylandCompositorExtension> *list, int index) \
64 { \
65 return static_cast<className##QuickExtensionContainer *>(list->data)->extension_vector.at(index); \
66 } \
67 static void append_extension(QQmlListProperty<QWaylandCompositorExtension> *list, QWaylandCompositorExtension *extension) \
68 { \
69 className##QuickExtensionContainer *quickExtObj = static_cast<className##QuickExtensionContainer *>(list->data); \
70 extension->setExtensionContainer(quickExtObj); \
71 } \
72 static void clearFunction(QQmlListProperty<QWaylandCompositorExtension> *list) \
73 { \
74 static_cast<className##QuickExtensionContainer *>(list->data)->extension_vector.clear(); \
75 } \
76 private: \
77 QList<QObject *> m_objects; \
78 };
79
80#define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_CLASS(className, QmlType) \
81 class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtension : public className, public QQmlParserStatus \
82 { \
83/* qmake ignore Q_OBJECT */ \
84 Q_OBJECT \
85 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \
86 Q_CLASSINFO("DefaultProperty", "data") \
87 Q_INTERFACES(QQmlParserStatus) \
88 QML_NAMED_ELEMENT(QmlType) \
89 QML_ADDED_IN_VERSION(1, 0) \
90 public: \
91 QQmlListProperty<QObject> data() \
92 { \
93 return QQmlListProperty<QObject>(this, &m_objects); \
94 } \
95 void classBegin() override {} \
96 void componentComplete() override { if (!isInitialized()) initialize(); } \
97 private: \
98 QList<QObject *> m_objects; \
99 };
100
101QT_END_NAMESPACE
102
103#endif /*QWAYLANDQUICKEXTENSION_H*/
104

source code of qtwayland/src/compositor/global/qwaylandquickextension.h