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 <gerald@wireshark.org>
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
59class LuaDbgWatchItemModel : public QStandardItemModel
60{
61 Q_OBJECT
62
63public:
64 using QStandardItemModel::QStandardItemModel;
65
66protected:
76 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
77 const QModelIndex &parent) override;
78};
79
83class LuaDbgWatchTreeWidget : public QTreeView
84{
85 Q_OBJECT
86
87public:
94 LuaDbgWatchTreeWidget(LuaDebuggerFontPolicy *fontPolicy, QWidget *parent);
95
96signals:
101
106
112 void requestCopyValue(QStandardItem *item, const QModelIndex &index);
113
118 void requestDuplicateRoot(QStandardItem *item);
119
124 void requestDeleteRows(const QList<QStandardItem *> &items);
125
126protected:
131 void startDrag(Qt::DropActions supportedActions) override;
132
137 void dragMoveEvent(QDragMoveEvent *event) override;
138
143 void dropEvent(QDropEvent *event) override;
144
149 void mouseDoubleClickEvent(QMouseEvent *event) override;
150
158 void keyPressEvent(QKeyEvent *event) override;
159
160private:
162 LuaDebuggerFontPolicy *fontPolicy_;
163};
164
168class LuaDbgVariablesReadOnlyDelegate : public QStyledItemDelegate
169{
170 Q_OBJECT
171
172 public:
174 using QStyledItemDelegate::QStyledItemDelegate;
175
183 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
184};
185
189class LuaDbgWatchValueColumnDelegate : public QStyledItemDelegate
190{
191 Q_OBJECT
192
193 public:
195 using QStyledItemDelegate::QStyledItemDelegate;
196
203 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
204
212 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
213};
214
218class LuaDbgWatchRootDelegate : public QStyledItemDelegate
219{
220 Q_OBJECT
221
222 public:
228 using CommitFn = std::function<void(QStandardItem *item, const QString &text)>;
229
236 LuaDbgWatchRootDelegate(QTreeView *tree, CommitFn commit, QObject *parent = nullptr);
237
245 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
246
252 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
253
260 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
261
262 private:
263 QTreeView *tree_;
264 CommitFn commit_;
265};
266
267/* ===== watch_row_presenter ===== */
268
282class LuaDebuggerWatchRowPresenter : public QObject
283{
284 Q_OBJECT
285
286 public:
295 LuaDebuggerWatchRowPresenter(QObject *parent, QTreeView *tree, QStandardItemModel *model,
297
299 void applyEmpty(QStandardItem *item, const QString &muted, const QString &watchTipExtra);
300
302 void applyNoLiveContext(QStandardItem *item, const QString &muted, const QString &watchTipExtra);
303
305 void applyError(QStandardItem *item, const QString &errStr, const QString &watchTipExtra);
306
308 void applySuccess(QStandardItem *item, const QString &spec, const char *val, const char *typ, bool can_expand,
309 const QString &watchTipExtra, int stackLevel, bool changeHighlightAllowed);
310
312 void applyExpression(QStandardItem *item, const QString &spec, const char *val, const char *typ, bool can_expand,
313 const QString &watchTipExtra, int stackLevel, bool changeHighlightAllowed);
314
315 private:
316 QTreeView *tree_ = nullptr;
317 QStandardItemModel *model_ = nullptr;
318 LuaDebuggerChangeHighlightTracker *tracker_ = nullptr;
319};
320
321/* ===== watch_controller ===== */
322
329class LuaDebuggerWatchController : public QObject
330{
331 Q_OBJECT
332
333public:
339
349 void attach(QTreeView *tree, QStandardItemModel *model);
350
358 void attachHeaderButtons(QToolButton *remove, QToolButton *removeAll);
359
363 void configureColumns() const;
364
368 void pruneExpansionMap();
369
374
380 QStringList expandedSubpathsForSpec(const QString &rootSpec) const;
381
387 void refillChildren(QStandardItem *item);
388
394 void refreshDisplay();
395
402 void refreshBranch(QStandardItem *item);
403
413 void applyItemState(QStandardItem *item, bool liveContext, const QString &muted);
414
424 void insertNewRow(const QString &initialSpec = QString(), bool openEditor = true);
425
437 void commitWatchRootSpec(QStandardItem *item, const QString &text);
438
445 void deleteRows(const QList<QStandardItem *> &items);
446
451
458 void copyValueForItem(QStandardItem *item, const QModelIndex &ix);
459
464 void duplicateRootItem(QStandardItem *item);
465
472 QList<QStandardItem *> selectedRootItemsForRemove() const;
473
482 void serializeTo(QVariantMap &settingsMap);
483
492 void restoreFrom(const QVariantMap &settingsMap);
493
506
513
514public slots:
519 void onExpanded(const QModelIndex &index);
520
525 void onCollapsed(const QModelIndex &index);
526
531 void showContextMenu(const QPoint &pos);
532
533private:
541 void fillPathChildren(QStandardItem *parent, const QString &path);
542
551 void fillExprChildren(QStandardItem *parent, const QString &rootSpec, const QString &subpath);
552
556 void updateHeaderButtonState();
557
559 LuaDebuggerDialog *host_ = nullptr;
560
562 QTreeView *tree_ = nullptr;
563
565 QStandardItemModel *model_ = nullptr;
566
568 QToolButton *removeButton_ = nullptr;
569
571 QToolButton *removeAllButton_ = nullptr;
572
579 LuaDebuggerWatchRowPresenter *rowPresenter_ = nullptr;
580
582 QHash<QString, LuaDbgTreeSectionExpansionState> expansion_;
583
590 qint32 placeholderEpoch_ = 0;
591};
592
593#endif
Variables tree: block inline editors on all columns.
Definition lua_debugger_watch.h:169
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Blocks editor creation by returning a null pointer.
Definition lua_debugger_watch.cpp:296
Model that routes drops to column 0 for watch reordering.
Definition lua_debugger_watch.h:60
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Handles a drop event, forcing the target column to 0 to preserve watch item order.
Definition lua_debugger_watch.cpp:82
Root watch cell: inline line edit for the expression column.
Definition lua_debugger_watch.h:219
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Creates the inline line editor for the cell.
Definition lua_debugger_watch.cpp:332
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:228
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Saves the editor's data back to the model.
Definition lua_debugger_watch.cpp:370
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Sets the data to be displayed and edited in the editor.
Definition lua_debugger_watch.cpp:350
Watch tree: top-level reorder only; nested rows are not drop targets.
Definition lua_debugger_watch.h:84
void requestDuplicateRoot(QStandardItem *item)
Emitted on Ctrl+Shift+D to request duplication of a top-level item.
void keyPressEvent(QKeyEvent *event) override
Handles watch-local keyboard shortcuts (remove-all, copy, duplicate, delete, inline edit)....
Definition lua_debugger_watch.cpp:212
void startDrag(Qt::DropActions supportedActions) override
Initiates a drag operation for top-level row reordering.
Definition lua_debugger_watch.cpp:103
void dragMoveEvent(QDragMoveEvent *event) override
Validates and constrains drag-move events to top-level drop targets only.
Definition lua_debugger_watch.cpp:116
void requestNewRow()
Emitted on double-click on an empty tree area to insert a new pending row.
void mouseDoubleClickEvent(QMouseEvent *event) override
Inserts a new pending row when the user double-clicks on empty space.
Definition lua_debugger_watch.cpp:193
void requestDeleteRows(const QList< QStandardItem * > &items)
Emitted on Delete or Backspace to remove the specified top-level rows.
void dropEvent(QDropEvent *event) override
Handles drop events, restricting reordering to top-level rows.
Definition lua_debugger_watch.cpp:135
void requestCopyValue(QStandardItem *item, const QModelIndex &index)
Emitted on Ctrl+Shift+C to request a value copy for the given item.
void requestRemoveAll()
Emitted on Ctrl+Shift+K with at least one row present to confirm and clear all rows.
Value column: elide middle; no editor.
Definition lua_debugger_watch.h:190
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Blocks editor creation by returning a null pointer.
Definition lua_debugger_watch.cpp:318
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Custom paint method to elide text in the middle.
Definition lua_debugger_watch.cpp:305
"Value changed since last pause" highlighter for the Watch and Variables trees.
Definition lua_debugger_utils.h:989
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:189
Owns the dialog's font story end-to-end.
Definition lua_debugger_code_editor.h:414
Watch panel: column layout, expand/collapse tracking + lazy fill, runtime expansion-state map,...
Definition lua_debugger_watch.h:330
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 onCollapsed(const QModelIndex &index)
Records the collapse of the item at index in the runtime expansion map.
Definition lua_debugger_watch.cpp:950
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 onExpanded(const QModelIndex &index)
Records the expansion of the item at index in the runtime expansion map.
Definition lua_debugger_watch.cpp:905
void showContextMenu(const QPoint &pos)
Displays the watch row context menu at the given viewport position.
Definition lua_debugger_watch.cpp:973
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 configureColumns() const
Configures column widths, resize modes, and visibility for the watch tree.
Definition lua_debugger_watch.cpp:780
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:283
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