From: Robert Knight Date: Mon, 23 Jul 2007 23:08:47 +0000 (+0000) Subject: Fix a couple of crashes. First was to avoid problem caused by KIconLoader::global... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/e6785665752a8a3e6f9d9a73d40fdb22a2af7d04 Fix a couple of crashes. First was to avoid problem caused by KIconLoader::global()->theme() returning 0 (which according to the API, it can do). Second was to fix the 'lastIndex' member of KCategorizedView::Private being out of date when used. According to the comments this member existed as an optimization. However in the only function where it is used, scrollbar updates are also performed. This will be several orders of magnitude more expensive than the 3 constant-time operations on Qt containers (QHash,QList) which the optimization avoided. So I removed the 'lastIndex' member and moved the calculation to where the data is needed. svn path=/trunk/KDE/kdebase/apps/; revision=691574 --- diff --git a/src/dolphinitemcategorizer.cpp b/src/dolphinitemcategorizer.cpp index e51f5f52f..d5c6d4e28 100644 --- a/src/dolphinitemcategorizer.cpp +++ b/src/dolphinitemcategorizer.cpp @@ -199,8 +199,8 @@ void DolphinItemCategorizer::drawCategory(const QModelIndex &index, QPainter *painter) const { QRect starRect = option.rect; - int iconSize = KIconLoader::global()->theme()->defaultSize(K3Icon::Small); + int iconSize = KIconLoader::global()->currentSize(K3Icon::Small); const QString category = categoryForItem(index, sortRole); QColor color = option.palette.color(QPalette::Text); @@ -366,7 +366,7 @@ void DolphinItemCategorizer::drawCategory(const QModelIndex &index, int DolphinItemCategorizer::categoryHeight(const QStyleOption &option) const { - int iconSize = KIconLoader::global()->theme()->defaultSize(K3Icon::Small); + int iconSize = KIconLoader::global()->currentSize(K3Icon::Small); return qMax(option.fontMetrics.height() + (iconSize / 4) * 2 + 2, iconSize + (iconSize / 4) * 2 + 2) /* 2 gradient */; } diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index d250c42c9..b07774157 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -83,7 +83,6 @@ KCategorizedView::Private::Private(KCategorizedView *listView) , isDragging(false) , dragLeftViewport(false) , proxyModel(0) - , lastIndex(QModelIndex()) { } @@ -388,6 +387,9 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index, void KCategorizedView::Private::updateScrollbars() { + // find the last index in the last category + QModelIndex lastIndex = categoriesIndexes.isEmpty() ? QModelIndex() : categoriesIndexes[categories.last()].last(); + int lastItemBottom = cachedRectIndex(lastIndex).top() + listView->spacing() + (listView->gridSize().isEmpty() ? 0 : listView->gridSize().height()) - listView->viewport()->height(); @@ -1243,8 +1245,6 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, qStableSort(indexList.begin(), indexList.end(), categoryLessThan); } - d->lastIndex = d->categoriesIndexes[d->categories[d->categories.count() - 1]][d->categoriesIndexes[d->categories[d->categories.count() - 1]].count() - 1]; - // Finally, fill data information of items situation. This will help when // trying to compute an item place in the viewport int i = 0; // position relative to the category beginning diff --git a/src/kcategorizedview_p.h b/src/kcategorizedview_p.h index 45d89aa21..1a8a7f376 100644 --- a/src/kcategorizedview_p.h +++ b/src/kcategorizedview_p.h @@ -154,7 +154,6 @@ public: // Attributes for speed reasons KSortFilterProxyModel *proxyModel; QModelIndexList sourceModelIndexList; // in source model - QModelIndex lastIndex; }; #endif // KCATEGORIZEDVIEW_P_H