Skip to content

Commit

Permalink
fix: Fix the issue of QPixmapCache running ineffectively
Browse files Browse the repository at this point in the history
   Fix the issue of QPixmapCache running ineffectively

Log: Fix the issue of QPixmapCache running ineffectively
Bug: https://pms.uniontech.com/bug-view-239575.html
  • Loading branch information
starhcq committed Jan 31, 2024
1 parent 63f2687 commit 8349b75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions deepin-system-monitor-main/gui/base/base_item_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,18 @@ void BaseItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
auto diff = (iconRect.height() - iconSize) / 2;
iconRect.adjust(0, diff, 0, -diff);

const QString &procPid = index.data(Qt::UserRole + 4).toString();

QPixmap *iconPixmap = nullptr;
core::process::ProcessIconCache::instance()->iconPixmapCache.find(procPid, iconPixmap);
if (iconPixmap) {
painter->drawPixmap(iconRect, *iconPixmap);
// Qt的QIcon::pixmap()接口返回QPixmap对象的内存不会回收,此处使用QPixmapCache类来管理进程图标内存资源
// 原有QPixmapCache::find接口返回的pixmap指针为空,改为返回pixmap引用对象,保证能根据进程名从缓存中获取到图标资源
// https://pms.uniontech.com/bug-view-239575.html
const QString &procName = index.data(Qt::UserRole + 4).toString();

QPixmap iconPixmap;
core::process::ProcessIconCache::instance()->iconPixmapCache.find(procName, iconPixmap);
if (!iconPixmap.isNull()) {
painter->drawPixmap(iconRect, iconPixmap);
} else {
const QPixmap &iconPix = icon.pixmap(iconRect.size());
core::process::ProcessIconCache::instance()->iconPixmapCache.insert(procPid, iconPix);
core::process::ProcessIconCache::instance()->iconPixmapCache.insert(procName, iconPix);
painter->drawPixmap(iconRect, iconPix);
}
}
Expand Down
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/model/process_table_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ QVariant ProcessTableModel::data(const QModelIndex &index, int role) const
} else if (role == Qt::UserRole + 3) {
return proc.appType();
} else if (role == Qt::UserRole + 4) {
return QString("%1").arg(proc.pid());
return QString("%1").arg(proc.name());
}
return {};
}
Expand Down

0 comments on commit 8349b75

Please sign in to comment.