]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Lazy-load the item data also in Compact View
authorFrank Reininghaus <frank78ac@googlemail.com>
Mon, 2 Dec 2013 22:14:20 +0000 (23:14 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Mon, 2 Dec 2013 22:14:39 +0000 (23:14 +0100)
The recent changes which prevent that all data for each item are saved
in a QHash already when loading the folder (see
https://git.reviewboard.kde.org/r/112725/), which save both memory and
time, do not work yet in Compact View, because
KItemListWidgetInformant::itemSizeHint() calls the model's data(int)
method for every item, which then initializes the hash.

This patch prevents that by accessing the file name directly if only
the "Name" is shown in the view, just like it's done in Icons View.

REVIEW: 113849

src/kitemviews/kstandarditemlistwidget.cpp

index 302150fec1267d93a094a3c5d2b0e3400acc41ca..acdf839aca58923f1c0bcac8dddf86f9ef0ae045 100644 (file)
@@ -99,11 +99,18 @@ QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemList
         // to show all roles without horizontal clipping.
         qreal maximumRequiredWidth = 0.0;
 
-        const QHash<QByteArray, QVariant> values = view->model()->data(index);
-        foreach (const QByteArray& role, view->visibleRoles()) {
-            const QString text = roleText(role, values);
-            const qreal requiredWidth = option.fontMetrics.width(text);
-            maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth);
+        const QList<QByteArray>& visibleRoles = view->visibleRoles();
+        const bool showOnlyTextRole = (visibleRoles.count() == 1) && (visibleRoles.first() == "text");
+
+        if (showOnlyTextRole) {
+            maximumRequiredWidth = option.fontMetrics.width(itemText(index, view));
+        } else {
+            const QHash<QByteArray, QVariant> values = view->model()->data(index);
+            foreach (const QByteArray& role, view->visibleRoles()) {
+                const QString text = roleText(role, values);
+                const qreal requiredWidth = option.fontMetrics.width(text);
+                maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth);
+            }
         }
 
         qreal width = option.padding * 4 + option.iconSize + maximumRequiredWidth;