From ce457a9cdc85e80349a4a9f6209c60d4b1150ab7 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 6 Feb 2023 22:59:30 +0100 Subject: [PATCH] ILocatorFilter: Replace refresh() with refreshRecipe() Most of refresh overrides were running synchronous method in main thread, however, it was really convoluted: we were starting asynchronous call and from inside the method running in separate thread we were scheduling the call back to main thread. Use Tasking::Sync for these cases instead. The only subclass that is doing the real asynchronous refresh is DirectoryFilter. Simplify the async call internals and pass data to the async call explicitly. Move the refresh method outside of DirectoryFilter class (to make it clear we shouldn't touch private members). Change-Id: I6af788611bdc49db1ff812f91202ac40a280fbc8 Reviewed-by: Eike Ziller --- .../coreplugin/locator/directoryfilter.cpp | 109 +++++++----------- .../coreplugin/locator/directoryfilter.h | 6 +- .../coreplugin/locator/ilocatorfilter.cpp | 22 ++-- .../coreplugin/locator/ilocatorfilter.h | 9 +- src/plugins/coreplugin/locator/locator.cpp | 16 +-- .../coreplugin/locator/locator_test.cpp | 2 - .../locator/opendocumentsfilter.cpp | 19 +++ .../coreplugin/locator/opendocumentsfilter.h | 5 +- src/plugins/cppeditor/cppincludesfilter.cpp | 31 ++--- src/plugins/cppeditor/cppincludesfilter.h | 4 +- src/plugins/help/helpindexfilter.cpp | 14 ++- src/plugins/help/helpindexfilter.h | 6 +- .../projectexplorer/allprojectsfilter.cpp | 20 ++-- .../projectexplorer/allprojectsfilter.h | 6 +- .../projectexplorer/currentprojectfilter.cpp | 25 ++-- .../projectexplorer/currentprojectfilter.h | 6 +- 16 files changed, 151 insertions(+), 149 deletions(-) diff --git a/src/plugins/coreplugin/locator/directoryfilter.cpp b/src/plugins/coreplugin/locator/directoryfilter.cpp index 19a9f098e62..9d07e530cd2 100644 --- a/src/plugins/coreplugin/locator/directoryfilter.cpp +++ b/src/plugins/coreplugin/locator/directoryfilter.cpp @@ -7,12 +7,12 @@ #include "../coreplugintr.h" #include +#include #include #include #include #include -#include #include #include #include @@ -60,8 +60,6 @@ DirectoryFilter::DirectoryFilter(Id id) void DirectoryFilter::saveState(QJsonObject &object) const { - QMutexLocker locker(&m_lock); // m_files is modified in other thread - if (displayName() != defaultDisplayName()) object.insert(kDisplayNameKey, displayName()); if (!m_directories.isEmpty()) { @@ -92,7 +90,6 @@ static FilePaths toFilePaths(const QJsonArray &array) void DirectoryFilter::restoreState(const QJsonObject &object) { - QMutexLocker locker(&m_lock); setDisplayName(object.value(kDisplayNameKey).toString(defaultDisplayName())); m_directories = toFilePaths(object.value(kDirectoriesKey).toArray()); m_filters = toStringList( @@ -107,8 +104,6 @@ void DirectoryFilter::restoreState(const QByteArray &state) { if (isOldSetting(state)) { // TODO read old settings, remove some time after Qt Creator 4.15 - QMutexLocker locker(&m_lock); - QString name; QStringList directories; QString shortcut; @@ -136,8 +131,6 @@ void DirectoryFilter::restoreState(const QByteArray &state) setDisplayName(name); setShortcutString(shortcut); setIncludedByDefault(defaultFilter); - - locker.unlock(); } else { ILocatorFilter::restoreState(state); } @@ -263,8 +256,6 @@ bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) &DirectoryFilter::updateOptionButtons, Qt::DirectConnection); m_dialog->directoryList->clear(); - // Note: assuming we only change m_directories in the Gui thread, - // we don't need to protect it here with mutex m_dialog->directoryList->addItems(Utils::transform(m_directories, &FilePath::toString)); m_dialog->nameLabel->setVisible(m_isCustomFilter); m_dialog->nameEdit->setVisible(m_isCustomFilter); @@ -276,14 +267,10 @@ bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) m_dialog->filePatternLabel->setText(Utils::msgFilePatternLabel()); m_dialog->filePatternLabel->setBuddy(m_dialog->filePattern); m_dialog->filePattern->setToolTip(Utils::msgFilePatternToolTip()); - // Note: assuming we only change m_filters in the Gui thread, - // we don't need to protect it here with mutex m_dialog->filePattern->setText(Utils::transform(m_filters, &QDir::toNativeSeparators).join(',')); m_dialog->exclusionPatternLabel->setText(Utils::msgExclusionPatternLabel()); m_dialog->exclusionPatternLabel->setBuddy(m_dialog->exclusionPattern); m_dialog->exclusionPattern->setToolTip(Utils::msgFilePatternToolTip()); - // Note: assuming we only change m_exclusionFilters in the Gui thread, - // we don't need to protect it here with mutex m_dialog->exclusionPattern->setText( Utils::transform(m_exclusionFilters, &QDir::toNativeSeparators).join(',')); m_dialog->shortcutEdit->setText(shortcutString()); @@ -291,7 +278,6 @@ bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) updateOptionButtons(); dialog.adjustSize(); if (dialog.exec() == QDialog::Accepted) { - QMutexLocker locker(&m_lock); bool directoriesChanged = false; const FilePaths oldDirectories = m_directories; const QStringList oldFilters = m_filters; @@ -353,53 +339,9 @@ void DirectoryFilter::updateOptionButtons() void DirectoryFilter::updateFileIterator() { - QMutexLocker locker(&m_lock); setFileIterator(new BaseFileFilter::ListIterator(m_files)); } -void DirectoryFilter::refresh(QFutureInterface &future) -{ - FilePaths directories; - QStringList filters, exclusionFilters; - { - QMutexLocker locker(&m_lock); - if (m_directories.isEmpty()) { - m_files.clear(); - QMetaObject::invokeMethod(this, &DirectoryFilter::updateFileIterator, - Qt::QueuedConnection); - future.setProgressRange(0, 1); - future.setProgressValueAndText(1, Tr::tr("%1 filter update: 0 files").arg(displayName())); - return; - } - directories = m_directories; - filters = m_filters; - exclusionFilters = m_exclusionFilters; - } - Utils::SubDirFileIterator subDirIterator(directories, filters, exclusionFilters); - future.setProgressRange(0, subDirIterator.maxProgress()); - Utils::FilePaths filesFound; - auto end = subDirIterator.end(); - for (auto it = subDirIterator.begin(); it != end; ++it) { - if (future.isCanceled()) - break; - filesFound << (*it).filePath; - if (future.isProgressUpdateNeeded() - || future.progressValue() == 0 /*workaround for regression in Qt*/) { - future.setProgressValueAndText(subDirIterator.currentProgress(), - Tr::tr("%1 filter update: %n files", nullptr, filesFound.size()).arg(displayName())); - } - } - - if (!future.isCanceled()) { - QMutexLocker locker(&m_lock); - m_files = filesFound; - QMetaObject::invokeMethod(this, &DirectoryFilter::updateFileIterator, Qt::QueuedConnection); - future.setProgressValue(subDirIterator.maxProgress()); - } else { - future.setProgressValueAndText(subDirIterator.currentProgress(), Tr::tr("%1 filter update: canceled").arg(displayName())); - } -} - void DirectoryFilter::setIsCustomFilter(bool value) { m_isCustomFilter = value; @@ -409,10 +351,7 @@ void DirectoryFilter::setDirectories(const FilePaths &directories) { if (directories == m_directories) return; - { - QMutexLocker locker(&m_lock); - m_directories = directories; - } + m_directories = directories; Internal::Locator::instance()->refresh({this}); } @@ -435,14 +374,54 @@ FilePaths DirectoryFilter::directories() const void DirectoryFilter::setFilters(const QStringList &filters) { - QMutexLocker locker(&m_lock); m_filters = filters; } void DirectoryFilter::setExclusionFilters(const QStringList &exclusionFilters) { - QMutexLocker locker(&m_lock); m_exclusionFilters = exclusionFilters; } +static void refresh(QFutureInterface &future, const FilePaths &directories, + const QStringList &filters, const QStringList &exclusionFilters, + const QString &displayName) +{ + if (directories.isEmpty()) + return; + + SubDirFileIterator subDirIterator(directories, filters, exclusionFilters); + future.setProgressRange(0, subDirIterator.maxProgress()); + FilePaths files; + const auto end = subDirIterator.end(); + for (auto it = subDirIterator.begin(); it != end; ++it) { + if (future.isCanceled()) { + future.setProgressValueAndText(subDirIterator.currentProgress(), + Tr::tr("%1 filter update: canceled").arg(displayName)); + return; + } + files << (*it).filePath; + if (future.isProgressUpdateNeeded() || future.progressValue() == 0) { + future.setProgressValueAndText(subDirIterator.currentProgress(), + Tr::tr("%1 filter update: %n files", nullptr, files.size()).arg(displayName)); + } + } + future.setProgressValue(subDirIterator.maxProgress()); + future.reportResult(files); +} + +using namespace Utils::Tasking; + +std::optional DirectoryFilter::refreshRecipe() +{ + const auto setup = [this](AsyncTask &async) { + async.setAsyncCallData(&refresh, m_directories, m_filters, m_exclusionFilters, + displayName()); + }; + const auto done = [this](const AsyncTask &async) { + m_files = async.isResultAvailable() ? async.result() : FilePaths(); + updateFileIterator(); + }; + return Async(setup, done); +} + } // namespace Core diff --git a/src/plugins/coreplugin/locator/directoryfilter.h b/src/plugins/coreplugin/locator/directoryfilter.h index 7fb88ce112d..04067988c32 100644 --- a/src/plugins/coreplugin/locator/directoryfilter.h +++ b/src/plugins/coreplugin/locator/directoryfilter.h @@ -7,10 +7,7 @@ #include -#include #include -#include -#include namespace Core { @@ -22,7 +19,6 @@ public: DirectoryFilter(Utils::Id id); void restoreState(const QByteArray &state) override; bool openConfigDialog(QWidget *parent, bool &needsRefresh) override; - void refresh(QFutureInterface &future) override; void setIsCustomFilter(bool value); void setDirectories(const Utils::FilePaths &directories); @@ -42,6 +38,7 @@ private: void handleRemoveDirectory(); void updateOptionButtons(); void updateFileIterator(); + std::optional refreshRecipe() override; Utils::FilePaths m_directories; QStringList m_filters; @@ -49,7 +46,6 @@ private: // Our config dialog, uses in addDirectory and editDirectory // to give their dialogs the right parent class DirectoryFilterOptions *m_dialog = nullptr; - mutable QMutex m_lock; Utils::FilePaths m_files; bool m_isCustomFilter = true; }; diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.cpp b/src/plugins/coreplugin/locator/ilocatorfilter.cpp index 61a433ffed7..4705ee32caa 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.cpp +++ b/src/plugins/coreplugin/locator/ilocatorfilter.cpp @@ -7,6 +7,7 @@ #include "../editormanager/editormanager.h" #include +#include #include #include @@ -99,6 +100,15 @@ void ILocatorFilter::prepareSearch(const QString &entry) Q_UNUSED(entry) } +/*! + Returns refresh recipe for refreshing cached data. By default, no recipe is returned, so + that the filter won't be refreshed. +*/ +std::optional ILocatorFilter::refreshRecipe() +{ + return {}; +} + /*! Called with the entry specified by \a selection when the user activates it in the result list. @@ -220,13 +230,13 @@ void ILocatorFilter::restoreState(const QByteArray &state) various aspects of the filter. Called when the user requests to configure the filter. - Set \a needsRefresh to \c true, if a refresh() should be done after + Set \a needsRefresh to \c true, if a refresh should be done after closing the dialog. Return \c false if the user canceled the dialog. The default implementation allows changing the shortcut and whether the filter is included by default. - \sa refresh() + \sa refreshRecipe() */ bool ILocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) { @@ -616,14 +626,6 @@ bool ILocatorFilter::isOldSetting(const QByteArray &state) \sa caseSensitivity() */ -/*! - \fn void Core::ILocatorFilter::refresh(QFutureInterface &future) - - Refreshes cached data asynchronously. - - If \a future is \c canceled, the refresh should be aborted. -*/ - /*! \enum Core::ILocatorFilter::Priority diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.h b/src/plugins/coreplugin/locator/ilocatorfilter.h index 5adb2ebef71..b032ab5f94d 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.h +++ b/src/plugins/coreplugin/locator/ilocatorfilter.h @@ -17,8 +17,12 @@ #include +namespace Utils::Tasking { class TaskItem; } + namespace Core { +namespace Internal { class Locator; } + class ILocatorFilter; class LocatorFilterEntry @@ -157,8 +161,6 @@ public: virtual void accept(const LocatorFilterEntry &selection, QString *newText, int *selectionStart, int *selectionLength) const; - virtual void refresh(QFutureInterface &future) { Q_UNUSED(future) }; - virtual QByteArray saveState() const; virtual void restoreState(const QByteArray &state); @@ -202,6 +204,9 @@ protected: static bool isOldSetting(const QByteArray &state); private: + friend class Internal::Locator; + virtual std::optional refreshRecipe(); + Utils::Id m_id; QString m_shortcut; Priority m_priority = Medium; diff --git a/src/plugins/coreplugin/locator/locator.cpp b/src/plugins/coreplugin/locator/locator.cpp index afc060385bc..d43b77e7508 100644 --- a/src/plugins/coreplugin/locator/locator.cpp +++ b/src/plugins/coreplugin/locator/locator.cpp @@ -382,14 +382,16 @@ void Locator::refresh(const QList &filters) using namespace Tasking; QList tasks{parallel}; for (ILocatorFilter *filter : std::as_const(m_refreshingFilters)) { - const auto setupRefresh = [filter](AsyncTask &async) { - async.setAsyncCallData(&ILocatorFilter::refresh, filter); + const auto task = filter->refreshRecipe(); + if (!task.has_value()) + continue; + + const Group group { + optional, + *task, + OnGroupDone([this, filter] { m_refreshingFilters.removeOne(filter); }) }; - const auto onRefreshDone = [this, filter](const AsyncTask &async) { - Q_UNUSED(async) - m_refreshingFilters.removeOne(filter); - }; - tasks.append(Async(setupRefresh, onRefreshDone)); + tasks.append(group); } m_taskTree.reset(new TaskTree{tasks}); diff --git a/src/plugins/coreplugin/locator/locator_test.cpp b/src/plugins/coreplugin/locator/locator_test.cpp index eca70f2eaab..a261d15586b 100644 --- a/src/plugins/coreplugin/locator/locator_test.cpp +++ b/src/plugins/coreplugin/locator/locator_test.cpp @@ -28,8 +28,6 @@ public: { setFileIterator(new BaseFileFilter::ListIterator(theFiles)); } - - void refresh(QFutureInterface &) override {} }; class ReferenceData diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp index dc2a25b3736..cc24d086065 100644 --- a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -115,4 +116,22 @@ QList OpenDocumentsFilter::editors() const return m_editors; } +void OpenDocumentsFilter::refreshInternally() +{ + QMutexLocker lock(&m_mutex); + m_editors.clear(); + const QList documentEntries = DocumentModel::entries(); + // create copy with only the information relevant to use + // to avoid model deleting entries behind our back + for (DocumentModel::Entry *e : documentEntries) + m_editors.append({e->filePath(), e->displayName()}); +} + +using namespace Utils::Tasking; + +std::optional OpenDocumentsFilter::refreshRecipe() +{ + return Sync([this] { refreshInternally(); return true; }); +} + } // Core::Internal diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.h b/src/plugins/coreplugin/locator/opendocumentsfilter.h index 4924b04a1fb..aa8792730f0 100644 --- a/src/plugins/coreplugin/locator/opendocumentsfilter.h +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.h @@ -7,10 +7,7 @@ #include -#include -#include #include -#include namespace Core { namespace Internal { @@ -38,6 +35,8 @@ private: }; QList editors() const; + void refreshInternally(); + std::optional refreshRecipe() override; mutable QMutex m_mutex; QList m_editors; diff --git a/src/plugins/cppeditor/cppincludesfilter.cpp b/src/plugins/cppeditor/cppincludesfilter.cpp index 970e179fc00..e96b3ee0d20 100644 --- a/src/plugins/cppeditor/cppincludesfilter.cpp +++ b/src/plugins/cppeditor/cppincludesfilter.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include using namespace Core; using namespace ProjectExplorer; @@ -109,19 +111,19 @@ CppIncludesFilter::CppIncludesFilter() setPriority(ILocatorFilter::Low); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); connect(CppModelManager::instance(), &CppModelManager::documentUpdated, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); connect(CppModelManager::instance(), &CppModelManager::aboutToRemoveFiles, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); connect(DocumentModel::model(), &QAbstractItemModel::rowsInserted, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); connect(DocumentModel::model(), &QAbstractItemModel::rowsRemoved, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); connect(DocumentModel::model(), &QAbstractItemModel::dataChanged, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); connect(DocumentModel::model(), &QAbstractItemModel::modelReset, - this, &CppIncludesFilter::markOutdated); + this, &CppIncludesFilter::invalidateCache); } void CppIncludesFilter::prepareSearch(const QString &entry) @@ -146,16 +148,17 @@ void CppIncludesFilter::prepareSearch(const QString &entry) BaseFileFilter::prepareSearch(entry); } -void CppIncludesFilter::refresh(QFutureInterface &future) -{ - Q_UNUSED(future) - QMetaObject::invokeMethod(this, &CppIncludesFilter::markOutdated, Qt::QueuedConnection); -} - -void CppIncludesFilter::markOutdated() +void CppIncludesFilter::invalidateCache() { m_needsUpdate = true; setFileIterator(nullptr); // clean up } +using namespace Utils::Tasking; + +std::optional CppIncludesFilter::refreshRecipe() +{ + return Sync([this] { invalidateCache(); return true; }); +} + } // namespace CppEditor::Internal diff --git a/src/plugins/cppeditor/cppincludesfilter.h b/src/plugins/cppeditor/cppincludesfilter.h index 6ae5dbb91c4..720b6cbb9b9 100644 --- a/src/plugins/cppeditor/cppincludesfilter.h +++ b/src/plugins/cppeditor/cppincludesfilter.h @@ -15,10 +15,10 @@ public: // ILocatorFilter interface public: void prepareSearch(const QString &entry) override; - void refresh(QFutureInterface &future) override; private: - void markOutdated(); + void invalidateCache(); + std::optional refreshRecipe() override; bool m_needsUpdate = true; }; diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp index fe1c34a48e0..ef77f343468 100644 --- a/src/plugins/help/helpindexfilter.cpp +++ b/src/plugins/help/helpindexfilter.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -105,12 +106,6 @@ void HelpIndexFilter::accept(const LocatorFilterEntry &selection, emit linksActivated(links, key); } -void HelpIndexFilter::refresh(QFutureInterface &future) -{ - Q_UNUSED(future) - invalidateCache(); -} - QStringList HelpIndexFilter::allIndices() const { LocalHelpManager::setupGuiHelpEngine(); @@ -121,3 +116,10 @@ void HelpIndexFilter::invalidateCache() { m_needsUpdate = true; } + +using namespace Utils::Tasking; + +std::optional HelpIndexFilter::refreshRecipe() +{ + return Sync([this] { invalidateCache(); return true; }); +} diff --git a/src/plugins/help/helpindexfilter.h b/src/plugins/help/helpindexfilter.h index 1dfc6f59952..56ffa226bb4 100644 --- a/src/plugins/help/helpindexfilter.h +++ b/src/plugins/help/helpindexfilter.h @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -28,7 +27,6 @@ public: const QString &entry) override; void accept(const Core::LocatorFilterEntry &selection, QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface &future) override; QStringList allIndices() const; @@ -36,10 +34,10 @@ signals: void linksActivated(const QMultiMap &links, const QString &key) const; private: - void invalidateCache(); - bool updateCache(QFutureInterface &future, const QStringList &cache, const QString &entry); + void invalidateCache(); + std::optional refreshRecipe() override; QStringList m_allIndicesCache; QStringList m_lastIndicesCache; diff --git a/src/plugins/projectexplorer/allprojectsfilter.cpp b/src/plugins/projectexplorer/allprojectsfilter.cpp index fddbceccb1c..19c2d499255 100644 --- a/src/plugins/projectexplorer/allprojectsfilter.cpp +++ b/src/plugins/projectexplorer/allprojectsfilter.cpp @@ -9,6 +9,7 @@ #include "projectmanager.h" #include +#include using namespace Core; @@ -25,12 +26,7 @@ AllProjectsFilter::AllProjectsFilter() setDefaultIncludedByDefault(true); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged, - this, &AllProjectsFilter::markFilesAsOutOfDate); -} - -void AllProjectsFilter::markFilesAsOutOfDate() -{ - setFileIterator(nullptr); + this, &AllProjectsFilter::invalidateCache); } void AllProjectsFilter::prepareSearch(const QString &entry) @@ -46,10 +42,16 @@ void AllProjectsFilter::prepareSearch(const QString &entry) BaseFileFilter::prepareSearch(entry); } -void AllProjectsFilter::refresh(QFutureInterface &future) +void AllProjectsFilter::invalidateCache() { - Q_UNUSED(future) - QMetaObject::invokeMethod(this, &AllProjectsFilter::markFilesAsOutOfDate, Qt::QueuedConnection); + setFileIterator(nullptr); +} + +using namespace Utils::Tasking; + +std::optional AllProjectsFilter::refreshRecipe() +{ + return Sync([this] { invalidateCache(); return true; }); } } // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/allprojectsfilter.h b/src/plugins/projectexplorer/allprojectsfilter.h index ae9fdffe92b..c85cc3fe28f 100644 --- a/src/plugins/projectexplorer/allprojectsfilter.h +++ b/src/plugins/projectexplorer/allprojectsfilter.h @@ -5,8 +5,6 @@ #include -#include - namespace ProjectExplorer { namespace Internal { @@ -16,11 +14,11 @@ class AllProjectsFilter : public Core::BaseFileFilter public: AllProjectsFilter(); - void refresh(QFutureInterface &future) override; void prepareSearch(const QString &entry) override; private: - void markFilesAsOutOfDate(); + void invalidateCache(); + std::optional refreshRecipe() override; }; } // namespace Internal diff --git a/src/plugins/projectexplorer/currentprojectfilter.cpp b/src/plugins/projectexplorer/currentprojectfilter.cpp index 69b88ddf46c..ec5a1e7ffdd 100644 --- a/src/plugins/projectexplorer/currentprojectfilter.cpp +++ b/src/plugins/projectexplorer/currentprojectfilter.cpp @@ -8,6 +8,7 @@ #include "projecttree.h" #include +#include using namespace Core; using namespace ProjectExplorer; @@ -28,11 +29,6 @@ CurrentProjectFilter::CurrentProjectFilter() this, &CurrentProjectFilter::currentProjectChanged); } -void CurrentProjectFilter::markFilesAsOutOfDate() -{ - setFileIterator(nullptr); -} - void CurrentProjectFilter::prepareSearch(const QString &entry) { Q_UNUSED(entry) @@ -52,19 +48,24 @@ void CurrentProjectFilter::currentProjectChanged() return; if (m_project) disconnect(m_project, &Project::fileListChanged, - this, &CurrentProjectFilter::markFilesAsOutOfDate); + this, &CurrentProjectFilter::invalidateCache); if (project) connect(project, &Project::fileListChanged, - this, &CurrentProjectFilter::markFilesAsOutOfDate); + this, &CurrentProjectFilter::invalidateCache); m_project = project; - markFilesAsOutOfDate(); + invalidateCache(); } -void CurrentProjectFilter::refresh(QFutureInterface &future) +void CurrentProjectFilter::invalidateCache() { - Q_UNUSED(future) - QMetaObject::invokeMethod(this, &CurrentProjectFilter::markFilesAsOutOfDate, - Qt::QueuedConnection); + setFileIterator(nullptr); +} + +using namespace Utils::Tasking; + +std::optional CurrentProjectFilter::refreshRecipe() +{ + return Sync([this] { invalidateCache(); return true; }); } diff --git a/src/plugins/projectexplorer/currentprojectfilter.h b/src/plugins/projectexplorer/currentprojectfilter.h index b9d63db2930..8db0c567c0e 100644 --- a/src/plugins/projectexplorer/currentprojectfilter.h +++ b/src/plugins/projectexplorer/currentprojectfilter.h @@ -5,8 +5,6 @@ #include -#include - namespace ProjectExplorer { class Project; @@ -19,12 +17,12 @@ class CurrentProjectFilter : public Core::BaseFileFilter public: CurrentProjectFilter(); - void refresh(QFutureInterface &future) override; void prepareSearch(const QString &entry) override; private: void currentProjectChanged(); - void markFilesAsOutOfDate(); + void invalidateCache(); + std::optional refreshRecipe() override; Project *m_project = nullptr; };