diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2022-09-20 16:32:46 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2022-09-21 14:01:23 +0000 |
commit | a527ceff605bb73685ecbe5cedfddf31d8a8be85 (patch) | |
tree | 45f9b217fa234b562177146e98077be7d3e783df | |
parent | a6a7ca36883d87f5b1a140aef7781a551b998c55 (diff) | |
download | qt-creator-a527ceff605bb73685ecbe5cedfddf31d8a8be85.tar.gz |
qmldesigner: make DesignerSettings thread save
Change-Id: I07074b35456533e9729644ef3647803d477bd6f1
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
27 files changed, 107 insertions, 111 deletions
diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp index 719406ea1a..18967a5fe1 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp @@ -109,7 +109,7 @@ void AssetsLibraryModel::toggleExpandAll(bool expand) void AssetsLibraryModel::deleteFiles(const QStringList &filePaths) { - bool askBeforeDelete = DesignerSettings::getValue( + bool askBeforeDelete = QmlDesignerPlugin::settings().value( DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET).toBool(); bool assetDelete = true; @@ -129,7 +129,7 @@ void AssetsLibraryModel::deleteFiles(const QStringList &filePaths) assetDelete = false; if (cb.isChecked()) - DesignerSettings::setValue(DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET, false); + QmlDesignerPlugin::settings().insert(DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET, false); } if (assetDelete) { diff --git a/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp b/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp index 82032b3fc2..a9b52c13b6 100644 --- a/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp +++ b/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp @@ -145,7 +145,7 @@ Utils::CrumblePath *CrumbleBar::crumblePath() bool CrumbleBar::showSaveDialog() { bool canceled = false; - bool alwaysSave = DesignerSettings::getValue(DesignerSettingsKey::ALWAYS_SAVE_IN_CRUMBLEBAR).toBool(); + bool alwaysSave = QmlDesignerPlugin::settings().value(DesignerSettingsKey::ALWAYS_SAVE_IN_CRUMBLEBAR).toBool(); if (alwaysSave) { Core::DocumentManager::saveModifiedDocumentSilently(currentDesignDocument()->editor()->document()); } else { @@ -155,7 +155,7 @@ bool CrumbleBar::showSaveDialog() tr("Always save when leaving subcomponent"), &alwaysSave); - DesignerSettings::setValue(DesignerSettingsKey::ALWAYS_SAVE_IN_CRUMBLEBAR, alwaysSave); + QmlDesignerPlugin::settings().insert(DesignerSettingsKey::ALWAYS_SAVE_IN_CRUMBLEBAR, alwaysSave); } return !canceled; } diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp index ae5eee7590..bed52cc7a7 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionviewwidget.cpp @@ -96,8 +96,6 @@ ConnectionViewWidget::ConnectionViewWidget(QWidget *parent) : for (auto toolButton : buttons) ui->toolBar->addWidget(toolButton); - auto settings = QmlDesignerPlugin::instance()->settings(); - if (!QmlProjectManager::QmlProject::isQtDesignStudio()) ui->tabBar->addTab(tr("Backends", "Title of dynamic properties view")); diff --git a/src/plugins/qmldesigner/components/debugview/debugview.cpp b/src/plugins/qmldesigner/components/debugview/debugview.cpp index c32edec724..2d3b232e51 100644 --- a/src/plugins/qmldesigner/components/debugview/debugview.cpp +++ b/src/plugins/qmldesigner/components/debugview/debugview.cpp @@ -44,13 +44,13 @@ const QString lineBreak = QStringLiteral("<br>"); bool isDebugViewEnabled() { - return QmlDesigner::DesignerSettings::getValue( + return QmlDesigner::QmlDesignerPlugin::settings().value( QmlDesigner::DesignerSettingsKey::ENABLE_DEBUGVIEW).toBool(); } bool isDebugViewShown() { - return QmlDesigner::DesignerSettings::getValue( + return QmlDesigner::QmlDesignerPlugin::settings().value( QmlDesigner::DesignerSettingsKey::SHOW_DEBUGVIEW).toBool(); } diff --git a/src/plugins/qmldesigner/components/debugview/debugviewwidget.cpp b/src/plugins/qmldesigner/components/debugview/debugviewwidget.cpp index e7c2ceac7b..766af4985c 100644 --- a/src/plugins/qmldesigner/components/debugview/debugviewwidget.cpp +++ b/src/plugins/qmldesigner/components/debugview/debugviewwidget.cpp @@ -100,7 +100,7 @@ void DebugViewWidget::setDebugViewEnabled(bool b) void DebugViewWidget::enabledCheckBoxToggled(bool b) { - DesignerSettings::setValue(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, b); + QmlDesignerPlugin::settings().insert(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, b); } } //namespace Internal diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp index b727df8491..5db622eb7b 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp @@ -535,7 +535,7 @@ void Edit3DView::createEdit3DActions() m_particlesRestartAction->action()->setEnabled(particlemode); if (m_seeker) m_seeker->setEnabled(false); - QmlDesigner::DesignerSettings::setValue("particleMode", particlemode); + QmlDesignerPlugin::settings().insert("particleMode", particlemode); setCurrentStateNode(rootModelNode()); resetPuppet(); }; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h index 8e4081176a..76cfdacdce 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h @@ -40,7 +40,7 @@ class Edit3DViewConfig public: static QList<QColor> load(const char key[]) { - QVariant var = DesignerSettings::getValue(key); + QVariant var = QmlDesignerPlugin::settings().value(key); if (!var.isValid()) return {}; @@ -91,7 +91,7 @@ private: static void saveVariant(const QByteArray &key, const QVariant &colorConfig) { - DesignerSettings::setValue(key, colorConfig); + QmlDesignerPlugin::settings().insert(key, colorConfig); } }; diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp index 5beb60a98e..7b9e27c7e1 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp @@ -95,12 +95,12 @@ FormEditorItem* FormEditorScene::itemForQmlItemNode(const QmlItemNode &qmlItemNo double FormEditorScene::canvasWidth() const { - return DesignerSettings::getValue(DesignerSettingsKey::CANVASWIDTH).toDouble(); + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::CANVASWIDTH).toDouble(); } double FormEditorScene::canvasHeight() const { - return DesignerSettings::getValue(DesignerSettingsKey::CANVASHEIGHT).toDouble(); + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::CANVASHEIGHT).toDouble(); } QList<FormEditorItem*> FormEditorScene::itemsForQmlItemNodes(const QList<QmlItemNode> &nodeList) const diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index 42ecfc0679..c3f697d5c6 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -36,6 +36,7 @@ #include "formeditorscene.h" #include "abstractcustomtool.h" +#include <qmldesignerplugin.h> #include <bindingproperty.h> #include <variantproperty.h> #include <designersettings.h> @@ -685,8 +686,8 @@ void FormEditorView::instancesCompleted(const QVector<ModelNode> &completedNodeL void FormEditorView::instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangedHash) { QList<FormEditorItem*> changedItems; - const int rootElementInitWidth = DesignerSettings::getValue(DesignerSettingsKey::ROOT_ELEMENT_INIT_WIDTH).toInt(); - const int rootElementInitHeight = DesignerSettings::getValue(DesignerSettingsKey::ROOT_ELEMENT_INIT_HEIGHT).toInt(); + const int rootElementInitWidth = QmlDesignerPlugin::settings().value(DesignerSettingsKey::ROOT_ELEMENT_INIT_WIDTH).toInt(); + const int rootElementInitHeight = QmlDesignerPlugin::settings().value(DesignerSettingsKey::ROOT_ELEMENT_INIT_HEIGHT).toInt(); QList<ModelNode> informationChangedNodes = Utils::filtered(informationChangedHash.keys(), [](const ModelNode &node) { return QmlItemNode::isValidQmlItemNode(node); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp index 6991c56141..ff52e244ca 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp @@ -479,12 +479,12 @@ ToolBox *FormEditorWidget::toolBox() const double FormEditorWidget::spacing() const { - return DesignerSettings::getValue(DesignerSettingsKey::ITEMSPACING).toDouble(); + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::ITEMSPACING).toDouble(); } double FormEditorWidget::containerPadding() const { - return DesignerSettings::getValue(DesignerSettingsKey::CONTAINERPADDING).toDouble(); + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::CONTAINERPADDING).toDouble(); } void FormEditorWidget::contextHelp(const Core::IContext::HelpCallback &callback) const diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp index e1911036b5..1e4a9d232f 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp @@ -285,7 +285,7 @@ void ItemLibraryWidget::goIntoComponent(const QString &source) void ItemLibraryWidget::delayedUpdateModel() { - static bool disableTimer = DesignerSettings::getValue(DesignerSettingsKey::DISABLE_ITEM_LIBRARY_UPDATE_TIMER).toBool(); + static bool disableTimer = QmlDesignerPlugin::settings().value(DesignerSettingsKey::DISABLE_ITEM_LIBRARY_UPDATE_TIMER).toBool(); if (disableTimer) updateModel(); else diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp index cc3934b628..64f7d05602 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp @@ -158,10 +158,10 @@ void NavigatorView::modelAttached(Model *model) QTimer::singleShot(0, this, [this, treeView]() { m_currentModelInterface->setFilter( - DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool()); + QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool()); m_currentModelInterface->setOrder( - DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool()); + QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool()); // Expand everything to begin with to ensure model node to index cache is populated treeView->expandAll(); @@ -528,7 +528,7 @@ void NavigatorView::rightButtonClicked() return; //Semantics are unclear for multi selection. bool blocked = blockSelectionChangedSignal(true); - bool reverse = DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); + bool reverse = QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); for (const ModelNode &node : selectedModelNodes()) { if (!node.isRootNode() && node.parentProperty().isNodeListProperty() && node.parentProperty().count() > 1) { @@ -568,7 +568,7 @@ void NavigatorView::rightButtonClicked() void NavigatorView::upButtonClicked() { bool blocked = blockSelectionChangedSignal(true); - bool reverse = DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); + bool reverse = QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); if (reverse) moveNodesDown(selectedModelNodes()); @@ -582,7 +582,7 @@ void NavigatorView::upButtonClicked() void NavigatorView::downButtonClicked() { bool blocked = blockSelectionChangedSignal(true); - bool reverse = DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); + bool reverse = QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); if (reverse) moveNodesUp(selectedModelNodes()); @@ -597,14 +597,14 @@ void NavigatorView::filterToggled(bool flag) { m_currentModelInterface->setFilter(flag); treeWidget()->expandAll(); - DesignerSettings::setValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS, flag); + QmlDesignerPlugin::settings().insert(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS, flag); } void NavigatorView::reverseOrderToggled(bool flag) { m_currentModelInterface->setOrder(flag); treeWidget()->expandAll(); - DesignerSettings::setValue(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER, flag); + QmlDesignerPlugin::settings().insert(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER, flag); } void NavigatorView::textFilterChanged(const QString &text) diff --git a/src/plugins/qmldesigner/components/navigator/navigatorwidget.cpp b/src/plugins/qmldesigner/components/navigator/navigatorwidget.cpp index d43f4a1fe6..f3ccd491c8 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatorwidget.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatorwidget.cpp @@ -138,7 +138,7 @@ QList<QToolButton *> NavigatorWidget::createToolBarWidgets() auto filterAction = new QAction(tr("Show Only Visible Components"), nullptr); filterAction->setCheckable(true); - bool filterFlag = DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool(); + bool filterFlag = QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool(); filterAction->setChecked(filterFlag); connect(filterAction, &QAction::toggled, this, &NavigatorWidget::filterToggled); @@ -147,7 +147,7 @@ QList<QToolButton *> NavigatorWidget::createToolBarWidgets() auto reverseAction = new QAction(tr("Reverse Component Order"), nullptr); reverseAction->setCheckable(true); - bool reverseFlag = DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); + bool reverseFlag = QmlDesignerPlugin::settings().value(DesignerSettingsKey::NAVIGATOR_REVERSE_ITEM_ORDER).toBool(); reverseAction->setChecked(reverseFlag); connect(reverseAction, &QAction::toggled, this, &NavigatorWidget::reverseOrderToggled); diff --git a/src/plugins/qmldesigner/components/propertyeditor/colorpalettebackend.h b/src/plugins/qmldesigner/components/propertyeditor/colorpalettebackend.h index 2042b30802..7266f89856 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/colorpalettebackend.h +++ b/src/plugins/qmldesigner/components/propertyeditor/colorpalettebackend.h @@ -35,6 +35,7 @@ #include <QPixmap> #include "designersettings.h" +#include <qmldesignerplugin.h> #include <coreplugin/icore.h> namespace QmlDesigner { @@ -59,7 +60,7 @@ struct Palette bool read() { - QStringList data = QmlDesigner::DesignerSettings::getValue(m_settingsKey).toStringList(); + QStringList data = QmlDesignerPlugin::settings().value(m_settingsKey).toStringList(); if (data.isEmpty()) return false; @@ -71,7 +72,7 @@ struct Palette void write() const { - QmlDesigner::DesignerSettings::setValue(m_settingsKey, m_colors); + QmlDesignerPlugin::settings().insert(m_settingsKey, m_colors); } QByteArray m_settingsKey; diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp index 30375f9fc0..6ed1d88c00 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp @@ -266,7 +266,7 @@ void TextEditorView::reformatFile() // Reformat document if we have a .ui.qml file if (document && document->filePath().toString().endsWith(".ui.qml") - && DesignerSettings::getValue(DesignerSettingsKey::REFORMAT_UI_QML_FILES).toBool()) { + && QmlDesignerPlugin::settings().value(DesignerSettingsKey::REFORMAT_UI_QML_FILES).toBool()) { QmlJS::Document::Ptr currentDocument(document->semanticInfo().document); QmlJS::Snapshot snapshot = QmlJS::ModelManagerInterface::instance()->snapshot(); diff --git a/src/plugins/qmldesigner/designercore/exceptions/exception.cpp b/src/plugins/qmldesigner/designercore/exceptions/exception.cpp index a3a9806f7e..8216117319 100644 --- a/src/plugins/qmldesigner/designercore/exceptions/exception.cpp +++ b/src/plugins/qmldesigner/designercore/exceptions/exception.cpp @@ -91,8 +91,8 @@ bool Exception::shouldAssert() bool Exception::warnAboutException() { #ifndef QMLDESIGNER_TEST - static bool warnException = !QmlDesignerPlugin::instance()->settings().value( - DesignerSettingsKey::ENABLE_MODEL_EXCEPTION_OUTPUT).toBool(); + static bool warnException = !QmlDesignerPlugin::settings().value( + DesignerSettingsKey::ENABLE_MODEL_EXCEPTION_OUTPUT).toBool(); return warnException; #else return true; diff --git a/src/plugins/qmldesigner/designercore/instances/interactiveconnectionmanager.cpp b/src/plugins/qmldesigner/designercore/instances/interactiveconnectionmanager.cpp index dd2f47e555..1c02b5a063 100644 --- a/src/plugins/qmldesigner/designercore/instances/interactiveconnectionmanager.cpp +++ b/src/plugins/qmldesigner/designercore/instances/interactiveconnectionmanager.cpp @@ -50,15 +50,14 @@ void InteractiveConnectionManager::setUp(NodeInstanceServerInterface *nodeInstan { ConnectionManager::setUp(nodeInstanceServer, qrcMappingString, target, view); - DesignerSettings settings = QmlDesignerPlugin::instance()->settings(); - int timeOutTime = settings.value(DesignerSettingsKey::PUPPET_KILL_TIMEOUT).toInt(); + int timeOutTime = QmlDesignerPlugin::settings() + .value(DesignerSettingsKey::PUPPET_KILL_TIMEOUT).toInt(); for (Connection &connection : connections()) { connection.timer.reset(new QTimer); connection.timer->setInterval(timeOutTime); } - if (QmlDesignerPlugin::instance() - ->settings() + if (QmlDesignerPlugin::settings() .value(DesignerSettingsKey::DEBUG_PUPPET) .toString() .isEmpty()) { diff --git a/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp b/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp index f2baf9c984..262811747c 100644 --- a/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp +++ b/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp @@ -149,7 +149,7 @@ bool PuppetCreator::useOnlyFallbackPuppet() const #ifndef QMLDESIGNER_TEST if (!m_target || !m_target->kit()->isValid()) qWarning() << "Invalid kit for QML puppet"; - return m_designerSettings.value(DesignerSettingsKey::USE_DEFAULT_PUPPET).toBool() + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::USE_DEFAULT_PUPPET).toBool() || m_target == nullptr || !m_target->kit()->isValid(); #else return true; @@ -188,9 +188,6 @@ PuppetCreator::PuppetCreator(ProjectExplorer::Target *target, const Model *model : m_target(target) , m_availablePuppetType(FallbackPuppet) , m_model(model) -#ifndef QMLDESIGNER_TEST - , m_designerSettings(QmlDesignerPlugin::instance()->settings()) -#endif { } @@ -232,7 +229,7 @@ QProcessUniquePointer PuppetCreator::puppetProcess( processFinishCallback); #ifndef QMLDESIGNER_TEST - QString forwardOutput = m_designerSettings.value(DesignerSettingsKey:: + QString forwardOutput = QmlDesignerPlugin::settings().value(DesignerSettingsKey:: FORWARD_PUPPET_OUTPUT).toString(); #else QString forwardOutput("all"); @@ -265,7 +262,7 @@ QProcessUniquePointer PuppetCreator::puppetProcess( } #ifndef QMLDESIGNER_TEST - QString debugPuppet = m_designerSettings.value(DesignerSettingsKey:: + QString debugPuppet = QmlDesignerPlugin::settings().value(DesignerSettingsKey:: DEBUG_PUPPET).toString(); #else QString debugPuppet("all"); @@ -415,7 +412,7 @@ QString PuppetCreator::defaultPuppetToplevelBuildDirectory() QString PuppetCreator::qmlPuppetToplevelBuildDirectory() const { #ifndef QMLDESIGNER_TEST - QString puppetToplevelBuildDirectory = m_designerSettings.value( + QString puppetToplevelBuildDirectory = QmlDesignerPlugin::settings().value( DesignerSettingsKey::PUPPET_TOPLEVEL_BUILD_DIRECTORY).toString(); if (puppetToplevelBuildDirectory.isEmpty()) return defaultPuppetToplevelBuildDirectory(); @@ -435,7 +432,7 @@ QString PuppetCreator::qmlPuppetDirectory(PuppetType puppetType) const if (puppetType == BinPathPuppet) return pathForBinPuppet(m_target).toFileInfo().absoluteDir().canonicalPath(); - return qmlPuppetFallbackDirectory(m_designerSettings); + return qmlPuppetFallbackDirectory(QmlDesignerPlugin::settings()); #else return QString(); #endif @@ -503,10 +500,10 @@ QProcessEnvironment PuppetCreator::processEnvironment() const environment.set("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); #ifndef QMLDESIGNER_TEST - const QString controlsStyle = m_designerSettings.value(DesignerSettingsKey:: + const QString controlsStyle = QmlDesignerPlugin::settings().value(DesignerSettingsKey:: CONTROLS_STYLE).toString(); - const bool smoothRendering = m_designerSettings.value(DesignerSettingsKey::SMOOTH_RENDERING) + const bool smoothRendering = QmlDesignerPlugin::settings().value(DesignerSettingsKey::SMOOTH_RENDERING) .toBool(); if (smoothRendering) @@ -553,7 +550,7 @@ QProcessEnvironment PuppetCreator::processEnvironment() const environment.set("QMLDESIGNER_FORCE_QAPPLICATION", "true"); } - bool particlemode = QmlDesigner::DesignerSettings::getValue("particleMode").toBool(); + bool particlemode = QmlDesigner::QmlDesignerPlugin::settings().value("particleMode").toBool(); if (!particlemode) environment.set("QT_QUICK3D_DISABLE_PARTICLE_SYSTEMS", "1"); else diff --git a/src/plugins/qmldesigner/designercore/instances/puppetcreator.h b/src/plugins/qmldesigner/designercore/instances/puppetcreator.h index 341e44c4df..2516c2d27e 100644 --- a/src/plugins/qmldesigner/designercore/instances/puppetcreator.h +++ b/src/plugins/qmldesigner/designercore/instances/puppetcreator.h @@ -108,9 +108,6 @@ private: PuppetType m_availablePuppetType; static QHash<Utils::Id, PuppetType> m_qml2PuppetForKitPuppetHash; const Model *m_model = nullptr; -#ifndef QMLDESIGNER_TEST - const DesignerSettings m_designerSettings; -#endif QString m_qrcMapping; }; diff --git a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp index 64a562c029..e5ea12a058 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp @@ -677,10 +677,10 @@ QString QmlObjectNode::generateTranslatableText(const QString &text) { #ifndef QMLDESIGNER_TEST - if (QmlDesignerPlugin::instance()->settings().value( + if (QmlDesignerPlugin::settings().value( DesignerSettingsKey::TYPE_OF_QSTR_FUNCTION).toInt()) - switch (QmlDesignerPlugin::instance()->settings().value( + switch (QmlDesignerPlugin::settings().value( DesignerSettingsKey::TYPE_OF_QSTR_FUNCTION).toInt()) { case 0: return QString(QStringLiteral("qsTr(\"%1\")")).arg(text); case 1: return QString(QStringLiteral("qsTrId(\"%1\")")).arg(text); diff --git a/src/plugins/qmldesigner/designersettings.cpp b/src/plugins/qmldesigner/designersettings.cpp index 8841267385..dacadf7404 100644 --- a/src/plugins/qmldesigner/designersettings.cpp +++ b/src/plugins/qmldesigner/designersettings.cpp @@ -25,8 +25,6 @@ #include "designersettings.h" -#include <qmldesignerplugin.h> - #include <QSettings> namespace QmlDesigner { @@ -36,11 +34,35 @@ namespace DesignerSettingsGroupKey { const char QML_DESIGNER_SETTINGS_GROUP[] = "Designer"; } -DesignerSettings::DesignerSettings() = default; +DesignerSettings::DesignerSettings(QSettings *settings) : + m_settings(settings) +{ + fromSettings(settings); +} + +void DesignerSettings::insert(const QByteArray &key, const QVariant &value) +{ + QMutexLocker locker(&m_mutex); + m_cache.insert(key, value); + toSettings(m_settings); +} + +void DesignerSettings::insert(const QHash<QByteArray, QVariant> &settingsHash) +{ + QMutexLocker locker(&m_mutex); + m_cache.insert(settingsHash); + toSettings(m_settings); +} + +QVariant DesignerSettings::value(const QByteArray &key, const QVariant &defaultValue) const +{ + QMutexLocker locker(&m_mutex); + return m_cache.value(key); +} void DesignerSettings::restoreValue(QSettings *settings, const QByteArray &key, const QVariant &defaultValue) { - insert(key, settings->value(QString::fromLatin1(key), defaultValue)); + m_cache.insert(key, settings->value(QString::fromLatin1(key), defaultValue)); } void DesignerSettings::fromSettings(QSettings *settings) @@ -80,8 +102,8 @@ void DesignerSettings::fromSettings(QSettings *settings) restoreValue(settings, DesignerSettingsKey::ALWAYS_DESIGN_MODE, true); restoreValue(settings, DesignerSettingsKey::DISABLE_ITEM_LIBRARY_UPDATE_TIMER, false); restoreValue(settings, DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET, true); - const QStringList defaultValue = QStringList() << "#222222" << "#999999"; - restoreValue(settings, DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, defaultValue); + restoreValue(settings, DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, + QStringList{"#222222", "#999999"}); restoreValue(settings, DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, "#aaaaaa"); restoreValue(settings, DesignerSettingsKey::SMOOTH_RENDERING, false); restoreValue(settings, DesignerSettingsKey::SHOW_DEBUG_SETTINGS, false); @@ -103,8 +125,8 @@ void DesignerSettings::toSettings(QSettings *settings) const settings->beginGroup(QLatin1String(DesignerSettingsGroupKey::QML_SETTINGS_GROUP)); settings->beginGroup(QLatin1String(DesignerSettingsGroupKey::QML_DESIGNER_SETTINGS_GROUP)); - QHash<QByteArray, QVariant>::const_iterator i = constBegin(); - while (i != constEnd()) { + QHash<QByteArray, QVariant>::const_iterator i = m_cache.constBegin(); + while (i != m_cache.constEnd()) { storeValue(settings, i.key(), i.value()); ++i; } @@ -113,17 +135,4 @@ void DesignerSettings::toSettings(QSettings *settings) const settings->endGroup(); } -QVariant DesignerSettings::getValue(const QByteArray &key) -{ - DesignerSettings settings = QmlDesignerPlugin::instance()->settings(); - return settings.value(key); -} - -void DesignerSettings::setValue(const QByteArray &key, const QVariant &value) -{ - DesignerSettings settings = QmlDesignerPlugin::instance()->settings(); - settings.insert(key, value); - QmlDesignerPlugin::instance()->setSettings(settings); -} - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designersettings.h b/src/plugins/qmldesigner/designersettings.h index 851a5e8ef2..c3d014cc34 100644 --- a/src/plugins/qmldesigner/designersettings.h +++ b/src/plugins/qmldesigner/designersettings.h @@ -30,6 +30,7 @@ #include <QHash> #include <QVariant> #include <QByteArray> +#include <QMutex> QT_BEGIN_NAMESPACE class QSettings; @@ -77,19 +78,25 @@ const char SMOOTH_RENDERING[] = "SmoothRendering"; const char OLD_STATES_EDITOR[] = "OldStatesEditor"; } -class QMLDESIGNERCORE_EXPORT DesignerSettings : public QHash<QByteArray, QVariant> +class QMLDESIGNERCORE_EXPORT DesignerSettings { public: - DesignerSettings(); + DesignerSettings(QSettings *settings); + void insert(const QByteArray &key, const QVariant &value); + void insert(const QHash<QByteArray, QVariant> &settingsHash); + QVariant value(const QByteArray &key, const QVariant &defaultValue = {}) const; + +private: void fromSettings(QSettings *); void toSettings(QSettings *) const; - static QVariant getValue(const QByteArray &key); - static void setValue(const QByteArray &key, const QVariant &value); -private: void restoreValue(QSettings *settings, const QByteArray &key, const QVariant &defaultValue = QVariant()); void storeValue(QSettings *settings, const QByteArray &key, const QVariant &value) const; + + QSettings *m_settings; + QHash<QByteArray, QVariant> m_cache; + mutable QMutex m_mutex; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/documentwarningwidget.cpp b/src/plugins/qmldesigner/documentwarningwidget.cpp index e691912fb9..cfa512e30d 100644 --- a/src/plugins/qmldesigner/documentwarningwidget.cpp +++ b/src/plugins/qmldesigner/documentwarningwidget.cpp @@ -200,12 +200,12 @@ void DocumentWarningWidget::emitGotoCodeClicked(const DocumentMessage &message) bool DocumentWarningWidget::warningsEnabled() const { - return DesignerSettings::getValue(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER).toBool(); + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER).toBool(); } void DocumentWarningWidget::ignoreCheckBoxToggled(bool b) { - DesignerSettings::setValue(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, !b); + QmlDesignerPlugin::settings().value(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, !b); } void DocumentWarningWidget::setErrors(const QList<DocumentMessage> &errors) diff --git a/src/plugins/qmldesigner/openuiqmlfiledialog.cpp b/src/plugins/qmldesigner/openuiqmlfiledialog.cpp index 8bd5a0e17c..8fa4648a74 100644 --- a/src/plugins/qmldesigner/openuiqmlfiledialog.cpp +++ b/src/plugins/qmldesigner/openuiqmlfiledialog.cpp @@ -55,9 +55,8 @@ OpenUiQmlFileDialog::OpenUiQmlFileDialog(QWidget *parent) : close(); }); connect(ui->checkBox, &QCheckBox::toggled, this, [](bool b){ - DesignerSettings settings = QmlDesignerPlugin::instance()->settings(); - settings.insert(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES, !b); - QmlDesignerPlugin::instance()->setSettings(settings); + QmlDesignerPlugin::settings().insert( + DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES, !b); }); } diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index 4890205f42..6226e54e80 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -124,7 +124,7 @@ QtQuickDesignerFactory::QtQuickDesignerFactory() setDocumentCreator([this]() { auto document = new QmlJSEditor::QmlJSEditorDocument(id()); document->setIsDesignModePreferred( - QmlDesigner::DesignerSettings::getValue( + QmlDesigner::QmlDesignerPlugin::settings().value( QmlDesigner::DesignerSettingsKey::ALWAYS_DESIGN_MODE).toBool()); return document; }); @@ -135,6 +135,7 @@ QtQuickDesignerFactory::QtQuickDesignerFactory() class QmlDesignerPluginPrivate { public: + DesignerSettings settings{Core::ICore::instance()->settings()}; QmlDesignerProjectManager projectManager; ViewManager viewManager{projectManager.asynchronousImageCache(), projectManager.asynchronousMeshImageCache()}; @@ -142,7 +143,6 @@ public: ShortCutManager shortCutManager; SettingsPage settingsPage; DesignModeWidget mainWidget; - DesignerSettings settings; QtQuickDesignerFactory m_qtQuickDesignerFactory; bool blockEditorChange = false; }; @@ -196,7 +196,7 @@ static bool shouldAssertInException() static bool warningsForQmlFilesInsteadOfUiQmlEnabled() { - return DesignerSettings::getValue(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES).toBool(); + return QmlDesignerPlugin::settings().value(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES).toBool(); } QmlDesignerPlugin::QmlDesignerPlugin() @@ -297,8 +297,6 @@ bool QmlDesignerPlugin::delayedInitialize() }); MetaInfo::setPluginPaths(pluginPaths); - d->settings.fromSettings(Core::ICore::settings()); - d->viewManager.registerView(std::make_unique<QmlDesigner::Internal::ConnectionView>()); auto timelineView = d->viewManager.registerView(std::make_unique<QmlDesigner::TimelineView>()); @@ -645,7 +643,7 @@ void QmlDesignerPlugin::emitCurrentTextEditorChanged(Core::IEditor *editor) double QmlDesignerPlugin::formEditorDevicePixelRatio() { - if (DesignerSettings::getValue(DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO).toBool()) + if (QmlDesignerPlugin::settings().value(DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO).toBool()) return 1; const QList<QWindow *> topLevelWindows = QApplication::topLevelWindows(); @@ -753,18 +751,9 @@ const DesignerActionManager &QmlDesignerPlugin::designerActionManager() const return d->viewManager.designerActionManager(); } -DesignerSettings QmlDesignerPlugin::settings() +DesignerSettings& QmlDesignerPlugin::settings() { - d->settings.fromSettings(Core::ICore::settings()); - return d->settings; -} - -void QmlDesignerPlugin::setSettings(const DesignerSettings &s) -{ - if (s != d->settings) { - d->settings = s; - d->settings.toSettings(Core::ICore::settings()); - } + return instance()->d->settings; } } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/qmldesignerplugin.h b/src/plugins/qmldesigner/qmldesignerplugin.h index 7670d4f1ea..976b9d57c0 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.h +++ b/src/plugins/qmldesigner/qmldesignerplugin.h @@ -75,8 +75,7 @@ public: DesignerActionManager &designerActionManager(); const DesignerActionManager &designerActionManager() const; - DesignerSettings settings(); - void setSettings(const DesignerSettings &s); + static DesignerSettings& settings(); DesignDocument *currentDesignDocument() const; Internal::DesignModeWidget *mainWidget() const; diff --git a/src/plugins/qmldesigner/settingspage.cpp b/src/plugins/qmldesigner/settingspage.cpp index 700402680a..7c1530fedb 100644 --- a/src/plugins/qmldesigner/settingspage.cpp +++ b/src/plugins/qmldesigner/settingspage.cpp @@ -63,7 +63,7 @@ public: void apply() final; - DesignerSettings settings() const; + QHash<QByteArray, QVariant> newSettings() const; void setSettings(const DesignerSettings &settings); private: @@ -108,9 +108,9 @@ SettingsPageWidget::SettingsPageWidget() setSettings(QmlDesignerPlugin::instance()->settings()); } -DesignerSettings SettingsPageWidget::settings() const +QHash<QByteArray, QVariant> SettingsPageWidget::newSettings() const { - DesignerSettings settings = QmlDesignerPlugin::instance()->settings(); + QHash<QByteArray, QVariant> settings; settings.insert(DesignerSettingsKey::ITEMSPACING, m_ui.spinItemSpacing->value()); settings.insert(DesignerSettingsKey::CONTAINERPADDING, m_ui.spinSnapMargin->value()); settings.insert(DesignerSettingsKey::CANVASWIDTH, m_ui.spinCanvasWidth->value()); @@ -154,7 +154,8 @@ DesignerSettings SettingsPageWidget::settings() const m_ui.fallbackPuppetPathLineEdit->lineEdit()->placeholderText()); if (newFallbackPuppetPath.isEmpty()) newFallbackPuppetPath = m_ui.fallbackPuppetPathLineEdit->lineEdit()->placeholderText(); - QString oldFallbackPuppetPath = PuppetCreator::qmlPuppetFallbackDirectory(settings); + + QString oldFallbackPuppetPath = PuppetCreator::qmlPuppetFallbackDirectory(QmlDesignerPlugin::settings()); if (oldFallbackPuppetPath != newFallbackPuppetPath && QFileInfo::exists(newFallbackPuppetPath)) { if (newFallbackPuppetPath == PuppetCreator::defaultPuppetFallbackDirectory()) @@ -270,8 +271,7 @@ void SettingsPageWidget::setSettings(const DesignerSettings &settings) void SettingsPageWidget::apply() { - DesignerSettings currentSettings(QmlDesignerPlugin::instance()->settings()); - DesignerSettings newSettings = settings(); + auto settings = newSettings(); const auto restartNecessaryKeys = { DesignerSettingsKey::PUPPET_DEFAULT_DIRECTORY, @@ -285,7 +285,7 @@ void SettingsPageWidget::apply() }; for (const char * const key : restartNecessaryKeys) { - if (currentSettings.value(key) != newSettings.value(key)) { + if (QmlDesignerPlugin::settings().value(key) != settings.value(key)) { QMessageBox::information(Core::ICore::dialogParent(), tr("Restart Required"), tr("The made changes will take effect after a " "restart of the QML Emulation layer or %1.") @@ -294,7 +294,7 @@ void SettingsPageWidget::apply() } } - QmlDesignerPlugin::instance()->setSettings(newSettings); + QmlDesignerPlugin::settings().insert(settings); } SettingsPage::SettingsPage() |