forked from qt-creator/qt-creator
Clang: Introduce OverviewModel for clang
Change-Id: I1473e3f679f4345a04c55f1ee80cfe35e21a4347 Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -28,8 +28,8 @@
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <utils/dropsupport.h>
|
||||
#include <utils/treemodel.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace CPlusPlus { class Document; }
|
||||
@@ -41,7 +41,7 @@ struct Link;
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
class CPPTOOLS_EXPORT AbstractOverviewModel : public QAbstractItemModel
|
||||
class CPPTOOLS_EXPORT AbstractOverviewModel : public Utils::TreeModel<>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -51,9 +51,8 @@ public:
|
||||
LineNumberRole
|
||||
};
|
||||
|
||||
AbstractOverviewModel() : QAbstractItemModel(nullptr) {}
|
||||
|
||||
virtual void rebuild(QSharedPointer<CPlusPlus::Document>) {}
|
||||
virtual bool rebuild(const QString &) { return false; }
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override
|
||||
{
|
||||
|
||||
@@ -186,23 +186,28 @@ QWidget *CppEditorOutline::widget() const
|
||||
return m_combo;
|
||||
}
|
||||
|
||||
void CppEditorOutline::updateNow()
|
||||
QSharedPointer<CPlusPlus::Document> getDocument(const QString &filePath)
|
||||
{
|
||||
CppTools::CppModelManager *cmmi = CppTools::CppModelManager::instance();
|
||||
const CPlusPlus::Snapshot snapshot = cmmi->snapshot();
|
||||
return snapshot.document(filePath);
|
||||
}
|
||||
|
||||
void CppEditorOutline::updateNow()
|
||||
{
|
||||
const QString filePath = m_editorWidget->textDocument()->filePath().toString();
|
||||
CPlusPlus::Document::Ptr document = snapshot.document(filePath);
|
||||
if (!document)
|
||||
m_document = getDocument(filePath);
|
||||
if (!m_document)
|
||||
return;
|
||||
|
||||
m_document = document;
|
||||
if (m_document->editorRevision()
|
||||
!= static_cast<unsigned>(m_editorWidget->document()->revision())) {
|
||||
m_updateTimer->start();
|
||||
return;
|
||||
}
|
||||
|
||||
m_model->rebuild(m_document);
|
||||
if (!m_model->rebuild(filePath))
|
||||
m_model->rebuild(m_document);
|
||||
|
||||
m_combo->view()->expandAll();
|
||||
updateIndexNow();
|
||||
|
||||
Reference in New Issue
Block a user