forked from qt-creator/qt-creator
CppEditor: Simplify CppCodeModelSettings setup
Change-Id: Ie6849caf8ded2c0901a9d2daeda6a1f81b68ed72 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -150,7 +150,7 @@ BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(TextEditor::TextD
|
||||
{
|
||||
using namespace Internal;
|
||||
|
||||
const CppCodeModelSettings *cms = CppEditorPlugin::instance()->codeModelSettings();
|
||||
const CppCodeModelSettings *cms = &cppCodeModelSettings();
|
||||
|
||||
BaseEditorDocumentParser::Configuration config = m_parser->configuration();
|
||||
config.usePrecompiledHeaders = cms->pchUsage() != CppCodeModelSettings::PchUse_None;
|
||||
|
@@ -68,6 +68,11 @@ static FilePath fallbackClangdFilePath()
|
||||
return Environment::systemEnvironment().searchInPath("clangd");
|
||||
}
|
||||
|
||||
CppCodeModelSettings::CppCodeModelSettings()
|
||||
{
|
||||
fromSettings(Core::ICore::settings());
|
||||
}
|
||||
|
||||
void CppCodeModelSettings::fromSettings(QtcSettings *s)
|
||||
{
|
||||
s->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
||||
@@ -594,4 +599,10 @@ int ClangdSettings::Data::defaultCompletionResults()
|
||||
return ok ? userValue : 100;
|
||||
}
|
||||
|
||||
CppCodeModelSettings &cppCodeModelSettings()
|
||||
{
|
||||
static CppCodeModelSettings theCppCodeModelSettings;
|
||||
return theCppCodeModelSettings;
|
||||
}
|
||||
|
||||
} // namespace CppEditor
|
||||
|
@@ -31,6 +31,8 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
CppCodeModelSettings();
|
||||
|
||||
void fromSettings(Utils::QtcSettings *s);
|
||||
void toSettings(Utils::QtcSettings *s);
|
||||
|
||||
@@ -212,4 +214,6 @@ private:
|
||||
bool m_blockIndexing = false;
|
||||
};
|
||||
|
||||
CppCodeModelSettings &cppCodeModelSettings();
|
||||
|
||||
} // namespace CppEditor
|
||||
|
@@ -46,7 +46,7 @@ namespace CppEditor::Internal {
|
||||
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
||||
{
|
||||
public:
|
||||
CppCodeModelSettingsWidget(CppCodeModelSettings *s);
|
||||
CppCodeModelSettingsWidget();
|
||||
|
||||
private:
|
||||
void apply() final;
|
||||
@@ -63,8 +63,8 @@ private:
|
||||
QPlainTextEdit *m_ignorePatternTextEdit;
|
||||
};
|
||||
|
||||
CppCodeModelSettingsWidget::CppCodeModelSettingsWidget(CppCodeModelSettings *s)
|
||||
: m_settings(s)
|
||||
CppCodeModelSettingsWidget::CppCodeModelSettingsWidget()
|
||||
: m_settings(&cppCodeModelSettings())
|
||||
{
|
||||
m_interpretAmbiguousHeadersAsCHeaders
|
||||
= new QCheckBox(Tr::tr("Interpret ambiguous headers as C headers"));
|
||||
@@ -184,14 +184,14 @@ bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
|
||||
return settingsChanged;
|
||||
}
|
||||
|
||||
CppCodeModelSettingsPage::CppCodeModelSettingsPage(CppCodeModelSettings *settings)
|
||||
CppCodeModelSettingsPage::CppCodeModelSettingsPage()
|
||||
{
|
||||
setId(Constants::CPP_CODE_MODEL_SETTINGS_ID);
|
||||
setDisplayName(Tr::tr("Code Model"));
|
||||
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
||||
setDisplayCategory(Tr::tr("C++"));
|
||||
setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png");
|
||||
setWidgetCreator([settings] { return new CppCodeModelSettingsWidget(settings); });
|
||||
setWidgetCreator([] { return new CppCodeModelSettingsWidget; });
|
||||
}
|
||||
|
||||
class ClangdSettingsWidget::Private
|
||||
|
@@ -12,7 +12,7 @@ namespace CppEditor::Internal {
|
||||
class CppCodeModelSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
explicit CppCodeModelSettingsPage(CppCodeModelSettings *settings);
|
||||
CppCodeModelSettingsPage();
|
||||
};
|
||||
|
||||
class ClangdSettingsWidget : public QWidget
|
||||
|
@@ -179,11 +179,10 @@ public:
|
||||
CppEditorFactory m_cppEditorFactory;
|
||||
|
||||
CppModelManager modelManager;
|
||||
CppCodeModelSettings m_codeModelSettings;
|
||||
CppToolsSettings settings;
|
||||
CppFileSettings m_fileSettings;
|
||||
CppFileSettingsPage m_cppFileSettingsPage{&m_fileSettings};
|
||||
CppCodeModelSettingsPage m_cppCodeModelSettingsPage{&m_codeModelSettings};
|
||||
CppCodeModelSettingsPage m_cppCodeModelSettingsPage;
|
||||
CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage;
|
||||
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
|
||||
};
|
||||
@@ -212,7 +211,6 @@ CppEditorPlugin *CppEditorPlugin::instance()
|
||||
void CppEditorPlugin::initialize()
|
||||
{
|
||||
d = new CppEditorPluginPrivate;
|
||||
d->m_codeModelSettings.fromSettings(ICore::settings());
|
||||
|
||||
CppModelManager::registerJsExtension();
|
||||
|
||||
@@ -621,11 +619,6 @@ bool CppEditorPlugin::usePragmaOnce(Project *project)
|
||||
return fileSettings(project).headerPragmaOnce;
|
||||
}
|
||||
|
||||
CppCodeModelSettings *CppEditorPlugin::codeModelSettings()
|
||||
{
|
||||
return &d->m_codeModelSettings;
|
||||
}
|
||||
|
||||
CppFileSettings CppEditorPlugin::fileSettings(Project *project)
|
||||
{
|
||||
if (!project)
|
||||
|
@@ -8,10 +8,7 @@
|
||||
namespace ProjectExplorer { class Project; }
|
||||
namespace Utils { class FilePath; }
|
||||
|
||||
namespace CppEditor {
|
||||
class CppCodeModelSettings;
|
||||
|
||||
namespace Internal {
|
||||
namespace CppEditor::Internal {
|
||||
|
||||
class CppEditorPluginPrivate;
|
||||
class CppFileSettings;
|
||||
@@ -39,7 +36,6 @@ public:
|
||||
void renameSymbolUnderCursor();
|
||||
void switchDeclarationDefinition();
|
||||
|
||||
CppCodeModelSettings *codeModelSettings();
|
||||
static CppFileSettings fileSettings(ProjectExplorer::Project *project);
|
||||
#ifdef WITH_TESTS
|
||||
static void setGlobalFileSettings(const CppFileSettings &settings);
|
||||
@@ -64,5 +60,4 @@ private:
|
||||
CppEditorPluginPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CppEditor
|
||||
} // namespace CppEditor::Internal
|
||||
|
@@ -338,7 +338,7 @@ CppCompletionAssistProcessor *getCppCompletionAssistProcessor()
|
||||
|
||||
CppCodeModelSettings *codeModelSettings()
|
||||
{
|
||||
return Internal::CppEditorPlugin::instance()->codeModelSettings();
|
||||
return &cppCodeModelSettings();
|
||||
}
|
||||
|
||||
int indexerFileSizeLimitInMb()
|
||||
|
Reference in New Issue
Block a user