From e06cf6eacc1dd71ed5f3463d0ec5bbb9ff27dd5f Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jens.bache-wiig@digia.com> Date: Wed, 15 May 2013 14:17:23 +0200 Subject: [PATCH] Remove currentRowItem and rename positionViewAtIndex Again trying to make the api a bit more consistent at using row vs. index. Change-Id: I769ca34c7bde628757a19fd47744b5cb1054a154 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Caroline Chao <caroline.chao@digia.com> --- src/controls/TableView.qml | 23 +++++++++------------ tests/auto/controls/data/tst_tableview.qml | 24 +++++++++++----------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml index cf8051512..132351b53 100644 --- a/src/controls/TableView.qml +++ b/src/controls/TableView.qml @@ -202,10 +202,6 @@ ScrollView { This is the content footer of the TableView */ property alias contentFooter: listView.footer - /*! \qmlproperty Item TableView::currentRowItem - This is the current item of the TableView */ - property alias currentRowItem: listView.currentItem - /*! \qmlproperty int TableView::rowCount The current number of rows */ readonly property alias rowCount: listView.count @@ -227,15 +223,18 @@ ScrollView { */ property alias currentRow: listView.currentIndex + /*! \internal */ + property alias __currentRowItem: listView.currentItem + /*! \qmlsignal TableView::activated() Emitted when the user activates an item by single or double-clicking (depending on the platform). */ signal activated /*! - \qmlmethod TableView::positionViewAtIndex + \qmlmethod TableView::positionViewAtRow( int row, PositionMode mode ) - Positions the view such that the \a index is at the position specified by \a mode: + Positions the view such that the specified \a row is at the position defined by \a mode: \list \li ListView.Beginning - position item at the top of the view. \li ListView.Center - position item in the center of the view. @@ -245,27 +244,25 @@ ScrollView { at the top of the view. \endlist - If using the \a index to position the view creates an empty space at the beginning + If positioning the \a row creates an empty space at the beginning or end of the view, then the view is positioned at the boundary. - The correct way to bring an item into view is with positionViewAtIndex. - Note that this method should only be called after the Component has completed. To position the view at startup, this method should be called by Component.onCompleted. For example, to position the view at the end at startup: \code - Component.onCompleted: table.positionViewAtIndex(rowCount -1, ListView.Contain) + Component.onCompleted: table.positionViewAtRow(rowCount -1, ListView.Contain) \endcode Depending on how the model is populated, the model may not be ready when TableView Component.onCompleted is called. In that case you may need to - delay the call to positionViewAtIndex by using a \l {Timer}. + delay the call to positionViewAtRow by using a \l {Timer}. */ - function positionViewAtIndex(index, mode) { - listView.positionViewAtIndex(index, mode) + function positionViewAtRow(row, mode) { + listView.positionViewAtRow(row, mode) } style: Qt.createComponent(Settings.theme() + "/TableViewStyle.qml", root) diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml index bc38ad46f..6de8d5779 100644 --- a/tests/auto/controls/data/tst_tableview.qml +++ b/tests/auto/controls/data/tst_tableview.qml @@ -77,12 +77,12 @@ TestCase { var table = Qt.createQmlObject(test_instanceStr, testCase, '') compare(table.currentRow, -1) verify(table.rowCount === 10) - verify (table.currentRowItem === null) + verify (table.__currentRowItem === null) table.currentRow = 0 - verify(table.currentRowItem !== null) + verify(table.__currentRowItem !== null) verify (table.currentRow === 0) table.currentRow = 3 - verify(table.currentRowItem !== null) + verify(table.__currentRowItem !== null) verify (table.currentRow === 3) table.destroy() } @@ -95,8 +95,8 @@ TestCase { verify(table !== null, "table created is null") table.forceActiveFocus(); - verify(table.currentRowItem !== undefined, "No current item found") - var label = findAChild(table.currentRowItem, "label") + verify(table.__currentRowItem !== undefined, "No current item found") + var label = findAChild(table.__currentRowItem, "label") verify(label !== undefined) compare(label.text, data.expected.toString()); table.destroy(); @@ -114,8 +114,8 @@ TestCase { var valuefrommodel = table.model.value; verify(valuefrommodel !== undefined, "The model has no defined value") - verify(table.currentRowItem !== undefined, "No current item found") - var label = findAChild(table.currentRowItem, "label") + verify(table.__currentRowItem !== undefined, "No current item found") + var label = findAChild(table.__currentRowItem, "label") verify(label !== undefined) compare(label.text, valuefrommodel.toString()); table.destroy(); @@ -136,8 +136,8 @@ TestCase { var valuefrommodel = table.model.dataAt(table.currentRow) verify(valuefrommodel !== undefined, "The model has no defined value") - verify(table.currentRowItem !== undefined, "No current item found") - var label = findAChild(table.currentRowItem, "label") + verify(table.__currentRowItem !== undefined, "No current item found") + var label = findAChild(table.__currentRowItem, "label") verify(label !== undefined) compare(label.text, valuefrommodel.toString()) table.destroy(); @@ -161,8 +161,8 @@ TestCase { // to go to next row (this model has 3 rows, read the second row) table.__incrementCurrentIndex() - verify(table.currentRowItem !== undefined, "No current item found") - var label = findAChild(table.currentRowItem, "label") + verify(table.__currentRowItem !== undefined, "No current item found") + var label = findAChild(table.__currentRowItem, "label") verify(label !== undefined) compare(label.text, data.expected.toString()); table.destroy(); @@ -228,7 +228,7 @@ TestCase { table.destroy() } - // In TableView, drawn text = table.currentRowItem.children[1].children[1].itemAt(0).children[0].children[0].text + // In TableView, drawn text = table.__currentRowItem.children[1].children[1].itemAt(0).children[0].children[0].text function findAChild(item, name) { -- GitLab