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