From f62d0dc8fb092d63ca2fbfbced36667b8766de4f Mon Sep 17 00:00:00 2001 From: qiqi49 Date: Fri, 15 Mar 2024 11:20:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(favorite):=E4=BF=AE=E5=A4=8D=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=9B=B4=E6=96=B0=E4=BF=A1=E6=81=AF=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=8C=BA=E5=9F=9F=E4=B8=8D=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension/favorite/app-favorite-model.cpp | 18 +++++++++++++++--- src/libappdata/app-database-interface.cpp | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/extension/favorite/app-favorite-model.cpp b/src/extension/favorite/app-favorite-model.cpp index 132f509..aaea837 100644 --- a/src/extension/favorite/app-favorite-model.cpp +++ b/src/extension/favorite/app-favorite-model.cpp @@ -91,9 +91,21 @@ void AppFavoritesModel::getFavoritesApps() void AppFavoritesModel::onAppUpdated(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { - for (const auto &role : roles) { - if (role == DataEntity::Favorite) { - updateFavoritesApps(m_sourceModel->appOfIndex(topLeft.row()), topLeft); + // 更新全部信息 + if (roles.isEmpty()) { + QPersistentModelIndex topLeftIndex(topLeft); + QPersistentModelIndex bottomRightIndex(bottomRight); + + int leftIndex = m_favoritesApps.indexOf(topLeftIndex); + int rightIndex = m_favoritesApps.indexOf(topLeftIndex); + + Q_EMIT dataChanged(index(leftIndex, 0, QModelIndex()), index(rightIndex, 0, QModelIndex())); + // 更新某一项信息 + } else { + for (int row = topLeft.row(); row <= bottomRight.row(); row ++) { + if (roles.contains(DataEntity::Favorite) ) { + updateFavoritesApps(m_sourceModel->appOfIndex(row), m_sourceModel->index(row, 0, QModelIndex())); + } } } } diff --git a/src/libappdata/app-database-interface.cpp b/src/libappdata/app-database-interface.cpp index c36d7e7..6526f59 100644 --- a/src/libappdata/app-database-interface.cpp +++ b/src/libappdata/app-database-interface.cpp @@ -258,7 +258,9 @@ void AppDatabaseWorkerPrivate::onAppDatabaseUpdate(const UkuiSearch::Application updates.append({app, roles}); } - Q_EMIT q->appUpdated(updates); + if (!updates.isEmpty()) { + Q_EMIT q->appUpdated(updates); + } } void AppDatabaseWorkerPrivate::onAppDatabaseDeleted(const QStringList &infos)