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 TST_QMLTYPEREGISTRAR_H |
30 | #define TST_QMLTYPEREGISTRAR_H |
31 | |
32 | #include "foreign.h" |
33 | |
34 | #include <QtQml/qqml.h> |
35 | |
36 | class SizeEnums |
37 | { |
38 | Q_GADGET |
39 | QML_NAMED_ELEMENT(SizeEnums) |
40 | QML_UNCREATABLE("Element is not creatable." ) |
41 | |
42 | public: |
43 | enum Unit { Pixel, Centimeter, Inch, Point }; |
44 | Q_ENUM(Unit) |
45 | }; |
46 | |
47 | class SizeValueType : public SizeEnums |
48 | { |
49 | QSize v; |
50 | Q_GADGET |
51 | Q_PROPERTY(int width READ width WRITE setWidth FINAL) |
52 | QML_NAMED_ELEMENT(MySize) |
53 | QML_FOREIGN(SizeGadget) |
54 | |
55 | public: |
56 | Q_INVOKABLE QString sizeToString() const |
57 | { |
58 | return QString::fromLatin1(str: "%1x%2" ).arg(a: v.width()).arg(a: v.height()); |
59 | } |
60 | |
61 | int width() const { return v.width(); } |
62 | void setWidth(int width) { v.setWidth(width); } |
63 | }; |
64 | |
65 | class Local : public Foreign |
66 | { |
67 | Q_OBJECT |
68 | QML_ELEMENT |
69 | public: |
70 | enum Flag { |
71 | Flag1 = 0x1, |
72 | Flag2 = 0x2, |
73 | Flag3 = 0x4, |
74 | Flag4 = 0x8 |
75 | }; |
76 | Q_DECLARE_FLAGS(Flags, Flag) |
77 | Q_FLAG(Flags) |
78 | }; |
79 | |
80 | class tst_qmltyperegistrar : public QObject |
81 | { |
82 | Q_OBJECT |
83 | |
84 | private slots: |
85 | void initTestCase(); |
86 | void qmltypesHasForeign(); |
87 | void qmltypesHasHppClassAndNoext(); |
88 | void qmltypesHasFileNames(); |
89 | void qmltypesHasFlags(); |
90 | void superAndForeignTypes(); |
91 | |
92 | private: |
93 | QByteArray qmltypesData; |
94 | }; |
95 | |
96 | #endif // TST_QMLTYPEREGISTRAR_H |
97 | |