forked from qt-creator/qt-creator
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:
@@ -309,7 +309,7 @@ public:
|
||||
_doc->check(_mode);
|
||||
|
||||
if (_modelManager)
|
||||
_modelManager->emitDocumentUpdated(_doc); // ### TODO: compress
|
||||
_modelManager->emitDocumentUpdated(_doc);
|
||||
|
||||
_doc->releaseSourceAndAST();
|
||||
}
|
||||
@@ -654,13 +654,6 @@ void CppModelManager::updateModifiedSourceFiles()
|
||||
updateSourceFiles(sourceFiles);
|
||||
}
|
||||
|
||||
CppModelManager *CppModelManager::instance()
|
||||
{
|
||||
// TODO this is pretty stupid. use regular singleton pattern.
|
||||
return ExtensionSystem::PluginManager::getObject<CppModelManager>();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\class CppTools::CppModelManager
|
||||
\brief The CppModelManager keeps track of one CppCodeModel instance
|
||||
@@ -670,6 +663,20 @@ CppModelManager *CppModelManager::instance()
|
||||
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)
|
||||
: CppModelManagerInterface(parent)
|
||||
{
|
||||
|
@@ -80,7 +80,7 @@ class CPPTOOLS_EXPORT CppModelManager : public CPlusPlus::CppModelManagerInterfa
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CppModelManager(QObject *parent);
|
||||
CppModelManager(QObject *parent = 0);
|
||||
virtual ~CppModelManager();
|
||||
|
||||
static CppModelManager *instance();
|
||||
@@ -192,6 +192,10 @@ private:
|
||||
CppPreprocessor *preproc,
|
||||
QStringList files);
|
||||
|
||||
private:
|
||||
static QMutex m_modelManagerMutex;
|
||||
static CppModelManager *m_modelManagerInstance;
|
||||
|
||||
private:
|
||||
CPlusPlus::Snapshot m_snapshot;
|
||||
|
||||
|
@@ -86,7 +86,6 @@ static CppToolsPlugin *m_instance = 0;
|
||||
static QHash<QString, QString> m_headerSourceMapping;
|
||||
|
||||
CppToolsPlugin::CppToolsPlugin() :
|
||||
m_modelManager(0),
|
||||
m_fileSettings(new CppFileSettings)
|
||||
{
|
||||
m_instance = this;
|
||||
@@ -95,7 +94,7 @@ CppToolsPlugin::CppToolsPlugin() :
|
||||
CppToolsPlugin::~CppToolsPlugin()
|
||||
{
|
||||
m_instance = 0;
|
||||
m_modelManager = 0; // deleted automatically
|
||||
delete CppModelManager::instance();
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// Objects
|
||||
m_modelManager = new CppModelManager(this);
|
||||
CppModelManager *modelManager = CppModelManager::instance();
|
||||
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
|
||||
connect(vcsManager, SIGNAL(repositoryChanged(QString)),
|
||||
m_modelManager, SLOT(updateModifiedSourceFiles()));
|
||||
modelManager, SLOT(updateModifiedSourceFiles()));
|
||||
connect(Core::DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
|
||||
m_modelManager, SLOT(updateSourceFiles(QStringList)));
|
||||
addAutoReleasedObject(m_modelManager);
|
||||
modelManager, SLOT(updateSourceFiles(QStringList)));
|
||||
|
||||
addAutoReleasedObject(new CppLocatorFilter(m_modelManager));
|
||||
addAutoReleasedObject(new CppClassesFilter(m_modelManager));
|
||||
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager));
|
||||
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, Core::ICore::editorManager()));
|
||||
addAutoReleasedObject(new CppLocatorFilter(modelManager));
|
||||
addAutoReleasedObject(new CppClassesFilter(modelManager));
|
||||
addAutoReleasedObject(new CppFunctionsFilter(modelManager));
|
||||
addAutoReleasedObject(new CppCurrentDocumentFilter(modelManager, Core::ICore::editorManager()));
|
||||
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
||||
addAutoReleasedObject(new SymbolsFindFilter(m_modelManager));
|
||||
addAutoReleasedObject(new SymbolsFindFilter(modelManager));
|
||||
addAutoReleasedObject(new CppCodeStyleSettingsPage);
|
||||
|
||||
// Menus
|
||||
|
@@ -71,7 +71,6 @@ public:
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||
void extensionsInitialized();
|
||||
ShutdownFlag aboutToShutdown();
|
||||
CppModelManager *cppModelManager() { return m_modelManager; }
|
||||
|
||||
private slots:
|
||||
void switchHeaderSource();
|
||||
@@ -110,7 +109,6 @@ private:
|
||||
#endif
|
||||
|
||||
private:
|
||||
CppModelManager *m_modelManager;
|
||||
QSharedPointer<CppFileSettings> m_fileSettings;
|
||||
CppToolsSettings *m_settings;
|
||||
};
|
||||
|
Reference in New Issue
Block a user