forked from qt-creator/qt-creator
CppEditor: Use IOptionPage::setWidgetCreator() for settings
Change-Id: I0d2f8ffae7ca4e7360de0f69566ab03036c10c53 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -548,18 +549,13 @@ void CppCodeStylePreferencesWidget::finish()
|
|||||||
emit finishEmitted();
|
emit finishEmitted();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ CppCodeStyleSettingsPage
|
// CppCodeStyleSettingsPageWidget
|
||||||
|
|
||||||
CppCodeStyleSettingsPage::CppCodeStyleSettingsPage()
|
class CppCodeStyleSettingsPageWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
setId(Constants::CPP_CODE_STYLE_SETTINGS_ID);
|
public:
|
||||||
setDisplayName(Tr::tr("Code Style"));
|
CppCodeStyleSettingsPageWidget()
|
||||||
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
{
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *CppCodeStyleSettingsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
CppCodeStylePreferences *originalCodeStylePreferences = CppToolsSettings::instance()
|
CppCodeStylePreferences *originalCodeStylePreferences = CppToolsSettings::instance()
|
||||||
->cppCodeStyle();
|
->cppCodeStyle();
|
||||||
m_pageCppCodeStylePreferences = new CppCodeStylePreferences();
|
m_pageCppCodeStylePreferences = new CppCodeStylePreferences();
|
||||||
@@ -571,15 +567,16 @@ QWidget *CppCodeStyleSettingsPage::widget()
|
|||||||
originalCodeStylePreferences->currentDelegate());
|
originalCodeStylePreferences->currentDelegate());
|
||||||
// we set id so that it won't be possible to set delegate to the original prefs
|
// we set id so that it won't be possible to set delegate to the original prefs
|
||||||
m_pageCppCodeStylePreferences->setId(originalCodeStylePreferences->id());
|
m_pageCppCodeStylePreferences->setId(originalCodeStylePreferences->id());
|
||||||
m_widget = TextEditorSettings::codeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID)
|
|
||||||
->createCodeStyleEditor(m_pageCppCodeStylePreferences);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeStyleSettingsPage::apply()
|
m_codeStyleEditor = TextEditorSettings::codeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID)
|
||||||
{
|
->createCodeStyleEditor(m_pageCppCodeStylePreferences);
|
||||||
if (m_widget) {
|
|
||||||
|
auto hbox = new QVBoxLayout(this);
|
||||||
|
hbox->addWidget(m_codeStyleEditor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apply() final
|
||||||
|
{
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
|
|
||||||
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
|
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
|
||||||
@@ -596,15 +593,21 @@ void CppCodeStyleSettingsPage::apply()
|
|||||||
originalCppCodeStylePreferences->toSettings(QLatin1String(CppEditor::Constants::CPP_SETTINGS_ID), s);
|
originalCppCodeStylePreferences->toSettings(QLatin1String(CppEditor::Constants::CPP_SETTINGS_ID), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_widget->apply();
|
m_codeStyleEditor->apply();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeStyleSettingsPage::finish()
|
CppCodeStylePreferences *m_pageCppCodeStylePreferences = nullptr;
|
||||||
|
CodeStyleEditorWidget *m_codeStyleEditor;
|
||||||
|
};
|
||||||
|
|
||||||
|
// CppCodeStyleSettingsPage
|
||||||
|
|
||||||
|
CppCodeStyleSettingsPage::CppCodeStyleSettingsPage()
|
||||||
{
|
{
|
||||||
if (m_widget)
|
setId(Constants::CPP_CODE_STYLE_SETTINGS_ID);
|
||||||
m_widget->finish();
|
setDisplayName(Tr::tr("Code Style"));
|
||||||
delete m_widget;
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
||||||
|
setWidgetCreator([] { return new CppCodeStyleSettingsPageWidget; });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CppEditor::Internal
|
} // namespace CppEditor::Internal
|
||||||
|
@@ -86,14 +86,6 @@ class CppCodeStyleSettingsPage : public Core::IOptionsPage
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CppCodeStyleSettingsPage();
|
CppCodeStyleSettingsPage();
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
CppCodeStylePreferences *m_pageCppCodeStylePreferences = nullptr;
|
|
||||||
QPointer<TextEditor::CodeStyleEditorWidget> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user