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; }
196 QVariant variant() const { return m_variant; }
197 QJSValue qjsvalue() const { return m_qjsvalue; }
198 void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); }
199 void resetQJSValue() { m_qjsvalue = QJSValue(QLatin1String("Reset!")); emit qjsvalueChanged(); }
201 Qt::MouseButtons buttons() const { return m_buttons; }
203 int intProperty() const { return m_intProperty; }
204 void setIntProperty(int i) { m_intProperty = i; emit intChanged(); }
206 Q_INVOKABLE MyEnum2 getEnumValue() const { return EnumValue4; }
208 MyEnum enumPropertyValue;
209 MyEnum enumProperty() const {
210 return enumPropertyValue;
212 void setEnumProperty(MyEnum v) {
213 enumPropertyValue = v;
216 MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
217 MyEnumContainer::RelatedEnum relatedEnumProperty() const {
218 return relatedEnumPropertyValue;
220 void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
221 relatedEnumPropertyValue = v;
224 MyEnumContainer::RelatedEnum unrelatedEnumPropertyValue;
225 MyEnumContainer::RelatedEnum unrelatedEnumProperty() const {
226 return unrelatedEnumPropertyValue;
228 void setUnrelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
229 unrelatedEnumPropertyValue = v;
232 MyEnum qtEnumPropertyValue;
233 MyEnum qtEnumProperty() const {
234 return qtEnumPropertyValue;
236 void setQtEnumProperty(MyEnum v) {
237 qtEnumPropertyValue = v;
242 void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
243 void unnamedArgumentSignal(int a, qreal, QString c);
244 void stringChanged();
246 void objectChanged();
247 void anotherBasicSignal();
248 void thirdBasicSignal();
249 void signalWithUnknownType(const MyQmlObject::MyType &arg);
250 void signalWithVariant(const QVariant &arg);
251 void signalWithQJSValue(const QJSValue &arg);
252 void signalWithGlobalName(int parseInt);
254 void qjsvalueChanged();
257 void deleteMe() { delete this; }
258 void methodNoArgs() { m_methodCalled = true; }
259 void method(int a) { if(a == 163) m_methodIntCalled = true; }
260 void setString(const QString &s) { m_string = s; }
261 void myinvokable(MyQmlObject *o) { myinvokableObject = o; }
262 void variantMethod(const QVariant &v) { m_variant = v; }
263 void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; }
264 void v8function(QQmlV8Function*);
265 void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; }
268 friend class tst_qqmlecmascript;
270 bool m_methodIntCalled;
275 QList<QObject *> m_objectQList;
282 Qt::MouseButtons m_buttons;
285 QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
287 class MyQmlContainer : public QObject
290 Q_PROPERTY(QQmlListProperty<MyQmlObject> children READ children CONSTANT)
294 QQmlListProperty<MyQmlObject> children() { return QQmlListProperty<MyQmlObject>(this, m_children); }
297 QList<MyQmlObject*> m_children;
301 class MyExpression : public QQmlExpression
305 MyExpression(QQmlContext *ctxt, const QString &expr)
306 : QQmlExpression(ctxt, 0, expr), changed(false)
308 QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged()));
309 setNotifyOnValueChanged(true);
315 void expressionValueChanged() {
321 class MyDefaultObject1 : public QObject
324 Q_PROPERTY(int horseLegs READ horseLegs CONSTANT)
325 Q_PROPERTY(int antLegs READ antLegs CONSTANT)
326 Q_PROPERTY(int emuLegs READ emuLegs CONSTANT)
328 int horseLegs() const { return 4; }
329 int antLegs() const { return 6; }
330 int emuLegs() const { return 2; }
333 class MyDefaultObject3 : public QObject
336 Q_PROPERTY(int antLegs READ antLegs CONSTANT)
337 Q_PROPERTY(int humanLegs READ humanLegs CONSTANT)
339 int antLegs() const { return 7; } // Mutant
340 int humanLegs() const { return 2; }
341 int millipedeLegs() const { return 1000; }
344 class MyDeferredObject : public QObject
347 Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
348 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
349 Q_PROPERTY(QObject *objectProperty2 READ objectProperty2 WRITE setObjectProperty2)
350 Q_CLASSINFO("DeferredPropertyNames", "value,objectProperty,objectProperty2")
353 MyDeferredObject() : m_value(0), m_object(0), m_object2(0) {}
355 int value() const { return m_value; }
356 void setValue(int v) { m_value = v; emit valueChanged(); }
358 QObject *objectProperty() const { return m_object; }
359 void setObjectProperty(QObject *obj) { m_object = obj; }
361 QObject *objectProperty2() const { return m_object2; }
362 void setObjectProperty2(QObject *obj) { m_object2 = obj; }
373 class MyBaseExtendedObject : public QObject
376 Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)
378 MyBaseExtendedObject() : m_value(0) {}
380 int baseProperty() const { return m_value; }
381 void setBaseProperty(int v) { m_value = v; }
387 class MyExtendedObject : public MyBaseExtendedObject
390 Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty)
392 MyExtendedObject() : m_value(0) {}
394 int coreProperty() const { return m_value; }
395 void setCoreProperty(int v) { m_value = v; }
401 class MyTypeObject : public QObject
405 Q_ENUMS(MyEnumContainer::RelatedEnum)
408 Q_PROPERTY(QString id READ id WRITE setId)
409 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
410 Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty)
411 Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
412 Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
413 Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty)
414 Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
415 Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
416 Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
417 Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty)
418 Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
419 Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty)
420 Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty)
421 Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
422 Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
423 Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
424 Q_PROPERTY(QDateTime dateTimeProperty2 READ dateTimeProperty2 WRITE setDateTimeProperty2)
425 Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
426 Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
427 Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
428 Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty)
429 Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
430 Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2)
431 Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty)
432 Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
433 Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
434 Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
435 Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
437 Q_PROPERTY(QQmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
441 : objectPropertyValue(0), componentPropertyValue(0) {}
447 void setId(const QString &v) {
451 QObject *objectPropertyValue;
452 QObject *objectProperty() const {
453 return objectPropertyValue;
455 void setObjectProperty(QObject *v) {
456 objectPropertyValue = v;
459 QQmlComponent *componentPropertyValue;
460 QQmlComponent *componentProperty() const {
461 return componentPropertyValue;
463 void setComponentProperty(QQmlComponent *v) {
464 componentPropertyValue = v;
467 enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
468 Q_DECLARE_FLAGS(MyFlags, MyFlag)
469 MyFlags flagPropertyValue;
470 MyFlags flagProperty() const {
471 return flagPropertyValue;
473 void setFlagProperty(MyFlags v) {
474 flagPropertyValue = v;
477 enum MyEnum { EnumVal1, EnumVal2 };
478 MyEnum enumPropertyValue;
479 MyEnum enumProperty() const {
480 return enumPropertyValue;
482 void setEnumProperty(MyEnum v) {
483 enumPropertyValue = v;
486 MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
487 MyEnumContainer::RelatedEnum relatedEnumProperty() const {
488 return relatedEnumPropertyValue;
490 void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
491 relatedEnumPropertyValue = v;
494 QString stringPropertyValue;
495 QString stringProperty() const {
496 return stringPropertyValue;
498 void setStringProperty(const QString &v) {
499 stringPropertyValue = v;
502 uint uintPropertyValue;
503 uint uintProperty() const {
504 return uintPropertyValue;
506 void setUintProperty(const uint &v) {
507 uintPropertyValue = v;
510 int intPropertyValue;
511 int intProperty() const {
512 return intPropertyValue;
514 void setIntProperty(const int &v) {
515 intPropertyValue = v;
518 qreal realPropertyValue;
519 qreal realProperty() const {
520 return realPropertyValue;
522 void setRealProperty(const qreal &v) {
523 realPropertyValue = v;
526 double doublePropertyValue;
527 double doubleProperty() const {
528 return doublePropertyValue;
530 void setDoubleProperty(const double &v) {
531 doublePropertyValue = v;
534 float floatPropertyValue;
535 float floatProperty() const {
536 return floatPropertyValue;
538 void setFloatProperty(const float &v) {
539 floatPropertyValue = v;
542 QColor colorPropertyValue;
543 QColor colorProperty() const {
544 return colorPropertyValue;
546 void setColorProperty(const QColor &v) {
547 colorPropertyValue = v;
550 QDate datePropertyValue;
551 QDate dateProperty() const {
552 return datePropertyValue;
554 void setDateProperty(const QDate &v) {
555 datePropertyValue = v;
558 QTime timePropertyValue;
559 QTime timeProperty() const {
560 return timePropertyValue;
562 void setTimeProperty(const QTime &v) {
563 timePropertyValue = v;
566 QDateTime dateTimePropertyValue;
567 QDateTime dateTimeProperty() const {
568 return dateTimePropertyValue;
570 void setDateTimeProperty(const QDateTime &v) {
571 dateTimePropertyValue = v;
574 QDateTime dateTimePropertyValue2;
575 QDateTime dateTimeProperty2() const {
576 return dateTimePropertyValue2;
578 void setDateTimeProperty2(const QDateTime &v) {
579 dateTimePropertyValue2 = v;
582 QPoint pointPropertyValue;
583 QPoint pointProperty() const {
584 return pointPropertyValue;
586 void setPointProperty(const QPoint &v) {
587 pointPropertyValue = v;
590 QPointF pointFPropertyValue;
591 QPointF pointFProperty() const {
592 return pointFPropertyValue;
594 void setPointFProperty(const QPointF &v) {
595 pointFPropertyValue = v;
598 QSize sizePropertyValue;
599 QSize sizeProperty() const {
600 return sizePropertyValue;
602 void setSizeProperty(const QSize &v) {
603 sizePropertyValue = v;
606 QSizeF sizeFPropertyValue;
607 QSizeF sizeFProperty() const {
608 return sizeFPropertyValue;
610 void setSizeFProperty(const QSizeF &v) {
611 sizeFPropertyValue = v;
614 QRect rectPropertyValue;
615 QRect rectProperty() const {
616 return rectPropertyValue;
618 void setRectProperty(const QRect &v) {
619 rectPropertyValue = v;
620 emit rectPropertyChanged();
623 QRect rectPropertyValue2;
624 QRect rectProperty2() const {
625 return rectPropertyValue2;
627 void setRectProperty2(const QRect &v) {
628 rectPropertyValue2 = v;
631 QRectF rectFPropertyValue;
632 QRectF rectFProperty() const {
633 return rectFPropertyValue;
635 void setRectFProperty(const QRectF &v) {
636 rectFPropertyValue = v;
639 bool boolPropertyValue;
640 bool boolProperty() const {
641 return boolPropertyValue;
643 void setBoolProperty(const bool &v) {
644 boolPropertyValue = v;
647 QVariant variantPropertyValue;
648 QVariant variantProperty() const {
649 return variantPropertyValue;
651 void setVariantProperty(const QVariant &v) {
652 variantPropertyValue = v;
655 QVector3D vectorPropertyValue;
656 QVector3D vectorProperty() const {
657 return vectorPropertyValue;
659 void setVectorProperty(const QVector3D &v) {
660 vectorPropertyValue = v;
663 QUrl urlPropertyValue;
664 QUrl urlProperty() const {
665 return urlPropertyValue;
667 void setUrlProperty(const QUrl &v) {
668 urlPropertyValue = v;
671 QQmlScriptString scriptPropertyValue;
672 QQmlScriptString scriptProperty() const {
673 return scriptPropertyValue;
675 void setScriptProperty(const QQmlScriptString &v) {
676 scriptPropertyValue = v;
679 void doAction() { emit action(); }
682 void rectPropertyChanged();
684 Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
686 class MyDerivedObject : public MyTypeObject
690 Q_INVOKABLE bool intProperty() const {
695 Q_DECLARE_METATYPE(QJSValue);
696 class MyInvokableBaseObject : public QObject
700 inline ~MyInvokableBaseObject() = 0;
702 Q_INVOKABLE inline void method_inherited(int a);
703 Q_INVOKABLE inline void method_overload();
706 class MyInvokableObject : public MyInvokableBaseObject
711 enum TestEnum { EnumValue1, EnumValue2 };
712 MyInvokableObject() { reset(); }
714 int invoked() const { return m_invoked; }
715 bool error() const { return m_invokedError; }
716 const QVariantList &actuals() const { return m_actuals; }
717 void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); }
719 Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); }
720 Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); }
722 Q_INVOKABLE void method_NoArgs() { invoke(0); }
723 Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
724 Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
725 Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
726 Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
727 Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
728 Q_INVOKABLE QJSValue method_NoArgs_QScriptValue() { invoke(6); return QJSValue("Hello world"); }
729 Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); }
731 Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; }
732 Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; }
733 Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; }
734 Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; }
735 Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; }
736 Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); }
737 Q_INVOKABLE void method_QScriptValue(QJSValue a) { invoke(14); m_actuals << qVariantFromValue(a); }
738 Q_INVOKABLE void method_intQScriptValue(int a, QJSValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); }
740 Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
741 Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
742 Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
744 Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
746 Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
748 Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
750 Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); }
751 Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); }
752 Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); }
754 Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); }
755 Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
756 Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
758 Q_INVOKABLE void method_unknown(MyInvokableObject *) { invoke(28); }
761 friend class MyInvokableBaseObject;
762 void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
765 QVariantList m_actuals;
768 MyInvokableBaseObject::~MyInvokableBaseObject() {}
770 void MyInvokableBaseObject::method_inherited(int a)
772 static_cast<MyInvokableObject *>(this)->invoke(-3);
773 static_cast<MyInvokableObject *>(this)->m_actuals << a;
776 // This is a hidden overload of the MyInvokableObject::method_overload() method
777 void MyInvokableBaseObject::method_overload()
779 static_cast<MyInvokableObject *>(this)->invoke(-2);
782 class NumberAssignment : public QObject
786 Q_PROPERTY(qreal test1 READ test1 WRITE setTest1)
788 qreal test1() const { return _test1; }
789 void setTest1(qreal v) { _test1 = v; }
791 Q_PROPERTY(qreal test2 READ test2 WRITE setTest2)
793 qreal test2() const { return _test2; }
794 void setTest2(qreal v) { _test2 = v; }
796 Q_PROPERTY(qreal test3 READ test3 WRITE setTest3)
798 qreal test3() const { return _test3; }
799 void setTest3(qreal v) { _test3 = v; }
801 Q_PROPERTY(qreal test4 READ test4 WRITE setTest4)
803 qreal test4() const { return _test4; }
804 void setTest4(qreal v) { _test4 = v; }
806 Q_PROPERTY(int test5 READ test5 WRITE setTest5)
808 int test5() const { return _test5; }
809 void setTest5(int v) { _test5 = v; }
811 Q_PROPERTY(int test6 READ test6 WRITE setTest6)
813 int test6() const { return _test6; }
814 void setTest6(int v) { _test6 = v; }
816 Q_PROPERTY(int test7 READ test7 WRITE setTest7)
818 int test7() const { return _test7; }
819 void setTest7(int v) { _test7 = v; }
821 Q_PROPERTY(int test8 READ test8 WRITE setTest8)
823 int test8() const { return _test8; }
824 void setTest8(int v) { _test8 = v; }
826 Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9)
828 unsigned int test9() const { return _test9; }
829 void setTest9(unsigned int v) { _test9 = v; }
831 Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10)
832 unsigned int _test10;
833 unsigned int test10() const { return _test10; }
834 void setTest10(unsigned int v) { _test10 = v; }
836 Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11)
837 unsigned int _test11;
838 unsigned int test11() const { return _test11; }
839 void setTest11(unsigned int v) { _test11 = v; }
841 Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12)
842 unsigned int _test12;
843 unsigned int test12() const { return _test12; }
844 void setTest12(unsigned int v) { _test12 = v; }
847 class DefaultPropertyExtendedObject : public QObject
850 Q_PROPERTY(QObject *firstProperty READ firstProperty WRITE setFirstProperty)
851 Q_PROPERTY(QObject *secondProperty READ secondProperty WRITE setSecondProperty)
853 DefaultPropertyExtendedObject(QObject *parent = 0) : QObject(parent), m_firstProperty(0), m_secondProperty(0) {}
855 QObject *firstProperty() const { return m_firstProperty; }
856 QObject *secondProperty() const { return m_secondProperty; }
857 void setFirstProperty(QObject *property) { m_firstProperty = property; }
858 void setSecondProperty(QObject *property) { m_secondProperty = property; }
860 QObject* m_firstProperty;
861 QObject* m_secondProperty;
864 class OverrideDefaultPropertyObject : public DefaultPropertyExtendedObject
867 Q_CLASSINFO("DefaultProperty", "secondProperty")
869 OverrideDefaultPropertyObject() {}
872 class MyRevisionedBaseClassRegistered : public QObject
875 Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
876 Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
879 MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
881 qreal propA() const { return m_pa; }
882 void setPropA(qreal p) {
888 qreal propB() const { return m_pb; }
889 void setPropB(qreal p) {
896 Q_INVOKABLE void methodA() { }
897 Q_INVOKABLE Q_REVISION(1) void methodB() { }
904 Q_REVISION(1) void signalB();
911 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
914 Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
915 Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
918 MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
920 qreal propC() const { return m_pc; }
921 void setPropC(qreal p) {
927 qreal propD() const { return m_pd; }
928 void setPropD(qreal p) {
935 Q_INVOKABLE void methodC() { }
936 Q_INVOKABLE Q_REVISION(1) void methodD() { }
943 Q_REVISION(1) void signalD();
950 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
953 Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
954 Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
957 MyRevisionedClass() {}
959 qreal prop1() const { return m_p1; }
960 void setProp1(qreal p) {
966 qreal prop2() const { return m_p2; }
967 void setProp2(qreal p) {
974 Q_INVOKABLE void method1() { }
975 Q_INVOKABLE Q_REVISION(1) void method2() { }
982 Q_REVISION(1) void signal2();
989 class MyRevisionedSubclass : public MyRevisionedClass
992 Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
993 Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
996 MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
998 qreal prop3() const { return m_p3; }
999 void setProp3(qreal p) {
1002 emit prop3Changed();
1005 qreal prop4() const { return m_p4; }
1006 void setProp4(qreal p) {
1009 emit prop4Changed();
1013 Q_INVOKABLE void method3() { }
1014 Q_INVOKABLE Q_REVISION(1) void method4() { }
1017 void prop3Changed();
1018 void prop4Changed();
1021 Q_REVISION(1) void signal4();
1028 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
1029 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
1030 QML_DECLARE_TYPE(MyRevisionedClass)
1031 QML_DECLARE_TYPE(MyRevisionedSubclass)
1032 Q_DECLARE_METATYPE(MyQmlObject::MyType)
1035 class ScarceResourceObject : public QObject
1038 Q_PROPERTY(QPixmap scarceResource READ scarceResource WRITE setScarceResource NOTIFY scarceResourceChanged)
1040 ScarceResourceObject(QObject *parent = 0) : QObject(parent), m_value(100, 100) { m_value.fill(Qt::blue); }
1041 ~ScarceResourceObject() {}
1043 QPixmap scarceResource() const { return m_value; }
1044 void setScarceResource(QPixmap v) { m_value = v; emit scarceResourceChanged(); }
1046 bool scarceResourceIsDetached() const { return m_value.isDetached(); }
1048 // this particular one returns a new one each time
1049 // this means that every Scarce Resource Copy will
1050 // consume resources (so that we can track disposal
1051 // of v8 handles with circular references).
1052 Q_INVOKABLE QPixmap newScarceResource() const
1054 QPixmap retn(800, 600);
1055 retn.fill(QColor(100, 110, 120, 45));
1060 void scarceResourceChanged();
1065 QML_DECLARE_TYPE(ScarceResourceObject)
1067 class testQObjectApi : public QObject
1071 Q_PROPERTY (int qobjectTestProperty READ qobjectTestProperty NOTIFY qobjectTestPropertyChanged)
1072 Q_PROPERTY (int qobjectTestWritableProperty READ qobjectTestWritableProperty WRITE setQObjectTestWritableProperty NOTIFY qobjectTestWritablePropertyChanged)
1073 Q_PROPERTY (int qobjectTestWritableFinalProperty READ qobjectTestWritableFinalProperty WRITE setQObjectTestWritableFinalProperty NOTIFY qobjectTestWritableFinalPropertyChanged FINAL)
1076 testQObjectApi(QObject* parent = 0)
1077 : QObject(parent), m_testProperty(0), m_testWritableProperty(0), m_testWritableFinalProperty(0), m_methodCallCount(0), m_trackedObject(0)
1081 ~testQObjectApi() {}
1083 enum MyEnum { EnumValue1 = 25, EnumValue2 = 42 };
1084 Q_INVOKABLE int qobjectEnumTestMethod(MyEnum val) { return (static_cast<int>(val) + 5); }
1085 Q_INVOKABLE int qobjectTestMethod(int increment = 1) { m_methodCallCount += increment; return m_methodCallCount; }
1087 Q_INVOKABLE void trackObject(QObject *obj) { m_trackedObject = obj; }
1088 Q_INVOKABLE QObject *trackedObject() const { return m_trackedObject; }
1089 Q_INVOKABLE void setTrackedObjectProperty(const QString &propName) const { m_trackedObject->setProperty(qPrintable(propName), QVariant(5)); }
1090 Q_INVOKABLE QVariant trackedObjectProperty(const QString &propName) const { return m_trackedObject->property(qPrintable(propName)); }
1092 Q_INVOKABLE void setSpecificProperty(QObject *obj, const QString & propName, const QVariant & v) const { obj->setProperty(qPrintable(propName), v); }
1093 Q_INVOKABLE void changeQObjectParent(QObject *obj) { obj->setParent(this); }
1095 int qobjectTestProperty() const { return m_testProperty; }
1096 void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); }
1098 int qobjectTestWritableProperty() const { return m_testWritableProperty; }
1099 void setQObjectTestWritableProperty(int tp) { m_testWritableProperty = tp; emit qobjectTestWritablePropertyChanged(tp); }
1101 int qobjectTestWritableFinalProperty() const { return m_testWritableFinalProperty; }
1102 void setQObjectTestWritableFinalProperty(int tp) { m_testWritableFinalProperty = tp; emit qobjectTestWritableFinalPropertyChanged(); }
1104 Q_INVOKABLE bool trackedObjectHasJsOwnership() {
1105 QObject * object = m_trackedObject;
1110 QQmlData *ddata = QQmlData::get(object, false);
1114 return ddata->indestructible?false:true;
1117 Q_INVOKABLE void deleteQObject(QObject *obj) { delete obj; }
1120 void qobjectTestPropertyChanged(int testProperty);
1121 void qobjectTestWritablePropertyChanged(int testWritableProperty);
1122 void qobjectTestWritableFinalPropertyChanged();
1126 int m_testWritableProperty;
1127 int m_testWritableFinalProperty;
1128 int m_methodCallCount;
1129 QObject *m_trackedObject;
1132 class testImportOrderApi : public QObject
1137 testImportOrderApi(int value, QObject *parent = 0) : QObject(parent), m_value(value) {}
1139 Q_PROPERTY(int value READ value)
1141 int value() const { return m_value; }
1147 class CircularReferenceObject : public QObject,
1148 public QV8GCCallback::Node
1153 CircularReferenceObject(QObject *parent = 0)
1154 : QObject(parent), QV8GCCallback::Node(callback), m_referenced(0), m_dtorCount(0)
1156 QV8GCCallback::addGcCallbackNode(this);
1159 ~CircularReferenceObject()
1161 if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1164 Q_INVOKABLE void setDtorCount(int *dtorCount)
1166 m_dtorCount = dtorCount;
1169 Q_INVOKABLE CircularReferenceObject *generate(QObject *parent = 0)
1171 CircularReferenceObject *retn = new CircularReferenceObject(parent);
1172 retn->m_dtorCount = m_dtorCount;
1173 retn->m_engine = m_engine;
1177 Q_INVOKABLE void addReference(QObject *other)
1179 m_referenced = other;
1182 static void callback(QV8GCCallback::Node *n)
1184 CircularReferenceObject *cro = static_cast<CircularReferenceObject*>(n);
1185 if (cro->m_referenced) {
1186 cro->m_engine->addRelationshipForGC(cro, cro->m_referenced);
1190 void setEngine(QQmlEngine* declarativeEngine)
1192 m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1196 QObject *m_referenced;
1198 QV8Engine* m_engine;
1200 Q_DECLARE_METATYPE(CircularReferenceObject*)
1202 class CircularReferenceHandle : public QObject,
1203 public QV8GCCallback::Node
1208 CircularReferenceHandle(QObject *parent = 0)
1209 : QObject(parent), QV8GCCallback::Node(gccallback), m_dtorCount(0), m_engine(0)
1211 QV8GCCallback::addGcCallbackNode(this);
1214 ~CircularReferenceHandle()
1216 if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1219 Q_INVOKABLE void setDtorCount(int *dtorCount)
1221 m_dtorCount = dtorCount;
1224 Q_INVOKABLE CircularReferenceHandle *generate(QObject *parent = 0)
1226 CircularReferenceHandle *retn = new CircularReferenceHandle(parent);
1227 retn->m_dtorCount = m_dtorCount;
1228 retn->m_engine = m_engine;
1232 Q_INVOKABLE void addReference(v8::Persistent<v8::Value> handle)
1234 m_referenced = qPersistentNew(handle);
1235 m_referenced.MakeWeak(static_cast<void*>(this), wrcallback);
1238 static void wrcallback(v8::Persistent<v8::Value> handle, void *)
1240 qPersistentDispose(handle);
1243 static void gccallback(QV8GCCallback::Node *n)
1245 CircularReferenceHandle *crh = static_cast<CircularReferenceHandle*>(n);
1246 crh->m_engine->addRelationshipForGC(crh, crh->m_referenced);
1249 void setEngine(QQmlEngine* declarativeEngine)
1251 m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1255 v8::Persistent<v8::Value> m_referenced;
1257 QV8Engine* m_engine;
1259 Q_DECLARE_METATYPE(CircularReferenceHandle*)
1261 class MyDynamicCreationDestructionObject : public QObject
1264 Q_PROPERTY (int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
1267 MyDynamicCreationDestructionObject(QObject *parent = 0) : QObject(parent), m_intProperty(0), m_dtorCount(0)
1271 ~MyDynamicCreationDestructionObject()
1278 int intProperty() const { return m_intProperty; }
1279 void setIntProperty(int val) { m_intProperty = val; emit intPropertyChanged(); }
1281 Q_INVOKABLE MyDynamicCreationDestructionObject *createNew()
1283 // no parent == ownership transfers to JS; same dtor counter.
1284 MyDynamicCreationDestructionObject *retn = new MyDynamicCreationDestructionObject;
1285 retn->setDtorCount(m_dtorCount);
1289 void setDtorCount(int *dtorCount)
1291 m_dtorCount = dtorCount;
1295 void intPropertyChanged();
1302 class WriteCounter : public QObject
1305 Q_PROPERTY(int value READ value WRITE setValue);
1307 WriteCounter() : m_value(0), m_count(0) {}
1309 int value() const { return m_value; }
1310 void setValue(int v) { m_value = v; ++m_count; }
1312 int count() const { return m_count; }
1319 class MySequenceConversionObject : public QObject
1323 Q_PROPERTY (QList<int> intListProperty READ intListProperty WRITE setIntListProperty NOTIFY intListPropertyChanged)
1324 Q_PROPERTY (QList<int> intListProperty2 READ intListProperty2 WRITE setIntListProperty2 NOTIFY intListProperty2Changed)
1325 Q_PROPERTY (QList<qreal> qrealListProperty READ qrealListProperty WRITE setQrealListProperty NOTIFY qrealListPropertyChanged)
1326 Q_PROPERTY (QList<bool> boolListProperty READ boolListProperty WRITE setBoolListProperty NOTIFY boolListPropertyChanged)
1327 Q_PROPERTY (QList<QString> stringListProperty READ stringListProperty WRITE setStringListProperty NOTIFY stringListPropertyChanged)
1328 Q_PROPERTY (QList<QUrl> urlListProperty READ urlListProperty WRITE setUrlListProperty NOTIFY urlListPropertyChanged)
1329 Q_PROPERTY (QStringList qstringListProperty READ qstringListProperty WRITE setQStringListProperty NOTIFY qstringListPropertyChanged)
1331 Q_PROPERTY (QList<QPoint> pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged)
1332 Q_PROPERTY (QList<QVariant> variantListProperty READ variantListProperty WRITE setVariantListProperty NOTIFY variantListPropertyChanged)
1334 Q_PROPERTY (qint32 maxIndex READ maxIndex CONSTANT)
1335 Q_PROPERTY (quint32 tooBigIndex READ tooBigIndex CONSTANT)
1336 Q_PROPERTY (qint32 negativeIndex READ negativeIndex CONSTANT)
1339 MySequenceConversionObject()
1341 m_intList << 1 << 2 << 3 << 4;
1342 m_intList2 << 1 << 2 << 3 << 4;
1343 m_qrealList << 1.1 << 2.2 << 3.3 << 4.4;
1344 m_boolList << true << false << true << false;
1345 m_stringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1346 m_urlList << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com");
1347 m_qstringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1349 m_pointList << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
1350 m_variantList << QVariant(QLatin1String("one")) << QVariant(true) << QVariant(3);
1353 ~MySequenceConversionObject() {}
1355 qint32 maxIndex() const
1359 quint32 tooBigIndex() const
1365 qint32 negativeIndex() const
1370 QList<int> intListProperty() const { return m_intList; }
1371 void setIntListProperty(const QList<int> &list) { m_intList = list; emit intListPropertyChanged(); }
1372 QList<int> intListProperty2() const { return m_intList2; }
1373 void setIntListProperty2(const QList<int> &list) { m_intList2 = list; emit intListProperty2Changed(); }
1374 QList<qreal> qrealListProperty() const { return m_qrealList; }
1375 void setQrealListProperty(const QList<qreal> &list) { m_qrealList = list; emit qrealListPropertyChanged(); }
1376 QList<bool> boolListProperty() const { return m_boolList; }
1377 void setBoolListProperty(const QList<bool> &list) { m_boolList = list; emit boolListPropertyChanged(); }
1378 QList<QString> stringListProperty() const { return m_stringList; }
1379 void setStringListProperty(const QList<QString> &list) { m_stringList = list; emit stringListPropertyChanged(); }
1380 QList<QUrl> urlListProperty() const { return m_urlList; }
1381 void setUrlListProperty(const QList<QUrl> &list) { m_urlList = list; emit urlListPropertyChanged(); }
1382 QStringList qstringListProperty() const { return m_qstringList; }
1383 void setQStringListProperty(const QStringList &list) { m_qstringList = list; emit qstringListPropertyChanged(); }
1384 QList<QPoint> pointListProperty() const { return m_pointList; }
1385 void setPointListProperty(const QList<QPoint> &list) { m_pointList = list; emit pointListPropertyChanged(); }
1386 QList<QVariant> variantListProperty() const { return m_variantList; }
1387 void setVariantListProperty(const QList<QVariant> &list) { m_variantList = list; emit variantListPropertyChanged(); }
1389 // now for "copy resource" sequences:
1390 Q_INVOKABLE QList<int> generateIntSequence() const { QList<int> retn; retn << 1 << 2 << 3; return retn; }
1391 Q_INVOKABLE QList<qreal> generateQrealSequence() const { QList<qreal> retn; retn << 1.1 << 2.2 << 3.3; return retn; }
1392 Q_INVOKABLE QList<bool> generateBoolSequence() const { QList<bool> retn; retn << true << false << true; return retn; }
1393 Q_INVOKABLE QList<QString> generateStringSequence() const { QList<QString> retn; retn << "one" << "two" << "three"; return retn; }
1394 Q_INVOKABLE QList<QUrl> generateUrlSequence() const { QList<QUrl> retn; retn << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); return retn; }
1395 Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; }
1397 // "reference resource" underlying qobject deletion test:
1398 Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; }
1399 Q_INVOKABLE void deleteTestObject(QObject *object) const { delete object; }
1402 void intListPropertyChanged();
1403 void intListProperty2Changed();
1404 void qrealListPropertyChanged();
1405 void boolListPropertyChanged();
1406 void stringListPropertyChanged();
1407 void urlListPropertyChanged();
1408 void qstringListPropertyChanged();
1409 void pointListPropertyChanged();
1410 void variantListPropertyChanged();
1413 QList<int> m_intList;
1414 QList<int> m_intList2;
1415 QList<qreal> m_qrealList;
1416 QList<bool> m_boolList;
1417 QList<QString> m_stringList;
1418 QList<QUrl> m_urlList;
1419 QStringList m_qstringList;
1421 QList<QPoint> m_pointList; // not a supported sequence type
1422 QList<QVariant> m_variantList; // not a supported sequence type, but QVariantList support is hardcoded.
1425 class MyDeleteObject : public QObject
1428 Q_PROPERTY(QObject *nestedObject READ nestedObject NOTIFY nestedObjectChanged);
1429 Q_PROPERTY(int deleteNestedObject READ deleteNestedObject NOTIFY deleteNestedObjectChanged);
1432 MyDeleteObject() : m_nestedObject(new MyQmlObject) {}
1434 QObject *nestedObject() const { return m_nestedObject; }
1435 int deleteNestedObject() { delete m_nestedObject; m_nestedObject = 0; return 1; }
1438 void nestedObjectChanged();
1439 void deleteNestedObjectChanged();
1442 MyQmlObject *m_nestedObject;
1445 class DateTimeExporter : public QObject
1450 DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC")
1452 switch (m_datetime.timeSpec()) {
1455 QDateTime utc(m_datetime.toUTC());
1456 utc.setTimeSpec(Qt::LocalTime);
1457 m_offset = m_datetime.secsTo(utc) / 60;
1458 m_timespec = "LocalTime";
1461 case Qt::OffsetFromUTC:
1462 m_offset = m_datetime.utcOffset() / 60;
1463 m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+')
1464 .arg(abs(m_offset) / 60)
1465 .arg(abs(m_offset) % 60);
1471 Q_INVOKABLE QDate getDate() const { return m_datetime.date(); }
1472 Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; }
1473 Q_INVOKABLE int getDateTimeOffset() const { return m_offset; }
1474 Q_INVOKABLE QString getTimeSpec() const { return m_timespec; }
1477 QDateTime m_datetime;
1482 class MyWorkerObject : public QObject
1490 void done(const QString &result);
1493 class MyUnregisteredEnumTypeObject : public QObject
1496 Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
1499 MyUnregisteredEnumTypeObject() : QObject(), m_ev(FirstValue) {}
1500 ~MyUnregisteredEnumTypeObject() {}
1507 MyEnum enumProperty() const { return m_ev; }
1508 void setEnumProperty(MyEnum v) { m_ev = v; }
1514 class FallbackBindingsObject : public QObject
1517 Q_PROPERTY (int test READ test NOTIFY testChanged)
1519 FallbackBindingsObject(QObject* parent = 0)
1520 : QObject(parent), m_test(100)
1524 int test() const { return m_test; }
1533 class FallbackBindingsDerived : public FallbackBindingsObject
1536 Q_PROPERTY (QString test READ test NOTIFY testChanged)
1538 FallbackBindingsDerived(QObject* parent = 0)
1539 : FallbackBindingsObject(parent), m_test("hello")
1543 QString test() const { return m_test; }
1552 class FallbackBindingsAttachedObject : public QObject
1555 Q_PROPERTY (int test READ test NOTIFY testChanged)
1557 FallbackBindingsAttachedObject(QObject *parent) : QObject(parent), m_test(100) {}
1559 int test() const { return m_test; }
1568 class FallbackBindingsAttachedDerived : public FallbackBindingsAttachedObject
1571 Q_PROPERTY (QString test READ test NOTIFY testChanged)
1573 FallbackBindingsAttachedDerived(QObject* parent = 0)
1574 : FallbackBindingsAttachedObject(parent), m_test("hello")
1578 QString test() const { return m_test; }
1587 class FallbackBindingsTypeObject : public QObject
1591 FallbackBindingsTypeObject() : QObject() {}
1593 static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
1594 return new FallbackBindingsAttachedObject(o);
1598 class FallbackBindingsTypeDerived : public QObject
1602 FallbackBindingsTypeDerived() : QObject() {}
1604 static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
1605 return new FallbackBindingsAttachedDerived(o);
1609 QML_DECLARE_TYPEINFO(FallbackBindingsTypeObject, QML_HAS_ATTACHED_PROPERTIES)
1610 QML_DECLARE_TYPEINFO(FallbackBindingsTypeDerived, QML_HAS_ATTACHED_PROPERTIES)
1612 void registerTypes();
1614 #endif // TESTTYPES_H