C++: changed the CppModelManager to use a normal singleton.

Also removed two TODOs.

Change-Id: I91b235795da7e87a21782d189844eacdd68c5f3c
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Erik Verbruggen
2012-10-15 16:38:56 +02:00
parent 826a90ba13
commit b6608da7d1
4 changed files with 29 additions and 22 deletions

View File

@@ -309,7 +309,7 @@ public:
_doc->check(_mode); _doc->check(_mode);
if (_modelManager) if (_modelManager)
_modelManager->emitDocumentUpdated(_doc); // ### TODO: compress _modelManager->emitDocumentUpdated(_doc);
_doc->releaseSourceAndAST(); _doc->releaseSourceAndAST();
} }
@@ -654,13 +654,6 @@ void CppModelManager::updateModifiedSourceFiles()
updateSourceFiles(sourceFiles); updateSourceFiles(sourceFiles);
} }
CppModelManager *CppModelManager::instance()
{
// TODO this is pretty stupid. use regular singleton pattern.
return ExtensionSystem::PluginManager::getObject<CppModelManager>();
}
/*! /*!
\class CppTools::CppModelManager \class CppTools::CppModelManager
\brief The CppModelManager keeps track of one CppCodeModel instance \brief The CppModelManager keeps track of one CppCodeModel instance
@@ -670,6 +663,20 @@ CppModelManager *CppModelManager::instance()
modified within Qt Creator. modified within Qt Creator.
*/ */
QMutex CppModelManager::m_modelManagerMutex;
CppModelManager *CppModelManager::m_modelManagerInstance = 0;
CppModelManager *CppModelManager::instance()
{
if (m_modelManagerInstance)
return m_modelManagerInstance;
QMutexLocker locker(&m_modelManagerMutex);
if (!m_modelManagerInstance) {
m_modelManagerInstance = new CppModelManager;
}
return m_modelManagerInstance;
}
CppModelManager::CppModelManager(QObject *parent) CppModelManager::CppModelManager(QObject *parent)
: CppModelManagerInterface(parent) : CppModelManagerInterface(parent)
{ {

View File

@@ -80,7 +80,7 @@ class CPPTOOLS_EXPORT CppModelManager : public CPlusPlus::CppModelManagerInterfa
Q_OBJECT Q_OBJECT
public: public:
CppModelManager(QObject *parent); CppModelManager(QObject *parent = 0);
virtual ~CppModelManager(); virtual ~CppModelManager();
static CppModelManager *instance(); static CppModelManager *instance();
@@ -192,6 +192,10 @@ private:
CppPreprocessor *preproc, CppPreprocessor *preproc,
QStringList files); QStringList files);
private:
static QMutex m_modelManagerMutex;
static CppModelManager *m_modelManagerInstance;
private: private:
CPlusPlus::Snapshot m_snapshot; CPlusPlus::Snapshot m_snapshot;

View File

@@ -86,7 +86,6 @@ static CppToolsPlugin *m_instance = 0;
static QHash<QString, QString> m_headerSourceMapping; static QHash<QString, QString> m_headerSourceMapping;
CppToolsPlugin::CppToolsPlugin() : CppToolsPlugin::CppToolsPlugin() :
m_modelManager(0),
m_fileSettings(new CppFileSettings) m_fileSettings(new CppFileSettings)
{ {
m_instance = this; m_instance = this;
@@ -95,7 +94,7 @@ CppToolsPlugin::CppToolsPlugin() :
CppToolsPlugin::~CppToolsPlugin() CppToolsPlugin::~CppToolsPlugin()
{ {
m_instance = 0; m_instance = 0;
m_modelManager = 0; // deleted automatically delete CppModelManager::instance();
} }
bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
@@ -106,20 +105,19 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
m_settings = new CppToolsSettings(this); // force registration of cpp tools settings m_settings = new CppToolsSettings(this); // force registration of cpp tools settings
// Objects // Objects
m_modelManager = new CppModelManager(this); CppModelManager *modelManager = CppModelManager::instance();
Core::VcsManager *vcsManager = Core::ICore::vcsManager(); Core::VcsManager *vcsManager = Core::ICore::vcsManager();
connect(vcsManager, SIGNAL(repositoryChanged(QString)), connect(vcsManager, SIGNAL(repositoryChanged(QString)),
m_modelManager, SLOT(updateModifiedSourceFiles())); modelManager, SLOT(updateModifiedSourceFiles()));
connect(Core::DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)), connect(Core::DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
m_modelManager, SLOT(updateSourceFiles(QStringList))); modelManager, SLOT(updateSourceFiles(QStringList)));
addAutoReleasedObject(m_modelManager);
addAutoReleasedObject(new CppLocatorFilter(m_modelManager)); addAutoReleasedObject(new CppLocatorFilter(modelManager));
addAutoReleasedObject(new CppClassesFilter(m_modelManager)); addAutoReleasedObject(new CppClassesFilter(modelManager));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager)); addAutoReleasedObject(new CppFunctionsFilter(modelManager));
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, Core::ICore::editorManager())); addAutoReleasedObject(new CppCurrentDocumentFilter(modelManager, Core::ICore::editorManager()));
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings)); addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
addAutoReleasedObject(new SymbolsFindFilter(m_modelManager)); addAutoReleasedObject(new SymbolsFindFilter(modelManager));
addAutoReleasedObject(new CppCodeStyleSettingsPage); addAutoReleasedObject(new CppCodeStyleSettingsPage);
// Menus // Menus

View File

@@ -71,7 +71,6 @@ public:
bool initialize(const QStringList &arguments, QString *errorMessage); bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized(); void extensionsInitialized();
ShutdownFlag aboutToShutdown(); ShutdownFlag aboutToShutdown();
CppModelManager *cppModelManager() { return m_modelManager; }
private slots: private slots:
void switchHeaderSource(); void switchHeaderSource();
@@ -110,7 +109,6 @@ private:
#endif #endif
private: private:
CppModelManager *m_modelManager;
QSharedPointer<CppFileSettings> m_fileSettings; QSharedPointer<CppFileSettings> m_fileSettings;
CppToolsSettings *m_settings; CppToolsSettings *m_settings;
}; };