diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2020-06-26 15:13:07 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2020-06-26 16:51:22 +0200 |
commit | b8cd87dea027f54957373a10c77a506ec2509b10 (patch) | |
tree | ab7b00b4be9a46c1a0c89afaab7016444a257633 /src/plugins/qmldesigner/qmlpreviewplugin | |
parent | 97ac63b4012ab55def11a58ee6bd7b6878dc37e1 (diff) | |
parent | 5a06305ffe054287f55cba4c5d860ea73fccf684 (diff) |
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
Diffstat (limited to 'src/plugins/qmldesigner/qmlpreviewplugin')
-rw-r--r-- | src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp | 44 | ||||
-rw-r--r-- | src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.h | 2 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp index 330446d8408..b94f87bc40a 100644 --- a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp +++ b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp @@ -27,6 +27,7 @@ #include "qmlpreviewactions.h" #include <zoomaction.h> +#include <designersettings.h> #include <utils/utilsicons.h> #include <projectexplorer/projectexplorer.h> @@ -47,12 +48,10 @@ const Utils::Icon previewIcon({ static void handleAction(const SelectionContext &context) { if (context.view()->isAttached()) { - if (context.toggled()) { + if (context.toggled()) ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE); - QmlPreviewPlugin::setQmlFile(); - } else { + else QmlPreviewPlugin::stopAllRunControls(); - } } } @@ -216,42 +215,46 @@ SwitchLanguageComboboxAction::SwitchLanguageComboboxAction(QObject *parent) connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged, this, - &SwitchLanguageComboboxAction::refreshProjectLocales); + &SwitchLanguageComboboxAction::updateProjectLocales); } QWidget *SwitchLanguageComboboxAction::createWidget(QWidget *parent) { QPointer<QComboBox> comboBox = new QComboBox(parent); comboBox->setToolTip(tr("Switch the language used by preview.")); - connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this, comboBox](int index) { - if (index == 0) - emit currentLocaleChanged(""); - else - emit currentLocaleChanged(comboBox->currentText()); - }); + comboBox->addItem(tr("Default")); auto refreshComboBoxFunction = [this, comboBox] (ProjectExplorer::Project *project) { if (comboBox) { - refreshProjectLocales(project); - comboBox->clear(); - comboBox->addItem(tr("Default")); - comboBox->addItems(m_localeStrings); + if (updateProjectLocales(project)) { + comboBox->clear(); + comboBox->addItem(tr("Default")); + comboBox->addItems(m_localeStrings); + } } }; - connect(ProjectExplorer::SessionManager::instance(), - &ProjectExplorer::SessionManager::startupProjectChanged, - refreshComboBoxFunction); + connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged, + comboBox, refreshComboBoxFunction); if (auto project = SessionManager::startupProject()) refreshComboBoxFunction(project); + // do this after refreshComboBoxFunction so we do not get currentLocaleChanged signals at initialization + connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this, comboBox](int index) { + if (index == 0) // == Default + emit currentLocaleChanged(""); + else + emit currentLocaleChanged(comboBox->currentText()); + }); + return comboBox; } -void SwitchLanguageComboboxAction::refreshProjectLocales(Project *project) +bool SwitchLanguageComboboxAction::updateProjectLocales(Project *project) { if (!project) - return; + return false; + auto previousLocales = m_localeStrings; m_localeStrings.clear(); const auto projectDirectory = project->rootProjectDirectory().toFileInfo().absoluteFilePath(); const QDir languageDirectory(projectDirectory + "/i18n"); @@ -262,6 +265,7 @@ void SwitchLanguageComboboxAction::refreshProjectLocales(Project *project) const QString locale = qmFile.left(localeEndPosition).mid(localeStartPosition); return locale; }); + return previousLocales != m_localeStrings; } SwitchLanguageAction::SwitchLanguageAction() diff --git a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.h b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.h index 8a71ee07c29..a23f125ca14 100644 --- a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.h +++ b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.h @@ -113,7 +113,7 @@ signals: protected: QWidget *createWidget(QWidget *parent) override; private: - void refreshProjectLocales(ProjectExplorer::Project *project); + bool updateProjectLocales(ProjectExplorer::Project *project); QStringList m_localeStrings; }; |