aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor/cppoutlinemodel.h
blob: ce499c91a0a71684bf1d66cba654c9736b8ff2d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <utils/dropsupport.h>
#include <utils/textutils.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 OutlineModel : public Utils::TreeModel<>
{
    Q_OBJECT

public:
    explicit OutlineModel(QObject *parent = nullptr);

    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 update(CPlusPlus::Document::Ptr doc);

    int editorRevision();

    bool isGenerated(const QModelIndex &sourceIndex) const;
    Utils::Link linkFromIndex(const QModelIndex &sourceIndex) const;
    Utils::Text::Position positionFromIndex(const QModelIndex &sourceIndex) const;
    using Range = std::pair<Utils::Text::Position, Utils::Text::Position>;
    Range rangeFromIndex(const QModelIndex &sourceIndex) const;

    // line is 1-based and column is 0-based
    QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = {}) const;

private:
    void rebuild();
    CPlusPlus::Symbol *symbolFromIndex(const QModelIndex &index) const;
    int globalSymbolCount() const;
    CPlusPlus::Symbol *globalSymbolAt(int index) const;
    void buildTree(SymbolItem *root, bool isRoot);

private:
    CPlusPlus::Document::Ptr m_candidate;
    CPlusPlus::Document::Ptr m_cppDocument;
    CPlusPlus::Overview m_overview;
    friend class SymbolItem;
    QTimer *m_updateTimer = nullptr;
};

} // namespace CppEditor::Internal