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

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);
}
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)
{
if ((a.top() != 0) && (b.top() != 0)) {
@ -221,8 +236,7 @@ void AllAppDataProvider::removeApps(QStringList &idList)
void AllAppDataProvider::onAppUpdated(const QList<DataEntity>& apps)
{
Q_UNUSED(apps);
reloadAppData();
updateData(apps);
sendData();
}

View File

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