CppEditor: Move plugin class definition to .cpp

Also remove the globale instance variable which is not used anymore.

Change-Id: Ia054f79570b2fb650db31bd8560a08b0c9fe4c8c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2024-01-25 16:44:34 +01:00
parent 9cc3988acd
commit 34087df11e
4 changed files with 35 additions and 52 deletions

View File

@@ -67,6 +67,8 @@
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/vcsmanager.h>
#include <extensionsystem/iplugin.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projectexplorerconstants.h>
@@ -181,26 +183,35 @@ public:
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
};
static CppEditorPlugin *m_instance = nullptr;
static QHash<FilePath, FilePath> m_headerSourceMapping;
CppEditorPlugin::CppEditorPlugin()
class CppEditorPlugin final : public ExtensionSystem::IPlugin
{
m_instance = this;
}
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CppEditor.json")
CppEditorPlugin::~CppEditorPlugin()
{
destroyCppQuickFixes();
delete d;
d = nullptr;
m_instance = nullptr;
}
public:
~CppEditorPlugin() final
{
destroyCppQuickFixes();
delete d;
d = nullptr;
}
CppEditorPlugin *CppEditorPlugin::instance()
{
return m_instance;
}
private:
void initialize() final;
void extensionsInitialized() final;
void setupMenus();
void addPerSymbolActions();
void addActionsForSelections();
void addPerFileActions();
void addGlobalActions();
void registerVariables();
void registerTests();
CppEditorPluginPrivate *d = nullptr;
};
void CppEditorPlugin::initialize()
{
@@ -540,7 +551,7 @@ void CppEditorPluginPrivate::inspectCppCodeModel()
}
}
void CppEditorPlugin::clearHeaderSourceCache()
void clearHeaderSourceCache()
{
m_headerSourceMapping.clear();
}
@@ -774,3 +785,5 @@ FilePath correspondingHeaderOrSource(const FilePath &filePath, bool *wasHeader,
}
} // namespace CppEditor
#include "cppeditorplugin.moc"

View File

@@ -3,38 +3,8 @@
#pragma once
#include <extensionsystem/iplugin.h>
namespace CppEditor::Internal {
class CppEditorPluginPrivate;
void clearHeaderSourceCache();
class CppEditorPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CppEditor.json")
public:
CppEditorPlugin();
~CppEditorPlugin() override;
static CppEditorPlugin *instance();
static void clearHeaderSourceCache();
private:
void initialize() override;
void extensionsInitialized() override;
void setupMenus();
void addPerSymbolActions();
void addActionsForSelections();
void addPerFileActions();
void addGlobalActions();
void registerVariables();
void registerTests();
CppEditorPluginPrivate *d = nullptr;
};
} // namespace CppEditor::Internal
} // CppEditor::Internal

View File

@@ -396,7 +396,7 @@ void CppFileSettingsWidget::apply()
*m_settings = rc;
m_settings->toSettings(Core::ICore::settings());
m_settings->applySuffixesToMimeDB();
CppEditorPlugin::clearHeaderSourceCache();
clearHeaderSourceCache();
}
static inline void setComboText(QComboBox *cb, const QString &text, int defaultIndex = 0)
@@ -600,7 +600,7 @@ public:
if (m_settings.useGlobalSettings() != m_wasGlobal
|| s.headerSearchPaths != m_initialSettings.headerSearchPaths
|| s.sourceSearchPaths != m_initialSettings.sourceSearchPaths) {
CppEditorPlugin::clearHeaderSourceCache();
clearHeaderSourceCache();
}
}

View File

@@ -49,10 +49,10 @@ void HeaderSourceTest::test()
createTempFile(headerPath);
bool wasHeader;
CppEditorPlugin::clearHeaderSourceCache();
clearHeaderSourceCache();
QCOMPARE(correspondingHeaderOrSource(sourcePath, &wasHeader), headerPath);
QVERIFY(!wasHeader);
CppEditorPlugin::clearHeaderSourceCache();
clearHeaderSourceCache();
QCOMPARE(correspondingHeaderOrSource(headerPath, &wasHeader), sourcePath);
QVERIFY(wasHeader);
}