From 04610551e30678fb78e081bf9af6c408f3c875c3 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Wed, 18 Oct 2023 20:47:36 +0800 Subject: [PATCH] fix: [extension] ext emblem icon cannot changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge old and new,new overwrites old if same location exists Log: fix extension bug --- .../emblemimpl/extensionemblemmanager.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/plugins/common/dfmplugin-utils/extensionimpl/emblemimpl/extensionemblemmanager.cpp b/src/plugins/common/dfmplugin-utils/extensionimpl/emblemimpl/extensionemblemmanager.cpp index 3875e20e2c..abbeffc4d6 100644 --- a/src/plugins/common/dfmplugin-utils/extensionimpl/emblemimpl/extensionemblemmanager.cpp +++ b/src/plugins/common/dfmplugin-utils/extensionimpl/emblemimpl/extensionemblemmanager.cpp @@ -161,20 +161,24 @@ void EmblemIconWorker::mergeGroup(const QList> &oldGroup, { Q_ASSERT(group); - *group = oldGroup; - if (oldGroup.size() >= kMaxEmblemCount) - return; + // Merge old and new, + // New overwrites old if same location exists - // other plugins canot override first plugin's emblem icon - QList posSpace { 0, 1, 2, 3 }; - std::for_each(oldGroup.begin(), oldGroup.end(), [&posSpace](const QPair &pair) { - posSpace.removeOne(pair.second); + QMap tmpMap; + std::for_each(oldGroup.begin(), oldGroup.end(), [&tmpMap](const QPair &pair) { + tmpMap.insert(pair.second, pair.first); }); - std::for_each(newGroup.begin(), newGroup.end(), [posSpace, group](const QPair &pair) { - if (posSpace.contains(pair.second)) - group->push_back(pair); + std::for_each(newGroup.begin(), newGroup.end(), [&tmpMap](const QPair &pair) { + tmpMap.insert(pair.second, pair.first); }); + + for (auto iter = tmpMap.begin(); iter != tmpMap.end(); ++iter) { + if (group->size() >= kMaxEmblemCount) + return; + + group->push_back(qMakePair(iter.value(), iter.key())); + } } ExtensionEmblemManager &ExtensionEmblemManager::instance()