CppEditor: Move some factory class definitions to .cpp

Change-Id: Icceae7f93ac52fe371813608ecec0de1feed317b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2024-02-02 14:43:50 +01:00
parent 6744c1e69c
commit fb609817bf
11 changed files with 102 additions and 86 deletions

View File

@@ -10,6 +10,7 @@
#include "cppeditortr.h" #include "cppeditortr.h"
#include "cpptoolsreuse.h" #include "cpptoolsreuse.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/session.h> #include <coreplugin/session.h>
@@ -185,14 +186,23 @@ bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
return settingsChanged; return settingsChanged;
} }
CppCodeModelSettingsPage::CppCodeModelSettingsPage() class CppCodeModelSettingsPage final : public Core::IOptionsPage
{ {
setId(Constants::CPP_CODE_MODEL_SETTINGS_ID); public:
setDisplayName(Tr::tr("Code Model")); CppCodeModelSettingsPage()
setCategory(Constants::CPP_SETTINGS_CATEGORY); {
setDisplayCategory(Tr::tr("C++")); setId(Constants::CPP_CODE_MODEL_SETTINGS_ID);
setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png"); setDisplayName(Tr::tr("Code Model"));
setWidgetCreator([] { return new CppCodeModelSettingsWidget; }); setCategory(Constants::CPP_SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("C++"));
setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png");
setWidgetCreator([] { return new CppCodeModelSettingsWidget; });
}
};
void setupCppCodeModelSettings()
{
static CppCodeModelSettingsPage theCppCodeModelSettingsPage;
} }
class ClangdSettingsWidget final : public QWidget class ClangdSettingsWidget final : public QWidget

View File

@@ -3,16 +3,9 @@
#pragma once #pragma once
#include <coreplugin/dialogs/ioptionspage.h>
namespace CppEditor::Internal { namespace CppEditor::Internal {
class CppCodeModelSettingsPage final : public Core::IOptionsPage void setupCppCodeModelSettings();
{
public:
CppCodeModelSettingsPage();
};
void setupClangdProjectSettingsPanel(); void setupClangdProjectSettingsPanel();
void setupClangdSettingsPage(); void setupClangdSettingsPage();

View File

@@ -607,12 +607,21 @@ public:
// CppCodeStyleSettingsPage // CppCodeStyleSettingsPage
CppCodeStyleSettingsPage::CppCodeStyleSettingsPage() class CppCodeStyleSettingsPage : public Core::IOptionsPage
{ {
setId(Constants::CPP_CODE_STYLE_SETTINGS_ID); public:
setDisplayName(Tr::tr("Code Style")); CppCodeStyleSettingsPage()
setCategory(Constants::CPP_SETTINGS_CATEGORY); {
setWidgetCreator([] { return new CppCodeStyleSettingsPageWidget; }); setId(Constants::CPP_CODE_STYLE_SETTINGS_ID);
setDisplayName(Tr::tr("Code Style"));
setCategory(Constants::CPP_SETTINGS_CATEGORY);
setWidgetCreator([] { return new CppCodeStyleSettingsPageWidget; });
}
};
void setupCppCodeStyleSettings()
{
static CppCodeStyleSettingsPage theCppCodeStyleSettingsPage;
} }
} // namespace CppEditor::Internal } // namespace CppEditor::Internal

View File

@@ -64,12 +64,7 @@ signals:
void finishEmitted(); void finishEmitted();
}; };
void setupCppCodeStyleSettings();
class CppCodeStyleSettingsPage : public Core::IOptionsPage
{
public:
CppCodeStyleSettingsPage();
};
} // namespace Internal } // namespace Internal
} // namespace CppEditor } // namespace CppEditor

View File

