diff options
-rw-r--r-- | src/controls/TableView.qml | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_tableview.qml | 18 |
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") |