Wireshark 4.7.3
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
json_data_source_view.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <config.h>
13
15
17
18#include <QAbstractScrollArea>
19#include <QTextLayout>
20
21class QTextLayout;
22
26struct TextLine {
27 QString line;
28 QList<QTextLayout::FormatRange> fmt_list;
33};
34
38struct TextBlock {
39 QList<TextLine> text_lines;
40};
41
46{
47 Q_OBJECT
48public:
55 explicit JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent = nullptr);
56
61
62signals:
68
74
75public slots:
80 void setMonospaceFont(const QFont &mono_font) override;
81
89 void markField(int start, int length, bool scroll_to = true, bool hover = false) override;
90
94 void unmarkField() override;
95
101 void markProtocol(int start, int length) override{Q_UNUSED(start) Q_UNUSED(length)}
102
108 void markAppendix(int start, int length) override{Q_UNUSED(start) Q_UNUSED(length)}
109
110protected:
111 // virtual bool event(QEvent *event);
112
116 virtual void paintEvent(QPaintEvent *) override;
117
121 virtual void resizeEvent(QResizeEvent *) override;
122
126 virtual void showEvent(QShowEvent *) override;
127
131 virtual void keyPressEvent(QKeyEvent *) override;
132
137 virtual void mousePressEvent (QMouseEvent *event) override;
138
143 virtual void mouseMoveEvent (QMouseEvent * event) override;
144
149 virtual void leaveEvent(QEvent *event) override;
150
151private:
155 void updateLayoutMetrics();
156
162 int stringWidth(const QString &line);
163
167 void updateScrollbars();
168
175 void addTextLine(TextBlock &text_block, TextLine &text_line, const QString &next_line = QString());
176
183 bool prettyPrintPlain(const char *in_buf, QString &out_str);
184
189 bool addJsonObject();
190
196 int offsetChars(bool include_pad = true);
197
202 int offsetPixels();
203
209 const TextLine *findTextLine(int line);
210
212 QTextLayout *layout_;
213
215 QList<TextBlock> text_blocks_;
216
218 bool layout_dirty_;
219
221 bool show_offset_; // Should we show the byte offset?
222
224 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
225
227 int line_height_; // Font line spacing
228
230 qsizetype max_line_length_; // In characters
231
233 proto_node *root_node_;
234
236 const TextLine *selected_line_;
237
239 const TextLine *hovered_line_;
240};
BaseDataSourceView(const QByteArray &data, QWidget *parent=nullptr)
Construct a BaseDataSourceView.
Definition base_data_source_view.h:31
Represents information about a dissected packet field.
Definition field_information.h:26
virtual void leaveEvent(QEvent *event) override
Handles leave events to clear hover states.
Definition json_data_source_view.cpp:292
void unmarkField() override
Clears the currently marked field.
Definition json_data_source_view.cpp:114
void markField(int start, int length, bool scroll_to=true, bool hover=false) override
Visually marks a field in the display.
Definition json_data_source_view.cpp:84
void fieldSelected(FieldInformation *finfo)
Signal emitted when a JSON field is selected.
void markAppendix(int start, int length) override
Marks the appendix in the view (unused for JSON view).
Definition json_data_source_view.h:108
virtual void showEvent(QShowEvent *) override
Handles show events.
Definition json_data_source_view.cpp:183
~JsonDataSourceView()
Destroys the JsonDataSourceView.
Definition json_data_source_view.cpp:63
virtual void keyPressEvent(QKeyEvent *) override
Handles key press events for navigation.
Definition json_data_source_view.cpp:193
void markProtocol(int start, int length) override
Marks a protocol in the view (unused for JSON view).
Definition json_data_source_view.h:101
virtual void mousePressEvent(QMouseEvent *event) override
Handles mouse press events for selecting fields.
Definition json_data_source_view.cpp:260
void setMonospaceFont(const QFont &mono_font) override
Sets the monospace font used for rendering the JSON text.
Definition json_data_source_view.cpp:69
void fieldHighlight(FieldInformation *finfo)
Signal emitted when a JSON field is hovered or highlighted.
virtual void mouseMoveEvent(QMouseEvent *event) override
Handles mouse move events for hovering over fields.
Definition json_data_source_view.cpp:279
virtual void paintEvent(QPaintEvent *) override
Handles paint events to draw the JSON text.
Definition json_data_source_view.cpp:120
JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent=nullptr)
Constructs a new JsonDataSourceView.
Definition json_data_source_view.cpp:32
virtual void resizeEvent(QResizeEvent *) override
Handles resize events to adjust the text layout.
Definition json_data_source_view.cpp:178
struct _proto_node proto_node
Represents a logical block of text composed of one or more formatted lines.
Definition json_data_source_view.h:38
QList< TextLine > text_lines
Definition json_data_source_view.h:39
Represents a single line of text with associated formatting, highlight, and key-value span metadata.
Definition json_data_source_view.h:26
int highlight_start
Definition json_data_source_view.h:29
int kv_length
Definition json_data_source_view.h:32
int highlight_length
Definition json_data_source_view.h:30
QList< QTextLayout::FormatRange > fmt_list
Definition json_data_source_view.h:28
QString line
Definition json_data_source_view.h:27
int kv_start
Definition json_data_source_view.h:31