forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/qds-1.59' into 4.13
Conflicts: src/plugins/clangformat/clangformatplugin.cpp src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp src/plugins/qmldesigner/qmldesigner.qbs Change-Id: Ie4a0beeb9fd32ac9683f4e8769988a9c3f3e369a
This commit is contained in:
@@ -6,6 +6,7 @@ add_qtc_plugin(QmlProjectManager
|
||||
fileformat/qmlprojectfileformat.cpp fileformat/qmlprojectfileformat.h
|
||||
fileformat/qmlprojectitem.cpp fileformat/qmlprojectitem.h
|
||||
qmlmainfileaspect.cpp qmlmainfileaspect.h
|
||||
qmlmultilanguageaspect.cpp qmlmultilanguageaspect.h
|
||||
qmlproject.cpp qmlproject.h
|
||||
qmlproject.qrc
|
||||
qmlprojectconstants.h
|
||||
|
||||
128
src/plugins/qmlprojectmanager/qmlmultilanguageaspect.cpp
Normal file
128
src/plugins/qmlprojectmanager/qmlmultilanguageaspect.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmlmultilanguageaspect.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
static bool isMultilanguagePresent()
|
||||
{
|
||||
const QVector<ExtensionSystem::PluginSpec *> specs = ExtensionSystem::PluginManager::plugins();
|
||||
return std::find_if(specs.begin(),
|
||||
specs.end(),
|
||||
[](ExtensionSystem::PluginSpec *spec) {
|
||||
return spec->name() == "MultiLanguage";
|
||||
})
|
||||
!= specs.end();
|
||||
}
|
||||
|
||||
static Utils::FilePath getMultilanguageDatabaseFilePath(ProjectExplorer::Target *target)
|
||||
{
|
||||
if (target) {
|
||||
auto filePath = target->project()->projectDirectory().pathAppended("/multilanguage-experimental-v1.db");
|
||||
if (filePath.exists())
|
||||
return filePath;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static QObject *getPreviewPlugin()
|
||||
{
|
||||
auto pluginIt = std::find_if(ExtensionSystem::PluginManager::plugins().begin(),
|
||||
ExtensionSystem::PluginManager::plugins().end(),
|
||||
[](const ExtensionSystem::PluginSpec *p) {
|
||||
return p->name() == "QmlPreview";
|
||||
});
|
||||
|
||||
if (pluginIt != ExtensionSystem::PluginManager::plugins().constEnd())
|
||||
return (*pluginIt)->plugin();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
namespace QmlProjectManager {
|
||||
|
||||
QmlMultiLanguageAspect::QmlMultiLanguageAspect(ProjectExplorer::Target *target)
|
||||
: m_target(target)
|
||||
{
|
||||
setVisible(isMultilanguagePresent());
|
||||
setSettingsKey(Constants::USE_MULTILANGUAGE_KEY);
|
||||
setLabel(tr("Use MultiLanguage translation database."), BaseBoolAspect::LabelPlacement::AtCheckBox);
|
||||
setToolTip(tr("Enable loading application with special desktop SQLite translation database."));
|
||||
|
||||
setDefaultValue(!databaseFilePath().isEmpty());
|
||||
QVariantMap getDefaultValues;
|
||||
fromMap(getDefaultValues);
|
||||
|
||||
if (auto previewPlugin = getPreviewPlugin())
|
||||
connect(previewPlugin, SIGNAL(localeChanged(QString)), this, SLOT(setLastUsedLanguage(QString)));
|
||||
}
|
||||
|
||||
QmlMultiLanguageAspect::~QmlMultiLanguageAspect()
|
||||
{
|
||||
}
|
||||
|
||||
void QmlMultiLanguageAspect::setLastUsedLanguage(const QString &language)
|
||||
{
|
||||
if (auto previewPlugin = getPreviewPlugin())
|
||||
previewPlugin->setProperty("locale", language);
|
||||
if (m_lastUsedLanguage != language) {
|
||||
m_lastUsedLanguage = language;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
QString QmlMultiLanguageAspect::lastUsedLanguage() const
|
||||
{
|
||||
return m_lastUsedLanguage;
|
||||
}
|
||||
|
||||
Utils::FilePath QmlMultiLanguageAspect::databaseFilePath() const
|
||||
{
|
||||
if (m_databaseFilePath.isEmpty())
|
||||
m_databaseFilePath = getMultilanguageDatabaseFilePath(m_target);
|
||||
return m_databaseFilePath;
|
||||
}
|
||||
|
||||
void QmlMultiLanguageAspect::toMap(QVariantMap &map) const
|
||||
{
|
||||
BaseBoolAspect::toMap(map);
|
||||
if (!m_lastUsedLanguage.isEmpty())
|
||||
map.insert(Constants::LAST_USED_LANGUAGE, m_lastUsedLanguage);
|
||||
}
|
||||
|
||||
void QmlMultiLanguageAspect::fromMap(const QVariantMap &map)
|
||||
{
|
||||
BaseBoolAspect::fromMap(map);
|
||||
setLastUsedLanguage(map.value(Constants::LAST_USED_LANGUAGE, "en").toString());
|
||||
}
|
||||
|
||||
} // namespace QmlProjectManager
|
||||
57
src/plugins/qmlprojectmanager/qmlmultilanguageaspect.h
Normal file
57
src/plugins/qmlprojectmanager/qmlmultilanguageaspect.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "qmlprojectmanager_global.h"
|
||||
|
||||
#include <qmlprojectmanager/qmlprojectmanagerconstants.h>
|
||||
|
||||
#include <projectexplorer/runconfigurationaspects.h>
|
||||
|
||||
namespace QmlProjectManager {
|
||||
|
||||
class QMLPROJECTMANAGER_EXPORT QmlMultiLanguageAspect : public ProjectExplorer::BaseBoolAspect
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QmlMultiLanguageAspect(ProjectExplorer::Target *target);
|
||||
~QmlMultiLanguageAspect() override;
|
||||
|
||||
QString lastUsedLanguage() const;
|
||||
Utils::FilePath databaseFilePath() const;
|
||||
void toMap(QVariantMap &map) const final;
|
||||
void fromMap(const QVariantMap &map) final;
|
||||
|
||||
public slots:
|
||||
void setLastUsedLanguage(const QString &language);
|
||||
|
||||
private:
|
||||
ProjectExplorer::Target *m_target = nullptr;
|
||||
mutable Utils::FilePath m_databaseFilePath;
|
||||
QString m_lastUsedLanguage;
|
||||
};
|
||||
|
||||
} // namespace QmlProjectManager
|
||||
@@ -7,6 +7,7 @@ DEFINES += QMLPROJECTMANAGER_LIBRARY
|
||||
|
||||
HEADERS += \
|
||||
qmlmainfileaspect.h \
|
||||
qmlmultilanguageaspect.h \
|
||||
qmlproject.h \
|
||||
qmlprojectplugin.h \
|
||||
qmlprojectconstants.h \
|
||||
@@ -17,6 +18,7 @@ HEADERS += \
|
||||
|
||||
SOURCES += \
|
||||
qmlmainfileaspect.cpp \
|
||||
qmlmultilanguageaspect.cpp \
|
||||
qmlproject.cpp \
|
||||
qmlprojectplugin.cpp \
|
||||
qmlprojectnodes.cpp \
|
||||
|
||||
@@ -16,6 +16,7 @@ QtcPlugin {
|
||||
name: "General"
|
||||
files: [
|
||||
"qmlmainfileaspect.cpp", "qmlmainfileaspect.h",
|
||||
"qmlmultilanguageaspect.cpp", "qmlmultilanguageaspect.h",
|
||||
"qmlproject.cpp", "qmlproject.h",
|
||||
"qmlproject.qrc",
|
||||
"qmlprojectconstants.h",
|
||||
|
||||
@@ -34,6 +34,8 @@ const char QML_PROJECT_ID[] = "QmlProjectManager.QmlProject";
|
||||
const char QML_VIEWER_ARGUMENTS_KEY[] = "QmlProjectManager.QmlRunConfiguration.QDeclarativeViewerArguments";
|
||||
const char QML_VIEWER_TARGET_DISPLAY_NAME[] = "QML Viewer";
|
||||
const char QML_MAINSCRIPT_KEY[] = "QmlProjectManager.QmlRunConfiguration.MainScript";
|
||||
const char USE_MULTILANGUAGE_KEY[] = "QmlProjectManager.QmlRunConfiguration.UseMultiLanguage";
|
||||
const char LAST_USED_LANGUAGE[] = "QmlProjectManager.QmlRunConfiguration.LastUsedLanguage";
|
||||
const char USER_ENVIRONMENT_CHANGES_KEY[] = "QmlProjectManager.QmlRunConfiguration.UserEnvironmentChanges";
|
||||
|
||||
} // namespace Constants
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "qmlproject.h"
|
||||
#include "qmlprojectmanagerconstants.h"
|
||||
#include "qmlmainfileaspect.h"
|
||||
#include "qmlmainfileaspect.h"
|
||||
#include "qmlmultilanguageaspect.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
@@ -59,6 +59,7 @@ using namespace QtSupport;
|
||||
using namespace Utils;
|
||||
|
||||
namespace QmlProjectManager {
|
||||
class QmlMultiLanguageAspect;
|
||||
namespace Internal {
|
||||
|
||||
// QmlProjectRunConfiguration
|
||||
@@ -81,30 +82,12 @@ private:
|
||||
|
||||
BaseStringAspect *m_qmlViewerAspect = nullptr;
|
||||
QmlMainFileAspect *m_qmlMainFileAspect = nullptr;
|
||||
QmlMultiLanguageAspect *m_multiLanguageAspect = nullptr;
|
||||
};
|
||||
|
||||
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
auto envAspect = addAspect<EnvironmentAspect>();
|
||||
|
||||
auto envModifier = [this](Environment env) {
|
||||
if (auto bs = dynamic_cast<const QmlBuildSystem *>(activeBuildSystem()))
|
||||
env.modify(bs->environment());
|
||||
return env;
|
||||
};
|
||||
|
||||
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
|
||||
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
||||
envAspect->addPreferredBaseEnvironment(tr("System Environment"), [envModifier] {
|
||||
return envModifier(Environment::systemEnvironment());
|
||||
});
|
||||
}
|
||||
|
||||
envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), [envModifier] {
|
||||
return envModifier(Environment());
|
||||
});
|
||||
|
||||
m_qmlViewerAspect = addAspect<BaseStringAspect>();
|
||||
m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
|
||||
m_qmlViewerAspect->setPlaceHolderText(commandLine().executable().toString());
|
||||
@@ -123,6 +106,34 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
||||
|
||||
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
|
||||
|
||||
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>(target);
|
||||
|
||||
auto envAspect = addAspect<EnvironmentAspect>();
|
||||
connect(m_multiLanguageAspect, &QmlMultiLanguageAspect::changed, envAspect, &EnvironmentAspect::environmentChanged);
|
||||
|
||||
auto envModifier = [this](Environment env) {
|
||||
if (auto bs = dynamic_cast<const QmlBuildSystem *>(activeBuildSystem()))
|
||||
env.modify(bs->environment());
|
||||
|
||||
if (m_multiLanguageAspect && m_multiLanguageAspect->value() && !m_multiLanguageAspect->databaseFilePath().isEmpty()) {
|
||||
env.set("QT_MULTILANGUAGE_DATABASE", m_multiLanguageAspect->databaseFilePath().toString());
|
||||
env.set("QT_MULTILANGUAGE_LANGUAGE", m_multiLanguageAspect->lastUsedLanguage());
|
||||
}
|
||||
return env;
|
||||
};
|
||||
|
||||
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
|
||||
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
||||
envAspect->addPreferredBaseEnvironment(tr("System Environment"), [envModifier] {
|
||||
return envModifier(Environment::systemEnvironment());
|
||||
});
|
||||
}
|
||||
|
||||
envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), [envModifier] {
|
||||
Environment environment;
|
||||
return envModifier(environment);
|
||||
});
|
||||
|
||||
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
||||
update();
|
||||
}
|
||||
@@ -208,6 +219,10 @@ QString QmlProjectRunConfiguration::commandLineArguments() const
|
||||
const QString main = bs->targetFile(FilePath::fromString(mainScript())).toString();
|
||||
if (!main.isEmpty())
|
||||
QtcProcess::addArg(&args, main, osType);
|
||||
|
||||
if (m_multiLanguageAspect && m_multiLanguageAspect->value())
|
||||
QtcProcess::addArg(&args, "-qmljsdebugger=file:unused_if_debugger_arguments_added,services:DebugTranslation", osType);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user