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/qtcassert.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
@@ -72,12 +71,40 @@ namespace Internal {
|
||||
|
||||
enum { debug = 0 };
|
||||
|
||||
static CppToolsPlugin *m_instance = 0;
|
||||
static CppToolsPlugin *m_instance = nullptr;
|
||||
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()
|
||||
: m_fileSettings(new CppFileSettings)
|
||||
, m_codeModelSettings(new CppCodeModelSettings)
|
||||
{
|
||||
m_instance = this;
|
||||
auto bridgeImplementation = std::unique_ptr<CppToolsBridgeQtCreatorImplementation>(new CppToolsBridgeQtCreatorImplementation);
|
||||
@@ -86,7 +113,9 @@ CppToolsPlugin::CppToolsPlugin()
|
||||
|
||||
CppToolsPlugin::~CppToolsPlugin()
|
||||
{
|
||||
m_instance = 0;
|
||||
delete d;
|
||||
d = nullptr;
|
||||
m_instance = nullptr;
|
||||
}
|
||||
|
||||
CppToolsPlugin *CppToolsPlugin::instance()
|
||||
@@ -134,18 +163,10 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(error)
|
||||
|
||||
CppModelManager::createCppModelManager(this, m_stringTable);
|
||||
|
||||
m_settings = new CppToolsSettings(this); // force registration of cpp tools settings
|
||||
|
||||
m_codeModelSettings->fromSettings(ICore::settings());
|
||||
d = new CppToolsPluginPluginPrivate;
|
||||
|
||||
JsExpander::registerQObjectForJs(QLatin1String("Cpp"), new CppToolsJsExtension);
|
||||
|
||||
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
||||
addAutoReleasedObject(new CppCodeModelSettingsPage(m_codeModelSettings));
|
||||
addAutoReleasedObject(new CppCodeStyleSettingsPage);
|
||||
|
||||
// Menus
|
||||
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||
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,
|
||||
// so, apply settings here
|
||||
m_fileSettings->fromSettings(ICore::settings());
|
||||
if (!m_fileSettings->applySuffixesToMimeDB())
|
||||
m_instance->m_fileSettings->fromSettings(ICore::settings());
|
||||
if (!m_instance->m_fileSettings->applySuffixesToMimeDB())
|
||||
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
|
||||
{
|
||||
return m_codeModelSettings;
|
||||
return d->m_codeModelSettings;
|
||||
}
|
||||
|
||||
StringTable &CppToolsPlugin::stringTable()
|
||||
{
|
||||
return instance()->m_stringTable;
|
||||
return m_instance->d->m_stringTable;
|
||||
}
|
||||
|
||||
void CppToolsPlugin::switchHeaderSource()
|
||||
|
@@ -47,6 +47,7 @@ class CppCodeModelSettings;
|
||||
namespace Internal {
|
||||
|
||||
struct CppFileSettings;
|
||||
class CppToolsPluginPluginPrivate;
|
||||
|
||||
class CppToolsPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
@@ -55,7 +56,7 @@ class CppToolsPlugin : public ExtensionSystem::IPlugin
|
||||
|
||||
public:
|
||||
CppToolsPlugin();
|
||||
~CppToolsPlugin();
|
||||
~CppToolsPlugin() final;
|
||||
|
||||
static CppToolsPlugin *instance();
|
||||
static const QStringList &headerSearchPaths();
|
||||
@@ -66,13 +67,13 @@ public:
|
||||
static Utils::FileName licenseTemplatePath();
|
||||
static QString licenseTemplate();
|
||||
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||
void extensionsInitialized();
|
||||
ShutdownFlag aboutToShutdown();
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
||||
void extensionsInitialized() final;
|
||||
|
||||
QSharedPointer<CppCodeModelSettings> codeModelSettings() const;
|
||||
|
||||
static StringTable &stringTable();
|
||||
|
||||
public slots:
|
||||
void switchHeaderSource();
|
||||
void switchHeaderSourceInNextSplit();
|
||||
@@ -179,10 +180,9 @@ private slots:
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend class CppToolsPluginPluginPrivate;
|
||||
CppToolsPluginPluginPrivate *d = nullptr;
|
||||
QSharedPointer<CppFileSettings> m_fileSettings;
|
||||
QSharedPointer<CppCodeModelSettings> m_codeModelSettings;
|
||||
CppToolsSettings *m_settings = nullptr;
|
||||
StringTable m_stringTable;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user