diff options
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/resetGadget.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 35 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 16 |
5 files changed, 67 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index d203f07e87..3f2ff8ef8e 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -835,6 +835,12 @@ bool QQmlValueTypeWrapper::virtualPut(Managed *m, PropertyKey id, const Value &v QMetaProperty property = metaObject->property(pd.coreIndex()); Q_ASSERT(property.isValid()); + if (value.isUndefined() && pd.isResettable()) { + property.resetOnGadget(reinterpret_cast<QObject *>(r->d()->gadgetPtr())); + if (heapObject) + r->d()->writeBack(pd.coreIndex()); + return true; + } QVariant v = QV4::ExecutionEngine::toVariant(value, property.metaType()); diff --git a/tests/auto/qml/qqmlecmascript/data/resetGadget.qml b/tests/auto/qml/qqmlecmascript/data/resetGadget.qml new file mode 100644 index 0000000000..2bc196da34 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/resetGadget.qml @@ -0,0 +1,9 @@ +import Qt.test + +ResettableGadgetHolder { + id: root + property bool trigger: false + onTriggerChanged: { + root.g.value = undefined + } +} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp index 40f5e5cf5c..d7a585de1a 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.cpp +++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp @@ -542,6 +542,7 @@ void registerTypes() qmlRegisterType<Receiver>("Qt.test", 1,0, "Receiver"); qmlRegisterType<Sender>("Qt.test", 1,0, "Sender"); qmlRegisterTypesAndRevisions<ReadOnlyBindable>("Qt.test", 1); + qmlRegisterTypesAndRevisions<ResettableGadgetHolder>("Qt.test", 1); } #include "testtypes.moc" diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index ff9dda36d1..bc4d97237c 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -2000,6 +2000,41 @@ public: QBindable<int> bindableX() const { return &_xProp; } }; +class ResettableGadget +{ + Q_GADGET + Q_PROPERTY(qreal value READ value WRITE setValue RESET resetValue) + + qreal m_value = 0; + +public: + qreal value() const { return m_value; } + void setValue(qreal val) { m_value = val; } + void resetValue() { m_value = 42; } +}; + +class ResettableGadgetHolder : public QObject { + Q_OBJECT + QML_ELEMENT + + Q_PROPERTY(ResettableGadget g READ g WRITE setG NOTIFY gChanged) + ResettableGadget m_g; + +signals: + void gChanged(); + +public: + ResettableGadget g() const { return m_g; } + void setG(ResettableGadget newG) + { + if (m_g.value() == newG.value()) + return; + m_g = newG; + Q_EMIT gChanged(); + } +}; + + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index edb1e9ba80..98f81c4648 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -416,6 +416,8 @@ private slots: void doNotCrashOnReadOnlyBindable(); + void resetGadet(); + private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); static void verifyContextLifetime(const QQmlRefPointer<QQmlContextData> &ctxt); @@ -10373,6 +10375,20 @@ void tst_qqmlecmascript::doNotCrashOnReadOnlyBindable() QCOMPARE(o->property("x").toInt(), 7); } +void tst_qqmlecmascript::resetGadet() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("resetGadget.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + auto resettableGadgetHolder = qobject_cast<ResettableGadgetHolder *>(o.get()); + QVERIFY(resettableGadgetHolder); + QCOMPARE(resettableGadgetHolder->g().value(), 0); + resettableGadgetHolder->setProperty("trigger", QVariant::fromValue(true)); + QCOMPARE(resettableGadgetHolder->g().value(), 42); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" |