Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeecmascript / testtypes.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
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 <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/qdeclarativeexpression.h>
47 #include <QtCore/qpoint.h>
48 #include <QtCore/qsize.h>
49 #include <QtDeclarative/qdeclarativelist.h>
50 #include <QtCore/qrect.h>
51 #include <QtGui/qmatrix.h>
52 #include <QtGui/qcolor.h>
53 #include <QtGui/qvector3d.h>
54 #include <QtCore/qdatetime.h>
55 #include <QtScript/qscriptvalue.h>
56 #include <QtDeclarative/qdeclarativescriptstring.h>
57 #include <QtDeclarative/qdeclarativecomponent.h>
58
59 class MyQmlAttachedObject : public QObject
60 {
61     Q_OBJECT
62     Q_PROPERTY(int value READ value CONSTANT)
63     Q_PROPERTY(int value2 READ value2 WRITE setValue2 NOTIFY value2Changed)
64 public:
65     MyQmlAttachedObject(QObject *parent) : QObject(parent), m_value2(0) {}
66
67     int value() const { return 19; }
68     int value2() const { return m_value2; }
69     void setValue2(int v) { if (m_value2 == v) return; m_value2 = v; emit value2Changed(); }
70
71     void emitMySignal() { emit mySignal(); }
72
73 signals:
74     void value2Changed();
75     void mySignal();
76
77 private:
78     int m_value2;
79 };
80
81 class MyQmlObject : public QObject
82 {
83     Q_OBJECT
84     Q_ENUMS(MyEnum)
85     Q_ENUMS(MyEnum2)
86     Q_PROPERTY(int deleteOnSet READ deleteOnSet WRITE setDeleteOnSet)
87     Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT)
88     Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT)
89     Q_PROPERTY(int value READ value WRITE setValue)
90     Q_PROPERTY(int console READ console CONSTANT)
91     Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged)
92     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged)
93     Q_PROPERTY(QDeclarativeListProperty<QObject> objectListProperty READ objectListProperty CONSTANT)
94     Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty)
95     Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
96     Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false)
97
98 public:
99     MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13) {}
100
101     enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 };
102     enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 };
103
104     bool trueProperty() const { return true; }
105     bool falseProperty() const { return false; }
106
107     QString stringProperty() const { return m_string; }
108     void setStringProperty(const QString &s)
109     {
110         if (s == m_string)
111             return;
112         m_string = s;
113         emit stringChanged();
114     }
115
116     QObject *objectProperty() const { return m_object; }
117     void setObjectProperty(QObject *obj) { 
118         if (obj == m_object)
119             return;
120         m_object = obj;
121         emit objectChanged();
122     }
123
124     QDeclarativeListProperty<QObject> objectListProperty() { return QDeclarativeListProperty<QObject>(this, m_objectQList); }
125
126     bool methodCalled() const { return m_methodCalled; }
127     bool methodIntCalled() const { return m_methodIntCalled; }
128
129     QString string() const { return m_string; }
130
131     static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) {
132         return new MyQmlAttachedObject(o);
133     }
134
135     int deleteOnSet() const { return 1; }
136     void setDeleteOnSet(int v) { if(v) delete this; }
137
138     int value() const { return m_value; }
139     void setValue(int v) { m_value = v; }
140
141     int resettableProperty() const { return m_resetProperty; }
142     void setResettableProperty(int v) { m_resetProperty = v; }
143     void resetProperty() { m_resetProperty = 13; }
144
145     QRegExp regExp() { return m_regExp; }
146     void setRegExp(const QRegExp &regExp) { m_regExp = regExp; }
147
148     int console() const { return 11; }
149
150     int nonscriptable() const { return 0; }
151     void setNonscriptable(int) {}
152
153     MyQmlObject *myinvokableObject;
154     Q_INVOKABLE MyQmlObject *returnme() { return this; }
155
156     struct MyType {
157         int value;
158     };
159     QVariant variant() const { return m_variant; }
160     
161 signals:
162     void basicSignal();
163     void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
164     void stringChanged();
165     void objectChanged();
166     void anotherBasicSignal();
167     void thirdBasicSignal();
168     void signalWithUnknownType(const MyQmlObject::MyType &arg);
169
170 public slots:
171     void deleteMe() { delete this; }
172     void methodNoArgs() { m_methodCalled = true; }
173     void method(int a) { if(a == 163) m_methodIntCalled = true; }
174     void setString(const QString &s) { m_string = s; }
175     void myinvokable(MyQmlObject *o) { myinvokableObject = o; }
176     void variantMethod(const QVariant &v) { m_variant = v; }
177
178 private:
179     friend class tst_qdeclarativeecmascript;
180     bool m_methodCalled;
181     bool m_methodIntCalled;
182
183     QObject *m_object;
184     QString m_string;
185     QList<QObject *> m_objectQList;
186     int m_value;
187     int m_resetProperty;
188     QRegExp m_regExp;
189     QVariant m_variant;
190 };
191
192 QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
193
194 class MyQmlContainer : public QObject
195 {
196     Q_OBJECT
197     Q_PROPERTY(QDeclarativeListProperty<MyQmlObject> children READ children CONSTANT)
198 public:
199     MyQmlContainer() {}
200
201     QDeclarativeListProperty<MyQmlObject> children() { return QDeclarativeListProperty<MyQmlObject>(this, m_children); }
202
203 private:
204     QList<MyQmlObject*> m_children;
205 };
206
207
208 class MyExpression : public QDeclarativeExpression
209 {
210     Q_OBJECT
211 public:
212     MyExpression(QDeclarativeContext *ctxt, const QString &expr)
213         : QDeclarativeExpression(ctxt, 0, expr), changed(false)
214     {
215         QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged()));
216         setNotifyOnValueChanged(true);
217     }
218
219     bool changed;
220
221 public slots:
222     void expressionValueChanged() {
223         changed = true;
224     }
225 };
226
227
228 class MyDefaultObject1 : public QObject
229 {
230     Q_OBJECT
231     Q_PROPERTY(int horseLegs READ horseLegs CONSTANT)
232     Q_PROPERTY(int antLegs READ antLegs CONSTANT)
233     Q_PROPERTY(int emuLegs READ emuLegs CONSTANT)
234 public:
235     int horseLegs() const { return 4; }
236     int antLegs() const { return 6; }
237     int emuLegs() const { return 2; }
238 };
239
240 class MyDefaultObject3 : public QObject
241 {
242     Q_OBJECT
243     Q_PROPERTY(int antLegs READ antLegs CONSTANT)
244     Q_PROPERTY(int humanLegs READ humanLegs CONSTANT)
245 public:
246     int antLegs() const { return 7; } // Mutant
247     int humanLegs() const { return 2; }
248     int millipedeLegs() const { return 1000; }
249 };
250
251 class MyDeferredObject : public QObject
252 {
253     Q_OBJECT
254     Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
255     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
256     Q_PROPERTY(QObject *objectProperty2 READ objectProperty2 WRITE setObjectProperty2)
257     Q_CLASSINFO("DeferredPropertyNames", "value,objectProperty,objectProperty2")
258
259 public:
260     MyDeferredObject() : m_value(0), m_object(0), m_object2(0) {}
261
262     int value() const { return m_value; }
263     void setValue(int v) { m_value = v; emit valueChanged(); }
264
265     QObject *objectProperty() const { return m_object; }
266     void setObjectProperty(QObject *obj) { m_object = obj; }
267
268     QObject *objectProperty2() const { return m_object2; }
269     void setObjectProperty2(QObject *obj) { m_object2 = obj; }
270
271 signals:
272     void valueChanged();
273
274 private:
275     int m_value;
276     QObject *m_object;
277     QObject *m_object2;
278 };
279
280 class MyBaseExtendedObject : public QObject
281 {
282 Q_OBJECT
283 Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)
284 public:
285     MyBaseExtendedObject() : m_value(0) {}
286
287     int baseProperty() const { return m_value; }
288     void setBaseProperty(int v) { m_value = v; }
289
290 private:
291     int m_value;
292 };
293
294 class MyExtendedObject : public MyBaseExtendedObject
295 {
296 Q_OBJECT
297 Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty)
298 public:
299     MyExtendedObject() : m_value(0) {}
300
301     int coreProperty() const { return m_value; }
302     void setCoreProperty(int v) { m_value = v; }
303
304 private:
305     int m_value;
306 };
307
308 class MyTypeObject : public QObject
309 {
310     Q_OBJECT
311     Q_ENUMS(MyEnum)
312     Q_FLAGS(MyFlags)
313
314     Q_PROPERTY(QString id READ id WRITE setId)
315     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
316     Q_PROPERTY(QDeclarativeComponent *componentProperty READ componentProperty WRITE setComponentProperty)
317     Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
318     Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
319     Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
320     Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
321     Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
322     Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty)
323     Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
324     Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty)
325     Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty)
326     Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
327     Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
328     Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
329     Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
330     Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
331     Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
332     Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty)
333     Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
334     Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2)
335     Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty)
336     Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
337     Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
338     Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
339     Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
340
341     Q_PROPERTY(QDeclarativeScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
342
343 public:
344     MyTypeObject()
345         : objectPropertyValue(0), componentPropertyValue(0) {}
346
347     QString idValue;
348     QString id() const {
349         return idValue;
350     }
351     void setId(const QString &v) {
352         idValue = v;
353     }
354
355     QObject *objectPropertyValue;
356     QObject *objectProperty() const {
357         return objectPropertyValue;
358     }
359     void setObjectProperty(QObject *v) {
360         objectPropertyValue = v;
361     }
362
363     QDeclarativeComponent *componentPropertyValue;
364     QDeclarativeComponent *componentProperty() const {
365         return componentPropertyValue;
366     }
367     void setComponentProperty(QDeclarativeComponent *v) {
368         componentPropertyValue = v;
369     }
370
371     enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
372     Q_DECLARE_FLAGS(MyFlags, MyFlag)
373     MyFlags flagPropertyValue;
374     MyFlags flagProperty() const {
375         return flagPropertyValue;
376     }
377     void setFlagProperty(MyFlags v) {
378         flagPropertyValue = v;
379     }
380
381     enum MyEnum { EnumVal1, EnumVal2 };
382     MyEnum enumPropertyValue;
383     MyEnum enumProperty() const {
384         return enumPropertyValue;
385     }
386     void setEnumProperty(MyEnum v) {
387         enumPropertyValue = v;
388     }
389
390     QString stringPropertyValue;
391     QString stringProperty() const {
392        return stringPropertyValue;
393     }
394     void setStringProperty(const QString &v) {
395         stringPropertyValue = v;
396     }
397
398     uint uintPropertyValue;
399     uint uintProperty() const {
400        return uintPropertyValue;
401     }
402     void setUintProperty(const uint &v) {
403         uintPropertyValue = v;
404     }
405
406     int intPropertyValue;
407     int intProperty() const {
408        return intPropertyValue;
409     }
410     void setIntProperty(const int &v) {
411         intPropertyValue = v;
412     }
413
414     qreal realPropertyValue;
415     qreal realProperty() const {
416        return realPropertyValue;
417     }
418     void setRealProperty(const qreal &v) {
419         realPropertyValue = v;
420     }
421
422     double doublePropertyValue;
423     double doubleProperty() const {
424        return doublePropertyValue;
425     }
426     void setDoubleProperty(const double &v) {
427         doublePropertyValue = v;
428     }
429
430     float floatPropertyValue;
431     float floatProperty() const {
432        return floatPropertyValue;
433     }
434     void setFloatProperty(const float &v) {
435         floatPropertyValue = v;
436     }
437
438     QColor colorPropertyValue;
439     QColor colorProperty() const {
440        return colorPropertyValue;
441     }
442     void setColorProperty(const QColor &v) {
443         colorPropertyValue = v;
444     }
445
446     QDate datePropertyValue;
447     QDate dateProperty() const {
448        return datePropertyValue;
449     }
450     void setDateProperty(const QDate &v) {
451         datePropertyValue = v;
452     }
453
454     QTime timePropertyValue;
455     QTime timeProperty() const {
456        return timePropertyValue;
457     }
458     void setTimeProperty(const QTime &v) {
459         timePropertyValue = v;
460     }
461
462     QDateTime dateTimePropertyValue;
463     QDateTime dateTimeProperty() const {
464        return dateTimePropertyValue;
465     }
466     void setDateTimeProperty(const QDateTime &v) {
467         dateTimePropertyValue = v;
468     }
469
470     QPoint pointPropertyValue;
471     QPoint pointProperty() const {
472        return pointPropertyValue;
473     }
474     void setPointProperty(const QPoint &v) {
475         pointPropertyValue = v;
476     }
477
478     QPointF pointFPropertyValue;
479     QPointF pointFProperty() const {
480        return pointFPropertyValue;
481     }
482     void setPointFProperty(const QPointF &v) {
483         pointFPropertyValue = v;
484     }
485
486     QSize sizePropertyValue;
487     QSize sizeProperty() const {
488        return sizePropertyValue;
489     }
490     void setSizeProperty(const QSize &v) {
491         sizePropertyValue = v;
492     }
493
494     QSizeF sizeFPropertyValue;
495     QSizeF sizeFProperty() const {
496        return sizeFPropertyValue;
497     }
498     void setSizeFProperty(const QSizeF &v) {
499         sizeFPropertyValue = v;
500     }
501
502     QRect rectPropertyValue;
503     QRect rectProperty() const {
504        return rectPropertyValue;
505     }
506     void setRectProperty(const QRect &v) {
507         rectPropertyValue = v;
508         emit rectPropertyChanged();
509     }
510
511     QRect rectPropertyValue2;
512     QRect rectProperty2() const {
513        return rectPropertyValue2;
514     }
515     void setRectProperty2(const QRect &v) {
516         rectPropertyValue2 = v;
517     }
518
519     QRectF rectFPropertyValue;
520     QRectF rectFProperty() const {
521        return rectFPropertyValue;
522     }
523     void setRectFProperty(const QRectF &v) {
524         rectFPropertyValue = v;
525     }
526
527     bool boolPropertyValue;
528     bool boolProperty() const {
529        return boolPropertyValue;
530     }
531     void setBoolProperty(const bool &v) {
532         boolPropertyValue = v;
533     }
534
535     QVariant variantPropertyValue;
536     QVariant variantProperty() const {
537        return variantPropertyValue;
538     }
539     void setVariantProperty(const QVariant &v) {
540         variantPropertyValue = v;
541     }
542
543     QVector3D vectorPropertyValue;
544     QVector3D vectorProperty() const {
545         return vectorPropertyValue;
546     }
547     void setVectorProperty(const QVector3D &v) {
548         vectorPropertyValue = v;
549     }
550
551     QUrl urlPropertyValue;
552     QUrl urlProperty() const {
553         return urlPropertyValue;
554     }
555     void setUrlProperty(const QUrl &v) {
556         urlPropertyValue = v;
557     }
558
559     QDeclarativeScriptString scriptPropertyValue;
560     QDeclarativeScriptString scriptProperty() const {
561         return scriptPropertyValue;
562     }
563     void setScriptProperty(const QDeclarativeScriptString &v) {
564         scriptPropertyValue = v;
565     }
566
567     void doAction() { emit action(); }
568 signals:
569     void action();
570     void rectPropertyChanged();
571 };
572 Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
573
574 class MyDerivedObject : public MyTypeObject
575 {
576     Q_OBJECT
577 public:
578     Q_INVOKABLE bool intProperty() const {
579         return true;
580     }
581 };
582
583 Q_DECLARE_METATYPE(QScriptValue);
584 class MyInvokableBaseObject : public QObject
585 {
586     Q_OBJECT
587 public:
588     inline ~MyInvokableBaseObject() = 0;
589
590     Q_INVOKABLE inline void method_inherited(int a);
591     Q_INVOKABLE inline void method_overload();
592 };
593
594 class MyInvokableObject : public MyInvokableBaseObject
595 {
596     Q_OBJECT
597     Q_ENUMS(TestEnum)
598 public:
599     enum TestEnum { EnumValue1, EnumValue2 };
600     MyInvokableObject() { reset(); }
601
602     int invoked() const { return m_invoked; }
603     bool error() const { return m_invokedError; }
604     const QVariantList &actuals() const { return m_actuals; }
605     void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); }
606
607     Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); }
608     Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); }
609
610     Q_INVOKABLE void method_NoArgs() { invoke(0); }
611     Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
612     Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
613     Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
614     Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
615     Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
616     Q_INVOKABLE QScriptValue method_NoArgs_QScriptValue() { invoke(6); return QScriptValue("Hello world"); }
617     Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); }
618
619     Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; }
620     Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; }
621     Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; }
622     Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; }
623     Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; }
624     Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); }
625     Q_INVOKABLE void method_QScriptValue(QScriptValue a) { invoke(14); m_actuals << qVariantFromValue(a); }
626     Q_INVOKABLE void method_intQScriptValue(int a, QScriptValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); }
627     
628     Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
629     Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
630     Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
631
632     Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
633
634     Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
635
636     Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
637
638 private:
639     friend class MyInvokableBaseObject;
640     void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
641     int m_invoked;
642     bool m_invokedError;
643     QVariantList m_actuals;
644 };
645
646 MyInvokableBaseObject::~MyInvokableBaseObject() {}
647
648 void MyInvokableBaseObject::method_inherited(int a)
649 {
650     static_cast<MyInvokableObject *>(this)->invoke(-3);
651     static_cast<MyInvokableObject *>(this)->m_actuals << a;
652 }
653
654 // This is a hidden overload of the MyInvokableObject::method_overload() method
655 void MyInvokableBaseObject::method_overload()
656 {
657     static_cast<MyInvokableObject *>(this)->invoke(-2);
658 }
659
660 class NumberAssignment : public QObject
661 {
662     Q_OBJECT
663 public:
664     Q_PROPERTY(qreal test1 READ test1 WRITE setTest1)
665     qreal _test1;
666     qreal test1() const { return _test1; }
667     void setTest1(qreal v) { _test1 = v; }
668
669     Q_PROPERTY(qreal test2 READ test2 WRITE setTest2)
670     qreal _test2;
671     qreal test2() const { return _test2; }
672     void setTest2(qreal v) { _test2 = v; }
673
674     Q_PROPERTY(qreal test3 READ test3 WRITE setTest3)
675     qreal _test3;
676     qreal test3() const { return _test3; }
677     void setTest3(qreal v) { _test3 = v; }
678
679     Q_PROPERTY(qreal test4 READ test4 WRITE setTest4)
680     qreal _test4;
681     qreal test4() const { return _test4; }
682     void setTest4(qreal v) { _test4 = v; }
683
684     Q_PROPERTY(int test5 READ test5 WRITE setTest5)
685     int _test5;
686     int test5() const { return _test5; }
687     void setTest5(int v) { _test5 = v; }
688
689     Q_PROPERTY(int test6 READ test6 WRITE setTest6)
690     int _test6;
691     int test6() const { return _test6; }
692     void setTest6(int v) { _test6 = v; }
693
694     Q_PROPERTY(int test7 READ test7 WRITE setTest7)
695     int _test7;
696     int test7() const { return _test7; }
697     void setTest7(int v) { _test7 = v; }
698
699     Q_PROPERTY(int test8 READ test8 WRITE setTest8)
700     int _test8;
701     int test8() const { return _test8; }
702     void setTest8(int v) { _test8 = v; }
703
704     Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9)
705     unsigned int _test9;
706     unsigned int test9() const { return _test9; }
707     void setTest9(unsigned int v) { _test9 = v; }
708
709     Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10)
710     unsigned int _test10;
711     unsigned int test10() const { return _test10; }
712     void setTest10(unsigned int v) { _test10 = v; }
713
714     Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11)
715     unsigned int _test11;
716     unsigned int test11() const { return _test11; }
717     void setTest11(unsigned int v) { _test11 = v; }
718
719     Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12)
720     unsigned int _test12;
721     unsigned int test12() const { return _test12; }
722     void setTest12(unsigned int v) { _test12 = v; }
723 };
724
725 class DefaultPropertyExtendedObject : public QObject
726 {
727     Q_OBJECT
728     Q_PROPERTY(QObject *firstProperty READ firstProperty WRITE setFirstProperty)
729     Q_PROPERTY(QObject *secondProperty READ secondProperty WRITE setSecondProperty)
730 public:
731     DefaultPropertyExtendedObject(QObject *parent = 0) : QObject(parent), m_firstProperty(0), m_secondProperty(0) {}
732
733     QObject *firstProperty() const { return m_firstProperty; }
734     QObject *secondProperty() const { return m_secondProperty; }
735     void setFirstProperty(QObject *property) { m_firstProperty = property; }
736     void setSecondProperty(QObject *property) { m_secondProperty = property; }
737 private:
738     QObject* m_firstProperty;
739     QObject* m_secondProperty;
740 };
741
742 class OverrideDefaultPropertyObject : public DefaultPropertyExtendedObject
743 {
744     Q_OBJECT
745     Q_CLASSINFO("DefaultProperty", "secondProperty")
746 public:
747     OverrideDefaultPropertyObject() {}
748 };
749
750 class MyRevisionedBaseClassRegistered : public QObject
751 {
752 Q_OBJECT
753     Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
754     Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
755
756 public:
757     MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
758
759     qreal propA() const { return m_pa; }
760     void setPropA(qreal p) {
761         if (p != m_pa) {
762             m_pa = p;
763             emit propAChanged();
764         }
765     }
766     qreal propB() const { return m_pb; }
767     void setPropB(qreal p) {
768         if (p != m_pb) {
769             m_pb = p;
770             emit propBChanged();
771         }
772     }
773
774     Q_INVOKABLE void methodA() { }
775     Q_INVOKABLE Q_REVISION(1) void methodB() { }
776
777 signals:
778     void propAChanged();
779     void propBChanged();
780
781     void signalA();
782     Q_REVISION(1) void signalB();
783
784 protected:
785     qreal m_pa;
786     qreal m_pb;
787 };
788
789 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
790 {
791 Q_OBJECT
792     Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
793     Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
794
795 public:
796     MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
797
798     qreal propC() const { return m_pc; }
799     void setPropC(qreal p) {
800         if (p != m_pc) {
801             m_pc = p;
802             emit propCChanged();
803         }
804     }
805     qreal propD() const { return m_pd; }
806     void setPropD(qreal p) {
807         if (p != m_pd) {
808             m_pd = p;
809             emit propDChanged();
810         }
811     }
812
813     Q_INVOKABLE void methodC() { }
814     Q_INVOKABLE Q_REVISION(1) void methodD() { }
815
816 signals:
817     void propCChanged();
818     void propDChanged();
819
820     void signalC();
821     Q_REVISION(1) void signalD();
822
823 protected:
824     qreal m_pc;
825     qreal m_pd;
826 };
827
828 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
829 {
830     Q_OBJECT
831     Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
832     Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
833
834 public:
835     MyRevisionedClass() {}
836
837     qreal prop1() const { return m_p1; }
838     void setProp1(qreal p) {
839         if (p != m_p1) {
840             m_p1 = p;
841             emit prop1Changed();
842         }
843     }
844     qreal prop2() const { return m_p2; }
845     void setProp2(qreal p) {
846         if (p != m_p2) {
847             m_p2 = p;
848             emit prop2Changed();
849         }
850     }
851
852     Q_INVOKABLE void method1() { }
853     Q_INVOKABLE Q_REVISION(1) void method2() { }
854
855 signals:
856     void prop1Changed();
857     void prop2Changed();
858
859     void signal1();
860     Q_REVISION(1) void signal2();
861
862 protected:
863     qreal m_p1;
864     qreal m_p2;
865 };
866
867 class MyRevisionedSubclass : public MyRevisionedClass
868 {
869     Q_OBJECT
870     Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
871     Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
872
873 public:
874     MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
875
876     qreal prop3() const { return m_p3; }
877     void setProp3(qreal p) {
878         if (p != m_p3) {
879             m_p3 = p;
880             emit prop3Changed();
881         }
882     }
883     qreal prop4() const { return m_p4; }
884     void setProp4(qreal p) {
885         if (p != m_p4) {
886             m_p4 = p;
887             emit prop4Changed();
888         }
889     }
890
891     Q_INVOKABLE void method3() { }
892     Q_INVOKABLE Q_REVISION(1) void method4() { }
893
894 signals:
895     void prop3Changed();
896     void prop4Changed();
897
898     void signal3();
899     Q_REVISION(1) void signal4();
900
901 protected:
902     qreal m_p3;
903     qreal m_p4;
904 };
905
906 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
907 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
908 QML_DECLARE_TYPE(MyRevisionedClass)
909 QML_DECLARE_TYPE(MyRevisionedSubclass)
910 Q_DECLARE_METATYPE(MyQmlObject::MyType)
911
912 void registerTypes();
913
914 #endif // TESTTYPES_H
915