summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2014-04-14 12:44:34 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-15 11:15:56 +0200
commitf580f4ce858a332e62948c1c5372995e9a576452 (patch)
treef5b633ce0a4f68c56f762e5d80075434e96e1f20
parent53fca456b2d5c4d290592846c0a14242ac218e1d (diff)
downloadqtquickcontrols-f580f4ce858a332e62948c1c5372995e9a576452.tar.gz
Ensure that styleData.row is initialized in delegates
While we specifically documented that you should not depend on the value being correct in onCompleted for 5.3, it is not optimal that the initial value is consistently set to 0 and later changed to it's appropriate value. This patch ensures that delegates are not instantiated until after the model model and row values have been fully initialized. Task-number: QTBUG-38307 Change-Id: Ib3300539a0283c997ab8b808fb229d3f22ed6324 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r--src/controls/TableView.qml5
-rw-r--r--tests/auto/controls/data/tst_tableview.qml18
2 files changed, 21 insertions, 2 deletions
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index 84046138..85ff4019 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -861,7 +861,7 @@ ScrollView {
Loader {
id: rowstyle
// row delegate
- sourceComponent: root.rowDelegate
+ sourceComponent: rowitem.itemModel !== undefined ? root.rowDelegate : null
// Row fills the view width regardless of item size
// But scrollbar should not adjust to it
height: item ? item.height : 16
@@ -891,7 +891,8 @@ ScrollView {
width: columnItem.width
height: parent ? parent.height : 0
visible: columnItem.visible
- sourceComponent: columnItem.delegate ? columnItem.delegate : itemDelegate
+ sourceComponent: rowitem.itemModel !== undefined ? // delays construction until model is initialized
+ (columnItem.delegate ? columnItem.delegate : itemDelegate) : null
// these properties are exposed to the item delegate
readonly property var model: itemModel
diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml
index a9f07a8b..c99d2dcd 100644
--- a/tests/auto/controls/data/tst_tableview.qml
+++ b/tests/auto/controls/data/tst_tableview.qml
@@ -385,6 +385,24 @@ TestCase {
verify(table.selection.contains(8))
}
+ function test_initializedStyleData() {
+ var table = Qt.createQmlObject('import QtQuick.Controls 1.2; \
+ import QtQuick 2.2; \
+ TableView { \
+ model: 3; \
+ TableViewColumn{} \
+ property var items: []; \
+ property var rows: []; \
+ itemDelegate: Item{ Component.onCompleted: { items.push(styleData.row) } } \
+ rowDelegate: Item{ Component.onCompleted: { if (styleData.row !== undefined) rows.push(styleData.row) } } \
+ }'
+ , testCase, '')
+ waitForRendering(table)
+ compare(table.items, [0, 1, 2]);
+ compare(table.rows, [0, 1, 2]);
+ }
+
+
function test_usingcppqobjectmodel() {
var component = Qt.createComponent("tableview/table1_qobjectmodel.qml")