From 07cbc49d33bdb2308639972013d358d0c112e5a5 Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Tue, 3 Mar 2020 12:30:28 +0100 Subject: [PATCH] Allow blocking auto files refresh While importing assets, qml files are generated under the import path and this triggers files update every time a file is added. This results into high CPU usage. Task-number: QDS-1675 Change-Id: Ia0775ef78bbffedfaf2c140365ee31718e7ee3a4 Reviewed-by: Tim Jenssen --- src/plugins/qmlprojectmanager/qmlproject.cpp | 9 +++++++++ src/plugins/qmlprojectmanager/qmlproject.h | 21 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index fc622179cae..fe7542e8cbe 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -57,11 +57,16 @@ #include #include #include +#include using namespace Core; using namespace ProjectExplorer; using namespace QmlProjectManager::Internal; +namespace { +Q_LOGGING_CATEGORY(infoLogger, "QmlProjectManager.QmlBuildSystem", QtInfoMsg) +} + namespace QmlProjectManager { QmlProject::QmlProject(const Utils::FilePath &fileName) @@ -276,6 +281,10 @@ QStringList QmlBuildSystem::makeAbsolute(const Utils::FilePath &path, const QStr void QmlBuildSystem::refreshFiles(const QSet &/*added*/, const QSet &removed) { + if (m_blockFilesUpdate) { + qCDebug(infoLogger) << "Auto files refresh blocked."; + return; + } refresh(Files); if (!removed.isEmpty()) { if (auto modelManager = QmlJS::ModelManagerInterface::instance()) diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 0cff1528984..acd8bc1094e 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -104,6 +104,27 @@ public: QPointer m_projectItem; Utils::FilePath m_canonicalProjectDir; + +private: + bool m_blockFilesUpdate = false; + friend class FilesUpdateBlocker; +}; + +class FilesUpdateBlocker { +public: + FilesUpdateBlocker(QmlBuildSystem* bs): m_bs(bs) { + if (m_bs) + m_bs->m_blockFilesUpdate = true; + } + + ~FilesUpdateBlocker() { + if (m_bs) { + m_bs->m_blockFilesUpdate = false; + m_bs->refresh(QmlBuildSystem::Everything); + } + } +private: + QPointer m_bs; }; class QMLPROJECTMANAGER_EXPORT QmlProject : public ProjectExplorer::Project