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 class MyInvokableObject : public MyInvokableBaseObject
715 enum TestEnum { EnumValue1, EnumValue2 };
716 MyInvokableObject() { reset(); }
718 int invoked() const { return m_invoked; }
719 bool error() const { return m_invokedError; }
720 const QVariantList &actuals() const { return m_actuals; }
721 void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); }
723 Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); }
724 Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); }
726 Q_INVOKABLE void method_NoArgs() { invoke(0); }
727 Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
728 Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
729 Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
730 Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
731 Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
732 Q_INVOKABLE QJSValue method_NoArgs_QScriptValue() { invoke(6); return QJSValue("Hello world"); }
733 Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); }
735 Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; }
736 Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; }
737 Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; }
738 Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; }
739 Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; }
740 Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); }
741 Q_INVOKABLE void method_QScriptValue(QJSValue a) { invoke(14); m_actuals << qVariantFromValue(a); }
742 Q_INVOKABLE void method_intQScriptValue(int a, QJSValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); }
744 Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
745 Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
746 Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
748 Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
750 Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
752 Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
754 Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); }
755 Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); }
756 Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); }
758 Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); }
759 Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
760 Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
762 Q_INVOKABLE void method_unknown(MyInvokableObject *) { invoke(28); }
765 friend class MyInvokableBaseObject;
766 void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
769 QVariantList m_actuals;
772 MyInvokableBaseObject::~MyInvokableBaseObject() {}
774 void MyInvokableBaseObject::method_inherited(int a)
776 static_cast<MyInvokableObject *>(this)->invoke(-3);
777 static_cast<MyInvokableObject *>(this)->m_actuals << a;
780 // This is a hidden overload of the MyInvokableObject::method_overload() method
781 void MyInvokableBaseObject::method_overload()
783 static_cast<MyInvokableObject *>(this)->invoke(-2);
786 class NumberAssignment : public QObject
790 Q_PROPERTY(qreal test1 READ test1 WRITE setTest1)
792 qreal test1() const { return _test1; }
793 void setTest1(qreal v) { _test1 = v; }
795 Q_PROPERTY(qreal test2 READ test2 WRITE setTest2)
797 qreal test2() const { return _test2; }
798 void setTest2(qreal v) { _test2 = v; }
800 Q_PROPERTY(qreal test3 READ test3 WRITE setTest3)
802 qreal test3() const { return _test3; }
803 void setTest3(qreal v) { _test3 = v; }
805 Q_PROPERTY(qreal test4 READ test4 WRITE setTest4)
807 qreal test4() const { return _test4; }
808 void setTest4(qreal v) { _test4 = v; }
810 Q_PROPERTY(int test5 READ test5 WRITE setTest5)
812 int test5() const { return _test5; }
813 void setTest5(int v) { _test5 = v; }
815 Q_PROPERTY(int test6 READ test6 WRITE setTest6)
817 int test6() const { return _test6; }
818 void setTest6(int v) { _test6 = v; }
820 Q_PROPERTY(int test7 READ test7 WRITE setTest7)
822 int test7() const { return _test7; }
823 void setTest7(int v) { _test7 = v; }
825 Q_PROPERTY(int test8 READ test8 WRITE setTest8)
827 int test8() const { return _test8; }
828 void setTest8(int v) { _test8 = v; }
830 Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9)
832 unsigned int test9() const { return _test9; }
833 void setTest9(unsigned int v) { _test9 = v; }
835 Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10)
836 unsigned int _test10;
837 unsigned int test10() const { return _test10; }
838 void setTest10(unsigned int v) { _test10 = v; }
840 Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11)
841 unsigned int _test11;
842 unsigned int test11() const { return _test11; }
843 void setTest11(unsigned int v) { _test11 = v; }
845 Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12)
846 unsigned int _test12;
847 unsigned int test12() const { return _test12; }
848 void setTest12(unsigned int v) { _test12 = v; }
851 class DefaultPropertyExtendedObject : public QObject
854 Q_PROPERTY(QObject *firstProperty READ firstProperty WRITE setFirstProperty)
855 Q_PROPERTY(QObject *secondProperty READ secondProperty WRITE setSecondProperty)
857 DefaultPropertyExtendedObject(QObject *parent = 0) : QObject(parent), m_firstProperty(0), m_secondProperty(0) {}
859 QObject *firstProperty() const { return m_firstProperty; }
860 QObject *secondProperty() const { return m_secondProperty; }
861 void setFirstProperty(QObject *property) { m_firstProperty = property; }
862 void setSecondProperty(QObject *property) { m_secondProperty = property; }
864 QObject* m_firstProperty;
865 QObject* m_secondProperty;
868 class OverrideDefaultPropertyObject : public DefaultPropertyExtendedObject
871 Q_CLASSINFO("DefaultProperty", "secondProperty")
873 OverrideDefaultPropertyObject() {}
876 class MyRevisionedBaseClassRegistered : public QObject
879 Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
880 Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
883 MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
885 qreal propA() const { return m_pa; }
886 void setPropA(qreal p) {
892 qreal propB() const { return m_pb; }
893 void setPropB(qreal p) {
900 Q_INVOKABLE void methodA() { }
901 Q_INVOKABLE Q_REVISION(1) void methodB() { }
908 Q_REVISION(1) void signalB();
915 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
918 Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
919 Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
922 MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
924 qreal propC() const { return m_pc; }
925 void setPropC(qreal p) {
931 qreal propD() const { return m_pd; }
932 void setPropD(qreal p) {
939 Q_INVOKABLE void methodC() { }
940 Q_INVOKABLE Q_REVISION(1) void methodD() { }
947 Q_REVISION(1) void signalD();
954 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
957 Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
958 Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
961 MyRevisionedClass() {}
963 qreal prop1() const { return m_p1; }
964 void setProp1(qreal p) {
970 qreal prop2() const { return m_p2; }
971 void setProp2(qreal p) {
978 Q_INVOKABLE void method1() { }
979 Q_INVOKABLE Q_REVISION(1) void method2() { }
986 Q_REVISION(1) void signal2();
993 class MyRevisionedSubclass : public MyRevisionedClass
996 Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
997 Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
1000 MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
1002 qreal prop3() const { return m_p3; }
1003 void setProp3(qreal p) {
1006 emit prop3Changed();
1009 qreal prop4() const { return m_p4; }
1010 void setProp4(qreal p) {
1013 emit prop4Changed();
1017 Q_INVOKABLE void method3() { }
1018 Q_INVOKABLE Q_REVISION(1) void method4() { }
1021 void prop3Changed();
1022 void prop4Changed();
1025 Q_REVISION(1) void signal4();
1032 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
1033 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
1034 QML_DECLARE_TYPE(MyRevisionedClass)
1035 QML_DECLARE_TYPE(MyRevisionedSubclass)
1036 Q_DECLARE_METATYPE(MyQmlObject::MyType)
1039 class ScarceResourceObject : public QObject
1042 Q_PROPERTY(QPixmap scarceResource READ scarceResource WRITE setScarceResource NOTIFY scarceResourceChanged)
1044 ScarceResourceObject(QObject *parent = 0) : QObject(parent), m_value(100, 100) { m_value.fill(Qt::blue); }
1045 ~ScarceResourceObject() {}
1047 QPixmap scarceResource() const { return m_value; }
1048 void setScarceResource(QPixmap v) { m_value = v; emit scarceResourceChanged(); }
1050 bool scarceResourceIsDetached() const { return m_value.isDetached(); }
1052 // this particular one returns a new one each time
1053 // this means that every Scarce Resource Copy will
1054 // consume resources (so that we can track disposal
1055 // of v8 handles with circular references).
1056 Q_INVOKABLE QPixmap newScarceResource() const
1058 QPixmap retn(800, 600);
1059 retn.fill(QColor(100, 110, 120, 45));
1064 void scarceResourceChanged();
1069 QML_DECLARE_TYPE(ScarceResourceObject)
1071 class testQObjectApi : public QObject
1075 Q_PROPERTY (int qobjectTestProperty READ qobjectTestProperty NOTIFY qobjectTestPropertyChanged)
1076 Q_PROPERTY (int qobjectTestWritableProperty READ qobjectTestWritableProperty WRITE setQObjectTestWritableProperty NOTIFY qobjectTestWritablePropertyChanged)
1077 Q_PROPERTY (int qobjectTestWritableFinalProperty READ qobjectTestWritableFinalProperty WRITE setQObjectTestWritableFinalProperty NOTIFY qobjectTestWritableFinalPropertyChanged FINAL)
1080 testQObjectApi(QObject* parent = 0)
1081 : QObject(parent), m_testProperty(0), m_testWritableProperty(0), m_testWritableFinalProperty(0), m_methodCallCount(0), m_trackedObject(0)
1085 ~testQObjectApi() {}
1087 enum MyEnum { EnumValue1 = 25, EnumValue2 = 42 };
1088 Q_INVOKABLE int qobjectEnumTestMethod(MyEnum val) { return (static_cast<int>(val) + 5); }
1089 Q_INVOKABLE int qobjectTestMethod(int increment = 1) { m_methodCallCount += increment; return m_methodCallCount; }
1091 Q_INVOKABLE void trackObject(QObject *obj) { m_trackedObject = obj; }
1092 Q_INVOKABLE QObject *trackedObject() const { return m_trackedObject; }
1093 Q_INVOKABLE void setTrackedObjectProperty(const QString &propName) const { m_trackedObject->setProperty(qPrintable(propName), QVariant(5)); }
1094 Q_INVOKABLE QVariant trackedObjectProperty(const QString &propName) const { return m_trackedObject->property(qPrintable(propName)); }
1096 Q_INVOKABLE void setSpecificProperty(QObject *obj, const QString & propName, const QVariant & v) const { obj->setProperty(qPrintable(propName), v); }
1097 Q_INVOKABLE void changeQObjectParent(QObject *obj) { obj->setParent(this); }
1099 int qobjectTestProperty() const { return m_testProperty; }
1100 void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); }
1102 int qobjectTestWritableProperty() const { return m_testWritableProperty; }
1103 void setQObjectTestWritableProperty(int tp) { m_testWritableProperty = tp; emit qobjectTestWritablePropertyChanged(tp); }
1105 int qobjectTestWritableFinalProperty() const { return m_testWritableFinalProperty; }
1106 void setQObjectTestWritableFinalProperty(int tp) { m_testWritableFinalProperty = tp; emit qobjectTestWritableFinalPropertyChanged(); }
1108 Q_INVOKABLE bool trackedObjectHasJsOwnership() {
1109 QObject * object = m_trackedObject;
1114 QQmlData *ddata = QQmlData::get(object, false);
1118 return ddata->indestructible?false:true;
1121 Q_INVOKABLE void deleteQObject(QObject *obj) { delete obj; }
1124 void qobjectTestPropertyChanged(int testProperty);
1125 void qobjectTestWritablePropertyChanged(int testWritableProperty);
1126 void qobjectTestWritableFinalPropertyChanged();
1130 int m_testWritableProperty;
1131 int m_testWritableFinalProperty;
1132 int m_methodCallCount;
1133 QObject *m_trackedObject;
1136 class testQObjectApiTwo : public QObject
1139 Q_PROPERTY(int twoTestProperty READ twoTestProperty WRITE setTwoTestProperty NOTIFY twoTestPropertyChanged)
1142 testQObjectApiTwo(QObject *parent = 0) : QObject(parent), m_ttp(42) {}
1143 ~testQObjectApiTwo() {}
1145 void setTwoTestProperty(int v) { m_ttp = v; emit twoTestPropertyChanged(); }
1146 int twoTestProperty() const { return m_ttp; }
1149 void twoTestPropertyChanged();
1155 class testImportOrderApi : public QObject
1160 testImportOrderApi(int value, QObject *parent = 0) : QObject(parent), m_value(value) {}
1162 Q_PROPERTY(int value READ value)
1164 int value() const { return m_value; }
1170 class CircularReferenceObject : public QObject,
1171 public QV8GCCallback::Node
1176 CircularReferenceObject(QObject *parent = 0)
1177 : QObject(parent), QV8GCCallback::Node(callback), m_referenced(0), m_dtorCount(0)
1179 QV8GCCallback::addGcCallbackNode(this);
1182 ~CircularReferenceObject()
1184 if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1187 Q_INVOKABLE void setDtorCount(int *dtorCount)
1189 m_dtorCount = dtorCount;
1192 Q_INVOKABLE CircularReferenceObject *generate(QObject *parent = 0)
1194 CircularReferenceObject *retn = new CircularReferenceObject(parent);
1195 retn->m_dtorCount = m_dtorCount;
1196 retn->m_engine = m_engine;
1200 Q_INVOKABLE void addReference(QObject *other)
1202 m_referenced = other;
1205 static void callback(QV8GCCallback::Node *n)
1207 CircularReferenceObject *cro = static_cast<CircularReferenceObject*>(n);
1208 if (cro->m_referenced) {
1209 cro->m_engine->addRelationshipForGC(cro, cro->m_referenced);
1213 void setEngine(QQmlEngine* declarativeEngine)
1215 m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1219 QObject *m_referenced;
1221 QV8Engine* m_engine;
1223 Q_DECLARE_METATYPE(CircularReferenceObject*)
1225 class CircularReferenceHandle : public QObject,
1226 public QV8GCCallback::Node
1231 CircularReferenceHandle(QObject *parent = 0)
1232 : QObject(parent), QV8GCCallback::Node(gccallback), m_dtorCount(0), m_engine(0)
1234 QV8GCCallback::addGcCallbackNode(this);
1237 ~CircularReferenceHandle()
1239 if (m_dtorCount) *m_dtorCount = *m_dtorCount + 1;
1242 Q_INVOKABLE void setDtorCount(int *dtorCount)
1244 m_dtorCount = dtorCount;
1247 Q_INVOKABLE CircularReferenceHandle *generate(QObject *parent = 0)
1249 CircularReferenceHandle *retn = new CircularReferenceHandle(parent);
1250 retn->m_dtorCount = m_dtorCount;
1251 retn->m_engine = m_engine;
1255 Q_INVOKABLE void addReference(v8::Persistent<v8::Value> handle)
1257 m_referenced = qPersistentNew(handle);
1258 m_referenced.MakeWeak(static_cast<void*>(this), wrcallback);
1261 static void wrcallback(v8::Persistent<v8::Value> handle, void *)
1263 qPersistentDispose(handle);
1266 static void gccallback(QV8GCCallback::Node *n)
1268 CircularReferenceHandle *crh = static_cast<CircularReferenceHandle*>(n);
1269 crh->m_engine->addRelationshipForGC(crh, crh->m_referenced);
1272 void setEngine(QQmlEngine* declarativeEngine)
1274 m_engine = QQmlEnginePrivate::get(declarativeEngine)->v8engine();
1278 v8::Persistent<v8::Value> m_referenced;
1280 QV8Engine* m_engine;
1282 Q_DECLARE_METATYPE(CircularReferenceHandle*)
1284 class MyDynamicCreationDestructionObject : public QObject
1287 Q_PROPERTY (int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
1290 MyDynamicCreationDestructionObject(QObject *parent = 0) : QObject(parent), m_intProperty(0), m_dtorCount(0)
1294 ~MyDynamicCreationDestructionObject()
1301 int intProperty() const { return m_intProperty; }
1302 void setIntProperty(int val) { m_intProperty = val; emit intPropertyChanged(); }
1304 Q_INVOKABLE MyDynamicCreationDestructionObject *createNew()
1306 // no parent == ownership transfers to JS; same dtor counter.
1307 MyDynamicCreationDestructionObject *retn = new MyDynamicCreationDestructionObject;
1308 retn->setDtorCount(m_dtorCount);
1312 void setDtorCount(int *dtorCount)
1314 m_dtorCount = dtorCount;
1318 void intPropertyChanged();
1325 class WriteCounter : public QObject
1328 Q_PROPERTY(int value READ value WRITE setValue);
1330 WriteCounter() : m_value(0), m_count(0) {}
1332 int value() const { return m_value; }
1333 void setValue(int v) { m_value = v; ++m_count; }
1335 int count() const { return m_count; }
1342 class MySequenceConversionObject : public QObject
1346 Q_PROPERTY (QList<int> intListProperty READ intListProperty WRITE setIntListProperty NOTIFY intListPropertyChanged)
1347 Q_PROPERTY (QList<int> intListProperty2 READ intListProperty2 WRITE setIntListProperty2 NOTIFY intListProperty2Changed)
1348 Q_PROPERTY (QList<qreal> qrealListProperty READ qrealListProperty WRITE setQrealListProperty NOTIFY qrealListPropertyChanged)
1349 Q_PROPERTY (QList<bool> boolListProperty READ boolListProperty WRITE setBoolListProperty NOTIFY boolListPropertyChanged)
1350 Q_PROPERTY (QList<QString> stringListProperty READ stringListProperty WRITE setStringListProperty NOTIFY stringListPropertyChanged)
1351 Q_PROPERTY (QList<QUrl> urlListProperty READ urlListProperty WRITE setUrlListProperty NOTIFY urlListPropertyChanged)
1352 Q_PROPERTY (QStringList qstringListProperty READ qstringListProperty WRITE setQStringListProperty NOTIFY qstringListPropertyChanged)
1354 Q_PROPERTY (QList<QPoint> pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged)
1355 Q_PROPERTY (QList<QVariant> variantListProperty READ variantListProperty WRITE setVariantListProperty NOTIFY variantListPropertyChanged)
1357 Q_PROPERTY (qint32 maxIndex READ maxIndex CONSTANT)
1358 Q_PROPERTY (quint32 tooBigIndex READ tooBigIndex CONSTANT)
1359 Q_PROPERTY (qint32 negativeIndex READ negativeIndex CONSTANT)
1362 MySequenceConversionObject()
1364 m_intList << 1 << 2 << 3 << 4;
1365 m_intList2 << 1 << 2 << 3 << 4;
1366 m_qrealList << 1.1 << 2.2 << 3.3 << 4.4;
1367 m_boolList << true << false << true << false;
1368 m_stringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1369 m_urlList << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com");
1370 m_qstringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth");
1372 m_pointList << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
1373 m_variantList << QVariant(QLatin1String("one")) << QVariant(true) << QVariant(3);
1376 ~MySequenceConversionObject() {}
1378 qint32 maxIndex() const
1382 quint32 tooBigIndex() const
1388 qint32 negativeIndex() const
1393 QList<int> intListProperty() const { return m_intList; }
1394 void setIntListProperty(const QList<int> &list) { m_intList = list; emit intListPropertyChanged(); }
1395 QList<int> intListProperty2() const { return m_intList2; }
1396 void setIntListProperty2(const QList<int> &list) { m_intList2 = list; emit intListProperty2Changed(); }
1397 QList<qreal> qrealListProperty() const { return m_qrealList; }
1398 void setQrealListProperty(const QList<qreal> &list) { m_qrealList = list; emit qrealListPropertyChanged(); }
1399 QList<bool> boolListProperty() const { return m_boolList; }
1400 void setBoolListProperty(const QList<bool> &list) { m_boolList = list; emit boolListPropertyChanged(); }
1401 QList<QString> stringListProperty() const { return m_stringList; }
1402 void setStringListProperty(const QList<QString> &list) { m_stringList = list; emit stringListPropertyChanged(); }
1403 QList<QUrl> urlListProperty() const { return m_urlList; }
1404 void setUrlListProperty(const QList<QUrl> &list) { m_urlList = list; emit urlListPropertyChanged(); }
1405 QStringList qstringListProperty() const { return m_qstringList; }
1406 void setQStringListProperty(const QStringList &list) { m_qstringList = list; emit qstringListPropertyChanged(); }
1407 QList<QPoint> pointListProperty() const { return m_pointList; }
1408 void setPointListProperty(const QList<QPoint> &list) { m_pointList = list; emit pointListPropertyChanged(); }
1409 QList<QVariant> variantListProperty() const { return m_variantList; }
1410 void setVariantListProperty(const QList<QVariant> &list) { m_variantList = list; emit variantListPropertyChanged(); }
1412 // now for "copy resource" sequences:
1413 Q_INVOKABLE QList<int> generateIntSequence() const { QList<int> retn; retn << 1 << 2 << 3; return retn; }
1414 Q_INVOKABLE QList<qreal> generateQrealSequence() const { QList<qreal> retn; retn << 1.1 << 2.2 << 3.3; return retn; }
1415 Q_INVOKABLE QList<bool> generateBoolSequence() const { QList<bool> retn; retn << true << false << true; return retn; }
1416 Q_INVOKABLE QList<QString> generateStringSequence() const { QList<QString> retn; retn << "one" << "two" << "three"; return retn; }
1417 Q_INVOKABLE QList<QUrl> generateUrlSequence() const { QList<QUrl> retn; retn << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); return retn; }
1418 Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; }
1419 Q_INVOKABLE bool parameterEqualsGeneratedIntSequence(const QList<int>& param) const { return (param == generateIntSequence()); }
1421 // "reference resource" underlying qobject deletion test:
1422 Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; }
1423 Q_INVOKABLE void deleteTestObject(QObject *object) const { delete object; }
1426 void intListPropertyChanged();
1427 void intListProperty2Changed();
1428 void qrealListPropertyChanged();
1429 void boolListPropertyChanged();
1430 void stringListPropertyChanged();
1431 void urlListPropertyChanged();
1432 void qstringListPropertyChanged();
1433 void pointListPropertyChanged();
1434 void variantListPropertyChanged();
1437 QList<int> m_intList;
1438 QList<int> m_intList2;
1439 QList<qreal> m_qrealList;
1440 QList<bool> m_boolList;
1441 QList<QString> m_stringList;
1442 QList<QUrl> m_urlList;
1443 QStringList m_qstringList;
1445 QList<QPoint> m_pointList; // not a supported sequence type
1446 QList<QVariant> m_variantList; // not a supported sequence type, but QVariantList support is hardcoded.
1449 class MyDeleteObject : public QObject
1452 Q_PROPERTY(QObject *nestedObject READ nestedObject NOTIFY nestedObjectChanged);
1453 Q_PROPERTY(int deleteNestedObject READ deleteNestedObject NOTIFY deleteNestedObjectChanged);
1456 MyDeleteObject() : m_nestedObject(new MyQmlObject) {}
1458 QObject *nestedObject() const { return m_nestedObject; }
1459 int deleteNestedObject() { delete m_nestedObject; m_nestedObject = 0; return 1; }
1462 void nestedObjectChanged();
1463 void deleteNestedObjectChanged();
1466 MyQmlObject *m_nestedObject;
1469 class DateTimeExporter : public QObject
1474 DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC")
1476 switch (m_datetime.timeSpec()) {
1479 QDateTime utc(m_datetime.toUTC());
1480 utc.setTimeSpec(Qt::LocalTime);
1481 m_offset = m_datetime.secsTo(utc) / 60;
1482 m_timespec = "LocalTime";
1485 case Qt::OffsetFromUTC:
1486 m_offset = m_datetime.utcOffset() / 60;
1487 m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+')
1488 .arg(abs(m_offset) / 60)
1489 .arg(abs(m_offset) % 60);
1495 Q_INVOKABLE QDate getDate() const { return m_datetime.date(); }
1496 Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; }
1497 Q_INVOKABLE int getDateTimeOffset() const { return m_offset; }
1498 Q_INVOKABLE QString getTimeSpec() const { return m_timespec; }
1501 QDateTime m_datetime;
1506 class MyWorkerObject : public QObject
1514 void done(const QString &result);
1517 class MyUnregisteredEnumTypeObject : public QObject
1520 Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
1523 MyUnregisteredEnumTypeObject() : QObject(), m_ev(FirstValue) {}
1524 ~MyUnregisteredEnumTypeObject() {}
1531 MyEnum enumProperty() const { return m_ev; }
1532 void setEnumProperty(MyEnum v) { m_ev = v; }
1538 class FallbackBindingsObject : public QObject
1541 Q_PROPERTY (int test READ test NOTIFY testChanged)
1543 FallbackBindingsObject(QObject* parent = 0)
1544 : QObject(parent), m_test(100)
1548 int test() const { return m_test; }
1557 class FallbackBindingsDerived : public FallbackBindingsObject
1560 Q_PROPERTY (QString test READ test NOTIFY testChanged)
1562 FallbackBindingsDerived(QObject* parent = 0)
1563 : FallbackBindingsObject(parent), m_test("hello")
1567 QString test() const { return m_test; }
1576 class FallbackBindingsAttachedObject : public QObject
1579 Q_PROPERTY (int test READ test NOTIFY testChanged)
1581 FallbackBindingsAttachedObject(QObject *parent) : QObject(parent), m_test(100) {}
1583 int test() const { return m_test; }
1592 class FallbackBindingsAttachedDerived : public FallbackBindingsAttachedObject
1595 Q_PROPERTY (QString test READ test NOTIFY testChanged)
1597 FallbackBindingsAttachedDerived(QObject* parent = 0)
1598 : FallbackBindingsAttachedObject(parent), m_test("hello")
1602 QString test() const { return m_test; }
1611 class FallbackBindingsTypeObject : public QObject
1615 FallbackBindingsTypeObject() : QObject() {}
1617 static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
1618 return new FallbackBindingsAttachedObject(o);
1622 class FallbackBindingsTypeDerived : public QObject
1626 FallbackBindingsTypeDerived() : QObject() {}
1628 static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) {
1629 return new FallbackBindingsAttachedDerived(o);
1633 QML_DECLARE_TYPEINFO(FallbackBindingsTypeObject, QML_HAS_ATTACHED_PROPERTIES)
1634 QML_DECLARE_TYPEINFO(FallbackBindingsTypeDerived, QML_HAS_ATTACHED_PROPERTIES)
1636 void registerTypes();
1638 #endif // TESTTYPES_H