summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qtableview.cpp
diff options
context:
space:
mode:
authorVyacheslav Grigoryev <armagvvg@gmail.com>2016-05-06 01:29:27 +0300
committerThorbjørn Lund Martsum <tmartsum@gmail.com>2016-05-09 05:14:38 +0000
commit558718ff4406638410364db7c1310cb38963d6df (patch)
tree114b3b7f765fc630bdce9b5369ec128840cf9ce4 /src/widgets/itemviews/qtableview.cpp
parent194a56ea79a4aa11a01dda0491427bb5ba4b37fd (diff)
QTableView: Fix selection for reordered or hidden rows/columns
The old code sometimes made incorrect selections when rows or columns were hidden or moved. It used logical top left and bottom right indexes to create a selection rectangle. However on moved or hidden cells a wrong rectangle was made. This fix calculates a simple rectangle without hidden cells and makes use of the row/column select functionality provided by the selection model, to make the right selection. [ChangeLog][QtWidgets][QTableView] Fixed a selection bug when rows or columns were hidden (QTBUG-50171) Task-number: QTBUG-50171 Change-Id: Id186012af26da7b2051ff5eb1c13e6b7494cca77 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews/qtableview.cpp')
-rw-r--r--src/widgets/itemviews/qtableview.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index ee0d41ce15..b68c105aba 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -3249,13 +3249,12 @@ void QTableViewPrivate::selectRow(int row, bool anchor)
command |= QItemSelectionModel::Current;
}
- 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);
+ QModelIndex upper = model->index(qMin(rowSectionAnchor, row), column, root);
+ QModelIndex lower = model->index(qMax(rowSectionAnchor, row), column, root);
+ if ((verticalHeader->sectionsMoved() && upper.row() != lower.row())) {
+ q->setSelection(q->visualRect(upper) | q->visualRect(lower), command | QItemSelectionModel::Rows);
} else {
- selectionModel->select(QItemSelection(tl, br), command);
+ selectionModel->select(QItemSelection(upper, lower), command | QItemSelectionModel::Rows);
}
}
}
@@ -3289,14 +3288,12 @@ void QTableViewPrivate::selectColumn(int column, bool anchor)
command |= QItemSelectionModel::Current;
}
- 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())
- || verticalHeader->sectionsMoved()) {
- q->setSelection(q->visualRect(tl)|q->visualRect(br), command);
+ QModelIndex left = model->index(row, qMin(columnSectionAnchor, column), root);
+ QModelIndex right = model->index(row, qMax(columnSectionAnchor, column), root);
+ if ((horizontalHeader->sectionsMoved() && left.column() != right.column())) {
+ q->setSelection(q->visualRect(left) | q->visualRect(right), command | QItemSelectionModel::Columns);
} else {
- selectionModel->select(QItemSelection(tl, br), command);
+ selectionModel->select(QItemSelection(left, right), command | QItemSelectionModel::Columns);
}
}
}