From a93c2608d69fa385c675a6b49e4d4bfb97f83ed2 Mon Sep 17 00:00:00 2001 From: Matthew Vogt Date: Fri, 22 Jun 2012 15:32:46 +1000 Subject: Add enum values from related types If moc marks a type as being related to another type (by using that type's enums or properties), then include the enum values exported by the related type in those exposed by the dependent type. Task-number: QTBUG-22675 Change-Id: I78e72791a4f470200a9ba986a865ffac6c873725 Reviewed-by: Chris Adams --- .../qml/qqmlecmascript/data/assignBasicTypes.2.qml | 1 + .../qml/qqmlecmascript/data/assignBasicTypes.qml | 1 + tests/auto/qml/qqmlecmascript/data/enums.1.qml | 18 +++++++ tests/auto/qml/qqmlecmascript/data/enums.3.qml | 5 ++ tests/auto/qml/qqmlecmascript/testtypes.h | 58 ++++++++++++++++++++++ .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 10 ++++ .../qml/qqmllanguage/data/assignBasicTypes.qml | 3 ++ tests/auto/qml/qqmllanguage/testtypes.h | 19 +++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 1 + 9 files changed, 116 insertions(+) (limited to 'tests') diff --git a/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml index 2c79729651..ff6d7311a1 100644 --- a/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml +++ b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml @@ -3,6 +3,7 @@ import Qt.test 1.0 MyTypeObject { flagProperty: if(1) "FlagVal1 | FlagVal3" enumProperty: if(1) "EnumVal2" + relatedEnumProperty: if(1) "RelatedValue" stringProperty: if(1) "Hello World!" uintProperty: if(1) 10 intProperty: if(1) -19 diff --git a/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.qml b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.qml index 86ff6b6bb3..ce3511f72a 100644 --- a/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.qml +++ b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.qml @@ -5,6 +5,7 @@ MyTypeObject { Component.onCompleted: { flagProperty = "FlagVal1 | FlagVal3" enumProperty = "EnumVal2" + relatedEnumProperty = "RelatedValue" stringProperty = "Hello World!" uintProperty = 10 intProperty = -19 diff --git a/tests/auto/qml/qqmlecmascript/data/enums.1.qml b/tests/auto/qml/qqmlecmascript/data/enums.1.qml index 6351823230..b9295c5c89 100644 --- a/tests/auto/qml/qqmlecmascript/data/enums.1.qml +++ b/tests/auto/qml/qqmlecmascript/data/enums.1.qml @@ -2,6 +2,18 @@ import Qt.test 1.0 import Qt.test 1.0 as Namespace MyQmlObject { + // Enum property type + enumProperty: MyQmlObject.EnumValue2 + + // Enum property whose value is from a related type + relatedEnumProperty: MyQmlObject.RelatedValue + + // Enum property whose value is defined in an unrelated type + unrelatedEnumProperty: MyTypeObject.RelatedValue + + // Enum property whose value is defined in the Qt namespace + qtEnumProperty: Qt.CaseInsensitive + // Enums from non-namespaced type property int a: MyQmlObject.EnumValue1 property int b: MyQmlObject.EnumValue2 @@ -17,4 +29,10 @@ MyQmlObject { // Test that enums don't mask attached properties property int i: MyQmlObject.value property int j: Namespace.MyQmlObject.value + + // Enums from a related type + property int k: MyQmlObject.RelatedValue + + // Enum values defined both in a type and a related type + property int l: MyQmlObject.MultiplyDefined } diff --git a/tests/auto/qml/qqmlecmascript/data/enums.3.qml b/tests/auto/qml/qqmlecmascript/data/enums.3.qml index fd3432fc9f..aaa6a333b7 100644 --- a/tests/auto/qml/qqmlecmascript/data/enums.3.qml +++ b/tests/auto/qml/qqmlecmascript/data/enums.3.qml @@ -22,6 +22,9 @@ Item { // -1 enum property int j: MyQmlObject.EnumValue5 + // Enums from a related type + property int k: MyQmlObject.RelatedValue + // Count the onChanged signals to see whether // they're assigned as literals or via bindings property int ac: 0 @@ -33,6 +36,7 @@ Item { property int hc: 0 property int ic: 0 property int jc: 0 + property int kc: 0 onAChanged: ac++ onBChanged: bc++ @@ -43,4 +47,5 @@ Item { onHChanged: hc++ onIChanged: ic++ onJChanged: jc++ + onKChanged: kc++ } diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index ab44d5986e..06e54ea552 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -86,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) @@ -106,12 +117,17 @@ class MyQmlObject : public QObject 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), m_buttons(0) {} enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3, EnumValue5 = -1 }; + enum MyEnum3 { MultiplyDefined = 333 }; bool trueProperty() const { return true; } bool falseProperty() const { return false; } @@ -189,6 +205,38 @@ public: 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); @@ -354,6 +402,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) @@ -361,6 +410,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) @@ -433,6 +483,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; diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index c429ffaa4b..e2f818c1ee 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -295,6 +295,7 @@ void tst_qqmlecmascript::assignBasicTypes() QVERIFY(object != 0); QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); + QCOMPARE(object->relatedEnumProperty(), MyEnumContainer::RelatedValue); QCOMPARE(object->stringProperty(), QString("Hello World!")); QCOMPARE(object->uintProperty(), uint(10)); QCOMPARE(object->intProperty(), -19); @@ -323,6 +324,7 @@ void tst_qqmlecmascript::assignBasicTypes() QVERIFY(object != 0); QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); + QCOMPARE(object->relatedEnumProperty(), MyEnumContainer::RelatedValue); QCOMPARE(object->stringProperty(), QString("Hello World!")); QCOMPARE(object->uintProperty(), uint(10)); QCOMPARE(object->intProperty(), -19); @@ -910,6 +912,10 @@ void tst_qqmlecmascript::enums() QObject *object = component.create(); QVERIFY(object != 0); + QCOMPARE(object->property("enumProperty").toInt(), (int)MyQmlObject::EnumValue2); + QCOMPARE(object->property("relatedEnumProperty").toInt(), (int)MyEnumContainer::RelatedValue); + QCOMPARE(object->property("unrelatedEnumProperty").toInt(), (int)MyEnumContainer::RelatedValue); + QCOMPARE(object->property("qtEnumProperty").toInt(), (int)Qt::CaseInsensitive); QCOMPARE(object->property("a").toInt(), 0); QCOMPARE(object->property("b").toInt(), 1); QCOMPARE(object->property("c").toInt(), 2); @@ -920,6 +926,8 @@ void tst_qqmlecmascript::enums() QCOMPARE(object->property("h").toInt(), 3); QCOMPARE(object->property("i").toInt(), 19); QCOMPARE(object->property("j").toInt(), 19); + QCOMPARE(object->property("k").toInt(), 42); + QCOMPARE(object->property("l").toInt(), 333); delete object; } @@ -984,6 +992,7 @@ void tst_qqmlecmascript::enums() QCOMPARE(object->property("h").toInt(), 2); QCOMPARE(object->property("i").toInt(), 3); QCOMPARE(object->property("j").toInt(), -1); + QCOMPARE(object->property("k").toInt(), 42); // count of change signals QCOMPARE(object->property("ac").toInt(), 0); @@ -995,6 +1004,7 @@ void tst_qqmlecmascript::enums() QCOMPARE(object->property("hc").toInt(), 1); // namespace -> binding QCOMPARE(object->property("ic").toInt(), 1); // namespace -> binding QCOMPARE(object->property("jc").toInt(), 0); + QCOMPARE(object->property("kc").toInt(), 0); delete object; } diff --git a/tests/auto/qml/qqmllanguage/data/assignBasicTypes.qml b/tests/auto/qml/qqmllanguage/data/assignBasicTypes.qml index 697278e0b7..4d54bc83c1 100644 --- a/tests/auto/qml/qqmllanguage/data/assignBasicTypes.qml +++ b/tests/auto/qml/qqmllanguage/data/assignBasicTypes.qml @@ -1,9 +1,12 @@ import Test 1.0 +import QtQuick 2.0 + MyTypeObject { flagProperty: "FlagVal1 | FlagVal3" enumProperty: "EnumVal2" qtEnumProperty: Qt.RichText mirroredEnumProperty: Qt.AlignHCenter + relatedEnumProperty: "RelatedValue" stringProperty: "Hello World!" uintProperty: 10 intProperty: -19 diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index 50b6089ffc..01f26c7f67 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -205,11 +205,21 @@ private: }; +class MyEnumContainer : public QObject +{ + Q_OBJECT + Q_ENUMS(RelatedEnum) + +public: + enum RelatedEnum { RelatedInvalid = -1, RelatedValue = 42 }; +}; + class MyTypeObject : public QObject { Q_OBJECT Q_ENUMS(MyEnum) Q_ENUMS(MyMirroredEnum) + Q_ENUMS(MyEnumContainer::RelatedEnum) Q_FLAGS(MyFlags) Q_PROPERTY(QString id READ id WRITE setId) @@ -220,6 +230,7 @@ class MyTypeObject : public QObject Q_PROPERTY(MyEnum readOnlyEnumProperty READ readOnlyEnumProperty) Q_PROPERTY(Qt::TextFormat qtEnumProperty READ qtEnumProperty WRITE setQtEnumProperty NOTIFY qtEnumPropertyChanged) Q_PROPERTY(MyMirroredEnum mirroredEnumProperty READ mirroredEnumProperty WRITE setMirroredEnumProperty NOTIFY mirroredEnumPropertyChanged) + Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringPropertyChanged) Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty NOTIFY uintPropertyChanged) Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged) @@ -323,6 +334,14 @@ public: emit mirroredEnumPropertyChanged(); } + MyEnumContainer::RelatedEnum relatedEnumPropertyValue; + MyEnumContainer::RelatedEnum relatedEnumProperty() const { + return relatedEnumPropertyValue; + } + void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) { + relatedEnumPropertyValue = v; + } + QString stringPropertyValue; QString stringProperty() const { return stringPropertyValue; diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 2f2f0a78d4..ed94eff574 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -587,6 +587,7 @@ void tst_qqmllanguage::assignBasicTypes() QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); QCOMPARE(object->qtEnumProperty(), Qt::RichText); QCOMPARE(object->mirroredEnumProperty(), MyTypeObject::MirroredEnumVal3); + QCOMPARE(object->relatedEnumProperty(), MyEnumContainer::RelatedValue); QCOMPARE(object->stringProperty(), QString("Hello World!")); QCOMPARE(object->uintProperty(), uint(10)); QCOMPARE(object->intProperty(), -19); -- cgit v1.2.3