From 2d1c7f6348943b9adbab3b940d17896c15636156 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 2 Jul 2012 11:52:08 +1000 Subject: section.property cannot deal with nested properties Handle nested property names in section.property. Task-number: QTBUG-24569 Change-Id: I0ea6003313108b8232bcd3a3015a4dbbd0753cec Reviewed-by: Andrew den Exter --- .../qquickvisualdatamodel/data/objectlist.qml | 4 +++ .../tst_qquickvisualdatamodel.cpp | 41 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml b/tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml index 99151aa9e1..b0d5bd8032 100644 --- a/tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml +++ b/tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml @@ -14,6 +14,10 @@ ListView { Text { objectName: "section"; text: parent.ListView.section } } } + + function changeSectionProperty() { + section.property = "object.subName" + } section.property: "name" section.criteria: ViewSection.FullString } diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 5da7dc7fba..4684df2cae 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -151,17 +151,42 @@ public: }; #endif +class DataSubObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString subName READ subName WRITE setSubName NOTIFY subNameChanged) + +public: + DataSubObject(QObject *parent=0) : QObject(parent) {} + + QString subName() const { return m_subName; } + void setSubName(const QString &name) { + if (name != m_subName) { + m_subName = name; + emit subNameChanged(); + } + } + +signals: + void subNameChanged(); + +private: + QString m_subName; +}; + class DataObject : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QObject *object READ object) public: DataObject(QObject *parent=0) : QObject(parent) {} DataObject(const QString &name, const QString &color, QObject *parent=0) - : QObject(parent), m_name(name), m_color(color) { } + : QObject(parent), m_name(name), m_color(color), m_object(new DataSubObject(this)) { } QString name() const { return m_name; } @@ -180,6 +205,11 @@ public: } } + QObject *object() const { return m_object; } + void setSubName(const QString &sn) { + m_object->setSubName(sn); + } + signals: void nameChanged(); void colorChanged(); @@ -187,6 +217,7 @@ signals: private: QString m_name; QString m_color; + DataSubObject *m_object; }; class ItemRequester : public QObject @@ -533,6 +564,14 @@ void tst_qquickvisualdatamodel::objectListModel() dataList[0]->setProperty("name", QLatin1String("Changed")); QCOMPARE(name->text(), QString("Changed")); QCOMPARE(name->property("modelName").toString(), QString("Changed")); + + // Test resolving nested section property + DataObject *obj = static_cast(dataList[0]); + obj->setSubName("SubItem 1"); + + QMetaObject::invokeMethod(listview, "changeSectionProperty"); + section = findItem(contentItem, "section", 0); + QCOMPARE(section->text(), QString("SubItem 1")); } void tst_qquickvisualdatamodel::singleRole() -- cgit v1.2.3