diff options
author | Marco Bubke <marco.bubke@qt.io> | 2023-04-18 13:38:07 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2023-04-19 16:00:36 +0000 |
commit | 66288ef1138e04161819c77f8186a69e82f29469 (patch) | |
tree | 48990f9be521292d66e4e0c69803a33624396a44 | |
parent | 34c69766dd0948bf7c15b4b9534cc21d073afd31 (diff) |
QmlDesigner: Cleanup QmlDesignerBasePlugin
Please don't put unrelated code into a plugin source file. It gets
really cluttered. Use UniqueObjectPtr if the QObject has a parent.
Change-Id: I6535163be1f67528a0cf66bf050f48601e3fa09c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
14 files changed, 369 insertions, 284 deletions
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp index 0d74be596f5..5cf88ab6fcd 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexturesmodel.cpp @@ -4,8 +4,8 @@ #include "contentlibrarytexturesmodel.h" #include "contentlibrarytexturescategory.h" -#include "qmldesignerplugin.h" +#include <designerpaths.h> #include <qmldesignerbase/qmldesignerbaseplugin.h> #include <utils/algorithm.h> @@ -119,8 +119,10 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &remoteUrl, co for (const QFileInfo &tex : texFiles) { QString fullRemoteUrl = QString("%1/%2/%3.zip").arg(remoteUrl, dir.fileName(), tex.baseName()); - QString localDownloadPath = QString("%1/%2/%3").arg(QmlDesignerBasePlugin::bundlesPathSetting(), - m_category, dir.fileName()); + QString localDownloadPath = QString("%1/%2/%3") + .arg(Paths::bundlesPathSetting(), + m_category, + dir.fileName()); QString key = QString("%1/%2/%3").arg(m_category, dir.fileName(), tex.baseName()); QString fileExt; QSize dimensions; diff --git a/src/plugins/qmldesigner/qmldesignerplugin.h b/src/plugins/qmldesigner/qmldesignerplugin.h index 78bf02ac042..6251317bc42 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.h +++ b/src/plugins/qmldesigner/qmldesignerplugin.h @@ -114,7 +114,6 @@ private: // variables QmlDesignerPluginPrivate *d = nullptr; static QmlDesignerPlugin *m_instance; QElapsedTimer m_usageTimer; - StudioConfigSettingsPage m_settingsPage; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesignerbase/CMakeLists.txt b/src/plugins/qmldesignerbase/CMakeLists.txt index f02c4861067..628403874c0 100644 --- a/src/plugins/qmldesignerbase/CMakeLists.txt +++ b/src/plugins/qmldesignerbase/CMakeLists.txt @@ -20,8 +20,16 @@ extend_qtc_plugin(QmlDesignerBase PUBLIC_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/utils SOURCES_PREFIX ${CMAKE_CURRENT_LIST_DIR}/utils SOURCES + designerpaths.cpp designerpaths.h designersettings.cpp designersettings.h qmlpuppetpaths.cpp qmlpuppetpaths.h +) + +extend_qtc_plugin(QmlDesignerBase + PUBLIC_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/studio + SOURCES_PREFIX ${CMAKE_CURRENT_LIST_DIR}/studio + SOURCES studiostyle.cpp studiostyle.h studioquickwidget.cpp studioquickwidget.h + studiosettingspage.cpp studiosettingspage.h ) diff --git a/src/plugins/qmldesignerbase/qmldesignerbaseplugin.cpp b/src/plugins/qmldesignerbase/qmldesignerbaseplugin.cpp index db2ff7b7ca9..2a2759c3007 100644 --- a/src/plugins/qmldesignerbase/qmldesignerbaseplugin.cpp +++ b/src/plugins/qmldesignerbase/qmldesignerbaseplugin.cpp @@ -3,41 +3,25 @@ #include "qmldesignerbaseplugin.h" +#include "studiosettingspage.h" + +#include "studio/studiostyle.h" #include "utils/designersettings.h" -#include "utils/hostosinfo.h" -#include "utils/studiostyle.h" -#include "utils/theme/theme.h" -#include <coreplugin/coreconstants.h> -#include <coreplugin/dialogs/restartdialog.h> #include <coreplugin/icore.h> -#include <projectexplorer/projectexplorer.h> -#include <projectexplorer/projectexplorerconstants.h> -#include <utils/hostosinfo.h> +#include <utils/uniqueobjectptr.h> #include <QApplication> -#include <QCheckBox> -#include <QGroupBox> -#include <QHBoxLayout> -#include <QLabel> -#include <QPushButton> -#include <QSpacerItem> -#include <QStandardPaths> -#include <QStyle> -#include <QStyleFactory> -#include <QVBoxLayout> -using Utils::HostOsInfo; namespace QmlDesigner { -const char EXAMPLES_DOWNLOAD_PATH[] = "StudioConfig/ExamplesDownloadPath"; -const char BUNDLES_DOWNLOAD_PATH[] = "StudioConfig/BundlesDownloadPath"; class QmlDesignerBasePlugin::Data { public: DesignerSettings settings; - QScopedPointer<StudioStyle> style; + Utils::UniqueObjectPtr<StudioStyle> style; + StudioConfigSettingsPage studioConfigSettingsPage; Data() : settings(Core::ICore::settings()) @@ -53,11 +37,6 @@ QmlDesignerBasePlugin::QmlDesignerBasePlugin() global = this; }; -QmlDesignerBasePlugin *QmlDesignerBasePlugin::instance() -{ - return global; -}; - QmlDesignerBasePlugin::~QmlDesignerBasePlugin() = default; DesignerSettings &QmlDesignerBasePlugin::settings() @@ -67,225 +46,22 @@ DesignerSettings &QmlDesignerBasePlugin::settings() QStyle *QmlDesignerBasePlugin::style() { - if (global->d->style.isNull()) - global->d->style.reset(new StudioStyle(qApp->style())); - - return global->d->style.data(); -} - -bool QmlDesignerBasePlugin::initialize(const QStringList &, QString *) -{ - d = std::make_unique<Data>(); - - return true; -} - -Utils::FilePath QmlDesignerBasePlugin::defaultExamplesPath() -{ - QStandardPaths::StandardLocation location = Utils::HostOsInfo::isMacHost() - ? QStandardPaths::HomeLocation - : QStandardPaths::DocumentsLocation; - - return Utils::FilePath::fromString(QStandardPaths::writableLocation(location)) - .pathAppended("QtDesignStudio/examples"); -} - -Utils::FilePath QmlDesignerBasePlugin::defaultBundlesPath() -{ - QStandardPaths::StandardLocation location = Utils::HostOsInfo::isMacHost() - ? QStandardPaths::HomeLocation - : QStandardPaths::DocumentsLocation; - - return Utils::FilePath::fromString(QStandardPaths::writableLocation(location)) - .pathAppended("QtDesignStudio/bundles"); -} - -QString QmlDesignerBasePlugin::examplesPathSetting() -{ - return Core::ICore::settings() - ->value(EXAMPLES_DOWNLOAD_PATH, defaultExamplesPath().toString()) - .toString(); -} - -QString QmlDesignerBasePlugin::bundlesPathSetting() -{ - return Core::ICore::settings() - ->value(BUNDLES_DOWNLOAD_PATH, defaultBundlesPath().toString()) - .toString(); -} - -static bool hideBuildMenuSetting() -{ - return Core::ICore::settings() - ->value(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_BUILD, false) - .toBool(); -} - -static bool hideDebugMenuSetting() -{ - return Core::ICore::settings() - ->value(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_DEBUG, false) - .toBool(); -} - -static bool hideAnalyzeMenuSetting() -{ - return Core::ICore::settings() - ->value(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_ANALYZE, false) - .toBool(); -} - -static bool hideToolsMenuSetting() -{ - return Core::ICore::settings()->value(Core::Constants::SETTINGS_MENU_HIDE_TOOLS, false).toBool(); -} + if (!global->d->style) + global->d->style = Utils::makeUniqueObjectPtr<StudioStyle>(QApplication::style()); -void setSettingIfDifferent(const QString &key, bool value, bool &dirty) -{ - QSettings *s = Core::ICore::settings(); - if (s->value(key, false).toBool() != value) { - dirty = true; - s->setValue(key, value); - } + return global->d->style.get(); } -StudioSettingsPage::StudioSettingsPage() - : m_buildCheckBox(new QCheckBox(tr("Build"))) - , m_debugCheckBox(new QCheckBox(tr("Debug"))) - , m_analyzeCheckBox(new QCheckBox(tr("Analyze"))) - , m_toolsCheckBox(new QCheckBox(tr("Tools"))) - , m_pathChooserExamples(new Utils::PathChooser()) - , m_pathChooserBundles(new Utils::PathChooser()) +StudioConfigSettingsPage *QmlDesignerBasePlugin::studioConfigSettingsPage() { - const QString toolTip = tr( - "Hide top-level menus with advanced functionality to simplify the UI. <b>Build</b> is " - "generally not required in the context of Qt Design Studio. <b>Debug</b> and " - "<b>Analyze</b> " - "are only required for debugging and profiling. <b>Tools</b> can be useful for bookmarks " - "and git integration."); - - QVBoxLayout *boxLayout = new QVBoxLayout(); - setLayout(boxLayout); - auto groupBox = new QGroupBox(tr("Hide Menu")); - groupBox->setToolTip(toolTip); - boxLayout->addWidget(groupBox); - - auto verticalLayout = new QVBoxLayout(); - groupBox->setLayout(verticalLayout); - - m_buildCheckBox->setToolTip(toolTip); - m_debugCheckBox->setToolTip(toolTip); - m_analyzeCheckBox->setToolTip(toolTip); - m_toolsCheckBox->setToolTip(toolTip); - - verticalLayout->addWidget(m_buildCheckBox); - verticalLayout->addWidget(m_debugCheckBox); - verticalLayout->addWidget(m_analyzeCheckBox); - verticalLayout->addWidget(m_toolsCheckBox); - - verticalLayout->addSpacerItem( - new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum)); - - m_buildCheckBox->setChecked(hideBuildMenuSetting()); - m_debugCheckBox->setChecked(hideDebugMenuSetting()); - m_analyzeCheckBox->setChecked(hideAnalyzeMenuSetting()); - m_toolsCheckBox->setChecked(hideToolsMenuSetting()); - - // Examples path setting - auto examplesGroupBox = new QGroupBox(tr("Examples")); - boxLayout->addWidget(examplesGroupBox); - - auto examplesLayout = new QHBoxLayout(this); - examplesGroupBox->setLayout(examplesLayout); - - auto examplesLabel = new QLabel(tr("Examples path:")); - m_pathChooserExamples->setFilePath( - Utils::FilePath::fromString(QmlDesignerBasePlugin::examplesPathSetting())); - auto examplesResetButton = new QPushButton(tr("Reset Path")); - - connect(examplesResetButton, &QPushButton::clicked, this, [this]() { - m_pathChooserExamples->setFilePath(QmlDesignerBasePlugin::defaultExamplesPath()); - }); - - examplesLayout->addWidget(examplesLabel); - examplesLayout->addWidget(m_pathChooserExamples); - examplesLayout->addWidget(examplesResetButton); - - // Bundles path setting - auto bundlesGroupBox = new QGroupBox(tr("Bundles")); - boxLayout->addWidget(bundlesGroupBox); - - auto bundlesLayout = new QHBoxLayout(this); - bundlesGroupBox->setLayout(bundlesLayout); - - QLabel *bundlesLabel = new QLabel(tr("Bundles path:")); - m_pathChooserBundles->setFilePath( - Utils::FilePath::fromString(QmlDesignerBasePlugin::bundlesPathSetting())); - QPushButton *bundlesResetButton = new QPushButton(tr("Reset Path")); - - connect(bundlesResetButton, &QPushButton::clicked, this, [this]() { - m_pathChooserBundles->setFilePath(QmlDesignerBasePlugin::defaultBundlesPath()); - }); - - bundlesLayout->addWidget(bundlesLabel); - bundlesLayout->addWidget(m_pathChooserBundles); - bundlesLayout->addWidget(bundlesResetButton); - - boxLayout->addSpacerItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding)); + return &global->d->studioConfigSettingsPage; } -void StudioSettingsPage::apply() +bool QmlDesignerBasePlugin::initialize(const QStringList &, QString *) { - bool dirty = false; - - setSettingIfDifferent(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_BUILD, - m_buildCheckBox->isChecked(), - dirty); - - setSettingIfDifferent(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_DEBUG, - m_debugCheckBox->isChecked(), - dirty); - - setSettingIfDifferent(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_ANALYZE, - m_analyzeCheckBox->isChecked(), - dirty); - - setSettingIfDifferent(Core::Constants::SETTINGS_MENU_HIDE_TOOLS, - m_toolsCheckBox->isChecked(), - dirty); - - if (dirty) { - const QString restartText = tr("The menu visibility change will take effect after restart."); - Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText); - restartDialog.exec(); - } - - QSettings *s = Core::ICore::settings(); - const QString value = m_pathChooserExamples->filePath().toString(); - - if (s->value(EXAMPLES_DOWNLOAD_PATH, false).toString() != value) { - s->setValue(EXAMPLES_DOWNLOAD_PATH, value); - emit global->examplesDownloadPathChanged(value); - } - - const QString bundlesPath = m_pathChooserBundles->filePath().toString(); - - if (s->value(BUNDLES_DOWNLOAD_PATH).toString() != bundlesPath) { - s->setValue(BUNDLES_DOWNLOAD_PATH, bundlesPath); - emit global->bundlesDownloadPathChanged(bundlesPath); - - const QString restartText = tr("Changing bundle path will take effect after restart."); - Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText); - restartDialog.exec(); - } -} + d = std::make_unique<Data>(); -StudioConfigSettingsPage::StudioConfigSettingsPage() -{ - setId("Z.StudioConfig.Settings"); - setDisplayName(tr("Qt Design Studio Configuration")); - setCategory(Core::Constants::SETTINGS_CATEGORY_CORE); - setWidgetCreator([] { return new StudioSettingsPage; }); + return true; } } // namespace QmlDesigner diff --git a/src/plugins/qmldesignerbase/qmldesignerbaseplugin.h b/src/plugins/qmldesignerbase/qmldesignerbaseplugin.h index 92e5ffc71bc..1418a6421b5 100644 --- a/src/plugins/qmldesignerbase/qmldesignerbaseplugin.h +++ b/src/plugins/qmldesignerbase/qmldesignerbaseplugin.h @@ -5,41 +5,16 @@ #include "qmldesignerbase_global.h" -#include <coreplugin/dialogs/ioptionspage.h> #include <extensionsystem/iplugin.h> -#include <utils/pathchooser.h> #include <memory> -QT_FORWARD_DECLARE_CLASS(QCheckBox) +QT_BEGIN_NAMESPACE +class QStyle; +QT_END_NAMESPACE namespace QmlDesigner { -class StudioSettingsPage : public Core::IOptionsPageWidget -{ - Q_OBJECT - -public: - void apply() final; - - StudioSettingsPage(); - -private: - QCheckBox *m_buildCheckBox; - QCheckBox *m_debugCheckBox; - QCheckBox *m_analyzeCheckBox; - QCheckBox *m_toolsCheckBox; - Utils::PathChooser *m_pathChooserExamples; - Utils::PathChooser *m_pathChooserBundles; -}; - -class QMLDESIGNERBASE_EXPORT StudioConfigSettingsPage : public Core::IOptionsPage -{ - Q_OBJECT - -public: - StudioConfigSettingsPage(); -}; class QMLDESIGNERBASE_EXPORT QmlDesignerBasePlugin final : public ExtensionSystem::IPlugin { @@ -50,19 +25,9 @@ public: QmlDesignerBasePlugin(); ~QmlDesignerBasePlugin(); - static QmlDesignerBasePlugin *instance(); - - static Utils::FilePath defaultExamplesPath(); - static Utils::FilePath defaultBundlesPath(); - static QString examplesPathSetting(); - static QString bundlesPathSetting(); - static class DesignerSettings &settings(); static QStyle *style(); - -signals: - void examplesDownloadPathChanged(const QString &path); - void bundlesDownloadPathChanged(const QString &path); + static class StudioConfigSettingsPage *studioConfigSettingsPage(); private: bool initialize(const QStringList &arguments, QString *errorMessage) override; diff --git a/src/plugins/qmldesignerbase/utils/studioquickwidget.cpp b/src/plugins/qmldesignerbase/studio/studioquickwidget.cpp index 2cfe5aa9741..2cfe5aa9741 100644 --- a/src/plugins/qmldesignerbase/utils/studioquickwidget.cpp +++ b/src/plugins/qmldesignerbase/studio/studioquickwidget.cpp diff --git a/src/plugins/qmldesignerbase/utils/studioquickwidget.h b/src/plugins/qmldesignerbase/studio/studioquickwidget.h index ef64fb6a69d..ef64fb6a69d 100644 --- a/src/plugins/qmldesignerbase/utils/studioquickwidget.h +++ b/src/plugins/qmldesignerbase/studio/studioquickwidget.h diff --git a/src/plugins/qmldesignerbase/studio/studiosettingspage.cpp b/src/plugins/qmldesignerbase/studio/studiosettingspage.cpp new file mode 100644 index 00000000000..affe25e7da2 --- /dev/null +++ b/src/plugins/qmldesignerbase/studio/studiosettingspage.cpp @@ -0,0 +1,217 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#include "studiosettingspage.h" + +#include "../utils/designerpaths.h" + +#include <coreplugin/coreconstants.h> +#include <coreplugin/dialogs/restartdialog.h> +#include <coreplugin/icore.h> +#include <projectexplorer/projectexplorer.h> +#include <projectexplorer/projectexplorerconstants.h> +#include <utils/theme/theme.h> + +#include <QApplication> +#include <QCheckBox> +#include <QGroupBox> +#include <QHBoxLayout> +#include <QLabel> +#include <QPushButton> +#include <QSpacerItem> +#include <QStyle> +#include <QStyleFactory> +#include <QVBoxLayout> + +namespace QmlDesigner { + +namespace { + +bool hideBuildMenuSetting() +{ + return Core::ICore::settings() + ->value(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_BUILD, false) + .toBool(); +} + +bool hideDebugMenuSetting() +{ + return Core::ICore::settings() + ->value(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_DEBUG, false) + .toBool(); +} + +bool hideAnalyzeMenuSetting() +{ + return Core::ICore::settings() + ->value(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_ANALYZE, false) + .toBool(); +} + +bool hideToolsMenuSetting() +{ + return Core::ICore::settings()->value(Core::Constants::SETTINGS_MENU_HIDE_TOOLS, false).toBool(); +} + +void setSettingIfDifferent(const QString &key, bool value, bool &dirty) +{ + QSettings *s = Core::ICore::settings(); + if (s->value(key, false).toBool() != value) { + dirty = true; + s->setValue(key, value); + } +} + +} // namespace + +StudioSettingsPage::StudioSettingsPage() + : m_buildCheckBox(new QCheckBox(tr("Build"))) + , m_debugCheckBox(new QCheckBox(tr("Debug"))) + , m_analyzeCheckBox(new QCheckBox(tr("Analyze"))) + , m_toolsCheckBox(new QCheckBox(tr("Tools"))) + , m_pathChooserExamples(new Utils::PathChooser()) + , m_pathChooserBundles(new Utils::PathChooser()) +{ + const QString toolTip = tr( + "Hide top-level menus with advanced functionality to simplify the UI. <b>Build</b> is " + "generally not required in the context of Qt Design Studio. <b>Debug</b> and " + "<b>Analyze</b> " + "are only required for debugging and profiling. <b>Tools</b> can be useful for bookmarks " + "and git integration."); + + QVBoxLayout *boxLayout = new QVBoxLayout(); + setLayout(boxLayout); + auto groupBox = new QGroupBox(tr("Hide Menu")); + groupBox->setToolTip(toolTip); + boxLayout->addWidget(groupBox); + + auto verticalLayout = new QVBoxLayout(); + groupBox->setLayout(verticalLayout); + + m_buildCheckBox->setToolTip(toolTip); + m_debugCheckBox->setToolTip(toolTip); + m_analyzeCheckBox->setToolTip(toolTip); + m_toolsCheckBox->setToolTip(toolTip); + + verticalLayout->addWidget(m_buildCheckBox); + verticalLayout->addWidget(m_debugCheckBox); + verticalLayout->addWidget(m_analyzeCheckBox); + verticalLayout->addWidget(m_toolsCheckBox); + + verticalLayout->addSpacerItem( + new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum)); + + m_buildCheckBox->setChecked(hideBuildMenuSetting()); + m_debugCheckBox->setChecked(hideDebugMenuSetting()); + m_analyzeCheckBox->setChecked(hideAnalyzeMenuSetting()); + m_toolsCheckBox->setChecked(hideToolsMenuSetting()); + + // Examples path setting + auto examplesGroupBox = new QGroupBox(tr("Examples")); + boxLayout->addWidget(examplesGroupBox); + + auto examplesLayout = new QHBoxLayout(this); + examplesGroupBox->setLayout(examplesLayout); + + auto examplesLabel = new QLabel(tr("Examples path:")); + m_pathChooserExamples->setFilePath(Utils::FilePath::fromString(Paths::examplesPathSetting())); + auto examplesResetButton = new QPushButton(tr("Reset Path")); + + connect(examplesResetButton, &QPushButton::clicked, this, [this]() { + m_pathChooserExamples->setFilePath(Paths::defaultExamplesPath()); + }); + + examplesLayout->addWidget(examplesLabel); + examplesLayout->addWidget(m_pathChooserExamples); + examplesLayout->addWidget(examplesResetButton); + + // Bundles path setting + auto bundlesGroupBox = new QGroupBox(tr("Bundles")); + boxLayout->addWidget(bundlesGroupBox); + + auto bundlesLayout = new QHBoxLayout(this); + bundlesGroupBox->setLayout(bundlesLayout); + + QLabel *bundlesLabel = new QLabel(tr("Bundles path:")); + m_pathChooserBundles->setFilePath(Utils::FilePath::fromString(Paths::bundlesPathSetting())); + QPushButton *bundlesResetButton = new QPushButton(tr("Reset Path")); + + connect(bundlesResetButton, &QPushButton::clicked, this, [this]() { + m_pathChooserBundles->setFilePath(Paths::defaultBundlesPath()); + }); + + bundlesLayout->addWidget(bundlesLabel); + bundlesLayout->addWidget(m_pathChooserBundles); + bundlesLayout->addWidget(bundlesResetButton); + + boxLayout->addSpacerItem( + new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding)); +} + +void StudioSettingsPage::apply() +{ + bool dirty = false; + + setSettingIfDifferent(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_BUILD, + m_buildCheckBox->isChecked(), + dirty); + + setSettingIfDifferent(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_DEBUG, + m_debugCheckBox->isChecked(), + dirty); + + setSettingIfDifferent(ProjectExplorer::Constants::SETTINGS_MENU_HIDE_ANALYZE, + m_analyzeCheckBox->isChecked(), + dirty); + + setSettingIfDifferent(Core::Constants::SETTINGS_MENU_HIDE_TOOLS, + m_toolsCheckBox->isChecked(), + dirty); + + if (dirty) { + const QString restartText = tr( + "The menu visibility change will take effect after restart."); + Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText); + restartDialog.exec(); + } + + QSettings *s = Core::ICore::settings(); + const QString value = m_pathChooserExamples->filePath().toString(); + + if (s->value(Paths::exampleDownloadPath, false).toString() != value) { + s->setValue(Paths::exampleDownloadPath, value); + emit examplesDownloadPathChanged(value); + } + + const QString bundlesPath = m_pathChooserBundles->filePath().toString(); + + if (s->value(Paths::bundlesDownloadPath).toString() != bundlesPath) { + s->setValue(Paths::bundlesDownloadPath, bundlesPath); + emit bundlesDownloadPathChanged(bundlesPath); + + const QString restartText = tr("Changing bundle path will take effect after restart."); + Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText); + restartDialog.exec(); + } +} + +StudioConfigSettingsPage::StudioConfigSettingsPage() +{ + setId("Z.StudioConfig.Settings"); + setDisplayName(tr("Qt Design Studio Configuration")); + setCategory(Core::Constants::SETTINGS_CATEGORY_CORE); + setWidgetCreator([&] { + auto page = new StudioSettingsPage; + connect(page, + &StudioSettingsPage::examplesDownloadPathChanged, + this, + &StudioConfigSettingsPage::examplesDownloadPathChanged); + connect(page, + &StudioSettingsPage::bundlesDownloadPathChanged, + this, + &StudioConfigSettingsPage::bundlesDownloadPathChanged); + return page; + }); +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesignerbase/studio/studiosettingspage.h b/src/plugins/qmldesignerbase/studio/studiosettingspage.h new file mode 100644 index 00000000000..0d0149f1167 --- /dev/null +++ b/src/plugins/qmldesignerbase/studio/studiosettingspage.h @@ -0,0 +1,49 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "../qmldesignerbase_global.h" + +#include <coreplugin/dialogs/ioptionspage.h> +#include <utils/pathchooser.h> + +QT_FORWARD_DECLARE_CLASS(QCheckBox) + +namespace QmlDesigner { + +class StudioSettingsPage : public Core::IOptionsPageWidget +{ + Q_OBJECT + +public: + void apply() final; + + StudioSettingsPage(); + +signals: + void examplesDownloadPathChanged(const QString &path); + void bundlesDownloadPathChanged(const QString &path); + +private: + QCheckBox *m_buildCheckBox; + QCheckBox *m_debugCheckBox; + QCheckBox *m_analyzeCheckBox; + QCheckBox *m_toolsCheckBox; + Utils::PathChooser *m_pathChooserExamples; + Utils::PathChooser *m_pathChooserBundles; +}; + +class QMLDESIGNERBASE_EXPORT StudioConfigSettingsPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + StudioConfigSettingsPage(); + +signals: + void examplesDownloadPathChanged(const QString &path); + void bundlesDownloadPathChanged(const QString &path); +}; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesignerbase/utils/studiostyle.cpp b/src/plugins/qmldesignerbase/studio/studiostyle.cpp index 4b2f1132274..4b2f1132274 100644 --- a/src/plugins/qmldesignerbase/utils/studiostyle.cpp +++ b/src/plugins/qmldesignerbase/studio/studiostyle.cpp diff --git a/src/plugins/qmldesignerbase/utils/studiostyle.h b/src/plugins/qmldesignerbase/studio/studiostyle.h index 4d6424cbef1..4d6424cbef1 100644 --- a/src/plugins/qmldesignerbase/utils/studiostyle.h +++ b/src/plugins/qmldesignerbase/studio/studiostyle.h diff --git a/src/plugins/qmldesignerbase/utils/designerpaths.cpp b/src/plugins/qmldesignerbase/utils/designerpaths.cpp new file mode 100644 index 00000000000..b4ad03ba716 --- /dev/null +++ b/src/plugins/qmldesignerbase/utils/designerpaths.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#include "designerpaths.h" + +#include <coreplugin/icore.h> +#include <utils/hostosinfo.h> + +#include <QStandardPaths> + +namespace QmlDesigner::Paths { + +Utils::FilePath defaultExamplesPath() +{ + QStandardPaths::StandardLocation location = Utils::HostOsInfo::isMacHost() + ? QStandardPaths::HomeLocation + : QStandardPaths::DocumentsLocation; + + return Utils::FilePath::fromString(QStandardPaths::writableLocation(location)) + .pathAppended("QtDesignStudio/examples"); +} + +Utils::FilePath defaultBundlesPath() +{ + QStandardPaths::StandardLocation location = Utils::HostOsInfo::isMacHost() + ? QStandardPaths::HomeLocation + : QStandardPaths::DocumentsLocation; + + return Utils::FilePath::fromString(QStandardPaths::writableLocation(location)) + .pathAppended("QtDesignStudio/bundles"); +} + +QString examplesPathSetting() +{ + return Core::ICore::settings() + ->value(exampleDownloadPath, defaultExamplesPath().toString()) + .toString(); +} + +QString bundlesPathSetting() +{ + return Core::ICore::settings() + ->value(bundlesDownloadPath, defaultBundlesPath().toString()) + .toString(); +} + +} // namespace QmlDesigner::Paths diff --git a/src/plugins/qmldesignerbase/utils/designerpaths.h b/src/plugins/qmldesignerbase/utils/designerpaths.h new file mode 100644 index 00000000000..df53997457f --- /dev/null +++ b/src/plugins/qmldesignerbase/utils/designerpaths.h @@ -0,0 +1,20 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "../qmldesignerbase_global.h" + +#include <utils/filepath.h> + +namespace QmlDesigner::Paths { + +inline constexpr QStringView exampleDownloadPath = u"StudioConfig/ExamplesDownloadPath"; +inline constexpr QStringView bundlesDownloadPath = u"StudioConfig/BundlesDownloadPath"; + +QMLDESIGNERBASE_EXPORT Utils::FilePath defaultExamplesPath(); +QMLDESIGNERBASE_EXPORT Utils::FilePath defaultBundlesPath(); +QMLDESIGNERBASE_EXPORT QString examplesPathSetting(); +QMLDESIGNERBASE_EXPORT QString bundlesPathSetting(); + +} // namespace QmlDesigner::Paths diff --git a/src/plugins/studiowelcome/examplecheckout.cpp b/src/plugins/studiowelcome/examplecheckout.cpp index a0e5d07bab6..61a8e429d68 100644 --- a/src/plugins/studiowelcome/examplecheckout.cpp +++ b/src/plugins/studiowelcome/examplecheckout.cpp @@ -7,6 +7,8 @@ #include <coreplugin/documentmanager.h> #include <coreplugin/icore.h> +#include <designerpaths.h> +#include <studiosettingspage.h> #include <qmldesignerbase/qmldesignerbaseplugin.h> #include <utils/archive.h> @@ -61,7 +63,7 @@ bool DataModelDownloader::downloadEnabled() const QString DataModelDownloader::targetPath() const { - return QmlDesigner::QmlDesignerBasePlugin::examplesPathSetting(); + return QmlDesigner::Paths::examplesPathSetting(); } static Utils::FilePath tempFilePath() @@ -105,8 +107,8 @@ DataModelDownloader::DataModelDownloader(QObject * /* parent */) auto studioWelcomePlugin = qobject_cast<StudioWelcome::Internal::StudioWelcomePlugin *>(plugin); if (studioWelcomePlugin) { - QObject::connect(QmlDesigner::QmlDesignerBasePlugin::instance(), - &QmlDesigner::QmlDesignerBasePlugin::examplesDownloadPathChanged, + QObject::connect(QmlDesigner::QmlDesignerBasePlugin::studioConfigSettingsPage(), + &QmlDesigner::StudioConfigSettingsPage::examplesDownloadPathChanged, this, &DataModelDownloader::targetPathMustChange); } |