X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/94fd0e85ff5a84c3ca3dc734f16ac31f73e12f7a..6861a876830e301878b65cb4e4574bfda4c73340:/src/iconmanager.cpp diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp index 94432102c..97dac53b7 100644 --- a/src/iconmanager.cpp +++ b/src/iconmanager.cpp @@ -32,10 +32,55 @@ #include #include #include +#include #include #include #include +/** + * If the passed item view is an instance of QListView, expensive + * layout operations are blocked in the constructor and are unblocked + * again in the destructor. + * + * This helper class is a workaround for the following huge performance + * problem when having directories with several 1000 items: + * - each change of an icon emits a dataChanged() signal from the model + * - QListView iterates through all items on each dataChanged() signal + * and invokes QItemDelegate::sizeHint() + * - the sizeHint() implementation of KFileItemDelegate is quite complex, + * invoking it 1000 times for each icon change might block the UI + * + * QListView does not invoke QItemDelegate::sizeHint() when the + * uniformItemSize property has been set to true, so this property is + * set before exchanging a block of icons. It is important to reset + * it again before the event loop is entered, otherwise QListView + * would not get the correct size hints after dispatching the layoutChanged() + * signal. + */ +class LayoutBlocker { +public: + LayoutBlocker(QAbstractItemView* view) : + m_uniformSizes(false), + m_view(qobject_cast(view)) + { + if (m_view != 0) { + m_uniformSizes = m_view->uniformItemSizes(); + m_view->setUniformItemSizes(true); + } + } + + ~LayoutBlocker() + { + if (m_view != 0) { + m_view->setUniformItemSizes(m_uniformSizes); + } + } + +private: + bool m_uniformSizes; + QListView* m_view; +}; + IconManager::IconManager(QAbstractItemView* parent, DolphinSortFilterProxyModel* model) : QObject(parent), m_showPreview(false), @@ -215,6 +260,7 @@ void IconManager::dispatchPreviewQueue() dispatchCount = previewsCount; } + LayoutBlocker blocker(m_view); for (int i = 0; i < dispatchCount; ++i) { const ItemInfo& preview = m_previews.first(); replaceIcon(preview.url, preview.pixmap);