Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
json_data_source_view.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <config.h>
13
15
17
18#include <QAbstractScrollArea>
19#include <QTextLayout>
20
21class QTextLayout;
22
23struct TextLine {
24 QString line;
25#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
26 QList<QTextLayout::FormatRange> fmt_list;
27#else
28 QVector<QTextLayout::FormatRange> fmt_list;
29#endif
30 int highlight_start;
31 int highlight_length;
32 int kv_start;
33 int kv_length;
34};
35
36struct TextBlock {
37 QList<TextLine> text_lines;
38};
39
44{
45 Q_OBJECT
46public:
53 explicit JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent = nullptr);
54
59
60signals:
66
72
73public slots:
78 void setMonospaceFont(const QFont &mono_font);
79
87 void markField(int start, int length, bool scroll_to = true, bool hover = false);
88
92 void unmarkField();
93
99 void markProtocol(int start, int length) {Q_UNUSED(start) Q_UNUSED(length)}
100
106 void markAppendix(int start, int length) {Q_UNUSED(start) Q_UNUSED(length)}
107
108protected:
109 // virtual bool event(QEvent *event);
110
114 virtual void paintEvent(QPaintEvent *);
115
119 virtual void resizeEvent(QResizeEvent *);
120
124 virtual void showEvent(QShowEvent *);
125
129 virtual void keyPressEvent(QKeyEvent *);
130
135 virtual void mousePressEvent (QMouseEvent *event);
136
141 virtual void mouseMoveEvent (QMouseEvent * event);
142
147 virtual void leaveEvent(QEvent *event);
148
149private:
153 void updateLayoutMetrics();
154
160 int stringWidth(const QString &line);
161
165 void updateScrollbars();
166
173 void addTextLine(TextBlock &text_block, TextLine &text_line, const QString &next_line = QString());
174
181 bool prettyPrintPlain(const char *in_buf, QString &out_str);
182
187 bool addJsonObject();
188
194 int offsetChars(bool include_pad = true);
195
200 int offsetPixels();
201
207 const TextLine *findTextLine(int line);
208
210 QTextLayout *layout_;
211
213 QList<TextBlock> text_blocks_;
214
216 bool layout_dirty_;
217
219 bool show_offset_; // Should we show the byte offset?
220
222 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
223
225 int line_height_; // Font line spacing
226
228 qsizetype max_line_length_; // In characters
229
231 proto_node *root_node_;
232
234 const TextLine *selected_line_;
235
237 const TextLine *hovered_line_;
238};
Abstract base class for widgets that display raw packet byte data.
Definition base_data_source_view.h:20
Represents information about a dissected packet field.
Definition field_information.h:26
A view for displaying and interacting with JSON formatted data sources.
Definition json_data_source_view.h:44
void unmarkField()
Clears the currently marked field.
Definition json_data_source_view.cpp:112
void markField(int start, int length, bool scroll_to=true, bool hover=false)
Visually marks a field in the display.
Definition json_data_source_view.cpp:82
void setMonospaceFont(const QFont &mono_font)
Sets the monospace font used for rendering the JSON text.
Definition json_data_source_view.cpp:67
void fieldSelected(FieldInformation *finfo)
Signal emitted when a JSON field is selected.
virtual void leaveEvent(QEvent *event)
Handles leave events to clear hover states.
Definition json_data_source_view.cpp:294
virtual void mouseMoveEvent(QMouseEvent *event)
Handles mouse move events for hovering over fields.
Definition json_data_source_view.cpp:281
~JsonDataSourceView()
Destroys the JsonDataSourceView.
Definition json_data_source_view.cpp:61
void markProtocol(int start, int length)
Marks a protocol in the view (unused for JSON view).
Definition json_data_source_view.h:99
virtual void showEvent(QShowEvent *)
Handles show events.
Definition json_data_source_view.cpp:185
void fieldHighlight(FieldInformation *finfo)
Signal emitted when a JSON field is hovered or highlighted.
virtual void resizeEvent(QResizeEvent *)
Handles resize events to adjust the text layout.
Definition json_data_source_view.cpp:180
virtual void paintEvent(QPaintEvent *)
Handles paint events to draw the JSON text.
Definition json_data_source_view.cpp:118
virtual void keyPressEvent(QKeyEvent *)
Handles key press events for navigation.
Definition json_data_source_view.cpp:195
virtual void mousePressEvent(QMouseEvent *event)
Handles mouse press events for selecting fields.
Definition json_data_source_view.cpp:262
void markAppendix(int start, int length)
Marks the appendix in the view (unused for JSON view).
Definition json_data_source_view.h:106
Definition proto.h:909
Definition json_data_source_view.h:36
Definition json_data_source_view.h:23