From 7a64a3f67d53a99e6e2200f6481c98013004b4e4 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 18 Aug 2009 11:56:46 +0200 Subject: QItemSelectionModel: hasSelection can return true when no selection we needed to finalize the selection when rows are removed Reviewed-by: ogoffart --- src/gui/itemviews/qitemselectionmodel.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp index 98810a0..8414460 100644 --- a/src/gui/itemviews/qitemselectionmodel.cpp +++ b/src/gui/itemviews/qitemselectionmodel.cpp @@ -573,6 +573,7 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare int start, int end) { Q_Q(QItemSelectionModel); + finalize(); // update current index if (currentIndex.isValid() && parent == currentIndex.parent() @@ -591,8 +592,8 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare } QItemSelection deselected; - QItemSelection::iterator it = currentSelection.begin(); - while (it != currentSelection.end()) { + QItemSelection::iterator it = ranges.begin(); + while (it != ranges.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) @@ -600,24 +601,22 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare if (parent.isValid() && start <= itParent.row() && itParent.row() <= end) { deselected.append(*it); - it = currentSelection.erase(it); + it = ranges.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); + it = ranges.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); + *it = QItemSelectionRange(model->index(end + 1, it->left(), it->parent()), it->bottomRight()); + ++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); + *it = QItemSelectionRange(it->topLeft(), model->index(start - 1, it->right(), it->parent())); + ++it; } else { if (it->top() < start && end < it->bottom()) // Middle intersection (do nothing) deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()), @@ -626,7 +625,8 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare } } - emit q->selectionChanged(QItemSelection(), deselected); + if (!deselected.isEmpty()) + emit q->selectionChanged(QItemSelection(), deselected); } /*! -- cgit v0.12