| Wireshark 4.7.3 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
15
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
34 class LuaDebuggerChangeHighlightTracker;
35 class LuaDebuggerDialog;
36 class LuaDebuggerFontPolicy;
37 class QKeyEvent;
38 class QListView;
39 class QMouseEvent;
40 class QPoint;
41 class QStandardItem;
42 class QStandardItemModel;
43 class QToolButton;
44 class QTreeView;
45
47 namespace WatchColumn
48{
49 constexpr int Spec = 0;
50 constexpr int Value = 1;
51 constexpr int Count = 2;
52} // namespace WatchColumn
53
54/* ===== watch_widgets ===== */
55
59 class LuaDbgWatchItemModel : public QStandardItemModel
60{
61 Q_OBJECT
62
63 public:
64 using QStandardItemModel::QStandardItemModel;
65
66 protected:
76 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
77 const QModelIndex &parent) override;
78};
79
83 class LuaDbgWatchTreeWidget : public QTreeView
84{
85 Q_OBJECT
86
87 public:
94 LuaDbgWatchTreeWidget(LuaDebuggerFontPolicy *fontPolicy, QWidget *parent);
95
96signals:
100 void requestNewRow();
101
105 void requestRemoveAll();
106
112 void requestCopyValue(QStandardItem *item, const QModelIndex &index);
113
118 void requestDuplicateRoot(QStandardItem *item);
119
124 void requestDeleteRows(const QList<QStandardItem *> &items);
125
126 protected:
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
160 private:
162 LuaDebuggerFontPolicy *fontPolicy_;
163};
164
168 class 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
189 class 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
218 class 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
282 class LuaDebuggerWatchRowPresenter : public QObject
283{
284 Q_OBJECT
285
286 public:
295 LuaDebuggerWatchRowPresenter(QObject *parent, QTreeView *tree, QStandardItemModel *model,
296 LuaDebuggerChangeHighlightTracker &tracker);
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
329 class LuaDebuggerWatchController : public QObject
330{
331 Q_OBJECT
332
333 public:
338 explicit LuaDebuggerWatchController(LuaDebuggerDialog *host);
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
373 void restoreExpansionState();
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
450 void removeAllTopLevelItems();
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
505 void scheduleDeferredPlaceholder();
506
512 void invalidatePlaceholder();
513
514 public slots:
519 void onExpanded(const QModelIndex &index);
520
525 void onCollapsed(const QModelIndex &index);
526
531 void showContextMenu(const QPoint &pos);
532
533 private:
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
LuaDbgVariablesReadOnlyDelegate
Variables tree: block inline editors on all columns.
Definition lua_debugger_watch.h:169
LuaDbgVariablesReadOnlyDelegate::createEditor
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:284
LuaDbgWatchItemModel
Model that routes drops to column 0 for watch reordering.
Definition lua_debugger_watch.h:60
LuaDbgWatchItemModel::dropMimeData
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
LuaDbgWatchRootDelegate::createEditor
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:320
LuaDbgWatchRootDelegate::CommitFn
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
LuaDbgWatchRootDelegate::setModelData
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:358
LuaDbgWatchRootDelegate::LuaDbgWatchRootDelegate
LuaDbgWatchRootDelegate(QTreeView *tree, CommitFn commit, QObject *parent=nullptr)
Constructs the root watch delegate.
Definition lua_debugger_watch.cpp:315
LuaDbgWatchRootDelegate::setEditorData
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:338
LuaDbgWatchTreeWidget::requestDuplicateRoot
void requestDuplicateRoot(QStandardItem *item)
Emitted on Ctrl+Shift+D to request duplication of a top-level item.
LuaDbgWatchTreeWidget::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Handles watch-local keyboard shortcuts (remove-all, copy, duplicate, delete, inline edit)....
Definition lua_debugger_watch.cpp:200
LuaDbgWatchTreeWidget::startDrag
void startDrag(Qt::DropActions supportedActions) override
Initiates a drag operation for top-level row reordering.
Definition lua_debugger_watch.cpp:103
LuaDbgWatchTreeWidget::dragMoveEvent
void dragMoveEvent(QDragMoveEvent *event) override
Validates and constrains drag-move events to top-level drop targets only.
Definition lua_debugger_watch.cpp:116
LuaDbgWatchTreeWidget::requestNewRow
void requestNewRow()
Emitted on double-click on an empty tree area to insert a new pending row.
LuaDbgWatchTreeWidget::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *event) override
Inserts a new pending row when the user double-clicks on empty space.
Definition lua_debugger_watch.cpp:185
LuaDbgWatchTreeWidget::requestDeleteRows
void requestDeleteRows(const QList< QStandardItem * > &items)
Emitted on Delete or Backspace to remove the specified top-level rows.
LuaDbgWatchTreeWidget::dropEvent
void dropEvent(QDropEvent *event) override
Handles drop events, restricting reordering to top-level rows.
Definition lua_debugger_watch.cpp:131
LuaDbgWatchTreeWidget::requestCopyValue
void requestCopyValue(QStandardItem *item, const QModelIndex &index)
Emitted on Ctrl+Shift+C to request a value copy for the given item.
LuaDbgWatchTreeWidget::LuaDbgWatchTreeWidget
LuaDbgWatchTreeWidget(LuaDebuggerFontPolicy *fontPolicy, QWidget *parent)
Constructs the watch tree widget.
Definition lua_debugger_watch.cpp:98
LuaDbgWatchTreeWidget::requestRemoveAll
void requestRemoveAll()
Emitted on Ctrl+Shift+K with at least one row present to confirm and clear all rows.
LuaDbgWatchValueColumnDelegate
Value column: elide middle; no editor.
Definition lua_debugger_watch.h:190
LuaDbgWatchValueColumnDelegate::createEditor
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:306
LuaDbgWatchValueColumnDelegate::paint
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:293
LuaDebuggerChangeHighlightTracker
"Value changed since last pause" highlighter for the Watch and Variables trees.
Definition lua_debugger_utils.h:995
LuaDebuggerDialog
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:189
LuaDebuggerFontPolicy
Owns the dialog's font story end-to-end.
Definition lua_debugger_code_editor.h:418
LuaDebuggerWatchController::invalidatePlaceholder
void invalidatePlaceholder()
Cancel the deferred placeholder by bumping the epoch. Call from handlePause() so the imminent refresh...
Definition lua_debugger_watch.cpp:1724
LuaDebuggerWatchController::restoreFrom
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:1685
LuaDebuggerWatchController::LuaDebuggerWatchController
LuaDebuggerWatchController(LuaDebuggerDialog *host)
Constructs the watch controller bound to the given dialog host.
Definition lua_debugger_watch.cpp:765
LuaDebuggerWatchController::insertNewRow
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:1243
LuaDebuggerWatchController::copyValueForItem
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:1149
LuaDebuggerWatchController::applyItemState
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:1589
LuaDebuggerWatchController::onCollapsed
void onCollapsed(const QModelIndex &index)
Records the collapse of the item at index in the runtime expansion map.
Definition lua_debugger_watch.cpp:937
LuaDebuggerWatchController::scheduleDeferredPlaceholder
void scheduleDeferredPlaceholder()
Schedule a deferred "Watch column shows —" placeholder paint after a step resume.
Definition lua_debugger_watch.cpp:1729
LuaDebuggerWatchController::refillChildren
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:820
LuaDebuggerWatchController::removeAllTopLevelItems
void removeAllTopLevelItems()
Confirm with the user, then remove every top-level row.
Definition lua_debugger_watch.cpp:1111
LuaDebuggerWatchController::refreshDisplay
void refreshDisplay()
Refresh value/type (and expansion affordances) for all watch roots, recursing into already-expanded b...
Definition lua_debugger_watch.cpp:1549
LuaDebuggerWatchController::onExpanded
void onExpanded(const QModelIndex &index)
Records the expansion of the item at index in the runtime expansion map.
Definition lua_debugger_watch.cpp:892
LuaDebuggerWatchController::showContextMenu
void showContextMenu(const QPoint &pos)
Displays the watch row context menu at the given viewport position.
Definition lua_debugger_watch.cpp:960
LuaDebuggerWatchController::restoreExpansionState
void restoreExpansionState()
Re-expand persisted subpaths after refilling roots from settings.
Definition lua_debugger_watch.cpp:861
LuaDebuggerWatchController::attachHeaderButtons
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:729
LuaDebuggerWatchController::selectedRootItemsForRemove
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:1056
LuaDebuggerWatchController::expandedSubpathsForSpec
QStringList expandedSubpathsForSpec(const QString &rootSpec) const
Look up expanded descendant keys for rootSpec (may be empty).
Definition lua_debugger_watch.cpp:781
LuaDebuggerWatchController::pruneExpansionMap
void pruneExpansionMap()
Drop expansion-map entries for watch specs no longer in the tree.
Definition lua_debugger_watch.cpp:786
LuaDebuggerWatchController::deleteRows
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:1079
LuaDebuggerWatchController::configureColumns
void configureColumns() const
Configures column widths, resize modes, and visibility for the watch tree.
Definition lua_debugger_watch.cpp:767
LuaDebuggerWatchController::commitWatchRootSpec
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:1303
LuaDebuggerWatchController::serializeTo
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:1651
LuaDebuggerWatchController::attach
void attach(QTreeView *tree, QStandardItemModel *model)
Bind the tree + model and wire all watch-internal signals (typed LuaDbgWatchTreeWidget gestures,...
Definition lua_debugger_watch.cpp:671
LuaDebuggerWatchController::refreshBranch
void refreshBranch(QStandardItem *item)
Re-evaluate one expanded branch depth-first; preserves the controller-tracked expansion state of nest...
Definition lua_debugger_watch.cpp:1569
LuaDebuggerWatchController::duplicateRootItem
void duplicateRootItem(QStandardItem *item)
Duplicate top-level watch row item below itself.
Definition lua_debugger_watch.cpp:1203
LuaDebuggerWatchRowPresenter
Per-row presentation for top-level Watch rows.
Definition lua_debugger_watch.h:283
LuaDebuggerWatchRowPresenter::applyNoLiveContext
void applyNoLiveContext(QStandardItem *item, const QString &muted, const QString &watchTipExtra)
Live context unavailable (debugger not paused).
Definition lua_debugger_watch.cpp:405
LuaDebuggerWatchRowPresenter::LuaDebuggerWatchRowPresenter
LuaDebuggerWatchRowPresenter(QObject *parent, QTreeView *tree, QStandardItemModel *model, LuaDebuggerChangeHighlightTracker &tracker)
Definition lua_debugger_watch.cpp:376
LuaDebuggerWatchRowPresenter::applyExpression
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:539
LuaDebuggerWatchRowPresenter::applyError
void applyError(QStandardItem *item, const QString &errStr, const QString &watchTipExtra)
Watch evaluation failed (path not found, expr error, etc.).
Definition lua_debugger_watch.cpp:446
LuaDebuggerWatchRowPresenter::applySuccess
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:488
LuaDebuggerWatchRowPresenter::applyEmpty
void applyEmpty(QStandardItem *item, const QString &muted, const QString &watchTipExtra)
Empty top-level row (no spec yet).
Definition lua_debugger_watch.cpp:382
lua_debugger_utils.h
WatchColumn
Column indices for the Watch tree model.
Definition lua_debugger_watch.h:48