diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-09-08 15:52:05 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-09-09 20:41:31 +0000 |
commit | 8a0135b82e9b354fe5304144a12c850c248f2a79 (patch) | |
tree | 4d1a0fd87d387bc9ea076780d8f2afbdfa193f0a | |
parent | 945c59f42fd1ab171df90b137ca40286120364f7 (diff) |
Add QQuickContainer::contentChildrenChanged() notifier
Makes possible to bind contentChildren to ExclusiveGroup::checkables.
Change-Id: Idf9afabb93f78b012d2ca5c77fe79f34bf76e584
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r-- | src/controls/qquickcontainer.cpp | 1 | ||||
-rw-r--r-- | src/controls/qquickcontainer_p.h | 3 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_tabbar.qml | 36 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/controls/qquickcontainer.cpp b/src/controls/qquickcontainer.cpp index 5138dc95..20b900a2 100644 --- a/src/controls/qquickcontainer.cpp +++ b/src/controls/qquickcontainer.cpp @@ -57,6 +57,7 @@ void QQuickContainerPrivate::init() Q_Q(QQuickContainer); contentModel = new QQmlObjectModel(q); QObject::connect(contentModel, &QQmlObjectModel::countChanged, q, &QQuickContainer::countChanged); + QObject::connect(contentModel, &QQmlObjectModel::childrenChanged, q, &QQuickContainer::contentChildrenChanged); } void QQuickContainerPrivate::cleanup() diff --git a/src/controls/qquickcontainer_p.h b/src/controls/qquickcontainer_p.h index 22fa059a..8fe35faf 100644 --- a/src/controls/qquickcontainer_p.h +++ b/src/controls/qquickcontainer_p.h @@ -61,7 +61,7 @@ class Q_QUICKCONTROLS_EXPORT QQuickContainer : public QQuickControl Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) Q_PROPERTY(QVariant contentModel READ contentModel CONSTANT FINAL) Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL) - Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren FINAL) + Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) Q_CLASSINFO("DefaultProperty", "contentData") public: @@ -81,6 +81,7 @@ public: Q_SIGNALS: void countChanged(); + void contentChildrenChanged(); protected: QQuickContainer(QQuickContainerPrivate &dd, QQuickItem *parent); diff --git a/tests/auto/controls/data/tst_tabbar.qml b/tests/auto/controls/data/tst_tabbar.qml index 1383431c..db5f45fa 100644 --- a/tests/auto/controls/data/tst_tabbar.qml +++ b/tests/auto/controls/data/tst_tabbar.qml @@ -60,6 +60,21 @@ TestCase { TabBar { } } + SignalSpy { + id: contentChildrenSpy + signalName: "contentChildrenChanged" + } + + function init() { + verify(!contentChildrenSpy.target) + compare(contentChildrenSpy.count, 0) + } + + function cleanup() { + contentChildrenSpy.target = null + contentChildrenSpy.clear() + } + function test_defaults() { var control = tabBar.createObject(testCase) verify(control) @@ -111,18 +126,24 @@ TestCase { control.currentIndexChanged.connect(verifyCurrentIndexCountDiff) control.countChanged.connect(verifyCurrentIndexCountDiff) + contentChildrenSpy.target = control + verify(contentChildrenSpy.valid) + compare(control.count, 0) compare(control.currentIndex, -1) control.addItem(tabButton.createObject(control, {text: "1"})) compare(control.count, 1) compare(control.currentIndex, 0) compare(control.currentItem.text, "1") + compare(contentChildrenSpy.count, 1) + control.addItem(tabButton.createObject(control, {text: "2"})) compare(control.count, 2) compare(control.currentIndex, 0) compare(control.currentItem.text, "1") compare(control.itemAt(0).text, "1") compare(control.itemAt(1).text, "2") + compare(contentChildrenSpy.count, 2) control.currentIndex = 1 @@ -133,6 +154,7 @@ TestCase { compare(control.itemAt(0).text, "1") compare(control.itemAt(1).text, "3") compare(control.itemAt(2).text, "2") + compare(contentChildrenSpy.count, 4) // append + insert->move control.insertItem(0, tabButton.createObject(control, {text: "4"})) compare(control.count, 4) @@ -142,6 +164,7 @@ TestCase { compare(control.itemAt(1).text, "1") compare(control.itemAt(2).text, "3") compare(control.itemAt(3).text, "2") + compare(contentChildrenSpy.count, 6) // append + insert->move control.insertItem(control.count, tabButton.createObject(control, {text: "5"})) compare(control.count, 5) @@ -152,6 +175,7 @@ TestCase { compare(control.itemAt(2).text, "3") compare(control.itemAt(3).text, "2") compare(control.itemAt(4).text, "5") + compare(contentChildrenSpy.count, 7) control.removeItem(control.count - 1) compare(control.count, 4) @@ -161,6 +185,7 @@ TestCase { compare(control.itemAt(1).text, "1") compare(control.itemAt(2).text, "3") compare(control.itemAt(3).text, "2") + compare(contentChildrenSpy.count, 8) control.removeItem(0) compare(control.count, 3) @@ -169,6 +194,7 @@ TestCase { compare(control.itemAt(0).text, "1") compare(control.itemAt(1).text, "3") compare(control.itemAt(2).text, "2") + compare(contentChildrenSpy.count, 9) control.removeItem(1) compare(control.count, 2) @@ -176,16 +202,19 @@ TestCase { compare(control.currentItem.text, "2") compare(control.itemAt(0).text, "1") compare(control.itemAt(1).text, "2") + compare(contentChildrenSpy.count, 10) control.removeItem(1) compare(control.count, 1) compare(control.currentIndex, 0) compare(control.currentItem.text, "1") compare(control.itemAt(0).text, "1") + compare(contentChildrenSpy.count, 11) control.removeItem(0) compare(control.count, 0) compare(control.currentIndex, -1) + compare(contentChildrenSpy.count, 12) control.destroy() } @@ -214,24 +243,31 @@ TestCase { return true } + contentChildrenSpy.target = control + verify(contentChildrenSpy.valid) + verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", ""])) verify(compareObjectNames(control.contentChildren, ["button1", "button2"])) control.addItem(tabButton.createObject(control, {objectName: "button3"})) verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", "", "button3"])) verify(compareObjectNames(control.contentChildren, ["button1", "button2", "button3"])) + compare(contentChildrenSpy.count, 1) control.insertItem(0, tabButton.createObject(control, {objectName: "button4"})) verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", "", "button3", "button4"])) verify(compareObjectNames(control.contentChildren, ["button4", "button1", "button2", "button3"])) + compare(contentChildrenSpy.count, 3) // append + insert->move control.moveItem(1, 2) verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", "", "button3", "button4"])) verify(compareObjectNames(control.contentChildren, ["button4", "button2", "button1", "button3"])) + compare(contentChildrenSpy.count, 4) control.removeItem(0) verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", "", "button3"])) verify(compareObjectNames(control.contentChildren, ["button2", "button1", "button3"])) + compare(contentChildrenSpy.count, 5) control.destroy() } |