aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/qmlpreviewplugin
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2020-06-15 22:20:51 +0200
committerTim Jenssen <tim.jenssen@qt.io>2020-06-18 12:37:53 +0000
commit2ed7a7963e16021dd6ce1e8e83f676cf2d751570 (patch)
tree3e8bc98eabda4820ee59f6a958cd98a5ba2e6e97 /src/plugins/qmldesigner/qmlpreviewplugin
parentdd8709e5546211976a97aa561d6c97cea4d233bb (diff)
qmldesigner: block local changes while initialization
- emit after the initialization - emit only if found languages are differrent Change-Id: I4f426b7bf055ef1d97e5db86bba075a032210303 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/qmlpreviewplugin')
-rw-r--r--src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp37
-rw-r--r--src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.h2
2 files changed, 22 insertions, 17 deletions
diff --git a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp
index 32d524f6909..c0da2f8b8c6 100644
--- a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp
+++ b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp
@@ -217,42 +217,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");
@@ -263,6 +267,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;
};