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