From 0457f8bb8e0dbfe1850be645ae9a704ebb85eebd Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 15 Nov 2012 13:08:12 +0200 Subject: [PATCH] Fix selection in QTableView when rows and columns have been moved MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The determination of top left and bottom right model indexes for the selection used logical indexes, which resulted in selection truncating itself if the first or last row or column had been moved to different position on the table. Changed the logic to use visual indexes instead. Task-number: QTBUG-28009 Change-Id: I4eb9dab690dafda9d2ab7c452dd6271fad70cb30 Reviewed-by: Thorbjørn Lund Martsum Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qtableview.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 32869ad..0fd4900 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3133,12 +3133,14 @@ void QTableViewPrivate::selectRow(int row, bool anchor) command |= QItemSelectionModel::Current; } - QModelIndex tl = model->index(qMin(rowSectionAnchor, row), 0, root); - QModelIndex br = model->index(qMax(rowSectionAnchor, row), model->columnCount(root) - 1, root); - if (verticalHeader->sectionsMoved() && tl.row() != br.row()) + QModelIndex tl = model->index(qMin(rowSectionAnchor, row), logicalColumn(0), root); + QModelIndex br = model->index(qMax(rowSectionAnchor, row), logicalColumn(model->columnCount(root) - 1), root); + if ((verticalHeader->sectionsMoved() && tl.row() != br.row()) + || horizontalHeader->sectionsMoved()) { q->setSelection(q->visualRect(tl)|q->visualRect(br), command); - else + } else { selectionModel->select(QItemSelection(tl, br), command); + } } } @@ -3171,13 +3173,15 @@ void QTableViewPrivate::selectColumn(int column, bool anchor) command |= QItemSelectionModel::Current; } - QModelIndex tl = model->index(0, qMin(columnSectionAnchor, column), root); - QModelIndex br = model->index(model->rowCount(root) - 1, + QModelIndex tl = model->index(logicalRow(0), qMin(columnSectionAnchor, column), root); + QModelIndex br = model->index(logicalRow(model->rowCount(root) - 1), qMax(columnSectionAnchor, column), root); - if (horizontalHeader->sectionsMoved() && tl.column() != br.column()) + if ((horizontalHeader->sectionsMoved() && tl.column() != br.column()) + || verticalHeader->sectionsMoved()) { q->setSelection(q->visualRect(tl)|q->visualRect(br), command); - else + } else { selectionModel->select(QItemSelection(tl, br), command); + } } } -- 2.7.4