@@ -160,18 +160,12 @@ public:
QAction *m_reparseExternallyChangedFiles = nullptr; QAction *m_reparseExternallyChangedFiles = nullptr;
QAction *m_findRefsCategorizedAction = nullptr; QAction *m_findRefsCategorizedAction = nullptr;
CppQuickFixSettingsPage m_quickFixSettingsPage;
QPointer<CppCodeModelInspectorDialog> m_cppCodeModelInspectorDialog; QPointer<CppCodeModelInspectorDialog> m_cppCodeModelInspectorDialog;
CppOutlineWidgetFactory m_cppOutlineWidgetFactory;
CppEditorFactory m_cppEditorFactory; CppEditorFactory m_cppEditorFactory;
CppModelManager modelManager; CppModelManager modelManager;
CppToolsSettings settings; CppToolsSettings settings;
CppCodeModelSettingsPage m_cppCodeModelSettingsPage;
CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage;
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
}; };
class CppEditorPlugin final : public ExtensionSystem::IPlugin class CppEditorPlugin final : public ExtensionSystem::IPlugin
@@ -206,6 +200,12 @@ void CppEditorPlugin::initialize()
{ {
d = new CppEditorPluginPrivate; d = new CppEditorPluginPrivate;
setupCppQuickFixSettings();
setupCppCodeModelSettings();
setupCppOutline();
setupCppCodeStyleSettings();
setupCppProjectUpdater();
CppModelManager::registerJsExtension(); CppModelManager::registerJsExtension();
setupMenus(); setupMenus();

View File

@@ -13,6 +13,7 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/find/itemviewfind.h> #include <coreplugin/find/itemviewfind.h>
#include <texteditor/ioutlinewidget.h>
#include <texteditor/textdocument.h> #include <texteditor/textdocument.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
@@ -24,6 +25,8 @@
#include <QTimer> #include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
using namespace TextEditor;
namespace CppEditor::Internal { namespace CppEditor::Internal {
class CppOutlineTreeView final : public Utils::NavigationTreeView class CppOutlineTreeView final : public Utils::NavigationTreeView
@@ -255,22 +258,36 @@ bool CppOutlineWidget::syncCursor()
return m_enableCursorSync && !m_blockCursorSync; return m_enableCursorSync && !m_blockCursorSync;
} }
bool CppOutlineWidgetFactory::supportsEditor(Core::IEditor *editor) const class CppOutlineWidgetFactory final : public IOutlineWidgetFactory
{ {
const auto cppEditor = qobject_cast<TextEditor::BaseTextEditor*>(editor); public:
if (!cppEditor || !CppModelManager::isCppEditor(cppEditor)) bool supportsEditor(Core::IEditor *editor) const final
return false; {
return !CppModelManager::usesClangd(cppEditor->textDocument()); const auto cppEditor = qobject_cast<BaseTextEditor*>(editor);
} if (!cppEditor || !CppModelManager::isCppEditor(cppEditor))
return false;
return !CppModelManager::usesClangd(cppEditor->textDocument());
}
TextEditor::IOutlineWidget *CppOutlineWidgetFactory::createWidget(Core::IEditor *editor) bool supportsSorting() const final
{
return true;
}
IOutlineWidget *createWidget(Core::IEditor *editor) final
{
const auto cppEditor = qobject_cast<BaseTextEditor*>(editor);
QTC_ASSERT(cppEditor, return nullptr);
const auto cppEditorWidget = qobject_cast<CppEditorWidget*>(cppEditor->widget());
QTC_ASSERT(cppEditorWidget, return nullptr);
return new CppOutlineWidget(cppEditorWidget);
}
};
void setupCppOutline()
{ {
const auto cppEditor = qobject_cast<TextEditor::BaseTextEditor*>(editor); static CppOutlineWidgetFactory theCppOutlineWidgetFactory;
QTC_ASSERT(cppEditor, return nullptr);
const auto cppEditorWidget = qobject_cast<CppEditorWidget*>(cppEditor->widget());
QTC_ASSERT(cppEditorWidget, return nullptr);
return new CppOutlineWidget(cppEditorWidget);
} }
} // namespace CppEditor::Internal } // namespace CppEditor::Internal

View File

@@ -3,16 +3,8 @@
#pragma once #pragma once
#include <texteditor/ioutlinewidget.h>
namespace CppEditor::Internal { namespace CppEditor::Internal {
class CppOutlineWidgetFactory final : public TextEditor::IOutlineWidgetFactory void setupCppOutline();
{
public:
bool supportsEditor(Core::IEditor *editor) const final;
bool supportsSorting() const final { return true; }
TextEditor::IOutlineWidget *createWidget(Core::IEditor *editor) final;
};
} // namespace CppEditor::Internal } // CppEditor::Internal

View File

@@ -97,14 +97,19 @@ void CppProjectUpdater::cancel()
m_futureSynchronizer.cancelAllFutures(); m_futureSynchronizer.cancelAllFutures();
} }
namespace Internal { class CppProjectUpdaterFactory final : public ProjectUpdaterFactory
CppProjectUpdaterFactory::CppProjectUpdaterFactory()
{ {
setLanguage(Constants::CXX_LANGUAGE_ID); public:
setCreator([] { return new CppProjectUpdater; }); CppProjectUpdaterFactory()
{
setLanguage(Constants::CXX_LANGUAGE_ID);
setCreator([] { return new CppProjectUpdater; });
}
};
void setupCppProjectUpdater()
{
static CppProjectUpdaterFactory theCppProjectUpdaterFactory;
} }
} // namespace Internal
} // namespace CppEditor } // namespace CppEditor

