X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tests%2Fauto%2Fqml%2Fqqmlecmascript%2Ftesttypes.h;h=a4983f13db70458e6dfb68fbd7f615a3d5629163;hb=70a2c0491d66aa05f9e9e67f8a845f4df84da857;hp=54fab264050d4f5c58f7b1113566c8b3a0fb952a;hpb=4821058f10118be55a541ad39e25ec9165cca3b3;p=profile%2Fivi%2Fqtdeclarative.git diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 54fab26..a4983f1 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -51,8 +51,12 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include #include @@ -82,11 +86,22 @@ private: int m_value2; }; +class MyEnumContainer : public QObject +{ + Q_OBJECT + Q_ENUMS(RelatedEnum) + +public: + enum RelatedEnum { RelatedInvalid = -1, RelatedValue = 42, MultiplyDefined = 666 }; +}; + class MyQmlObject : public QObject { Q_OBJECT Q_ENUMS(MyEnum) Q_ENUMS(MyEnum2) + Q_ENUMS(MyEnum3) + Q_ENUMS(MyEnumContainer::RelatedEnum) Q_PROPERTY(int deleteOnSet READ deleteOnSet WRITE setDeleteOnSet) Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT) Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT) @@ -100,12 +115,19 @@ class MyQmlObject : public QObject Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp) Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false) Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intChanged) + Q_PROPERTY(QJSValue qjsvalue READ qjsvalue WRITE setQJSValue NOTIFY qjsvalueChanged) + Q_PROPERTY(QJSValue qjsvalueWithReset READ qjsvalue WRITE setQJSValue RESET resetQJSValue NOTIFY qjsvalueChanged) + Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty) + Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty) + Q_PROPERTY(MyEnumContainer::RelatedEnum unrelatedEnumProperty READ unrelatedEnumProperty WRITE setUnrelatedEnumProperty) + Q_PROPERTY(MyEnum qtEnumProperty READ qtEnumProperty WRITE setQtEnumProperty) public: - MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0) {} + MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0), m_buttons(0) {} enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; - enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 }; + enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3, EnumValue5 = -1 }; + enum MyEnum3 { MultiplyDefined = 333 }; bool trueProperty() const { return true; } bool falseProperty() const { return false; } @@ -171,12 +193,53 @@ public: struct MyType { int value; }; + struct MyOtherType { + int value; + }; QVariant variant() const { return m_variant; } QJSValue qjsvalue() const { return m_qjsvalue; } + void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); } + void resetQJSValue() { m_qjsvalue = QJSValue(QLatin1String("Reset!")); emit qjsvalueChanged(); } + + Qt::MouseButtons buttons() const { return m_buttons; } int intProperty() const { return m_intProperty; } void setIntProperty(int i) { m_intProperty = i; emit intChanged(); } + Q_INVOKABLE MyEnum2 getEnumValue() const { return EnumValue4; } + + MyEnum enumPropertyValue; + MyEnum enumProperty() const { + return enumPropertyValue; + } + void setEnumProperty(MyEnum v) { + enumPropertyValue = v; + } + + MyEnumContainer::RelatedEnum relatedEnumPropertyValue; + MyEnumContainer::RelatedEnum relatedEnumProperty() const { + return relatedEnumPropertyValue; + } + void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) { + relatedEnumPropertyValue = v; + } + + MyEnumContainer::RelatedEnum unrelatedEnumPropertyValue; + MyEnumContainer::RelatedEnum unrelatedEnumProperty() const { + return unrelatedEnumPropertyValue; + } + void setUnrelatedEnumProperty(MyEnumContainer::RelatedEnum v) { + unrelatedEnumPropertyValue = v; + } + + MyEnum qtEnumPropertyValue; + MyEnum qtEnumProperty() const { + return qtEnumPropertyValue; + } + void setQtEnumProperty(MyEnum v) { + qtEnumPropertyValue = v; + } + signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e); @@ -187,10 +250,12 @@ signals: void anotherBasicSignal(); void thirdBasicSignal(); void signalWithUnknownType(const MyQmlObject::MyType &arg); + void signalWithCompletelyUnknownType(const MyQmlObject::MyOtherType &arg); void signalWithVariant(const QVariant &arg); void signalWithQJSValue(const QJSValue &arg); void signalWithGlobalName(int parseInt); void intChanged(); + void qjsvalueChanged(); public slots: void deleteMe() { delete this; } @@ -201,6 +266,7 @@ public slots: void variantMethod(const QVariant &v) { m_variant = v; } void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; } void v8function(QQmlV8Function*); + void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; } private: friend class tst_qqmlecmascript; @@ -217,6 +283,7 @@ private: QVariant m_variant; QJSValue m_qjsvalue; int m_intProperty; + Qt::MouseButtons m_buttons; }; QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES) @@ -339,6 +406,7 @@ class MyTypeObject : public QObject { Q_OBJECT Q_ENUMS(MyEnum) + Q_ENUMS(MyEnumContainer::RelatedEnum) Q_FLAGS(MyFlags) Q_PROPERTY(QString id READ id WRITE setId) @@ -346,6 +414,7 @@ class MyTypeObject : public QObject Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty) Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty) Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty) + Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty) Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty) Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty) @@ -356,6 +425,7 @@ class MyTypeObject : public QObject Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty) Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty) Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty) + Q_PROPERTY(QDateTime dateTimeProperty2 READ dateTimeProperty2 WRITE setDateTimeProperty2) Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty) Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty) Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty) @@ -417,6 +487,14 @@ public: enumPropertyValue = v; } + MyEnumContainer::RelatedEnum relatedEnumPropertyValue; + MyEnumContainer::RelatedEnum relatedEnumProperty() const { + return relatedEnumPropertyValue; + } + void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) { + relatedEnumPropertyValue = v; + } + QString stringPropertyValue; QString stringProperty() const { return stringPropertyValue; @@ -497,6 +575,14 @@ public: dateTimePropertyValue = v; } + QDateTime dateTimePropertyValue2; + QDateTime dateTimeProperty2() const { + return dateTimePropertyValue2; + } + void setDateTimeProperty2(const QDateTime &v) { + dateTimePropertyValue2 = v; + } + QPoint pointPropertyValue; QPoint pointProperty() const { return pointPropertyValue; @@ -665,6 +751,16 @@ public: Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; } + Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); } + + Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); } + + Q_INVOKABLE void method_unknown(MyInvokableObject *) { invoke(28); } + private: friend class MyInvokableBaseObject; void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} @@ -997,6 +1093,9 @@ public: Q_INVOKABLE void setTrackedObjectProperty(const QString &propName) const { m_trackedObject->setProperty(qPrintable(propName), QVariant(5)); } Q_INVOKABLE QVariant trackedObjectProperty(const QString &propName) const { return m_trackedObject->property(qPrintable(propName)); } + Q_INVOKABLE void setSpecificProperty(QObject *obj, const QString & propName, const QVariant & v) const { obj->setProperty(qPrintable(propName), v); } + Q_INVOKABLE void changeQObjectParent(QObject *obj) { obj->setParent(this); } + int qobjectTestProperty() const { return m_testProperty; } void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); } @@ -1006,6 +1105,21 @@ public: int qobjectTestWritableFinalProperty() const { return m_testWritableFinalProperty; } void setQObjectTestWritableFinalProperty(int tp) { m_testWritableFinalProperty = tp; emit qobjectTestWritableFinalPropertyChanged(); } + Q_INVOKABLE bool trackedObjectHasJsOwnership() { + QObject * object = m_trackedObject; + + if (!object) + return false; + + QQmlData *ddata = QQmlData::get(object, false); + if (!ddata) + return false; + else + return ddata->indestructible?false:true; + } + + Q_INVOKABLE void deleteQObject(QObject *obj) { delete obj; } + signals: void qobjectTestPropertyChanged(int testProperty); void qobjectTestWritablePropertyChanged(int testWritableProperty); @@ -1019,6 +1133,40 @@ private: QObject *m_trackedObject; }; +class testQObjectApiTwo : public QObject +{ + Q_OBJECT + Q_PROPERTY(int twoTestProperty READ twoTestProperty WRITE setTwoTestProperty NOTIFY twoTestPropertyChanged) + +public: + testQObjectApiTwo(QObject *parent = 0) : QObject(parent), m_ttp(42) {} + ~testQObjectApiTwo() {} + + void setTwoTestProperty(int v) { m_ttp = v; emit twoTestPropertyChanged(); } + int twoTestProperty() const { return m_ttp; } + +signals: + void twoTestPropertyChanged(); + +private: + int m_ttp; +}; + +class testImportOrderApi : public QObject +{ + Q_OBJECT + +public: + testImportOrderApi(int value, QObject *parent = 0) : QObject(parent), m_value(value) {} + + Q_PROPERTY(int value READ value) + + int value() const { return m_value; } + +private: + int m_value; +}; + class CircularReferenceObject : public QObject, public QV8GCCallback::Node { @@ -1110,11 +1258,9 @@ public: m_referenced.MakeWeak(static_cast(this), wrcallback); } - static void wrcallback(v8::Persistent handle, void *params) + static void wrcallback(v8::Persistent handle, void *) { - CircularReferenceHandle *crh = static_cast(params); qPersistentDispose(handle); - crh->m_referenced.Clear(); } static void gccallback(QV8GCCallback::Node *n) @@ -1270,6 +1416,7 @@ public: Q_INVOKABLE QList generateStringSequence() const { QList retn; retn << "one" << "two" << "three"; return retn; } Q_INVOKABLE QList generateUrlSequence() const { QList retn; retn << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); return retn; } Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; } + Q_INVOKABLE bool parameterEqualsGeneratedIntSequence(const QList& param) const { return (param == generateIntSequence()); } // "reference resource" underlying qobject deletion test: Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; } @@ -1319,6 +1466,173 @@ private: MyQmlObject *m_nestedObject; }; +class DateTimeExporter : public QObject +{ + Q_OBJECT + +public: + DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC") + { + switch (m_datetime.timeSpec()) { + case Qt::LocalTime: + { + QDateTime utc(m_datetime.toUTC()); + utc.setTimeSpec(Qt::LocalTime); + m_offset = m_datetime.secsTo(utc) / 60; + m_timespec = "LocalTime"; + } + break; + case Qt::OffsetFromUTC: + m_offset = m_datetime.utcOffset() / 60; + m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+') + .arg(abs(m_offset) / 60) + .arg(abs(m_offset) % 60); + default: + break; + } + } + + Q_INVOKABLE QDate getDate() const { return m_datetime.date(); } + Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; } + Q_INVOKABLE int getDateTimeOffset() const { return m_offset; } + Q_INVOKABLE QString getTimeSpec() const { return m_timespec; } + +private: + QDateTime m_datetime; + int m_offset; + QString m_timespec; +}; + +class MyWorkerObject : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + void doIt(); + +Q_SIGNALS: + void done(const QString &result); +}; + +class MyUnregisteredEnumTypeObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty) + +public: + MyUnregisteredEnumTypeObject() : QObject(), m_ev(FirstValue) {} + ~MyUnregisteredEnumTypeObject() {} + + enum MyEnum { + FirstValue = 1, + SecondValue = 2 + }; + + MyEnum enumProperty() const { return m_ev; } + void setEnumProperty(MyEnum v) { m_ev = v; } + +private: + MyEnum m_ev; +}; + +class FallbackBindingsObject : public QObject +{ + Q_OBJECT + Q_PROPERTY (int test READ test NOTIFY testChanged) +public: + FallbackBindingsObject(QObject* parent = 0) + : QObject(parent), m_test(100) + { + } + + int test() const { return m_test; } + +Q_SIGNALS: + void testChanged(); + +private: + int m_test; +}; + +class FallbackBindingsDerived : public FallbackBindingsObject +{ + Q_OBJECT + Q_PROPERTY (QString test READ test NOTIFY testChanged) +public: + FallbackBindingsDerived(QObject* parent = 0) + : FallbackBindingsObject(parent), m_test("hello") + { + } + + QString test() const { return m_test; } + +Q_SIGNALS: + void testChanged(); + +private: + QString m_test; +}; + +class FallbackBindingsAttachedObject : public QObject +{ + Q_OBJECT + Q_PROPERTY (int test READ test NOTIFY testChanged) +public: + FallbackBindingsAttachedObject(QObject *parent) : QObject(parent), m_test(100) {} + + int test() const { return m_test; } + +Q_SIGNALS: + void testChanged(); + +private: + int m_test; +}; + +class FallbackBindingsAttachedDerived : public FallbackBindingsAttachedObject +{ + Q_OBJECT + Q_PROPERTY (QString test READ test NOTIFY testChanged) +public: + FallbackBindingsAttachedDerived(QObject* parent = 0) + : FallbackBindingsAttachedObject(parent), m_test("hello") + { + } + + QString test() const { return m_test; } + +Q_SIGNALS: + void testChanged(); + +private: + QString m_test; +}; + +class FallbackBindingsTypeObject : public QObject +{ + Q_OBJECT +public: + FallbackBindingsTypeObject() : QObject() {} + + static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) { + return new FallbackBindingsAttachedObject(o); + } +}; + +class FallbackBindingsTypeDerived : public QObject +{ + Q_OBJECT +public: + FallbackBindingsTypeDerived() : QObject() {} + + static FallbackBindingsAttachedObject *qmlAttachedProperties(QObject *o) { + return new FallbackBindingsAttachedDerived(o); + } +}; + +QML_DECLARE_TYPEINFO(FallbackBindingsTypeObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPEINFO(FallbackBindingsTypeDerived, QML_HAS_ATTACHED_PROPERTIES) + void registerTypes(); #endif // TESTTYPES_H