diff options
| author | Peter Penz <[email protected]> | 2012-03-25 23:57:51 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-03-26 00:00:12 +0200 |
| commit | b7f0091733ec558ced0eacf0708c0146e3961bb3 (patch) | |
| tree | 47cff440872d820d77003d2099f889b470451c1b /src/kitemviews/kfileitemlistview.cpp | |
| parent | e70c2f8aa472c01433f9416c363c698677c5b45f (diff) | |
Internal interface cleanup
Let derived classes from KItemListView just implement
preferredColumnWidth() for one role of an item instead of returning
a hashtable for a given item-range.
Diffstat (limited to 'src/kitemviews/kfileitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemlistview.cpp | 81 |
1 files changed, 16 insertions, 65 deletions
diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index a0650b665..aa368bfef 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -193,52 +193,29 @@ QSizeF KFileItemListView::itemSizeHint(int index) const return QSize(); } -QHash<QByteArray, qreal> KFileItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const +qreal KFileItemListView::preferredColumnWidth(int index, const QByteArray& role) const { - QElapsedTimer timer; - timer.start(); + const KItemListStyleOption& option = styleOption(); - QHash<QByteArray, qreal> widths; + qreal width = m_minimumRolesWidths.value(role, 0); - int calculatedItemCount = 0; - bool maxTimeExceeded = false; - foreach (const KItemRange& itemRange, itemRanges) { - const int startIndex = itemRange.index; - const int endIndex = startIndex + itemRange.count - 1; + const QHash<QByteArray, QVariant> values = model()->data(index); + const QString text = KFileItemListWidget::roleText(role, values); + if (!text.isEmpty()) { + const qreal columnPadding = option.padding * 3; + width = qMax(width, qreal(2 * columnPadding + option.fontMetrics.width(text))); + } - for (int i = startIndex; i <= endIndex; ++i) { - foreach (const QByteArray& visibleRole, visibleRoles()) { - qreal maxWidth = widths.value(visibleRole, 0); - const QSizeF itemSize = visibleRoleSizeHint(i, visibleRole); - maxWidth = qMax(itemSize.width(), maxWidth); - widths.insert(visibleRole, maxWidth); - } + if (role == "name") { + // Increase the width by the expansion-toggle and the current expansion level + const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); + width += option.padding + (expandedParentsCount + 1) * itemSize().height() + KIconLoader::SizeSmall; - if (calculatedItemCount > 100 && timer.elapsed() > 200) { - // When having several thousands of items calculating the sizes can get - // very expensive. We accept a possibly too small role-size in favour - // of having no blocking user interface. - #ifdef KFILEITEMLISTVIEW_DEBUG - kDebug() << "Timer exceeded, stopped after" << calculatedItemCount << "items"; - #endif - maxTimeExceeded = true; - break; - } - ++calculatedItemCount; - } - if (maxTimeExceeded) { - break; - } + // Increase the width by the required space for the icon + width += option.padding * 2 + option.iconSize; } -#ifdef KFILEITEMLISTVIEW_DEBUG - int rangesItemCount = 0; - foreach (const KItemRange& itemRange, itemRanges) { - rangesItemCount += itemRange.count; - } - kDebug() << "[TIME] Calculated dynamic item size for " << rangesItemCount << "items:" << timer.elapsed(); -#endif - return widths; + return width; } QPixmap KFileItemListView::createDragPixmap(const QSet<int>& indexes) const @@ -496,32 +473,6 @@ void KFileItemListView::updateIconSize() updateTimersInterval(); } -QSizeF KFileItemListView::visibleRoleSizeHint(int index, const QByteArray& role) const -{ - const KItemListStyleOption& option = styleOption(); - - qreal width = m_minimumRolesWidths.value(role, 0); - const qreal height = option.padding * 2 + option.fontMetrics.height(); - - const QHash<QByteArray, QVariant> values = model()->data(index); - const QString text = KFileItemListWidget::roleText(role, values); - if (!text.isEmpty()) { - const qreal columnPadding = option.padding * 3; - width = qMax(width, qreal(2 * columnPadding + option.fontMetrics.width(text))); - } - - if (role == "name") { - // Increase the width by the expansion-toggle and the current expansion level - const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); - width += option.padding + (expandedParentsCount + 1) * itemSize().height() + KIconLoader::SizeSmall; - - // Increase the width by the required space for the icon - width += option.padding * 2 + option.iconSize; - } - - return QSizeF(width, height); -} - void KFileItemListView::updateLayoutOfVisibleItems() { if (!model()) { |
