forked from qt-creator/qt-creator
CPlusPlus: CppEditor: refactor overview model
Introduce abstract model to be able to use clang based version of it in follow up patches. Fix warnings and modernize source code a little. Move OverviewModel to CppTools. Change-Id: Idcc9bf03cad047026a456bd01063597a1eb95147 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -17,15 +17,13 @@ HEADERS += \
|
||||
$$PWD/Icons.h \
|
||||
$$PWD/ExpressionUnderCursor.h \
|
||||
$$PWD/BackwardsScanner.h \
|
||||
$$PWD/MatchingText.h \
|
||||
$$PWD/OverviewModel.h
|
||||
$$PWD/MatchingText.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/Icons.cpp \
|
||||
$$PWD/ExpressionUnderCursor.cpp \
|
||||
$$PWD/BackwardsScanner.cpp \
|
||||
$$PWD/MatchingText.cpp \
|
||||
$$PWD/OverviewModel.cpp
|
||||
$$PWD/MatchingText.cpp
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
|
@@ -113,7 +113,6 @@ Project {
|
||||
"MatchingText.cpp", "MatchingText.h",
|
||||
"NamePrettyPrinter.cpp", "NamePrettyPrinter.h",
|
||||
"Overview.cpp", "Overview.h",
|
||||
"OverviewModel.cpp", "OverviewModel.h",
|
||||
"PPToken.cpp", "PPToken.h",
|
||||
"PreprocessorClient.cpp", "PreprocessorClient.h",
|
||||
"PreprocessorEnvironment.cpp", "PreprocessorEnvironment.h",
|
||||
|
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <cpptools/cppeditoroutline.h>
|
||||
|
||||
#include <cplusplus/OverviewModel.h>
|
||||
#include <cpptools/cppoverviewmodel.h>
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
@@ -42,10 +42,6 @@
|
||||
namespace CppEditor {
|
||||
namespace Internal {
|
||||
|
||||
enum {
|
||||
debug = false
|
||||
};
|
||||
|
||||
CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) :
|
||||
Utils::NavigationTreeView(parent)
|
||||
{
|
||||
@@ -71,11 +67,11 @@ void CppOutlineTreeView::contextMenuEvent(QContextMenuEvent *event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
CppOutlineFilterModel::CppOutlineFilterModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
m_sourceModel(sourceModel)
|
||||
CppOutlineFilterModel::CppOutlineFilterModel(CppTools::AbstractOverviewModel *sourceModel,
|
||||
QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
, m_sourceModel(sourceModel)
|
||||
{
|
||||
setSourceModel(m_sourceModel);
|
||||
}
|
||||
|
||||
bool CppOutlineFilterModel::filterAcceptsRow(int sourceRow,
|
||||
@@ -104,11 +100,13 @@ CppOutlineWidget::CppOutlineWidget(CppEditorWidget *editor) :
|
||||
m_editor(editor),
|
||||
m_treeView(new CppOutlineTreeView(this)),
|
||||
m_model(m_editor->outline()->model()),
|
||||
m_proxyModel(new CppOutlineFilterModel(m_model, this)),
|
||||
m_enableCursorSync(true),
|
||||
m_blockCursorSync(false)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
m_proxyModel = new CppOutlineFilterModel(m_model, this);
|
||||
m_proxyModel->setSourceModel(m_model);
|
||||
|
||||
auto *layout = new QVBoxLayout;
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(Core::ItemViewFind::createSearchableWrapper(m_treeView));
|
||||
@@ -151,9 +149,6 @@ void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index)
|
||||
QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
|
||||
|
||||
m_blockCursorSync = true;
|
||||
if (debug)
|
||||
qDebug() << "CppOutline - updating selection due to cursor move";
|
||||
|
||||
m_treeView->setCurrentIndex(proxyIndex);
|
||||
m_treeView->scrollTo(proxyIndex);
|
||||
m_blockCursorSync = false;
|
||||
@@ -166,14 +161,12 @@ void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)
|
||||
if (symbol) {
|
||||
m_blockCursorSync = true;
|
||||
|
||||
if (debug)
|
||||
qDebug() << "CppOutline - moving cursor to" << symbol->line() << symbol->column() - 1;
|
||||
|
||||
Core::EditorManager::cutForwardNavigationHistory();
|
||||
Core::EditorManager::addCurrentPositionToNavigationHistory();
|
||||
|
||||
// line has to be 1 based, column 0 based!
|
||||
m_editor->gotoLine(symbol->line(), symbol->column() - 1, true, true);
|
||||
m_editor->gotoLine(static_cast<int>(symbol->line()), static_cast<int>(symbol->column() - 1),
|
||||
true, true);
|
||||
m_blockCursorSync = false;
|
||||
}
|
||||
}
|
||||
@@ -194,18 +187,16 @@ bool CppOutlineWidget::syncCursor()
|
||||
|
||||
bool CppOutlineWidgetFactory::supportsEditor(Core::IEditor *editor) const
|
||||
{
|
||||
if (qobject_cast<CppEditor*>(editor))
|
||||
return true;
|
||||
return false;
|
||||
return qobject_cast<CppEditor*>(editor);
|
||||
}
|
||||
|
||||
TextEditor::IOutlineWidget *CppOutlineWidgetFactory::createWidget(Core::IEditor *editor)
|
||||
{
|
||||
CppEditor *cppEditor = qobject_cast<CppEditor*>(editor);
|
||||
CppEditorWidget *cppEditorWidget = qobject_cast<CppEditorWidget*>(cppEditor->widget());
|
||||
QTC_ASSERT(cppEditorWidget, return 0);
|
||||
auto *cppEditor = qobject_cast<CppEditor*>(editor);
|
||||
auto *cppEditorWidget = qobject_cast<CppEditorWidget*>(cppEditor->widget());
|
||||
QTC_ASSERT(cppEditorWidget, return nullptr);
|
||||
|
||||
CppOutlineWidget *widget = new CppOutlineWidget(cppEditorWidget);
|
||||
auto *widget = new CppOutlineWidget(cppEditorWidget);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@@ -30,12 +30,11 @@
|
||||
|
||||
#include <texteditor/ioutlinewidget.h>
|
||||
|
||||
#include <cpptools/abstractoverviewmodel.h>
|
||||
#include <utils/navigationtreeview.h>
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
namespace CPlusPlus { class OverviewModel; }
|
||||
|
||||
namespace CppEditor {
|
||||
namespace Internal {
|
||||
|
||||
@@ -45,20 +44,20 @@ class CppOutlineTreeView : public Utils::NavigationTreeView
|
||||
public:
|
||||
CppOutlineTreeView(QWidget *parent);
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
};
|
||||
|
||||
class CppOutlineFilterModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CppOutlineFilterModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent);
|
||||
CppOutlineFilterModel(CppTools::AbstractOverviewModel *sourceModel, QObject *parent);
|
||||
// QSortFilterProxyModel
|
||||
bool filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const;
|
||||
Qt::DropActions supportedDragActions() const;
|
||||
const QModelIndex &sourceParent) const override;
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
private:
|
||||
CPlusPlus::OverviewModel *m_sourceModel;
|
||||
CppTools::AbstractOverviewModel *m_sourceModel;
|
||||
};
|
||||
|
||||
class CppOutlineWidget : public TextEditor::IOutlineWidget
|
||||
@@ -68,8 +67,8 @@ public:
|
||||
CppOutlineWidget(CppEditorWidget *editor);
|
||||
|
||||
// IOutlineWidget
|
||||
virtual QList<QAction*> filterMenuActions() const;
|
||||
virtual void setCursorSynchronization(bool syncWithCursor);
|
||||
QList<QAction*> filterMenuActions() const override;
|
||||
void setCursorSynchronization(bool syncWithCursor) override;
|
||||
|
||||
private:
|
||||
void modelUpdated();
|
||||
@@ -81,8 +80,8 @@ private:
|
||||
private:
|
||||
CppEditorWidget *m_editor;
|
||||
CppOutlineTreeView *m_treeView;
|
||||
CPlusPlus::OverviewModel *m_model;
|
||||
CppOutlineFilterModel *m_proxyModel;
|
||||
CppTools::AbstractOverviewModel *m_model;
|
||||
QSortFilterProxyModel *m_proxyModel;
|
||||
|
||||
bool m_enableCursorSync;
|
||||
bool m_blockCursorSync;
|
||||
@@ -92,8 +91,8 @@ class CppOutlineWidgetFactory : public TextEditor::IOutlineWidgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool supportsEditor(Core::IEditor *editor) const;
|
||||
TextEditor::IOutlineWidget *createWidget(Core::IEditor *editor);
|
||||
bool supportsEditor(Core::IEditor *editor) const override;
|
||||
TextEditor::IOutlineWidget *createWidget(Core::IEditor *editor) override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
100
src/plugins/cpptools/abstractoverviewmodel.h
Normal file
100
src/plugins/cpptools/abstractoverviewmodel.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <utils/dropsupport.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace CPlusPlus {
|
||||
class Document;
|
||||
class Symbol;
|
||||
}
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
class CPPTOOLS_EXPORT AbstractOverviewModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Role {
|
||||
FileNameRole = Qt::UserRole + 1,
|
||||
LineNumberRole
|
||||
};
|
||||
|
||||
AbstractOverviewModel(QObject *parent = nullptr) : QAbstractItemModel(parent) {}
|
||||
|
||||
virtual QSharedPointer<CPlusPlus::Document> document() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual CPlusPlus::Symbol *symbolFromIndex(const QModelIndex &) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void rebuild(QSharedPointer<CPlusPlus::Document>) {}
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
|
||||
Qt::DropActions supportedDragActions() const override
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList mimeTypes() const override
|
||||
{
|
||||
return Utils::DropSupport::mimeTypesForFilePaths();
|
||||
}
|
||||
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override
|
||||
{
|
||||
auto mimeData = new Utils::DropMimeData;
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
const QVariant fileName = data(index, FileNameRole);
|
||||
if (!fileName.canConvert<QString>())
|
||||
continue;
|
||||
const QVariant lineNumber = data(index, LineNumberRole);
|
||||
if (!lineNumber.canConvert<unsigned>())
|
||||
continue;
|
||||
mimeData->addFile(fileName.toString(), static_cast<int>(lineNumber.value<unsigned>()));
|
||||
}
|
||||
return mimeData;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
@@ -25,14 +25,15 @@
|
||||
|
||||
#include "cppeditoroutline.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <cpptools/cpptoolssettings.h>
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cppoverviewmodel.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "cpptoolssettings.h"
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <cplusplus/OverviewModel.h>
|
||||
#include <utils/treeviewcombobox.h>
|
||||
|
||||
#include <QAction>
|
||||
@@ -56,14 +57,13 @@ class OverviewProxyModel : public QSortFilterProxyModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OverviewProxyModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent)
|
||||
OverviewProxyModel(CppTools::AbstractOverviewModel *sourceModel, QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
, m_sourceModel(sourceModel)
|
||||
{
|
||||
setSourceModel(m_sourceModel);
|
||||
}
|
||||
|
||||
bool filterAcceptsRow(int sourceRow,const QModelIndex &sourceParent) const
|
||||
bool filterAcceptsRow(int sourceRow,const QModelIndex &sourceParent) const override
|
||||
{
|
||||
// Ignore generated symbols, e.g. by macro expansion (Q_OBJECT)
|
||||
const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0, sourceParent);
|
||||
@@ -74,12 +74,12 @@ public:
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
private:
|
||||
CPlusPlus::OverviewModel *m_sourceModel;
|
||||
CppTools::AbstractOverviewModel *m_sourceModel;
|
||||
};
|
||||
|
||||
QTimer *newSingleShotTimer(QObject *parent, int msInternal, const QString &objectName)
|
||||
{
|
||||
QTimer *timer = new QTimer(parent);
|
||||
auto *timer = new QTimer(parent);
|
||||
timer->setObjectName(objectName);
|
||||
timer->setSingleShot(true);
|
||||
timer->setInterval(msInternal);
|
||||
@@ -94,9 +94,11 @@ CppEditorOutline::CppEditorOutline(TextEditor::TextEditorWidget *editorWidget)
|
||||
: QObject(editorWidget)
|
||||
, m_editorWidget(editorWidget)
|
||||
, m_combo(new Utils::TreeViewComboBox)
|
||||
, m_model(new CPlusPlus::OverviewModel(this))
|
||||
, m_proxyModel(new OverviewProxyModel(m_model, this))
|
||||
{
|
||||
m_model = new CppTools::OverviewModel(this);
|
||||
m_proxyModel = new OverviewProxyModel(m_model, this);
|
||||
m_proxyModel->setSourceModel(m_model);
|
||||
|
||||
// Set up proxy model
|
||||
if (CppTools::CppToolsSettings::instance()->sortedEditorDocumentOutline())
|
||||
m_proxyModel->sort(0, Qt::AscendingOrder);
|
||||
@@ -163,7 +165,7 @@ void CppEditorOutline::setSorted(bool sort)
|
||||
}
|
||||
}
|
||||
|
||||
CPlusPlus::OverviewModel *CppEditorOutline::model() const
|
||||
CppTools::AbstractOverviewModel *CppEditorOutline::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
@@ -194,7 +196,8 @@ void CppEditorOutline::updateNow()
|
||||
if (!document)
|
||||
return;
|
||||
|
||||
if (document->editorRevision() != (unsigned) m_editorWidget->document()->revision()) {
|
||||
if (document->editorRevision()
|
||||
!= static_cast<unsigned>(m_editorWidget->document()->revision())) {
|
||||
m_updateTimer->start();
|
||||
return;
|
||||
}
|
||||
@@ -212,11 +215,12 @@ void CppEditorOutline::updateIndex()
|
||||
|
||||
void CppEditorOutline::updateIndexNow()
|
||||
{
|
||||
if (!m_model->document())
|
||||
const CPlusPlus::Document::Ptr document = m_model->document();
|
||||
if (!document)
|
||||
return;
|
||||
|
||||
const unsigned revision = m_editorWidget->document()->revision();
|
||||
if (m_model->document()->editorRevision() != revision) {
|
||||
const auto revision = static_cast<unsigned>(m_editorWidget->document()->revision());
|
||||
if (document->editorRevision() != revision) {
|
||||
m_updateIndexTimer->start();
|
||||
return;
|
||||
}
|
||||
@@ -253,7 +257,7 @@ void CppEditorOutline::gotoSymbolInEditor()
|
||||
Core::EditorManager::cutForwardNavigationHistory();
|
||||
Core::EditorManager::addCurrentPositionToNavigationHistory();
|
||||
m_editorWidget->gotoLine(link.targetLine, link.targetColumn, true, true);
|
||||
m_editorWidget->activateEditor();
|
||||
emit m_editorWidget->activateEditor();
|
||||
}
|
||||
|
||||
QModelIndex CppEditorOutline::indexForPosition(int line, int column,
|
||||
|
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include "abstractoverviewmodel.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QObject>
|
||||
|
||||
@@ -36,7 +38,6 @@ class QSortFilterProxyModel;
|
||||
class QTimer;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace CPlusPlus { class OverviewModel; }
|
||||
namespace TextEditor { class TextEditorWidget; }
|
||||
namespace Utils { class TreeViewComboBox; }
|
||||
|
||||
@@ -51,7 +52,7 @@ public:
|
||||
|
||||
void update();
|
||||
|
||||
CPlusPlus::OverviewModel *model() const;
|
||||
AbstractOverviewModel *model() const;
|
||||
QModelIndex modelIndex();
|
||||
|
||||
QWidget *widget() const; // Must be deleted by client.
|
||||
@@ -79,7 +80,7 @@ private:
|
||||
TextEditor::TextEditorWidget *m_editorWidget;
|
||||
|
||||
Utils::TreeViewComboBox *m_combo; // Not owned
|
||||
CPlusPlus::OverviewModel *m_model;
|
||||
AbstractOverviewModel *m_model;
|
||||
QSortFilterProxyModel *m_proxyModel;
|
||||
QModelIndex m_modelIndex;
|
||||
QAction *m_sortAction;
|
||||
|
@@ -23,20 +23,21 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "OverviewModel.h"
|
||||
|
||||
#include "Overview.h"
|
||||
#include "cppoverviewmodel.h"
|
||||
|
||||
#include <cplusplus/Icons.h>
|
||||
#include <cplusplus/Scope.h>
|
||||
#include <cplusplus/Literals.h>
|
||||
#include <cplusplus/Overview.h>
|
||||
#include <cplusplus/Scope.h>
|
||||
#include <cplusplus/Symbols.h>
|
||||
|
||||
#include <utils/dropsupport.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
namespace CppTools {
|
||||
|
||||
OverviewModel::OverviewModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
: AbstractOverviewModel(parent)
|
||||
{ }
|
||||
|
||||
OverviewModel::~OverviewModel()
|
||||
@@ -68,10 +69,11 @@ QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent)
|
||||
if (!parent.isValid()) {
|
||||
if (row == 0) // account for no symbol item
|
||||
return createIndex(row, column);
|
||||
Symbol *symbol = globalSymbolAt(row-1); // account for no symbol item
|
||||
Symbol *symbol = globalSymbolAt(static_cast<unsigned>(row-1)); // account for no symbol item
|
||||
return createIndex(row, column, symbol);
|
||||
} else {
|
||||
Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer());
|
||||
Symbol *parentSymbol = static_cast<Symbol *>(
|
||||
parent.internalPointer());
|
||||
Q_ASSERT(parentSymbol);
|
||||
|
||||
if (Template *t = parentSymbol->asTemplate())
|
||||
@@ -79,8 +81,8 @@ QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent)
|
||||
parentSymbol = templateParentSymbol;
|
||||
|
||||
Scope *scope = parentSymbol->asScope();
|
||||
Q_ASSERT(scope != 0);
|
||||
return createIndex(row, 0, scope->memberAt(row));
|
||||
Q_ASSERT(scope != nullptr);
|
||||
return createIndex(row, 0, scope->memberAt(static_cast<unsigned>(row)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +98,9 @@ QModelIndex OverviewModel::parent(const QModelIndex &child) const
|
||||
if (scope->enclosingScope()) {
|
||||
QModelIndex index;
|
||||
if (scope->enclosingScope() && scope->enclosingScope()->enclosingScope()) // the parent doesn't have a parent
|
||||
index = createIndex(scope->index(), 0, scope);
|
||||
index = createIndex(static_cast<int>(scope->index()), 0, scope);
|
||||
else //+1 to account for no symbol item
|
||||
index = createIndex(scope->index() + 1, 0, scope);
|
||||
index = createIndex(static_cast<int>(scope->index() + 1), 0, scope);
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -110,11 +112,12 @@ int OverviewModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (hasDocument()) {
|
||||
if (!parent.isValid()) {
|
||||
return globalSymbolCount()+1; // account for no symbol item
|
||||
return static_cast<int>(globalSymbolCount() + 1); // account for no symbol item
|
||||
} else {
|
||||
if (!parent.parent().isValid() && parent.row() == 0) // account for no symbol item
|
||||
return 0;
|
||||
Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer());
|
||||
Symbol *parentSymbol = static_cast<Symbol *>(
|
||||
parent.internalPointer());
|
||||
Q_ASSERT(parentSymbol);
|
||||
|
||||
if (Template *t = parentSymbol->asTemplate())
|
||||
@@ -123,7 +126,7 @@ int OverviewModel::rowCount(const QModelIndex &parent) const
|
||||
|
||||
if (Scope *parentScope = parentSymbol->asScope()) {
|
||||
if (!parentScope->isFunction() && !parentScope->isObjCMethod())
|
||||
return parentScope->memberCount();
|
||||
return static_cast<int>(parentScope->memberCount());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -173,15 +176,17 @@ QVariant OverviewModel::data(const QModelIndex &index, int role) const
|
||||
else
|
||||
name = QLatin1String("@implementation ") + name;
|
||||
|
||||
if (clazz->isCategory())
|
||||
name += QLatin1String(" (") + _overview.prettyName(clazz->categoryName()) + QLatin1Char(')');
|
||||
if (clazz->isCategory()) {
|
||||
name += QLatin1String(" (") + _overview.prettyName(clazz->categoryName())
|
||||
+ QLatin1Char(')');
|
||||
}
|
||||
}
|
||||
if (symbol->isObjCPropertyDeclaration())
|
||||
name = QLatin1String("@property ") + name;
|
||||
if (Template *t = symbol->asTemplate())
|
||||
if (Symbol *templateDeclaration = t->declaration()) {
|
||||
QStringList parameters;
|
||||
parameters.reserve(t->templateParameterCount());
|
||||
parameters.reserve(static_cast<int>(t->templateParameterCount()));
|
||||
for (unsigned i = 0; i < t->templateParameterCount(); ++i)
|
||||
parameters.append(_overview.prettyName(t->templateParameterAt(i)->name()));
|
||||
name += QLatin1Char('<') + parameters.join(QLatin1String(", ")) + QLatin1Char('>');
|
||||
@@ -216,11 +221,11 @@ QVariant OverviewModel::data(const QModelIndex &index, int role) const
|
||||
case Qt::DecorationRole: {
|
||||
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
||||
return Icons::iconForSymbol(symbol);
|
||||
} break;
|
||||
}
|
||||
|
||||
case FileNameRole: {
|
||||
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
||||
return QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
|
||||
return QString::fromUtf8(symbol->fileName(), static_cast<int>(symbol->fileNameLength()));
|
||||
}
|
||||
|
||||
case LineNumberRole: {
|
||||
@@ -245,36 +250,4 @@ void OverviewModel::rebuild(Document::Ptr doc)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
Qt::ItemFlags OverviewModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
|
||||
Qt::DropActions OverviewModel::supportedDragActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList OverviewModel::mimeTypes() const
|
||||
{
|
||||
return Utils::DropSupport::mimeTypesForFilePaths();
|
||||
}
|
||||
|
||||
QMimeData *OverviewModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
auto mimeData = new Utils::DropMimeData;
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
const QVariant fileName = data(index, FileNameRole);
|
||||
if (!fileName.canConvert<QString>())
|
||||
continue;
|
||||
const QVariant lineNumber = data(index, LineNumberRole);
|
||||
if (!fileName.canConvert<unsigned>())
|
||||
continue;
|
||||
mimeData->addFile(fileName.toString(), lineNumber.value<unsigned>());
|
||||
}
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
@@ -25,51 +25,41 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CppDocument.h"
|
||||
#include "Overview.h"
|
||||
#include "abstractoverviewmodel.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/Overview.h>
|
||||
|
||||
namespace CPlusPlus {
|
||||
namespace CppTools {
|
||||
|
||||
class CPLUSPLUS_EXPORT OverviewModel : public QAbstractItemModel
|
||||
class CPPTOOLS_EXPORT OverviewModel : public AbstractOverviewModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Role {
|
||||
FileNameRole = Qt::UserRole + 1,
|
||||
LineNumberRole
|
||||
};
|
||||
OverviewModel(QObject *parent = nullptr);
|
||||
~OverviewModel() override;
|
||||
|
||||
public:
|
||||
OverviewModel(QObject *parent = 0);
|
||||
virtual ~OverviewModel();
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QModelIndex parent(const QModelIndex &child) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
CPlusPlus::Document::Ptr document() const override;
|
||||
CPlusPlus::Symbol *symbolFromIndex(const QModelIndex &index) const override;
|
||||
|
||||
Document::Ptr document() const;
|
||||
Symbol *symbolFromIndex(const QModelIndex &index) const;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
Qt::DropActions supportedDragActions() const;
|
||||
QStringList mimeTypes() const;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
|
||||
void rebuild(Document::Ptr doc);
|
||||
void rebuild(CPlusPlus::Document::Ptr doc) override;
|
||||
|
||||
private:
|
||||
bool hasDocument() const;
|
||||
unsigned globalSymbolCount() const;
|
||||
Symbol *globalSymbolAt(unsigned index) const;
|
||||
CPlusPlus::Symbol *globalSymbolAt(unsigned index) const;
|
||||
|
||||
private:
|
||||
Document::Ptr _cppDocument;
|
||||
Overview _overview;
|
||||
CPlusPlus::Document::Ptr _cppDocument;
|
||||
CPlusPlus::Overview _overview;
|
||||
};
|
||||
|
||||
} // namespace CPlusPlus
|
||||
} // namespace CppTools
|
@@ -4,6 +4,7 @@ include(../../qtcreatorplugin.pri)
|
||||
|
||||
HEADERS += \
|
||||
abstracteditorsupport.h \
|
||||
abstractoverviewmodel.h \
|
||||
baseeditordocumentparser.h \
|
||||
baseeditordocumentprocessor.h \
|
||||
builtincursorinfo.h \
|
||||
@@ -47,6 +48,7 @@ HEADERS += \
|
||||
cppmodelmanager.h \
|
||||
cppmodelmanagersupport.h \
|
||||
cppmodelmanagersupportinternal.h \
|
||||
cppoverviewmodel.h \
|
||||
cpppointerdeclarationformatter.h \
|
||||
cppprojectfile.h \
|
||||
cppprojectupdater.h \
|
||||
@@ -142,6 +144,7 @@ SOURCES += \
|
||||
cppmodelmanager.cpp \
|
||||
cppmodelmanagersupport.cpp \
|
||||
cppmodelmanagersupportinternal.cpp \
|
||||
cppoverviewmodel.cpp \
|
||||
cpppointerdeclarationformatter.cpp \
|
||||
cppprojectfile.cpp \
|
||||
cppprojectupdater.cpp \
|
||||
|
@@ -30,6 +30,7 @@ Project {
|
||||
files: [
|
||||
"abstracteditorsupport.cpp",
|
||||
"abstracteditorsupport.h",
|
||||
"abstractoverviewmodel.h",
|
||||
"baseeditordocumentparser.cpp",
|
||||
"baseeditordocumentparser.h",
|
||||
"baseeditordocumentprocessor.cpp",
|
||||
@@ -121,6 +122,8 @@ Project {
|
||||
"cppmodelmanagersupport.h",
|
||||
"cppmodelmanagersupportinternal.cpp",
|
||||
"cppmodelmanagersupportinternal.h",
|
||||
"cppoverviewmodel.cpp",
|
||||
"cppoverviewmodel.h",
|
||||
"cpppointerdeclarationformatter.cpp",
|
||||
"cpppointerdeclarationformatter.h",
|
||||
"cppprojectfile.cpp",
|
||||
|
Reference in New Issue
Block a user