1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef TESTTYPES_H
42 #define TESTTYPES_H
43
44 #include <QtCore/qobject.h>
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/qdeclarativeexpression.h>
47 #include <QtCore/qpoint.h>
48 #include <QtCore/qsize.h>
49 #include <QtDeclarative/qdeclarativelist.h>
50 #include <QtCore/qrect.h>
51 #include <QtGui/qmatrix.h>
52 #include <QtGui/qcolor.h>
53 #include <QtGui/qvector3d.h>
54 #include <QtCore/qdatetime.h>
55 #include <QtScript/qscriptvalue.h>
56 #include <QtDeclarative/qdeclarativescriptstring.h>
57 #include <QtDeclarative/qdeclarativecomponent.h>
58
59 class MyQmlAttachedObject : public QObject
60 {
61 Q_OBJECT
Q_PROPERTY(int value READ value CONSTANT)62 Q_PROPERTY(int value READ value CONSTANT)
63 Q_PROPERTY(int value2 READ value2 WRITE setValue2 NOTIFY value2Changed)
64 public:
65 MyQmlAttachedObject(QObject *parent) : QObject(parent), m_value2(0) {}
66
value()67 int value() const { return 19; }
value2()68 int value2() const { return m_value2; }
setValue2(int v)69 void setValue2(int v) { if (m_value2 == v) return; m_value2 = v; emit value2Changed(); }
70
emitMySignal()71 void emitMySignal() { emit mySignal(); }
72
73 signals:
74 void value2Changed();
75 void mySignal();
76
77 private:
78 int m_value2;
79 };
80
81 class MyQmlObject : public QObject
82 {
83 Q_OBJECT
Q_ENUMS(MyEnum)84 Q_ENUMS(MyEnum)
85 Q_ENUMS(MyEnum2)
86 Q_PROPERTY(int deleteOnSet READ deleteOnSet WRITE setDeleteOnSet)
87 Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT)
88 Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT)
89 Q_PROPERTY(int value READ value WRITE setValue)
90 Q_PROPERTY(int console READ console CONSTANT)
91 Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged)
92 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged)
93 Q_PROPERTY(QDeclarativeListProperty<QObject> objectListProperty READ objectListProperty CONSTANT)
94 Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty)
95 Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
96 Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false)
97
98 public:
99 MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13) {}
100
101 enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 };
102 enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 };
103
trueProperty()104 bool trueProperty() const { return true; }
falseProperty()105 bool falseProperty() const { return false; }
106
stringProperty()107 QString stringProperty() const { return m_string; }
setStringProperty(const QString & s)108 void setStringProperty(const QString &s)
109 {
110 if (s == m_string)
111 return;
112 m_string = s;
113 emit stringChanged();
114 }
115
objectProperty()116 QObject *objectProperty() const { return m_object; }
setObjectProperty(QObject * obj)117 void setObjectProperty(QObject *obj) {
118 if (obj == m_object)
119 return;
120 m_object = obj;
121 emit objectChanged();
122 }
123
objectListProperty()124 QDeclarativeListProperty<QObject> objectListProperty() { return QDeclarativeListProperty<QObject>(this, m_objectQList); }
125
methodCalled()126 bool methodCalled() const { return m_methodCalled; }
methodIntCalled()127 bool methodIntCalled() const { return m_methodIntCalled; }
128
string()129 QString string() const { return m_string; }
130
qmlAttachedProperties(QObject * o)131 static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) {
132 return new MyQmlAttachedObject(o);
133 }
134
deleteOnSet()135 int deleteOnSet() const { return 1; }
setDeleteOnSet(int v)136 void setDeleteOnSet(int v) { if(v) delete this; }
137
value()138 int value() const { return m_value; }
setValue(int v)139 void setValue(int v) { m_value = v; }
140
resettableProperty()141 int resettableProperty() const { return m_resetProperty; }
setResettableProperty(int v)142 void setResettableProperty(int v) { m_resetProperty = v; }
resetProperty()143 void resetProperty() { m_resetProperty = 13; }
144
regExp()145 QRegExp regExp() { return m_regExp; }
setRegExp(const QRegExp & regExp)146 void setRegExp(const QRegExp ®Exp) { m_regExp = regExp; }
147
console()148 int console() const { return 11; }
149
nonscriptable()150 int nonscriptable() const { return 0; }
setNonscriptable(int)151 void setNonscriptable(int) {}
152
153 MyQmlObject *myinvokableObject;
returnme()154 Q_INVOKABLE MyQmlObject *returnme() { return this; }
155
156 struct MyType {
157 int value;
158 };
variant()159 QVariant variant() const { return m_variant; }
160
161 signals:
162 void basicSignal();
163 void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
164 void stringChanged();
165 void objectChanged();
166 void anotherBasicSignal();
167 void thirdBasicSignal();
168 void signalWithUnknownType(const MyQmlObject::MyType &arg);
169
170 public slots:
deleteMe()171 void deleteMe() { delete this; }
methodNoArgs()172 void methodNoArgs() { m_methodCalled = true; }
method(int a)173 void method(int a) { if(a == 163) m_methodIntCalled = true; }
setString(const QString & s)174 void setString(const QString &s) { m_string = s; }
myinvokable(MyQmlObject * o)175 void myinvokable(MyQmlObject *o) { myinvokableObject = o; }
variantMethod(const QVariant & v)176 void variantMethod(const QVariant &v) { m_variant = v; }
177
178 private:
179 friend class tst_qdeclarativeecmascript;
180 bool m_methodCalled;
181 bool m_methodIntCalled;
182
183 QObject *m_object;
184 QString m_string;
185 QList<QObject *> m_objectQList;
186 int m_value;
187 int m_resetProperty;
188 QRegExp m_regExp;
189 QVariant m_variant;
190 };
191
QML_DECLARE_TYPEINFO(MyQmlObject,QML_HAS_ATTACHED_PROPERTIES)192 QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
193
194 class MyQmlContainer : public QObject
195 {
196 Q_OBJECT
197 Q_PROPERTY(QDeclarativeListProperty<MyQmlObject> children READ children CONSTANT)
198 public:
199 MyQmlContainer() {}
200
201 QDeclarativeListProperty<MyQmlObject> children() { return QDeclarativeListProperty<MyQmlObject>(this, m_children); }
202
203 private:
204 QList<MyQmlObject*> m_children;
205 };
206
207
208 class MyExpression : public QDeclarativeExpression
209 {
210 Q_OBJECT
211 public:
MyExpression(QDeclarativeContext * ctxt,const QString & expr)212 MyExpression(QDeclarativeContext *ctxt, const QString &expr)
213 : QDeclarativeExpression(ctxt, 0, expr), changed(false)
214 {
215 QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged()));
216 setNotifyOnValueChanged(true);
217 }
218
219 bool changed;
220
221 public slots:
expressionValueChanged()222 void expressionValueChanged() {
223 changed = true;
224 }
225 };
226
227
228 class MyDefaultObject1 : public QObject
229 {
230 Q_OBJECT
Q_PROPERTY(int horseLegs READ horseLegs CONSTANT)231 Q_PROPERTY(int horseLegs READ horseLegs CONSTANT)
232 Q_PROPERTY(int antLegs READ antLegs CONSTANT)
233 Q_PROPERTY(int emuLegs READ emuLegs CONSTANT)
234 public:
235 int horseLegs() const { return 4; }
antLegs()236 int antLegs() const { return 6; }
emuLegs()237 int emuLegs() const { return 2; }
238 };
239
240 class MyDefaultObject3 : public QObject
241 {
242 Q_OBJECT
Q_PROPERTY(int antLegs READ antLegs CONSTANT)243 Q_PROPERTY(int antLegs READ antLegs CONSTANT)
244 Q_PROPERTY(int humanLegs READ humanLegs CONSTANT)
245 public:
246 int antLegs() const { return 7; } // Mutant
humanLegs()247 int humanLegs() const { return 2; }
millipedeLegs()248 int millipedeLegs() const { return 1000; }
249 };
250
251 class MyDeferredObject : public QObject
252 {
253 Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)254 Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
255 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
256 Q_PROPERTY(QObject *objectProperty2 READ objectProperty2 WRITE setObjectProperty2)
257 Q_CLASSINFO("DeferredPropertyNames", "value,objectProperty,objectProperty2")
258
259 public:
260 MyDeferredObject() : m_value(0), m_object(0), m_object2(0) {}
261
value()262 int value() const { return m_value; }
setValue(int v)263 void setValue(int v) { m_value = v; emit valueChanged(); }
264
objectProperty()265 QObject *objectProperty() const { return m_object; }
setObjectProperty(QObject * obj)266 void setObjectProperty(QObject *obj) { m_object = obj; }
267
objectProperty2()268 QObject *objectProperty2() const { return m_object2; }
setObjectProperty2(QObject * obj)269 void setObjectProperty2(QObject *obj) { m_object2 = obj; }
270
271 signals:
272 void valueChanged();
273
274 private:
275 int m_value;
276 QObject *m_object;
277 QObject *m_object2;
278 };
279
280 class MyBaseExtendedObject : public QObject
281 {
282 Q_OBJECT
Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)283 Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)
284 public:
285 MyBaseExtendedObject() : m_value(0) {}
286
baseProperty()287 int baseProperty() const { return m_value; }
setBaseProperty(int v)288 void setBaseProperty(int v) { m_value = v; }
289
290 private:
291 int m_value;
292 };
293
294 class MyExtendedObject : public MyBaseExtendedObject
295 {
296 Q_OBJECT
Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty)297 Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty)
298 public:
299 MyExtendedObject() : m_value(0) {}
300
coreProperty()301 int coreProperty() const { return m_value; }
setCoreProperty(int v)302 void setCoreProperty(int v) { m_value = v; }
303
304 private:
305 int m_value;
306 };
307
308 class MyTypeObject : public QObject
309 {
310 Q_OBJECT
Q_ENUMS(MyEnum)311 Q_ENUMS(MyEnum)
312 Q_FLAGS(MyFlags)
313
314 Q_PROPERTY(QString id READ id WRITE setId)
315 Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty)
316 Q_PROPERTY(QDeclarativeComponent *componentProperty READ componentProperty WRITE setComponentProperty)
317 Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty)
318 Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty)
319 Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
320 Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty)
321 Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
322 Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty)
323 Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
324 Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty)
325 Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty)
326 Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
327 Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
328 Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
329 Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
330 Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
331 Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
332 Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty)
333 Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
334 Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2)
335 Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty)
336 Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
337 Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
338 Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
339 Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
340
341 Q_PROPERTY(QDeclarativeScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
342
343 public:
344 MyTypeObject()
345 : objectPropertyValue(0), componentPropertyValue(0) {}
346
347 QString idValue;
id()348 QString id() const {
349 return idValue;
350 }
setId(const QString & v)351 void setId(const QString &v) {
352 idValue = v;
353 }
354
355 QObject *objectPropertyValue;
objectProperty()356 QObject *objectProperty() const {
357 return objectPropertyValue;
358 }
setObjectProperty(QObject * v)359 void setObjectProperty(QObject *v) {
360 objectPropertyValue = v;
361 }
362
363 QDeclarativeComponent *componentPropertyValue;
componentProperty()364 QDeclarativeComponent *componentProperty() const {
365 return componentPropertyValue;
366 }
setComponentProperty(QDeclarativeComponent * v)367 void setComponentProperty(QDeclarativeComponent *v) {
368 componentPropertyValue = v;
369 }
370
371 enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
Q_DECLARE_FLAGS(MyFlags,MyFlag)372 Q_DECLARE_FLAGS(MyFlags, MyFlag)
373 MyFlags flagPropertyValue;
374 MyFlags flagProperty() const {
375 return flagPropertyValue;
376 }
setFlagProperty(MyFlags v)377 void setFlagProperty(MyFlags v) {
378 flagPropertyValue = v;
379 }
380
381 enum MyEnum { EnumVal1, EnumVal2 };
382 MyEnum enumPropertyValue;
enumProperty()383 MyEnum enumProperty() const {
384 return enumPropertyValue;
385 }
setEnumProperty(MyEnum v)386 void setEnumProperty(MyEnum v) {
387 enumPropertyValue = v;
388 }
389
390 QString stringPropertyValue;
stringProperty()391 QString stringProperty() const {
392 return stringPropertyValue;
393 }
setStringProperty(const QString & v)394 void setStringProperty(const QString &v) {
395 stringPropertyValue = v;
396 }
397
398 uint uintPropertyValue;
uintProperty()399 uint uintProperty() const {
400 return uintPropertyValue;
401 }
setUintProperty(const uint & v)402 void setUintProperty(const uint &v) {
403 uintPropertyValue = v;
404 }
405
406 int intPropertyValue;
intProperty()407 int intProperty() const {
408 return intPropertyValue;
409 }
setIntProperty(const int & v)410 void setIntProperty(const int &v) {
411 intPropertyValue = v;
412 }
413
414 qreal realPropertyValue;
realProperty()415 qreal realProperty() const {
416 return realPropertyValue;
417 }
setRealProperty(const qreal & v)418 void setRealProperty(const qreal &v) {
419 realPropertyValue = v;
420 }
421
422 double doublePropertyValue;
doubleProperty()423 double doubleProperty() const {
424 return doublePropertyValue;
425 }
setDoubleProperty(const double & v)426 void setDoubleProperty(const double &v) {
427 doublePropertyValue = v;
428 }
429
430 float floatPropertyValue;
floatProperty()431 float floatProperty() const {
432 return floatPropertyValue;
433 }
setFloatProperty(const float & v)434 void setFloatProperty(const float &v) {
435 floatPropertyValue = v;
436 }
437
438 QColor colorPropertyValue;
colorProperty()439 QColor colorProperty() const {
440 return colorPropertyValue;
441 }
setColorProperty(const QColor & v)442 void setColorProperty(const QColor &v) {
443 colorPropertyValue = v;
444 }
445
446 QDate datePropertyValue;
dateProperty()447 QDate dateProperty() const {
448 return datePropertyValue;
449 }
setDateProperty(const QDate & v)450 void setDateProperty(const QDate &v) {
451 datePropertyValue = v;
452 }
453
454 QTime timePropertyValue;
timeProperty()455 QTime timeProperty() const {
456 return timePropertyValue;
457 }
setTimeProperty(const QTime & v)458 void setTimeProperty(const QTime &v) {
459 timePropertyValue = v;
460 }
461
462 QDateTime dateTimePropertyValue;
dateTimeProperty()463 QDateTime dateTimeProperty() const {
464 return dateTimePropertyValue;
465 }
setDateTimeProperty(const QDateTime & v)466 void setDateTimeProperty(const QDateTime &v) {
467 dateTimePropertyValue = v;
468 }
469
470 QPoint pointPropertyValue;
pointProperty()471 QPoint pointProperty() const {
472 return pointPropertyValue;
473 }
setPointProperty(const QPoint & v)474 void setPointProperty(const QPoint &v) {
475 pointPropertyValue = v;
476 }
477
478 QPointF pointFPropertyValue;
pointFProperty()479 QPointF pointFProperty() const {
480 return pointFPropertyValue;
481 }
setPointFProperty(const QPointF & v)482 void setPointFProperty(const QPointF &v) {
483 pointFPropertyValue = v;
484 }
485
486 QSize sizePropertyValue;
sizeProperty()487 QSize sizeProperty() const {
488 return sizePropertyValue;
489 }
setSizeProperty(const QSize & v)490 void setSizeProperty(const QSize &v) {
491 sizePropertyValue = v;
492 }
493
494 QSizeF sizeFPropertyValue;
sizeFProperty()495 QSizeF sizeFProperty() const {
496 return sizeFPropertyValue;
497 }
setSizeFProperty(const QSizeF & v)498 void setSizeFProperty(const QSizeF &v) {
499 sizeFPropertyValue = v;
500 }
501
502 QRect rectPropertyValue;
rectProperty()503 QRect rectProperty() const {
504 return rectPropertyValue;
505 }
setRectProperty(const QRect & v)506 void setRectProperty(const QRect &v) {
507 rectPropertyValue = v;
508 emit rectPropertyChanged();
509 }
510
511 QRect rectPropertyValue2;
rectProperty2()512 QRect rectProperty2() const {
513 return rectPropertyValue2;
514 }
setRectProperty2(const QRect & v)515 void setRectProperty2(const QRect &v) {
516 rectPropertyValue2 = v;
517 }
518
519 QRectF rectFPropertyValue;
rectFProperty()520 QRectF rectFProperty() const {
521 return rectFPropertyValue;
522 }
setRectFProperty(const QRectF & v)523 void setRectFProperty(const QRectF &v) {
524 rectFPropertyValue = v;
525 }
526
527 bool boolPropertyValue;
boolProperty()528 bool boolProperty() const {
529 return boolPropertyValue;
530 }
setBoolProperty(const bool & v)531 void setBoolProperty(const bool &v) {
532 boolPropertyValue = v;
533 }
534
535 QVariant variantPropertyValue;
variantProperty()536 QVariant variantProperty() const {
537 return variantPropertyValue;
538 }
setVariantProperty(const QVariant & v)539 void setVariantProperty(const QVariant &v) {
540 variantPropertyValue = v;
541 }
542
543 QVector3D vectorPropertyValue;
vectorProperty()544 QVector3D vectorProperty() const {
545 return vectorPropertyValue;
546 }
setVectorProperty(const QVector3D & v)547 void setVectorProperty(const QVector3D &v) {
548 vectorPropertyValue = v;
549 }
550
551 QUrl urlPropertyValue;
urlProperty()552 QUrl urlProperty() const {
553 return urlPropertyValue;
554 }
setUrlProperty(const QUrl & v)555 void setUrlProperty(const QUrl &v) {
556 urlPropertyValue = v;
557 }
558
559 QDeclarativeScriptString scriptPropertyValue;
scriptProperty()560 QDeclarativeScriptString scriptProperty() const {
561 return scriptPropertyValue;
562 }
setScriptProperty(const QDeclarativeScriptString & v)563 void setScriptProperty(const QDeclarativeScriptString &v) {
564 scriptPropertyValue = v;
565 }
566
doAction()567 void doAction() { emit action(); }
568 signals:
569 void action();
570 void rectPropertyChanged();
571 };
Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)572 Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
573
574 class MyDerivedObject : public MyTypeObject
575 {
576 Q_OBJECT
577 public:
578 Q_INVOKABLE bool intProperty() const {
579 return true;
580 }
581 };
582
583 Q_DECLARE_METATYPE(QScriptValue);
584 class MyInvokableBaseObject : public QObject
585 {
586 Q_OBJECT
587 public:
588 inline ~MyInvokableBaseObject() = 0;
589
590 Q_INVOKABLE inline void method_inherited(int a);
591 Q_INVOKABLE inline void method_overload();
592 };
593
594 class MyInvokableObject : public MyInvokableBaseObject
595 {
596 Q_OBJECT
597 Q_ENUMS(TestEnum)
598 public:
599 enum TestEnum { EnumValue1, EnumValue2 };
MyInvokableObject()600 MyInvokableObject() { reset(); }
601
invoked()602 int invoked() const { return m_invoked; }
error()603 bool error() const { return m_invokedError; }
actuals()604 const QVariantList &actuals() const { return m_actuals; }
reset()605 void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); }
606
method_get_QPointF()607 Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); }
method_get_QPoint()608 Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); }
609
method_NoArgs()610 Q_INVOKABLE void method_NoArgs() { invoke(0); }
method_NoArgs_int()611 Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
method_NoArgs_real()612 Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
method_NoArgs_QPointF()613 Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
method_NoArgs_QObject()614 Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
method_NoArgs_unknown()615 Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
method_NoArgs_QScriptValue()616 Q_INVOKABLE QScriptValue method_NoArgs_QScriptValue() { invoke(6); return QScriptValue("Hello world"); }
method_NoArgs_QVariant()617 Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); }
618
method_int(int a)619 Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; }
method_intint(int a,int b)620 Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; }
method_real(qreal a)621 Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; }
method_QString(QString a)622 Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; }
method_QPointF(QPointF a)623 Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; }
method_QObject(QObject * a)624 Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); }
method_QScriptValue(QScriptValue a)625 Q_INVOKABLE void method_QScriptValue(QScriptValue a) { invoke(14); m_actuals << qVariantFromValue(a); }
method_intQScriptValue(int a,QScriptValue b)626 Q_INVOKABLE void method_intQScriptValue(int a, QScriptValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); }
627
method_overload(int a)628 Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
method_overload(int a,int b)629 Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
method_overload(QString a)630 Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
631
method_with_enum(TestEnum e)632 Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
633
634 Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
635
636 Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; }
637
638 private:
639 friend class MyInvokableBaseObject;
invoke(int idx)640 void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
641 int m_invoked;
642 bool m_invokedError;
643 QVariantList m_actuals;
644 };
645
~MyInvokableBaseObject()646 MyInvokableBaseObject::~MyInvokableBaseObject() {}
647
method_inherited(int a)648 void MyInvokableBaseObject::method_inherited(int a)
649 {
650 static_cast<MyInvokableObject *>(this)->invoke(-3);
651 static_cast<MyInvokableObject *>(this)->m_actuals << a;
652 }
653
654 // This is a hidden overload of the MyInvokableObject::method_overload() method
method_overload()655 void MyInvokableBaseObject::method_overload()
656 {
657 static_cast<MyInvokableObject *>(this)->invoke(-2);
658 }
659
660 class NumberAssignment : public QObject
661 {
662 Q_OBJECT
663 public:
664 Q_PROPERTY(qreal test1 READ test1 WRITE setTest1)
665 qreal _test1;
test1()666 qreal test1() const { return _test1; }
setTest1(qreal v)667 void setTest1(qreal v) { _test1 = v; }
668
669 Q_PROPERTY(qreal test2 READ test2 WRITE setTest2)
670 qreal _test2;
test2()671 qreal test2() const { return _test2; }
setTest2(qreal v)672 void setTest2(qreal v) { _test2 = v; }
673
674 Q_PROPERTY(qreal test3 READ test3 WRITE setTest3)
675 qreal _test3;
test3()676 qreal test3() const { return _test3; }
setTest3(qreal v)677 void setTest3(qreal v) { _test3 = v; }
678
679 Q_PROPERTY(qreal test4 READ test4 WRITE setTest4)
680 qreal _test4;
test4()681 qreal test4() const { return _test4; }
setTest4(qreal v)682 void setTest4(qreal v) { _test4 = v; }
683
684 Q_PROPERTY(int test5 READ test5 WRITE setTest5)
685 int _test5;
test5()686 int test5() const { return _test5; }
setTest5(int v)687 void setTest5(int v) { _test5 = v; }
688
689 Q_PROPERTY(int test6 READ test6 WRITE setTest6)
690 int _test6;
test6()691 int test6() const { return _test6; }
setTest6(int v)692 void setTest6(int v) { _test6 = v; }
693
694 Q_PROPERTY(int test7 READ test7 WRITE setTest7)
695 int _test7;
test7()696 int test7() const { return _test7; }
setTest7(int v)697 void setTest7(int v) { _test7 = v; }
698
699 Q_PROPERTY(int test8 READ test8 WRITE setTest8)
700 int _test8;
test8()701 int test8() const { return _test8; }
setTest8(int v)702 void setTest8(int v) { _test8 = v; }
703
704 Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9)
705 unsigned int _test9;
test9()706 unsigned int test9() const { return _test9; }
setTest9(unsigned int v)707 void setTest9(unsigned int v) { _test9 = v; }
708
709 Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10)
710 unsigned int _test10;
test10()711 unsigned int test10() const { return _test10; }
setTest10(unsigned int v)712 void setTest10(unsigned int v) { _test10 = v; }
713
714 Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11)
715 unsigned int _test11;
test11()716 unsigned int test11() const { return _test11; }
setTest11(unsigned int v)717 void setTest11(unsigned int v) { _test11 = v; }
718
719 Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12)
720 unsigned int _test12;
test12()721 unsigned int test12() const { return _test12; }
setTest12(unsigned int v)722 void setTest12(unsigned int v) { _test12 = v; }
723 };
724
725 class DefaultPropertyExtendedObject : public QObject
726 {
727 Q_OBJECT
Q_PROPERTY(QObject * firstProperty READ firstProperty WRITE setFirstProperty)728 Q_PROPERTY(QObject *firstProperty READ firstProperty WRITE setFirstProperty)
729 Q_PROPERTY(QObject *secondProperty READ secondProperty WRITE setSecondProperty)
730 public:
731 DefaultPropertyExtendedObject(QObject *parent = 0) : QObject(parent), m_firstProperty(0), m_secondProperty(0) {}
732
firstProperty()733 QObject *firstProperty() const { return m_firstProperty; }
secondProperty()734 QObject *secondProperty() const { return m_secondProperty; }
setFirstProperty(QObject * property)735 void setFirstProperty(QObject *property) { m_firstProperty = property; }
setSecondProperty(QObject * property)736 void setSecondProperty(QObject *property) { m_secondProperty = property; }
737 private:
738 QObject* m_firstProperty;
739 QObject* m_secondProperty;
740 };
741
742 class OverrideDefaultPropertyObject : public DefaultPropertyExtendedObject
743 {
744 Q_OBJECT
745 Q_CLASSINFO("DefaultProperty", "secondProperty")
746 public:
OverrideDefaultPropertyObject()747 OverrideDefaultPropertyObject() {}
748 };
749
750 class MyRevisionedBaseClassRegistered : public QObject
751 {
752 Q_OBJECT
Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)753 Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
754 Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
755
756 public:
757 MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
758
propA()759 qreal propA() const { return m_pa; }
setPropA(qreal p)760 void setPropA(qreal p) {
761 if (p != m_pa) {
762 m_pa = p;
763 emit propAChanged();
764 }
765 }
propB()766 qreal propB() const { return m_pb; }
setPropB(qreal p)767 void setPropB(qreal p) {
768 if (p != m_pb) {
769 m_pb = p;
770 emit propBChanged();
771 }
772 }
773
methodA()774 Q_INVOKABLE void methodA() { }
methodB()775 Q_INVOKABLE Q_REVISION(1) void methodB() { }
776
777 signals:
778 void propAChanged();
779 void propBChanged();
780
781 void signalA();
782 Q_REVISION(1) void signalB();
783
784 protected:
785 qreal m_pa;
786 qreal m_pb;
787 };
788
789 class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
790 {
791 Q_OBJECT
Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)792 Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
793 Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
794
795 public:
796 MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
797
propC()798 qreal propC() const { return m_pc; }
setPropC(qreal p)799 void setPropC(qreal p) {
800 if (p != m_pc) {
801 m_pc = p;
802 emit propCChanged();
803 }
804 }
propD()805 qreal propD() const { return m_pd; }
setPropD(qreal p)806 void setPropD(qreal p) {
807 if (p != m_pd) {
808 m_pd = p;
809 emit propDChanged();
810 }
811 }
812
methodC()813 Q_INVOKABLE void methodC() { }
methodD()814 Q_INVOKABLE Q_REVISION(1) void methodD() { }
815
816 signals:
817 void propCChanged();
818 void propDChanged();
819
820 void signalC();
821 Q_REVISION(1) void signalD();
822
823 protected:
824 qreal m_pc;
825 qreal m_pd;
826 };
827
828 class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
829 {
830 Q_OBJECT
Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)831 Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
832 Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
833
834 public:
835 MyRevisionedClass() {}
836
prop1()837 qreal prop1() const { return m_p1; }
setProp1(qreal p)838 void setProp1(qreal p) {
839 if (p != m_p1) {
840 m_p1 = p;
841 emit prop1Changed();
842 }
843 }
prop2()844 qreal prop2() const { return m_p2; }
setProp2(qreal p)845 void setProp2(qreal p) {
846 if (p != m_p2) {
847 m_p2 = p;
848 emit prop2Changed();
849 }
850 }
851
method1()852 Q_INVOKABLE void method1() { }
method2()853 Q_INVOKABLE Q_REVISION(1) void method2() { }
854
855 signals:
856 void prop1Changed();
857 void prop2Changed();
858
859 void signal1();
860 Q_REVISION(1) void signal2();
861
862 protected:
863 qreal m_p1;
864 qreal m_p2;
865 };
866
867 class MyRevisionedSubclass : public MyRevisionedClass
868 {
869 Q_OBJECT
Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)870 Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
871 Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
872
873 public:
874 MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
875
prop3()876 qreal prop3() const { return m_p3; }
setProp3(qreal p)877 void setProp3(qreal p) {
878 if (p != m_p3) {
879 m_p3 = p;
880 emit prop3Changed();
881 }
882 }
prop4()883 qreal prop4() const { return m_p4; }
setProp4(qreal p)884 void setProp4(qreal p) {
885 if (p != m_p4) {
886 m_p4 = p;
887 emit prop4Changed();
888 }
889 }
890
method3()891 Q_INVOKABLE void method3() { }
method4()892 Q_INVOKABLE Q_REVISION(1) void method4() { }
893
894 signals:
895 void prop3Changed();
896 void prop4Changed();
897
898 void signal3();
899 Q_REVISION(1) void signal4();
900
901 protected:
902 qreal m_p3;
903 qreal m_p4;
904 };
905
906 QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
907 QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
908 QML_DECLARE_TYPE(MyRevisionedClass)
909 QML_DECLARE_TYPE(MyRevisionedSubclass)
910 Q_DECLARE_METATYPE(MyQmlObject::MyType)
911
912 void registerTypes();
913
914 #endif // TESTTYPES_H
915
916