mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 23:14:31 +00:00
Cache icons in TorrentContentModel
This commit caches icons in TorrentContentModel in the same way they are cached in TorrentModel. This commit should improve performance when user navigating through torrent list using up/down keys. A scrolling through all the list (276 torrents) took: Total wall time: 18.813s Total CPU time: 3.210s IconProvider::generateDifferentSizes(): 0.170s IconProvider::generateDifferentSizes is 5th most hottest function on this use case.
This commit is contained in:
parent
3202ad368f
commit
9023232653
@ -37,6 +37,18 @@
|
||||
#include "torrentcontentmodelfile.h"
|
||||
#include <QDir>
|
||||
|
||||
namespace {
|
||||
QIcon get_directory_icon() {
|
||||
static QIcon cached = IconProvider::instance()->getIcon("inode-directory");
|
||||
return cached;
|
||||
}
|
||||
|
||||
QIcon get_file_icon() {
|
||||
static QIcon cached = IconProvider::instance()->getIcon("text-plain");
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
TorrentContentModel::TorrentContentModel(QObject *parent):
|
||||
QAbstractItemModel(parent),
|
||||
m_rootItem(new TorrentContentModelFolder(QList<QVariant>() << tr("Name") << tr("Size")
|
||||
@ -169,9 +181,9 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
|
||||
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
||||
if (index.column() == 0 && role == Qt::DecorationRole) {
|
||||
if (item->itemType() == TorrentContentModelItem::FolderType)
|
||||
return IconProvider::instance()->getIcon("inode-directory");
|
||||
return get_directory_icon();
|
||||
else
|
||||
return IconProvider::instance()->getIcon("text-plain");
|
||||
return get_file_icon();
|
||||
}
|
||||
if (index.column() == 0 && role == Qt::CheckStateRole) {
|
||||
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user