Commit fdaddec7 authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by David Schulz

CppTools: Clean up CppModelManager(Interface)

* Const correctness
* Better variable names
* Sort order of includes and forward declarations
* Comment fixes
* Cosmetic/Whitespace changes

Change-Id: Ieb137266ac7eddedb00c37f8b2cc8677d67e4bdd
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent f0682231
......@@ -128,7 +128,7 @@ CMakeProject::~CMakeProject()
it = m_uiCodeModelSupport.constBegin();
end = m_uiCodeModelSupport.constEnd();
for (; it!=end; ++it) {
modelManager->removeEditorSupport(it.value());
modelManager->removeExtraEditorSupport(it.value());
delete it.value();
}
......@@ -794,7 +794,7 @@ void CMakeProject::createUiCodeModelSupport()
// qDebug()<<"adding new codemodelsupport";
QtSupport::UiCodeModelSupport *cms = new QtSupport::UiCodeModelSupport(modelManager, this, uiFile, uiHeaderFilePath);
m_uiCodeModelSupport.insert(uiFile, cms);
modelManager->addEditorSupport(cms);
modelManager->addExtraEditorSupport(cms);
}
}
}
......@@ -803,7 +803,7 @@ void CMakeProject::createUiCodeModelSupport()
QMap<QString, QtSupport::UiCodeModelSupport *>::const_iterator it, end;
end = oldCodeModelSupport.constEnd();
for (it = oldCodeModelSupport.constBegin(); it!=end; ++it) {
modelManager->removeEditorSupport(it.value());
modelManager->removeExtraEditorSupport(it.value());
delete it.value();
}
}
......
......@@ -561,7 +561,7 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent)
CPPEditorWidget::~CPPEditorWidget()
{
if (m_modelManager)
m_modelManager->deleteEditorSupport(editor());
m_modelManager->deleteCppEditorSupport(editor());
delete m_completionSupport;
}
......
This diff is collapsed.
......@@ -31,6 +31,7 @@
#define CPPMODELMANAGER_H
#include "cpptools_global.h"
#include "cppmodelmanagerinterface.h"
#include <projectexplorer/project.h>
......@@ -40,10 +41,7 @@
#include <QMutex>
namespace Core { class IEditor; }
namespace TextEditor {
class BaseTextEditorWidget;
} // namespace TextEditor
namespace TextEditor { class BaseTextEditorWidget; }
namespace CppTools {
......@@ -81,14 +79,14 @@ public:
bool replaceDocument(Document::Ptr newDoc);
virtual void GC();
virtual bool isCppEditor(Core::IEditor *editor) const;
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
virtual void addEditorSupport(AbstractEditorSupport *editorSupport);
virtual void removeEditorSupport(AbstractEditorSupport *editorSupport);
virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *editor);
virtual void deleteEditorSupport(TextEditor::BaseTextEditor *textEditor);
virtual bool isCppEditor(Core::IEditor *editor) const;
virtual void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
virtual void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor);
virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor);
virtual QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
......@@ -143,14 +141,14 @@ public:
return m_definedMacros;
}
Q_SIGNALS:
signals:
void aboutToRemoveFiles(const QStringList &files);
public Q_SLOTS:
public slots:
virtual void updateModifiedSourceFiles();
private Q_SLOTS:
// this should be executed in the GUI thread.
private slots:
// This should be executed in the GUI thread.
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onAboutToUnloadSession();
void onCoreAboutToClose();
......@@ -169,42 +167,46 @@ private:
void dumpModelManagerConfiguration();
private:
static QMutex m_modelManagerMutex;
static CppModelManager *m_modelManagerInstance;
static QMutex m_instanceMutex;
static CppModelManager *m_instance;
private:
// snapshot
// Snapshot
mutable QMutex m_snapshotMutex;
CPlusPlus::Snapshot m_snapshot;
bool m_enableGC;
// project integration
// Project integration
mutable QMutex m_projectMutex;
QMap<ProjectExplorer::Project *, ProjectInfo> m_projects;
QMap<QString, QList<CppTools::ProjectPart::Ptr> > m_srcToProjectPart;
// cached/calculated from the projects and/or their project-parts
QMap<ProjectExplorer::Project *, ProjectInfo> m_projectToProjectsInfo;
QMap<QString, QList<CppTools::ProjectPart::Ptr> > m_fileToProjectParts;
// The members below are cached/(re)calculated from the projects and/or their project parts
bool m_dirty;
QStringList m_projectFiles;
QStringList m_includePaths;
QStringList m_frameworkPaths;
QByteArray m_definedMacros;
// editor integration
mutable QMutex m_editorSupportMutex;
QMap<TextEditor::BaseTextEditor *, CppEditorSupport *> m_editorSupport;
QSet<AbstractEditorSupport *> m_addtionalEditorSupport;
CppFindReferences *m_findReferences;
bool m_indexerEnabled;
// Editor integration
mutable QMutex m_cppEditorSupportsMutex;
QMap<TextEditor::BaseTextEditor *, CppEditorSupport *> m_cppEditorSupports;
QSet<AbstractEditorSupport *> m_extraEditorSupports;
// Completion
CppCompletionAssistProvider *m_completionAssistProvider;
CppCompletionAssistProvider *m_completionFallback;
// Highlighting
CppHighlightingSupportFactory *m_highlightingFactory;
CppHighlightingSupportFactory *m_highlightingFallback;
// Indexing
CppIndexingSupport *m_indexingSupporter;
CppIndexingSupport *m_internalIndexingSupport;
bool m_indexerEnabled;
CppFindReferences *m_findReferences;
bool m_enableGC;
};
} // namespace Internal
......
......@@ -29,11 +29,15 @@
#include "cppmodelmanagerinterface.h"
#include <projectexplorer/toolchain.h>
#include <projectexplorer/headerpath.h>
#include <cplusplus/pp-engine.h>
#include <QtCore/QSet>
#include <projectexplorer/headerpath.h>
#include <projectexplorer/toolchain.h>
#include <QSet>
using namespace CppTools;
using namespace ProjectExplorer;
/*!
\enum CppTools::CppModelManagerInterface::ProgressNotificationMode
......@@ -44,15 +48,16 @@
\value ForcedProgressNotification
Notify regardless of the number of files requested for update.
\value ReservedProgressNotification
Notify only if more than one file is requested for update.
*/
/*!
\enum CppTools::CppModelManagerInterface::QtVersion
Allows C++ parser engine to inject headers or change inner settings as
needed to parse Qt language extensions for concrete major Qt version
\value UnknownQt
Parser may choose any policy
\value NoQt
......@@ -63,9 +68,6 @@
Parser may enable tricks for Qt v5.x
*/
using namespace CppTools;
using namespace ProjectExplorer;
ProjectPart::ProjectPart()
: cVersion(C89)
, cxxVersion(CXX11)
......@@ -76,12 +78,13 @@ ProjectPart::ProjectPart()
{
}
/**
* @brief Retrieves info from concrete compiler using it's flags.
* @param tc Either nullptr or toolchain for project's active target.
* @param cxxflags C++ or Objective-C++ flags.
* @param cflags C or ObjectiveC flags if possible, \a cxxflags otherwise.
*/
/*!
\brief Retrieves info from concrete compiler using it's flags.
\param tc Either nullptr or toolchain for project's active target.
\param cxxflags C++ or Objective-C++ flags.
\param cflags C or ObjectiveC flags if possible, \a cxxflags otherwise.
*/
void ProjectPart::evaluateToolchain(const ToolChain *tc,
const QStringList &cxxflags,
const QStringList &cflags,
......@@ -89,6 +92,7 @@ void ProjectPart::evaluateToolchain(const ToolChain *tc,
{
if (!tc)
return;
ToolChain::CompilerFlags cxx = tc->compilerFlags(cxxflags);
ToolChain::CompilerFlags c = (cxxflags == cflags)
? cxx : tc->compilerFlags(cflags);
......@@ -117,14 +121,14 @@ void ProjectPart::evaluateToolchain(const ToolChain *tc,
cWarningFlags = tc->warningFlags(cflags);
cxxWarningFlags = tc->warningFlags(cxxflags);
QList<HeaderPath> headers = tc->systemHeaderPaths(cxxflags, sysRoot);
const QList<HeaderPath> headers = tc->systemHeaderPaths(cxxflags, sysRoot);
foreach (const HeaderPath &header, headers)
if (header.kind() == HeaderPath::FrameworkHeaderPath)
frameworkPaths << header.path();
else
includePaths << header.path();
QByteArray macros = tc->predefinedMacros(cxxflags);
const QByteArray macros = tc->predefinedMacros(cxxflags);
if (!macros.isEmpty()) {
if (!defines.isEmpty())
defines += '\n';
......@@ -156,7 +160,6 @@ CppModelManagerInterface *CppModelManagerInterface::instance()
return g_instance;
}
void CppModelManagerInterface::ProjectInfo::clearProjectParts()
{
m_projectParts.clear();
......@@ -166,33 +169,32 @@ void CppModelManagerInterface::ProjectInfo::clearProjectParts()
m_defines.clear();
}
void CppModelManagerInterface::ProjectInfo::appendProjectPart(
const ProjectPart::Ptr &part)
void CppModelManagerInterface::ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part)
{
if (!part)
return;
m_projectParts.append(part);
// update include paths
// Update include paths
QSet<QString> incs = QSet<QString>::fromList(m_includePaths);
foreach (const QString &ins, part->includePaths)
incs.insert(ins);
m_includePaths = incs.toList();
// update framework paths
// Update framework paths
QSet<QString> frms = QSet<QString>::fromList(m_frameworkPaths);
foreach (const QString &frm, part->frameworkPaths)
frms.insert(frm);
m_frameworkPaths = frms.toList();
// update source files
// Update source files
QSet<QString> srcs = QSet<QString>::fromList(m_sourceFiles);
foreach (const ProjectFile &file, part->files)
srcs.insert(file.path);
m_sourceFiles = srcs.toList();
// update defines
// Update defines
if (!m_defines.isEmpty())
m_defines.append('\n');
m_defines.append(part->defines);
......
......@@ -31,16 +31,17 @@
#define CPPMODELMANAGERINTERFACE_H
#include "cpptools_global.h"
#include "cppprojectfile.h"
#include <cplusplus/CppDocument.h>
#include <projectexplorer/toolchain.h>
#include <QObject>
#include <QFuture>
#include <QHash>
#include <QObject>
#include <QPointer>
#include <QStringList>
#include <QFuture>
namespace Core { class IEditor; }
namespace CPlusPlus { class LookupContext; }
......@@ -49,9 +50,10 @@ namespace TextEditor { class BaseTextEditor; }
namespace Utils { class FileName; }
namespace CppTools {
class AbstractEditorSupport;
class CppCompletionSupport;
class CppCompletionAssistProvider;
class CppCompletionSupport;
class CppEditorSupport;
class CppHighlightingSupport;
class CppHighlightingSupportFactory;
......@@ -97,7 +99,7 @@ public:
typedef QSharedPointer<ProjectPart> Ptr;
public: //attributes
public:
QList<ProjectFile> files;
QByteArray defines;
QStringList includePaths;
......@@ -116,8 +118,7 @@ class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
Q_OBJECT
public:
// Documented in source file.
// Documented in source file.
enum ProgressNotificationMode {
ForcedProgressNotification,
ReservedProgressNotification
......@@ -127,11 +128,11 @@ public:
{
public:
ProjectInfo()
{ }
{}
ProjectInfo(QPointer<ProjectExplorer::Project> project)
: m_project(project)
{ }
{}
operator bool() const
{ return !m_project.isNull(); }
......@@ -163,10 +164,10 @@ public:
const QByteArray defines() const
{ return m_defines; }
private: // attributes
private:
QPointer<ProjectExplorer::Project> m_project;
QList<ProjectPart::Ptr> m_projectParts;
// the attributes below are calculated from the project parts.
// The members below are (re)calculated from the project parts once a part is appended.
QStringList m_includePaths;
QStringList m_frameworkPaths;
QStringList m_sourceFiles;
......@@ -220,10 +221,10 @@ public:
virtual QStringList includePaths() = 0;
virtual void addEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
virtual void removeEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *editor) = 0;
virtual void deleteEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
virtual void addExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
virtual void removeExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
virtual QList<int> references(CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context) = 0;
......@@ -247,7 +248,7 @@ public:
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
virtual CppTools::CppIndexingSupport *indexingSupport() = 0;
Q_SIGNALS:
signals:
void documentUpdated(CPlusPlus::Document::Ptr doc);
void sourceFilesRefreshed(const QStringList &files);
......@@ -256,8 +257,7 @@ Q_SIGNALS:
/// Other classes can use this to get notified when the \c ProjectExplorer has updated the parts.
void projectPartsUpdated(ProjectExplorer::Project *project);
public Q_SLOTS:
public slots:
virtual void updateModifiedSourceFiles() = 0;
virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles,
ProgressNotificationMode mode = ReservedProgressNotification) = 0;
......
......@@ -1466,7 +1466,7 @@ Qt4ProFileNode::~Qt4ProFileNode()
QMap<QString, QtSupport::UiCodeModelSupport *>::const_iterator it, end;
end = m_uiCodeModelSupport.constEnd();
for (it = m_uiCodeModelSupport.constBegin(); it != end; ++it) {
modelManager->removeEditorSupport(it.value());
modelManager->removeExtraEditorSupport(it.value());
delete it.value();
}
m_parseFutureWatcher.waitForFinished();
......@@ -2318,7 +2318,7 @@ void Qt4ProFileNode::createUiCodeModelSupport()
// qDebug()<<"adding new codemodelsupport";
QtSupport::UiCodeModelSupport *cms = new QtSupport::UiCodeModelSupport(modelManager, m_project, uiFile->path(), uiHeaderFilePath);
m_uiCodeModelSupport.insert(uiFile->path(), cms);
modelManager->addEditorSupport(cms);
modelManager->addExtraEditorSupport(cms);
}
}
}
......@@ -2326,7 +2326,7 @@ void Qt4ProFileNode::createUiCodeModelSupport()
QMap<QString, QtSupport::UiCodeModelSupport *>::const_iterator it, end;
end = oldCodeModelSupport.constEnd();
for (it = oldCodeModelSupport.constBegin(); it!=end; ++it) {
modelManager->removeEditorSupport(it.value());
modelManager->removeExtraEditorSupport(it.value());
delete it.value();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment