forked from qt-creator/qt-creator
CppEditor: Apply 'static pattern' to CppToolsSettings
Change-Id: I1632787e1a1ebf60427c92b302b25a1a2550853f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -565,7 +565,7 @@ Utils::EditOperations ClangFormatBaseIndenter::format(const TextEditor::RangesIn
|
|||||||
{
|
{
|
||||||
bool doFormatting = mode == FormattingMode::Forced || formatCodeInsteadOfIndent();
|
bool doFormatting = mode == FormattingMode::Forced || formatCodeInsteadOfIndent();
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
doFormatting = doFormatting || CppEditor::CppToolsSettings::instance()->cppCodeStyle()
|
doFormatting = doFormatting || CppEditor::CppToolsSettings::cppCodeStyle()
|
||||||
->codeStyleSettings().forceFormatting;
|
->codeStyleSettings().forceFormatting;
|
||||||
#endif
|
#endif
|
||||||
if (!doFormatting)
|
if (!doFormatting)
|
||||||
|
@@ -161,7 +161,7 @@ CppCodeStyleSettings CppCodeStyleSettings::currentProjectCodeStyle()
|
|||||||
|
|
||||||
CppCodeStyleSettings CppCodeStyleSettings::currentGlobalCodeStyle()
|
CppCodeStyleSettings CppCodeStyleSettings::currentGlobalCodeStyle()
|
||||||
{
|
{
|
||||||
CppCodeStylePreferences *cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
|
CppCodeStylePreferences *cppCodeStylePreferences = CppToolsSettings::cppCodeStyle();
|
||||||
QTC_ASSERT(cppCodeStylePreferences, return CppCodeStyleSettings());
|
QTC_ASSERT(cppCodeStylePreferences, return CppCodeStyleSettings());
|
||||||
|
|
||||||
return cppCodeStylePreferences->currentCodeStyleSettings();
|
return cppCodeStylePreferences->currentCodeStyleSettings();
|
||||||
@@ -188,8 +188,7 @@ TextEditor::TabSettings CppCodeStyleSettings::currentProjectTabSettings()
|
|||||||
|
|
||||||
TextEditor::TabSettings CppCodeStyleSettings::currentGlobalTabSettings()
|
TextEditor::TabSettings CppCodeStyleSettings::currentGlobalTabSettings()
|
||||||
{
|
{
|
||||||
CppCodeStylePreferences *cppCodeStylePreferences
|
CppCodeStylePreferences *cppCodeStylePreferences = CppToolsSettings::cppCodeStyle();
|
||||||
= CppToolsSettings::instance()->cppCodeStyle();
|
|
||||||
QTC_ASSERT(cppCodeStylePreferences, return TextEditor::TabSettings());
|
QTC_ASSERT(cppCodeStylePreferences, return TextEditor::TabSettings());
|
||||||
|
|
||||||
return cppCodeStylePreferences->currentTabSettings();
|
return cppCodeStylePreferences->currentTabSettings();
|
||||||
|
@@ -469,7 +469,7 @@ void CppCodeStylePreferencesWidget::updatePreview()
|
|||||||
{
|
{
|
||||||
CppCodeStylePreferences *cppCodeStylePreferences = m_preferences
|
CppCodeStylePreferences *cppCodeStylePreferences = m_preferences
|
||||||
? m_preferences
|
? m_preferences
|
||||||
: CppToolsSettings::instance()->cppCodeStyle();
|
: CppToolsSettings::cppCodeStyle();
|
||||||
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
|
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
|
||||||
const TabSettings ts = cppCodeStylePreferences->currentTabSettings();
|
const TabSettings ts = cppCodeStylePreferences->currentTabSettings();
|
||||||
QtStyleCodeFormatter formatter(ts, ccss);
|
QtStyleCodeFormatter formatter(ts, ccss);
|
||||||
@@ -568,8 +568,7 @@ class CppCodeStyleSettingsPageWidget : public Core::IOptionsPageWidget
|
|||||||
public:
|
public:
|
||||||
CppCodeStyleSettingsPageWidget()
|
CppCodeStyleSettingsPageWidget()
|
||||||
{
|
{
|
||||||
CppCodeStylePreferences *originalCodeStylePreferences = CppToolsSettings::instance()
|
CppCodeStylePreferences *originalCodeStylePreferences = CppToolsSettings::cppCodeStyle();
|
||||||
->cppCodeStyle();
|
|
||||||
m_pageCppCodeStylePreferences = new CppCodeStylePreferences();
|
m_pageCppCodeStylePreferences = new CppCodeStylePreferences();
|
||||||
m_pageCppCodeStylePreferences->setDelegatingPool(
|
m_pageCppCodeStylePreferences->setDelegatingPool(
|
||||||
originalCodeStylePreferences->delegatingPool());
|
originalCodeStylePreferences->delegatingPool());
|
||||||
@@ -589,7 +588,7 @@ public:
|
|||||||
|
|
||||||
void apply() final
|
void apply() final
|
||||||
{
|
{
|
||||||
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
|
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::cppCodeStyle();
|
||||||
if (originalCppCodeStylePreferences->codeStyleSettings() != m_pageCppCodeStylePreferences->codeStyleSettings()) {
|
if (originalCppCodeStylePreferences->codeStyleSettings() != m_pageCppCodeStylePreferences->codeStyleSettings()) {
|
||||||
originalCppCodeStylePreferences->setCodeStyleSettings(m_pageCppCodeStylePreferences->codeStyleSettings());
|
originalCppCodeStylePreferences->setCodeStyleSettings(m_pageCppCodeStylePreferences->codeStyleSettings());
|
||||||
originalCppCodeStylePreferences->toSettings(QLatin1String(CppEditor::Constants::CPP_SETTINGS_ID));
|
originalCppCodeStylePreferences->toSettings(QLatin1String(CppEditor::Constants::CPP_SETTINGS_ID));
|
||||||
|
@@ -40,7 +40,7 @@ void DoxygenTest::cleanTestCase()
|
|||||||
void DoxygenTest::cleanup()
|
void DoxygenTest::cleanup()
|
||||||
{
|
{
|
||||||
if (oldSettings)
|
if (oldSettings)
|
||||||
CppToolsSettings::instance()->setCommentsSettings(*oldSettings);
|
CppToolsSettings::setCommentsSettings(*oldSettings);
|
||||||
QVERIFY(Core::EditorManager::closeAllEditors(false));
|
QVERIFY(Core::EditorManager::closeAllEditors(false));
|
||||||
QVERIFY(TestCase::garbageCollectGlobalSnapshot());
|
QVERIFY(TestCase::garbageCollectGlobalSnapshot());
|
||||||
}
|
}
|
||||||
@@ -434,9 +434,8 @@ void DoxygenTest::runTest(const QByteArray &original,
|
|||||||
&testDocument.m_editorWidget));
|
&testDocument.m_editorWidget));
|
||||||
|
|
||||||
if (settings) {
|
if (settings) {
|
||||||
auto *cts = CppToolsSettings::instance();
|
oldSettings.reset(new TextEditor::CommentsSettings(CppToolsSettings::commentsSettings()));
|
||||||
oldSettings.reset(new TextEditor::CommentsSettings(cts->commentsSettings()));
|
CppToolsSettings::setCommentsSettings(*settings);
|
||||||
cts->setCommentsSettings(*settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to test documents that start with a comment. By default, the
|
// We want to test documents that start with a comment. By default, the
|
||||||
|
@@ -79,7 +79,7 @@ CppEditorOutline::CppEditorOutline(CppEditorWidget *editorWidget)
|
|||||||
m_proxyModel->setSourceModel(m_model);
|
m_proxyModel->setSourceModel(m_model);
|
||||||
|
|
||||||
// Set up proxy model
|
// Set up proxy model
|
||||||
if (CppToolsSettings::instance()->sortedEditorDocumentOutline())
|
if (CppToolsSettings::sortedEditorDocumentOutline())
|
||||||
m_proxyModel->sort(0, Qt::AscendingOrder);
|
m_proxyModel->sort(0, Qt::AscendingOrder);
|
||||||
else
|
else
|
||||||
m_proxyModel->sort(-1, Qt::AscendingOrder); // don't sort yet, but set column for sortedOutline()
|
m_proxyModel->sort(-1, Qt::AscendingOrder); // don't sort yet, but set column for sortedOutline()
|
||||||
|
@@ -19,7 +19,7 @@ CppQtStyleIndenter::CppQtStyleIndenter(QTextDocument *doc)
|
|||||||
{
|
{
|
||||||
// Just for safety. setCodeStylePreferences should be called when the editor the
|
// Just for safety. setCodeStylePreferences should be called when the editor the
|
||||||
// indenter belongs to gets initialized.
|
// indenter belongs to gets initialized.
|
||||||
m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
|
m_cppCodeStylePreferences = CppToolsSettings::cppCodeStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
CppQtStyleIndenter::~CppQtStyleIndenter() = default;
|
CppQtStyleIndenter::~CppQtStyleIndenter() = default;
|
||||||
|
@@ -129,7 +129,7 @@ BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDoc
|
|||||||
|
|
||||||
// Enforce the default cpp code style, so we are independent of config file settings.
|
// Enforce the default cpp code style, so we are independent of config file settings.
|
||||||
// This is needed by e.g. the GenerateGetterSetter quick fix.
|
// This is needed by e.g. the GenerateGetterSetter quick fix.
|
||||||
m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
|
m_cppCodeStylePreferences = CppToolsSettings::cppCodeStyle();
|
||||||
QVERIFY(m_cppCodeStylePreferences);
|
QVERIFY(m_cppCodeStylePreferences);
|
||||||
m_cppCodeStylePreferencesOriginalDelegateId = m_cppCodeStylePreferences->currentDelegateId();
|
m_cppCodeStylePreferencesOriginalDelegateId = m_cppCodeStylePreferences->currentDelegateId();
|
||||||
m_cppCodeStylePreferences->setCurrentDelegate("qt");
|
m_cppCodeStylePreferences->setCurrentDelegate("qt");
|
||||||
@@ -3479,14 +3479,12 @@ void CppCodeStyleSettingsChanger::setSettings(const CppCodeStyleSettings &settin
|
|||||||
QVariant variant;
|
QVariant variant;
|
||||||
variant.setValue(settings);
|
variant.setValue(settings);
|
||||||
|
|
||||||
CppCodeStylePreferences *preferences = CppToolsSettings::instance()->cppCodeStyle();
|
CppToolsSettings::cppCodeStyle()->currentDelegate()->setValue(variant);
|
||||||
preferences->currentDelegate()->setValue(variant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCodeStyleSettings CppCodeStyleSettingsChanger::currentSettings()
|
CppCodeStyleSettings CppCodeStyleSettingsChanger::currentSettings()
|
||||||
{
|
{
|
||||||
CppCodeStylePreferences *preferences = CppToolsSettings::instance()->cppCodeStyle();
|
return CppToolsSettings::cppCodeStyle()->currentDelegate()->value().value<CppCodeStyleSettings>();
|
||||||
return preferences->currentDelegate()->value().value<CppCodeStyleSettings>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickfixTest::testGenerateGettersSetters_data()
|
void QuickfixTest::testGenerateGettersSetters_data()
|
||||||
@@ -5392,7 +5390,7 @@ SpaceBeforeParens: Always
|
|||||||
CppTestDocument::create("file.cpp", origSource, expectedSource)});
|
CppTestDocument::create("file.cpp", origSource, expectedSource)});
|
||||||
InsertDefsFromDecls factory;
|
InsertDefsFromDecls factory;
|
||||||
factory.setMode(InsertDefsFromDecls::Mode::Impl);
|
factory.setMode(InsertDefsFromDecls::Mode::Impl);
|
||||||
CppCodeStylePreferences * const prefs = CppToolsSettings::instance()->cppCodeStyle();
|
CppCodeStylePreferences * const prefs = CppToolsSettings::cppCodeStyle();
|
||||||
const CppCodeStyleSettings settings = prefs->codeStyleSettings();
|
const CppCodeStyleSettings settings = prefs->codeStyleSettings();
|
||||||
CppCodeStyleSettings tempSettings = settings;
|
CppCodeStyleSettings tempSettings = settings;
|
||||||
tempSettings.forceFormatting = true;
|
tempSettings.forceFormatting = true;
|
||||||
|
@@ -29,21 +29,24 @@ using namespace TextEditor;
|
|||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CppToolsSettingsPrivate
|
class CppToolsSettingsPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommentsSettings m_commentsSettings;
|
CommentsSettings m_commentsSettings;
|
||||||
CppCodeStylePreferences *m_globalCodeStyle = nullptr;
|
CppCodeStylePreferences *m_globalCodeStyle = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace Internal
|
|
||||||
|
|
||||||
CppToolsSettings *CppToolsSettings::m_instance = nullptr;
|
} // Internal
|
||||||
|
|
||||||
|
CppToolsSettings *m_instance = nullptr;
|
||||||
|
Internal::CppToolsSettingsPrivate *d = nullptr;
|
||||||
|
|
||||||
CppToolsSettings::CppToolsSettings()
|
CppToolsSettings::CppToolsSettings()
|
||||||
: d(new Internal::CppToolsSettingsPrivate)
|
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_instance, return);
|
QTC_ASSERT(!m_instance, return);
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
|
d = new Internal::CppToolsSettingsPrivate;
|
||||||
|
|
||||||
qRegisterMetaType<CppCodeStyleSettings>("CppEditor::CppCodeStyleSettings");
|
qRegisterMetaType<CppCodeStyleSettings>("CppEditor::CppCodeStyleSettings");
|
||||||
|
|
||||||
@@ -156,12 +159,12 @@ CppToolsSettings *CppToolsSettings::instance()
|
|||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCodeStylePreferences *CppToolsSettings::cppCodeStyle() const
|
CppCodeStylePreferences *CppToolsSettings::cppCodeStyle()
|
||||||
{
|
{
|
||||||
return d->m_globalCodeStyle;
|
return d->m_globalCodeStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentsSettings &CppToolsSettings::commentsSettings() const
|
const CommentsSettings &CppToolsSettings::commentsSettings()
|
||||||
{
|
{
|
||||||
return d->m_commentsSettings;
|
return d->m_commentsSettings;
|
||||||
}
|
}
|
||||||
@@ -178,7 +181,7 @@ static QString sortEditorDocumentOutlineKey()
|
|||||||
+ QLatin1String(Constants::CPPEDITOR_SORT_EDITOR_DOCUMENT_OUTLINE);
|
+ QLatin1String(Constants::CPPEDITOR_SORT_EDITOR_DOCUMENT_OUTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppToolsSettings::sortedEditorDocumentOutline() const
|
bool CppToolsSettings::sortedEditorDocumentOutline()
|
||||||
{
|
{
|
||||||
return ICore::settings()
|
return ICore::settings()
|
||||||
->value(sortEditorDocumentOutlineKey(), kSortEditorDocumentOutlineDefault)
|
->value(sortEditorDocumentOutlineKey(), kSortEditorDocumentOutlineDefault)
|
||||||
@@ -190,7 +193,6 @@ void CppToolsSettings::setSortedEditorDocumentOutline(bool sorted)
|
|||||||
ICore::settings()->setValueWithDefault(sortEditorDocumentOutlineKey(),
|
ICore::settings()->setValueWithDefault(sortEditorDocumentOutlineKey(),
|
||||||
sorted,
|
sorted,
|
||||||
kSortEditorDocumentOutlineDefault);
|
kSortEditorDocumentOutlineDefault);
|
||||||
emit editorDocumentOutlineSortingChanged(sorted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -9,40 +9,27 @@
|
|||||||
|
|
||||||
namespace TextEditor { class CommentsSettings; }
|
namespace TextEditor { class CommentsSettings; }
|
||||||
|
|
||||||
namespace CppEditor
|
namespace CppEditor {
|
||||||
{
|
|
||||||
class CppCodeStylePreferences;
|
class CppCodeStylePreferences;
|
||||||
|
|
||||||
namespace Internal { class CppToolsSettingsPrivate; }
|
// This class is meant to go away.
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides a central place for cpp tools settings.
|
|
||||||
*/
|
|
||||||
class CPPEDITOR_EXPORT CppToolsSettings : public QObject
|
class CPPEDITOR_EXPORT CppToolsSettings : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppToolsSettings();
|
CppToolsSettings();
|
||||||
~CppToolsSettings() override;
|
~CppToolsSettings() override;
|
||||||
|
|
||||||
static CppToolsSettings *instance();
|
static CppToolsSettings *instance();
|
||||||
|
|
||||||
CppCodeStylePreferences *cppCodeStyle() const;
|
static CppCodeStylePreferences *cppCodeStyle();
|
||||||
|
|
||||||
const TextEditor::CommentsSettings &commentsSettings() const;
|
static const TextEditor::CommentsSettings &commentsSettings();
|
||||||
void setCommentsSettings(const TextEditor::CommentsSettings &commentsSettings);
|
static void setCommentsSettings(const TextEditor::CommentsSettings &commentsSettings);
|
||||||
|
|
||||||
bool sortedEditorDocumentOutline() const;
|
static bool sortedEditorDocumentOutline();
|
||||||
void setSortedEditorDocumentOutline(bool sorted);
|
static void setSortedEditorDocumentOutline(bool sorted);
|
||||||
|
|
||||||
signals:
|
|
||||||
void editorDocumentOutlineSortingChanged(bool isSorted);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Internal::CppToolsSettingsPrivate *d;
|
|
||||||
|
|
||||||
static CppToolsSettings *m_instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -34,8 +34,7 @@ void GlslIndenter::indentBlock(const QTextBlock &block,
|
|||||||
{
|
{
|
||||||
// TODO: do something with it
|
// TODO: do something with it
|
||||||
CppEditor::QtStyleCodeFormatter
|
CppEditor::QtStyleCodeFormatter
|
||||||
codeFormatter(tabSettings,
|
codeFormatter(tabSettings, CppEditor::CppToolsSettings::cppCodeStyle()->codeStyleSettings());
|
||||||
CppEditor::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
|
|
||||||
|
|
||||||
codeFormatter.updateStateUntil(block);
|
codeFormatter.updateStateUntil(block);
|
||||||
int indent;
|
int indent;
|
||||||
@@ -66,8 +65,7 @@ void GlslIndenter::indent(const QTextCursor &cursor,
|
|||||||
|
|
||||||
// TODO: do something with it
|
// TODO: do something with it
|
||||||
CppEditor::QtStyleCodeFormatter codeFormatter(tabSettings,
|
CppEditor::QtStyleCodeFormatter codeFormatter(tabSettings,
|
||||||
CppEditor::CppToolsSettings::instance()
|
CppEditor::CppToolsSettings::cppCodeStyle()
|
||||||
->cppCodeStyle()
|
|
||||||
->codeStyleSettings());
|
->codeStyleSettings());
|
||||||
codeFormatter.updateStateUntil(block);
|
codeFormatter.updateStateUntil(block);
|
||||||
|
|
||||||
@@ -92,8 +90,7 @@ int GlslIndenter::indentFor(const QTextBlock &block,
|
|||||||
int /*cursorPositionInEditor*/)
|
int /*cursorPositionInEditor*/)
|
||||||
{
|
{
|
||||||
CppEditor::QtStyleCodeFormatter
|
CppEditor::QtStyleCodeFormatter
|
||||||
codeFormatter(tabSettings,
|
codeFormatter(tabSettings, CppEditor::CppToolsSettings::cppCodeStyle()->codeStyleSettings());
|
||||||
CppEditor::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
|
|
||||||
|
|
||||||
codeFormatter.updateStateUntil(block);
|
codeFormatter.updateStateUntil(block);
|
||||||
int indent;
|
int indent;
|
||||||
@@ -109,8 +106,7 @@ TextEditor::IndentationForBlock GlslIndenter::indentationForBlocks(
|
|||||||
int /*cursorPositionInEditor*/)
|
int /*cursorPositionInEditor*/)
|
||||||
{
|
{
|
||||||
CppEditor::QtStyleCodeFormatter
|
CppEditor::QtStyleCodeFormatter
|
||||||
codeFormatter(tabSettings,
|
codeFormatter(tabSettings, CppEditor::CppToolsSettings::cppCodeStyle()->codeStyleSettings());
|
||||||
CppEditor::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
|
|
||||||
|
|
||||||
codeFormatter.updateStateUntil(blocks.last());
|
codeFormatter.updateStateUntil(blocks.last());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user