| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2020 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef INTERFACES_H |
| 30 | #define INTERFACES_H |
| 31 | |
| 32 | #include <QtQml/qqml.h> |
| 33 | |
| 34 | struct Interface { |
| 35 | }; |
| 36 | |
| 37 | QT_BEGIN_NAMESPACE |
| 38 | #define MyInterface_iid "io.qt.bugreports.Interface" |
| 39 | Q_DECLARE_INTERFACE(Interface, MyInterface_iid); |
| 40 | QT_END_NAMESPACE |
| 41 | |
| 42 | class A : public QObject, Interface { |
| 43 | Q_OBJECT |
| 44 | Q_INTERFACES(Interface) |
| 45 | }; |
| 46 | |
| 47 | class B : public QObject, Interface { |
| 48 | Q_OBJECT |
| 49 | Q_INTERFACES(Interface) |
| 50 | }; |
| 51 | |
| 52 | class C : public QObject { |
| 53 | Q_OBJECT |
| 54 | }; |
| 55 | |
| 56 | struct Interface2 |
| 57 | { |
| 58 | Q_GADGET |
| 59 | QML_INTERFACE |
| 60 | }; |
| 61 | |
| 62 | QT_BEGIN_NAMESPACE |
| 63 | #define MyInterface2_iid "io.qt.bugreports.Interface2" |
| 64 | Q_DECLARE_INTERFACE(Interface2, MyInterface2_iid); |
| 65 | QT_END_NAMESPACE |
| 66 | |
| 67 | class A2 : public QObject, Interface2 { |
| 68 | Q_OBJECT |
| 69 | QML_ELEMENT |
| 70 | Q_INTERFACES(Interface2) |
| 71 | }; |
| 72 | |
| 73 | class B2 : public QObject, Interface2 { |
| 74 | Q_OBJECT |
| 75 | QML_ELEMENT |
| 76 | Q_INTERFACES(Interface2) |
| 77 | }; |
| 78 | |
| 79 | class C2 : public QObject { |
| 80 | Q_OBJECT |
| 81 | QML_ELEMENT |
| 82 | }; |
| 83 | |
| 84 | class InterfaceConsumer : public QObject { |
| 85 | Q_OBJECT |
| 86 | Q_PROPERTY(Interface *i READ interface WRITE setInterface NOTIFY interfaceChanged) |
| 87 | Q_PROPERTY(int testValue READ testValue NOTIFY testValueChanged) |
| 88 | |
| 89 | public: |
| 90 | |
| 91 | Interface* interface() const |
| 92 | { |
| 93 | return m_interface; |
| 94 | } |
| 95 | void setInterface(Interface* interface) |
| 96 | { |
| 97 | QObject* object = reinterpret_cast<QObject*>(interface); |
| 98 | m_testValue = object->property(name: "i").toInt(); |
| 99 | emit testValueChanged(); |
| 100 | if (m_interface == interface) |
| 101 | return; |
| 102 | |
| 103 | m_interface = interface; |
| 104 | emit interfaceChanged(); |
| 105 | } |
| 106 | |
| 107 | int testValue() { |
| 108 | return m_testValue; |
| 109 | } |
| 110 | |
| 111 | signals: |
| 112 | void interfaceChanged(); |
| 113 | void testValueChanged(); |
| 114 | |
| 115 | private: |
| 116 | Interface* m_interface = nullptr; |
| 117 | int m_testValue = 0; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | class InterfaceConsumer2 : public QObject |
| 122 | { |
| 123 | Q_OBJECT |
| 124 | |
| 125 | Q_PROPERTY(Interface2 *i READ interface WRITE setInterface NOTIFY interfaceChanged) |
| 126 | Q_PROPERTY(int testValue READ testValue NOTIFY testValueChanged) |
| 127 | |
| 128 | QML_ELEMENT |
| 129 | |
| 130 | public: |
| 131 | |
| 132 | Interface2* interface() const |
| 133 | { |
| 134 | return m_interface; |
| 135 | } |
| 136 | void setInterface(Interface2* interface2) |
| 137 | { |
| 138 | QObject* object = reinterpret_cast<QObject*>(interface2); |
| 139 | m_testValue = object->property(name: "i").toInt(); |
| 140 | emit testValueChanged(); |
| 141 | if (m_interface == interface2) |
| 142 | return; |
| 143 | |
| 144 | m_interface = interface2; |
| 145 | emit interfaceChanged(); |
| 146 | } |
| 147 | |
| 148 | int testValue() { |
| 149 | return m_testValue; |
| 150 | } |
| 151 | |
| 152 | signals: |
| 153 | void interfaceChanged(); |
| 154 | void testValueChanged(); |
| 155 | |
| 156 | private: |
| 157 | Interface2 *m_interface = nullptr; |
| 158 | int m_testValue = 0; |
| 159 | }; |
| 160 | |
| 161 | #endif // INTERFACES_H |
| 162 |
