1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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>
64 #include <private/qqmlengine_p.h>
65 #include <private/qv8engine_p.h>
67 class MyQmlAttachedObject : public QObject
70 Q_PROPERTY(int value READ value CONSTANT)
71 Q_PROPERTY(int value2 READ value2 WRITE setValue2 NOTIFY value2Changed)
73 MyQmlAttachedObject(QObject *parent) : QObject(parent), m_value2(0) {}
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(); }
79 void emitMySignal() { emit mySignal(); }
89 class MyEnumContainer : public QObject
95 enum RelatedEnum { RelatedInvalid = -1, RelatedValue = 42, MultiplyDefined = 666 };
98 class MyQmlObject : public QObject
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)
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) {}
128 enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 };
129 enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3, EnumValue5 = -1 };
130 enum MyEnum3 { MultiplyDefined = 333 };
132 bool trueProperty() const { return true; }
133 bool falseProperty() const { return false; }
135 QString stringProperty() const { return m_string; }
136 void setStringProperty(const QString &s)
141 emit stringChanged();
144 QUrl urlProperty() const { return m_url; }
145 void setUrlProperty(const QUrl &url)
153 QObject *objectProperty() const { return m_object; }
154 void setObjectProperty(QObject *obj) {
158 emit objectChanged();
161 QQmlListProperty<QObject> objectListProperty() { return QQmlListProperty<QObject>(this, m_objectQList); }
163 bool methodCalled() const { return m_methodCalled; }
164 bool methodIntCalled() const { return m_methodIntCalled; }
166 QString string() const { return m_string; }
168 static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) {
169 return new MyQmlAttachedObject(o);
172 int deleteOnSet() const { return 1; }
173 void setDeleteOnSet(int v) { if(v) delete this; }
175 int value() const { return m_value; }
176 void setValue(int v) { m_value = v; }
178 int resettableProperty() const { return m_resetProperty; }
179 void setResettableProperty(int v) { m_resetProperty = v; }
180 void resetProperty() { m_resetProperty = 13; }
182 QRegExp regExp() { return m_regExp; }
183 void setRegExp(const QRegExp ®Exp) { m_regExp = regExp; }
185 int console() const { return 11; }
187 int nonscriptable() const { return 0; }
188 void setNonscriptable(int) {}
190 MyQmlObject *myinvokableObject;
191 Q_INVOKABLE MyQmlObject *returnme() { return this; }
199 QVariant variant() const { return m_variant; }
200 QJSValue qjsvalue() const { return m_qjsvalue; }
201 void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); }
202 void resetQJSValue() { m_qjsvalue = QJSValue(QLatin1String("Reset!")); emit qjsvalueChanged(); }
204 Qt::MouseButtons buttons() const { return m_buttons; }
206 int intProperty() const { return m_intProperty; }
207 void setIntProperty(int i) { m_intProperty = i; emit intChanged(); }
209 Q_INVOKABLE MyEnum2 getEnumValue() const { return EnumValue4; }
211 MyEnum enumPropertyValue;
212 MyEnum enumProperty() const {
213 return enumPropertyValue;
215 void setEnumProperty(MyEnum v) {
216 enumPropertyValue = v;
219 MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
220 MyEnumContainer::RelatedEnum relatedEnumProperty() const {
221 return relatedEnumPropertyValue;
223 void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
224 relatedEnumPropertyValue = v;
227 MyEnumContainer::RelatedEnum unrelatedEnumPropertyValue;
228 MyEnumContainer::RelatedEnum unrelatedEnumProperty() const {
229 return unrelatedEnumPropertyValue;
231 void setUnrelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
232 unrelatedEnumPropertyValue = v;
235 MyEnum qtEnumPropertyValue;
236 MyEnum qtEnumProperty() const {
237 return qtEnumPropertyValue;
239 void setQtEnumProperty(MyEnum v) {
240 qtEnumPropertyValue = v;
245 void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
246 void unnamedArgumentSignal(int a, qreal, QString c);
247 void stringChanged();
249 void objectChanged();
250 void anotherBasicSignal();
251 void thirdBasicSignal();
252 void signalWithUnknownType(const MyQmlObject::MyType &arg);
253 void signalWithCompletelyUnknownType(const MyQmlObject::MyOtherType &arg);
254 void signalWithVariant(const QVariant &arg);
255 void signalWithQJSValue(const QJSValue &arg);
256 void signalWithGlobalName(int parseInt);
258 void qjsvalueChanged();
261 void deleteMe() { delete this; }
262 void methodNoArgs() { m_methodCalled = true; }
263 void method(int a) { if(a == 163) m_methodIntCalled = true; }
264 void setString(const QString &s) { m_string = s; }
265 void myinvokable(MyQmlObject *o) { myinvokableObject = o; }
266 void variantMethod(const QVariant &v) { m_variant = v; }
267 void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; }
268 void v8function(QQmlV8Function*);
269 void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; }
272 friend class tst_qqmlecmascript;
274 bool m_methodIntCalled;
279 QList<QObject *> m_objectQList;
286 Qt::MouseButtons m_buttons;
289 QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
291 class MyQmlContainer : public QObject
294 Q_PROPERTY(QQmlListProperty<MyQmlObject> children READ children CONSTANT)
298 QQmlListProperty<MyQmlObject> children() { return QQmlListProperty<MyQmlObject>(this, m_children); }
301 QList<MyQmlObject*> m_children;
305 class MyExpression : public QQmlExpression
309 MyExpression(QQmlContext *ctxt, const QString &expr)
310 : QQmlExpression(ctxt, 0, expr), changed(false)
312 QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged()));
313 setNotifyOnValueChanged(true);
319 void expressionValueChanged() {
325 class MyDefaultObject1 : public QObject
328 Q_PROPERTY(int horseLegs READ horseLegs CONSTANT)
329 Q_PROPERTY(int antLegs READ antLegs CONSTANT)
330 Q_PROPERTY(int emuLegs READ emuLegs CONSTANT)
332 int horseLegs() const { return 4; }
333 int antLegs() const { return 6; }
334 int emuLegs() const { return 2; }
337 class MyDefaultObject3 : public QObject
340 Q_PROPERTY(int antLegs READ antLegs CONSTANT)
341 Q_PROPERTY(int humanLegs READ humanLegs CONSTANT)
343 int antLegs() const { return 7; } // Mutant
344 int humanLegs() const { return 2; }
345 int millipedeLegs() const { return 1000; }
348 class MyDeferredObject : public QObject
351 Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
352 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
353 Q_PROPERTY(QObject *objectProperty2 READ objectProperty2 WRITE setObjectProperty2)
354 Q_CLASSINFO("DeferredPropertyNames", "value,objectProperty,objectProperty2")
357 MyDeferredObject() : m_value(0), m_object(0), m_object2(0) {}
359 int value() const { return m_value; }
360 void setValue(int v) { m_value = v; emit valueChanged(); }
362 QObject *objectProperty() const { return m_object; }
363 void setObjectProperty(QObject *obj) { m_object = obj; }
365 QObject *objectProperty2() const { return m_object2; }
366 void setObjectProperty2(QObject *obj) { m_object2 = obj; }
377 class MyBaseExtendedObject : public QObject
380 Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)
382 MyBaseExtendedObject() : m_value(0) {}
384 int baseProperty() const { return m_value; }
385 void setBaseProperty(int v) { m_value = v; }
391 class MyExtendedObject : public MyBaseExtendedObject
394 Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty)
396 MyExtendedObject() : m_value(0) {}
398 int coreProperty() const { return m_value; }
399 void setCoreProperty(int v) { m_value = v; }
405 class MyTypeObject : public QObject
409 Q_ENUMS(MyEnumContainer::RelatedEnum)
412 Q_PROPERTY(QString id READ id WRITE setId)
413 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
414 Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty)
415 Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
416 Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
417 Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty)
418 Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
419 Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
420 Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
421 Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty)
422 Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
423 Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty)
424 Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty)
425 Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
426 Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
427 Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
428 Q_PROPERTY(QDateTime dateTimeProperty2 READ dateTimeProperty2 WRITE setDateTimeProperty2)
429 Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
430 Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
431 Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
432 Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty)
433 Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
434 Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2)
435 Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty)
436 Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
437 Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
438 Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
439 Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
441 Q_PROPERTY(QQmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
445 : objectPropertyValue(0), componentPropertyValue(0) {}
451 void setId(const QString &v) {
455 QObject *objectPropertyValue;
456 QObject *objectProperty() const {
457 return objectPropertyValue;
459 void setObjectProperty(QObject *v) {
460 objectPropertyValue = v;
463 QQmlComponent *componentPropertyValue;
464 QQmlComponent *componentProperty() const {
465 return componentPropertyValue;
467 void setComponentProperty(QQmlComponent *v) {
468 componentPropertyValue = v;
471 enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
472 Q_DECLARE_FLAGS(MyFlags, MyFlag)
473 MyFlags flagPropertyValue;
474 MyFlags flagProperty() const {
475 return flagPropertyValue;
477 void setFlagProperty(MyFlags v) {
478 flagPropertyValue = v;
481 enum MyEnum { EnumVal1, EnumVal2 };
482 MyEnum enumPropertyValue;
483 MyEnum enumProperty() const {
484 return enumPropertyValue;
486 void setEnumProperty(MyEnum v) {
487 enumPropertyValue = v;
490 MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
491 MyEnumContainer::RelatedEnum relatedEnumProperty() const {
492 return relatedEnumPropertyValue;
494 void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
495 relatedEnumPropertyValue = v;
498 QString stringPropertyValue;
499 QString stringProperty() const {
500 return stringPropertyValue;
502 void setStringProperty(const QString &v) {
503 stringPropertyValue = v;
506 uint uintPropertyValue;
507 uint uintProperty() const {
508 return uintPropertyValue;
510 void setUintProperty(const uint &v) {
511 uintPropertyValue = v;
514 int intPropertyValue;
515 int intProperty() const {
516 return intPropertyValue;
518 void setIntProperty(const int &v) {
519 intPropertyValue = v;
522 qreal realPropertyValue;
523 qreal realProperty() const {
524 return realPropertyValue;
526 void setRealProperty(const qreal &v) {
527 realPropertyValue = v;
530 double doublePropertyValue;
531 double doubleProperty() const {
532 return doublePropertyValue;
534 void setDoubleProperty(const double &v) {
535 doublePropertyValue = v;
538 float floatPropertyValue;
539 float floatProperty() const {
540 return floatPropertyValue;
542 void setFloatProperty(const float &v) {
543 floatPropertyValue = v;
546 QColor colorPropertyValue;
547 QColor colorProperty() const {
548 return colorPropertyValue;
550 void setColorProperty(const QColor &v) {
551 colorPropertyValue = v;
554 QDate datePropertyValue;
555 QDate dateProperty() const {
556 return datePropertyValue;
558 void setDateProperty(const QDate &v) {
559 datePropertyValue = v;
562 QTime timePropertyValue;
563 QTime timeProperty() const {
564 return timePropertyValue;
566 void setTimeProperty(const QTime &v) {
567 timePropertyValue = v;
570 QDateTime dateTimePropertyValue;
571 QDateTime dateTimeProperty() const {
572 return dateTimePropertyValue;
574 void setDateTimeProperty(const QDateTime &v) {
575 dateTimePropertyValue = v;
578 QDateTime dateTimePropertyValue2;
579 QDateTime dateTimeProperty2() const {
580 return dateTimePropertyValue2;
582 void setDateTimeProperty2(const QDateTime &v) {
583 dateTimePropertyValue2 = v;
586 QPoint pointPropertyValue;
587 QPoint pointProperty() const {
588 return pointPropertyValue;
590 void setPointProperty(const QPoint &v) {
591 pointPropertyValue = v;
594 QPointF pointFPropertyValue;
595 QPointF pointFProperty() const {
596 return pointFPropertyValue;
598 void setPointFProperty(const QPointF &v) {
599 pointFPropertyValue = v;
602 QSize sizePropertyValue;
603 QSize sizeProperty() const {
604 return sizePropertyValue;
606 void setSizeProperty(const QSize &v) {
607 sizePropertyValue = v;
610 QSizeF sizeFPropertyValue;
611 QSizeF sizeFProperty() const {
612 return sizeFPropertyValue;
614 void setSizeFProperty(const QSizeF &v) {
615 sizeFPropertyValue = v;
618 QRect rectPropertyValue;
619 QRect rectProperty() const {
620 return rectPropertyValue;
622 void setRectProperty(const QRect &v) {
623 rectPropertyValue = v;
624 emit rectPropertyChanged();
627 QRect rectPropertyValue2;
628 QRect rectProperty2() const {
629 return rectPropertyValue2;
631 void setRectProperty2(const QRect &v) {
632 rectPropertyValue2 = v;
635 QRectF rectFPropertyValue;
636 QRectF rectFProperty() const {
637 return rectFPropertyValue;
639 void setRectFProperty(const QRectF &v) {
640 rectFPropertyValue = v;
643 bool boolPropertyValue;
644 bool boolProperty() const {
645 return boolPropertyValue;
647 void setBoolProperty(const bool &v) {
648 boolPropertyValue = v;
651 QVariant variantPropertyValue;
652 QVariant variantProperty() const {
653 return variantPropertyValue;
655 void setVariantProperty(const QVariant &v) {
656 variantPropertyValue = v;
659 QVector3D vectorPropertyValue;
660 QVector3D vectorProperty() const {
661 return vectorPropertyValue;
663 void setVectorProperty(const QVector3D &v) {
664 vectorPropertyValue = v;
667 QUrl urlPropertyValue;
668 QUrl urlProperty() const {
669 return urlPropertyValue;
671 void setUrlProperty(const QUrl &v) {
672 urlPropertyValue = v;
675 QQmlScriptString scriptPropertyValue;
676 QQmlScriptString scriptProperty() const {
677 return scriptPropertyValue;
679 void setScriptProperty(const QQmlScriptString &v) {
680 scriptPropertyValue = v;
683 void doAction() { emit action(); }
686 void rectPropertyChanged();
688 Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
690 class MyDerivedObject : public MyTypeObject
694 Q_INVOKABLE bool intProperty() const {
699 Q_DECLARE_METATYPE(QJSValue);
700 class MyInvokableBaseObject : public QObject
704 inline ~MyInvokableBaseObject() = 0;
706 Q_INVOKABLE inline void method_inherited(int a);
707 Q_INVOKABLE inline void method_overload();
710 struct NonRegisteredType
715 class MyInvokableObject : public MyInvokableBaseObject
720 enum TestEnum { EnumValue1, EnumValue2 };
721 MyInvokableObject() { reset(); }
723 int invoked() const { return m_invoked; }
724 bool error() const { return m_invokedError; }
725 const QVariantList &actuals() const { return m_actuals; }
726 void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); }
728 Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); }
729 Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); }
731 Q_INVOKABLE void method_NoArgs() { invoke(0); }
732 Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
733 Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
734 Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
735 Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
736 Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
737 Q_INVOKABLE QJSValue method_NoArgs_QScriptValue() { invoke(6); return QJSValue("Hello world"); }
738 Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); }
740 Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; }
741 Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; }
742 Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; }
743 Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; }
744 Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; }
745 Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); }
746 Q_INVOKABLE void method_QScriptValue(QJSValue a) { invoke(14); m_actuals << qVariantFromValue(a); }
747 Q_INVOKABLE void method_intQScriptValue(int a, QJSValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); }
749 Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
750 Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
751 Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
753 Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
755 Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
757 Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
759 Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); }
760 Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); }
761 Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); }
763 Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); }
764 Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
765 Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
767 Q_INVOKABLE void method_unknown(NonRegisteredType) { invoke(28); }
770 friend class MyInvokableBaseObject;
771 void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
774 QVariantList m_actuals;
777 MyInvokableBaseObject::~MyInvokableBaseObject() {}
779 void MyInvokableBaseObject::method_inherited(int a)
781 static_cast<MyInvokableObject *>(this)->invoke(-3);
782 static_cast<MyInvokableObject *>(this)->m_actuals << a;
785 // This is a hidden overload of the MyInvokableObject::method_overload() method
786 void MyInvokableBaseObject::method_overload()
788 static_cast<MyInvokableObject *>(this)->invoke(-2);
791 class NumberAssignment : public QObject
795 Q_PROPERTY(qreal test1 READ test1 WRITE setTest1)
797 qreal test1() const { return _test1; }
798 void setTest1(qreal v) { _test1 = v; }
800 Q_PROPERTY(qreal test2 READ test2 WRITE setTest2)
802 qreal test2() const { return _test2; }
803 void setTest2(qreal v) { _test2 = v; }
805 Q_PROPERTY(qreal test3 READ test3 WRITE setTest3)
807 qreal test3() const { return _test3; }
808 void setTest3(qreal v) { _test3 = v; }
810 Q_PROPERTY(qreal test4 READ test4 WRITE setTest4)
812 qreal test4() const { return _test4; }
813 void setTest4(qreal v) { _test4 = v; }
815 Q_PROPERTY(int test5 READ test5 WRITE setTest5)
817 int test5() const { return _test5; }
818 void setTest5(int v) { _test5 = v; }
820 Q_PROPERTY(int test6 READ test6 WRITE setTest6)
822 int test6() const { return _test6; }
823 void setTest6(int v) { _test6 = v; }
825 Q_PROPERTY(int test7 READ test7 WRITE setTest7)
827 int test7() const { return _test7; }
828 void setTest7(int v) { _test7 = v; }
830 Q_PROPERTY(int test8 READ test8 WRITE setTest8)
832 int test8() const { return _test8; }
833 void setTest8(int v) { _test8 = v; }
835 Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9)
837 unsigned int test9() const { return _test9; }
838 void setTest9(unsigned int v) { _test9 = v; }
840 Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10)
841 unsigned int _test10;
842 unsigned int test10() const { return _test10; }
843 void setTest10(unsigned int v) { _test10 = v; }
845 Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11)
846 unsigned int _test11;
847 unsigned int test11() const { return _test11; }
848 void setTest11(unsigned int v) { _test11 = v; }
850 Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12)
851 unsigned int _test12;
852 unsigned int test12() const { return _test12; }
853 void setTest12(unsigned int v) { _test12 = v; }
856 class DefaultPropertyExtendedObject : public QObject
859 Q_PROPERTY(QObject *firstProperty READ firstProperty WRITE setFirstProperty)
860 Q_PROPERTY(QObject *secondProperty READ secondProperty WRITE setSecondProperty)
862 DefaultPropertyExtendedObject(QObject *parent = 0) : QObject(parent), m_firstProperty(0), m_secondProperty(0) {}
864 QObject *firstProperty() const { return m_firstProperty; }
865 QObject *secondProperty() const { return m_secondProperty; }
866 void setFirstProperty(QObject *property) { m_firstProperty = property; }
867 void setSecondProperty(QObject *property) { m_secondProperty = property; }
869 QObject* m_firstProperty;
870 QObject* m_secondProperty;
873 class OverrideDefaultPropertyObject : public DefaultPropertyExtendedObject
876 Q_CLASSINFO("DefaultProperty", "secondProperty")
878 OverrideDefaultPropertyObject() {}
881 class MyRevisionedBaseClassRegistered : public QObject
884 Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
885 Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
888 MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
890 qreal propA() const { return m_pa; }
891 void setPropA(qreal p) {
897 qreal propB() const { return m_pb; }
898 void setPropB(qreal p) {
905 Q_INVOKABLE void methodA() { }
906 Q_INVOKABLE Q_REVISION(1) void methodB() { }
913 Q_REVISION(1) void signalB();
920 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
923 Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
924 Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
927 MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
929 qreal propC() const { return m_pc; }
930 void setPropC(qreal p) {
936 qreal propD() const { return m_pd; }
937 void setPropD(qreal p) {
944 Q_INVOKABLE void methodC() { }
945 Q_INVOKABLE Q_REVISION(1) void methodD() { }
952 Q_REVISION(1) void signalD();
959 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
962 Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
963 Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
966 MyRevisionedClass() {}
968 qreal prop1() const { return m_p1; }
969 void setProp1(qreal p) {
975 qreal prop2() const { return m_p2; }
976 void setProp2(qreal p) {
983 Q_INVOKABLE void method1() { }
984 Q_INVOKABLE Q_REVISION(1) void method2() { }
991 Q_REVISION(1) void signal2();
998 class MyRevisionedSubclass : public MyRevisionedClass
1001 Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
1002 Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
1005 MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
1007 qreal prop3() const { return m_p3; }
1008 void setProp3(qreal p) {
1011 emit prop3Changed();
1014 qreal prop4() const { return m_p4; }
1015 void setProp4(qreal p) {
1018 emit prop4Changed();
1022 Q_INVOKABLE void method3() { }
1023 Q_INVOKABLE Q_REVISION(1) void method4() { }
1026 void prop3Changed();
1027 void prop4Changed();
1030 Q_REVISION(1) void signal4();
1037 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
1038 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
1039 QML_DECLARE_TYPE(MyRevisionedClass)
1040 QML_DECLARE_TYPE(MyRevisionedSubclass)
1041 Q_DECLARE_METATYPE(MyQmlObject::MyType)
1044 class ScarceResourceObject : public QObject
1047 Q_PROPERTY(QPixmap scarceResource READ scarceResource WRITE setScarceResource NOTIFY scarceResourceChanged)
1049 ScarceResourceObject(QObject *parent = 0) : QObject(parent), m_value(100, 100) { m_value.fill(Qt::blue); }
1050 ~ScarceResourceObject() {}
1052 QPixmap scarceResource() const { return m_value; }
1053 void setScarceResource(QPixmap v) { m_value = v; emit scarceResourceChanged(); }
1055 bool scarceResourceIsDetached() const { return m_value.isDetached(); }
1057 // this particular one returns a new one each time
1058 // this means that every Scarce Resource Copy will
1059 // consume resources (so that we can track disposal
1060 // of v8 handles with circular references).
1061 Q_INVOKABLE QPixmap newScarceResource() const
1063 QPixmap retn(800, 600);
1064 retn.fill(QColor(100, 110, 120, 45));
1069 void scarceResourceChanged();
1074 QML_DECLARE_TYPE(ScarceResourceObject)
1076 class testQObjectApi : public QObject
1080 Q_PROPERTY (int qobjectTestProperty READ qobjectTestProperty NOTIFY qobjectTestPropertyChanged)
1081 Q_PROPERTY (int qobjectTestWritableProperty READ qobjectTestWritableProperty WRITE setQObjectTestWritableProperty NOTIFY qobjectTestWritablePropertyChanged)
1082 Q_PROPERTY (int qobjectTestWritableFinalProperty READ qobjectTestWritableFinalProperty WRITE setQObjectTestWritableFinalProperty NOTIFY qobjectTestWritableFinalPropertyChanged FINAL)
1085 testQObjectApi(QObject* parent = 0)
1086 : QObject(parent), m_testProperty(0), m_testWritableProperty(0), m_testWritableFinalProperty(0), m_methodCallCount(0), m_trackedObject(0)
1090 ~testQObjectApi() {}
1092 enum MyEnum { EnumValue1 = 25, EnumValue2 = 42 };
1093 Q_INVOKABLE int qobjectEnumTestMethod(MyEnum val) { return (static_cast<int>(val) + 5); }
1094 Q_INVOKABLE int qobjectTestMethod(int increment = 1) { m_methodCallCount += increment; return m_methodCallCount; }
1096 Q_INVOKABLE void trackObject(QObject *obj) { m_trackedObject = obj; }
1097 Q_INVOKABLE QObject *trackedObject() const { return m_trackedObject; }
1098 Q_INVOKABLE void setTrackedObjectProperty(const QString &propName) const { m_trackedObject->setProperty(qPrintable(propName), QVariant(5)); }
1099 Q_INVOKABLE QVariant trackedObjectProperty(const QString &propName) const { return m_trackedObject->property(qPrintable(propName)); }
1101 Q_INVOKABLE void setSpecificProperty(QObject *obj, const QString & propName, const QVariant & v) const { obj->setProperty(qPrintable(propName), v); }
1102 Q_INVOKABLE void changeQObjectParent(QObject *obj) { obj->setParent(this); }
1104 int qobjectTestProperty() const { return m_testProperty; }
1105 void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); }
1107 int qobjectTestWritableProperty() const { return m_testWritableProperty; }
1108 void setQObjectTestWritableProperty(int tp) { m_testWritableProperty = tp; emit qobjectTestWritablePropertyChanged(tp); }
1110 int qobjectTestWritableFinalProperty() const { return m_testWritableFinalProperty; }
1111 void setQObjectTestWritableFinalProperty(int tp) { m_testWritableFinalProperty = tp; emit qobjectTestWritableFinalPropertyChanged(); }
1113 Q_INVOKABLE bool trackedObjectHasJsOwnership() {
1114 QObject * object = m_trackedObject;
1119 QQmlData *ddata = QQmlData::get(object, false);
1123 return ddata->indestructible?false:true;
1126 Q_INVOKABLE void deleteQObject(QObject *obj) { delete obj; }
1129 void qobjectTestPropertyChanged(int testProperty);
1130 void qobjectTestWritablePropertyChanged(int testWritableProperty);
1131 void qobjectTestWritableFinalPropertyChanged();
1135 int m_testWritableProperty;
1136 int m_testWritableFinalProperty;
1137 int m_methodCallCount;
1138 QObject *m_trackedObject;
1141 class testQObjectApiTwo : public QObject
1144 Q_PROPERTY(int twoTestProperty READ twoTestProperty WRITE setTwoTestProperty NOTIFY twoTestPropertyChanged)
1147 testQObjectApiTwo(QObject *parent = 0) : QObject(parent), m_ttp(42) {}
1148 ~testQObjectApiTwo() {}
1150 void setTwoTestProperty(int v) { m_ttp = v; emit twoTestPropertyChanged(); }
1151 int twoTestProperty() const { return m_ttp; }
1154 void twoTestPropertyChanged();
1160 class testImportOrderApi : public QObject
1165 testImportOrderApi(int value, QObject *parent = 0) : QObject(parent), m_value(value) {}
1167 Q_PROPERTY(int value READ value)
1169 int value() const { return m_value; }
1175 class CircularReferenceObject : public QObject,
1176 public QV8GCCallback::Node
1181 CircularReferenceObject(QObject *parent = 0)
1182 : QObject(parent), QV8GCCallback::Node(callback), m_referenced(0), m_dtorCount(0)
1184 QV8GCCallback::addGcCallbackNode(this);
1187 ~CircularReferenceObject()
1189 if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1192 Q_INVOKABLE void setDtorCount(int *dtorCount)
1194 m_dtorCount = dtorCount;
1197 Q_INVOKABLE CircularReferenceObject *generate(QObject *parent = 0)
1199 CircularReferenceObject *retn = new CircularReferenceObject(parent);
1200 retn->m_dtorCount = m_dtorCount;
1201 retn->m_engine = m_engine;
1205 Q_INVOKABLE void addReference(QObject *other)
1207 m_referenced = other;
1210 static void callback(QV8GCCallback::Node *n)
1212 CircularReferenceObject *cro = static_cast<CircularReferenceObject*>(n);
1213 if (cro->m_referenced) {
1214 cro->m_engine->addRelationshipForGC(cro, cro->m_referenced);
1218 void setEngine(QQmlEngine* declarativeEngine)
1220 m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1224 QObject *m_referenced;
1226 QV8Engine* m_engine;
1228 Q_DECLARE_METATYPE(CircularReferenceObject*)
1230 class CircularReferenceHandle : public QObject,
1231 public QV8GCCallback::Node
1236 CircularReferenceHandle(QObject *parent = 0)
1237 : QObject(parent), QV8GCCallback::Node(gccallback), m_dtorCount(0), m_engine(0)
1239 QV8GCCallback::addGcCallbackNode(this);
1242 ~CircularReferenceHandle()
1244 if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1247 Q_INVOKABLE void setDtorCount(int *dtorCount)
1249 m_dtorCount = dtorCount;
1252 Q_INVOKABLE CircularReferenceHandle *generate(QObject *parent = 0)
1254 CircularReferenceHandle *retn = new CircularReferenceHandle(parent);
1255 retn->m_dtorCount = m_dtorCount;
1256 retn->m_engine = m_engine;
1260 Q_INVOKABLE void addReference(v8::Persistent<v8::Value> handle)
1262 m_referenced = qPersistentNew(handle);
1263 m_referenced.MakeWeak(static_cast<void*>(this), wrcallback);
1266 static void wrcallback(v8::Persistent<v8::Value> handle, void *)
1268 qPersistentDispose(handle);
1271 static void gccallback(QV8GCCallback::Node *n)
1273 CircularReferenceHandle *crh = static_cast<CircularReferenceHandle*>(n);
1274 crh->m_engine->addRelationshipForGC(crh, crh->m_referenced);
1277 void setEngine(QQmlEngine* declarativeEngine)
1279 m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1283 v8::Persistent<v8::Value> m_referenced;
1285 QV8Engine* m_engine;
1287 Q_DECLARE_METATYPE(CircularReferenceHandle*)
1289 class MyDynamicCreationDestructionObject : public QObject
1292 Q_PROPERTY (int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
1295 MyDynamicCreationDestructionObject(QObject *parent = 0) : QObject(parent), m_intProperty(0), m_dtorCount(0)
1299 ~MyDynamicCreationDestructionObject()
1306 int intProperty() const { return m_intProperty; }
1307 void setIntProperty(int val) { m_intProperty = val; emit intPropertyChanged(); }
1309 Q_INVOKABLE MyDynamicCreationDestructionObject *createNew()
1311 // no parent == ownership transfers to JS; same dtor counter.
1312 MyDynamicCreationDestructionObject *retn = new MyDynamicCreationDestructionObject;
1313 retn->setDtorCount(m_dtorCount);
1317 void setDtorCount(int *dtorCount)
1319 m_dtorCount = dtorCount;
1323 void intPropertyChanged();
1330 class WriteCounter : public QObject
1333 Q_PROPERTY(int value READ value WRITE setValue);
1335 WriteCounter() : m_value(0), m_count(0) {}
1337 int value() const { return m_value; }
1338 void setValue(int v) { m_value = v; ++m_count; }
1340 int count() const { return m_count; }
1347 class MySequenceConversionObject : public QObject
1351 Q_PROPERTY (QList<int> intListProperty READ intListProperty WRITE setIntListProperty NOTIFY intListPropertyChanged)
1352 Q_PROPERTY (QList<int> intListProperty2 READ intListProperty2 WRITE setIntListProperty2 NOTIFY intListProperty2Changed)
1353 Q_PROPERTY (QList<qreal> qrealListProperty READ qrealListProperty WRITE setQrealListProperty NOTIFY qrealListPropertyChanged)
1354 Q_PROPERTY (QList<bool> boolListProperty READ boolListProperty WRITE setBoolListProperty NOTIFY boolListPropertyChanged)
1355 Q_PROPERTY (QList<QString> stringListProperty READ stringListProperty WRITE setStringListProperty NOTIFY stringListPropertyChanged)
1356 Q_PROPERTY (QList<QUrl> urlListProperty READ urlListProperty WRITE setUrlListProperty NOTIFY urlListPropertyChanged)
1357 Q_PROPERTY (QStringList qstringListProperty READ qstringListProperty WRITE setQStringListProperty NOTIFY qstringListPropertyChanged)
1359 Q_PROPERTY (QList<QPoint> pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged)
1360 Q_PROPERTY (QList<NonRegisteredType> typeListProperty READ typeListProperty WRITE setTypeListProperty NOTIFY typeListPropertyChanged)
1361 Q_PROPERTY (QList<QVariant> variantListProperty READ variantListProperty WRITE setVariantListProperty NOTIFY variantListPropertyChanged)
1363 Q_PROPERTY (qint32 maxIndex READ maxIndex CONSTANT)
1364 Q_PROPERTY (quint32 tooBigIndex READ tooBigIndex CONSTANT)
1365 Q_PROPERTY (qint32 negativeIndex READ negativeIndex CONSTANT)
1368 MySequenceConversionObject()
1370 m_intList << 1 << 2 << 3 << 4;
1371 m_intList2 << 1 << 2 << 3 << 4;
1372 m_qrealList << 1.1 << 2.2 << 3.3 << 4.4;
1373 m_boolList << true << false << true << false;
1374 m_stringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1375 m_urlList << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com");
1376 m_qstringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1378 m_pointList << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
1379 m_variantList << QVariant(QLatin1String("one")) << QVariant(true) << QVariant(3);
1382 ~MySequenceConversionObject() {}
1384 qint32 maxIndex() const
1388 quint32 tooBigIndex() const
1394 qint32 negativeIndex() const
1399 QList<int> intListProperty() const { return m_intList; }
1400 void setIntListProperty(const QList<int> &list) { m_intList = list; emit intListPropertyChanged(); }
1401 QList<int> intListProperty2() const { return m_intList2; }
1402 void setIntListProperty2(const QList<int> &list) { m_intList2 = list; emit intListProperty2Changed(); }
1403 QList<qreal> qrealListProperty() const { return m_qrealList; }
1404 void setQrealListProperty(const QList<qreal> &list) { m_qrealList = list; emit qrealListPropertyChanged(); }
1405 QList<bool> boolListProperty() const { return m_boolList; }
1406 void setBoolListProperty(const QList<bool> &list) { m_boolList = list; emit boolListPropertyChanged(); }
1407 QList<QString> stringListProperty() const { return m_stringList; }
1408 void setStringListProperty(const QList<QString> &list) { m_stringList = list; emit stringListPropertyChanged(); }
1409 QList<QUrl> urlListProperty() const { return m_urlList; }
1410 void setUrlListProperty(const QList<QUrl> &list) { m_urlList = list; emit urlListPropertyChanged(); }
1411 QStringList qstringListProperty() const { return m_qstringList; }
1412 void setQStringListProperty(const QStringList &list) { m_qstringList = list; emit qstringListPropertyChanged(); }
1413 QList<QPoint> pointListProperty() const { return m_pointList; }
1414 void setPointListProperty(const QList<QPoint> &list) { m_pointList = list; emit pointListPropertyChanged(); }
1415 QList<NonRegisteredType> typeListProperty() const { return m_typeList; }
1416 void setTypeListProperty(const QList<NonRegisteredType> &list) { m_typeList = list; emit typeListPropertyChanged(); }
1417 QList<QVariant> variantListProperty() const { return m_variantList; }
1418 void setVariantListProperty(const QList<QVariant> &list) { m_variantList = list; emit variantListPropertyChanged(); }
1420 // now for "copy resource" sequences:
1421 Q_INVOKABLE QList<int> generateIntSequence() const { QList<int> retn; retn << 1 << 2 << 3; return retn; }
1422 Q_INVOKABLE QList<qreal> generateQrealSequence() const { QList<qreal> retn; retn << 1.1 << 2.2 << 3.3; return retn; }
1423 Q_INVOKABLE QList<bool> generateBoolSequence() const { QList<bool> retn; retn << true << false << true; return retn; }
1424 Q_INVOKABLE QList<QString> generateStringSequence() const { QList<QString> retn; retn << "one" << "two" << "three"; return retn; }
1425 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; }
1426 Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; }
1427 Q_INVOKABLE bool parameterEqualsGeneratedIntSequence(const QList<int>& param) const { return (param == generateIntSequence()); }
1429 // "reference resource" underlying qobject deletion test:
1430 Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; }
1431 Q_INVOKABLE void deleteTestObject(QObject *object) const { delete object; }
1434 void intListPropertyChanged();
1435 void intListProperty2Changed();
1436 void qrealListPropertyChanged();
1437 void boolListPropertyChanged();
1438 void stringListPropertyChanged();
1439 void urlListPropertyChanged();
1440 void qstringListPropertyChanged();
1441 void pointListPropertyChanged();
1442 void typeListPropertyChanged();
1443 void variantListPropertyChanged();
1446 QList<int> m_intList;
1447 QList<int> m_intList2;
1448 QList<qreal> m_qrealList;
1449 QList<bool> m_boolList;
1450 QList<QString> m_stringList;
1451 QList<QUrl> m_urlList;
1452 QStringList m_qstringList;
1454 QList<QPoint> m_pointList;
1455 QList<NonRegisteredType> m_typeList; // not a supported sequence type
1456 QList<QVariant> m_variantList; // not a supported sequence type, but QVariantList support is hardcoded.
1459 class MyDeleteObject : public QObject
1462 Q_PROPERTY(QObject *nestedObject READ nestedObject NOTIFY nestedObjectChanged);
1463 Q_PROPERTY(int deleteNestedObject READ deleteNestedObject NOTIFY deleteNestedObjectChanged);
1466 MyDeleteObject() : m_nestedObject(new MyQmlObject) {}
1468 QObject *nestedObject() const { return m_nestedObject; }
1469 int deleteNestedObject() { delete m_nestedObject; m_nestedObject = 0; return 1; }
1472 void nestedObjectChanged();
1473 void deleteNestedObjectChanged();
1476 MyQmlObject *m_nestedObject;
1479 class DateTimeExporter : public QObject
1484 DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC")
1486 switch (m_datetime.timeSpec()) {
1489 QDateTime utc(m_datetime.toUTC());
1490 utc.setTimeSpec(Qt::LocalTime);
1491 m_offset = m_datetime.secsTo(utc) / 60;
1492 m_timespec = "LocalTime";
1495 case Qt::OffsetFromUTC:
1496 m_offset = m_datetime.utcOffset() / 60;
1497 m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+')
1498 .arg(abs(m_offset) / 60)
1499 .arg(abs(m_offset) % 60);
1505 Q_INVOKABLE QDate getDate() const { return m_datetime.date(); }
1506 Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; }
1507 Q_INVOKABLE int getDateTimeOffset() const { return m_offset; }
1508 Q_INVOKABLE QString getTimeSpec() const { return m_timespec; }
1511 QDateTime m_datetime;
1516 class MyWorkerObject : public QObject
1524 void done(const QString &result);
1527 class MyUnregisteredEnumTypeObject : public QObject
1530 Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
1533 MyUnregisteredEnumTypeObject() : QObject(), m_ev(FirstValue) {}
1534 ~MyUnregisteredEnumTypeObject() {}
1541 MyEnum enumProperty() const { return m_ev; }
1542 void setEnumProperty(MyEnum v) { m_ev = v; }
1548 class FallbackBindingsObject : public QObject
1551 Q_PROPERTY (int test READ test NOTIFY testChanged)
1553 FallbackBindingsObject(QObject* parent = 0)
1554 : QObject(parent), m_test(100)
1558 int test() const { return m_test; }
1567 class FallbackBindingsDerived : public FallbackBindingsObject
1570 Q_PROPERTY (QString test READ test NOTIFY testChanged)
1572 FallbackBindingsDerived(QObject* parent = 0)
1573 : FallbackBindingsObject(parent), m_test("hello")
1577 QString test() const { return m_test; }
1586 class FallbackBindingsAttachedObject : public QObject
1589 Q_PROPERTY (int test READ test NOTIFY testChanged)
1591 FallbackBindingsAttachedObject(QObject *parent) : QObject(parent), m_test(100) {}
1593 int test() const { return m_test; }
1602 class FallbackBindingsAttachedDerived : public FallbackBindingsAttachedObject
1605 Q_PROPERTY (QString test READ test NOTIFY testChanged)
1607 FallbackBindingsAttachedDerived(QObject* parent = 0)
1608 : FallbackBindingsAttachedObject(parent), m_test("hello")
1612 QString test() const { return m_test; }
1621 class FallbackBindingsTypeObject : public QObject
1625 FallbackBindingsTypeObject() : QObject() {}
1627 static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
1628 return new FallbackBindingsAttachedObject(o);
1632 class FallbackBindingsTypeDerived : public QObject
1636 FallbackBindingsTypeDerived() : QObject() {}
1638 static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
1639 return new FallbackBindingsAttachedDerived(o);
1643 QML_DECLARE_TYPEINFO(FallbackBindingsTypeObject, QML_HAS_ATTACHED_PROPERTIES)
1644 QML_DECLARE_TYPEINFO(FallbackBindingsTypeDerived, QML_HAS_ATTACHED_PROPERTIES)
1646 void registerTypes();
1648 #endif // TESTTYPES_H