Cache status icons in file model
This commit is contained in:
parent
19a621a357
commit
8caf7124fd
|
@ -357,18 +357,21 @@ QVariant SyncthingFileModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
break;
|
||||
case 4: {
|
||||
static constexpr auto size = 16;
|
||||
auto &manager = IconManager::instance();
|
||||
auto icon = QPixmap(size * 2, size);
|
||||
auto painter = QPainter(&icon);
|
||||
auto left = 0;
|
||||
icon.fill(QColor(Qt::transparent));
|
||||
if (item->existsInDb) {
|
||||
manager.renderForkAwesomeIcon(QtForkAwesome::Icon::Globe, &painter, QRect(left, 0, size, size));
|
||||
}
|
||||
left += size;
|
||||
if (item->existsLocally) {
|
||||
manager.renderForkAwesomeIcon(QtForkAwesome::Icon::Home, &painter, QRect(left, 0, size, size));
|
||||
auto &icon = m_statusIcons[(item->existsInDb ? 0x01 : 0x00) | (item->existsLocally ? 0x02 : 0x00)];
|
||||
if (icon.isNull()) {
|
||||
static constexpr auto size = 16;
|
||||
icon = QPixmap(size * 2, size);
|
||||
auto &manager = IconManager::instance();
|
||||
auto painter = QPainter(&icon);
|
||||
auto left = 0;
|
||||
icon.fill(QColor(Qt::transparent));
|
||||
if (item->existsInDb) {
|
||||
manager.renderForkAwesomeIcon(QtForkAwesome::Icon::Globe, &painter, QRect(left, 0, size, size));
|
||||
}
|
||||
left += size;
|
||||
if (item->existsLocally) {
|
||||
manager.renderForkAwesomeIcon(QtForkAwesome::Icon::Home, &painter, QRect(left, 0, size, size));
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
} break;
|
||||
|
@ -787,6 +790,9 @@ void SyncthingFileModel::handleNewConfigAvailable()
|
|||
|
||||
void SyncthingFileModel::handleForkAwesomeIconsChanged()
|
||||
{
|
||||
for (auto &icon : m_statusIcons) {
|
||||
icon = QPixmap();
|
||||
}
|
||||
invalidateAllIndicies(QVector<int>({ Qt::DecorationRole }));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QHash>
|
||||
#include <QPixmap>
|
||||
#include <QSet>
|
||||
|
||||
#include <map>
|
||||
|
@ -122,6 +123,7 @@ private:
|
|||
QString m_manuallyEditedIgnorePatterns;
|
||||
QString m_ignoreAllByDefaultPattern;
|
||||
QChar m_pathSeparator;
|
||||
mutable QPixmap m_statusIcons[4];
|
||||
int m_columns;
|
||||
bool m_selectionMode;
|
||||
bool m_hasIgnorePatterns;
|
||||
|
|
Loading…
Reference in New Issue