]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix layout-issues when sorting by roles that are changed
authorPeter Penz <peter.penz19@gmail.com>
Fri, 4 Nov 2011 22:31:11 +0000 (23:31 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 4 Nov 2011 22:34:39 +0000 (23:34 +0100)
When sorting is enabled for a role that gets changed e.g. because
a value like the MIME-type is determined asynchronously, then the
layout might get messed up.

slotItemsMoved() has been adjusted to invalidate the sizehint-cache
and to update the group-headers.

BUG: 285542
FIXED-IN: 4.8.0

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kitemlistsizehintresolver.cpp
src/kitemviews/kitemlistsizehintresolver_p.h
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemmodelbase.h

index afc6decee81309d32d0fec60ef8fb21cd094a067..c0c442e2380f122954a0b69c99be7364bdef7638 100644 (file)
@@ -88,7 +88,7 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) :
     // for a lot of items within a quite small timeslot. To prevent expensive resortings the
     // resorting is postponed until the timer has been exceeded.
     m_resortAllItemsTimer = new QTimer(this);
-    m_resortAllItemsTimer->setInterval(1000);
+    m_resortAllItemsTimer->setInterval(500);
     m_resortAllItemsTimer->setSingleShot(true);
     connect(m_resortAllItemsTimer, SIGNAL(timeout()), this, SLOT(resortAllItems()));
 
index 00eb79bddbcac3b284fa837427b087093a30e9a1..0520fac0408257067ba9bd35cca283a34120f04a 100644 (file)
@@ -60,11 +60,13 @@ void KItemListSizeHintResolver::itemsRemoved(int index, int count)
     m_sizeHintCache.erase(begin, end);
 }
 
-void KItemListSizeHintResolver::itemsMoved(int from, int to, int count)
+void KItemListSizeHintResolver::itemsMoved(int index, int count)
 {
-    Q_UNUSED(from);
-    Q_UNUSED(to);
-    Q_UNUSED(count);
+    while (count) {
+        m_sizeHintCache[index] = QSizeF();
+        ++index;
+        --count;
+    }
 }
 
 void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QByteArray>& roles)
index f4f65eccb9b833684088289a4b7be2c245d827b1..1345e0321f4f49dd7a5387d383dc28467df9c42c 100644 (file)
@@ -28,6 +28,9 @@
 
 class KItemListView;
 
+/**
+ * @brief Calculates and caches the sizehints of items in KItemListView.
+ */
 class LIBDOLPHINPRIVATE_EXPORT KItemListSizeHintResolver
 {
 public:
@@ -37,7 +40,7 @@ public:
 
     void itemsInserted(int index, int count);
     void itemsRemoved(int index, int count);
-    void itemsMoved(int from, int to, int count);
+    void itemsMoved(int index, int count);
     void itemsChanged(int index, int count, const QSet<QByteArray>& roles);
 
     void clearCache();
index b11fe905dbb8ae77af0ec36947741a044c1b8606..7976f397b49484bbebf6213e5d4cbca5f11a5f0d 100644 (file)
@@ -708,7 +708,6 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
 
         if (!hasMultipleRanges) {
             doLayout(Animation, index, count);
-            update();
         }
     }
 
@@ -789,7 +788,6 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
         m_layouter->markAsDirty();
         if (!hasMultipleRanges) {
             doLayout(Animation, index, -count);
-            update();
         }
     }
 
@@ -804,6 +802,13 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
 
 void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes)
 {
+    m_sizeHintResolver->itemsMoved(itemRange.index, itemRange.count);
+    m_layouter->markAsDirty();
+
+    if (m_controller) {
+        m_controller->selectionManager()->itemsMoved(itemRange, movedToIndexes);
+    }
+
     const int firstVisibleMovedIndex = qMax(firstVisibleIndex(), itemRange.index);
     const int lastVisibleMovedIndex = qMin(lastVisibleIndex(), itemRange.index + itemRange.count - 1);
 
@@ -811,12 +816,14 @@ void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>
         KItemListWidget* widget = m_visibleItems.value(index);
         if (widget) {
             updateWidgetProperties(widget, index);
+            if (m_grouped) {
+                updateGroupHeaderForWidget(widget);
+            }
+            initializeItemListWidget(widget);
         }
     }
 
-    if (m_controller) {
-        m_controller->selectionManager()->itemsMoved(itemRange, movedToIndexes);
-    }
+    doLayout(NoAnimation, 0, 0);
 }
 
 void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
@@ -854,9 +861,6 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
             // in modified group headers
             updateVisibleGroupHeaders();
             doLayout(NoAnimation, 0, 0);
-            if (!m_layoutTimer->isActive()) {
-                m_layoutTimer->start();
-            }
         }
     }
 }
@@ -1328,7 +1332,11 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
         widget->setVisible(true);
 
         if (widget->size() != itemBounds.size()) {
-            m_animation->start(widget, KItemListViewAnimation::ResizeAnimation, itemBounds.size());
+            if (animate) {
+                m_animation->start(widget, KItemListViewAnimation::ResizeAnimation, itemBounds.size());
+            } else {
+                widget->resize(itemBounds.size());
+            }
         }
     }
 
@@ -1484,6 +1492,8 @@ void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index)
 
 void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget)
 {
+    Q_ASSERT(m_grouped);
+
     const int index = widget->index();
     if (!m_layouter->isFirstGroupItem(index)) {
         // The widget does not represent the first item of a group
index 693ffb763ab403b2f84d874a3fdc9804aa2b4685..edca15bd1c68331b4255ce7bedc1a2fdc0703cb4 100644 (file)
@@ -108,6 +108,12 @@ public:
      */
     virtual QString roleDescription(const QByteArray& role) const;
 
+    /**
+     * @return List of group headers. Each list-item consists of the index of the item
+     *         that represents the first item of a group and a value represented
+     *         as QVariant. The value is shown by an instance of KItemListGroupHeader.
+     *         Per default an empty list is returned.
+     */
     virtual QList<QPair<int, QVariant> > groups() const;
 
     /**