Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
lua_debugger_watch.h
Go to the documentation of this file.
1/* lua_debugger_watch.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <[email protected]>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
16#ifndef LUA_DEBUGGER_WATCH_H
17#define LUA_DEBUGGER_WATCH_H
18
19#include <QHash>
20#include <QList>
21#include <QModelIndex>
22#include <QObject>
23#include <QStandardItemModel>
24#include <QString>
25#include <QStringList>
26#include <QStyledItemDelegate>
27#include <QTreeView>
28#include <QVariantMap>
29
30#include <functional>
31
32#include "lua_debugger_utils.h"
33
37class QKeyEvent;
38class QListView;
39class QMouseEvent;
40class QPoint;
41class QStandardItem;
42class QStandardItemModel;
43class QToolButton;
44class QTreeView;
45
47namespace WatchColumn
48{
49constexpr int Spec = 0;
50constexpr int Value = 1;
51constexpr int Count = 2;
52} // namespace WatchColumn
53
54/* ===== watch_widgets ===== */
55
57class LuaDbgWatchItemModel : public QStandardItemModel
58{
59 Q_OBJECT
60
61 public:
62 using QStandardItemModel::QStandardItemModel;
63
64 protected:
65 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
66 const QModelIndex &parent) override;
67};
68
70class LuaDbgWatchTreeWidget : public QTreeView
71{
72 Q_OBJECT
73
74 public:
78 LuaDbgWatchTreeWidget(LuaDebuggerFontPolicy *fontPolicy, QWidget *parent);
79
80 signals:
86 void requestCopyValue(QStandardItem *item, const QModelIndex &index);
88 void requestDuplicateRoot(QStandardItem *item);
90 void requestDeleteRows(const QList<QStandardItem *> &items);
91
92 protected:
93 void startDrag(Qt::DropActions supportedActions) override;
94 void dragMoveEvent(QDragMoveEvent *event) override;
95 void dropEvent(QDropEvent *event) override;
97 void mouseDoubleClickEvent(QMouseEvent *event) override;
102 void keyPressEvent(QKeyEvent *event) override;
103
104 private:
105 LuaDebuggerFontPolicy *fontPolicy_;
106};
107
109class LuaDbgVariablesReadOnlyDelegate : public QStyledItemDelegate
110{
111 Q_OBJECT
112
113 public:
114 using QStyledItemDelegate::QStyledItemDelegate;
115
116 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
117};
118
120class LuaDbgWatchValueColumnDelegate : public QStyledItemDelegate
121{
122 Q_OBJECT
123
124 public:
125 using QStyledItemDelegate::QStyledItemDelegate;
126
127 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
128
129 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
130};
131
133class LuaDbgWatchRootDelegate : public QStyledItemDelegate
134{
135 Q_OBJECT
136
137 public:
141 using CommitFn = std::function<void(QStandardItem *item, const QString &text)>;
142
143 LuaDbgWatchRootDelegate(QTreeView *tree, CommitFn commit, QObject *parent = nullptr);
144
145 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
146 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
147 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
148
149 private:
150 QTreeView *tree_;
151 CommitFn commit_;
152};
153
154/* ===== watch_row_presenter ===== */
155
169class LuaDebuggerWatchRowPresenter : public QObject
170{
171 Q_OBJECT
172
173 public:
182 LuaDebuggerWatchRowPresenter(QObject *parent, QTreeView *tree, QStandardItemModel *model,
184
186 void applyEmpty(QStandardItem *item, const QString &muted, const QString &watchTipExtra);
187
189 void applyNoLiveContext(QStandardItem *item, const QString &muted, const QString &watchTipExtra);
190
192 void applyError(QStandardItem *item, const QString &errStr, const QString &watchTipExtra);
193
195 void applySuccess(QStandardItem *item, const QString &spec, const char *val, const char *typ, bool can_expand,
196 const QString &watchTipExtra, int stackLevel, bool changeHighlightAllowed);
197
199 void applyExpression(QStandardItem *item, const QString &spec, const char *val, const char *typ, bool can_expand,
200 const QString &watchTipExtra, int stackLevel, bool changeHighlightAllowed);
201
202 private:
203 QTreeView *tree_ = nullptr;
204 QStandardItemModel *model_ = nullptr;
205 LuaDebuggerChangeHighlightTracker *tracker_ = nullptr;
206};
207
208/* ===== watch_controller ===== */
209
216class LuaDebuggerWatchController : public QObject
217{
218 Q_OBJECT
219
220 public:
222
229 void attach(QTreeView *tree, QStandardItemModel *model);
230
234 void attachHeaderButtons(QToolButton *remove, QToolButton *removeAll);
235
236 void configureColumns() const;
237
239 void pruneExpansionMap();
243 QStringList expandedSubpathsForSpec(const QString &rootSpec) const;
244
248 void refillChildren(QStandardItem *item);
249
254 void refreshDisplay();
255
259 void refreshBranch(QStandardItem *item);
260
265 void applyItemState(QStandardItem *item, bool liveContext, const QString &muted);
266
272 void insertNewRow(const QString &initialSpec = QString(), bool openEditor = true);
273
281 void commitWatchRootSpec(QStandardItem *item, const QString &text);
282
286 void deleteRows(const QList<QStandardItem *> &items);
287
290
293 void copyValueForItem(QStandardItem *item, const QModelIndex &ix);
294
296 void duplicateRootItem(QStandardItem *item);
297
301 QList<QStandardItem *> selectedRootItemsForRemove() const;
302
308 void serializeTo(QVariantMap &settingsMap);
309
315 void restoreFrom(const QVariantMap &settingsMap);
316
329
336
337 public slots:
338 void onExpanded(const QModelIndex &index);
339 void onCollapsed(const QModelIndex &index);
340 void showContextMenu(const QPoint &pos);
341
342 private:
346 void fillPathChildren(QStandardItem *parent, const QString &path);
347
351 void fillExprChildren(QStandardItem *parent, const QString &rootSpec, const QString &subpath);
352
355 void updateHeaderButtonState();
356
357 LuaDebuggerDialog *host_ = nullptr;
358 QTreeView *tree_ = nullptr;
359 QStandardItemModel *model_ = nullptr;
360 QToolButton *removeButton_ = nullptr;
361 QToolButton *removeAllButton_ = nullptr;
366 LuaDebuggerWatchRowPresenter *rowPresenter_ = nullptr;
367
369 QHash<QString, LuaDbgTreeSectionExpansionState> expansion_;
370
377 qint32 placeholderEpoch_ = 0;
378};
379
380#endif
Definition lua_debugger_watch.h:110
Definition lua_debugger_watch.h:58
Definition lua_debugger_watch.h:134
std::function< void(QStandardItem *item, const QString &text)> CommitFn
Callback invoked from setModelData when the user finishes editing a top-level watch row's expression....
Definition lua_debugger_watch.h:141
Definition lua_debugger_watch.h:71
void requestDuplicateRoot(QStandardItem *item)
Ctrl+Shift+D on a top-level item.
void keyPressEvent(QKeyEvent *event) override
Definition lua_debugger_watch.cpp:212
void requestNewRow()
Double-click on empty tree area: insert a new (pending) row.
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition lua_debugger_watch.cpp:193
void requestDeleteRows(const QList< QStandardItem * > &items)
Delete / Backspace on top-level rows: remove items.
void requestCopyValue(QStandardItem *item, const QModelIndex &index)
Ctrl+Shift+C on item (any row, top-level or child).
void requestRemoveAll()
Ctrl+Shift+K with at least one row present: confirm + clear.
Definition lua_debugger_watch.h:121
"Value changed since last pause" highlighter for the Watch and Variables trees.
Definition lua_debugger_utils.h:534
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:165
Owns the dialog's font story end-to-end.
Definition lua_debugger_code_editor.h:300
Watch panel: column layout, expand/collapse tracking + lazy fill, runtime expansion-state map,...
Definition lua_debugger_watch.h:217
void invalidatePlaceholder()
Cancel the deferred placeholder by bumping the epoch. Call from handlePause() so the imminent refresh...
Definition lua_debugger_watch.cpp:1737
void restoreFrom(const QVariantMap &settingsMap)
Replace the watch tree with the contents of Watches in settingsMap. Empty / container-typed entries a...
Definition lua_debugger_watch.cpp:1698
void insertNewRow(const QString &initialSpec=QString(), bool openEditor=true)
Insert a top-level watch row; optionally open the inline editor. An empty initialSpec creates a "pend...
Definition lua_debugger_watch.cpp:1256
void copyValueForItem(QStandardItem *item, const QModelIndex &ix)
Copy the (untruncated when paused) value of item to the clipboard; shared between the row context men...
Definition lua_debugger_watch.cpp:1162
void applyItemState(QStandardItem *item, bool liveContext, const QString &muted)
Apply the per-row presentation for item given the current liveness context. Reads the row state,...
Definition lua_debugger_watch.cpp:1602
void scheduleDeferredPlaceholder()
Schedule a deferred "Watch column shows —" placeholder paint after a step resume.
Definition lua_debugger_watch.cpp:1742
void refillChildren(QStandardItem *item)
Re-query and replace all children of item. Used by the lazy-expand path and by refreshBranch after pa...
Definition lua_debugger_watch.cpp:833
void removeAllTopLevelItems()
Confirm with the user, then remove every top-level row.
Definition lua_debugger_watch.cpp:1124
void refreshDisplay()
Refresh value/type (and expansion affordances) for all watch roots, recursing into already-expanded b...
Definition lua_debugger_watch.cpp:1562
void restoreExpansionState()
Re-expand persisted subpaths after refilling roots from settings.
Definition lua_debugger_watch.cpp:874
void attachHeaderButtons(QToolButton *remove, QToolButton *removeAll)
Bind the section-header strip. Click signals are wired here; enable/disable state tracks the model an...
Definition lua_debugger_watch.cpp:742
QList< QStandardItem * > selectedRootItemsForRemove() const
Top-level watch rows in the current selection (column 0) only; used by the section header Remove cont...
Definition lua_debugger_watch.cpp:1069
QStringList expandedSubpathsForSpec(const QString &rootSpec) const
Look up expanded descendant keys for rootSpec (may be empty).
Definition lua_debugger_watch.cpp:794
void pruneExpansionMap()
Drop expansion-map entries for watch specs no longer in the tree.
Definition lua_debugger_watch.cpp:799
void deleteRows(const QList< QStandardItem * > &items)
Delete the given top-level watch rows from the tree. Children, non-top-level rows and stale pointers ...
Definition lua_debugger_watch.cpp:1092
void commitWatchRootSpec(QStandardItem *item, const QString &text)
Apply the user's edit of a top-level watch row's expression.
Definition lua_debugger_watch.cpp:1316
void serializeTo(QVariantMap &settingsMap)
Snapshot the live watch tree as a flat array of canonical spec strings into settingsMap (at the Watch...
Definition lua_debugger_watch.cpp:1664
void attach(QTreeView *tree, QStandardItemModel *model)
Bind the tree + model and wire all watch-internal signals (typed LuaDbgWatchTreeWidget gestures,...
Definition lua_debugger_watch.cpp:684
void refreshBranch(QStandardItem *item)
Re-evaluate one expanded branch depth-first; preserves the controller-tracked expansion state of nest...
Definition lua_debugger_watch.cpp:1582
void duplicateRootItem(QStandardItem *item)
Duplicate top-level watch row item below itself.
Definition lua_debugger_watch.cpp:1216
Per-row presentation for top-level Watch rows.
Definition lua_debugger_watch.h:170
void applyNoLiveContext(QStandardItem *item, const QString &muted, const QString &watchTipExtra)
Live context unavailable (debugger not paused).
Definition lua_debugger_watch.cpp:417
void applyExpression(QStandardItem *item, const QString &spec, const char *val, const char *typ, bool can_expand, const QString &watchTipExtra, int stackLevel, bool changeHighlightAllowed)
Expression-style watch root with a successful read.
Definition lua_debugger_watch.cpp:551
void applyError(QStandardItem *item, const QString &errStr, const QString &watchTipExtra)
Watch evaluation failed (path not found, expr error, etc.).
Definition lua_debugger_watch.cpp:458
void applySuccess(QStandardItem *item, const QString &spec, const char *val, const char *typ, bool can_expand, const QString &watchTipExtra, int stackLevel, bool changeHighlightAllowed)
Path-style watch root with a successful read.
Definition lua_debugger_watch.cpp:500
void applyEmpty(QStandardItem *item, const QString &muted, const QString &watchTipExtra)
Empty top-level row (no spec yet).
Definition lua_debugger_watch.cpp:394
Column indices for the Watch tree model.
Definition lua_debugger_watch.h:48