forked from qt-creator/qt-creator
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:
@@ -6,6 +6,8 @@
|
||||
#include "editorconfiguration.h"
|
||||
#include "project.h"
|
||||
#include "projectexplorertr.h"
|
||||
#include "projectpanelfactory.h"
|
||||
#include "projectsettingswidget.h"
|
||||
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
|
||||
@@ -17,44 +19,64 @@
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QStackedWidget>
|
||||
|
||||
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
|
||||
|
||||
@@ -3,20 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <projectexplorer/projectsettingswidget.h>
|
||||
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
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "editorconfiguration.h"
|
||||
#include "project.h"
|
||||
#include "projectexplorertr.h"
|
||||
#include "projectpanelfactory.h"
|
||||
#include "projectsettingswidget.h"
|
||||
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/behaviorsettings.h>
|
||||
@@ -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
|
||||
|
||||
@@ -3,46 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <projectexplorer/projectsettingswidget.h>
|
||||
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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user