diff options
author | Martin Jones <martin.jones@nokia.com> | 2012-07-02 11:52:08 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-02 06:09:21 +0200 |
commit | 2d1c7f6348943b9adbab3b940d17896c15636156 (patch) | |
tree | 00ad9dde8e689f24626961507872059c3ceeda58 /tests/auto/quick/qquickvisualdatamodel | |
parent | 6ede3b0138bed45f91dfa6b84b662b7f342b45a3 (diff) | |
download | qtdeclarative-2d1c7f6348943b9adbab3b940d17896c15636156.tar.gz |
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 <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickvisualdatamodel')
-rw-r--r-- | tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml | 4 | ||||
-rw-r--r-- | tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp | 41 |
2 files changed, 44 insertions, 1 deletions
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<DataObject*>(dataList[0]); + obj->setSubName("SubItem 1"); + + QMetaObject::invokeMethod(listview, "changeSectionProperty"); + section = findItem<QQuickText>(contentItem, "section", 0); + QCOMPARE(section->text(), QString("SubItem 1")); } void tst_qquickvisualdatamodel::singleRole() |