diff options
| author | Frank Reininghaus <[email protected]> | 2013-09-04 21:34:03 +0200 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2013-09-04 21:37:01 +0200 |
| commit | 8f7c3619ec734bbf31ae81315a6548db9cbd19aa (patch) | |
| tree | f7706c4e400baf6fd73834e569271307a2137338 /src/kitemviews/kstandarditemlistwidget.cpp | |
| parent | a4ef4bbfdebad708e4b3c772c1ce3e236a4da145 (diff) | |
Try to avoid calling the model's data method if only "text" is needed
Currently, KStandardItemListWidgetInformant::itemSizeHint() calls the
model's data(int) method for every single item, but the full data is
actually only needed for the size calculation in Compact View. In
Details View, no data is needed at all to determine the size required
for the item, and in Icons View, only the name is needed.
This patch makes it possible for subclasses of
KStandardItemListWidgetInformant to provide an alternative way to
obtain the "text", and implements this in the subclass
KFileItemListWidgetInformant.
The final goal is to achieve that the QHash which contains all data
for a file item is only created if it is really needed, e.g., because
the view needs access to the data for displaying the item on the
screen.
REVIEW: 112253
Diffstat (limited to 'src/kitemviews/kstandarditemlistwidget.cpp')
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index bc0503663..4b9f33b6f 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -57,13 +57,12 @@ KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant() QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemListView* view) const { - const QHash<QByteArray, QVariant> values = view->model()->data(index); const KItemListStyleOption& option = view->styleOption(); const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0); switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) { case KStandardItemListWidget::IconsLayout: { - const QString text = KStringHandler::preProcessWrap(values["text"].toString()); + const QString text = KStringHandler::preProcessWrap(itemText(index, view)); const qreal itemWidth = view->itemSize().width(); const qreal maxWidth = itemWidth - 2 * option.padding; @@ -100,6 +99,7 @@ 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); @@ -159,6 +159,11 @@ qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArra return width; } +QString KStandardItemListWidgetInformant::itemText(int index, const KItemListView* view) const +{ + return view->model()->data(index).value("text").toString(); +} + QString KStandardItemListWidgetInformant::roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values) const { |
