Locator: Reuse TaskTreeRunner for filters refreshing

Change-Id: I9db6c24491ce5f972707160bf84da01fce67657b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-13 16:23:19 +01:00
parent 61a8128512
commit 0ac4e7f55f
2 changed files with 16 additions and 16 deletions

View File

@@ -35,6 +35,7 @@
#include <QMainWindow> #include <QMainWindow>
using namespace Tasking;
using namespace Utils; using namespace Utils;
namespace Core { namespace Core {
@@ -150,7 +151,7 @@ bool Locator::delayedInitialize()
void Locator::aboutToShutdown() void Locator::aboutToShutdown()
{ {
m_refreshTimer.stop(); m_refreshTimer.stop();
m_taskTree.reset(); m_taskTreeRunner.reset();
} }
void Locator::loadSettings() void Locator::loadSettings()
@@ -377,10 +378,18 @@ void Locator::refresh(const QList<ILocatorFilter *> &filters)
if (ExtensionSystem::PluginManager::isShuttingDown()) if (ExtensionSystem::PluginManager::isShuttingDown())
return; return;
m_taskTree.reset(); // Superfluous, just for clarity. The next reset() below is enough. m_taskTreeRunner.reset(); // Superfluous, just for clarity. The start() below is enough.
m_refreshingFilters = Utils::filteredUnique(m_refreshingFilters + filters); m_refreshingFilters = Utils::filteredUnique(m_refreshingFilters + filters);
using namespace Tasking; const auto onTreeSetup = [](TaskTree *taskTree) {
auto progress = new TaskProgress(taskTree);
progress->setDisplayName(Tr::tr("Updating Locator Caches"));
};
const auto onTreeDone = [this](DoneWith result) {
if (result == DoneWith::Success)
saveSettings();
};
QList<GroupItem> tasks{parallel}; QList<GroupItem> tasks{parallel};
for (ILocatorFilter *filter : std::as_const(m_refreshingFilters)) { for (ILocatorFilter *filter : std::as_const(m_refreshingFilters)) {
const auto task = filter->refreshRecipe(); const auto task = filter->refreshRecipe();
@@ -394,16 +403,7 @@ void Locator::refresh(const QList<ILocatorFilter *> &filters)
}; };
tasks.append(group); tasks.append(group);
} }
m_taskTreeRunner.start(tasks, onTreeSetup, onTreeDone);
m_taskTree.reset(new TaskTree{tasks});
connect(m_taskTree.get(), &TaskTree::done, this, [this](DoneWith result) {
if (result == DoneWith::Success)
saveSettings();
m_taskTree.release()->deleteLater();
});
auto progress = new TaskProgress(m_taskTree.get());
progress->setDisplayName(Tr::tr("Updating Locator Caches"));
m_taskTree->start();
} }
void Locator::showFilter(ILocatorFilter *filter, LocatorWidget *widget) void Locator::showFilter(ILocatorFilter *filter, LocatorWidget *widget)

View File

@@ -8,11 +8,11 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <solutions/tasking/tasktreerunner.h>
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
namespace Tasking { class TaskTree; }
namespace Core { namespace Core {
namespace Internal { namespace Internal {
@@ -71,7 +71,7 @@ private:
QList<ILocatorFilter *> m_customFilters; QList<ILocatorFilter *> m_customFilters;
QMap<Utils::Id, QAction *> m_filterActionMap; QMap<Utils::Id, QAction *> m_filterActionMap;
QTimer m_refreshTimer; QTimer m_refreshTimer;
std::unique_ptr<Tasking::TaskTree> m_taskTree; Tasking::TaskTreeRunner m_taskTreeRunner;
QList<ILocatorFilter *> m_refreshingFilters; QList<ILocatorFilter *> m_refreshingFilters;
}; };