From 7c8948bef4774d64bd79d3b5ba7b04444d0bd7e3 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 13 Jul 2023 17:59:56 +0200 Subject: [PATCH] WebAssembly: Self-register aspects in runconfiguration No real benefit in this particular case, but the general pattern now. Change-Id: Ia06d3221a2ccd4b7ab429f6e045c11fffffe99ad Reviewed-by: Alessandro Portale --- .../webassemblyrunconfiguration.cpp | 27 ++++++++++--------- .../webassemblyrunconfigurationaspects.cpp | 8 ++++-- .../webassemblyrunconfigurationaspects.h | 6 +++-- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/plugins/webassembly/webassemblyrunconfiguration.cpp b/src/plugins/webassembly/webassemblyrunconfiguration.cpp index 32f1bf581bb..7459853f508 100644 --- a/src/plugins/webassembly/webassemblyrunconfiguration.cpp +++ b/src/plugins/webassembly/webassemblyrunconfiguration.cpp @@ -69,25 +69,28 @@ class EmrunRunConfiguration : public ProjectExplorer::RunConfiguration { public: EmrunRunConfiguration(Target *target, Utils::Id id) - : RunConfiguration(target, id) + : RunConfiguration(target, id) { - auto webBrowserAspect = addAspect(target); + webBrowser.setTarget(target); - auto effectiveEmrunCall = addAspect(); - effectiveEmrunCall->setLabelText(Tr::tr("Effective emrun call:")); - effectiveEmrunCall->setDisplayStyle(StringAspect::TextEditDisplay); - effectiveEmrunCall->setReadOnly(true); + effectiveEmrunCall.setLabelText(Tr::tr("Effective emrun call:")); + effectiveEmrunCall.setDisplayStyle(StringAspect::TextEditDisplay); + effectiveEmrunCall.setReadOnly(true); - setUpdater([this, target, effectiveEmrunCall, webBrowserAspect] { - effectiveEmrunCall->setValue(emrunCommand(target, - buildKey(), - webBrowserAspect->currentBrowser(), - "").toUserOutput()); + setUpdater([this, target] { + effectiveEmrunCall.setValue(emrunCommand(target, + buildKey(), + webBrowser.currentBrowser(), + "").toUserOutput()); }); - connect(webBrowserAspect, &BaseAspect::changed, this, &RunConfiguration::update); + connect(&webBrowser, &BaseAspect::changed, this, &RunConfiguration::update); connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); } + +private: + WebBrowserSelectionAspect webBrowser{this}; + StringAspect effectiveEmrunCall{this}; }; class EmrunRunWorker : public SimpleTargetRunner diff --git a/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp b/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp index 05b7e89e821..74ee0ded60f 100644 --- a/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp +++ b/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp @@ -41,9 +41,13 @@ static WebBrowserEntries emrunBrowsers(ProjectExplorer::Target *target) return result; } -WebBrowserSelectionAspect::WebBrowserSelectionAspect(ProjectExplorer::Target *target) - : m_availableBrowsers(emrunBrowsers(target)) +WebBrowserSelectionAspect::WebBrowserSelectionAspect(AspectContainer *container) + : BaseAspect(container) +{} + +void WebBrowserSelectionAspect::setTarget(ProjectExplorer::Target *target) { + m_availableBrowsers = emrunBrowsers(target); if (!m_availableBrowsers.isEmpty()) { const int defaultIndex = qBound(0, m_availableBrowsers.count() - 1, 1); m_currentBrowser = m_availableBrowsers.at(defaultIndex).first; diff --git a/src/plugins/webassembly/webassemblyrunconfigurationaspects.h b/src/plugins/webassembly/webassemblyrunconfigurationaspects.h index 8a3cc24bdb2..db584d33a19 100644 --- a/src/plugins/webassembly/webassemblyrunconfigurationaspects.h +++ b/src/plugins/webassembly/webassemblyrunconfigurationaspects.h @@ -18,7 +18,9 @@ class WebBrowserSelectionAspect : public Utils::BaseAspect Q_OBJECT public: - WebBrowserSelectionAspect(ProjectExplorer::Target *target); + WebBrowserSelectionAspect(Utils::AspectContainer *container); + + void setTarget(ProjectExplorer::Target *target); void addToLayout(Layouting::LayoutItem &parent) override; @@ -37,7 +39,7 @@ public: private: QComboBox *m_webBrowserComboBox = nullptr; QString m_currentBrowser; - const WebBrowserEntries m_availableBrowsers; + WebBrowserEntries m_availableBrowsers; }; } // namespace Internal