File: breakpointmodel.h

package info (click to toggle)
kdevelop 4%3A24.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 71,888 kB
  • sloc: cpp: 290,869; python: 3,626; javascript: 3,518; sh: 1,316; ansic: 703; xml: 401; php: 95; lisp: 66; makefile: 31; sed: 12
file content (235 lines) | stat: -rw-r--r-- 7,733 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
    SPDX-FileCopyrightText: 2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
    SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
    SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/


#ifndef KDEVPLATFORM_BREAKPOINTMODEL_H
#define KDEVPLATFORM_BREAKPOINTMODEL_H

#include "breakpoint.h"

#include <util/namespacedoperatorbitwiseorworkaroundqtbug.h>

#include <KTextEditor/Document>

#include <QAbstractTableModel>

class QUrl;
class TestBreakpointModel;

namespace KTextEditor {
class Cursor;
}

namespace KDevelop
{
class IDocument;
class Breakpoint;
class BreakpointModelPrivate;

class ScopedIncrementor
{
    int& m_value;

public:
    explicit ScopedIncrementor(int& value)
        : m_value(value)
    {
        ++m_value;
    }
    ~ScopedIncrementor()
    {
        --m_value;
    }
    Q_DISABLE_COPY_MOVE(ScopedIncrementor)
};

class KDEVPLATFORMDEBUGGER_EXPORT BreakpointModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    enum Column {
        /**
         * Whether the breakpoint is active or not (settable by user): value is Qt::Checked
         * or Qt::Unchecked.
         */
        EnableColumn,

        /**
         * Synchronization state of the breakpoint (not settable by user): value is one of the
         * BreakpointState enum values.
         */
        StateColumn,

        /**
         * Kind/type of breakpoint (never changes): value is one of the BreakpointKind
         * enum values.
         */
        KindColumn,

        /**
         * Location of the breakpoint (modifiable by user); value is a string describing the
         * location; note that the formatting of retrieved data can be affected by a custom
         * BreakpointRole.
         */
        LocationColumn,

        /**
         * Condition for conditional breakpoints (modifiable by user).
         */
        ConditionColumn,

        /**
         * The number of times this breakpoint has been hit (cannot be modified by the user).
         */
        HitCountColumn,

        /**
         * How many hits of the breakpoint will be ignored before the breakpoint actually stops
         * the program (can be modified by the user and is updated by the debugger backend).
         */
        IgnoreHitsColumn,

        NumColumns
    };

    enum ColumnFlag {
        EnableColumnFlag = 1 << EnableColumn,
        StateColumnFlag = 1 << StateColumn,
        KindColumnFlag = 1 << KindColumn,
        LocationColumnFlag = 1 << LocationColumn,
        ConditionColumnFlag = 1 << ConditionColumn,
        HitCountColumnFlag = 1 << HitCountColumn,
        IgnoreHitsColumnFlag = 1 << IgnoreHitsColumn
    };
    Q_DECLARE_FLAGS(ColumnFlags, ColumnFlag)

    explicit BreakpointModel(QObject* parent);
    ~BreakpointModel() override;

    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QModelIndex breakpointIndex(Breakpoint *b, int column);
    bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    int columnCount(const QModelIndex& parent = QModelIndex()) const override;

     ///Note: to retrieve the full path use Breakpoint::LocationRole, Qt::DisplayRole returns only a file's name
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;

    /**
     * Delete a given registered breakpoint.
     * @param breakpoint a non-null pointer
     */
    void removeBreakpoint(Breakpoint* breakpoint);

    void toggleBreakpoint(const QUrl &url, const KTextEditor::Cursor& cursor);


    KDevelop::Breakpoint* addCodeBreakpoint();
    KDevelop::Breakpoint* addCodeBreakpoint(const QUrl& location, int line);
    KDevelop::Breakpoint* addCodeBreakpoint(const QString& expression);
    KDevelop::Breakpoint* addWatchpoint();
    KDevelop::Breakpoint* addWatchpoint(const QString& expression);
    KDevelop::Breakpoint* addReadWatchpoint();
    KDevelop::Breakpoint* addReadWatchpoint(const QString& expression);
    KDevelop::Breakpoint* addAccessWatchpoint();
    KDevelop::Breakpoint* addAccessWatchpoint(const QString& expression);

    Breakpoint* breakpoint(int row) const;
    QList<Breakpoint*> breakpoints() const;

Q_SIGNALS:
    void hit(int row);

public Q_SLOTS:
    void save();
    void load();

private:
    using MarkType = KTextEditor::Document::MarkTypes;
    static constexpr MarkType BreakpointMark = MarkType::BreakpointActive;
    static constexpr MarkType ReachedBreakpointMark = MarkType::BreakpointReached;
    static constexpr MarkType DisabledBreakpointMark = MarkType::BreakpointDisabled;
    static constexpr MarkType PendingBreakpointMark = MarkType::markType08;
    /// A bit mask of breakpoint mark types.
    static constexpr MarkType AllBreakpointMarks =
        MarkType(BreakpointMark | ReachedBreakpointMark | DisabledBreakpointMark | PendingBreakpointMark);

private Q_SLOTS:
    void markChanged(KTextEditor::Document* document, KTextEditor::Mark mark,
                     KTextEditor::Document::MarkChangeAction action);
    void textDocumentCreated(KDevelop::IDocument*);
    void documentUrlChanged(KDevelop::IDocument* document, const QUrl& previousUrl);
    void aboutToReload();
    void aboutToInvalidateMovingInterfaceContent(KTextEditor::Document* document);
    void reloaded(KTextEditor::Document* document);
    void documentSaved(KDevelop::IDocument*);
    void aboutToDeleteMovingInterfaceContent(KTextEditor::Document *document);

    void markContextMenuRequested(KTextEditor::Document* document, KTextEditor::Mark mark, QPoint pos, bool& handled);

private:
    static const QPixmap* breakpointPixmap();
    static const QPixmap* pendingBreakpointPixmap();
    static const QPixmap* reachedBreakpointPixmap();
    static const QPixmap* disabledBreakpointPixmap();

private:
    friend class Breakpoint;
    friend class IBreakpointController;
    friend class ::TestBreakpointModel;

    void updateErrorText(int row, const QString& errorText);
    void notifyHit(int row);

    void registerBreakpoint(Breakpoint* breakpoint);
    void scheduleSave();

    void reportChange(Breakpoint *breakpoint, Breakpoint::Column column);

    /**
     * Call this function and keep the returned guard object alive while adding or removing document marks.
     */
    ScopedIncrementor markChangeGuard();

    /**
     * Remove all breakpoint marks from @p document.
     */
    void removeBreakpointMarks(KTextEditor::Document& document);

    /**
     * Initialize breakpoint marks and moving cursors in a given document.
     */
    void setupDocumentBreakpoints(KTextEditor::Document& document) const;

    /**
     * Remove breakpoint marks and moving cursors from a given document.
     */
    void detachDocumentBreakpoints(KTextEditor::Document& document) const;

    Breakpoint *breakpoint(const QUrl& url, int line) const;

    /**
     * Assign a new moving cursor to the breakpoint.
     * @param breakpoint a non-null pointer to the breakpoint
     * @param document a non-null pointer to the document, in which to create the moving cursor
     * @param line position of the new moving cursor in the range [0, document->lines())
     */
    void setupMovingCursor(Breakpoint* breakpoint, KTextEditor::Document* document, int line) const;

private:
    const QScopedPointer<class BreakpointModelPrivate> d_ptr;
    Q_DECLARE_PRIVATE(BreakpointModel)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(BreakpointModel::ColumnFlags)
}

#endif