summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-08-15 09:42:49 +0200
committerDavid Schulz <david.schulz@qt.io>2022-08-16 07:53:41 +0000
commitb39c7cd782c7e99b11ffd4977e7660be1f992d08 (patch)
tree9b010e95f07d1bdf5236f159c3249b3797031641
parent8703bcd777f8d1c7e903162f03254f81630ca428 (diff)
downloadqt-creator-b39c7cd782c7e99b11ffd4977e7660be1f992d08.tar.gz
CppEditor: remove unneeded indirection for the outline model
Change-Id: I01e9fb0dae30d6df22c0f5d7255ab247c48749fc Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/plugins/clangcodemodel/clangmodelmanagersupport.cpp1
-rw-r--r--src/plugins/cppeditor/CMakeLists.txt1
-rw-r--r--src/plugins/cppeditor/abstractoverviewmodel.h104
-rw-r--r--src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp5
-rw-r--r--src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h1
-rw-r--r--src/plugins/cppeditor/cppeditor.qbs1
-rw-r--r--src/plugins/cppeditor/cppeditoroutline.cpp17
-rw-r--r--src/plugins/cppeditor/cppeditoroutline.h6
-rw-r--r--src/plugins/cppeditor/cppmodelmanager.cpp7
-rw-r--r--src/plugins/cppeditor/cppmodelmanager.h3
-rw-r--r--src/plugins/cppeditor/cppmodelmanagersupport.h2
-rw-r--r--src/plugins/cppeditor/cppoutline.cpp6
-rw-r--r--src/plugins/cppeditor/cppoutline.h6
-rw-r--r--src/plugins/cppeditor/cppoverviewmodel.cpp38
-rw-r--r--src/plugins/cppeditor/cppoverviewmodel.h38
15 files changed, 86 insertions, 150 deletions
diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp
index 17617322fe..d8f61a3707 100644
--- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp
+++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp
@@ -38,7 +38,6 @@
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
-#include <cppeditor/abstractoverviewmodel.h>
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppeditorwidget.h>
diff --git a/src/plugins/cppeditor/CMakeLists.txt b/src/plugins/cppeditor/CMakeLists.txt
index e6463b77e5..d7836fc9cb 100644
--- a/src/plugins/cppeditor/CMakeLists.txt
+++ b/src/plugins/cppeditor/CMakeLists.txt
@@ -5,7 +5,6 @@ add_qtc_plugin(CppEditor
PLUGIN_TEST_DEPENDS QbsProjectManager QmakeProjectManager
SOURCES
abstracteditorsupport.cpp abstracteditorsupport.h
- abstractoverviewmodel.h
baseeditordocumentparser.cpp baseeditordocumentparser.h
baseeditordocumentprocessor.cpp baseeditordocumentprocessor.h
builtincursorinfo.cpp builtincursorinfo.h
diff --git a/src/plugins/cppeditor/abstractoverviewmodel.h b/src/plugins/cppeditor/abstractoverviewmodel.h
deleted file mode 100644
index 57fef64924..0000000000
--- a/src/plugins/cppeditor/abstractoverviewmodel.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** 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 "cppeditor_global.h"
-
-#include <utils/dropsupport.h>
-#include <utils/treemodel.h>
-
-#include <QSharedPointer>
-
-#include <utility>
-
-namespace CPlusPlus { class Document; }
-
-namespace Utils {
-class LineColumn;
-class Link;
-}
-
-namespace CppEditor {
-
-class CPPEDITOR_EXPORT AbstractOverviewModel : public Utils::TreeModel<>
-{
- Q_OBJECT
-
-public:
- enum Role {
- FileNameRole = Qt::UserRole + 1,
- LineNumberRole
- };
-
- virtual void rebuild(QSharedPointer<CPlusPlus::Document>) {}
- virtual bool rebuild(const QString &) { return false; }
-
- 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;
- for (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(Utils::FilePath::fromVariant(fileName),
- static_cast<int>(lineNumber.value<unsigned>()));
- }
- return mimeData;
- }
-
- virtual bool isGenerated(const QModelIndex &) const { return false; }
- virtual Utils::Link linkFromIndex(const QModelIndex &) const = 0;
- virtual Utils::LineColumn lineColumnFromIndex(const QModelIndex &) const = 0;
-
- using Range = std::pair<Utils::LineColumn, Utils::LineColumn>;
- virtual Range rangeFromIndex(const QModelIndex &) const = 0;
-
-signals:
- void needsUpdate();
-};
-
-} // namespace CppEditor
diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp
index 578d45098f..5c0a51b040 100644
--- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp
+++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp
@@ -113,11 +113,6 @@ TextEditor::BaseHoverHandler *BuiltinModelManagerSupport::createHoverHandler()
return new CppHoverHandler;
}
-std::unique_ptr<AbstractOverviewModel> BuiltinModelManagerSupport::createOverviewModel()
-{
- return std::make_unique<OverviewModel>();
-}
-
void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data,
const Utils::LinkHandler &processLinkCallback,
bool resolveTarget, bool inNextSplit)
diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h
index 620d9f8f38..36fea5e84f 100644
--- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h
+++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.h
@@ -43,7 +43,6 @@ public:
CppCompletionAssistProvider *completionAssistProvider();
TextEditor::BaseHoverHandler *createHoverHandler();
- std::unique_ptr<AbstractOverviewModel> createOverviewModel();
BaseEditorDocumentProcessor *createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) final;
diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs
index 989619b9be..9960d309f8 100644
--- a/src/plugins/cppeditor/cppeditor.qbs
+++ b/src/plugins/cppeditor/cppeditor.qbs
@@ -29,7 +29,6 @@ QtcPlugin {
files: [
"abstracteditorsupport.cpp",
"abstracteditorsupport.h",
- "abstractoverviewmodel.h",
"baseeditordocumentparser.cpp",
"baseeditordocumentparser.h",
"baseeditordocumentprocessor.cpp",
diff --git a/src/plugins/cppeditor/cppeditoroutline.cpp b/src/plugins/cppeditor/cppeditoroutline.cpp
index 62d1e3bf19..958ac01a7a 100644
--- a/src/plugins/cppeditor/cppeditoroutline.cpp
+++ b/src/plugins/cppeditor/cppeditoroutline.cpp
@@ -57,7 +57,7 @@ class OverviewProxyModel : public QSortFilterProxyModel
Q_OBJECT
public:
- OverviewProxyModel(CppEditor::AbstractOverviewModel &sourceModel, QObject *parent)
+ OverviewProxyModel(CppEditor::Internal::OverviewModel &sourceModel, QObject *parent)
: QSortFilterProxyModel(parent)
, m_sourceModel(sourceModel)
{
@@ -73,7 +73,7 @@ public:
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
private:
- CppEditor::AbstractOverviewModel &m_sourceModel;
+ CppEditor::Internal::OverviewModel &m_sourceModel;
};
QTimer *newSingleShotTimer(QObject *parent, int msInternal, const QString &objectName)
@@ -94,7 +94,7 @@ CppEditorOutline::CppEditorOutline(TextEditor::TextEditorWidget *editorWidget)
, m_editorWidget(editorWidget)
, m_combo(new Utils::TreeViewComboBox)
{
- m_model = CppModelManager::instance()->createOverviewModel();
+ m_model = std::make_unique<OverviewModel>();
m_proxyModel = new OverviewProxyModel(*m_model, this);
m_proxyModel->setSourceModel(m_model.get());
@@ -130,7 +130,7 @@ CppEditorOutline::CppEditorOutline(TextEditor::TextEditorWidget *editorWidget)
m_updateTimer = newSingleShotTimer(this, UpdateOutlineIntervalInMs,
QLatin1String("CppEditorOutline::m_updateTimer"));
connect(m_updateTimer, &QTimer::timeout, this, &CppEditorOutline::updateNow);
- connect(m_model.get(), &AbstractOverviewModel::needsUpdate, this,
+ connect(m_model.get(), &OverviewModel::needsUpdate, this,
&CppEditorOutline::updateNow);
m_updateIndexTimer = newSingleShotTimer(this, UpdateOutlineIntervalInMs,
@@ -148,7 +148,7 @@ bool CppEditorOutline::isSorted() const
return m_proxyModel->sortColumn() == 0;
}
-AbstractOverviewModel *CppEditorOutline::model() const
+OverviewModel *CppEditorOutline::model() const
{
return m_model.get();
}
@@ -189,8 +189,7 @@ void CppEditorOutline::updateNow()
return;
}
- if (!m_model->rebuild(filePath))
- m_model->rebuild(m_document);
+ m_model->rebuild(m_document);
m_combo->view()->expandAll();
updateIndexNow();
@@ -244,7 +243,7 @@ void CppEditorOutline::gotoSymbolInEditor()
emit m_editorWidget->activateEditor();
}
-static bool contains(const AbstractOverviewModel::Range &range, int line, int column)
+static bool contains(const OverviewModel::Range &range, int line, int column)
{
if (line < range.first.line || line > range.second.line)
return false;
@@ -262,7 +261,7 @@ QModelIndex CppEditorOutline::indexForPosition(int line, int column,
const int rowCount = m_model->rowCount(rootIndex);
for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = m_model->index(row, 0, rootIndex);
- const AbstractOverviewModel::Range range = m_model->rangeFromIndex(index);
+ const OverviewModel::Range range = m_model->rangeFromIndex(index);
if (range.first.line > line)
break;
// Skip ranges that do not include current line and column.
diff --git a/src/plugins/cppeditor/cppeditoroutline.h b/src/plugins/cppeditor/cppeditoroutline.h
index 39043866fe..59870bb656 100644
--- a/src/plugins/cppeditor/cppeditoroutline.h
+++ b/src/plugins/cppeditor/cppeditoroutline.h
@@ -25,7 +25,7 @@
#pragma once
-#include "abstractoverviewmodel.h"
+#include "cppoverviewmodel.h"
#include <QModelIndex>
#include <QObject>
@@ -52,7 +52,7 @@ public:
void update();
- AbstractOverviewModel *model() const;
+ OverviewModel *model() const;
QModelIndex modelIndex();
QWidget *widget() const; // Must be deleted by client.
@@ -77,7 +77,7 @@ private:
private:
QSharedPointer<CPlusPlus::Document> m_document;
- std::unique_ptr<AbstractOverviewModel> m_model;
+ std::unique_ptr<OverviewModel> m_model;
TextEditor::TextEditorWidget *m_editorWidget;
diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp
index a53c04ee68..fad28d90a8 100644
--- a/src/plugins/cppeditor/cppmodelmanager.cpp
+++ b/src/plugins/cppeditor/cppmodelmanager.cpp
@@ -26,7 +26,7 @@
#include "cppmodelmanager.h"
#include "abstracteditorsupport.h"
-#include "abstractoverviewmodel.h"
+#include "cppoverviewmodel.h"
#include "baseeditordocumentprocessor.h"
#include "builtinindexingsupport.h"
#include "cppcodemodelinspectordumper.h"
@@ -549,11 +549,6 @@ Core::ILocatorFilter *CppModelManager::currentDocumentFilter() const
return d->m_currentDocumentFilter.get();
}
-std::unique_ptr<AbstractOverviewModel> CppModelManager::createOverviewModel() const
-{
- return d->m_builtinModelManagerSupport.createOverviewModel();
-}
-
QString CppModelManager::configurationFileName()
{
return Preprocessor::configurationFileName();
diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h
index 32f5db0717..94df813dc2 100644
--- a/src/plugins/cppeditor/cppmodelmanager.h
+++ b/src/plugins/cppeditor/cppmodelmanager.h
@@ -61,7 +61,6 @@ class TextDocument;
namespace CppEditor {
class AbstractEditorSupport;
-class AbstractOverviewModel;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class CppEditorDocumentHandle;
@@ -203,8 +202,6 @@ public:
static Core::ILocatorFilter *createAuxiliaryCurrentDocumentFilter();
- std::unique_ptr<AbstractOverviewModel> createOverviewModel() const;
-
CppIndexingSupport *indexingSupport();
QStringList projectFiles();
diff --git a/src/plugins/cppeditor/cppmodelmanagersupport.h b/src/plugins/cppeditor/cppmodelmanagersupport.h
index 6ff57f0e6b..e7df47bb8d 100644
--- a/src/plugins/cppeditor/cppmodelmanagersupport.h
+++ b/src/plugins/cppeditor/cppmodelmanagersupport.h
@@ -42,7 +42,7 @@ class BaseHoverHandler;
namespace CppEditor {
-class AbstractOverviewModel;
+class OverviewModel;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class ProjectPart;
diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp
index dbb06361d0..30c86026a1 100644
--- a/src/plugins/cppeditor/cppoutline.cpp
+++ b/src/plugins/cppeditor/cppoutline.cpp
@@ -68,7 +68,7 @@ void CppOutlineTreeView::contextMenuEvent(QContextMenuEvent *event)
event->accept();
}
-CppOutlineFilterModel::CppOutlineFilterModel(AbstractOverviewModel &sourceModel,
+CppOutlineFilterModel::CppOutlineFilterModel(OverviewModel &sourceModel,
QObject *parent)
: QSortFilterProxyModel(parent)
, m_sourceModel(sourceModel)
@@ -102,7 +102,7 @@ CppOutlineWidget::CppOutlineWidget(CppEditorWidget *editor) :
m_blockCursorSync(false),
m_sorted(false)
{
- AbstractOverviewModel *model = m_editor->outline()->model();
+ OverviewModel *model = m_editor->outline()->model();
m_proxyModel = new CppOutlineFilterModel(*model, this);
m_proxyModel->setSourceModel(model);
@@ -179,7 +179,7 @@ void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index)
void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)
{
QModelIndex index = m_proxyModel->mapToSource(proxyIndex);
- AbstractOverviewModel *model = m_editor->outline()->model();
+ OverviewModel *model = m_editor->outline()->model();
Utils::LineColumn lineColumn = model->lineColumnFromIndex(index);
if (!lineColumn.isValid())
return;
diff --git a/src/plugins/cppeditor/cppoutline.h b/src/plugins/cppeditor/cppoutline.h
index 9c6e3e14d7..9da1fb9082 100644
--- a/src/plugins/cppeditor/cppoutline.h
+++ b/src/plugins/cppeditor/cppoutline.h
@@ -25,8 +25,8 @@
#pragma once
-#include "abstractoverviewmodel.h"
#include "cppeditorwidget.h"
+#include "cppoverviewmodel.h"
#include <texteditor/ioutlinewidget.h>
@@ -50,13 +50,13 @@ class CppOutlineFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
- CppOutlineFilterModel(AbstractOverviewModel &sourceModel, QObject *parent);
+ CppOutlineFilterModel(OverviewModel &sourceModel, QObject *parent);
// QSortFilterProxyModel
bool filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const override;
Qt::DropActions supportedDragActions() const override;
private:
- AbstractOverviewModel &m_sourceModel;
+ OverviewModel &m_sourceModel;
};
class CppOutlineWidget : public TextEditor::IOutlineWidget
diff --git a/src/plugins/cppeditor/cppoverviewmodel.cpp b/src/plugins/cppeditor/cppoverviewmodel.cpp
index de7a8df2f4..9e032ce922 100644
--- a/src/plugins/cppeditor/cppoverviewmodel.cpp
+++ b/src/plugins/cppeditor/cppoverviewmodel.cpp
@@ -126,10 +126,10 @@ public:
case Qt::DecorationRole:
return Icons::iconForSymbol(symbol);
- case AbstractOverviewModel::FileNameRole:
+ case OverviewModel::FileNameRole:
return QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
- case AbstractOverviewModel::LineNumberRole:
+ case OverviewModel::LineNumberRole:
return symbol->line();
default:
@@ -168,6 +168,40 @@ Symbol *OverviewModel::symbolFromIndex(const QModelIndex &index) const
return item ? item->symbol : nullptr;
}
+Qt::ItemFlags OverviewModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return Qt::NoItemFlags;
+
+ 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;
+ for (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(Utils::FilePath::fromVariant(fileName),
+ static_cast<int>(lineNumber.value<unsigned>()));
+ }
+ return mimeData;
+}
+
void OverviewModel::rebuild(Document::Ptr doc)
{
beginResetModel();
diff --git a/src/plugins/cppeditor/cppoverviewmodel.h b/src/plugins/cppeditor/cppoverviewmodel.h
index 27911f7085..0ac9787c89 100644
--- a/src/plugins/cppeditor/cppoverviewmodel.h
+++ b/src/plugins/cppeditor/cppoverviewmodel.h
@@ -25,25 +25,49 @@
#pragma once
-#include "abstractoverviewmodel.h"
+#include <utils/dropsupport.h>
+#include <utils/treemodel.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/Overview.h>
+#include <QSharedPointer>
+
+#include <utility>
+
+namespace Utils {
+class LineColumn;
+class Link;
+} // namespace Utils
+
namespace CppEditor::Internal {
class SymbolItem;
-class OverviewModel : public AbstractOverviewModel
+class OverviewModel : public Utils::TreeModel<>
{
Q_OBJECT
public:
- void rebuild(CPlusPlus::Document::Ptr doc) override;
+ enum Role {
+ FileNameRole = Qt::UserRole + 1,
+ LineNumberRole
+ };
+
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+ Qt::DropActions supportedDragActions() const override;
+ QStringList mimeTypes() const override;
+ QMimeData *mimeData(const QModelIndexList &indexes) const override;
+
+ void rebuild(CPlusPlus::Document::Ptr doc);
+
+ bool isGenerated(const QModelIndex &sourceIndex) const;
+ Utils::Link linkFromIndex(const QModelIndex &sourceIndex) const;
+ Utils::LineColumn lineColumnFromIndex(const QModelIndex &sourceIndex) const;
+ using Range = std::pair<Utils::LineColumn, Utils::LineColumn>;
+ Range rangeFromIndex(const QModelIndex &sourceIndex) const;
- bool isGenerated(const QModelIndex &sourceIndex) const override;
- Utils::Link linkFromIndex(const QModelIndex &sourceIndex) const override;
- Utils::LineColumn lineColumnFromIndex(const QModelIndex &sourceIndex) const override;
- Range rangeFromIndex(const QModelIndex &sourceIndex) const override;
+signals:
+ void needsUpdate();
private:
CPlusPlus::Symbol *symbolFromIndex(const QModelIndex &index) const;