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>
This commit is contained in:
Miikka Heikkinen 2012-11-15 13:08:12 +02:00 committed by The Qt Project
parent 526bac5f69
commit 0457f8bb8e

View File

@ -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);
}
}
}