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