Lazy-load the item data also in Compact View

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
This commit is contained in:
Frank Reininghaus 2013-12-02 23:14:20 +01:00
parent 0c76683c36
commit 3dc7c849c0

View 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;