qmlproject: add convenience method to QmlMultiLanguageAspect

Change-Id: I88799aa1c5caa5c967b7c680ef9ddcbdd4b01bf5
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Tim Jenssen
2020-07-21 13:47:14 +02:00
parent 3659f5b41d
commit b45b771581
4 changed files with 35 additions and 17 deletions

View File

@@ -546,12 +546,8 @@ void NodeInstanceView::auxiliaryDataChanged(const ModelNode &node,
} }
} else if (node.isRootNode() && name == "language@Internal") { } else if (node.isRootNode() && name == "language@Internal") {
const QString languageAsString = value.toString(); const QString languageAsString = value.toString();
if (m_currentTarget) { if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current(m_currentTarget))
if (auto rc = m_currentTarget->activeRunConfiguration()) { multiLanguageAspect->setLastUsedLanguage(languageAsString);
if (auto multiLanguageAspect = rc->aspect<QmlProjectManager::QmlMultiLanguageAspect>())
multiLanguageAspect->setLastUsedLanguage(languageAsString);
}
}
nodeInstanceServer()->changeLanguage({languageAsString}); nodeInstanceServer()->changeLanguage({languageAsString});
} else if (node.isRootNode() && name == "previewSize@Internal") { } else if (node.isRootNode() && name == "previewSize@Internal") {
nodeInstanceServer()->changePreviewImageSize(value.toSize()); nodeInstanceServer()->changePreviewImageSize(value.toSize());
@@ -994,12 +990,8 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
} }
QString lastUsedLanguage; QString lastUsedLanguage;
if (m_currentTarget) { if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current(m_currentTarget))
if (auto rc = m_currentTarget->activeRunConfiguration()) { lastUsedLanguage = multiLanguageAspect->lastUsedLanguage();
if (auto multiLanguageAspect = rc->aspect<QmlProjectManager::QmlMultiLanguageAspect>())
lastUsedLanguage = multiLanguageAspect->lastUsedLanguage();
}
}
return CreateSceneCommand( return CreateSceneCommand(
instanceContainerList, instanceContainerList,

View File

@@ -512,11 +512,9 @@ QProcessEnvironment PuppetCreator::processEnvironment() const
customFileSelectors = m_target->additionalData("CustomFileSelectorsData").toStringList(); customFileSelectors = m_target->additionalData("CustomFileSelectorsData").toStringList();
if (auto *rc = m_target->activeRunConfiguration()) { if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current(m_target)) {
if (auto multiLanguageAspect = rc->aspect<QmlProjectManager::QmlMultiLanguageAspect>()) { if (!multiLanguageAspect->databaseFilePath().isEmpty())
if (!multiLanguageAspect->databaseFilePath().isEmpty()) environment.set("QT_MULTILANGUAGE_DATABASE", multiLanguageAspect->databaseFilePath().toString());
environment.set("QT_MULTILANGUAGE_DATABASE", multiLanguageAspect->databaseFilePath().toString());
}
} }
} }

View File

@@ -30,6 +30,7 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
static bool isMultilanguagePresent() static bool isMultilanguagePresent()
@@ -125,4 +126,27 @@ void QmlMultiLanguageAspect::fromMap(const QVariantMap &map)
setLastUsedLanguage(map.value(Constants::LAST_USED_LANGUAGE, "en").toString()); setLastUsedLanguage(map.value(Constants::LAST_USED_LANGUAGE, "en").toString());
} }
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current()
{
if (auto project = ProjectExplorer::SessionManager::startupProject())
return current(project);
return {};
}
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(ProjectExplorer::Project *project)
{
if (auto target = project->activeTarget())
return current(target);
return {};
}
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(ProjectExplorer::Target *target)
{
if (auto runConfiguration = target->activeRunConfiguration()) {
if (auto multiLanguageAspect = runConfiguration->aspect<QmlProjectManager::QmlMultiLanguageAspect>())
return multiLanguageAspect;
}
return {};
}
} // namespace QmlProjectManager } // namespace QmlProjectManager

View File

@@ -45,6 +45,10 @@ public:
void toMap(QVariantMap &map) const final; void toMap(QVariantMap &map) const final;
void fromMap(const QVariantMap &map) final; void fromMap(const QVariantMap &map) final;
static QmlMultiLanguageAspect *current();
static QmlMultiLanguageAspect *current(ProjectExplorer::Project *project);
static QmlMultiLanguageAspect *current(ProjectExplorer::Target *target);
public slots: public slots:
void setLastUsedLanguage(const QString &language); void setLastUsedLanguage(const QString &language);