Commit 2ba49e4e authored by Kai Koehne's avatar Kai Koehne
Browse files

CppEditor: Reuse OverviewModel from text editor also in the outline pane

There's no use synchronizing the same model twice.
parent 1430358d
...@@ -1417,6 +1417,11 @@ SemanticInfo CPPEditor::semanticInfo() const ...@@ -1417,6 +1417,11 @@ SemanticInfo CPPEditor::semanticInfo() const
return m_lastSemanticInfo; return m_lastSemanticInfo;
} }
CPlusPlus::OverviewModel *CPPEditor::overviewModel() const
{
return m_overviewModel;
}
bool CPPEditor::isElectricCharacter(QChar ch) const bool CPPEditor::isElectricCharacter(QChar ch) const
{ {
if (ch == QLatin1Char('{') || if (ch == QLatin1Char('{') ||
......
...@@ -165,6 +165,7 @@ public: ...@@ -165,6 +165,7 @@ public:
unsigned editorRevision() const; unsigned editorRevision() const;
bool isOutdated() const; bool isOutdated() const;
SemanticInfo semanticInfo() const; SemanticInfo semanticInfo() const;
CPlusPlus::OverviewModel *overviewModel() const;
virtual void paste(); // reimplemented from BaseTextEditor virtual void paste(); // reimplemented from BaseTextEditor
virtual void cut(); // reimplemented from BaseTextEditor virtual void cut(); // reimplemented from BaseTextEditor
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include <coreplugin/ifile.h> #include <coreplugin/ifile.h>
#include <cplusplus/OverviewModel.h> #include <cplusplus/OverviewModel.h>
#include <QtGui/QVBoxLayout>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtGui/QVBoxLayout>
#include <QtCore/QTimer>
using namespace CppEditor::Internal; using namespace CppEditor::Internal;
...@@ -49,7 +50,7 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) : ...@@ -49,7 +50,7 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) :
TextEditor::IOutlineWidget(), TextEditor::IOutlineWidget(),
m_editor(editor), m_editor(editor),
m_treeView(new CppOutlineTreeView(this)), m_treeView(new CppOutlineTreeView(this)),
m_model(new CPlusPlus::OverviewModel(this)), m_model(m_editor->overviewModel()),
m_proxyModel(new CppOutlineFilterModel(this)), m_proxyModel(new CppOutlineFilterModel(this)),
m_enableCursorSync(true), m_enableCursorSync(true),
m_blockCursorSync(false) m_blockCursorSync(false)
...@@ -63,14 +64,8 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) : ...@@ -63,14 +64,8 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) :
m_proxyModel->setSourceModel(m_model); m_proxyModel->setSourceModel(m_model);
m_treeView->setModel(m_proxyModel); m_treeView->setModel(m_proxyModel);
CppTools::CppModelManagerInterface *modelManager = CppTools::CppModelManagerInterface::instance(); connect(m_model, SIGNAL(modelReset()), this, SLOT(modelUpdated()));
modelUpdated();
connect(modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SLOT(updateOutline(CPlusPlus::Document::Ptr)));
if (modelManager->snapshot().contains(editor->file()->fileName())) {
updateOutline(modelManager->snapshot().document(editor->file()->fileName()));
}
connect(m_editor, SIGNAL(cursorPositionChanged()), connect(m_editor, SIGNAL(cursorPositionChanged()),
this, SLOT(updateSelectionInTree())); this, SLOT(updateSelectionInTree()));
...@@ -85,18 +80,10 @@ void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor) ...@@ -85,18 +80,10 @@ void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor)
updateSelectionInTree(); updateSelectionInTree();
} }
void CppOutlineWidget::updateOutline(CPlusPlus::Document::Ptr document) void CppOutlineWidget::modelUpdated()
{ {
m_document = document; m_treeView->expandAll();
if (document && m_editor updateSelectionInTree();
&& (document->fileName() == m_editor->file()->fileName())
&& (document->editorRevision() == m_editor->editorRevision())) {
if (debug)
qDebug() << "CppOutline - rebuilding model";
m_model->rebuild(document);
m_treeView->expandAll();
updateSelectionInTree();
}
} }
void CppOutlineWidget::updateSelectionInTree() void CppOutlineWidget::updateSelectionInTree()
...@@ -130,7 +117,8 @@ void CppOutlineWidget::updateSelectionInText(const QItemSelection &selection) ...@@ -130,7 +117,8 @@ void CppOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (symbol) { if (symbol) {
m_blockCursorSync = true; m_blockCursorSync = true;
unsigned line, column; unsigned line, column;
m_document->translationUnit()->getPosition(symbol->startOffset(), &line, &column);
m_model->document()->translationUnit()->getPosition(symbol->startOffset(), &line, &column);
if (debug) if (debug)
qDebug() << "CppOutline - moving cursor to" << line << column - 1; qDebug() << "CppOutline - moving cursor to" << line << column - 1;
...@@ -161,9 +149,9 @@ QModelIndex CppOutlineWidget::indexForPosition(const QModelIndex &rootIndex, int ...@@ -161,9 +149,9 @@ QModelIndex CppOutlineWidget::indexForPosition(const QModelIndex &rootIndex, int
bool CppOutlineWidget::positionInsideSymbol(unsigned cursorLine, unsigned cursorColumn, CPlusPlus::Symbol *symbol) const bool CppOutlineWidget::positionInsideSymbol(unsigned cursorLine, unsigned cursorColumn, CPlusPlus::Symbol *symbol) const
{ {
if (!m_document) if (!m_model->document())
return false; return false;
CPlusPlus::TranslationUnit *translationUnit = m_document->translationUnit(); CPlusPlus::TranslationUnit *translationUnit = m_model->document()->translationUnit();
unsigned symbolStartLine = -1; unsigned symbolStartLine = -1;
unsigned symbolStartColumn = -1; unsigned symbolStartColumn = -1;
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
virtual void setCursorSynchronization(bool syncWithCursor); virtual void setCursorSynchronization(bool syncWithCursor);
private slots: private slots:
void updateOutline(CPlusPlus::Document::Ptr document); void modelUpdated();
void updateSelectionInTree(); void updateSelectionInTree();
void updateSelectionInText(const QItemSelection &selection); void updateSelectionInText(const QItemSelection &selection);
...@@ -52,7 +52,6 @@ private: ...@@ -52,7 +52,6 @@ private:
CppOutlineTreeView *m_treeView; CppOutlineTreeView *m_treeView;
CPlusPlus::OverviewModel *m_model; CPlusPlus::OverviewModel *m_model;
CppOutlineFilterModel *m_proxyModel; CppOutlineFilterModel *m_proxyModel;
CPlusPlus::Document::Ptr m_document;
bool m_enableCursorSync; bool m_enableCursorSync;
bool m_blockCursorSync; bool m_blockCursorSync;
......
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