Test unregistered local enums in QML methods and signal handlers.
[profile/ivi/qtdeclarative.git] / tests / auto / qml / qqmllanguage / testtypes.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef TESTTYPES_H
42 #define TESTTYPES_H
43
44 #include <QtCore/qobject.h>
45 #include <QtCore/qrect.h>
46 #include <QtCore/qdatetime.h>
47 #include <QtGui/qmatrix.h>
48 #include <QtGui/qcolor.h>
49 #include <QtGui/qvector3d.h>
50 #include <QtGui/qvector4d.h>
51 #include <QtQml/qqml.h>
52 #include <QtQml/qqmlcomponent.h>
53 #include <QtQml/qqmlparserstatus.h>
54 #include <QtQml/qqmlpropertyvaluesource.h>
55 #include <QtQml/qqmlscriptstring.h>
56 #include <QtQml/qqmlproperty.h>
57
58 #include <private/qqmlcustomparser_p.h>
59
60 QVariant myCustomVariantTypeConverter(const QString &data);
61
62 class MyInterface 
63 {
64 public:
65     MyInterface() : id(913) {}
66     int id;
67 };
68
69 QT_BEGIN_NAMESPACE
70 #define MyInterface_iid "org.qt-project.Qt.Test.MyInterface"
71 Q_DECLARE_INTERFACE(MyInterface, MyInterface_iid);
72 QT_END_NAMESPACE
73 QML_DECLARE_INTERFACE(MyInterface);
74
75 struct MyCustomVariantType
76 {
77     MyCustomVariantType() : a(0) {}
78     int a;
79 };
80 Q_DECLARE_METATYPE(MyCustomVariantType);
81
82 class MyAttachedObject : public QObject
83 {
84     Q_OBJECT
85     Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
86     Q_PROPERTY(int value2 READ value2 WRITE setValue2)
87 public:
88     MyAttachedObject(QObject *parent) : QObject(parent), m_value(0), m_value2(0) {}
89
90     int value() const { return m_value; }
91     void setValue(int v) { if (m_value != v) { m_value = v; emit valueChanged(); } }
92
93     int value2() const { return m_value2; }
94     void setValue2(int v) { m_value2 = v; }
95
96 signals:
97     void valueChanged();
98
99 private:
100     int m_value;
101     int m_value2;
102 };
103
104 class MyQmlObject : public QObject, public MyInterface
105 {
106     Q_OBJECT
107     Q_PROPERTY(int value READ value WRITE setValue FINAL)
108     Q_PROPERTY(QString readOnlyString READ readOnlyString)
109     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
110     Q_PROPERTY(QRect rect READ rect WRITE setRect)
111     Q_PROPERTY(QMatrix matrix READ matrix WRITE setMatrix)  //assumed to be unsupported by QML
112     Q_PROPERTY(MyInterface *interfaceProperty READ interface WRITE setInterface)
113     Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal)
114     Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType)
115     Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject)
116     Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal)
117     Q_PROPERTY(int nonScriptable READ nonScriptable WRITE setNonScriptable SCRIPTABLE false)
118
119     Q_INTERFACES(MyInterface)
120 public:
121     MyQmlObject() : m_value(-1), m_interface(0), m_qmlobject(0) { qRegisterMetaType<MyCustomVariantType>("MyCustomVariantType"); }
122
123     int value() const { return m_value; }
124     void setValue(int v) { m_value = v; }
125
126     QString readOnlyString() const { return QLatin1String(""); }
127
128     bool enabled() const { return false; }
129     void setEnabled(bool) {}
130
131     QRect rect() const { return QRect(); }
132     void setRect(const QRect&) {}
133
134     QMatrix matrix() const { return QMatrix(); }
135     void setMatrix(const QMatrix&) {}
136
137     MyInterface *interface() const { return m_interface; }
138     void setInterface(MyInterface *iface) { m_interface = iface; }
139
140     static MyAttachedObject *qmlAttachedProperties(QObject *other) {
141         return new MyAttachedObject(other);
142     }
143     Q_CLASSINFO("DefaultMethod", "basicSlot()")
144
145     int onLiteralSignal() const { return m_value; }
146     void setOnLiteralSignal(int v) { m_value = v; }
147
148     MyQmlObject *qmlobject() const { return m_qmlobject; }
149     void setQmlobject(MyQmlObject *o) { m_qmlobject = o; }
150
151     MyCustomVariantType customType() const { return m_custom; }
152     void setCustomType(const MyCustomVariantType &v)  { m_custom = v; }
153
154     int propertyWithNotify() const { return m_propertyWithNotify; }
155     void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); }
156
157     int nonScriptable() const { return 0; }
158     void setNonScriptable(int) {}
159 public slots:
160     void basicSlot() { qWarning("MyQmlObject::basicSlot"); }
161     void basicSlotWithArgs(int v) { qWarning("MyQmlObject::basicSlotWithArgs(%d)", v); }
162
163 signals:
164     void basicSignal();
165     void basicParameterizedSignal(int parameter);
166     void oddlyNamedNotifySignal();
167
168 private:
169     friend class tst_qqmllanguage;
170     int m_value;
171     MyInterface *m_interface;
172     MyQmlObject *m_qmlobject;
173     MyCustomVariantType m_custom;
174     int m_propertyWithNotify;
175 };
176 QML_DECLARE_TYPE(MyQmlObject)
177 QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
178
179 class MyGroupedObject : public QObject
180 {
181     Q_OBJECT
182     Q_PROPERTY(QQmlScriptString script READ script WRITE setScript)
183     Q_PROPERTY(int value READ value WRITE setValue)
184 public:
185     QQmlScriptString script() const { return m_script; }
186     void setScript(const QQmlScriptString &s) { m_script = s; }
187
188     int value() const { return m_value; }
189     void setValue(int v) { m_value = v; }
190
191 private:
192     int m_value;
193     QQmlScriptString m_script;
194 };
195
196
197 class MyTypeObject : public QObject
198 {
199     Q_OBJECT
200     Q_ENUMS(MyEnum)
201     Q_FLAGS(MyFlags)
202
203     Q_PROPERTY(QString id READ id WRITE setId)
204     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
205     Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty)
206     Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
207     Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
208     Q_PROPERTY(MyEnum readOnlyEnumProperty READ readOnlyEnumProperty)
209     Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
210     Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
211     Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
212     Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty)
213     Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
214     Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty)
215     Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty)
216     Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
217     Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
218     Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
219     Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
220     Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
221     Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
222     Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty)
223     Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
224     Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2)
225     Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty)
226     Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
227     Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
228     Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
229     Q_PROPERTY(QVector4D vector4Property READ vector4Property WRITE setVector4Property)
230     Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
231
232     Q_PROPERTY(QQmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
233     Q_PROPERTY(MyGroupedObject *grouped READ grouped CONSTANT)
234     Q_PROPERTY(MyGroupedObject *nullGrouped READ nullGrouped CONSTANT)
235
236 public:
237     MyTypeObject()
238         : objectPropertyValue(0), componentPropertyValue(0) {}
239
240     QString idValue;
241     QString id() const {
242         return idValue;
243     }
244     void setId(const QString &v) {
245         idValue = v;
246     }
247
248     QObject *objectPropertyValue;
249     QObject *objectProperty() const {
250         return objectPropertyValue;
251     }
252     void setObjectProperty(QObject *v) {
253         objectPropertyValue = v;
254     }
255
256     QQmlComponent *componentPropertyValue;
257     QQmlComponent *componentProperty() const {
258         return componentPropertyValue;
259     }
260     void setComponentProperty(QQmlComponent *v) {
261         componentPropertyValue = v;
262     }
263
264     enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
265     Q_DECLARE_FLAGS(MyFlags, MyFlag)
266     MyFlags flagPropertyValue;
267     MyFlags flagProperty() const {
268         return flagPropertyValue;
269     }
270     void setFlagProperty(MyFlags v) {
271         flagPropertyValue = v;
272     }
273
274     enum MyEnum { EnumVal1, EnumVal2 };
275     MyEnum enumPropertyValue;
276     MyEnum enumProperty() const {
277         return enumPropertyValue;
278     }
279     void setEnumProperty(MyEnum v) {
280         enumPropertyValue = v;
281     }
282
283     MyEnum readOnlyEnumProperty() const {
284         return EnumVal1;
285     }
286
287     QString stringPropertyValue;
288     QString stringProperty() const {
289        return stringPropertyValue;
290     }
291     void setStringProperty(const QString &v) {
292         stringPropertyValue = v;
293     }
294
295     uint uintPropertyValue;
296     uint uintProperty() const {
297        return uintPropertyValue;
298     }
299     void setUintProperty(const uint &v) {
300         uintPropertyValue = v;
301     }
302
303     int intPropertyValue;
304     int intProperty() const {
305        return intPropertyValue;
306     }
307     void setIntProperty(const int &v) {
308         intPropertyValue = v;
309     }
310
311     qreal realPropertyValue;
312     qreal realProperty() const {
313        return realPropertyValue;
314     }
315     void setRealProperty(const qreal &v) {
316         realPropertyValue = v;
317     }
318
319     double doublePropertyValue;
320     double doubleProperty() const {
321        return doublePropertyValue;
322     }
323     void setDoubleProperty(const double &v) {
324         doublePropertyValue = v;
325     }
326
327     float floatPropertyValue;
328     float floatProperty() const {
329        return floatPropertyValue;
330     }
331     void setFloatProperty(const float &v) {
332         floatPropertyValue = v;
333     }
334
335     QColor colorPropertyValue;
336     QColor colorProperty() const {
337        return colorPropertyValue;
338     }
339     void setColorProperty(const QColor &v) {
340         colorPropertyValue = v;
341     }
342
343     QDate datePropertyValue;
344     QDate dateProperty() const {
345        return datePropertyValue;
346     }
347     void setDateProperty(const QDate &v) {
348         datePropertyValue = v;
349     }
350
351     QTime timePropertyValue;
352     QTime timeProperty() const {
353        return timePropertyValue;
354     }
355     void setTimeProperty(const QTime &v) {
356         timePropertyValue = v;
357     }
358
359     QDateTime dateTimePropertyValue;
360     QDateTime dateTimeProperty() const {
361        return dateTimePropertyValue;
362     }
363     void setDateTimeProperty(const QDateTime &v) {
364         dateTimePropertyValue = v;
365     }
366
367     QPoint pointPropertyValue;
368     QPoint pointProperty() const {
369        return pointPropertyValue;
370     }
371     void setPointProperty(const QPoint &v) {
372         pointPropertyValue = v;
373     }
374
375     QPointF pointFPropertyValue;
376     QPointF pointFProperty() const {
377        return pointFPropertyValue;
378     }
379     void setPointFProperty(const QPointF &v) {
380         pointFPropertyValue = v;
381     }
382
383     QSize sizePropertyValue;
384     QSize sizeProperty() const {
385        return sizePropertyValue;
386     }
387     void setSizeProperty(const QSize &v) {
388         sizePropertyValue = v;
389     }
390
391     QSizeF sizeFPropertyValue;
392     QSizeF sizeFProperty() const {
393        return sizeFPropertyValue;
394     }
395     void setSizeFProperty(const QSizeF &v) {
396         sizeFPropertyValue = v;
397     }
398
399     QRect rectPropertyValue;
400     QRect rectProperty() const {
401        return rectPropertyValue;
402     }
403     void setRectProperty(const QRect &v) {
404         rectPropertyValue = v;
405         emit rectPropertyChanged();
406     }
407
408     QRect rectPropertyValue2;
409     QRect rectProperty2() const {
410        return rectPropertyValue2;
411     }
412     void setRectProperty2(const QRect &v) {
413         rectPropertyValue2 = v;
414     }
415
416     QRectF rectFPropertyValue;
417     QRectF rectFProperty() const {
418        return rectFPropertyValue;
419     }
420     void setRectFProperty(const QRectF &v) {
421         rectFPropertyValue = v;
422     }
423
424     bool boolPropertyValue;
425     bool boolProperty() const {
426        return boolPropertyValue;
427     }
428     void setBoolProperty(const bool &v) {
429         boolPropertyValue = v;
430     }
431
432     QVariant variantPropertyValue;
433     QVariant variantProperty() const {
434        return variantPropertyValue;
435     }
436     void setVariantProperty(const QVariant &v) {
437         variantPropertyValue = v;
438     }
439
440     QVector3D vectorPropertyValue;
441     QVector3D vectorProperty() const {
442         return vectorPropertyValue;
443     }
444     void setVectorProperty(const QVector3D &v) {
445         vectorPropertyValue = v;
446     }
447
448     QVector4D vector4PropertyValue;
449     QVector4D vector4Property() const {
450         return vector4PropertyValue;
451     }
452     void setVector4Property(const QVector4D &v) {
453         vector4PropertyValue = v;
454     }
455
456     QUrl urlPropertyValue;
457     QUrl urlProperty() const {
458         return urlPropertyValue;
459     }
460     void setUrlProperty(const QUrl &v) {
461         urlPropertyValue = v;
462     }
463
464     QQmlScriptString scriptPropertyValue;
465     QQmlScriptString scriptProperty() const {
466         return scriptPropertyValue;
467     }
468     void setScriptProperty(const QQmlScriptString &v) {
469         scriptPropertyValue = v;
470     }
471
472     MyGroupedObject groupedValue;
473     MyGroupedObject *grouped() { return &groupedValue; }
474
475     MyGroupedObject *nullGrouped() { return 0; }
476
477     void doAction() { emit action(); }
478 signals:
479     void action();
480     void rectPropertyChanged();
481 };
482 Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
483
484
485 class MyContainer : public QObject
486 {
487     Q_OBJECT
488     Q_PROPERTY(QQmlListProperty<QObject> children READ children)
489     Q_PROPERTY(QQmlListProperty<MyContainer> containerChildren READ containerChildren)
490     Q_PROPERTY(QQmlListProperty<MyInterface> qlistInterfaces READ qlistInterfaces)
491     Q_CLASSINFO("DefaultProperty", "children")
492 public:
493     MyContainer() {}
494
495     QQmlListProperty<QObject> children() { return QQmlListProperty<QObject>(this, m_children); }
496     QQmlListProperty<MyContainer> containerChildren() { return QQmlListProperty<MyContainer>(this, m_containerChildren); }
497     QList<QObject *> *getChildren() { return &m_children; }
498     QQmlListProperty<MyInterface> qlistInterfaces() { return QQmlListProperty<MyInterface>(this, m_interfaces); }
499     QList<MyInterface *> *getQListInterfaces() { return &m_interfaces; }
500
501     QList<MyContainer*> m_containerChildren;
502     QList<QObject*> m_children;
503     QList<MyInterface *> m_interfaces;
504 };
505
506
507 class MyPropertyValueSource : public QObject, public QQmlPropertyValueSource
508 {
509     Q_OBJECT
510     Q_INTERFACES(QQmlPropertyValueSource)
511 public:
512     MyPropertyValueSource()
513         : QQmlPropertyValueSource() {}
514
515     QQmlProperty prop;
516     virtual void setTarget(const QQmlProperty &p)
517     {
518         prop = p;
519     }
520 };
521
522 class UnavailableType : public QObject
523 {
524     Q_OBJECT
525 public:
526     UnavailableType() {}
527 };
528
529 class MyDotPropertyObject : public QObject
530 {
531     Q_OBJECT
532     Q_PROPERTY(MyQmlObject *obj READ obj)
533     Q_PROPERTY(MyQmlObject *readWriteObj READ readWriteObj WRITE setReadWriteObj)
534 public:
535     MyDotPropertyObject() : m_rwobj(0), m_ownRWObj(false) {}
536     ~MyDotPropertyObject()
537     {
538         if (m_ownRWObj)
539             delete m_rwobj;
540     }
541
542     MyQmlObject *obj() { return 0; }
543
544     MyQmlObject *readWriteObj()
545     {
546         if (!m_rwobj) {
547             m_rwobj = new MyQmlObject;
548             m_ownRWObj = true;
549         }
550         return m_rwobj;
551     }
552
553     void setReadWriteObj(MyQmlObject *obj)
554     {
555         if (m_ownRWObj) {
556             delete m_rwobj;
557             m_ownRWObj = false;
558         }
559
560         m_rwobj = obj;
561     }
562
563 private:
564     MyQmlObject *m_rwobj;
565     bool m_ownRWObj;
566 };
567
568
569 namespace MyNamespace {
570     class MyNamespacedType : public QObject
571     {
572         Q_OBJECT
573     };
574
575     class MySecondNamespacedType : public QObject
576     {
577         Q_OBJECT
578         Q_PROPERTY(QQmlListProperty<MyNamespace::MyNamespacedType> list READ list)
579     public:
580         QQmlListProperty<MyNamespacedType> list() { return QQmlListProperty<MyNamespacedType>(this, m_list); }
581
582     private:
583         QList<MyNamespacedType *> m_list;
584     };
585 }
586
587 class MyCustomParserType : public QObject
588 {
589     Q_OBJECT
590 };
591
592 class MyCustomParserTypeParser : public QQmlCustomParser
593 {
594 public:
595     QByteArray compile(const QList<QQmlCustomParserProperty> &) { return QByteArray(); }
596     void setCustomData(QObject *, const QByteArray &) {}
597 };
598
599 class MyParserStatus : public QObject, public QQmlParserStatus
600 {
601     Q_INTERFACES(QQmlParserStatus)
602     Q_OBJECT
603 public:
604     MyParserStatus() : m_cbc(0), m_ccc(0) {}
605
606     int classBeginCount() const { return m_cbc; }
607     int componentCompleteCount() const { return m_ccc; }
608
609     virtual void classBegin() { m_cbc++; }
610     virtual void componentComplete() { m_ccc++; }
611 private:
612     int m_cbc;
613     int m_ccc;
614 };
615
616 class MyRevisionedBaseClassRegistered : public QObject
617 {
618     Q_OBJECT
619     Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
620     Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
621
622 public:
623     MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
624
625     qreal propA() const { return m_pa; }
626     void setPropA(qreal p) {
627         if (p != m_pa) {
628             m_pa = p;
629             emit propAChanged();
630         }
631     }
632     qreal propB() const { return m_pb; }
633     void setPropB(qreal p) {
634         if (p != m_pb) {
635             m_pb = p;
636             emit propBChanged();
637         }
638     }
639
640     Q_INVOKABLE void methodA() { }
641     Q_INVOKABLE Q_REVISION(1) void methodB() { }
642
643 signals:
644     void propAChanged();
645     void propBChanged();
646
647     void signalA();
648     Q_REVISION(1) void signalB();
649
650 protected:
651     qreal m_pa;
652     qreal m_pb;
653 };
654
655 class MyRevisionedIllegalOverload : public MyRevisionedBaseClassRegistered
656 {
657     Q_OBJECT
658     Q_PROPERTY(qreal propA READ propA WRITE setPropA REVISION 1);
659 };
660
661 class MyRevisionedLegalOverload : public MyRevisionedBaseClassRegistered
662 {
663     Q_OBJECT
664     Q_PROPERTY(qreal propB READ propB WRITE setPropB REVISION 1);
665 };
666
667 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
668 {
669     Q_OBJECT
670     Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
671     Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
672
673 public:
674     MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
675
676     qreal propC() const { return m_pc; }
677     void setPropC(qreal p) {
678         if (p != m_pc) {
679             m_pc = p;
680             emit propCChanged();
681         }
682     }
683     qreal propD() const { return m_pd; }
684     void setPropD(qreal p) {
685         if (p != m_pd) {
686             m_pd = p;
687             emit propDChanged();
688         }
689     }
690
691     Q_INVOKABLE void methodC() { }
692     Q_INVOKABLE Q_REVISION(1) void methodD() { }
693
694 signals:
695     void propCChanged();
696     void propDChanged();
697
698     void signalC();
699     Q_REVISION(1) void signalD();
700
701 protected:
702     qreal m_pc;
703     qreal m_pd;
704 };
705
706 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
707 {
708     Q_OBJECT
709     Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
710     Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
711
712 public:
713     MyRevisionedClass() : m_p1(1), m_p2(2) {}
714
715     qreal prop1() const { return m_p1; }
716     void setProp1(qreal p) {
717         if (p != m_p1) {
718             m_p1 = p;
719             emit prop1Changed();
720         }
721     }
722     qreal prop2() const { return m_p2; }
723     void setProp2(qreal p) {
724         if (p != m_p2) {
725             m_p2 = p;
726             emit prop2Changed();
727         }
728     }
729
730     Q_INVOKABLE void method1() { }
731     Q_INVOKABLE Q_REVISION(1) void method2() { }
732
733 signals:
734     void prop1Changed();
735     void prop2Changed();
736
737     void signal1();
738     Q_REVISION(1) void signal2();
739
740 protected:
741     qreal m_p1;
742     qreal m_p2;
743 };
744
745 class MyRevisionedSubclass : public MyRevisionedClass
746 {
747     Q_OBJECT
748     Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
749     Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
750
751 public:
752     MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
753
754     qreal prop3() const { return m_p3; }
755     void setProp3(qreal p) {
756         if (p != m_p3) {
757             m_p3 = p;
758             emit prop3Changed();
759         }
760     }
761     qreal prop4() const { return m_p4; }
762     void setProp4(qreal p) {
763         if (p != m_p4) {
764             m_p4 = p;
765             emit prop4Changed();
766         }
767     }
768
769     Q_INVOKABLE void method3() { }
770     Q_INVOKABLE Q_REVISION(1) void method4() { }
771
772 signals:
773     void prop3Changed();
774     void prop4Changed();
775
776     void signal3();
777     Q_REVISION(1) void signal4();
778
779 protected:
780     qreal m_p3;
781     qreal m_p4;
782 };
783
784 class MySubclass : public MyRevisionedClass
785 {
786     Q_OBJECT
787     Q_PROPERTY(qreal prop5 READ prop5 WRITE setProp5 NOTIFY prop5Changed)
788
789 public:
790     MySubclass() : m_p5(5) {}
791
792     qreal prop5() const { return m_p5; }
793     void setProp5(qreal p) {
794         if (p != m_p5) {
795             m_p5 = p;
796             emit prop5Changed();
797         }
798     }
799
800     Q_INVOKABLE void method5() { }
801
802 signals:
803     void prop5Changed();
804
805 protected:
806     qreal m_p5;
807 };
808
809 class MyVersion2Class : public QObject
810 {
811     Q_OBJECT
812 };
813
814 class MyEnum1Class : public QObject
815 {
816     Q_OBJECT
817     Q_ENUMS(EnumA)
818
819 public:
820     MyEnum1Class() : value(A_Invalid) {}
821
822     enum EnumA
823     {
824         A_Invalid = -1,
825
826         A_11 = 11,
827         A_13 = 13
828     };
829
830     Q_INVOKABLE void setValue(EnumA v) { value = v; }
831
832     EnumA getValue() { return value; }
833
834 private:
835     EnumA value;
836 };
837
838 class MyEnum2Class : public QObject
839 {
840     Q_OBJECT
841     Q_ENUMS(EnumB)
842     Q_ENUMS(EnumE)
843
844 public:
845     MyEnum2Class() : valueA(MyEnum1Class::A_Invalid), valueB(B_Invalid), valueC(Qt::PlainText),
846                      valueD(Qt::ElideLeft), valueE(E_Invalid), valueE2(E_Invalid) {}
847
848     enum EnumB
849     {
850         B_Invalid = -1,
851
852         B_29 = 29,
853         B_31 = 31,
854         B_37 = 37
855     };
856
857     enum EnumE
858     {
859         E_Invalid = -1,
860
861         E_14 = 14,
862         E_76 = 76
863     };
864
865     MyEnum1Class::EnumA getValueA() { return valueA; }
866     EnumB getValueB() { return valueB; }
867     Qt::TextFormat getValueC() { return valueC; }
868     Qt::TextElideMode getValueD() { return valueD; }
869     EnumE getValueE() { return valueE; }
870     EnumE getValueE2() { return valueE2; }
871
872     Q_INVOKABLE void setValueA(MyEnum1Class::EnumA v) { valueA = v; emit valueAChanged(v); }
873     Q_INVOKABLE void setValueB(EnumB v) { valueB = v; emit valueBChanged(v); }
874     Q_INVOKABLE void setValueC(Qt::TextFormat v) { valueC = v; emit valueCChanged(v); }     //registered
875     Q_INVOKABLE void setValueD(Qt::TextElideMode v) { valueD = v; emit valueDChanged(v); }  //unregistered
876     Q_INVOKABLE void setValueE(EnumE v) { valueE = v; emit valueEChanged(v); }
877     Q_INVOKABLE void setValueE2(MyEnum2Class::EnumE v) { valueE2 = v; emit valueE2Changed(v); }
878
879 signals:
880     void valueAChanged(MyEnum1Class::EnumA newValue);
881     void valueBChanged(MyEnum2Class::EnumB newValue);
882     void valueCChanged(Qt::TextFormat newValue);
883     void valueDChanged(Qt::TextElideMode newValue);
884     void valueEChanged(EnumE newValue);
885     void valueE2Changed(MyEnum2Class::EnumE newValue);
886
887 private:
888     MyEnum1Class::EnumA valueA;
889     EnumB valueB;
890     Qt::TextFormat valueC;
891     Qt::TextElideMode valueD;
892     EnumE valueE;
893     EnumE valueE2;
894 };
895
896 class MyEnumDerivedClass : public MyEnum2Class
897 {
898     Q_OBJECT
899 };
900
901 Q_DECLARE_METATYPE(MyEnum2Class::EnumB)
902 Q_DECLARE_METATYPE(MyEnum1Class::EnumA)
903 Q_DECLARE_METATYPE(Qt::TextFormat)
904
905 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
906 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
907 QML_DECLARE_TYPE(MyRevisionedClass)
908 QML_DECLARE_TYPE(MyRevisionedSubclass)
909 QML_DECLARE_TYPE(MySubclass)
910
911 void registerTypes();
912
913 #endif // TESTTYPES_H