summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews/qitemselectionmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemviews/qitemselectionmodel.cpp')
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 9dad95f..98810a0 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -34,7 +34,7 @@
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://www.qtsoftware.com/contact.
+** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -590,11 +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);
- q->select(QItemSelection(tl, br), QItemSelectionModel::Deselect);
- finalize();
+ 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);
}
/*!