From 1969991c4a4bd39ee224b0fa3c8cffa51f061757 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 1 Sep 2016 16:46:29 +0200 Subject: Fix binding re-evaluation when list model properties change This is a regression from commit 4876ea6a18ccdfd72014582aa5d50ab9f6b6ec9e, which avoided returning an expensive QObject when calling get() but also lost the ability to perform binding captures when accessing the properties. This change restores the captures by performing them by hand in get() and also triggering the notifiers directly when the values change, without creating the QObject. Task-number: QTBUG-52356 Change-Id: Ia429ffafd4032b63d3e592aa63bb0864a24e0965 Reviewed-by: Michael Brasser Reviewed-by: Lars Knoll --- .../qml/qqmllistmodel/data/bindingsOnGetResult.qml | 27 ++++++++++++++++++++++ tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 13 +++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/auto/qml/qqmllistmodel/data/bindingsOnGetResult.qml (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmllistmodel/data/bindingsOnGetResult.qml b/tests/auto/qml/qqmllistmodel/data/bindingsOnGetResult.qml new file mode 100644 index 0000000000..6bf750dcda --- /dev/null +++ b/tests/auto/qml/qqmllistmodel/data/bindingsOnGetResult.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +QtObject { + property ListModel model: ListModel { + ListElement { modified: false } + ListElement { modified: false } + ListElement { modified: false } + ListElement { modified: false } + ListElement { modified: false } + } + + property bool isModified: { + for (var i = 0; i < model.count; ++i) { + if (model.get(i).modified) + return true; + } + return false; + } + + property bool success: false + Component.onCompleted: { + // trigger read and setup of property captures + success = isModified + model.setProperty(0, "modified", true) + success = isModified + } +} diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index 6b1deceaf2..8a90be601a 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -127,6 +127,7 @@ private slots: void datetime_data(); void about_to_be_signals(); void modify_through_delegate(); + void bindingsOnGetResult(); }; bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object) @@ -1474,6 +1475,18 @@ void tst_qqmllistmodel::modify_through_delegate() QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("age")).toInt(), 18); } +void tst_qqmllistmodel::bindingsOnGetResult() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("bindingsOnGetResult.qml")); + QVERIFY2(!component.isError(), qPrintable(component.errorString())); + + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + + QVERIFY(obj->property("success").toBool()); +} + QTEST_MAIN(tst_qqmllistmodel) #include "tst_qqmllistmodel.moc" -- cgit v1.2.3