From: Peter Penz Date: Tue, 21 Feb 2012 15:46:56 +0000 (+0100) Subject: Don't trigger assert when switching to details-view X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/7deb601f317d7c806e69d0d82d99a03d0859ca85 Don't trigger assert when switching to details-view 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 --- diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index 03f379837..25f7738bf 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -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 KFileItemListView::visibleRolesSizes(const KItemRangeL return sizes; } -bool KFileItemListView::supportsItemExpanding() const -{ - return m_itemLayout == DetailsLayout; -} - QPixmap KFileItemListView::createDragPixmap(const QSet& indexes) const { if (!model()) { diff --git a/src/kitemviews/kfileitemlistview.h b/src/kitemviews/kfileitemlistview.h index ea8477858..897015641 100644 --- a/src/kitemviews/kfileitemlistview.h +++ b/src/kitemviews/kfileitemlistview.h @@ -80,9 +80,6 @@ public: /** @reimp */ virtual QHash visibleRolesSizes(const KItemRangeList& itemRanges) const; - /** @reimp */ - virtual bool supportsItemExpanding() const; - /** @reimp */ virtual QPixmap createDragPixmap(const QSet& indexes) const; diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index ede3c3623..9078cb85a 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -372,6 +372,9 @@ void KFileItemModel::clear() void KFileItemModel::setRoles(const QSet& roles) { + if (m_roles == roles) { + return; + } m_roles = roles; if (count() > 0) { diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 7050d21c9..01f07f1db 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -216,25 +216,14 @@ void KFileItemModelRolesUpdater::setPaused(bool paused) void KFileItemModelRolesUpdater::setRoles(const QSet& 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(); + } } } diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index bee2f3d6a..372726954 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -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 KItemListView::visibleRolesSizes(const KItemRangeList& bool KItemListView::supportsItemExpanding() const { - return false; + return m_supportsItemExpanding; } QRectF KItemListView::itemRect(int index) const @@ -767,6 +768,14 @@ QList 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); diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h index 293f4b1ec..d524dbdf4 100644 --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -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 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; diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 80be1e592..54787d28f 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -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();