[Kde-bindings] KDE/kdelibs/kdeui/itemviews

Stephen Kelly steveire at gmail.com
Tue May 18 17:33:27 UTC 2010


SVN commit 1128212 by skelly:

Add new signals for more efficient reporting.

CCMAIL: kde-bindings at kde.org

 M  +22 -14    kselectionproxymodel.cpp  
 M  +14 -0     kselectionproxymodel.h  


--- trunk/KDE/kdelibs/kdeui/itemviews/kselectionproxymodel.cpp #1128211:1128212
@@ -1405,13 +1405,15 @@
     QItemSelection fullSelection = m_indexMapper->mapSelectionRightToLeft(m_selectionModel->selection());
 
     QItemSelection newRootRanges;
+    QItemSelection removedRootRanges;
     if (!m_includeAllSelected) {
         newRootRanges = getRootRanges(selected);
 
+        QItemSelection futureSelection = fullSelection;
         QItemSelection exposedSelection;
         {
-            QItemSelection removedRootRanges = getRootRanges(deselected);
-            QListIterator<QItemSelectionRange> i(removedRootRanges);
+            QItemSelection deselectedRootRanges = getRootRanges(deselected);
+            QListIterator<QItemSelectionRange> i(deselectedRootRanges);
             while (i.hasNext()) {
                 // Need to sort first.
                 const QItemSelectionRange range = i.next();
@@ -1422,18 +1424,22 @@
                       if (isDescendantOf(range, selectedRange.topLeft()) && !(newRootRanges.contains(selectedRange.topLeft())))
                           exposedSelection.append(selectedRange);
                     }
-                    removeRangeFromProxy(range);
+                    removedRootRanges << range;
                 }
             }
+            futureSelection.merge(QItemSelection(removedRootRanges), QItemSelectionModel::Deselect);
         }
         newRootRanges << getRootRanges(exposedSelection);
 
         {
             QMutableListIterator<QItemSelectionRange> i(newRootRanges);
+            // TODO: This is what m_rootIndexList should be maintained as.
+            QItemSelection existingSelection = fullSelection;
+            existingSelection.merge(selected, QItemSelectionModel::Deselect);
             while (i.hasNext()) {
                 const QItemSelectionRange range = i.next();
                 const QModelIndex topLeft = range.topLeft();
-                if (isDescendantOf(m_rootIndexList, topLeft) || isDescendantOf(fullSelection, topLeft)) {
+                if (isDescendantOf(existingSelection, topLeft) || isDescendantOf(futureSelection, topLeft)) {
                     i.remove();
                 }
             }
@@ -1441,7 +1447,7 @@
 
         QItemSelection obscuredRanges;
         {
-            QMutableListIterator<QItemSelectionRange> i(fullSelection);
+            QMutableListIterator<QItemSelectionRange> i(futureSelection);
             while (i.hasNext()) {
                 QItemSelectionRange range = i.next();
                 QItemSelection result;
@@ -1471,30 +1477,32 @@
                 }
             }
         }
-        QItemSelection obscuredRootRanges = getRootRanges(obscuredRanges);
+        removedRootRanges << getRootRanges(obscuredRanges);
+    } else {
+        removedRootRanges << deselected;
+        newRootRanges << selected;
+    }
+
+    q->rootSelectionAboutToBeRemoved(removedRootRanges);
         {
-            QListIterator<QItemSelectionRange> i(obscuredRootRanges);
+        QListIterator<QItemSelectionRange> i(removedRootRanges);
             while (i.hasNext()) {
-                removeRangeFromProxy(i.next());
-            }
-        }
-    } else {
-        QListIterator<QItemSelectionRange> i(deselected);
-        while (i.hasNext()) {
             const QItemSelectionRange range = i.next();
             removeRangeFromProxy(range);
         }
-        newRootRanges << selected;
     }
+
     if (!m_selectionModel->hasSelection())
     {
       Q_ASSERT(m_rootIndexList.isEmpty());
       Q_ASSERT(m_mappedFirstChildren.isEmpty());
       Q_ASSERT(m_mappedParents.isEmpty());
     }
+    // TODO: Make insertion range based too.
     QModelIndexList newIndexes = getNewIndexes(newRootRanges);
     if (newIndexes.size() > 0)
         insertionSort(newIndexes);
+    q->rootSelectionAdded(newRootRanges);
 }
 
 SourceProxyIndexMapping KSelectionProxyModelPrivate::regroup(const QModelIndexList &list) const
--- trunk/KDE/kdelibs/kdeui/itemviews/kselectionproxymodel.h #1128211:1128212
@@ -274,6 +274,20 @@
     */
     void rootIndexAdded(const QModelIndex &newIndex);
 
+    /**
+      @internal
+      Emitted before @p selection, a selection in the sourceModel, is removed from
+      the root selection.
+    */
+    void rootSelectionAboutToBeRemoved(const QItemSelection &selection);
+
+    /**
+      @internal
+      Emitted after @p selection, a selection in the sourceModel, is added to
+      the root selection.
+    */
+    void rootSelectionAdded(const QItemSelection &selection);
+
 protected:
     QList<QPersistentModelIndex> sourceRootIndexes() const;
 



More information about the Kde-bindings mailing list