Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the issue of QPixmapCache running ineffectively #314

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 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,11 @@ 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());
QString cmdlineStr = proc.cmdlineString();
if (!cmdlineStr.isEmpty())
return cmdlineStr;
else
return QString("%1").arg(proc.name());
}
return {};
}
Expand Down
Loading