summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp60
-rw-r--r--src/gui/itemviews/qitemselectionmodel_p.h2
-rw-r--r--src/gui/itemviews/qtableview.cpp17
3 files changed, 44 insertions, 35 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 0f35ac1..06c345f 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -590,31 +590,43 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare
emit q->currentColumnChanged(currentIndex, old);
}
- // update selectionsx
- QModelIndex tl = model->index(start, 0, parent);
- QModelIndex br = model->index(end, model->columnCount(parent) - 1, parent);
- recursiveDeselect(QItemSelectionRange(tl, br));
- finalize();
-}
-
-void QItemSelectionModelPrivate::recursiveDeselect(const QItemSelectionRange &range)
-{
- Q_Q(QItemSelectionModel);
-
- QItemSelection sel(range.topLeft(), range.bottomRight());
- q->select(sel, QItemSelectionModel::Deselect);
-
- QModelIndexList idxList = range.indexes();
- QModelIndexList::const_iterator it = idxList.begin();
- for (; it != idxList.end(); ++it)
- {
- if (!model->hasChildren(*it))
- continue;
-
- const QModelIndex &firstChild = it->child(0,0);
- const QModelIndex &lastChild = it->child(model->rowCount(*it) - 1, model->columnCount(*it) - 1);
- recursiveDeselect(QItemSelectionRange(firstChild, lastChild));
+ QItemSelection deselected;
+ QItemSelection::iterator it = currentSelection.begin();
+ while (it != currentSelection.end()) {
+ if (it->topLeft().parent() != parent) { // Check parents until reaching root or contained in range
+ QModelIndex itParent = it->topLeft().parent();
+ while (itParent.isValid() && itParent.parent() != parent)
+ itParent = itParent.parent();
+
+ if (parent.isValid() && start <= itParent.row() && itParent.row() <= end) {
+ deselected.append(*it);
+ it = currentSelection.erase(it);
+ } else {
+ ++it;
+ }
+ } else if (start <= it->bottom() && it->bottom() <= end // Full inclusion
+ && start <= it->top() && it->top() <= end) {
+ deselected.append(*it);
+ it = currentSelection.erase(it);
+ } else if (start <= it->top() && it->top() <= end) { // Top intersection
+ deselected.append(QItemSelectionRange(it->topLeft(), model->index(end, it->left(), it->parent())));
+ it = currentSelection.insert(it, QItemSelectionRange(model->index(end + 1, it->left(), it->parent()),
+ it->bottomRight()));
+ it = currentSelection.erase(++it);
+ } else if (start <= it->bottom() && it->bottom() <= end) { // Bottom intersection
+ deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()), it->bottomRight()));
+ it = currentSelection.insert(it, QItemSelectionRange(it->topLeft(),
+ model->index(start - 1, it->right(), it->parent())));
+ it = currentSelection.erase(++it);
+ } else {
+ if (it->top() < start && end < it->bottom()) // Middle intersection (do nothing)
+ deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()),
+ model->index(end, it->left(), it->parent())));
+ ++it;
+ }
}
+
+ emit q->selectionChanged(QItemSelection(), deselected);
}
/*!
diff --git a/src/gui/itemviews/qitemselectionmodel_p.h b/src/gui/itemviews/qitemselectionmodel_p.h
index 8176d4c..18ad506 100644
--- a/src/gui/itemviews/qitemselectionmodel_p.h
+++ b/src/gui/itemviews/qitemselectionmodel_p.h
@@ -77,8 +77,6 @@ public:
void _q_layoutAboutToBeChanged();
void _q_layoutChanged();
- void recursiveDeselect(const QItemSelectionRange &range);
-
inline void remove(QList<QItemSelectionRange> &r)
{
QList<QItemSelectionRange>::const_iterator it = r.constBegin();
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index 2009499..8fc99a0 100644
--- a/src/gui/itemviews/qtableview.cpp
+++ b/src/gui/itemviews/qtableview.cpp
@@ -1197,17 +1197,16 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
visualRow = bottom;
break;
case MovePageUp: {
- int top = 0;
- while (top < bottom && d->isVisualRowHiddenOrDisabled(top, visualColumn))
- ++top;
- int newRow = qMax(rowAt(visualRect(current).top() - d->viewport->height()), top);
- return d->model->index(qBound(0, newRow, bottom), current.column(), d->root);
+ int newRow = rowAt(visualRect(current).top() - d->viewport->height());
+ if (newRow == -1)
+ newRow = d->logicalRow(0);
+ return d->model->index(newRow, current.column(), d->root);
}
case MovePageDown: {
- int newRow = qMin(rowAt(visualRect(current).bottom() + d->viewport->height()), bottom);
- if (newRow < 0)
- newRow = bottom;
- return d->model->index(qBound(0, newRow, bottom), current.column(), d->root);
+ int newRow = rowAt(visualRect(current).bottom() + d->viewport->height());
+ if (newRow == -1)
+ newRow = d->logicalRow(bottom);
+ return d->model->index(newRow, current.column(), d->root);
}}
int logicalRow = d->logicalRow(visualRow);