Support enum return types in Q_INVOKABLE functions.
[profile/ivi/qtdeclarative.git] / tests / auto / qml / qqmlecmascript / 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 <QtQml/qqml.h>
46 #include <QtQml/qqmlexpression.h>
47 #include <QtCore/qpoint.h>
48 #include <QtCore/qsize.h>
49 #include <QtQml/qqmllist.h>
50 #include <QtCore/qrect.h>
51 #include <QtGui/qmatrix.h>
52 #include <QtGui/qcolor.h>
53 #include <QtGui/qvector3d.h>
54 #include <QtGui/QFont>
55 #include <QtGui/QPixmap>
56 #include <QtCore/qdatetime.h>
57 #include <QtCore/qjsonarray.h>
58 #include <QtCore/qjsonobject.h>
59 #include <QtCore/qjsonvalue.h>
60 #include <QtQml/qjsvalue.h>
61 #include <QtQml/qqmlscriptstring.h>
62 #include <QtQml/qqmlcomponent.h>
63
64 #include <private/qqmlengine_p.h>
65 #include <private/qv8engine_p.h>
66
67 class MyQmlAttachedObject : public QObject
68 {
69     Q_OBJECT
70     Q_PROPERTY(int value READ value CONSTANT)
71     Q_PROPERTY(int value2 READ value2 WRITE setValue2 NOTIFY value2Changed)
72 public:
73     MyQmlAttachedObject(QObject *parent) : QObject(parent), m_value2(0) {}
74
75     int value() const { return 19; }
76     int value2() const { return m_value2; }
77     void setValue2(int v) { if (m_value2 == v) return; m_value2 = v; emit value2Changed(); }
78
79     void emitMySignal() { emit mySignal(); }
80
81 signals:
82     void value2Changed();
83     void mySignal();
84
85 private:
86     int m_value2;
87 };
88
89 class MyQmlObject : public QObject
90 {
91     Q_OBJECT
92     Q_ENUMS(MyEnum)
93     Q_ENUMS(MyEnum2)
94     Q_PROPERTY(int deleteOnSet READ deleteOnSet WRITE setDeleteOnSet)
95     Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT)
96     Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT)
97     Q_PROPERTY(int value READ value WRITE setValue)
98     Q_PROPERTY(int console READ console CONSTANT)
99     Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged)
100     Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty NOTIFY urlChanged)
101     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged)
102     Q_PROPERTY(QQmlListProperty<QObject> objectListProperty READ objectListProperty CONSTANT)
103     Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty)
104     Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
105     Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false)
106     Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intChanged)
107     Q_PROPERTY(QJSValue qjsvalue READ qjsvalue WRITE setQJSValue NOTIFY qjsvalueChanged)
108     Q_PROPERTY(QJSValue qjsvalueWithReset READ qjsvalue WRITE setQJSValue RESET resetQJSValue NOTIFY qjsvalueChanged)
109
110 public:
111     MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0), m_buttons(0) {}
112
113     enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 };
114     enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 };
115
116     bool trueProperty() const { return true; }
117     bool falseProperty() const { return false; }
118
119     QString stringProperty() const { return m_string; }
120     void setStringProperty(const QString &s)
121     {
122         if (s == m_string)
123             return;
124         m_string = s;
125         emit stringChanged();
126     }
127
128     QUrl urlProperty() const { return m_url; }
129     void setUrlProperty(const QUrl &url)
130     {
131         if (url == m_url)
132             return;
133         m_url = url;
134         emit urlChanged();
135     }
136
137     QObject *objectProperty() const { return m_object; }
138     void setObjectProperty(QObject *obj) { 
139         if (obj == m_object)
140             return;
141         m_object = obj;
142         emit objectChanged();
143     }
144
145     QQmlListProperty<QObject> objectListProperty() { return QQmlListProperty<QObject>(this, m_objectQList); }
146
147     bool methodCalled() const { return m_methodCalled; }
148     bool methodIntCalled() const { return m_methodIntCalled; }
149
150     QString string() const { return m_string; }
151
152     static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) {
153         return new MyQmlAttachedObject(o);
154     }
155
156     int deleteOnSet() const { return 1; }
157     void setDeleteOnSet(int v) { if(v) delete this; }
158
159     int value() const { return m_value; }
160     void setValue(int v) { m_value = v; }
161
162     int resettableProperty() const { return m_resetProperty; }
163     void setResettableProperty(int v) { m_resetProperty = v; }
164     void resetProperty() { m_resetProperty = 13; }
165
166     QRegExp regExp() { return m_regExp; }
167     void setRegExp(const QRegExp &regExp) { m_regExp = regExp; }
168
169     int console() const { return 11; }
170
171     int nonscriptable() const { return 0; }
172     void setNonscriptable(int) {}
173
174     MyQmlObject *myinvokableObject;
175     Q_INVOKABLE MyQmlObject *returnme() { return this; }
176
177     struct MyType {
178         int value;
179     };
180     QVariant variant() const { return m_variant; }
181     QJSValue qjsvalue() const { return m_qjsvalue; }
182     void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); }
183     void resetQJSValue() { m_qjsvalue = QJSValue(QLatin1String("Reset!")); emit qjsvalueChanged(); }
184
185     Qt::MouseButtons buttons() const { return m_buttons; }
186
187     int intProperty() const { return m_intProperty; }
188     void setIntProperty(int i) { m_intProperty = i; emit intChanged(); }
189     
190     Q_INVOKABLE MyEnum2 getEnumValue() const { return EnumValue4; }
191
192 signals:
193     void basicSignal();
194     void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
195     void unnamedArgumentSignal(int a, qreal, QString c);
196     void stringChanged();
197     void urlChanged();
198     void objectChanged();
199     void anotherBasicSignal();
200     void thirdBasicSignal();
201     void signalWithUnknownType(const MyQmlObject::MyType &arg);
202     void signalWithVariant(const QVariant &arg);
203     void signalWithQJSValue(const QJSValue &arg);
204     void signalWithGlobalName(int parseInt);
205     void intChanged();
206     void qjsvalueChanged();
207
208 public slots:
209     void deleteMe() { delete this; }
210     void methodNoArgs() { m_methodCalled = true; }
211     void method(int a) { if(a == 163) m_methodIntCalled = true; }
212     void setString(const QString &s) { m_string = s; }
213     void myinvokable(MyQmlObject *o) { myinvokableObject = o; }
214     void variantMethod(const QVariant &v) { m_variant = v; }
215     void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; }
216     void v8function(QQmlV8Function*);
217     void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; }
218
219 private:
220     friend class tst_qqmlecmascript;
221     bool m_methodCalled;
222     bool m_methodIntCalled;
223
224     QObject *m_object;
225     QString m_string;
226     QUrl m_url;
227     QList<QObject *> m_objectQList;
228     int m_value;
229     int m_resetProperty;
230     QRegExp m_regExp;
231     QVariant m_variant;
232     QJSValue m_qjsvalue;
233     int m_intProperty;
234     Qt::MouseButtons m_buttons;
235 };
236
237 QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
238
239 class MyQmlContainer : public QObject
240 {
241     Q_OBJECT
242     Q_PROPERTY(QQmlListProperty<MyQmlObject> children READ children CONSTANT)
243 public:
244     MyQmlContainer() {}
245
246     QQmlListProperty<MyQmlObject> children() { return QQmlListProperty<MyQmlObject>(this, m_children); }
247
248 private:
249     QList<MyQmlObject*> m_children;
250 };
251
252
253 class MyExpression : public QQmlExpression
254 {
255     Q_OBJECT
256 public:
257     MyExpression(QQmlContext *ctxt, const QString &expr)
258         : QQmlExpression(ctxt, 0, expr), changed(false)
259     {
260         QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged()));
261         setNotifyOnValueChanged(true);
262     }
263
264     bool changed;
265
266 public slots:
267     void expressionValueChanged() {
268         changed = true;
269     }
270 };
271
272
273 class MyDefaultObject1 : public QObject
274 {
275     Q_OBJECT
276     Q_PROPERTY(int horseLegs READ horseLegs CONSTANT)
277     Q_PROPERTY(int antLegs READ antLegs CONSTANT)
278     Q_PROPERTY(int emuLegs READ emuLegs CONSTANT)
279 public:
280     int horseLegs() const { return 4; }
281     int antLegs() const { return 6; }
282     int emuLegs() const { return 2; }
283 };
284
285 class MyDefaultObject3 : public QObject
286 {
287     Q_OBJECT
288     Q_PROPERTY(int antLegs READ antLegs CONSTANT)
289     Q_PROPERTY(int humanLegs READ humanLegs CONSTANT)
290 public:
291     int antLegs() const { return 7; } // Mutant
292     int humanLegs() const { return 2; }
293     int millipedeLegs() const { return 1000; }
294 };
295
296 class MyDeferredObject : public QObject
297 {
298     Q_OBJECT
299     Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
300     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
301     Q_PROPERTY(QObject *objectProperty2 READ objectProperty2 WRITE setObjectProperty2)
302     Q_CLASSINFO("DeferredPropertyNames", "value,objectProperty,objectProperty2")
303
304 public:
305     MyDeferredObject() : m_value(0), m_object(0), m_object2(0) {}
306
307     int value() const { return m_value; }
308     void setValue(int v) { m_value = v; emit valueChanged(); }
309
310     QObject *objectProperty() const { return m_object; }
311     void setObjectProperty(QObject *obj) { m_object = obj; }
312
313     QObject *objectProperty2() const { return m_object2; }
314     void setObjectProperty2(QObject *obj) { m_object2 = obj; }
315
316 signals:
317     void valueChanged();
318
319 private:
320     int m_value;
321     QObject *m_object;
322     QObject *m_object2;
323 };
324
325 class MyBaseExtendedObject : public QObject
326 {
327 Q_OBJECT
328 Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)
329 public:
330     MyBaseExtendedObject() : m_value(0) {}
331
332     int baseProperty() const { return m_value; }
333     void setBaseProperty(int v) { m_value = v; }
334
335 private:
336     int m_value;
337 };
338
339 class MyExtendedObject : public MyBaseExtendedObject
340 {
341 Q_OBJECT
342 Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty)
343 public:
344     MyExtendedObject() : m_value(0) {}
345
346     int coreProperty() const { return m_value; }
347     void setCoreProperty(int v) { m_value = v; }
348
349 private:
350     int m_value;
351 };
352
353 class MyTypeObject : public QObject
354 {
355     Q_OBJECT
356     Q_ENUMS(MyEnum)
357     Q_FLAGS(MyFlags)
358
359     Q_PROPERTY(QString id READ id WRITE setId)
360     Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
361     Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty)
362     Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
363     Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
364     Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
365     Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
366     Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
367     Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty)
368     Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
369     Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty)
370     Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty)
371     Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
372     Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
373     Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
374     Q_PROPERTY(QDateTime dateTimeProperty2 READ dateTimeProperty2 WRITE setDateTimeProperty2)
375     Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
376     Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
377     Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
378     Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty)
379     Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
380     Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2)
381     Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty)
382     Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
383     Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
384     Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
385     Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
386
387     Q_PROPERTY(QQmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
388
389 public:
390     MyTypeObject()
391         : objectPropertyValue(0), componentPropertyValue(0) {}
392
393     QString idValue;
394     QString id() const {
395         return idValue;
396     }
397     void setId(const QString &v) {
398         idValue = v;
399     }
400
401     QObject *objectPropertyValue;
402     QObject *objectProperty() const {
403         return objectPropertyValue;
404     }
405     void setObjectProperty(QObject *v) {
406         objectPropertyValue = v;
407     }
408
409     QQmlComponent *componentPropertyValue;
410     QQmlComponent *componentProperty() const {
411         return componentPropertyValue;
412     }
413     void setComponentProperty(QQmlComponent *v) {
414         componentPropertyValue = v;
415     }
416
417     enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
418     Q_DECLARE_FLAGS(MyFlags, MyFlag)
419     MyFlags flagPropertyValue;
420     MyFlags flagProperty() const {
421         return flagPropertyValue;
422     }
423     void setFlagProperty(MyFlags v) {
424         flagPropertyValue = v;
425     }
426
427     enum MyEnum { EnumVal1, EnumVal2 };
428     MyEnum enumPropertyValue;
429     MyEnum enumProperty() const {
430         return enumPropertyValue;
431     }
432     void setEnumProperty(MyEnum v) {
433         enumPropertyValue = v;
434     }
435
436     QString stringPropertyValue;
437     QString stringProperty() const {
438        return stringPropertyValue;
439     }
440     void setStringProperty(const QString &v) {
441         stringPropertyValue = v;
442     }
443
444     uint uintPropertyValue;
445     uint uintProperty() const {
446        return uintPropertyValue;
447     }
448     void setUintProperty(const uint &v) {
449         uintPropertyValue = v;
450     }
451
452     int intPropertyValue;
453     int intProperty() const {
454        return intPropertyValue;
455     }
456     void setIntProperty(const int &v) {
457         intPropertyValue = v;
458     }
459
460     qreal realPropertyValue;
461     qreal realProperty() const {
462        return realPropertyValue;
463     }
464     void setRealProperty(const qreal &v) {
465         realPropertyValue = v;
466     }
467
468     double doublePropertyValue;
469     double doubleProperty() const {
470        return doublePropertyValue;
471     }
472     void setDoubleProperty(const double &v) {
473         doublePropertyValue = v;
474     }
475
476     float floatPropertyValue;
477     float floatProperty() const {
478        return floatPropertyValue;
479     }
480     void setFloatProperty(const float &v) {
481         floatPropertyValue = v;
482     }
483
484     QColor colorPropertyValue;
485     QColor colorProperty() const {
486        return colorPropertyValue;
487     }
488     void setColorProperty(const QColor &v) {
489         colorPropertyValue = v;
490     }
491
492     QDate datePropertyValue;
493     QDate dateProperty() const {
494        return datePropertyValue;
495     }
496     void setDateProperty(const QDate &v) {
497         datePropertyValue = v;
498     }
499
500     QTime timePropertyValue;
501     QTime timeProperty() const {
502        return timePropertyValue;
503     }
504     void setTimeProperty(const QTime &v) {
505         timePropertyValue = v;
506     }
507
508     QDateTime dateTimePropertyValue;
509     QDateTime dateTimeProperty() const {
510        return dateTimePropertyValue;
511     }
512     void setDateTimeProperty(const QDateTime &v) {
513         dateTimePropertyValue = v;
514     }
515
516     QDateTime dateTimePropertyValue2;
517     QDateTime dateTimeProperty2() const {
518        return dateTimePropertyValue2;
519     }
520     void setDateTimeProperty2(const QDateTime &v) {
521         dateTimePropertyValue2 = v;
522     }
523
524     QPoint pointPropertyValue;
525     QPoint pointProperty() const {
526        return pointPropertyValue;
527     }
528     void setPointProperty(const QPoint &v) {
529         pointPropertyValue = v;
530     }
531
532     QPointF pointFPropertyValue;
533     QPointF pointFProperty() const {
534        return pointFPropertyValue;
535     }
536     void setPointFProperty(const QPointF &v) {
537         pointFPropertyValue = v;
538     }
539
540     QSize sizePropertyValue;
541     QSize sizeProperty() const {
542        return sizePropertyValue;
543     }
544     void setSizeProperty(const QSize &v) {
545         sizePropertyValue = v;
546     }
547
548     QSizeF sizeFPropertyValue;
549     QSizeF sizeFProperty() const {
550        return sizeFPropertyValue;
551     }
552     void setSizeFProperty(const QSizeF &v) {
553         sizeFPropertyValue = v;
554     }
555
556     QRect rectPropertyValue;
557     QRect rectProperty() const {
558        return rectPropertyValue;
559     }
560     void setRectProperty(const QRect &v) {
561         rectPropertyValue = v;
562         emit rectPropertyChanged();
563     }
564
565     QRect rectPropertyValue2;
566     QRect rectProperty2() const {
567        return rectPropertyValue2;
568     }
569     void setRectProperty2(const QRect &v) {
570         rectPropertyValue2 = v;
571     }
572
573     QRectF rectFPropertyValue;
574     QRectF rectFProperty() const {
575        return rectFPropertyValue;
576     }
577     void setRectFProperty(const QRectF &v) {
578         rectFPropertyValue = v;
579     }
580
581     bool boolPropertyValue;
582     bool boolProperty() const {
583        return boolPropertyValue;
584     }
585     void setBoolProperty(const bool &v) {
586         boolPropertyValue = v;
587     }
588
589     QVariant variantPropertyValue;
590     QVariant variantProperty() const {
591        return variantPropertyValue;
592     }
593     void setVariantProperty(const QVariant &v) {
594         variantPropertyValue = v;
595     }
596
597     QVector3D vectorPropertyValue;
598     QVector3D vectorProperty() const {
599         return vectorPropertyValue;
600     }
601     void setVectorProperty(const QVector3D &v) {
602         vectorPropertyValue = v;
603     }
604
605     QUrl urlPropertyValue;
606     QUrl urlProperty() const {
607         return urlPropertyValue;
608     }
609     void setUrlProperty(const QUrl &v) {
610         urlPropertyValue = v;
611     }
612
613     QQmlScriptString scriptPropertyValue;
614     QQmlScriptString scriptProperty() const {
615         return scriptPropertyValue;
616     }
617     void setScriptProperty(const QQmlScriptString &v) {
618         scriptPropertyValue = v;
619     }
620
621     void doAction() { emit action(); }
622 signals:
623     void action();
624     void rectPropertyChanged();
625 };
626 Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
627
628 class MyDerivedObject : public MyTypeObject
629 {
630     Q_OBJECT
631 public:
632     Q_INVOKABLE bool intProperty() const {
633         return true;
634     }
635 };
636
637 Q_DECLARE_METATYPE(QJSValue);
638 class MyInvokableBaseObject : public QObject
639 {
640     Q_OBJECT
641 public:
642     inline ~MyInvokableBaseObject() = 0;
643
644     Q_INVOKABLE inline void method_inherited(int a);
645     Q_INVOKABLE inline void method_overload();
646 };
647
648 class MyInvokableObject : public MyInvokableBaseObject
649 {
650     Q_OBJECT
651     Q_ENUMS(TestEnum)
652 public:
653     enum TestEnum { EnumValue1, EnumValue2 };
654     MyInvokableObject() { reset(); }
655
656     int invoked() const { return m_invoked; }
657     bool error() const { return m_invokedError; }
658     const QVariantList &actuals() const { return m_actuals; }
659     void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); }
660
661     Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); }
662     Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); }
663
664     Q_INVOKABLE void method_NoArgs() { invoke(0); }
665     Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
666     Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
667     Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
668     Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
669     Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
670     Q_INVOKABLE QJSValue method_NoArgs_QScriptValue() { invoke(6); return QJSValue("Hello world"); }
671     Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); }
672
673     Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; }
674     Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; }
675     Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; }
676     Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; }
677     Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; }
678     Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); }
679     Q_INVOKABLE void method_QScriptValue(QJSValue a) { invoke(14); m_actuals << qVariantFromValue(a); }
680     Q_INVOKABLE void method_intQScriptValue(int a, QJSValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); }
681     
682     Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
683     Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
684     Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
685
686     Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
687
688     Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
689
690     Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
691
692     Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); }
693     Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); }
694     Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); }
695
696     Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); }
697     Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
698     Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
699
700     Q_INVOKABLE void method_unknown(MyInvokableObject *o) { invoke(28); }
701
702 private:
703     friend class MyInvokableBaseObject;
704     void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
705     int m_invoked;
706     bool m_invokedError;
707     QVariantList m_actuals;
708 };
709
710 MyInvokableBaseObject::~MyInvokableBaseObject() {}
711
712 void MyInvokableBaseObject::method_inherited(int a)
713 {
714     static_cast<MyInvokableObject *>(this)->invoke(-3);
715     static_cast<MyInvokableObject *>(this)->m_actuals << a;
716 }
717
718 // This is a hidden overload of the MyInvokableObject::method_overload() method
719 void MyInvokableBaseObject::method_overload()
720 {
721     static_cast<MyInvokableObject *>(this)->invoke(-2);
722 }
723
724 class NumberAssignment : public QObject
725 {
726     Q_OBJECT
727 public:
728     Q_PROPERTY(qreal test1 READ test1 WRITE setTest1)
729     qreal _test1;
730     qreal test1() const { return _test1; }
731     void setTest1(qreal v) { _test1 = v; }
732
733     Q_PROPERTY(qreal test2 READ test2 WRITE setTest2)
734     qreal _test2;
735     qreal test2() const { return _test2; }
736     void setTest2(qreal v) { _test2 = v; }
737
738     Q_PROPERTY(qreal test3 READ test3 WRITE setTest3)
739     qreal _test3;
740     qreal test3() const { return _test3; }
741     void setTest3(qreal v) { _test3 = v; }
742
743     Q_PROPERTY(qreal test4 READ test4 WRITE setTest4)
744     qreal _test4;
745     qreal test4() const { return _test4; }
746     void setTest4(qreal v) { _test4 = v; }
747
748     Q_PROPERTY(int test5 READ test5 WRITE setTest5)
749     int _test5;
750     int test5() const { return _test5; }
751     void setTest5(int v) { _test5 = v; }
752
753     Q_PROPERTY(int test6 READ test6 WRITE setTest6)
754     int _test6;
755     int test6() const { return _test6; }
756     void setTest6(int v) { _test6 = v; }
757
758     Q_PROPERTY(int test7 READ test7 WRITE setTest7)
759     int _test7;
760     int test7() const { return _test7; }
761     void setTest7(int v) { _test7 = v; }
762
763     Q_PROPERTY(int test8 READ test8 WRITE setTest8)
764     int _test8;
765     int test8() const { return _test8; }
766     void setTest8(int v) { _test8 = v; }
767
768     Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9)
769     unsigned int _test9;
770     unsigned int test9() const { return _test9; }
771     void setTest9(unsigned int v) { _test9 = v; }
772
773     Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10)
774     unsigned int _test10;
775     unsigned int test10() const { return _test10; }
776     void setTest10(unsigned int v) { _test10 = v; }
777
778     Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11)
779     unsigned int _test11;
780     unsigned int test11() const { return _test11; }
781     void setTest11(unsigned int v) { _test11 = v; }
782
783     Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12)
784     unsigned int _test12;
785     unsigned int test12() const { return _test12; }
786     void setTest12(unsigned int v) { _test12 = v; }
787 };
788
789 class DefaultPropertyExtendedObject : public QObject
790 {
791     Q_OBJECT
792     Q_PROPERTY(QObject *firstProperty READ firstProperty WRITE setFirstProperty)
793     Q_PROPERTY(QObject *secondProperty READ secondProperty WRITE setSecondProperty)
794 public:
795     DefaultPropertyExtendedObject(QObject *parent = 0) : QObject(parent), m_firstProperty(0), m_secondProperty(0) {}
796
797     QObject *firstProperty() const { return m_firstProperty; }
798     QObject *secondProperty() const { return m_secondProperty; }
799     void setFirstProperty(QObject *property) { m_firstProperty = property; }
800     void setSecondProperty(QObject *property) { m_secondProperty = property; }
801 private:
802     QObject* m_firstProperty;
803     QObject* m_secondProperty;
804 };
805
806 class OverrideDefaultPropertyObject : public DefaultPropertyExtendedObject
807 {
808     Q_OBJECT
809     Q_CLASSINFO("DefaultProperty", "secondProperty")
810 public:
811     OverrideDefaultPropertyObject() {}
812 };
813
814 class MyRevisionedBaseClassRegistered : public QObject
815 {
816 Q_OBJECT
817     Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
818     Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
819
820 public:
821     MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
822
823     qreal propA() const { return m_pa; }
824     void setPropA(qreal p) {
825         if (p != m_pa) {
826             m_pa = p;
827             emit propAChanged();
828         }
829     }
830     qreal propB() const { return m_pb; }
831     void setPropB(qreal p) {
832         if (p != m_pb) {
833             m_pb = p;
834             emit propBChanged();
835         }
836     }
837
838     Q_INVOKABLE void methodA() { }
839     Q_INVOKABLE Q_REVISION(1) void methodB() { }
840
841 signals:
842     void propAChanged();
843     void propBChanged();
844
845     void signalA();
846     Q_REVISION(1) void signalB();
847
848 protected:
849     qreal m_pa;
850     qreal m_pb;
851 };
852
853 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
854 {
855 Q_OBJECT
856     Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
857     Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
858
859 public:
860     MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
861
862     qreal propC() const { return m_pc; }
863     void setPropC(qreal p) {
864         if (p != m_pc) {
865             m_pc = p;
866             emit propCChanged();
867         }
868     }
869     qreal propD() const { return m_pd; }
870     void setPropD(qreal p) {
871         if (p != m_pd) {
872             m_pd = p;
873             emit propDChanged();
874         }
875     }
876
877     Q_INVOKABLE void methodC() { }
878     Q_INVOKABLE Q_REVISION(1) void methodD() { }
879
880 signals:
881     void propCChanged();
882     void propDChanged();
883
884     void signalC();
885     Q_REVISION(1) void signalD();
886
887 protected:
888     qreal m_pc;
889     qreal m_pd;
890 };
891
892 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
893 {
894     Q_OBJECT
895     Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
896     Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
897
898 public:
899     MyRevisionedClass() {}
900
901     qreal prop1() const { return m_p1; }
902     void setProp1(qreal p) {
903         if (p != m_p1) {
904             m_p1 = p;
905             emit prop1Changed();
906         }
907     }
908     qreal prop2() const { return m_p2; }
909     void setProp2(qreal p) {
910         if (p != m_p2) {
911             m_p2 = p;
912             emit prop2Changed();
913         }
914     }
915
916     Q_INVOKABLE void method1() { }
917     Q_INVOKABLE Q_REVISION(1) void method2() { }
918
919 signals:
920     void prop1Changed();
921     void prop2Changed();
922
923     void signal1();
924     Q_REVISION(1) void signal2();
925
926 protected:
927     qreal m_p1;
928     qreal m_p2;
929 };
930
931 class MyRevisionedSubclass : public MyRevisionedClass
932 {
933     Q_OBJECT
934     Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
935     Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
936
937 public:
938     MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
939
940     qreal prop3() const { return m_p3; }
941     void setProp3(qreal p) {
942         if (p != m_p3) {
943             m_p3 = p;
944             emit prop3Changed();
945         }
946     }
947     qreal prop4() const { return m_p4; }
948     void setProp4(qreal p) {
949         if (p != m_p4) {
950             m_p4 = p;
951             emit prop4Changed();
952         }
953     }
954
955     Q_INVOKABLE void method3() { }
956     Q_INVOKABLE Q_REVISION(1) void method4() { }
957
958 signals:
959     void prop3Changed();
960     void prop4Changed();
961
962     void signal3();
963     Q_REVISION(1) void signal4();
964
965 protected:
966     qreal m_p3;
967     qreal m_p4;
968 };
969
970 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
971 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
972 QML_DECLARE_TYPE(MyRevisionedClass)
973 QML_DECLARE_TYPE(MyRevisionedSubclass)
974 Q_DECLARE_METATYPE(MyQmlObject::MyType)
975
976
977 class ScarceResourceObject : public QObject
978 {
979     Q_OBJECT
980     Q_PROPERTY(QPixmap scarceResource READ scarceResource WRITE setScarceResource NOTIFY scarceResourceChanged)
981 public:
982     ScarceResourceObject(QObject *parent = 0) : QObject(parent), m_value(100, 100) { m_value.fill(Qt::blue); }
983     ~ScarceResourceObject() {}
984
985     QPixmap scarceResource() const { return m_value; }
986     void setScarceResource(QPixmap v) { m_value = v; emit scarceResourceChanged(); }
987
988     bool scarceResourceIsDetached() const { return m_value.isDetached(); }
989
990     // this particular one returns a new one each time
991     // this means that every Scarce Resource Copy will
992     // consume resources (so that we can track disposal
993     // of v8 handles with circular references).
994     Q_INVOKABLE QPixmap newScarceResource() const
995     {
996         QPixmap retn(800, 600);
997         retn.fill(QColor(100, 110, 120, 45));
998         return retn;
999     }
1000
1001 signals:
1002     void scarceResourceChanged();
1003
1004 private:
1005     QPixmap m_value;
1006 };
1007 QML_DECLARE_TYPE(ScarceResourceObject)
1008
1009 class testQObjectApi : public QObject
1010 {
1011     Q_OBJECT
1012     Q_ENUMS(MyEnum)
1013     Q_PROPERTY (int qobjectTestProperty READ qobjectTestProperty NOTIFY qobjectTestPropertyChanged)
1014     Q_PROPERTY (int qobjectTestWritableProperty READ qobjectTestWritableProperty WRITE setQObjectTestWritableProperty NOTIFY qobjectTestWritablePropertyChanged)
1015     Q_PROPERTY (int qobjectTestWritableFinalProperty READ qobjectTestWritableFinalProperty WRITE setQObjectTestWritableFinalProperty NOTIFY qobjectTestWritableFinalPropertyChanged FINAL)
1016
1017 public:
1018     testQObjectApi(QObject* parent = 0)
1019         : QObject(parent), m_testProperty(0), m_testWritableProperty(0), m_testWritableFinalProperty(0), m_methodCallCount(0), m_trackedObject(0)
1020     {
1021     }
1022
1023     ~testQObjectApi() {}
1024
1025     enum MyEnum { EnumValue1 = 25, EnumValue2 = 42 };
1026     Q_INVOKABLE int qobjectEnumTestMethod(MyEnum val) { return (static_cast<int>(val) + 5); }
1027     Q_INVOKABLE int qobjectTestMethod(int increment = 1) { m_methodCallCount += increment; return m_methodCallCount; }
1028
1029     Q_INVOKABLE void trackObject(QObject *obj) { m_trackedObject = obj; }
1030     Q_INVOKABLE QObject *trackedObject() const { return m_trackedObject; }
1031     Q_INVOKABLE void setTrackedObjectProperty(const QString &propName) const { m_trackedObject->setProperty(qPrintable(propName), QVariant(5)); }
1032     Q_INVOKABLE QVariant trackedObjectProperty(const QString &propName) const { return m_trackedObject->property(qPrintable(propName)); }
1033
1034     Q_INVOKABLE void setSpecificProperty(QObject *obj, const QString & propName, const QVariant & v) const { obj->setProperty(qPrintable(propName), v); }
1035     Q_INVOKABLE void changeQObjectParent(QObject *obj) { obj->setParent(this); }
1036
1037     int qobjectTestProperty() const { return m_testProperty; }
1038     void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); }
1039
1040     int qobjectTestWritableProperty() const { return m_testWritableProperty; }
1041     void setQObjectTestWritableProperty(int tp) { m_testWritableProperty = tp; emit qobjectTestWritablePropertyChanged(tp); }
1042
1043     int qobjectTestWritableFinalProperty() const { return m_testWritableFinalProperty; }
1044     void setQObjectTestWritableFinalProperty(int tp) { m_testWritableFinalProperty = tp; emit qobjectTestWritableFinalPropertyChanged(); }
1045
1046     Q_INVOKABLE bool trackedObjectHasJsOwnership() {
1047         QObject * object = m_trackedObject;
1048
1049         if (!object)
1050             return false;
1051
1052         QQmlData *ddata = QQmlData::get(object, false);
1053         if (!ddata)
1054             return false;
1055         else
1056             return ddata->indestructible?false:true;
1057     }
1058
1059     Q_INVOKABLE void deleteQObject(QObject *obj) { delete obj; }
1060
1061 signals:
1062     void qobjectTestPropertyChanged(int testProperty);
1063     void qobjectTestWritablePropertyChanged(int testWritableProperty);
1064     void qobjectTestWritableFinalPropertyChanged();
1065
1066 private:
1067     int m_testProperty;
1068     int m_testWritableProperty;
1069     int m_testWritableFinalProperty;
1070     int m_methodCallCount;
1071     QObject *m_trackedObject;
1072 };
1073
1074 class CircularReferenceObject : public QObject,
1075                                 public QV8GCCallback::Node
1076 {
1077     Q_OBJECT
1078
1079 public:
1080     CircularReferenceObject(QObject *parent = 0)
1081         : QObject(parent), QV8GCCallback::Node(callback), m_referenced(0), m_dtorCount(0)
1082     {
1083         QV8GCCallback::addGcCallbackNode(this);
1084     }
1085
1086     ~CircularReferenceObject()
1087     {
1088         if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1089     }
1090
1091     Q_INVOKABLE void setDtorCount(int *dtorCount)
1092     {
1093         m_dtorCount = dtorCount;
1094     }
1095
1096     Q_INVOKABLE CircularReferenceObject *generate(QObject *parent = 0)
1097     {
1098         CircularReferenceObject *retn = new CircularReferenceObject(parent);
1099         retn->m_dtorCount = m_dtorCount;
1100         retn->m_engine = m_engine;
1101         return retn;
1102     }
1103
1104     Q_INVOKABLE void addReference(QObject *other)
1105     {
1106         m_referenced = other;
1107     }
1108
1109     static void callback(QV8GCCallback::Node *n)
1110     {
1111         CircularReferenceObject *cro = static_cast<CircularReferenceObject*>(n);
1112         if (cro->m_referenced) {
1113             cro->m_engine->addRelationshipForGC(cro, cro->m_referenced);
1114         }
1115     }
1116
1117     void setEngine(QQmlEngine* declarativeEngine)
1118     {
1119         m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1120     }
1121
1122 private:
1123     QObject *m_referenced;
1124     int *m_dtorCount;
1125     QV8Engine* m_engine;
1126 };
1127 Q_DECLARE_METATYPE(CircularReferenceObject*)
1128
1129 class CircularReferenceHandle : public QObject,
1130                                 public QV8GCCallback::Node
1131 {
1132     Q_OBJECT
1133
1134 public:
1135     CircularReferenceHandle(QObject *parent = 0)
1136         : QObject(parent), QV8GCCallback::Node(gccallback), m_dtorCount(0), m_engine(0)
1137     {
1138         QV8GCCallback::addGcCallbackNode(this);
1139     }
1140
1141     ~CircularReferenceHandle()
1142     {
1143         if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1144     }
1145
1146     Q_INVOKABLE void setDtorCount(int *dtorCount)
1147     {
1148         m_dtorCount = dtorCount;
1149     }
1150
1151     Q_INVOKABLE CircularReferenceHandle *generate(QObject *parent = 0)
1152     {
1153         CircularReferenceHandle *retn = new CircularReferenceHandle(parent);
1154         retn->m_dtorCount = m_dtorCount;
1155         retn->m_engine = m_engine;
1156         return retn;
1157     }
1158
1159     Q_INVOKABLE void addReference(v8::Persistent<v8::Value> handle)
1160     {
1161         m_referenced = qPersistentNew(handle);
1162         m_referenced.MakeWeak(static_cast<void*>(this), wrcallback);
1163     }
1164
1165     static void wrcallback(v8::Persistent<v8::Value> handle, void *)
1166     {
1167         qPersistentDispose(handle);
1168     }
1169
1170     static void gccallback(QV8GCCallback::Node *n)
1171     {
1172         CircularReferenceHandle *crh = static_cast<CircularReferenceHandle*>(n);
1173         crh->m_engine->addRelationshipForGC(crh, crh->m_referenced);
1174     }
1175
1176     void setEngine(QQmlEngine* declarativeEngine)
1177     {
1178         m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1179     }
1180
1181 private:
1182     v8::Persistent<v8::Value> m_referenced;
1183     int *m_dtorCount;
1184     QV8Engine* m_engine;
1185 };
1186 Q_DECLARE_METATYPE(CircularReferenceHandle*)
1187
1188 class MyDynamicCreationDestructionObject : public QObject
1189 {
1190     Q_OBJECT
1191     Q_PROPERTY (int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
1192
1193 public:
1194     MyDynamicCreationDestructionObject(QObject *parent = 0) : QObject(parent), m_intProperty(0), m_dtorCount(0)
1195     {
1196     }
1197
1198     ~MyDynamicCreationDestructionObject()
1199     {
1200         if (m_dtorCount) {
1201             (*m_dtorCount)++;
1202         }
1203     }
1204
1205     int intProperty() const { return m_intProperty; }
1206     void setIntProperty(int val) { m_intProperty = val; emit intPropertyChanged(); }
1207
1208     Q_INVOKABLE MyDynamicCreationDestructionObject *createNew()
1209     {
1210         // no parent == ownership transfers to JS; same dtor counter.
1211         MyDynamicCreationDestructionObject *retn = new MyDynamicCreationDestructionObject;
1212         retn->setDtorCount(m_dtorCount);
1213         return retn;
1214     }
1215
1216     void setDtorCount(int *dtorCount)
1217     {
1218         m_dtorCount = dtorCount;
1219     }
1220
1221 signals:
1222     void intPropertyChanged();
1223
1224 private:
1225     int m_intProperty;
1226     int *m_dtorCount;
1227 };
1228
1229 class WriteCounter : public QObject
1230 {
1231     Q_OBJECT
1232     Q_PROPERTY(int value READ value WRITE setValue);
1233 public:
1234     WriteCounter() : m_value(0), m_count(0) {}
1235
1236     int value() const { return m_value; }
1237     void setValue(int v) { m_value = v; ++m_count; }
1238
1239     int count() const { return m_count; }
1240
1241 private:
1242     int m_value;
1243     int m_count;
1244 };
1245
1246 class MySequenceConversionObject : public QObject
1247 {
1248     Q_OBJECT
1249
1250     Q_PROPERTY (QList<int> intListProperty READ intListProperty WRITE setIntListProperty NOTIFY intListPropertyChanged)
1251     Q_PROPERTY (QList<int> intListProperty2 READ intListProperty2 WRITE setIntListProperty2 NOTIFY intListProperty2Changed)
1252     Q_PROPERTY (QList<qreal> qrealListProperty READ qrealListProperty WRITE setQrealListProperty NOTIFY qrealListPropertyChanged)
1253     Q_PROPERTY (QList<bool> boolListProperty READ boolListProperty WRITE setBoolListProperty NOTIFY boolListPropertyChanged)
1254     Q_PROPERTY (QList<QString> stringListProperty READ stringListProperty WRITE setStringListProperty NOTIFY stringListPropertyChanged)
1255     Q_PROPERTY (QList<QUrl> urlListProperty READ urlListProperty WRITE setUrlListProperty NOTIFY urlListPropertyChanged)
1256     Q_PROPERTY (QStringList qstringListProperty READ qstringListProperty WRITE setQStringListProperty NOTIFY qstringListPropertyChanged)
1257
1258     Q_PROPERTY (QList<QPoint> pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged)
1259     Q_PROPERTY (QList<QVariant> variantListProperty READ variantListProperty WRITE setVariantListProperty NOTIFY variantListPropertyChanged)
1260
1261     Q_PROPERTY (qint32 maxIndex READ maxIndex CONSTANT)
1262     Q_PROPERTY (quint32 tooBigIndex READ tooBigIndex CONSTANT)
1263     Q_PROPERTY (qint32 negativeIndex READ negativeIndex CONSTANT)
1264
1265 public:
1266     MySequenceConversionObject()
1267     {
1268         m_intList << 1 << 2 << 3 << 4;
1269         m_intList2 << 1 << 2 << 3 << 4;
1270         m_qrealList << 1.1 << 2.2 << 3.3 << 4.4;
1271         m_boolList << true << false << true << false;
1272         m_stringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1273         m_urlList << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com");
1274         m_qstringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1275
1276         m_pointList << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
1277         m_variantList << QVariant(QLatin1String("one")) << QVariant(true) << QVariant(3);
1278     }
1279
1280     ~MySequenceConversionObject() {}
1281
1282     qint32 maxIndex() const
1283     {
1284         return INT_MAX;
1285     }
1286     quint32 tooBigIndex() const
1287     {
1288         quint32 retn = 7;
1289         retn += INT_MAX;
1290         return retn;
1291     }
1292     qint32 negativeIndex() const
1293     {
1294         return -5;
1295     }
1296
1297     QList<int> intListProperty() const { return m_intList; }
1298     void setIntListProperty(const QList<int> &list) { m_intList = list; emit intListPropertyChanged(); }
1299     QList<int> intListProperty2() const { return m_intList2; }
1300     void setIntListProperty2(const QList<int> &list) { m_intList2 = list; emit intListProperty2Changed(); }
1301     QList<qreal> qrealListProperty() const { return m_qrealList; }
1302     void setQrealListProperty(const QList<qreal> &list) { m_qrealList = list; emit qrealListPropertyChanged(); }
1303     QList<bool> boolListProperty() const { return m_boolList; }
1304     void setBoolListProperty(const QList<bool> &list) { m_boolList = list; emit boolListPropertyChanged(); }
1305     QList<QString> stringListProperty() const { return m_stringList; }
1306     void setStringListProperty(const QList<QString> &list) { m_stringList = list; emit stringListPropertyChanged(); }
1307     QList<QUrl> urlListProperty() const { return m_urlList; }
1308     void setUrlListProperty(const QList<QUrl> &list) { m_urlList = list; emit urlListPropertyChanged(); }
1309     QStringList qstringListProperty() const { return m_qstringList; }
1310     void setQStringListProperty(const QStringList &list) { m_qstringList = list; emit qstringListPropertyChanged(); }
1311     QList<QPoint> pointListProperty() const { return m_pointList; }
1312     void setPointListProperty(const QList<QPoint> &list) { m_pointList = list; emit pointListPropertyChanged(); }
1313     QList<QVariant> variantListProperty() const { return m_variantList; }
1314     void setVariantListProperty(const QList<QVariant> &list) { m_variantList = list; emit variantListPropertyChanged(); }
1315
1316     // now for "copy resource" sequences:
1317     Q_INVOKABLE QList<int> generateIntSequence() const { QList<int> retn; retn << 1 << 2 << 3; return retn; }
1318     Q_INVOKABLE QList<qreal> generateQrealSequence() const { QList<qreal> retn; retn << 1.1 << 2.2 << 3.3; return retn; }
1319     Q_INVOKABLE QList<bool> generateBoolSequence() const { QList<bool> retn; retn << true << false << true; return retn; }
1320     Q_INVOKABLE QList<QString> generateStringSequence() const { QList<QString> retn; retn << "one" << "two" << "three"; return retn; }
1321     Q_INVOKABLE QList<QUrl> generateUrlSequence() const { QList<QUrl> retn; retn << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); return retn; }
1322     Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; }
1323
1324     // "reference resource" underlying qobject deletion test:
1325     Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; }
1326     Q_INVOKABLE void deleteTestObject(QObject *object) const { delete object; }
1327
1328 signals:
1329     void intListPropertyChanged();
1330     void intListProperty2Changed();
1331     void qrealListPropertyChanged();
1332     void boolListPropertyChanged();
1333     void stringListPropertyChanged();
1334     void urlListPropertyChanged();
1335     void qstringListPropertyChanged();
1336     void pointListPropertyChanged();
1337     void variantListPropertyChanged();
1338
1339 private:
1340     QList<int> m_intList;
1341     QList<int> m_intList2;
1342     QList<qreal> m_qrealList;
1343     QList<bool> m_boolList;
1344     QList<QString> m_stringList;
1345     QList<QUrl> m_urlList;
1346     QStringList m_qstringList;
1347
1348     QList<QPoint> m_pointList; // not a supported sequence type
1349     QList<QVariant> m_variantList; // not a supported sequence type, but QVariantList support is hardcoded.
1350 };
1351
1352 class MyDeleteObject : public QObject
1353 {
1354     Q_OBJECT
1355     Q_PROPERTY(QObject *nestedObject READ nestedObject NOTIFY nestedObjectChanged);
1356     Q_PROPERTY(int deleteNestedObject READ deleteNestedObject NOTIFY deleteNestedObjectChanged);
1357
1358 public:
1359     MyDeleteObject() : m_nestedObject(new MyQmlObject) {}
1360
1361     QObject *nestedObject() const { return m_nestedObject; }
1362     int deleteNestedObject() { delete m_nestedObject; m_nestedObject = 0; return 1; }
1363
1364 signals:
1365     void nestedObjectChanged();
1366     void deleteNestedObjectChanged();
1367
1368 private:
1369     MyQmlObject *m_nestedObject;
1370 };
1371
1372 class DateTimeExporter : public QObject
1373 {
1374     Q_OBJECT
1375
1376 public:
1377     DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC")
1378     {
1379         switch (m_datetime.timeSpec()) {
1380         case Qt::LocalTime:
1381             {
1382             QDateTime utc(m_datetime.toUTC());
1383             utc.setTimeSpec(Qt::LocalTime);
1384             m_offset = m_datetime.secsTo(utc) / 60;
1385             m_timespec = "LocalTime";
1386             }
1387             break;
1388         case Qt::OffsetFromUTC:
1389             m_offset = m_datetime.utcOffset() / 60;
1390             m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+')
1391                                            .arg(abs(m_offset) / 60)
1392                                            .arg(abs(m_offset) % 60);
1393         default:
1394             break;
1395         }
1396     }
1397
1398     Q_INVOKABLE QDate getDate() const { return m_datetime.date(); }
1399     Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; }
1400     Q_INVOKABLE int getDateTimeOffset() const { return m_offset; }
1401     Q_INVOKABLE QString getTimeSpec() const { return m_timespec; }
1402
1403 private:
1404     QDateTime m_datetime;
1405     int m_offset;
1406     QString m_timespec;
1407 };
1408
1409 class MyWorkerObject : public QObject
1410 {
1411     Q_OBJECT
1412
1413 public Q_SLOTS:
1414     void doIt();
1415
1416 Q_SIGNALS:
1417     void done(const QString &result);
1418 };
1419
1420 class MyUnregisteredEnumTypeObject : public QObject
1421 {
1422     Q_OBJECT
1423     Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
1424
1425 public:
1426     MyUnregisteredEnumTypeObject() : QObject(), m_ev(FirstValue) {}
1427     ~MyUnregisteredEnumTypeObject() {}
1428
1429     enum MyEnum {
1430         FirstValue = 1,
1431         SecondValue = 2
1432     };
1433
1434     MyEnum enumProperty() const { return m_ev; }
1435     void setEnumProperty(MyEnum v) { m_ev = v; }
1436
1437 private:
1438     MyEnum m_ev;
1439 };
1440
1441 void registerTypes();
1442
1443 #endif // TESTTYPES_H
1444