From 2f2f4b2750eeaffd56babe395a4c824921cdff9c Mon Sep 17 00:00:00 2001 From: ck Date: Fri, 14 Jun 2024 15:30:59 +0800 Subject: [PATCH] fix: little black square icon show again - reset model to fix black square icon - if icon is fullpath convert to url Issue: https://github.com/linuxdeepin/developer-center/issues/8577 --- src/models/appitem.cpp | 9 ++++++++- src/models/appsmodel.cpp | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/models/appitem.cpp b/src/models/appitem.cpp index 33d783de..cf0c4d91 100644 --- a/src/models/appitem.cpp +++ b/src/models/appitem.cpp @@ -4,6 +4,8 @@ #include "appitem.h" +#include + AppItem::AppItem(const QString &freedesktopId) : QStandardItem() { @@ -47,7 +49,12 @@ const QString AppItem::iconName() const void AppItem::setIconName(const QString &iconName) { - setData(iconName.isEmpty() ? "application-x-desktop" : iconName, AppItem::IconNameRole); + QString name = iconName; + if (QFileInfo(iconName).isAbsolute()) { + name = QUrl::fromLocalFile(iconName).toString(); // path ==> file://path + } + + setData(iconName.isEmpty() ? "application-x-desktop" : name, AppItem::IconNameRole); } const QStringList AppItem::categories() const diff --git a/src/models/appsmodel.cpp b/src/models/appsmodel.cpp index 7dcc1127..83894c89 100644 --- a/src/models/appsmodel.cpp +++ b/src/models/appsmodel.cpp @@ -197,14 +197,17 @@ QVariant AppsModel::data(const QModelIndex &index, int role) const void AppsModel::updateModelData() { - // TODO release icon's cache when gtk's icon-theme.cache is updated. - IconUtils::tryUpdateIconCache(); + beginResetModel(); + qDebug() << "reset model."; + QList items(allAppInfosShouldBeShown()); cleanUpInvalidApps(items); QList duplicatedItems = updateItems(items); for (AppItem * item : std::as_const(duplicatedItems)) { delete item; } + + endResetModel(); } // the caller manage the return values' ownership (i.e. might need to free them)