summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/gui/itemviews/qabstractitemview.cpp12
-rw-r--r--src/gui/itemviews/qabstractitemview_p.h1
-rw-r--r--src/gui/itemviews/qtableview.cpp28
3 files changed, 39 insertions, 2 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp
index 9d977a5..757ded9 100644
--- a/src/gui/itemviews/qabstractitemview.cpp
+++ b/src/gui/itemviews/qabstractitemview.cpp
@@ -69,6 +69,7 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate()
: model(QAbstractItemModelPrivate::staticEmptyModel()),
itemDelegate(0),
selectionModel(0),
+ ctrlDragSelectionFlag(QItemSelectionModel::NoUpdate),
selectionMode(QAbstractItemView::ExtendedSelection),
selectionBehavior(QAbstractItemView::SelectItems),
currentlyCommittingEditor(0),
@@ -1589,6 +1590,11 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event)
d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
d->autoScroll = autoScroll;
QRect rect(d->pressedPosition - offset, pos);
+ if (command.testFlag(QItemSelectionModel::Toggle)) {
+ command &= ~QItemSelectionModel::Toggle;
+ d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
+ command |= d->ctrlDragSelectionFlag;
+ }
setSelection(rect, command);
// signal handlers may change the model
@@ -1659,6 +1665,10 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event)
if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) {
setState(DragSelectingState);
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
+ if (command.testFlag(QItemSelectionModel::Toggle)) {
+ command &= ~QItemSelectionModel::Toggle;
+ command |= d->ctrlDragSelectionFlag;
+ }
// Do the normalize ourselves, since QRect::normalized() is flawed
QRect selectionRect = QRect(topLeft, bottomRight);
@@ -1699,6 +1709,8 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event)
EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers);
bool edited = edit(index, trigger, event);
+ d->ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate;
+
//in the case the user presses on no item we might decide to clear the selection
if (d->selectionModel && !index.isValid())
d->selectionModel->select(QModelIndex(), selectionCommand(index, event));
diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h
index 725d0a9..6b1ec8e 100644
--- a/src/gui/itemviews/qabstractitemview_p.h
+++ b/src/gui/itemviews/qabstractitemview_p.h
@@ -342,6 +342,7 @@ public:
QMap<int, QPointer<QAbstractItemDelegate> > rowDelegates;
QMap<int, QPointer<QAbstractItemDelegate> > columnDelegates;
QPointer<QItemSelectionModel> selectionModel;
+ QItemSelectionModel::SelectionFlag ctrlDragSelectionFlag;
QAbstractItemView::SelectionMode selectionMode;
QAbstractItemView::SelectionBehavior selectionBehavior;
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);