diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2012-11-15 13:08:12 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-23 17:04:00 +0100 |
commit | 0457f8bb8e0dbfe1850be645ae9a704ebb85eebd (patch) | |
tree | 826c282ba0740d5e4412173ee1acd8ccb51224ee /src | |
parent | 526bac5f693ecc028985064a5ae04d3106b9ef68 (diff) |
Fix selection in QTableView when rows and columns have been moved
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 <tmartsum@gmail.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 32869ad292..0fd4900b29 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); + } } } |