forked from qt-creator/qt-creator
CppEditor: Use new construction pattern for project panels
Change-Id: I60dffd8fb7c00671054b5e229ba8c0a0cb622b1d Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/session.h>
|
#include <coreplugin/session.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/projectpanelfactory.h>
|
||||||
|
#include <projectexplorer/projectsettingswidget.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/infolabel.h>
|
#include <utils/infolabel.h>
|
||||||
#include <utils/itemviews.h>
|
#include <utils/itemviews.h>
|
||||||
@@ -36,6 +39,8 @@
|
|||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
|
|
||||||
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
||||||
@@ -578,24 +583,16 @@ ClangdSettingsPage::ClangdSettingsPage()
|
|||||||
setWidgetCreator([] { return new ClangdSettingsPageWidget; });
|
setWidgetCreator([] { return new ClangdSettingsPageWidget; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClangdProjectSettingsWidget : public ProjectSettingsWidget
|
||||||
class ClangdProjectSettingsWidget::Private
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(const ClangdProjectSettings &s) : settings(s), widget(s.settings(), true) {}
|
ClangdProjectSettingsWidget(const ClangdProjectSettings &settings)
|
||||||
|
: m_settings(settings), m_widget(settings.settings(), true)
|
||||||
ClangdProjectSettings settings;
|
|
||||||
ClangdSettingsWidget widget;
|
|
||||||
QCheckBox useGlobalSettingsCheckBox;
|
|
||||||
};
|
|
||||||
|
|
||||||
ClangdProjectSettingsWidget::ClangdProjectSettingsWidget(const ClangdProjectSettings &settings)
|
|
||||||
: d(new Private(settings))
|
|
||||||
{
|
{
|
||||||
setGlobalSettingsId(Constants::CPP_CLANGD_SETTINGS_ID);
|
setGlobalSettingsId(Constants::CPP_CLANGD_SETTINGS_ID);
|
||||||
const auto layout = new QVBoxLayout(this);
|
const auto layout = new QVBoxLayout(this);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->addWidget(&d->widget);
|
layout->addWidget(&m_widget);
|
||||||
|
|
||||||
const auto updateGlobalSettingsCheckBox = [this] {
|
const auto updateGlobalSettingsCheckBox = [this] {
|
||||||
if (ClangdSettings::instance().granularity() == ClangdSettings::Granularity::Session) {
|
if (ClangdSettings::instance().granularity() == ClangdSettings::Granularity::Session) {
|
||||||
@@ -603,9 +600,9 @@ ClangdProjectSettingsWidget::ClangdProjectSettingsWidget(const ClangdProjectSett
|
|||||||
setUseGlobalSettings(true);
|
setUseGlobalSettings(true);
|
||||||
} else {
|
} else {
|
||||||
setUseGlobalSettingsCheckBoxEnabled(true);
|
setUseGlobalSettingsCheckBoxEnabled(true);
|
||||||
setUseGlobalSettings(d->settings.useGlobalSettings());
|
setUseGlobalSettings(m_settings.useGlobalSettings());
|
||||||
}
|
}
|
||||||
d->widget.setEnabled(!useGlobalSettings());
|
m_widget.setEnabled(!useGlobalSettings());
|
||||||
};
|
};
|
||||||
|
|
||||||
updateGlobalSettingsCheckBox();
|
updateGlobalSettingsCheckBox();
|
||||||
@@ -614,20 +611,39 @@ ClangdProjectSettingsWidget::ClangdProjectSettingsWidget(const ClangdProjectSett
|
|||||||
|
|
||||||
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged, this,
|
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged, this,
|
||||||
[this](bool checked) {
|
[this](bool checked) {
|
||||||
d->widget.setEnabled(!checked);
|
m_widget.setEnabled(!checked);
|
||||||
d->settings.setUseGlobalSettings(checked);
|
m_settings.setUseGlobalSettings(checked);
|
||||||
if (!checked)
|
if (!checked)
|
||||||
d->settings.setSettings(d->widget.settingsData());
|
m_settings.setSettings(m_widget.settingsData());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&d->widget, &ClangdSettingsWidget::settingsDataChanged, this, [this] {
|
connect(&m_widget, &ClangdSettingsWidget::settingsDataChanged, this, [this] {
|
||||||
d->settings.setSettings(d->widget.settingsData());
|
m_settings.setSettings(m_widget.settingsData());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangdProjectSettingsWidget::~ClangdProjectSettingsWidget()
|
private:
|
||||||
|
ClangdProjectSettings m_settings;
|
||||||
|
ClangdSettingsWidget m_widget;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ClangdProjectSettingsPanelFactory final : public ProjectPanelFactory
|
||||||
{
|
{
|
||||||
delete d;
|
public:
|
||||||
|
ClangdProjectSettingsPanelFactory()
|
||||||
|
{
|
||||||
|
setPriority(100);
|
||||||
|
setDisplayName(Tr::tr("Clangd"));
|
||||||
|
setCreateWidgetFunction([](Project *project) {
|
||||||
|
return new ClangdProjectSettingsWidget(project);
|
||||||
|
});
|
||||||
|
ProjectPanelFactory::registerFactory(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setupClangdProjectSettingsPanel()
|
||||||
|
{
|
||||||
|
static ClangdProjectSettingsPanelFactory theClangdProjectSettingsPanelFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // CppEditor::Internal
|
} // CppEditor::Internal
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cppcodemodelsettings.h"
|
#include "cppcodemodelsettings.h"
|
||||||
#include <projectexplorer/projectsettingswidget.h>
|
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
@@ -40,17 +39,6 @@ private:
|
|||||||
Private * const d;
|
Private * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangdProjectSettingsWidget : public ProjectExplorer::ProjectSettingsWidget
|
void setupClangdProjectSettingsPanel();
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
} // CppEditor::Internal
|
||||||
ClangdProjectSettingsWidget(const ClangdProjectSettings &settings);
|
|
||||||
~ClangdProjectSettingsWidget();
|
|
||||||
|
|
||||||
private:
|
|
||||||
class Private;
|
|
||||||
Private * const d;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // CppEditor::Internal namespace
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@
|
|||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
#include <projectexplorer/projectpanelfactory.h>
|
|
||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
|
|
||||||
#include <texteditor/colorpreviewhoverhandler.h>
|
#include <texteditor/colorpreviewhoverhandler.h>
|
||||||
@@ -524,32 +523,12 @@ void CppEditorPlugin::addGlobalActions()
|
|||||||
|
|
||||||
void CppEditorPlugin::setupProjectPanels()
|
void CppEditorPlugin::setupProjectPanels()
|
||||||
{
|
{
|
||||||
const auto quickFixSettingsPanelFactory = new ProjectPanelFactory;
|
setupCppQuickFixProjectPanel();
|
||||||
quickFixSettingsPanelFactory->setPriority(100);
|
setupCppFileSettingsProjectPanel();
|
||||||
quickFixSettingsPanelFactory->setId(Constants::QUICK_FIX_PROJECT_PANEL_ID);
|
|
||||||
quickFixSettingsPanelFactory->setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME));
|
|
||||||
quickFixSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
||||||
return new CppQuickFixProjectSettingsWidget(project);
|
|
||||||
});
|
|
||||||
ProjectPanelFactory::registerFactory(quickFixSettingsPanelFactory);
|
|
||||||
|
|
||||||
const auto fileNamesPanelFactory = new ProjectPanelFactory;
|
|
||||||
fileNamesPanelFactory->setPriority(99);
|
|
||||||
fileNamesPanelFactory->setDisplayName(Tr::tr("C++ File Naming"));
|
|
||||||
fileNamesPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
||||||
return new CppFileSettingsForProjectWidget(project);
|
|
||||||
});
|
|
||||||
ProjectPanelFactory::registerFactory(fileNamesPanelFactory);
|
|
||||||
|
|
||||||
if (CppModelManager::isClangCodeModelActive()) {
|
if (CppModelManager::isClangCodeModelActive()) {
|
||||||
d->m_clangdSettingsPage = new ClangdSettingsPage;
|
d->m_clangdSettingsPage = new ClangdSettingsPage;
|
||||||
const auto clangdPanelFactory = new ProjectPanelFactory;
|
setupClangdProjectSettingsPanel();
|
||||||
clangdPanelFactory->setPriority(100);
|
|
||||||
clangdPanelFactory->setDisplayName(Tr::tr("Clangd"));
|
|
||||||
clangdPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
||||||
return new ClangdProjectSettingsWidget(project);
|
|
||||||
});
|
|
||||||
ProjectPanelFactory::registerFactory(clangdPanelFactory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/projectpanelfactory.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
@@ -21,7 +22,6 @@
|
|||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
@@ -586,6 +587,25 @@ void CppFileSettingsForProjectWidget::Private::maybeClearHeaderSourceCache()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CppFileSettingsProjectPanelFactory final : public ProjectPanelFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CppFileSettingsProjectPanelFactory()
|
||||||
|
{
|
||||||
|
setPriority(99);
|
||||||
|
setDisplayName(Tr::tr("C++ File Naming"));
|
||||||
|
setCreateWidgetFunction([](Project *project) {
|
||||||
|
return new CppFileSettingsForProjectWidget(project);
|
||||||
|
});
|
||||||
|
ProjectPanelFactory::registerFactory(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setupCppFileSettingsProjectPanel()
|
||||||
|
{
|
||||||
|
static CppFileSettingsProjectPanelFactory theCppFileSettingsProjectPanelFactory;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CppEditor::Internal
|
} // namespace CppEditor::Internal
|
||||||
|
|
||||||
#include <cppfilesettingspage.moc>
|
#include <cppfilesettingspage.moc>
|
||||||
|
|||||||
@@ -85,4 +85,6 @@ private:
|
|||||||
Private * const d;
|
Private * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void setupCppFileSettingsProjectPanel();
|
||||||
|
|
||||||
} // namespace CppEditor::Internal
|
} // namespace CppEditor::Internal
|
||||||
|
|||||||
@@ -5,17 +5,35 @@
|
|||||||
|
|
||||||
#include "cppeditorconstants.h"
|
#include "cppeditorconstants.h"
|
||||||
#include "cppeditortr.h"
|
#include "cppeditortr.h"
|
||||||
|
#include "cppquickfixprojectsettings.h"
|
||||||
#include "cppquickfixsettingswidget.h"
|
#include "cppquickfixsettingswidget.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/projectpanelfactory.h>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
|
|
||||||
CppQuickFixProjectSettingsWidget::CppQuickFixProjectSettingsWidget(ProjectExplorer::Project *project,
|
class CppQuickFixProjectSettingsWidget : public ProjectSettingsWidget
|
||||||
QWidget *parent)
|
{
|
||||||
: ProjectExplorer::ProjectSettingsWidget(parent)
|
public:
|
||||||
|
explicit CppQuickFixProjectSettingsWidget(Project *project);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void currentItemChanged(bool useGlobalSettings);
|
||||||
|
void buttonCustomClicked();
|
||||||
|
|
||||||
|
CppQuickFixSettingsWidget *m_settingsWidget;
|
||||||
|
CppQuickFixProjectsSettings::CppQuickFixProjectsSettingsPtr m_projectSettings;
|
||||||
|
|
||||||
|
QPushButton *m_pushButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
CppQuickFixProjectSettingsWidget::CppQuickFixProjectSettingsWidget(Project *project)
|
||||||
{
|
{
|
||||||
setGlobalSettingsId(CppEditor::Constants::QUICK_FIX_SETTINGS_ID);
|
setGlobalSettingsId(CppEditor::Constants::QUICK_FIX_SETTINGS_ID);
|
||||||
m_projectSettings = CppQuickFixProjectsSettings::getSettings(project);
|
m_projectSettings = CppQuickFixProjectsSettings::getSettings(project);
|
||||||
@@ -50,8 +68,6 @@ CppQuickFixProjectSettingsWidget::CppQuickFixProjectSettingsWidget(ProjectExplor
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CppQuickFixProjectSettingsWidget::~CppQuickFixProjectSettingsWidget() = default;
|
|
||||||
|
|
||||||
void CppQuickFixProjectSettingsWidget::currentItemChanged(bool useGlobalSettings)
|
void CppQuickFixProjectSettingsWidget::currentItemChanged(bool useGlobalSettings)
|
||||||
{
|
{
|
||||||
if (useGlobalSettings) {
|
if (useGlobalSettings) {
|
||||||
@@ -88,4 +104,24 @@ void CppQuickFixProjectSettingsWidget::buttonCustomClicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CppQuickFixProjectPanelFactory final : public ProjectPanelFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CppQuickFixProjectPanelFactory()
|
||||||
|
{
|
||||||
|
setPriority(100);
|
||||||
|
setId(Constants::QUICK_FIX_PROJECT_PANEL_ID);
|
||||||
|
setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME));
|
||||||
|
setCreateWidgetFunction([](Project *project) {
|
||||||
|
return new CppQuickFixProjectSettingsWidget(project);
|
||||||
|
});
|
||||||
|
ProjectPanelFactory::registerFactory(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setupCppQuickFixProjectPanel()
|
||||||
|
{
|
||||||
|
static CppQuickFixProjectPanelFactory theCppQuickFixProjectPanelFactory;
|
||||||
|
}
|
||||||
|
|
||||||
} // CppEditor::Internal
|
} // CppEditor::Internal
|
||||||
|
|||||||
@@ -3,35 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cppquickfixprojectsettings.h"
|
|
||||||
#include <projectexplorer/projectsettingswidget.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QPushButton;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
|
|
||||||
class CppQuickFixSettingsWidget;
|
void setupCppQuickFixProjectPanel();
|
||||||
class CppQuickFixProjectSettingsWidget : public ProjectExplorer::ProjectSettingsWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit CppQuickFixProjectSettingsWidget(ProjectExplorer::Project *project,
|
|
||||||
QWidget *parent = nullptr);
|
|
||||||
~CppQuickFixProjectSettingsWidget();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void currentItemChanged(bool useGlobalSettings);
|
|
||||||
void buttonCustomClicked();
|
|
||||||
|
|
||||||
CppQuickFixSettingsWidget *m_settingsWidget;
|
|
||||||
CppQuickFixProjectsSettings::CppQuickFixProjectsSettingsPtr m_projectSettings;
|
|
||||||
|
|
||||||
QPushButton *m_pushButton;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // CppEditor::Internal
|
} // CppEditor::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user