From 4773f89f8cf4027e3be17205eb371840ea849ec3 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 15 Nov 2023 10:24:56 +0100 Subject: [PATCH] ProjectExplorer: Use new construction pattern for some project panels Change-Id: I0c7cd43a2fcd9480cab06270a4fee295cf5a5fc1 Reviewed-by: Christian Stenger --- .../codestylesettingspropertiespage.cpp | 70 ++++++++++++------- .../codestylesettingspropertiespage.h | 18 +---- .../editorsettingspropertiespage.cpp | 41 +++++++++++ .../editorsettingspropertiespage.h | 44 +----------- .../projectexplorer/projectexplorer.cpp | 14 +--- 5 files changed, 96 insertions(+), 91 deletions(-) diff --git a/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp b/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp index f7ed131e575..6f3f4761241 100644 --- a/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp @@ -6,6 +6,8 @@ #include "editorconfiguration.h" #include "project.h" #include "projectexplorertr.h" +#include "projectpanelfactory.h" +#include "projectsettingswidget.h" #include @@ -17,44 +19,64 @@ #include #include -#include #include using namespace TextEditor; namespace ProjectExplorer::Internal { -CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) +class CodeStyleSettingsWidget final : public ProjectSettingsWidget { - auto languageComboBox = new QComboBox(this); - auto stackedWidget = new QStackedWidget(this); +public: + explicit CodeStyleSettingsWidget(Project *project) + { + auto languageComboBox = new QComboBox(this); + auto stackedWidget = new QStackedWidget(this); - setGlobalSettingsId(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID); - setUseGlobalSettingsCheckBoxVisible(false); + setGlobalSettingsId(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID); + setUseGlobalSettingsCheckBoxVisible(false); - const EditorConfiguration *config = project->editorConfiguration(); + const EditorConfiguration *config = project->editorConfiguration(); - for (ICodeStylePreferencesFactory *factory : TextEditorSettings::codeStyleFactories()) { - Utils::Id languageId = factory->languageId(); - ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId); + for (ICodeStylePreferencesFactory *factory : TextEditorSettings::codeStyleFactories()) { + Utils::Id languageId = factory->languageId(); + ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId); - auto preview = factory->createCodeStyleEditor(codeStylePreferences, project, stackedWidget); - if (preview && preview->layout()) - preview->layout()->setContentsMargins(QMargins()); - stackedWidget->addWidget(preview); - languageComboBox->addItem(factory->displayName()); + auto preview = factory->createCodeStyleEditor(codeStylePreferences, project, stackedWidget); + if (preview && preview->layout()) + preview->layout()->setContentsMargins(QMargins()); + stackedWidget->addWidget(preview); + languageComboBox->addItem(factory->displayName()); + } + + connect(languageComboBox, &QComboBox::currentIndexChanged, + stackedWidget, &QStackedWidget::setCurrentIndex); + + using namespace Layouting; + + Column { + Row { new QLabel(Tr::tr("Language:")), languageComboBox, st }, + stackedWidget, + noMargin + }.attachTo(this); } +}; - connect(languageComboBox, &QComboBox::currentIndexChanged, - stackedWidget, &QStackedWidget::setCurrentIndex); +class CodeStyleProjectPanelFactory final : public ProjectPanelFactory +{ +public: + CodeStyleProjectPanelFactory() + { + setPriority(40); + setDisplayName(Tr::tr("Code Style")); + setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); }); + ProjectPanelFactory::registerFactory(this); + } +}; - using namespace Layouting; - - Column { - Row { new QLabel(Tr::tr("Language:")), languageComboBox, st }, - stackedWidget, - noMargin - }.attachTo(this); +void setupCodeStyleProjectPanel() +{ + static CodeStyleProjectPanelFactory theCodeStyleProjectPanelFactory; } } // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/codestylesettingspropertiespage.h b/src/plugins/projectexplorer/codestylesettingspropertiespage.h index f07735f0eee..fed471a31a3 100644 --- a/src/plugins/projectexplorer/codestylesettingspropertiespage.h +++ b/src/plugins/projectexplorer/codestylesettingspropertiespage.h @@ -3,20 +3,8 @@ #pragma once -#include +namespace ProjectExplorer::Internal { -namespace ProjectExplorer { +void setupCodeStyleProjectPanel(); -class Project; - -namespace Internal { - -class CodeStyleSettingsWidget : public ProjectSettingsWidget -{ - Q_OBJECT -public: - explicit CodeStyleSettingsWidget(Project *project); -}; - -} // namespace Internal -} // namespace ProjectExplorer +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp index e0c2b93bb26..96deedfd625 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp @@ -6,6 +6,8 @@ #include "editorconfiguration.h" #include "project.h" #include "projectexplorertr.h" +#include "projectpanelfactory.h" +#include "projectsettingswidget.h" #include #include @@ -25,6 +27,28 @@ namespace ProjectExplorer::Internal { +class EditorSettingsWidget : public ProjectSettingsWidget +{ +public: + explicit EditorSettingsWidget(Project *project); + +private: + void globalSettingsActivated(bool useGlobal); + void restoreDefaultValues(); + + void settingsToUi(const EditorConfiguration *config); + + Project *m_project; + + QPushButton *m_restoreButton; + QCheckBox *m_showWrapColumn; + QCheckBox *m_tintMarginArea; + QSpinBox *m_wrapColumn; + QCheckBox *m_useIndenter; + QGroupBox *m_displaySettings; + TextEditor::BehaviorSettingsWidget *m_behaviorSettings; +}; + EditorSettingsWidget::EditorSettingsWidget(Project *project) : m_project(project) { setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS); @@ -135,4 +159,21 @@ void EditorSettingsWidget::restoreDefaultValues() settingsToUi(config); } +class EditorSettingsProjectPanelFactory final : public ProjectPanelFactory +{ +public: + EditorSettingsProjectPanelFactory() + { + setPriority(30); + setDisplayName(Tr::tr("Editor")); + setCreateWidgetFunction([](Project *project) { return new EditorSettingsWidget(project); }); + ProjectPanelFactory::registerFactory(this); + } +}; + +void setupEditorSettingsProjectPanel() +{ + static EditorSettingsProjectPanelFactory theEditorSettingsProjectPanelFactory; +} + } // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.h b/src/plugins/projectexplorer/editorsettingspropertiespage.h index ae9f3ccfe62..6aabd996443 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.h +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.h @@ -3,46 +3,8 @@ #pragma once -#include +namespace ProjectExplorer::Internal { -QT_BEGIN_NAMESPACE -class QCheckBox; -class QGroupBox; -class QPushButton; -class QSpinBox; -QT_END_NAMESPACE +void setupEditorSettingsProjectPanel(); -namespace TextEditor { class BehaviorSettingsWidget; } - -namespace ProjectExplorer { - -class EditorConfiguration; -class Project; - -namespace Internal { - -class EditorSettingsWidget : public ProjectSettingsWidget -{ - Q_OBJECT -public: - explicit EditorSettingsWidget(Project *project); - -private: - void globalSettingsActivated(bool useGlobal); - void restoreDefaultValues(); - - void settingsToUi(const EditorConfiguration *config); - - Project *m_project; - - QPushButton *m_restoreButton; - QCheckBox *m_showWrapColumn; - QCheckBox *m_tintMarginArea; - QSpinBox *m_wrapColumn; - QCheckBox *m_useIndenter; - QGroupBox *m_displaySettings; - TextEditor::BehaviorSettingsWidget *m_behaviorSettings; -}; - -} // namespace Internal -} // namespace ProjectExplorer +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 3e6131b36d5..c180d70658e 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -882,19 +882,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er &dd->m_outputPane, &AppOutputPane::projectRemoved); // ProjectPanelFactories - auto panelFactory = new ProjectPanelFactory; - panelFactory->setPriority(30); - panelFactory->setDisplayName(Tr::tr("Editor")); - panelFactory->setCreateWidgetFunction([](Project *project) { return new EditorSettingsWidget(project); }); - ProjectPanelFactory::registerFactory(panelFactory); - panelFactory = new ProjectPanelFactory; - panelFactory->setPriority(40); - panelFactory->setDisplayName(Tr::tr("Code Style")); - panelFactory->setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); }); - ProjectPanelFactory::registerFactory(panelFactory); + setupEditorSettingsProjectPanel(); + setupCodeStyleProjectPanel(); - panelFactory = new ProjectExplorer::ProjectPanelFactory; + auto panelFactory = new ProjectExplorer::ProjectPanelFactory; panelFactory->setPriority(45); panelFactory->setDisplayName(Tr::tr("Documentation Comments")); panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {