aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-01-07 11:51:37 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2015-01-07 15:34:19 +0100
commit05fd01c14a7a4b26f366704fb0b0a4eddaceccf4 (patch)
tree583f404187502c83721db32e901bb8ed108ab51d /tests
parent353e43cb6d73ee97ebff1a8c737b2c133b135ab8 (diff)
Fix property access and method invocation on value types that use inheritance
For gadgets/value types we use moc's static_metacall, which doesn't call the parent class implementation. Therefore before placing a static metacall we must resolve the indicies and find the right meta-object. Change-Id: I258e3d9ecfc704498c68772dc42b16134a3bfd83 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/customvaluetype.qml3
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp54
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/customvaluetype.qml b/tests/auto/qml/qqmlvaluetypes/data/customvaluetype.qml
index 7ae73475c3..380eb55f54 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/customvaluetype.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/customvaluetype.qml
@@ -5,4 +5,7 @@ TypeWithCustomValueType {
desk {
monitorCount: 3
}
+ derivedGadget {
+ baseProperty: 42
+ }
}
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index f07a34b2f2..45cbbebdc3 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -90,6 +90,7 @@ private slots:
void groupedInterceptors_data();
void customValueType();
void customValueTypeInQml();
+ void gadgetInheritance();
private:
QQmlEngine engine;
@@ -1484,13 +1485,48 @@ void tst_qqmlvaluetypes::customValueType()
QCOMPARE(cppOffice.desk().monitorCount, 2);
}
+struct BaseGadget
+{
+ Q_GADGET
+ Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty)
+public:
+ BaseGadget() : m_baseProperty(0) {}
+
+ int baseProperty() const { return m_baseProperty; }
+ void setBaseProperty(int value) { m_baseProperty = value; }
+ int m_baseProperty;
+
+ Q_INVOKABLE void functionInBaseGadget(int value) { m_baseProperty = value; }
+};
+
+Q_DECLARE_METATYPE(BaseGadget)
+
+struct DerivedGadget : public BaseGadget
+{
+ Q_GADGET
+ Q_PROPERTY(int derivedProperty READ derivedProperty WRITE setDerivedProperty)
+public:
+ DerivedGadget() : m_derivedProperty(0) {}
+
+ int derivedProperty() const { return m_derivedProperty; }
+ void setDerivedProperty(int value) { m_derivedProperty = value; }
+ int m_derivedProperty;
+
+ Q_INVOKABLE void functionInDerivedGadget(int value) { m_derivedProperty = value; }
+};
+
class TypeWithCustomValueType : public QObject
{
Q_OBJECT
Q_PROPERTY(MyDesk desk MEMBER m_desk)
+ Q_PROPERTY(DerivedGadget derivedGadget READ derivedGadget WRITE setDerivedGadget)
public:
MyDesk m_desk;
+
+ DerivedGadget derivedGadget() const { return m_derivedGadget; }
+ void setDerivedGadget(const DerivedGadget &value) { m_derivedGadget = value; }
+ DerivedGadget m_derivedGadget;
};
void tst_qqmlvaluetypes::customValueTypeInQml()
@@ -1503,6 +1539,24 @@ void tst_qqmlvaluetypes::customValueTypeInQml()
TypeWithCustomValueType *t = qobject_cast<TypeWithCustomValueType*>(object.data());
Q_ASSERT(t);
QCOMPARE(t->m_desk.monitorCount, 3);
+ QCOMPARE(t->m_derivedGadget.baseProperty(), 42);
+}
+
+Q_DECLARE_METATYPE(DerivedGadget)
+
+void tst_qqmlvaluetypes::gadgetInheritance()
+{
+ QJSEngine engine;
+
+ QJSValue value = engine.toScriptValue(DerivedGadget());
+
+ QCOMPARE(value.property("baseProperty").toInt(), 0);
+ value.setProperty("baseProperty", 10);
+ QCOMPARE(value.property("baseProperty").toInt(), 10);
+
+ QJSValue method = value.property("functionInBaseGadget");
+ method.call(QJSValueList() << QJSValue(42));
+ QCOMPARE(value.property("baseProperty").toInt(), 42);
}
QTEST_MAIN(tst_qqmlvaluetypes)