]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Internal interface cleanup
authorPeter Penz <peter.penz19@gmail.com>
Sun, 25 Mar 2012 21:57:51 +0000 (23:57 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 25 Mar 2012 22:00:12 +0000 (00:00 +0200)
Let derived classes from KItemListView just implement
preferredColumnWidth() for one role of an item instead of returning
a hashtable for a given item-range.

src/kitemviews/kfileitemlistview.cpp
src/kitemviews/kfileitemlistview.h
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h

index a0650b665660a6ccd3a37a67ef45dd2c5ade086b..aa368bfef033be53d111745a8c672007e83c2b47 100644 (file)
@@ -193,52 +193,29 @@ QSizeF KFileItemListView::itemSizeHint(int index) const
     return QSize();
 }
 
-QHash<QByteArray, qreal> KFileItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const
-{
-    QElapsedTimer timer;
-    timer.start();
-
-    QHash<QByteArray, qreal> widths;
-
-    int calculatedItemCount = 0;
-    bool maxTimeExceeded = false;
-    foreach (const KItemRange& itemRange, itemRanges) {
-        const int startIndex = itemRange.index;
-        const int endIndex = startIndex + itemRange.count - 1;
-
-        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 (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;
-        }
+qreal KFileItemListView::preferredColumnWidth(int index, const QByteArray& role) const
+{
+    const KItemListStyleOption& option = styleOption();
+
+    qreal width = m_minimumRolesWidths.value(role, 0);
+
+    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)));
     }
 
-#ifdef KFILEITEMLISTVIEW_DEBUG
-    int rangesItemCount = 0;
-    foreach (const KItemRange& itemRange, itemRanges) {
-        rangesItemCount += itemRange.count;
+    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;
     }
-    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()) {
index db8566934af41bf77020ec327aab38a4d4aa999c..1e372881a364af2f9714547d990ab885971405b3 100644 (file)
@@ -78,7 +78,7 @@ public:
     virtual QSizeF itemSizeHint(int index) const;
 
     /** @reimp */
-    virtual QHash<QByteArray, qreal> preferredColumnWidths(const KItemRangeList& itemRanges) const;
+    qreal preferredColumnWidth(int index, const QByteArray& role) const;
 
     /** @reimp */
     virtual QPixmap createDragPixmap(const QSet<int>& indexes) const;
@@ -109,7 +109,6 @@ private slots:
     void updateIconSize();
 
 private:
-    QSizeF visibleRoleSizeHint(int index, const QByteArray& role) const;
     void updateLayoutOfVisibleItems();
     void updateTimersInterval();
     void updateMinimumRolesWidths();
index e68c1143e7c61eec1b25c17f44365155e9d0151c..fdb68a1a4019df46b95bedf8c69d06292fc06613 100644 (file)
@@ -514,10 +514,11 @@ QSizeF KItemListView::itemSizeHint(int index) const
     return itemSize();
 }
 
-QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const
+qreal KItemListView::preferredColumnWidth(int index, const QByteArray& role) const
 {
-    Q_UNUSED(itemRanges);
-    return QHash<QByteArray, qreal>();
+    Q_UNUSED(index);
+    Q_UNUSED(role);
+    return 100;
 }
 
 void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
@@ -1898,6 +1899,44 @@ bool KItemListView::useAlternateBackgrounds() const
     return m_itemSize.isEmpty() && m_visibleRoles.count() > 1;
 }
 
+QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const
+{
+    QElapsedTimer timer;
+    timer.start();
+
+    QHash<QByteArray, qreal> widths;
+
+    int calculatedItemCount = 0;
+    bool maxTimeExceeded = false;
+    foreach (const KItemRange& itemRange, itemRanges) {
+        const int startIndex = itemRange.index;
+        const int endIndex = startIndex + itemRange.count - 1;
+
+        for (int i = startIndex; i <= endIndex; ++i) {
+            foreach (const QByteArray& visibleRole, visibleRoles()) {
+                qreal maxWidth = widths.value(visibleRole, 0);
+                const qreal width = preferredColumnWidth(i, visibleRole);
+                maxWidth = qMax(width, maxWidth);
+                widths.insert(visibleRole, maxWidth);
+            }
+
+            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.
+                maxTimeExceeded = true;
+                break;
+            }
+            ++calculatedItemCount;
+        }
+        if (maxTimeExceeded) {
+            break;
+        }
+    }
+
+    return widths;
+}
+
 void KItemListView::applyColumnWidthsFromHeader()
 {
     // Apply the new size to the layouter
index a3c2059d141e7eac596aed50e2a91ccb63ec6ee3..4026925856fcf3cbf5da64f69f3a30780a3dc4b0 100644 (file)
@@ -193,13 +193,10 @@ public:
     virtual QSizeF itemSizeHint(int index) const;
 
     /**
-     * @param itemRanges Items that must be checked for getting the widths of columns.
-     * @return           The preferred width of the column of each visible role. The width will
-     *                   be respected if the width of the item size is <= 0 (see
-     *                   KItemListView::setItemSize()). Per default an empty hash
-     *                   is returned.
+     * @return The preferred column-width of the item with the index \a index
+     *         for the given \a role that is shown in the column.
      */
-    virtual QHash<QByteArray, qreal> preferredColumnWidths(const KItemRangeList& itemRanges) const;
+    virtual qreal preferredColumnWidth(int index, const QByteArray& role) const;
 
     /**
      * If set to true, items having child-items can be expanded to show the child-items as
@@ -524,6 +521,15 @@ private:
      */
     bool useAlternateBackgrounds() const;
 
+    /**
+     * @param itemRanges Items that must be checked for getting the widths of columns.
+     * @return           The preferred width of the column of each visible role. The width will
+     *                   be respected if the width of the item size is <= 0 (see
+     *                   KItemListView::setItemSize()). Per default an empty hash
+     *                   is returned.
+     */
+    QHash<QByteArray, qreal> preferredColumnWidths(const KItemRangeList& itemRanges) const;
+
     /**
      * Applies the column-widths from m_headerWidget to the layout
      * of the view.