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