]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Improve the performance of the code part which checks which items are visible. Althou...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 11 Jun 2008 17:50:59 +0000 (17:50 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 11 Jun 2008 17:50:59 +0000 (17:50 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=819663

src/iconmanager.cpp
src/iconmanager.h

index 8bcc8e58b97facc9e0a96922bd7e480e7c6162d4..002f4e86d5fba26cb333ff2d957173b5be683865 100644 (file)
@@ -138,6 +138,14 @@ void IconManager::updatePreviews()
     updateCutItems();
 }
 
     updateCutItems();
 }
 
+void IconManager::cancelPreviews()
+{
+    killPreviewJobs();
+    m_cutItemsCache.clear();
+    m_pendingItems.clear();
+    m_dispatchedItems.clear();
+}
+
 void IconManager::generatePreviews(const KFileItemList& items)
 {
     applyCutItemEffect();
 void IconManager::generatePreviews(const KFileItemList& items)
 {
     applyCutItemEffect();
@@ -148,18 +156,25 @@ void IconManager::generatePreviews(const KFileItemList& items)
 
     // Order the items in a way that the preview for the visible items
     // is generated first, as this improves the feeled performance a lot.
 
     // Order the items in a way that the preview for the visible items
     // is generated first, as this improves the feeled performance a lot.
+    // Implementation note: using KDirModel::itemForUrl() would lead to a more
+    // readable code, but it is a lot slower in comparison to itemListContains().
     const QRect visibleArea = m_view->viewport()->rect();
     KFileItemList orderedItems;
     const QRect visibleArea = m_view->viewport()->rect();
     KFileItemList orderedItems;
-    foreach (const KFileItem& item, items) {
-        const QModelIndex dirIndex = m_dolphinModel->indexForItem(item);
-        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+    const int rowCount = m_proxyModel->rowCount();
+    for (int row = 0; row < rowCount; ++row) {
+        const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
         const QRect itemRect = m_view->visualRect(proxyIndex);
         const QRect itemRect = m_view->visualRect(proxyIndex);
-        if (itemRect.intersects(visibleArea)) {
-            orderedItems.insert(0, item);
-            m_pendingItems.insert(0, item.url());
-        } else {
-            orderedItems.append(item);
-            m_pendingItems.append(item.url());
+        const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
+        KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
+        const KUrl url = item.url();
+        if (itemListContains(items, url)) {
+            if (itemRect.intersects(visibleArea)) {
+                orderedItems.insert(0, item);
+                m_pendingItems.insert(0, url);
+            } else {
+                orderedItems.append(item);
+                m_pendingItems.append(url);
+            }
         }
     }
 
         }
     }
 
@@ -269,17 +284,25 @@ void IconManager::resumePreviews()
     // Create a new preview job for the remaining items.
     // Order the items in a way that the preview for the visible items
     // is generated first, as this improves the feeled performance a lot.
     // Create a new preview job for the remaining items.
     // Order the items in a way that the preview for the visible items
     // is generated first, as this improves the feeled performance a lot.
+    // Implementation note: using KDirModel::itemForUrl() would lead to a more
+    // readable code, but it is a lot slower in comparison
+    // to m_pendingItems.contains().
     const QRect visibleArea = m_view->viewport()->rect();
     KFileItemList orderedItems;
     const QRect visibleArea = m_view->viewport()->rect();
     KFileItemList orderedItems;
-    foreach (const KUrl& url, m_pendingItems) {
-        const QModelIndex dirIndex = m_dolphinModel->indexForUrl(url);
-        const KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
-        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+
+    const int rowCount = m_proxyModel->rowCount();
+    for (int row = 0; row < rowCount; ++row) {
+        const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
         const QRect itemRect = m_view->visualRect(proxyIndex);
         const QRect itemRect = m_view->visualRect(proxyIndex);
-        if (itemRect.intersects(visibleArea)) {
-            orderedItems.insert(0, item);
-        } else {
-            orderedItems.append(item);
+        const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
+        KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
+        const KUrl url = item.url();
+        if (m_pendingItems.contains(url)) {
+            if (itemRect.intersects(visibleArea)) {
+                orderedItems.insert(0, item);
+            } else {
+                orderedItems.append(item);
+            }
         }
     }
 
         }
     }
 
@@ -497,4 +520,14 @@ void IconManager::killPreviewJobs()
     m_previewJobs.clear();
 }
 
     m_previewJobs.clear();
 }
 
+bool IconManager::itemListContains(const KFileItemList& items, const KUrl& url) const
+{
+    foreach (const KFileItem& item, items) {
+        if (url == item.url()) {
+            return true;
+        }
+    }
+    return false;
+}
+
 #include "iconmanager.moc"
 #include "iconmanager.moc"
index 85538f87d80b785dcf8493c2d59326384bbf1654..b5a8221750b05368c723859dba2430b81fa3556a 100644 (file)
@@ -60,10 +60,18 @@ public:
     bool showPreview() const;
 
     /**
     bool showPreview() const;
 
     /**
-     * Updates the previews for all already available items.
+     * Updates the previews for all already available items. It is only necessary
+     * to invoke this method when the icon size of the abstract item view has
+     * been changed.
      */
     void updatePreviews();
 
      */
     void updatePreviews();
 
+    /**
+     * Cancels all pending previews. Should be invoked when the URL of the item
+     * view has been changed.
+     */
+    void cancelPreviews();
+
 private slots:
     /**
      * Generates previews for the items \a items asynchronously.
 private slots:
     /**
      * Generates previews for the items \a items asynchronously.
@@ -144,6 +152,12 @@ private:
     /** Kills all ongoing preview jobs. */
     void killPreviewJobs();
 
     /** Kills all ongoing preview jobs. */
     void killPreviewJobs();
 
+    /**
+     * Returns true, if the item list \a items contains an item with the
+     * URL \a url. This is a helper method for IconManager::generatePreviews().
+     */
+    bool itemListContains(const KFileItemList& items, const KUrl& url) const;
+
 private:
     /** Remembers the pixmap for an item specified by an URL. */
     struct ItemInfo
 private:
     /** Remembers the pixmap for an item specified by an URL. */
     struct ItemInfo