]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Don't trigger assert when switching to details-view
authorPeter Penz <peter.penz19@gmail.com>
Tue, 21 Feb 2012 15:46:56 +0000 (16:46 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 21 Feb 2012 15:49:38 +0000 (16:49 +0100)
If the visible roles of the details-view are equal to the visible roles
of other views, then switching to the details-view will trigger an
assert because the invisible roles don't get updated.

Thanks to Frank Reininghaus for the detailed analyses!

In the context of this fix optimizations have been done when switching
view-modes: The "don't-animate-workaround" could be removed.

BUG: 294531
FIXED-IN: 4.8.1

src/kitemviews/kfileitemlistview.cpp
src/kitemviews/kfileitemlistview.h
src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodelrolesupdater.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h
src/views/dolphinview.cpp

index 03f379837cfcba418f080584250a5a5f1f4c5987..25f7738bfd9115ff93eed0e0d861d6b0986a14c7 100644 (file)
@@ -97,8 +97,17 @@ bool KFileItemListView::previewsShown() const
 void KFileItemListView::setItemLayout(Layout layout)
 {
     if (m_itemLayout != layout) {
+        const bool updateRoles = (m_itemLayout == DetailsLayout || layout == DetailsLayout);
         m_itemLayout = layout;
+        if (updateRoles) {
+            // The details-layout requires some invisible roles that
+            // must be added to the model if the new layout is "details".
+            // If the old layout was "details" the roles will get removed.
+            applyRolesToModel();
+        }
         updateLayoutOfVisibleItems();
+
+        setSupportsItemExpanding(m_itemLayout == DetailsLayout);
     }
 }
 
@@ -234,11 +243,6 @@ QHash<QByteArray, QSizeF> KFileItemListView::visibleRolesSizes(const KItemRangeL
     return sizes;
 }
 
-bool KFileItemListView::supportsItemExpanding() const
-{
-    return m_itemLayout == DetailsLayout;
-}
-
 QPixmap KFileItemListView::createDragPixmap(const QSet<int>& indexes) const
 {
     if (!model()) {
index ea8477858e7b349ea5996843493cd45750c7ff5d..897015641e1221d4a7ef47153dd52f4e7a1f21da 100644 (file)
@@ -80,9 +80,6 @@ public:
     /** @reimp */
     virtual QHash<QByteArray, QSizeF> visibleRolesSizes(const KItemRangeList& itemRanges) const;
 
-    /** @reimp */
-    virtual bool supportsItemExpanding() const;
-
     /** @reimp */
     virtual QPixmap createDragPixmap(const QSet<int>& indexes) const;
 
index ede3c36239ab2997fd18560eac3ffa39ad048919..9078cb85a0aebd6d5558fdc2949632e097fed237 100644 (file)
@@ -372,6 +372,9 @@ void KFileItemModel::clear()
 
 void KFileItemModel::setRoles(const QSet<QByteArray>& roles)
 {
+    if (m_roles == roles) {
+        return;
+    }
     m_roles = roles;
 
     if (count() > 0) {
index 7050d21c95f012eba7f6c2349a68b6856c404799..01f07f1db7ec5ac8c3f12bbe66013fc934e00ec8 100644 (file)
@@ -216,25 +216,14 @@ void KFileItemModelRolesUpdater::setPaused(bool paused)
 
 void KFileItemModelRolesUpdater::setRoles(const QSet<QByteArray>& roles)
 {
-    if (roles.count() == m_roles.count()) {
-        bool isEqual = true;
-        foreach (const QByteArray& role, roles) {
-            if (!m_roles.contains(role)) {
-                isEqual = false;
-                break;
-            }
-        }
-        if (isEqual) {
-            return;
-        }
-    }
-
-    m_roles = roles;
+    if (m_roles != roles) {
+        m_roles = roles;
 
-    if (m_paused) {
-        m_rolesChangedDuringPausing = true;
-    } else {
-        sortAndResolveAllRoles();
+        if (m_paused) {
+            m_rolesChangedDuringPausing = true;
+        } else {
+            sortAndResolveAllRoles();
+        }
     }
 }
 
index bee2f3d6a4ba80afd3b2a652d312155828e355df..372726954ffc41fe1c86a2ce423d34b0fae7de8f 100644 (file)
@@ -54,6 +54,7 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
     QGraphicsWidget(parent),
     m_enabledSelectionToggles(false),
     m_grouped(false),
+    m_supportsItemExpanding(false),
     m_activeTransactions(0),
     m_endTransactionAnimationHint(Animation),
     m_itemSize(),
@@ -503,7 +504,7 @@ QHash<QByteArray, QSizeF> KItemListView::visibleRolesSizes(const KItemRangeList&
 
 bool KItemListView::supportsItemExpanding() const
 {
-    return false;
+    return m_supportsItemExpanding;
 }
 
 QRectF KItemListView::itemRect(int index) const
@@ -767,6 +768,14 @@ QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const
     return m_visibleItems.values();
 }
 
+void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
+{
+    if (m_supportsItemExpanding != supportsExpanding) {
+        m_supportsItemExpanding = supportsExpanding;
+        updateSiblingsInformation();
+    }
+}
+
 void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
 {
     updateVisibleRolesSizes(itemRanges);
index 293f4b1ecd2d2c8c4bbf7fb0f8f14f32a5f89b05..d524dbdf4f98f6f8dfbbf7a4d4f7fce147b882b1 100644 (file)
@@ -176,7 +176,7 @@ public:
      *         has to take care itself how to visually represent the expanded items provided
      *         by the model.
      */
-    virtual bool supportsItemExpanding() const;
+    bool supportsItemExpanding() const;
 
     /**
      * @return The rectangle of the item relative to the top/left of
@@ -298,6 +298,13 @@ protected:
 
     QList<KItemListWidget*> visibleItemListWidgets() const;
 
+    /**
+     * Must be called by the derived class if it supports the expanding
+     * of items.
+     * @see supportsItemExpanding()
+     */
+    void setSupportsItemExpanding(bool supportsExpanding);
+
 protected slots:
     virtual void slotItemsInserted(const KItemRangeList& itemRanges);
     virtual void slotItemsRemoved(const KItemRangeList& itemRanges);
@@ -547,6 +554,7 @@ private:
 private:
     bool m_enabledSelectionToggles;
     bool m_grouped;
+    bool m_supportsItemExpanding;
     int m_activeTransactions; // Counter for beginTransaction()/endTransaction()
     LayoutAnimationHint m_endTransactionAnimationHint;
 
index 80be1e592c63991c95a30d6520bc92b1f1375720..54787d28fda0808c529f2332c86b06f0536d4690 100644 (file)
@@ -1168,19 +1168,6 @@ void DolphinView::applyViewProperties()
 
     const Mode mode = props.viewMode();
     if (m_mode != mode) {
-        // Prevent an animated transition of the position and size of the items when switching
-        // the view-mode by temporary clearing the model and updating it again after the view mode
-        // has been modified.
-        const bool restoreModel = (model->count() > 0);
-        if (restoreModel) {
-            const int currentItemIndex = m_container->controller()->selectionManager()->currentItem();
-            if (currentItemIndex >= 0) {
-                m_currentItemUrl = model->fileItem(currentItemIndex).url();
-            }
-            m_selectedUrls = selectedItems().urlList();
-            model->clear();
-        }
-
         const Mode previousMode = m_mode;
         m_mode = mode;
 
@@ -1201,10 +1188,6 @@ void DolphinView::applyViewProperties()
         if (m_container->zoomLevel() != oldZoomLevel) {
             emit zoomLevelChanged(m_container->zoomLevel(), oldZoomLevel);
         }
-
-        if (restoreModel) {
-            loadDirectory(url());
-        }
     }
 
     const bool hiddenFilesShown = props.hiddenFilesShown();