summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews/qtableview.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-09-17 11:07:30 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-09-17 11:21:34 (GMT)
commit0644e3dce532b1df00a77d3a30c61d6b75d3ff30 (patch)
tree7b4acda816afe82688a26debacc5ddbe4a50646e /src/gui/itemviews/qtableview.cpp
parent56987a10b1bedacc6515de4c28240126ab0cbf29 (diff)
downloadQt-0644e3dce532b1df00a77d3a30c61d6b75d3ff30.zip
Qt-0644e3dce532b1df00a77d3a30c61d6b75d3ff30.tar.gz
Qt-0644e3dce532b1df00a77d3a30c61d6b75d3ff30.tar.bz2
Control-drag header selection behaved wierdly.
The QItemSelectionModel::Current was not set in QTableViewPrivate::selectColumn(). However, Control-drag selection in QTableView behaved differently than other software such as OpenOffice's spreadsheet. Now the behaviour when Control-dragging is that the selection will be set to the opposite of the selection state of the first cell. If that cell is selected, we will deselected the cells while dragging, and conversely, if it isn't selected, the cells will be selected. Reviewed-by: Olivier Task-number: QT-1435 Task-number: 191545
Diffstat (limited to 'src/gui/itemviews/qtableview.cpp')
-rw-r--r--src/gui/itemviews/qtableview.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index 684da3f..f1ffaa6 100644
--- a/src/gui/itemviews/qtableview.cpp
+++ b/src/gui/itemviews/qtableview.cpp
@@ -2519,9 +2519,21 @@ void QTableViewPrivate::selectRow(int row, bool anchor)
QModelIndex index = model->index(row, column, root);
QItemSelectionModel::SelectionFlags command = q->selectionCommand(index);
selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
- if ((!(command & QItemSelectionModel::Current) && anchor)
+ if ((anchor && !(command & QItemSelectionModel::Current))
|| (q->selectionMode() == QTableView::SingleSelection))
rowSectionAnchor = row;
+
+ if (q->selectionMode() != QTableView::SingleSelection
+ && command.testFlag(QItemSelectionModel::Toggle)) {
+ if (anchor)
+ ctrlDragSelectionFlag = verticalHeader->selectionModel()->selectedRows().contains(index)
+ ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
+ command &= ~QItemSelectionModel::Toggle;
+ command |= ctrlDragSelectionFlag;
+ if (!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())
@@ -2545,9 +2557,21 @@ void QTableViewPrivate::selectColumn(int column, bool anchor)
QModelIndex index = model->index(row, column, root);
QItemSelectionModel::SelectionFlags command = q->selectionCommand(index);
selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
- if ((!(command & QItemSelectionModel::Current) && anchor)
+ if ((anchor && !(command & QItemSelectionModel::Current))
|| (q->selectionMode() == QTableView::SingleSelection))
columnSectionAnchor = column;
+
+ if (q->selectionMode() != QTableView::SingleSelection
+ && command.testFlag(QItemSelectionModel::Toggle)) {
+ if (anchor)
+ ctrlDragSelectionFlag = horizontalHeader->selectionModel()->selectedColumns().contains(index)
+ ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
+ command &= ~QItemSelectionModel::Toggle;
+ command |= ctrlDragSelectionFlag;
+ if (!anchor)
+ command |= QItemSelectionModel::Current;
+ }
+
QModelIndex tl = model->index(0, qMin(columnSectionAnchor, column), root);
QModelIndex br = model->index(model->rowCount(root) - 1,
qMax(columnSectionAnchor, column), root);