summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp60
-rw-r--r--src/gui/itemviews/qitemselectionmodel_p.h2
2 files changed, 36 insertions, 26 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();