修改数据更新时冗余的问题

This commit is contained in:
youdiansaodongxi 2023-04-21 13:41:19 +08:00
parent 50e26f8676
commit 71a42aaa82
2 changed files with 17 additions and 2 deletions

View File

@ -136,6 +136,21 @@ void AllAppDataProvider::mergeData(QVector<DataEntity> &data)
data.append(m_appData); data.append(m_appData);
} }
void AllAppDataProvider::updateData(const QList<DataEntity> &apps)
{
QMutexLocker locker(&m_mutex);
for (const DataEntity & app : apps) {
for (DataEntity & appdata : m_appData) {
if (appdata.id() == app.id()) {
appdata = app;
setRecentState(appdata);
break;
}
}
}
std::sort(m_appData.begin(), m_appData.end(), appDataSort);
}
bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b) bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
{ {
if ((a.top() != 0) && (b.top() != 0)) { if ((a.top() != 0) && (b.top() != 0)) {
@ -221,8 +236,7 @@ void AllAppDataProvider::removeApps(QStringList &idList)
void AllAppDataProvider::onAppUpdated(const QList<DataEntity>& apps) void AllAppDataProvider::onAppUpdated(const QList<DataEntity>& apps)
{ {
Q_UNUSED(apps); updateData(apps);
reloadAppData();
sendData(); sendData();
} }

View File

@ -52,6 +52,7 @@ private:
void reloadAppData(); void reloadAppData();
void reloadFolderData(); void reloadFolderData();
void mergeData(QVector<DataEntity> &data); void mergeData(QVector<DataEntity> &data);
void updateData(const QList<DataEntity>& apps);
static bool appDataSort(const DataEntity &a, const DataEntity &b); static bool appDataSort(const DataEntity &a, const DataEntity &b);
static void setRecentState(DataEntity &app); static void setRecentState(DataEntity &app);