forked from qt-creator/qt-creator
CppToolsPlugin: Partially pimpl and remove use of global object pool
Change-Id: Iee09bf2fc7c945b8dcf950edfe94889d35c63735 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -57,7 +57,6 @@
|
|||||||
#include <utils/mimetypes/mimedatabase.h>
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtPlugin>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -72,12 +71,40 @@ namespace Internal {
|
|||||||
|
|
||||||
enum { debug = 0 };
|
enum { debug = 0 };
|
||||||
|
|
||||||
static CppToolsPlugin *m_instance = 0;
|
static CppToolsPlugin *m_instance = nullptr;
|
||||||
static QHash<QString, QString> m_headerSourceMapping;
|
static QHash<QString, QString> m_headerSourceMapping;
|
||||||
|
|
||||||
|
class CppToolsPluginPluginPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CppToolsPluginPluginPrivate()
|
||||||
|
: m_codeModelSettings(new CppCodeModelSettings)
|
||||||
|
{
|
||||||
|
CppModelManager::createCppModelManager(m_instance, m_stringTable);
|
||||||
|
m_settings = new CppToolsSettings(m_instance); // force registration of cpp tools settings
|
||||||
|
m_codeModelSettings->fromSettings(ICore::settings());
|
||||||
|
m_cppFileSettingsPage = new CppFileSettingsPage(m_instance->m_fileSettings);
|
||||||
|
m_cppCodeModelSettingsPage = new CppCodeModelSettingsPage(m_codeModelSettings);
|
||||||
|
m_cppCodeStyleSettingsPage = new CppCodeStyleSettingsPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
~CppToolsPluginPluginPrivate()
|
||||||
|
{
|
||||||
|
delete m_cppFileSettingsPage;
|
||||||
|
delete m_cppCodeModelSettingsPage;
|
||||||
|
delete m_cppCodeStyleSettingsPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSharedPointer<CppCodeModelSettings> m_codeModelSettings;
|
||||||
|
CppToolsSettings *m_settings = nullptr;
|
||||||
|
StringTable m_stringTable;
|
||||||
|
CppFileSettingsPage *m_cppFileSettingsPage = nullptr;
|
||||||
|
CppCodeModelSettingsPage *m_cppCodeModelSettingsPage = nullptr;
|
||||||
|
CppCodeStyleSettingsPage *m_cppCodeStyleSettingsPage = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
CppToolsPlugin::CppToolsPlugin()
|
CppToolsPlugin::CppToolsPlugin()
|
||||||
: m_fileSettings(new CppFileSettings)
|
: m_fileSettings(new CppFileSettings)
|
||||||
, m_codeModelSettings(new CppCodeModelSettings)
|
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
auto bridgeImplementation = std::unique_ptr<CppToolsBridgeQtCreatorImplementation>(new CppToolsBridgeQtCreatorImplementation);
|
auto bridgeImplementation = std::unique_ptr<CppToolsBridgeQtCreatorImplementation>(new CppToolsBridgeQtCreatorImplementation);
|
||||||
@@ -86,7 +113,9 @@ CppToolsPlugin::CppToolsPlugin()
|
|||||||
|
|
||||||
CppToolsPlugin::~CppToolsPlugin()
|
CppToolsPlugin::~CppToolsPlugin()
|
||||||
{
|
{
|
||||||
m_instance = 0;
|
delete d;
|
||||||
|
d = nullptr;
|
||||||
|
m_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppToolsPlugin *CppToolsPlugin::instance()
|
CppToolsPlugin *CppToolsPlugin::instance()
|
||||||
@@ -134,18 +163,10 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
Q_UNUSED(arguments)
|
Q_UNUSED(arguments)
|
||||||
Q_UNUSED(error)
|
Q_UNUSED(error)
|
||||||
|
|
||||||
CppModelManager::createCppModelManager(this, m_stringTable);
|
d = new CppToolsPluginPluginPrivate;
|
||||||
|
|
||||||
m_settings = new CppToolsSettings(this); // force registration of cpp tools settings
|
|
||||||
|
|
||||||
m_codeModelSettings->fromSettings(ICore::settings());
|
|
||||||
|
|
||||||
JsExpander::registerQObjectForJs(QLatin1String("Cpp"), new CppToolsJsExtension);
|
JsExpander::registerQObjectForJs(QLatin1String("Cpp"), new CppToolsJsExtension);
|
||||||
|
|
||||||
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
|
||||||
addAutoReleasedObject(new CppCodeModelSettingsPage(m_codeModelSettings));
|
|
||||||
addAutoReleasedObject(new CppCodeStyleSettingsPage);
|
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||||
ActionContainer *mcpptools = ActionManager::createMenu(CppTools::Constants::M_TOOLS_CPP);
|
ActionContainer *mcpptools = ActionManager::createMenu(CppTools::Constants::M_TOOLS_CPP);
|
||||||
@@ -188,24 +209,19 @@ void CppToolsPlugin::extensionsInitialized()
|
|||||||
{
|
{
|
||||||
// The Cpp editor plugin, which is loaded later on, registers the Cpp mime types,
|
// The Cpp editor plugin, which is loaded later on, registers the Cpp mime types,
|
||||||
// so, apply settings here
|
// so, apply settings here
|
||||||
m_fileSettings->fromSettings(ICore::settings());
|
m_instance->m_fileSettings->fromSettings(ICore::settings());
|
||||||
if (!m_fileSettings->applySuffixesToMimeDB())
|
if (!m_instance->m_fileSettings->applySuffixesToMimeDB())
|
||||||
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
|
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtensionSystem::IPlugin::ShutdownFlag CppToolsPlugin::aboutToShutdown()
|
|
||||||
{
|
|
||||||
return SynchronousShutdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSharedPointer<CppCodeModelSettings> CppToolsPlugin::codeModelSettings() const
|
QSharedPointer<CppCodeModelSettings> CppToolsPlugin::codeModelSettings() const
|
||||||
{
|
{
|
||||||
return m_codeModelSettings;
|
return d->m_codeModelSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTable &CppToolsPlugin::stringTable()
|
StringTable &CppToolsPlugin::stringTable()
|
||||||
{
|
{
|
||||||
return instance()->m_stringTable;
|
return m_instance->d->m_stringTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppToolsPlugin::switchHeaderSource()
|
void CppToolsPlugin::switchHeaderSource()
|
||||||
|
@@ -47,6 +47,7 @@ class CppCodeModelSettings;
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
struct CppFileSettings;
|
struct CppFileSettings;
|
||||||
|
class CppToolsPluginPluginPrivate;
|
||||||
|
|
||||||
class CppToolsPlugin : public ExtensionSystem::IPlugin
|
class CppToolsPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
@@ -55,7 +56,7 @@ class CppToolsPlugin : public ExtensionSystem::IPlugin
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CppToolsPlugin();
|
CppToolsPlugin();
|
||||||
~CppToolsPlugin();
|
~CppToolsPlugin() final;
|
||||||
|
|
||||||
static CppToolsPlugin *instance();
|
static CppToolsPlugin *instance();
|
||||||
static const QStringList &headerSearchPaths();
|
static const QStringList &headerSearchPaths();
|
||||||
@@ -66,13 +67,13 @@ public:
|
|||||||
static Utils::FileName licenseTemplatePath();
|
static Utils::FileName licenseTemplatePath();
|
||||||
static QString licenseTemplate();
|
static QString licenseTemplate();
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
ShutdownFlag aboutToShutdown();
|
|
||||||
|
|
||||||
QSharedPointer<CppCodeModelSettings> codeModelSettings() const;
|
QSharedPointer<CppCodeModelSettings> codeModelSettings() const;
|
||||||
|
|
||||||
static StringTable &stringTable();
|
static StringTable &stringTable();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void switchHeaderSource();
|
void switchHeaderSource();
|
||||||
void switchHeaderSourceInNextSplit();
|
void switchHeaderSourceInNextSplit();
|
||||||
@@ -179,10 +180,9 @@ private slots:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class CppToolsPluginPluginPrivate;
|
||||||
|
CppToolsPluginPluginPrivate *d = nullptr;
|
||||||
QSharedPointer<CppFileSettings> m_fileSettings;
|
QSharedPointer<CppFileSettings> m_fileSettings;
|
||||||
QSharedPointer<CppCodeModelSettings> m_codeModelSettings;
|
|
||||||
CppToolsSettings *m_settings = nullptr;
|
|
||||||
StringTable m_stringTable;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user