summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-18 09:56:46 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-18 09:59:24 (GMT)
commit7a64a3f67d53a99e6e2200f6481c98013004b4e4 (patch)
treee9e48a7d27a8700526713b4840c37870d1738e36 /src/gui/itemviews
parent610af2bf4d6d57f86ca71c9764b5b03b01aafad8 (diff)
downloadQt-7a64a3f67d53a99e6e2200f6481c98013004b4e4.zip
Qt-7a64a3f67d53a99e6e2200f6481c98013004b4e4.tar.gz
Qt-7a64a3f67d53a99e6e2200f6481c98013004b4e4.tar.bz2
QItemSelectionModel: hasSelection can return true when no selection
we needed to finalize the selection when rows are removed Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp22
1 files 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);
}
/*!