ProjectExplorer: Use new construction pattern for some project panels

Change-Id: I0c7cd43a2fcd9480cab06270a4fee295cf5a5fc1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-11-15 10:24:56 +01:00
parent 8c337722d0
commit 4773f89f8c
5 changed files with 96 additions and 91 deletions

View File

@@ -6,6 +6,8 @@
#include "editorconfiguration.h" #include "editorconfiguration.h"
#include "project.h" #include "project.h"
#include "projectexplorertr.h" #include "projectexplorertr.h"
#include "projectpanelfactory.h"
#include "projectsettingswidget.h"
#include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppeditorconstants.h>
@@ -17,14 +19,16 @@
#include <QComboBox> #include <QComboBox>
#include <QLabel> #include <QLabel>
#include <QLayout>
#include <QStackedWidget> #include <QStackedWidget>
using namespace TextEditor; using namespace TextEditor;
namespace ProjectExplorer::Internal { namespace ProjectExplorer::Internal {
CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) class CodeStyleSettingsWidget final : public ProjectSettingsWidget
{
public:
explicit CodeStyleSettingsWidget(Project *project)
{ {
auto languageComboBox = new QComboBox(this); auto languageComboBox = new QComboBox(this);
auto stackedWidget = new QStackedWidget(this); auto stackedWidget = new QStackedWidget(this);
@@ -56,5 +60,23 @@ CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project)
noMargin noMargin
}.attachTo(this); }.attachTo(this);
} }
};
class CodeStyleProjectPanelFactory final : public ProjectPanelFactory
{
public:
CodeStyleProjectPanelFactory()
{
setPriority(40);
setDisplayName(Tr::tr("Code Style"));
setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); });
ProjectPanelFactory::registerFactory(this);
}
};
void setupCodeStyleProjectPanel()
{
static CodeStyleProjectPanelFactory theCodeStyleProjectPanelFactory;
}
} // ProjectExplorer::Internal } // ProjectExplorer::Internal

View File

@@ -3,20 +3,8 @@
#pragma once #pragma once
#include <projectexplorer/projectsettingswidget.h> namespace ProjectExplorer::Internal {
namespace ProjectExplorer { void setupCodeStyleProjectPanel();
class Project; } // ProjectExplorer::Internal
namespace Internal {
class CodeStyleSettingsWidget : public ProjectSettingsWidget
{
Q_OBJECT
public:
explicit CodeStyleSettingsWidget(Project *project);
};
} // namespace Internal
} // namespace ProjectExplorer

View File

@@ -6,6 +6,8 @@
#include "editorconfiguration.h" #include "editorconfiguration.h"
#include "project.h" #include "project.h"
#include "projectexplorertr.h" #include "projectexplorertr.h"
#include "projectpanelfactory.h"
#include "projectsettingswidget.h"
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <texteditor/behaviorsettings.h> #include <texteditor/behaviorsettings.h>
@@ -25,6 +27,28 @@
namespace ProjectExplorer::Internal { 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) EditorSettingsWidget::EditorSettingsWidget(Project *project) : m_project(project)
{ {
setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS); setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS);
@@ -135,4 +159,21 @@ void EditorSettingsWidget::restoreDefaultValues()
settingsToUi(config); 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 } // ProjectExplorer::Internal

View File

@@ -3,46 +3,8 @@
#pragma once #pragma once
#include <projectexplorer/projectsettingswidget.h> namespace ProjectExplorer::Internal {
QT_BEGIN_NAMESPACE void setupEditorSettingsProjectPanel();
class QCheckBox;
class QGroupBox;
class QPushButton;
class QSpinBox;
QT_END_NAMESPACE
namespace TextEditor { class BehaviorSettingsWidget; } } // ProjectExplorer::Internal
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

View File

@@ -882,19 +882,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
&dd->m_outputPane, &AppOutputPane::projectRemoved); &dd->m_outputPane, &AppOutputPane::projectRemoved);
// ProjectPanelFactories // 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; setupEditorSettingsProjectPanel();
panelFactory->setPriority(40); setupCodeStyleProjectPanel();
panelFactory->setDisplayName(Tr::tr("Code Style"));
panelFactory->setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); });
ProjectPanelFactory::registerFactory(panelFactory);
panelFactory = new ProjectExplorer::ProjectPanelFactory; auto panelFactory = new ProjectExplorer::ProjectPanelFactory;
panelFactory->setPriority(45); panelFactory->setPriority(45);
panelFactory->setDisplayName(Tr::tr("Documentation Comments")); panelFactory->setDisplayName(Tr::tr("Documentation Comments"));
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) { panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {