]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Details view: Fix filter issue with sibblings
authorPeter Penz <peter.penz19@gmail.com>
Tue, 14 Feb 2012 21:58:24 +0000 (22:58 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 14 Feb 2012 22:00:48 +0000 (23:00 +0100)
When the filter has been enabled, the sibblings got not updated. Explicitely
update the sibblings when inserting, removing or moving items. For layouting
implicitely update the sibblings only for recycled widgets.

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h

index f9ba397fab630a69cdd3295c62317b2cd8b8afee..ede3c36239ab2997fd18560eac3ffa39ad048919 100644 (file)
@@ -471,7 +471,10 @@ bool KFileItemModel::isExpandable(int index) const
 int KFileItemModel::expandedParentsCount(int index) const
 {
     if (index >= 0 && index < count()) {
-        return m_itemData.at(index)->values.value("expandedParentsCount").toInt();
+        const int parentsCount = m_itemData.at(index)->values.value("expandedParentsCount").toInt();
+        if (parentsCount > 0) {
+            return parentsCount;
+        }
     }
     return 0;
 }
index 247354419e50c6ec1c6c3265933b419d5356e5c1..4f0d68d2e69643d8cca4d5d406b556b18c8b43c2 100644 (file)
@@ -833,6 +833,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
 
         if (!hasMultipleRanges) {
             doLayout(animateChangedItemCount(count) ? Animation : NoAnimation, index, count);
+            updateSiblingsInformation();
         }
     }
 
@@ -841,7 +842,9 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
     }
 
     if (hasMultipleRanges) {
+        m_endTransactionAnimationHint = NoAnimation;
         endTransaction();
+        updateSiblingsInformation();
     }
 }
 
@@ -919,6 +922,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
             m_activeTransactions = 0;
             doLayout(animateChangedItemCount(count) ? Animation : NoAnimation, index, -count);
             m_activeTransactions = activeTransactions;
+            updateSiblingsInformation();
         }
     }
 
@@ -927,7 +931,9 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
     }
 
     if (hasMultipleRanges) {
+        m_endTransactionAnimationHint = NoAnimation;
         endTransaction();
+        updateSiblingsInformation();
     }
 }
 
@@ -954,14 +960,8 @@ void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>
         }
     }
 
-    if (supportsItemExpanding()) {
-        // The siblings information only gets updated in KItemListView::doLayout() if
-        // items have been inserted or removed. In the case of just moving the items
-        // the siblings must be updated manually:
-        updateSiblingsInformation(firstVisibleMovedIndex, lastVisibleMovedIndex);
-    }
-
     doLayout(NoAnimation);
+    updateSiblingsInformation();
 }
 
 void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
@@ -1353,15 +1353,9 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
 
     const int lastVisibleIndex = m_layouter->lastVisibleIndex();
 
-    int firstExpansionIndex = -1;
-    int lastExpansionIndex = -1;
+    int firstSibblingIndex = -1;
+    int lastSibblingIndex = -1;
     const bool supportsExpanding = supportsItemExpanding();
-    if (supportsExpanding && changedCount != 0) {
-        // Any inserting or removing of items might result in changing the siblings-information
-        // of other visible items.
-        firstExpansionIndex = firstVisibleIndex;
-        lastExpansionIndex = lastVisibleIndex;
-    }
 
     QList<int> reusableItems = recycleInvisibleItems(firstVisibleIndex, lastVisibleIndex, hint);
 
@@ -1409,10 +1403,10 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
             }
 
             if (supportsExpanding && changedCount == 0) {
-                if (firstExpansionIndex < 0) {
-                    firstExpansionIndex = i;
+                if (firstSibblingIndex < 0) {
+                    firstSibblingIndex = i;
                 }
-                lastExpansionIndex = i;
+                lastSibblingIndex = i;
             }
         }
 
@@ -1476,8 +1470,9 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
         recycleWidget(m_visibleItems.value(index));
     }
 
-    if (supportsExpanding) {
-        updateSiblingsInformation(firstExpansionIndex, lastExpansionIndex);
+    if (supportsExpanding && firstSibblingIndex >= 0) {
+        Q_ASSERT(lastSibblingIndex >= 0);
+        updateSiblingsInformation(firstSibblingIndex, lastSibblingIndex);
     }
 
     if (m_grouped) {
@@ -1999,16 +1994,21 @@ void KItemListView::updateGroupHeaderHeight()
 
 void KItemListView::updateSiblingsInformation(int firstIndex, int lastIndex)
 {
-    const int firstVisibleIndex = m_layouter->firstVisibleIndex();
-    const int lastVisibleIndex  = m_layouter->lastVisibleIndex();
-    const bool isRangeVisible = firstIndex >= 0 &&
-                                lastIndex  >= firstIndex &&
-                                lastIndex  >= firstVisibleIndex &&
-                                firstIndex <= lastVisibleIndex;
-    if (!isRangeVisible) {
+    if (!supportsItemExpanding()) {
         return;
     }
 
+    if (firstIndex < 0 || lastIndex < 0) {
+        firstIndex = m_layouter->firstVisibleIndex();
+        lastIndex  = m_layouter->lastVisibleIndex();
+    } else {
+        const bool isRangeVisible = (firstIndex <= m_layouter->lastVisibleIndex() &&
+                                     lastIndex  >= m_layouter->firstVisibleIndex());
+        if (!isRangeVisible) {
+            return;
+        }
+    }
+
     int previousParents = 0;
     QBitArray previousSiblings;
 
@@ -2054,10 +2054,12 @@ void KItemListView::updateSiblingsInformation(int firstIndex, int lastIndex)
         }
     }
 
+    Q_ASSERT(previousParents >= 0);
     for (int i = rootIndex; i <= lastIndex; ++i) {
         // Update the parent-siblings in case if the current item represents
         // a child or an upper parent.
         const int currentParents = m_model->expandedParentsCount(i);
+        Q_ASSERT(currentParents >= 0);
         if (previousParents < currentParents) {
             previousParents = currentParents;
             previousSiblings.resize(currentParents);
index dbb746d92c3c53fcc31e6886f1d4239a817f5b73..118ed2f0316bd0980d373d7d022af4e597b70b17 100644 (file)
@@ -498,10 +498,12 @@ private:
 
     /**
      * Updates the siblings-information for all visible items that are inside
-     * the range of \p firstIndex and \p lastIndex.
+     * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
+     * is smaller than 0, the siblings-information for all visible items gets
+     * updated.
      * @see KItemListWidget::setSiblingsInformation()
      */
-    void updateSiblingsInformation(int firstIndex, int lastIndex);
+    void updateSiblingsInformation(int firstIndex = -1, int lastIndex = -1);
 
     /**
      * Helper method for updateExpansionIndicators().