]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[KItemListView] Check if KItemListStyleOption actually changed before emitting a...
authorKai Uwe Broulik <kde@privat.broulik.de>
Thu, 29 Mar 2018 07:21:17 +0000 (09:21 +0200)
committerKai Uwe Broulik <kde@privat.broulik.de>
Thu, 29 Mar 2018 07:21:17 +0000 (09:21 +0200)
This avoids work being done when it doesn't need to be.
For instance, the preview generator waits for everything to have settled using a 200ms timer before generating a preview.
This timer fired also in response to onStyleOptionChanged and needlessly delayed preview generation when navigating between folders
despite the style option (e.g. icon size, view mode) not having changed.

Differential Revision: https://phabricator.kde.org/D11481

src/kitemviews/kitemlistgroupheader.cpp
src/kitemviews/kitemliststyleoption.cpp
src/kitemviews/kitemliststyleoption.h
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistwidget.cpp
src/kitemviews/kstandarditemlistview.cpp

index fb92989894243f1ef5c6103ee391c3831a698d7e..06a32484aabf3e1be09aeb96713cbd4d99336b63 100644 (file)
@@ -78,6 +78,10 @@ QVariant KItemListGroupHeader::data() const
 
 void KItemListGroupHeader::setStyleOption(const KItemListStyleOption& option)
 {
+    if (m_styleOption == option) {
+        return;
+    }
+
     const KItemListStyleOption previous = m_styleOption;
     m_styleOption = option;
     m_dirtyCache = true;
index 1ebcad141509fc499bc01211c7bc2f98f1b17aa3..bcfb86064b39182175d0234ed5d414efb87e4d49 100644 (file)
@@ -53,3 +53,23 @@ KItemListStyleOption::KItemListStyleOption(const KItemListStyleOption& other) :
 KItemListStyleOption::~KItemListStyleOption()
 {
 }
+
+bool KItemListStyleOption::operator==(const KItemListStyleOption& other) const
+{
+    return rect == other.rect
+            && font == other.font
+            && fontMetrics == other.fontMetrics
+            && palette == other.palette
+            && padding == other.padding
+            && horizontalMargin == other.horizontalMargin
+            && verticalMargin == other.verticalMargin
+            && iconSize == other.iconSize
+            && extendedSelectionRegion == other.extendedSelectionRegion
+            && maxTextLines == other.maxTextLines
+            && maxTextWidth == other.maxTextWidth;
+}
+
+bool KItemListStyleOption::operator!=(const KItemListStyleOption& other) const
+{
+    return !(*this == other);
+}
index 09b787c27d272d71b70f7d3b7d3b3e8c77dbdfcb..93aafac1f53a9b3c027c97f0f68c47f572ec2eb8 100644 (file)
@@ -45,6 +45,11 @@ public:
     bool extendedSelectionRegion;
     int maxTextLines;
     int maxTextWidth;
+
+    bool operator==(const KItemListStyleOption& other) const;
+    bool operator!=(const KItemListStyleOption& other) const;
+
+
 };
 #endif
 
index 489c6f9b69f44522670b946fb72c74f7d886cbe6..f0647fb3eac23fc922532e447a4f20c541cbe3c1 100644 (file)
@@ -752,6 +752,10 @@ void KItemListView::setItemSize(const QSizeF& size)
 
 void KItemListView::setStyleOption(const KItemListStyleOption& option)
 {
+    if (m_styleOption == option) {
+        return;
+    }
+
     const KItemListStyleOption previousOption = m_styleOption;
     m_styleOption = option;
 
index 61dd7256eb98b7e9ac7f61b4981ea52b8f32edf7..28b374620c38ff7fe1122164f8011756a4489faa 100644 (file)
@@ -191,10 +191,13 @@ qreal KItemListWidget::columnWidth(const QByteArray& role) const
 
 void KItemListWidget::setStyleOption(const KItemListStyleOption& option)
 {
+    if (m_styleOption == option) {
+        return;
+    }
+
     const KItemListStyleOption previous = m_styleOption;
     clearHoverCache();
     m_styleOption = option;
-
     styleOptionChanged(option, previous);
     update();
 }
index ee1c061036f7a10c6b90183923a546fc57759f4e..929ee1da80a2db5b56cb589a46b09c876a9362bf 100644 (file)
@@ -146,27 +146,20 @@ void KStandardItemListView::applyDefaultStyleOption(int iconSize,
 {
     KItemListStyleOption option = styleOption();
 
-    bool changed = false;
     if (option.iconSize < 0) {
         option.iconSize = iconSize;
-        changed = true;
     }
     if (option.padding < 0) {
         option.padding = padding;
-        changed = true;
     }
     if (option.horizontalMargin < 0) {
         option.horizontalMargin = horizontalMargin;
-        changed = true;
     }
     if (option.verticalMargin < 0) {
         option.verticalMargin = verticalMargin;
-        changed = true;
     }
 
-    if (changed) {
-        setStyleOption(option);
-    }
+    setStyleOption(option);
 }
 
 void KStandardItemListView::updateLayoutOfVisibleItems()