QmlProjectManager: Use aspects more directly

Change-Id: Ibfa91c541666ed81dbe5238075cafebd628f5889
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-07-14 12:13:00 +02:00
parent 2a8765b35b
commit 6d5b078238

View File

@@ -59,27 +59,29 @@ private:
FilePath mainScript() const; FilePath mainScript() const;
FilePath qmlRuntimeFilePath() const; FilePath qmlRuntimeFilePath() const;
void createQtVersionAspect(); void setupQtVersionAspect();
FilePathAspect qmlViewer{this};
ArgumentsAspect arguments{this};
QmlMainFileAspect qmlMainFile{this};
SelectionAspect qtversion{this};
QmlMultiLanguageAspect multiLanguage{this};
EnvironmentAspect environment{this};
X11ForwardingAspect x11Forwarding{this};
FilePathAspect *m_qmlViewerAspect = nullptr;
QmlMainFileAspect *m_qmlMainFileAspect = nullptr;
QmlMultiLanguageAspect *m_multiLanguageAspect = nullptr;
SelectionAspect *m_qtversionAspect = nullptr;
mutable bool usePuppetAsQmlRuntime = false; mutable bool usePuppetAsQmlRuntime = false;
}; };
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id) QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
m_qmlViewerAspect = addAspect<FilePathAspect>(); qmlViewer.setSettingsKey(Constants::QML_VIEWER_KEY);
m_qmlViewerAspect->setLabelText(Tr::tr("Override device QML viewer:")); qmlViewer.setLabelText(Tr::tr("Override device QML viewer:"));
m_qmlViewerAspect->setPlaceHolderText(qmlRuntimeFilePath().toUserOutput()); qmlViewer.setPlaceHolderText(qmlRuntimeFilePath().toUserOutput());
m_qmlViewerAspect->setHistoryCompleter("QmlProjectManager.viewer.history"); qmlViewer.setHistoryCompleter("QmlProjectManager.viewer.history");
m_qmlViewerAspect->setSettingsKey(Constants::QML_VIEWER_KEY);
auto argumentAspect = addAspect<ArgumentsAspect>(); arguments.setSettingsKey(Constants::QML_VIEWER_ARGUMENTS_KEY);
argumentAspect->setMacroExpander(macroExpander()); arguments.setMacroExpander(macroExpander());
argumentAspect->setSettingsKey(Constants::QML_VIEWER_ARGUMENTS_KEY);
setCommandLineGetter([this, target] { setCommandLineGetter([this, target] {
const FilePath qmlRuntime = qmlRuntimeFilePath(); const FilePath qmlRuntime = qmlRuntimeFilePath();
@@ -88,7 +90,7 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
cmd.addArg("--qml-runtime"); cmd.addArg("--qml-runtime");
// arguments in .user file // arguments in .user file
cmd.addArgs(aspect<ArgumentsAspect>()->arguments(), CommandLine::Raw); cmd.addArgs(arguments(), CommandLine::Raw);
// arguments from .qmlproject file // arguments from .qmlproject file
const QmlBuildSystem *bs = qobject_cast<QmlBuildSystem *>(target->buildSystem()); const QmlBuildSystem *bs = qobject_cast<QmlBuildSystem *>(target->buildSystem());
@@ -120,35 +122,31 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
return cmd; return cmd;
}); });
m_qmlMainFileAspect = addAspect<QmlMainFileAspect>(); qmlMainFile.setTarget(target);
m_qmlMainFileAspect->setTarget(target); connect(&qmlMainFile, &BaseAspect::changed, this, &RunConfiguration::update);
connect(m_qmlMainFileAspect, &QmlMainFileAspect::changed, this, &RunConfiguration::update);
createQtVersionAspect(); if (QmlProject::isQtDesignStudio())
setupQtVersionAspect();
else
qtversion.setVisible(false);
connect(target, &Target::kitChanged, this, &RunConfiguration::update); connect(target, &Target::kitChanged, this, &RunConfiguration::update);
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>(); multiLanguage.setTarget(target);
m_multiLanguageAspect->setTarget(target);
auto buildSystem = qobject_cast<const QmlBuildSystem *>(activeBuildSystem()); auto buildSystem = qobject_cast<const QmlBuildSystem *>(activeBuildSystem());
if (buildSystem) if (buildSystem)
m_multiLanguageAspect->setValue(buildSystem->multilanguageSupport()); multiLanguage.setValue(buildSystem->multilanguageSupport());
auto envAspect = addAspect<EnvironmentAspect>(); connect(&multiLanguage, &BaseAspect::changed,
connect(m_multiLanguageAspect, &environment, &EnvironmentAspect::environmentChanged);
&QmlMultiLanguageAspect::changed,
envAspect,
&EnvironmentAspect::environmentChanged);
auto envModifier = [this](Environment env) { auto envModifier = [this](Environment env) {
if (auto bs = qobject_cast<const QmlBuildSystem *>(activeBuildSystem())) if (auto bs = qobject_cast<const QmlBuildSystem *>(activeBuildSystem()))
env.modify(bs->environment()); env.modify(bs->environment());
if (m_multiLanguageAspect && m_multiLanguageAspect->value() if (multiLanguage() && !multiLanguage.databaseFilePath().isEmpty()) {
&& !m_multiLanguageAspect->databaseFilePath().isEmpty()) { env.set("QT_MULTILANGUAGE_DATABASE", multiLanguage.databaseFilePath().path());
env.set("QT_MULTILANGUAGE_DATABASE", env.set("QT_MULTILANGUAGE_LANGUAGE", multiLanguage.currentLocale());
m_multiLanguageAspect->databaseFilePath().toString());
env.set("QT_MULTILANGUAGE_LANGUAGE", m_multiLanguageAspect->currentLocale());
} else { } else {
env.unset("QT_MULTILANGUAGE_DATABASE"); env.unset("QT_MULTILANGUAGE_DATABASE");
env.unset("QT_MULTILANGUAGE_LANGUAGE"); env.unset("QT_MULTILANGUAGE_LANGUAGE");
@@ -158,20 +156,17 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit()); const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) { if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
envAspect->addPreferredBaseEnvironment(Tr::tr("System Environment"), [envModifier] { environment.addPreferredBaseEnvironment(Tr::tr("System Environment"), [envModifier] {
return envModifier(Environment::systemEnvironment()); return envModifier(Environment::systemEnvironment());
}); });
} }
envAspect->addSupportedBaseEnvironment(Tr::tr("Clean Environment"), [envModifier] { environment.addSupportedBaseEnvironment(Tr::tr("Clean Environment"), [envModifier] {
Environment environment; Environment environment;
return envModifier(environment); return envModifier(environment);
}); });
if (HostOsInfo::isAnyUnixHost()) { x11Forwarding.setMacroExpander(macroExpander());
auto x11Forwarding = addAspect<X11ForwardingAspect>();
x11Forwarding->setMacroExpander(macroExpander());
}
setRunnableModifier([this](Runnable &r) { setRunnableModifier([this](Runnable &r) {
const QmlBuildSystem *bs = static_cast<QmlBuildSystem *>(activeBuildSystem()); const QmlBuildSystem *bs = static_cast<QmlBuildSystem *>(activeBuildSystem());
@@ -202,9 +197,8 @@ FilePath QmlProjectRunConfiguration::qmlRuntimeFilePath() const
{ {
usePuppetAsQmlRuntime = false; usePuppetAsQmlRuntime = false;
// Give precedence to the manual override in the run configuration. // Give precedence to the manual override in the run configuration.
const FilePath qmlViewer = m_qmlViewerAspect->filePath(); if (!qmlViewer().isEmpty())
if (!qmlViewer.isEmpty()) return qmlViewer();
return qmlViewer;
Kit *kit = target()->kit(); Kit *kit = target()->kit();
@@ -241,15 +235,11 @@ FilePath QmlProjectRunConfiguration::qmlRuntimeFilePath() const
return dev ? dev->filePath("qml").searchInPath() : "qml"; return dev ? dev->filePath("qml").searchInPath() : "qml";
} }
void QmlProjectRunConfiguration::createQtVersionAspect() void QmlProjectRunConfiguration::setupQtVersionAspect()
{ {
if (!QmlProject::isQtDesignStudio()) qtversion.setSettingsKey("QmlProjectManager.kit");
return; qtversion.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
qtversion.setLabelText(Tr::tr("Qt Version:"));
m_qtversionAspect = addAspect<SelectionAspect>();
m_qtversionAspect->setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
m_qtversionAspect->setLabelText(Tr::tr("Qt Version:"));
m_qtversionAspect->setSettingsKey("QmlProjectManager.kit");
Kit *kit = target()->kit(); Kit *kit = target()->kit();
QtVersion *version = QtKitAspect::qtVersion(kit); QtVersion *version = QtKitAspect::qtVersion(kit);
@@ -259,23 +249,23 @@ void QmlProjectRunConfiguration::createQtVersionAspect()
const bool isQt6Project = buildSystem && buildSystem->qt6Project(); const bool isQt6Project = buildSystem && buildSystem->qt6Project();
if (isQt6Project) { if (isQt6Project) {
m_qtversionAspect->addOption(Tr::tr("Qt 6")); qtversion.addOption(Tr::tr("Qt 6"));
m_qtversionAspect->setReadOnly(true); qtversion.setReadOnly(true);
} else { /* Only if this is not a Qt 6 project changing kits makes sense */ } else { /* Only if this is not a Qt 6 project changing kits makes sense */
m_qtversionAspect->addOption(Tr::tr("Qt 5")); qtversion.addOption(Tr::tr("Qt 5"));
m_qtversionAspect->addOption(Tr::tr("Qt 6")); qtversion.addOption(Tr::tr("Qt 6"));
const int valueForVersion = version->qtVersion().majorVersion() == 6 ? 1 : 0; const int valueForVersion = version->qtVersion().majorVersion() == 6 ? 1 : 0;
m_qtversionAspect->setValue(valueForVersion); qtversion.setValue(valueForVersion);
connect(m_qtversionAspect, &SelectionAspect::changed, this, [&]() { connect(&qtversion, &BaseAspect::changed, this, [this] {
QTC_ASSERT(target(), return ); QTC_ASSERT(target(), return );
auto project = target()->project(); auto project = target()->project();
QTC_ASSERT(project, return ); QTC_ASSERT(project, return );
int oldValue = !m_qtversionAspect->value(); int oldValue = !qtversion();
const int preferedQtVersion = m_qtversionAspect->value() > 0 ? 6 : 5; const int preferedQtVersion = qtversion() > 0 ? 6 : 5;
Kit *currentKit = target()->kit(); Kit *currentKit = target()->kit();
const QList<Kit *> kits = Utils::filtered(KitManager::kits(), [&](const Kit *k) { const QList<Kit *> kits = Utils::filtered(KitManager::kits(), [&](const Kit *k) {
@@ -296,9 +286,10 @@ void QmlProjectRunConfiguration::createQtVersionAspect()
project->setActiveTarget(newTarget, SetActive::Cascade); project->setActiveTarget(newTarget, SetActive::Cascade);
/* Reset the aspect. We changed the target and this aspect should not change. */ /* Reset the aspect. We changed the target and this aspect should not change. */
m_qtversionAspect->blockSignals(true); // FIXME: That should use setValueSilently()
m_qtversionAspect->setValue(oldValue); qtversion.blockSignals(true);
m_qtversionAspect->blockSignals(false); qtversion.setValue(oldValue);
qtversion.blockSignals(false);
} }
}); });
} }
@@ -307,13 +298,14 @@ void QmlProjectRunConfiguration::createQtVersionAspect()
bool QmlProjectRunConfiguration::isEnabled() const bool QmlProjectRunConfiguration::isEnabled() const
{ {
return m_qmlMainFileAspect->isQmlFilePresent() && !commandLine().executable().isEmpty() return const_cast<QmlProjectRunConfiguration *>(this)->qmlMainFile.isQmlFilePresent()
&& !commandLine().executable().isEmpty()
&& activeBuildSystem()->hasParsingData(); && activeBuildSystem()->hasParsingData();
} }
FilePath QmlProjectRunConfiguration::mainScript() const FilePath QmlProjectRunConfiguration::mainScript() const
{ {
return m_qmlMainFileAspect->mainScript(); return qmlMainFile.mainScript();
} }
// QmlProjectRunConfigurationFactory // QmlProjectRunConfigurationFactory