| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 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 https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | #ifndef TESTTYPES_H |
| 29 | #define TESTTYPES_H |
| 30 | |
| 31 | #include <QtCore/qobject.h> |
| 32 | #include <QtCore/qrect.h> |
| 33 | #include <QtCore/qdatetime.h> |
| 34 | #include <QtGui/qtransform.h> |
| 35 | #include <QtGui/qcolor.h> |
| 36 | #include <QtGui/qvector2d.h> |
| 37 | #include <QtGui/qvector3d.h> |
| 38 | #include <QtGui/qvector4d.h> |
| 39 | #include <QtGui/qquaternion.h> |
| 40 | #include <QtQml/qqml.h> |
| 41 | #include <QtQml/qqmlcomponent.h> |
| 42 | #include <QtQml/qqmlparserstatus.h> |
| 43 | #include <QtQml/qqmlpropertyvaluesource.h> |
| 44 | #include <QtQml/qqmlscriptstring.h> |
| 45 | #include <QtQml/qqmlproperty.h> |
| 46 | #include <private/qqmlcustomparser_p.h> |
| 47 | |
| 48 | QVariant myCustomVariantTypeConverter(const QString &data); |
| 49 | |
| 50 | class MyInterface |
| 51 | { |
| 52 | public: |
| 53 | MyInterface() : id(913) {} |
| 54 | int id; |
| 55 | }; |
| 56 | |
| 57 | QT_BEGIN_NAMESPACE |
| 58 | #define MyInterface_iid "org.qt-project.Qt.Test.MyInterface" |
| 59 | Q_DECLARE_INTERFACE(MyInterface, MyInterface_iid); |
| 60 | QT_END_NAMESPACE |
| 61 | QML_DECLARE_INTERFACE(MyInterface); |
| 62 | |
| 63 | struct MyCustomVariantType |
| 64 | { |
| 65 | MyCustomVariantType() : a(0) {} |
| 66 | int a; |
| 67 | }; |
| 68 | Q_DECLARE_METATYPE(MyCustomVariantType); |
| 69 | |
| 70 | class MyAttachedObject : public QObject |
| 71 | { |
| 72 | Q_OBJECT |
| 73 | Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) |
| 74 | Q_PROPERTY(int value2 READ value2 WRITE setValue2) |
| 75 | public: |
| 76 | MyAttachedObject(QObject *parent) : QObject(parent), m_value(0), m_value2(0) {} |
| 77 | |
| 78 | int value() const { return m_value; } |
| 79 | void setValue(int v) { if (m_value != v) { m_value = v; emit valueChanged(); } } |
| 80 | |
| 81 | int value2() const { return m_value2; } |
| 82 | void setValue2(int v) { m_value2 = v; } |
| 83 | |
| 84 | signals: |
| 85 | void valueChanged(); |
| 86 | |
| 87 | private: |
| 88 | int m_value; |
| 89 | int m_value2; |
| 90 | }; |
| 91 | |
| 92 | class SomethingUnknown : public QObject { |
| 93 | Q_OBJECT |
| 94 | }; |
| 95 | |
| 96 | class SomethingKnown : public SomethingUnknown { |
| 97 | Q_OBJECT |
| 98 | }; |
| 99 | |
| 100 | class MyQmlObject : public QObject, public MyInterface |
| 101 | { |
| 102 | Q_OBJECT |
| 103 | Q_PROPERTY(int value READ value WRITE setValue FINAL) |
| 104 | Q_PROPERTY(QString readOnlyString READ readOnlyString) |
| 105 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) |
| 106 | Q_PROPERTY(QRect rect READ rect WRITE setRect) |
| 107 | Q_PROPERTY(QTransform transform READ transform WRITE setTransform) //assumed to be unsupported by QML |
| 108 | Q_PROPERTY(MyInterface *interfaceProperty READ interface WRITE setInterface) |
| 109 | Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal) |
| 110 | Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType) |
| 111 | Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject) |
| 112 | Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) |
| 113 | Q_PROPERTY(int nonScriptable READ nonScriptable WRITE setNonScriptable SCRIPTABLE false) |
| 114 | Q_PROPERTY(QJSValue qjsvalue READ qjsvalue WRITE setQJSValue NOTIFY qjsvalueChanged) |
| 115 | Q_PROPERTY(SomethingUnknown* somethingUnknown READ somethingUnknown WRITE setSomethingUnknown NOTIFY somethingUnknownChanged) |
| 116 | |
| 117 | Q_INTERFACES(MyInterface) |
| 118 | public: |
| 119 | MyQmlObject(); |
| 120 | |
| 121 | int value() const { return m_value; } |
| 122 | void setValue(int v) { m_value = v; } |
| 123 | |
| 124 | QString readOnlyString() const { return QLatin1String("" ); } |
| 125 | |
| 126 | bool enabled() const { return false; } |
| 127 | void setEnabled(bool) {} |
| 128 | |
| 129 | QRect rect() const { return QRect(); } |
| 130 | void setRect(const QRect&) {} |
| 131 | |
| 132 | QTransform transform() const { return QTransform(); } |
| 133 | void setTransform(const QTransform &) {} |
| 134 | |
| 135 | MyInterface *interface() const { return m_interface; } |
| 136 | void setInterface(MyInterface *iface) { m_interface = iface; } |
| 137 | |
| 138 | static MyAttachedObject *qmlAttachedProperties(QObject *other) { |
| 139 | return new MyAttachedObject(other); |
| 140 | } |
| 141 | Q_CLASSINFO("DefaultMethod" , "basicSlot()" ) |
| 142 | |
| 143 | int onLiteralSignal() const { return m_value; } |
| 144 | void setOnLiteralSignal(int v) { m_value = v; } |
| 145 | |
| 146 | MyQmlObject *qmlobject() const { return m_qmlobject; } |
| 147 | void setQmlobject(MyQmlObject *o) { m_qmlobject = o; } |
| 148 | |
| 149 | MyCustomVariantType customType() const { return m_custom; } |
| 150 | void setCustomType(const MyCustomVariantType &v) { m_custom = v; } |
| 151 | |
| 152 | int propertyWithNotify() const { return m_propertyWithNotify; } |
| 153 | void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); } |
| 154 | |
| 155 | int nonScriptable() const { return 0; } |
| 156 | void setNonScriptable(int) {} |
| 157 | |
| 158 | QJSValue qjsvalue() const { return m_qjsvalue; } |
| 159 | void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); } |
| 160 | |
| 161 | int childAddedEventCount() const { return m_childAddedEventCount; } |
| 162 | |
| 163 | SomethingUnknown* somethingUnknown() const { return nullptr; } |
| 164 | void setSomethingUnknown(SomethingUnknown* something) { Q_UNUSED(something); } |
| 165 | |
| 166 | public slots: |
| 167 | void basicSlot() { qWarning(msg: "MyQmlObject::basicSlot" ); } |
| 168 | void basicSlotWithArgs(int v) { qWarning(msg: "MyQmlObject::basicSlotWithArgs(%d)" , v); } |
| 169 | void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; } |
| 170 | |
| 171 | signals: |
| 172 | void basicSignal(); |
| 173 | void basicParameterizedSignal(int parameter); |
| 174 | void oddlyNamedNotifySignal(); |
| 175 | void signalWithDefaultArg(int parameter = 5); |
| 176 | void qjsvalueChanged(); |
| 177 | void somethingUnknownChanged(); |
| 178 | |
| 179 | protected: |
| 180 | virtual bool event(QEvent *event); |
| 181 | |
| 182 | private: |
| 183 | friend class tst_qqmllanguage; |
| 184 | int m_value; |
| 185 | MyInterface *m_interface; |
| 186 | MyQmlObject *m_qmlobject; |
| 187 | MyCustomVariantType m_custom; |
| 188 | int m_propertyWithNotify; |
| 189 | QJSValue m_qjsvalue; |
| 190 | int m_childAddedEventCount; |
| 191 | }; |
| 192 | QML_DECLARE_TYPE(MyQmlObject) |
| 193 | QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES) |
| 194 | |
| 195 | class MyGroupedObject : public QObject |
| 196 | { |
| 197 | Q_OBJECT |
| 198 | Q_PROPERTY(QQmlScriptString script READ script WRITE setScript) |
| 199 | Q_PROPERTY(int value READ value WRITE setValue) |
| 200 | public: |
| 201 | QQmlScriptString script() const { return m_script; } |
| 202 | void setScript(const QQmlScriptString &s) { m_script = s; } |
| 203 | |
| 204 | int value() const { return m_value; } |
| 205 | void setValue(int v) { m_value = v; } |
| 206 | |
| 207 | private: |
| 208 | int m_value; |
| 209 | QQmlScriptString m_script; |
| 210 | }; |
| 211 | |
| 212 | |
| 213 | class MyEnumContainer : public QObject |
| 214 | { |
| 215 | Q_OBJECT |
| 216 | Q_ENUMS(RelatedEnum) |
| 217 | |
| 218 | public: |
| 219 | enum RelatedEnum { RelatedInvalid = -1, RelatedValue = 42 }; |
| 220 | }; |
| 221 | |
| 222 | class MyTypeObject : public QObject |
| 223 | { |
| 224 | Q_OBJECT |
| 225 | Q_ENUMS(MyEnum) |
| 226 | Q_ENUMS(MyMirroredEnum) |
| 227 | Q_ENUMS(MyEnumContainer::RelatedEnum) |
| 228 | Q_FLAGS(MyFlags) |
| 229 | |
| 230 | Q_PROPERTY(QString id READ id WRITE setId) |
| 231 | Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectPropertyChanged) |
| 232 | Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty) |
| 233 | Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty NOTIFY flagPropertyChanged) |
| 234 | Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty NOTIFY enumPropertyChanged) |
| 235 | Q_PROPERTY(MyEnum readOnlyEnumProperty READ readOnlyEnumProperty) |
| 236 | Q_PROPERTY(Qt::TextFormat qtEnumProperty READ qtEnumProperty WRITE setQtEnumProperty NOTIFY qtEnumPropertyChanged) |
| 237 | Q_PROPERTY(MyMirroredEnum mirroredEnumProperty READ mirroredEnumProperty WRITE setMirroredEnumProperty NOTIFY mirroredEnumPropertyChanged) |
| 238 | Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty) |
| 239 | Q_PROPERTY(MyScopedEnum scopedEnum READ scopedEnum WRITE setScopedEnum) |
| 240 | Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringPropertyChanged) |
| 241 | Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty NOTIFY byteArrayPropertyChanged) |
| 242 | Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty NOTIFY uintPropertyChanged) |
| 243 | Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged) |
| 244 | Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty NOTIFY realPropertyChanged) |
| 245 | Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty NOTIFY doublePropertyChanged) |
| 246 | Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty NOTIFY floatPropertyChanged) |
| 247 | Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty NOTIFY colorPropertyChanged) |
| 248 | Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty NOTIFY datePropertyChanged) |
| 249 | Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty NOTIFY timePropertyChanged) |
| 250 | Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty NOTIFY dateTimePropertyChanged) |
| 251 | Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty NOTIFY pointPropertyChanged) |
| 252 | Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty NOTIFY pointFPropertyChanged) |
| 253 | Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty NOTIFY sizePropertyChanged) |
| 254 | Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty NOTIFY sizeFPropertyChanged) |
| 255 | Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged) |
| 256 | Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2 ) |
| 257 | Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty NOTIFY rectFPropertyChanged) |
| 258 | Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty NOTIFY boolPropertyChanged) |
| 259 | Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty NOTIFY variantPropertyChanged) |
| 260 | Q_PROPERTY(QVector2D vector2Property READ vector2Property WRITE setVector2Property NOTIFY vector2PropertyChanged) |
| 261 | Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty NOTIFY vectorPropertyChanged) |
| 262 | Q_PROPERTY(QVector4D vector4Property READ vector4Property WRITE setVector4Property NOTIFY vector4PropertyChanged) |
| 263 | Q_PROPERTY(QQuaternion quaternionProperty READ quaternionProperty WRITE setQuaternionProperty NOTIFY quaternionPropertyChanged) |
| 264 | Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty NOTIFY urlPropertyChanged) |
| 265 | |
| 266 | Q_PROPERTY(QQmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty) |
| 267 | Q_PROPERTY(MyGroupedObject *grouped READ grouped CONSTANT) |
| 268 | Q_PROPERTY(MyGroupedObject *nullGrouped READ nullGrouped CONSTANT) |
| 269 | |
| 270 | Q_PROPERTY(MyTypeObject *selfGroupProperty READ selfGroupProperty) |
| 271 | |
| 272 | public: |
| 273 | MyTypeObject() |
| 274 | : objectPropertyValue(0), componentPropertyValue(0) {} |
| 275 | |
| 276 | QString idValue; |
| 277 | QString id() const { |
| 278 | return idValue; |
| 279 | } |
| 280 | void setId(const QString &v) { |
| 281 | idValue = v; |
| 282 | } |
| 283 | |
| 284 | QObject *objectPropertyValue; |
| 285 | QObject *objectProperty() const { |
| 286 | return objectPropertyValue; |
| 287 | } |
| 288 | void setObjectProperty(QObject *v) { |
| 289 | objectPropertyValue = v; |
| 290 | emit objectPropertyChanged(); |
| 291 | } |
| 292 | |
| 293 | QQmlComponent *componentPropertyValue; |
| 294 | QQmlComponent *componentProperty() const { |
| 295 | return componentPropertyValue; |
| 296 | } |
| 297 | void setComponentProperty(QQmlComponent *v) { |
| 298 | componentPropertyValue = v; |
| 299 | } |
| 300 | |
| 301 | enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; |
| 302 | Q_DECLARE_FLAGS(MyFlags, MyFlag) |
| 303 | MyFlags flagPropertyValue; |
| 304 | MyFlags flagProperty() const { |
| 305 | return flagPropertyValue; |
| 306 | } |
| 307 | void setFlagProperty(MyFlags v) { |
| 308 | flagPropertyValue = v; |
| 309 | emit flagPropertyChanged(); |
| 310 | } |
| 311 | |
| 312 | enum MyEnum { EnumVal1, EnumVal2, lowercaseEnumVal }; |
| 313 | MyEnum enumPropertyValue; |
| 314 | MyEnum enumProperty() const { |
| 315 | return enumPropertyValue; |
| 316 | } |
| 317 | void setEnumProperty(MyEnum v) { |
| 318 | enumPropertyValue = v; |
| 319 | emit enumPropertyChanged(); |
| 320 | } |
| 321 | |
| 322 | MyEnum readOnlyEnumProperty() const { |
| 323 | return EnumVal1; |
| 324 | } |
| 325 | |
| 326 | Qt::TextFormat qtEnumPropertyValue; |
| 327 | Qt::TextFormat qtEnumProperty() const { |
| 328 | return qtEnumPropertyValue; |
| 329 | } |
| 330 | void setQtEnumProperty(Qt::TextFormat v) { |
| 331 | qtEnumPropertyValue = v; |
| 332 | emit qtEnumPropertyChanged(); |
| 333 | } |
| 334 | |
| 335 | enum MyMirroredEnum { |
| 336 | MirroredEnumVal1 = Qt::AlignLeft, |
| 337 | MirroredEnumVal2 = Qt::AlignRight, |
| 338 | MirroredEnumVal3 = Qt::AlignHCenter }; |
| 339 | MyMirroredEnum mirroredEnumPropertyValue; |
| 340 | MyMirroredEnum mirroredEnumProperty() const { |
| 341 | return mirroredEnumPropertyValue; |
| 342 | } |
| 343 | void setMirroredEnumProperty(MyMirroredEnum v) { |
| 344 | mirroredEnumPropertyValue = v; |
| 345 | emit mirroredEnumPropertyChanged(); |
| 346 | } |
| 347 | |
| 348 | MyEnumContainer::RelatedEnum relatedEnumPropertyValue; |
| 349 | MyEnumContainer::RelatedEnum relatedEnumProperty() const { |
| 350 | return relatedEnumPropertyValue; |
| 351 | } |
| 352 | void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) { |
| 353 | relatedEnumPropertyValue = v; |
| 354 | } |
| 355 | |
| 356 | enum class MyScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3 }; |
| 357 | Q_ENUM(MyScopedEnum) |
| 358 | MyScopedEnum scopedEnumPropertyValue; |
| 359 | MyScopedEnum scopedEnum() const { return scopedEnumPropertyValue; } |
| 360 | void setScopedEnum(MyScopedEnum v) { |
| 361 | scopedEnumPropertyValue = v; |
| 362 | } |
| 363 | |
| 364 | QString stringPropertyValue; |
| 365 | QString stringProperty() const { |
| 366 | return stringPropertyValue; |
| 367 | } |
| 368 | void setStringProperty(const QString &v) { |
| 369 | stringPropertyValue = v; |
| 370 | emit stringPropertyChanged(); |
| 371 | } |
| 372 | |
| 373 | QByteArray byteArrayPropertyValue; |
| 374 | QByteArray byteArrayProperty() const { |
| 375 | return byteArrayPropertyValue; |
| 376 | } |
| 377 | void setByteArrayProperty(const QByteArray &v) { |
| 378 | byteArrayPropertyValue = v; |
| 379 | emit byteArrayPropertyChanged(); |
| 380 | } |
| 381 | |
| 382 | uint uintPropertyValue; |
| 383 | uint uintProperty() const { |
| 384 | return uintPropertyValue; |
| 385 | } |
| 386 | void setUintProperty(const uint &v) { |
| 387 | uintPropertyValue = v; |
| 388 | emit uintPropertyChanged(); |
| 389 | } |
| 390 | |
| 391 | int intPropertyValue; |
| 392 | int intProperty() const { |
| 393 | return intPropertyValue; |
| 394 | } |
| 395 | void setIntProperty(const int &v) { |
| 396 | intPropertyValue = v; |
| 397 | emit intPropertyChanged(); |
| 398 | } |
| 399 | |
| 400 | qreal realPropertyValue; |
| 401 | qreal realProperty() const { |
| 402 | return realPropertyValue; |
| 403 | } |
| 404 | void setRealProperty(const qreal &v) { |
| 405 | realPropertyValue = v; |
| 406 | emit realPropertyChanged(); |
| 407 | } |
| 408 | |
| 409 | double doublePropertyValue; |
| 410 | double doubleProperty() const { |
| 411 | return doublePropertyValue; |
| 412 | } |
| 413 | void setDoubleProperty(const double &v) { |
| 414 | doublePropertyValue = v; |
| 415 | emit doublePropertyChanged(); |
| 416 | } |
| 417 | |
| 418 | float floatPropertyValue; |
| 419 | float floatProperty() const { |
| 420 | return floatPropertyValue; |
| 421 | } |
| 422 | void setFloatProperty(const float &v) { |
| 423 | floatPropertyValue = v; |
| 424 | emit floatPropertyChanged(); |
| 425 | } |
| 426 | |
| 427 | QColor colorPropertyValue; |
| 428 | QColor colorProperty() const { |
| 429 | return colorPropertyValue; |
| 430 | } |
| 431 | void setColorProperty(const QColor &v) { |
| 432 | colorPropertyValue = v; |
| 433 | emit colorPropertyChanged(); |
| 434 | } |
| 435 | |
| 436 | QDate datePropertyValue; |
| 437 | QDate dateProperty() const { |
| 438 | return datePropertyValue; |
| 439 | } |
| 440 | void setDateProperty(const QDate &v) { |
| 441 | datePropertyValue = v; |
| 442 | emit datePropertyChanged(); |
| 443 | } |
| 444 | |
| 445 | QTime timePropertyValue; |
| 446 | QTime timeProperty() const { |
| 447 | return timePropertyValue; |
| 448 | } |
| 449 | void setTimeProperty(const QTime &v) { |
| 450 | timePropertyValue = v; |
| 451 | emit timePropertyChanged(); |
| 452 | } |
| 453 | |
| 454 | QDateTime dateTimePropertyValue; |
| 455 | QDateTime dateTimeProperty() const { |
| 456 | return dateTimePropertyValue; |
| 457 | } |
| 458 | void setDateTimeProperty(const QDateTime &v) { |
| 459 | dateTimePropertyValue = v; |
| 460 | emit dateTimePropertyChanged(); |
| 461 | } |
| 462 | |
| 463 | QPoint pointPropertyValue; |
| 464 | QPoint pointProperty() const { |
| 465 | return pointPropertyValue; |
| 466 | } |
| 467 | void setPointProperty(const QPoint &v) { |
| 468 | pointPropertyValue = v; |
| 469 | emit pointPropertyChanged(); |
| 470 | } |
| 471 | |
| 472 | QPointF pointFPropertyValue; |
| 473 | QPointF pointFProperty() const { |
| 474 | return pointFPropertyValue; |
| 475 | } |
| 476 | void setPointFProperty(const QPointF &v) { |
| 477 | pointFPropertyValue = v; |
| 478 | emit pointFPropertyChanged(); |
| 479 | } |
| 480 | |
| 481 | QSize sizePropertyValue; |
| 482 | QSize sizeProperty() const { |
| 483 | return sizePropertyValue; |
| 484 | } |
| 485 | void setSizeProperty(const QSize &v) { |
| 486 | sizePropertyValue = v; |
| 487 | emit sizePropertyChanged(); |
| 488 | } |
| 489 | |
| 490 | QSizeF sizeFPropertyValue; |
| 491 | QSizeF sizeFProperty() const { |
| 492 | return sizeFPropertyValue; |
| 493 | } |
| 494 | void setSizeFProperty(const QSizeF &v) { |
| 495 | sizeFPropertyValue = v; |
| 496 | emit sizeFPropertyChanged(); |
| 497 | } |
| 498 | |
| 499 | QRect rectPropertyValue; |
| 500 | QRect rectProperty() const { |
| 501 | return rectPropertyValue; |
| 502 | } |
| 503 | void setRectProperty(const QRect &v) { |
| 504 | rectPropertyValue = v; |
| 505 | emit rectPropertyChanged(); |
| 506 | } |
| 507 | |
| 508 | QRect rectPropertyValue2; |
| 509 | QRect rectProperty2() const { |
| 510 | return rectPropertyValue2; |
| 511 | } |
| 512 | void setRectProperty2(const QRect &v) { |
| 513 | rectPropertyValue2 = v; |
| 514 | } |
| 515 | |
| 516 | QRectF rectFPropertyValue; |
| 517 | QRectF rectFProperty() const { |
| 518 | return rectFPropertyValue; |
| 519 | } |
| 520 | void setRectFProperty(const QRectF &v) { |
| 521 | rectFPropertyValue = v; |
| 522 | emit rectFPropertyChanged(); |
| 523 | } |
| 524 | |
| 525 | bool boolPropertyValue; |
| 526 | bool boolProperty() const { |
| 527 | return boolPropertyValue; |
| 528 | } |
| 529 | void setBoolProperty(const bool &v) { |
| 530 | boolPropertyValue = v; |
| 531 | emit boolPropertyChanged(); |
| 532 | } |
| 533 | |
| 534 | QVariant variantPropertyValue; |
| 535 | QVariant variantProperty() const { |
| 536 | return variantPropertyValue; |
| 537 | } |
| 538 | void setVariantProperty(const QVariant &v) { |
| 539 | variantPropertyValue = v; |
| 540 | emit variantPropertyChanged(); |
| 541 | } |
| 542 | |
| 543 | QVector3D vectorPropertyValue; |
| 544 | QVector3D vectorProperty() const { |
| 545 | return vectorPropertyValue; |
| 546 | } |
| 547 | void setVectorProperty(const QVector3D &v) { |
| 548 | vectorPropertyValue = v; |
| 549 | emit vectorPropertyChanged(); |
| 550 | } |
| 551 | |
| 552 | QVector2D vector2PropertyValue; |
| 553 | QVector2D vector2Property() const { |
| 554 | return vector2PropertyValue; |
| 555 | } |
| 556 | void setVector2Property(const QVector2D &v) { |
| 557 | vector2PropertyValue = v; |
| 558 | emit vector2PropertyChanged(); |
| 559 | } |
| 560 | |
| 561 | QVector4D vector4PropertyValue; |
| 562 | QVector4D vector4Property() const { |
| 563 | return vector4PropertyValue; |
| 564 | } |
| 565 | void setVector4Property(const QVector4D &v) { |
| 566 | vector4PropertyValue = v; |
| 567 | emit vector4PropertyChanged(); |
| 568 | } |
| 569 | |
| 570 | QQuaternion quaternionPropertyValue; |
| 571 | QQuaternion quaternionProperty() const { |
| 572 | return quaternionPropertyValue; |
| 573 | } |
| 574 | void setQuaternionProperty(const QQuaternion &v) { |
| 575 | quaternionPropertyValue = v; |
| 576 | emit quaternionPropertyChanged(); |
| 577 | } |
| 578 | |
| 579 | QUrl urlPropertyValue; |
| 580 | QUrl urlProperty() const { |
| 581 | return urlPropertyValue; |
| 582 | } |
| 583 | void setUrlProperty(const QUrl &v) { |
| 584 | urlPropertyValue = v; |
| 585 | emit urlPropertyChanged(); |
| 586 | } |
| 587 | |
| 588 | QQmlScriptString scriptPropertyValue; |
| 589 | QQmlScriptString scriptProperty() const { |
| 590 | return scriptPropertyValue; |
| 591 | } |
| 592 | void setScriptProperty(const QQmlScriptString &v) { |
| 593 | scriptPropertyValue = v; |
| 594 | } |
| 595 | |
| 596 | MyGroupedObject groupedValue; |
| 597 | MyGroupedObject *grouped() { return &groupedValue; } |
| 598 | |
| 599 | MyGroupedObject *nullGrouped() { return 0; } |
| 600 | |
| 601 | MyTypeObject *selfGroupProperty() { return this; } |
| 602 | |
| 603 | void doAction() { emit action(); } |
| 604 | signals: |
| 605 | void action(); |
| 606 | |
| 607 | void objectPropertyChanged(); |
| 608 | void flagPropertyChanged(); |
| 609 | void enumPropertyChanged(); |
| 610 | void qtEnumPropertyChanged(); |
| 611 | void mirroredEnumPropertyChanged(); |
| 612 | void stringPropertyChanged(); |
| 613 | void byteArrayPropertyChanged(); |
| 614 | void uintPropertyChanged(); |
| 615 | void intPropertyChanged(); |
| 616 | void realPropertyChanged(); |
| 617 | void doublePropertyChanged(); |
| 618 | void floatPropertyChanged(); |
| 619 | void colorPropertyChanged(); |
| 620 | void datePropertyChanged(); |
| 621 | void timePropertyChanged(); |
| 622 | void dateTimePropertyChanged(); |
| 623 | void pointPropertyChanged(); |
| 624 | void pointFPropertyChanged(); |
| 625 | void sizePropertyChanged(); |
| 626 | void sizeFPropertyChanged(); |
| 627 | void rectPropertyChanged(); |
| 628 | void rectFPropertyChanged(); |
| 629 | void boolPropertyChanged(); |
| 630 | void variantPropertyChanged(); |
| 631 | void vectorPropertyChanged(); |
| 632 | void vector2PropertyChanged(); |
| 633 | void vector4PropertyChanged(); |
| 634 | void quaternionPropertyChanged(); |
| 635 | void urlPropertyChanged(); |
| 636 | |
| 637 | }; |
| 638 | Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags) |
| 639 | |
| 640 | // FIXME: If no subclass is used for the singleton registration with qmlRegisterSingletonType(), |
| 641 | // the valueTypes() test will fail. |
| 642 | class MyTypeObjectSingleton : public MyTypeObject |
| 643 | { |
| 644 | Q_OBJECT |
| 645 | }; |
| 646 | |
| 647 | class MyContainer : public QObject |
| 648 | { |
| 649 | Q_OBJECT |
| 650 | Q_PROPERTY(QQmlListProperty<QObject> children READ children) |
| 651 | Q_PROPERTY(QQmlListProperty<MyContainer> containerChildren READ containerChildren) |
| 652 | Q_PROPERTY(QQmlListProperty<MyInterface> qlistInterfaces READ qlistInterfaces) |
| 653 | Q_CLASSINFO("DefaultProperty" , "children" ) |
| 654 | public: |
| 655 | MyContainer() {} |
| 656 | |
| 657 | QQmlListProperty<QObject> children() { return QQmlListProperty<QObject>(this, m_children); } |
| 658 | QQmlListProperty<MyContainer> containerChildren() { return QQmlListProperty<MyContainer>(this, m_containerChildren); } |
| 659 | QList<QObject *> *getChildren() { return &m_children; } |
| 660 | QQmlListProperty<MyInterface> qlistInterfaces() { return QQmlListProperty<MyInterface>(this, m_interfaces); } |
| 661 | QList<MyInterface *> *getQListInterfaces() { return &m_interfaces; } |
| 662 | |
| 663 | QList<MyContainer*> m_containerChildren; |
| 664 | QList<QObject*> m_children; |
| 665 | QList<MyInterface *> m_interfaces; |
| 666 | }; |
| 667 | |
| 668 | |
| 669 | class MyPropertyValueSource : public QObject, public QQmlPropertyValueSource |
| 670 | { |
| 671 | Q_OBJECT |
| 672 | Q_INTERFACES(QQmlPropertyValueSource) |
| 673 | public: |
| 674 | MyPropertyValueSource() |
| 675 | : QQmlPropertyValueSource() {} |
| 676 | |
| 677 | QQmlProperty prop; |
| 678 | virtual void setTarget(const QQmlProperty &p) |
| 679 | { |
| 680 | prop = p; |
| 681 | } |
| 682 | }; |
| 683 | |
| 684 | class UnavailableType : public QObject |
| 685 | { |
| 686 | Q_OBJECT |
| 687 | public: |
| 688 | UnavailableType() {} |
| 689 | }; |
| 690 | |
| 691 | class MyReceiversTestObject : public QObject |
| 692 | { |
| 693 | Q_OBJECT |
| 694 | |
| 695 | Q_PROPERTY(int prop READ prop NOTIFY propChanged) |
| 696 | public: |
| 697 | MyReceiversTestObject() {} |
| 698 | |
| 699 | int prop() const { return 5; } |
| 700 | |
| 701 | int mySignalCount() { return receivers(SIGNAL(mySignal())); } |
| 702 | int propChangedCount() { return receivers(SIGNAL(propChanged())); } |
| 703 | int myUnconnectedSignalCount() { return receivers(SIGNAL(myUnconnectedSignal())); } |
| 704 | |
| 705 | signals: |
| 706 | void mySignal(); |
| 707 | void propChanged(); |
| 708 | void myUnconnectedSignal(); |
| 709 | |
| 710 | private: |
| 711 | friend class tst_qqmllanguage; |
| 712 | }; |
| 713 | |
| 714 | class MyDotPropertyObject : public QObject |
| 715 | { |
| 716 | Q_OBJECT |
| 717 | Q_PROPERTY(MyQmlObject *obj READ obj) |
| 718 | Q_PROPERTY(MyQmlObject *readWriteObj READ readWriteObj WRITE setReadWriteObj) |
| 719 | public: |
| 720 | MyDotPropertyObject() : m_rwobj(0), m_ownRWObj(false) {} |
| 721 | ~MyDotPropertyObject() |
| 722 | { |
| 723 | if (m_ownRWObj) |
| 724 | delete m_rwobj; |
| 725 | } |
| 726 | |
| 727 | MyQmlObject *obj() { return 0; } |
| 728 | |
| 729 | MyQmlObject *readWriteObj() |
| 730 | { |
| 731 | if (!m_rwobj) { |
| 732 | m_rwobj = new MyQmlObject; |
| 733 | m_ownRWObj = true; |
| 734 | } |
| 735 | return m_rwobj; |
| 736 | } |
| 737 | |
| 738 | void setReadWriteObj(MyQmlObject *obj) |
| 739 | { |
| 740 | if (m_ownRWObj) { |
| 741 | delete m_rwobj; |
| 742 | m_ownRWObj = false; |
| 743 | } |
| 744 | |
| 745 | m_rwobj = obj; |
| 746 | } |
| 747 | |
| 748 | private: |
| 749 | MyQmlObject *m_rwobj; |
| 750 | bool m_ownRWObj; |
| 751 | }; |
| 752 | |
| 753 | namespace MyStaticNamespace { |
| 754 | Q_NAMESPACE |
| 755 | QML_ELEMENT |
| 756 | |
| 757 | enum MyNSEnum { |
| 758 | Key1 = 1, |
| 759 | Key2, |
| 760 | Key5 = 5 |
| 761 | }; |
| 762 | Q_ENUM_NS(MyNSEnum); |
| 763 | |
| 764 | enum class MyOtherNSEnum { |
| 765 | OtherKey1 = 1, |
| 766 | OtherKey2 |
| 767 | }; |
| 768 | Q_ENUM_NS(MyOtherNSEnum); |
| 769 | |
| 770 | |
| 771 | class MyNamespacedType : public QObject |
| 772 | { |
| 773 | Q_OBJECT |
| 774 | Q_PROPERTY(MyStaticNamespace::MyNSEnum myEnum MEMBER m_myEnum) |
| 775 | QML_NAMED_ELEMENT(MyStaticNamespacedType) |
| 776 | MyStaticNamespace::MyNSEnum m_myEnum = MyNSEnum::Key1; |
| 777 | }; |
| 778 | |
| 779 | class MySecondNamespacedType : public QObject |
| 780 | { |
| 781 | Q_OBJECT |
| 782 | Q_PROPERTY(QQmlListProperty<MyStaticNamespace::MyNamespacedType> list READ list) |
| 783 | QML_NAMED_ELEMENT(MyStaticSecondNamespacedType) |
| 784 | public: |
| 785 | QQmlListProperty<MyNamespacedType> list() |
| 786 | { |
| 787 | return QQmlListProperty<MyNamespacedType>(this, &m_list); |
| 788 | } |
| 789 | |
| 790 | private: |
| 791 | QList<MyNamespacedType *> m_list; |
| 792 | }; |
| 793 | } |
| 794 | |
| 795 | namespace MyNamespace { |
| 796 | Q_NAMESPACE |
| 797 | enum MyNSEnum { |
| 798 | Key1 = 1, |
| 799 | Key2, |
| 800 | Key5 = 5 |
| 801 | }; |
| 802 | Q_ENUM_NS(MyNSEnum); |
| 803 | |
| 804 | enum class MyOtherNSEnum { |
| 805 | OtherKey1 = 1, |
| 806 | OtherKey2 |
| 807 | }; |
| 808 | Q_ENUM_NS(MyOtherNSEnum); |
| 809 | |
| 810 | |
| 811 | class MyNamespacedType : public QObject |
| 812 | { |
| 813 | Q_OBJECT |
| 814 | Q_PROPERTY(MyNamespace::MyNSEnum myEnum MEMBER m_myEnum) |
| 815 | MyNamespace::MyNSEnum m_myEnum = MyNSEnum::Key1; |
| 816 | }; |
| 817 | |
| 818 | class MySecondNamespacedType : public QObject |
| 819 | { |
| 820 | Q_OBJECT |
| 821 | Q_PROPERTY(QQmlListProperty<MyNamespace::MyNamespacedType> list READ list) |
| 822 | public: |
| 823 | QQmlListProperty<MyNamespacedType> list() { return QQmlListProperty<MyNamespacedType>(this, m_list); } |
| 824 | |
| 825 | private: |
| 826 | QList<MyNamespacedType *> m_list; |
| 827 | }; |
| 828 | } |
| 829 | |
| 830 | class MyCustomParserType : public QObject |
| 831 | { |
| 832 | Q_OBJECT |
| 833 | }; |
| 834 | |
| 835 | class MyCustomParserTypeParser : public QQmlCustomParser |
| 836 | { |
| 837 | public: |
| 838 | virtual void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) {} |
| 839 | virtual void applyBindings(QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) {} |
| 840 | }; |
| 841 | |
| 842 | class EnumSupportingCustomParser : public QQmlCustomParser |
| 843 | { |
| 844 | public: |
| 845 | virtual void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &); |
| 846 | virtual void applyBindings(QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) {} |
| 847 | }; |
| 848 | |
| 849 | class MyParserStatus : public QObject, public QQmlParserStatus |
| 850 | { |
| 851 | Q_INTERFACES(QQmlParserStatus) |
| 852 | Q_OBJECT |
| 853 | public: |
| 854 | MyParserStatus() : m_cbc(0), m_ccc(0) {} |
| 855 | |
| 856 | int classBeginCount() const { return m_cbc; } |
| 857 | int componentCompleteCount() const { return m_ccc; } |
| 858 | |
| 859 | virtual void classBegin() { m_cbc++; } |
| 860 | virtual void componentComplete() { m_ccc++; } |
| 861 | private: |
| 862 | int m_cbc; |
| 863 | int m_ccc; |
| 864 | }; |
| 865 | |
| 866 | class MyRevisionedBaseClassRegistered : public QObject |
| 867 | { |
| 868 | Q_OBJECT |
| 869 | Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged) |
| 870 | Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1) |
| 871 | |
| 872 | public: |
| 873 | MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {} |
| 874 | |
| 875 | qreal propA() const { return m_pa; } |
| 876 | void setPropA(qreal p) { |
| 877 | if (p != m_pa) { |
| 878 | m_pa = p; |
| 879 | emit propAChanged(); |
| 880 | } |
| 881 | } |
| 882 | qreal propB() const { return m_pb; } |
| 883 | void setPropB(qreal p) { |
| 884 | if (p != m_pb) { |
| 885 | m_pb = p; |
| 886 | emit propBChanged(); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | Q_INVOKABLE void methodA() { } |
| 891 | Q_INVOKABLE Q_REVISION(1) void methodB() { } |
| 892 | |
| 893 | signals: |
| 894 | void propAChanged(); |
| 895 | void propBChanged(); |
| 896 | |
| 897 | void signalA(); |
| 898 | Q_REVISION(1) void signalB(); |
| 899 | |
| 900 | protected: |
| 901 | qreal m_pa; |
| 902 | qreal m_pb; |
| 903 | }; |
| 904 | |
| 905 | class MyRevisionedIllegalOverload : public MyRevisionedBaseClassRegistered |
| 906 | { |
| 907 | Q_OBJECT |
| 908 | Q_PROPERTY(qreal propA READ propA WRITE setPropA REVISION 1); |
| 909 | }; |
| 910 | |
| 911 | class MyRevisionedLegalOverload : public MyRevisionedBaseClassRegistered |
| 912 | { |
| 913 | Q_OBJECT |
| 914 | Q_PROPERTY(qreal propB READ propB WRITE setPropB REVISION 1); |
| 915 | }; |
| 916 | |
| 917 | class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered |
| 918 | { |
| 919 | Q_OBJECT |
| 920 | Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged) |
| 921 | Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1) |
| 922 | |
| 923 | public: |
| 924 | MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {} |
| 925 | |
| 926 | qreal propC() const { return m_pc; } |
| 927 | void setPropC(qreal p) { |
| 928 | if (p != m_pc) { |
| 929 | m_pc = p; |
| 930 | emit propCChanged(); |
| 931 | } |
| 932 | } |
| 933 | qreal propD() const { return m_pd; } |
| 934 | void setPropD(qreal p) { |
| 935 | if (p != m_pd) { |
| 936 | m_pd = p; |
| 937 | emit propDChanged(); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | Q_INVOKABLE void methodC() { } |
| 942 | Q_INVOKABLE Q_REVISION(1) void methodD() { } |
| 943 | |
| 944 | signals: |
| 945 | void propCChanged(); |
| 946 | void propDChanged(); |
| 947 | |
| 948 | void signalC(); |
| 949 | Q_REVISION(1) void signalD(); |
| 950 | |
| 951 | protected: |
| 952 | qreal m_pc; |
| 953 | qreal m_pd; |
| 954 | }; |
| 955 | |
| 956 | class MyRevisionedClass : public MyRevisionedBaseClassUnregistered |
| 957 | { |
| 958 | Q_OBJECT |
| 959 | Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed) |
| 960 | Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1) |
| 961 | |
| 962 | public: |
| 963 | MyRevisionedClass() : m_p1(1), m_p2(2) {} |
| 964 | |
| 965 | qreal prop1() const { return m_p1; } |
| 966 | void setProp1(qreal p) { |
| 967 | if (p != m_p1) { |
| 968 | m_p1 = p; |
| 969 | emit prop1Changed(); |
| 970 | } |
| 971 | } |
| 972 | qreal prop2() const { return m_p2; } |
| 973 | void setProp2(qreal p) { |
| 974 | if (p != m_p2) { |
| 975 | m_p2 = p; |
| 976 | emit prop2Changed(); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | Q_INVOKABLE void method1() { } |
| 981 | Q_INVOKABLE Q_REVISION(1) void method2() { } |
| 982 | |
| 983 | signals: |
| 984 | void prop1Changed(); |
| 985 | void prop2Changed(); |
| 986 | |
| 987 | void signal1(); |
| 988 | Q_REVISION(1) void signal2(); |
| 989 | |
| 990 | protected: |
| 991 | qreal m_p1; |
| 992 | qreal m_p2; |
| 993 | }; |
| 994 | |
| 995 | class MyRevisionedSubclass : public MyRevisionedClass |
| 996 | { |
| 997 | Q_OBJECT |
| 998 | Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed) |
| 999 | Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1) |
| 1000 | |
| 1001 | public: |
| 1002 | MyRevisionedSubclass() : m_p3(3), m_p4(4) {} |
| 1003 | |
| 1004 | qreal prop3() const { return m_p3; } |
| 1005 | void setProp3(qreal p) { |
| 1006 | if (p != m_p3) { |
| 1007 | m_p3 = p; |
| 1008 | emit prop3Changed(); |
| 1009 | } |
| 1010 | } |
| 1011 | qreal prop4() const { return m_p4; } |
| 1012 | void setProp4(qreal p) { |
| 1013 | if (p != m_p4) { |
| 1014 | m_p4 = p; |
| 1015 | emit prop4Changed(); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | Q_INVOKABLE void method3() { } |
| 1020 | Q_INVOKABLE Q_REVISION(1) void method4() { } |
| 1021 | |
| 1022 | signals: |
| 1023 | void prop3Changed(); |
| 1024 | void prop4Changed(); |
| 1025 | |
| 1026 | void signal3(); |
| 1027 | Q_REVISION(1) void signal4(); |
| 1028 | |
| 1029 | protected: |
| 1030 | qreal m_p3; |
| 1031 | qreal m_p4; |
| 1032 | }; |
| 1033 | |
| 1034 | class MySubclass : public MyRevisionedClass |
| 1035 | { |
| 1036 | Q_OBJECT |
| 1037 | Q_PROPERTY(qreal prop5 READ prop5 WRITE setProp5 NOTIFY prop5Changed) |
| 1038 | |
| 1039 | public: |
| 1040 | MySubclass() : m_p5(5) {} |
| 1041 | |
| 1042 | qreal prop5() const { return m_p5; } |
| 1043 | void setProp5(qreal p) { |
| 1044 | if (p != m_p5) { |
| 1045 | m_p5 = p; |
| 1046 | emit prop5Changed(); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | Q_INVOKABLE void method5() { } |
| 1051 | |
| 1052 | signals: |
| 1053 | void prop5Changed(); |
| 1054 | |
| 1055 | protected: |
| 1056 | qreal m_p5; |
| 1057 | }; |
| 1058 | |
| 1059 | class MyUncreateableBaseClass : public QObject |
| 1060 | { |
| 1061 | Q_OBJECT |
| 1062 | Q_PROPERTY(bool prop1 READ prop1 WRITE setprop1) |
| 1063 | Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1) |
| 1064 | Q_PROPERTY(bool prop3 READ prop3 WRITE setprop3 REVISION 1) |
| 1065 | public: |
| 1066 | explicit MyUncreateableBaseClass(bool /* arg */, QObject *parent = 0) |
| 1067 | : QObject(parent), _prop1(false), _prop2(false), _prop3(false) |
| 1068 | { |
| 1069 | } |
| 1070 | |
| 1071 | bool _prop1; |
| 1072 | bool prop1() const { return _prop1; } |
| 1073 | void setprop1(bool p) { _prop1 = p; } |
| 1074 | bool _prop2; |
| 1075 | bool prop2() const { return _prop2; } |
| 1076 | void setprop2(bool p) { _prop2 = p; } |
| 1077 | bool _prop3; |
| 1078 | bool prop3() const { return _prop3; } |
| 1079 | void setprop3(bool p) { _prop3 = p; } |
| 1080 | }; |
| 1081 | |
| 1082 | class MyCreateableDerivedClass : public MyUncreateableBaseClass |
| 1083 | { |
| 1084 | Q_OBJECT |
| 1085 | Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1) |
| 1086 | |
| 1087 | public: |
| 1088 | MyCreateableDerivedClass(QObject *parent = 0) |
| 1089 | : MyUncreateableBaseClass(true, parent) |
| 1090 | { |
| 1091 | } |
| 1092 | }; |
| 1093 | |
| 1094 | class MyExtendedUncreateableBaseClass : public QObject |
| 1095 | { |
| 1096 | Q_OBJECT |
| 1097 | Q_PROPERTY(bool prop1 READ prop1 WRITE setprop1) |
| 1098 | Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1) |
| 1099 | Q_PROPERTY(bool prop3 READ prop3 WRITE setprop3 REVISION 1) |
| 1100 | public: |
| 1101 | explicit MyExtendedUncreateableBaseClass(QObject *parent = 0) |
| 1102 | : QObject(parent), _prop1(false), _prop2(false), _prop3(false) |
| 1103 | { |
| 1104 | } |
| 1105 | |
| 1106 | bool _prop1; |
| 1107 | bool prop1() const { return _prop1; } |
| 1108 | void setprop1(bool p) { _prop1 = p; } |
| 1109 | bool _prop2; |
| 1110 | bool prop2() const { return _prop2; } |
| 1111 | void setprop2(bool p) { _prop2 = p; } |
| 1112 | bool _prop3; |
| 1113 | bool prop3() const { return _prop3; } |
| 1114 | void setprop3(bool p) { _prop3 = p; } |
| 1115 | }; |
| 1116 | |
| 1117 | class MyExtendedUncreateableBaseClassExtension : public QObject |
| 1118 | { |
| 1119 | Q_OBJECT |
| 1120 | Q_PROPERTY(bool prop4 READ prop4 WRITE setprop4) |
| 1121 | public: |
| 1122 | explicit MyExtendedUncreateableBaseClassExtension(QObject *parent = 0) |
| 1123 | : QObject(parent), _prop4(false) |
| 1124 | { |
| 1125 | } |
| 1126 | |
| 1127 | bool _prop4; |
| 1128 | bool prop4() const { return _prop4; } |
| 1129 | void setprop4(bool p) { _prop4 = p; } |
| 1130 | }; |
| 1131 | |
| 1132 | class MyExtendedCreateableDerivedClass : public MyExtendedUncreateableBaseClass |
| 1133 | { |
| 1134 | Q_OBJECT |
| 1135 | Q_PROPERTY(bool prop5 READ prop5 WRITE setprop5) |
| 1136 | |
| 1137 | public: |
| 1138 | MyExtendedCreateableDerivedClass(QObject *parent = 0) |
| 1139 | : MyExtendedUncreateableBaseClass(parent), _prop5(false) |
| 1140 | { |
| 1141 | } |
| 1142 | |
| 1143 | bool _prop5; |
| 1144 | bool prop5() const { return _prop5; } |
| 1145 | void setprop5(bool p) { _prop5 = p; } |
| 1146 | }; |
| 1147 | |
| 1148 | class MyVersion2Class : public QObject |
| 1149 | { |
| 1150 | Q_OBJECT |
| 1151 | }; |
| 1152 | |
| 1153 | class MyEnum1Class : public QObject |
| 1154 | { |
| 1155 | Q_OBJECT |
| 1156 | Q_ENUMS(EnumA) |
| 1157 | |
| 1158 | public: |
| 1159 | MyEnum1Class() : value(A_Invalid) {} |
| 1160 | |
| 1161 | enum EnumA |
| 1162 | { |
| 1163 | A_Invalid = -1, |
| 1164 | |
| 1165 | A_11 = 11, |
| 1166 | A_13 = 13 |
| 1167 | }; |
| 1168 | |
| 1169 | Q_INVOKABLE void setValue(EnumA v) { value = v; } |
| 1170 | |
| 1171 | EnumA getValue() { return value; } |
| 1172 | |
| 1173 | private: |
| 1174 | EnumA value; |
| 1175 | }; |
| 1176 | |
| 1177 | class MyEnum2Class : public QObject |
| 1178 | { |
| 1179 | Q_OBJECT |
| 1180 | Q_ENUMS(EnumB) |
| 1181 | Q_ENUMS(EnumE) |
| 1182 | |
| 1183 | public: |
| 1184 | MyEnum2Class() : valueA(MyEnum1Class::A_Invalid), valueB(B_Invalid), valueC(Qt::PlainText), |
| 1185 | valueD(Qt::ElideLeft), valueE(E_Invalid), valueE2(E_Invalid) {} |
| 1186 | |
| 1187 | enum EnumB |
| 1188 | { |
| 1189 | B_Invalid = -1, |
| 1190 | |
| 1191 | B_29 = 29, |
| 1192 | B_31 = 31, |
| 1193 | B_37 = 37 |
| 1194 | }; |
| 1195 | |
| 1196 | enum EnumE |
| 1197 | { |
| 1198 | E_Invalid = -1, |
| 1199 | |
| 1200 | E_14 = 14, |
| 1201 | E_76 = 76 |
| 1202 | }; |
| 1203 | |
| 1204 | MyEnum1Class::EnumA getValueA() { return valueA; } |
| 1205 | EnumB getValueB() { return valueB; } |
| 1206 | Qt::TextFormat getValueC() { return valueC; } |
| 1207 | Qt::TextElideMode getValueD() { return valueD; } |
| 1208 | EnumE getValueE() { return valueE; } |
| 1209 | EnumE getValueE2() { return valueE2; } |
| 1210 | |
| 1211 | Q_INVOKABLE void setValueA(MyEnum1Class::EnumA v) { valueA = v; emit valueAChanged(newValue: v); } |
| 1212 | Q_INVOKABLE void setValueB(EnumB v) { valueB = v; emit valueBChanged(newValue: v); } |
| 1213 | Q_INVOKABLE void setValueC(Qt::TextFormat v) { valueC = v; emit valueCChanged(newValue: v); } //registered |
| 1214 | Q_INVOKABLE void setValueD(Qt::TextElideMode v) { valueD = v; emit valueDChanged(newValue: v); } //unregistered |
| 1215 | Q_INVOKABLE void setValueE(EnumE v) { valueE = v; emit valueEChanged(newValue: v); } |
| 1216 | Q_INVOKABLE void setValueE2(MyEnum2Class::EnumE v) { valueE2 = v; emit valueE2Changed(newValue: v); } |
| 1217 | |
| 1218 | signals: |
| 1219 | void valueAChanged(MyEnum1Class::EnumA newValue); |
| 1220 | void valueBChanged(MyEnum2Class::EnumB newValue); |
| 1221 | void valueCChanged(Qt::TextFormat newValue); |
| 1222 | void valueDChanged(Qt::TextElideMode newValue); |
| 1223 | void valueEChanged(EnumE newValue); |
| 1224 | void valueE2Changed(MyEnum2Class::EnumE newValue); |
| 1225 | |
| 1226 | private: |
| 1227 | MyEnum1Class::EnumA valueA; |
| 1228 | EnumB valueB; |
| 1229 | Qt::TextFormat valueC; |
| 1230 | Qt::TextElideMode valueD; |
| 1231 | EnumE valueE; |
| 1232 | EnumE valueE2; |
| 1233 | }; |
| 1234 | |
| 1235 | class MyEnumDerivedClass : public MyEnum2Class |
| 1236 | { |
| 1237 | Q_OBJECT |
| 1238 | }; |
| 1239 | |
| 1240 | class MyCompositeBaseType : public QObject |
| 1241 | { |
| 1242 | Q_OBJECT |
| 1243 | Q_ENUMS(CompositeEnum) |
| 1244 | Q_ENUMS(ScopedCompositeEnum) |
| 1245 | |
| 1246 | public: |
| 1247 | enum CompositeEnum { EnumValue0, EnumValue42 = 42 }; |
| 1248 | enum class ScopedCompositeEnum : int { EnumValue15 = 15 }; |
| 1249 | static QObject *qmlAttachedProperties(QObject *parent) { return new QObject(parent); } |
| 1250 | }; |
| 1251 | |
| 1252 | class MyArrayBufferTestClass : public QObject |
| 1253 | { |
| 1254 | Q_OBJECT |
| 1255 | Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty NOTIFY byteArrayPropertyChanged) |
| 1256 | |
| 1257 | signals: |
| 1258 | void byteArrayPropertyChanged(); |
| 1259 | void byteArraySignal(QByteArray arg); |
| 1260 | |
| 1261 | public: |
| 1262 | QByteArray byteArrayPropertyValue; |
| 1263 | QByteArray byteArrayProperty() const { |
| 1264 | return byteArrayPropertyValue; |
| 1265 | } |
| 1266 | void setByteArrayProperty(const QByteArray &v) { |
| 1267 | byteArrayPropertyValue = v; |
| 1268 | emit byteArrayPropertyChanged(); |
| 1269 | } |
| 1270 | Q_INVOKABLE void emitByteArraySignal(char begin, char num) { |
| 1271 | byteArraySignal(arg: byteArrayMethod_CountUp(begin, num)); |
| 1272 | } |
| 1273 | Q_INVOKABLE int byteArrayMethod_Sum(QByteArray arg) { |
| 1274 | int sum = 0; |
| 1275 | for (int i = 0; i < arg.size(); ++i) { |
| 1276 | sum += arg[i]; |
| 1277 | } |
| 1278 | return sum; |
| 1279 | } |
| 1280 | Q_INVOKABLE QByteArray byteArrayMethod_CountUp(char begin, int num) { |
| 1281 | QByteArray ret; |
| 1282 | for (int i = 0; i < num; ++i) { |
| 1283 | ret.push_back(c: begin++); |
| 1284 | } |
| 1285 | return ret; |
| 1286 | } |
| 1287 | Q_INVOKABLE bool byteArrayMethod_Overloaded(QByteArray) { |
| 1288 | return true; |
| 1289 | } |
| 1290 | Q_INVOKABLE bool byteArrayMethod_Overloaded(int) { |
| 1291 | return false; |
| 1292 | } |
| 1293 | Q_INVOKABLE bool byteArrayMethod_Overloaded(QString) { |
| 1294 | return false; |
| 1295 | } |
| 1296 | Q_INVOKABLE bool byteArrayMethod_Overloaded(QJSValue) { |
| 1297 | return false; |
| 1298 | } |
| 1299 | Q_INVOKABLE bool byteArrayMethod_Overloaded(QVariant) { |
| 1300 | return false; |
| 1301 | } |
| 1302 | }; |
| 1303 | |
| 1304 | Q_DECLARE_METATYPE(MyEnum2Class::EnumB) |
| 1305 | Q_DECLARE_METATYPE(MyEnum1Class::EnumA) |
| 1306 | Q_DECLARE_METATYPE(Qt::TextFormat) |
| 1307 | Q_DECLARE_METATYPE(MyCompositeBaseType::CompositeEnum) |
| 1308 | |
| 1309 | QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered) |
| 1310 | QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered) |
| 1311 | QML_DECLARE_TYPE(MyRevisionedClass) |
| 1312 | QML_DECLARE_TYPE(MyRevisionedSubclass) |
| 1313 | QML_DECLARE_TYPE(MySubclass) |
| 1314 | QML_DECLARE_TYPE(MyReceiversTestObject) |
| 1315 | QML_DECLARE_TYPE(MyCompositeBaseType) |
| 1316 | QML_DECLARE_TYPEINFO(MyCompositeBaseType, QML_HAS_ATTACHED_PROPERTIES) |
| 1317 | |
| 1318 | class CustomBinding : public QObject, public QQmlParserStatus |
| 1319 | { |
| 1320 | Q_OBJECT |
| 1321 | Q_INTERFACES(QQmlParserStatus) |
| 1322 | Q_PROPERTY(QObject* target READ target WRITE setTarget) |
| 1323 | public: |
| 1324 | |
| 1325 | virtual void classBegin() {} |
| 1326 | virtual void componentComplete(); |
| 1327 | |
| 1328 | QObject *target() const { return m_target; } |
| 1329 | void setTarget(QObject *newTarget) { m_target = newTarget; } |
| 1330 | |
| 1331 | QPointer<QObject> m_target; |
| 1332 | QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit; |
| 1333 | QList<const QV4::CompiledData::Binding*> bindings; |
| 1334 | QByteArray m_bindingData; |
| 1335 | }; |
| 1336 | |
| 1337 | class CustomBindingParser : public QQmlCustomParser |
| 1338 | { |
| 1339 | virtual void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) {} |
| 1340 | virtual void applyBindings(QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &); |
| 1341 | }; |
| 1342 | |
| 1343 | class SimpleObjectWithCustomParser : public QObject |
| 1344 | { |
| 1345 | Q_OBJECT |
| 1346 | Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty) |
| 1347 | public: |
| 1348 | SimpleObjectWithCustomParser() |
| 1349 | : m_intProperty(0) |
| 1350 | , m_customBindingsCount(0) |
| 1351 | {} |
| 1352 | |
| 1353 | int intProperty() const { return m_intProperty; } |
| 1354 | void setIntProperty(int value) { m_intProperty = value; } |
| 1355 | |
| 1356 | void setCustomBindingsCount(int count) { m_customBindingsCount = count; } |
| 1357 | int customBindingsCount() const { return m_customBindingsCount; } |
| 1358 | |
| 1359 | private: |
| 1360 | int m_intProperty; |
| 1361 | int m_customBindingsCount; |
| 1362 | }; |
| 1363 | |
| 1364 | class SimpleObjectExtension : public QObject |
| 1365 | { |
| 1366 | Q_OBJECT |
| 1367 | Q_PROPERTY(int extendedProperty READ extendedProperty WRITE setExtendedProperty NOTIFY extendedPropertyChanged) |
| 1368 | public: |
| 1369 | SimpleObjectExtension(QObject *parent = 0) |
| 1370 | : QObject(parent) |
| 1371 | , m_extendedProperty(1584) |
| 1372 | {} |
| 1373 | |
| 1374 | void setExtendedProperty(int extendedProperty) { m_extendedProperty = extendedProperty; emit extendedPropertyChanged(); } |
| 1375 | int extendedProperty() const { return m_extendedProperty; } |
| 1376 | |
| 1377 | signals: |
| 1378 | void extendedPropertyChanged(); |
| 1379 | private: |
| 1380 | int m_extendedProperty; |
| 1381 | }; |
| 1382 | |
| 1383 | class SimpleObjectCustomParser : public QQmlCustomParser |
| 1384 | { |
| 1385 | virtual void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) {} |
| 1386 | virtual void applyBindings(QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &); |
| 1387 | }; |
| 1388 | |
| 1389 | class RootObjectInCreationTester : public QObject |
| 1390 | { |
| 1391 | Q_OBJECT |
| 1392 | Q_PROPERTY(QObject *subObject READ subObject WRITE setSubObject FINAL) |
| 1393 | Q_CLASSINFO("DeferredPropertyNames" , "subObject" ); |
| 1394 | public: |
| 1395 | RootObjectInCreationTester() |
| 1396 | : obj(0) |
| 1397 | {} |
| 1398 | |
| 1399 | QObject *subObject() const { return obj; } |
| 1400 | void setSubObject(QObject *o) { obj = o; } |
| 1401 | |
| 1402 | private: |
| 1403 | QObject *obj; |
| 1404 | }; |
| 1405 | |
| 1406 | class LazyDeferredSubObject : public QObject |
| 1407 | { |
| 1408 | Q_OBJECT |
| 1409 | Q_PROPERTY(QObject *subObject READ subObject WRITE setSubObject NOTIFY subObjectChanged FINAL) |
| 1410 | Q_CLASSINFO("DeferredPropertyNames" , "subObject" ); |
| 1411 | public: |
| 1412 | LazyDeferredSubObject() |
| 1413 | : obj(0) |
| 1414 | {} |
| 1415 | |
| 1416 | QObject *subObject() const { if (!obj) qmlExecuteDeferred(const_cast<LazyDeferredSubObject *>(this)); return obj; } |
| 1417 | void setSubObject(QObject *o) { if (obj == o) return; obj = o; emit subObjectChanged(); } |
| 1418 | |
| 1419 | signals: |
| 1420 | void subObjectChanged(); |
| 1421 | |
| 1422 | private: |
| 1423 | QObject *obj; |
| 1424 | }; |
| 1425 | |
| 1426 | class DeferredProperties : public QObject |
| 1427 | { |
| 1428 | Q_OBJECT |
| 1429 | Q_PROPERTY(QObject *groupProperty MEMBER m_group) |
| 1430 | Q_PROPERTY(QQmlListProperty<QObject> listProperty READ listProperty) |
| 1431 | Q_CLASSINFO("DeferredPropertyNames" , "groupProperty,listProperty" ) |
| 1432 | Q_CLASSINFO("DefaultProperty" , "listProperty" ) |
| 1433 | public: |
| 1434 | QQmlListProperty<QObject> listProperty() { return QQmlListProperty<QObject>(this, m_list); } |
| 1435 | |
| 1436 | private: |
| 1437 | QObject *m_group = 0; |
| 1438 | QObjectList m_list; |
| 1439 | }; |
| 1440 | |
| 1441 | class ScopedEnumsWithNameClash |
| 1442 | { |
| 1443 | Q_GADGET |
| 1444 | Q_ENUMS(ScopedEnum) |
| 1445 | Q_ENUMS(OtherScopedEnum) |
| 1446 | |
| 1447 | public: |
| 1448 | enum class ScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3, OtherScopedEnum }; |
| 1449 | enum class OtherScopedEnum : int { ScopedVal1 = 10, ScopedVal2 = 11, ScopedVal3 = 12 }; |
| 1450 | }; |
| 1451 | |
| 1452 | class ScopedEnumsWithResolvedNameClash |
| 1453 | { |
| 1454 | Q_GADGET |
| 1455 | Q_ENUMS(ScopedEnum) |
| 1456 | Q_ENUMS(OtherScopedEnum) |
| 1457 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
| 1458 | |
| 1459 | public: |
| 1460 | enum class ScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3, OtherScopedEnum }; |
| 1461 | enum class OtherScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3 }; |
| 1462 | }; |
| 1463 | |
| 1464 | class Extension : public QObject |
| 1465 | { |
| 1466 | Q_OBJECT |
| 1467 | Q_PROPERTY(int extension READ extension CONSTANT) |
| 1468 | public: |
| 1469 | Extension(QObject *parent = nullptr) : QObject(parent) {} |
| 1470 | int extension() const { return 42; } |
| 1471 | }; |
| 1472 | |
| 1473 | class Extended : public QObject |
| 1474 | { |
| 1475 | Q_OBJECT |
| 1476 | QML_EXTENDED(Extension) |
| 1477 | QML_NAMED_ELEMENT(Extended) |
| 1478 | Q_PROPERTY(int base READ base CONSTANT) |
| 1479 | |
| 1480 | public: |
| 1481 | int base() const { return 43; } |
| 1482 | }; |
| 1483 | |
| 1484 | class Local : public QObject |
| 1485 | { |
| 1486 | Q_OBJECT |
| 1487 | }; |
| 1488 | |
| 1489 | class Foreign |
| 1490 | { |
| 1491 | Q_GADGET |
| 1492 | QML_FOREIGN(Local) |
| 1493 | QML_NAMED_ELEMENT(Foreign) |
| 1494 | }; |
| 1495 | |
| 1496 | class ForeignExtended |
| 1497 | { |
| 1498 | Q_GADGET |
| 1499 | QML_FOREIGN(Local) |
| 1500 | QML_NAMED_ELEMENT(ForeignExtended) |
| 1501 | QML_EXTENDED(Extension) |
| 1502 | }; |
| 1503 | |
| 1504 | class BareSingleton : public QObject |
| 1505 | { |
| 1506 | Q_OBJECT |
| 1507 | QML_SINGLETON |
| 1508 | QML_ELEMENT |
| 1509 | |
| 1510 | public: |
| 1511 | BareSingleton(QObject *parent = nullptr) : QObject(parent) |
| 1512 | { |
| 1513 | setObjectName("statically registered" ); |
| 1514 | } |
| 1515 | }; |
| 1516 | |
| 1517 | class UncreatableSingleton : public QObject |
| 1518 | { |
| 1519 | Q_OBJECT |
| 1520 | QML_SINGLETON |
| 1521 | QML_ELEMENT |
| 1522 | |
| 1523 | public: |
| 1524 | static UncreatableSingleton *instance(); |
| 1525 | |
| 1526 | private: |
| 1527 | UncreatableSingleton() { setObjectName("uncreatable" ); } |
| 1528 | }; |
| 1529 | |
| 1530 | void registerTypes(); |
| 1531 | |
| 1532 | #endif // TESTTYPES_H |
| 1533 | |