View File

@@ -16,18 +16,6 @@ namespace ProjectExplorer { class ExtraCompiler; }
namespace CppEditor { namespace CppEditor {
namespace Internal {
// registered in extensionsystem's object pool for plugins with weak dependency to CppEditor
class CppProjectUpdaterFactory final
: public ProjectExplorer::ProjectUpdaterFactory
{
public:
CppProjectUpdaterFactory();
};
} // namespace Internal
class CPPEDITOR_EXPORT CppProjectUpdater final class CPPEDITOR_EXPORT CppProjectUpdater final
: public QObject, public ProjectExplorer::ProjectUpdater : public QObject, public ProjectExplorer::ProjectUpdater
{ {
@@ -43,4 +31,6 @@ private:
Tasking::TaskTreeRunner m_taskTreeRunner; Tasking::TaskTreeRunner m_taskTreeRunner;
}; };
void setupCppProjectUpdater();
} // namespace CppEditor } // namespace CppEditor

View File

@@ -7,14 +7,25 @@
#include "cppeditortr.h" #include "cppeditortr.h"
#include "cppquickfixsettingswidget.h" #include "cppquickfixsettingswidget.h"
#include <coreplugin/dialogs/ioptionspage.h>
namespace CppEditor::Internal { namespace CppEditor::Internal {
CppQuickFixSettingsPage::CppQuickFixSettingsPage() class CppQuickFixSettingsPage : public Core::IOptionsPage
{ {
setId(Constants::QUICK_FIX_SETTINGS_ID); public:
setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME)); CppQuickFixSettingsPage()
setCategory(Constants::CPP_SETTINGS_CATEGORY); {
setWidgetCreator([] { return new CppQuickFixSettingsWidget; }); setId(Constants::QUICK_FIX_SETTINGS_ID);
setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME));
setCategory(Constants::CPP_SETTINGS_CATEGORY);
setWidgetCreator([] { return new CppQuickFixSettingsWidget; });
}
};
void setupCppQuickFixSettings()
{
static CppQuickFixSettingsPage theCppQuickFixSettingsPage;
} }
} // CppEditor::Internal } // CppEditor::Internal

View File

@@ -3,14 +3,8 @@
#pragma once #pragma once
#include <coreplugin/dialogs/ioptionspage.h>
namespace CppEditor::Internal { namespace CppEditor::Internal {
class CppQuickFixSettingsPage : public Core::IOptionsPage void setupCppQuickFixSettings();
{
public:
CppQuickFixSettingsPage();
};
} // CppEditor::Internal } // CppEditor::Internal