| 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
14#include "base_data_source_view.h"
15
16#include <ui/qt/utils/field_information.h>
17
18#include <QAbstractScrollArea>
19#include <QTextLayout>
20
21 class QTextLayout;
22
26 struct TextLine {
27 QString line;
28 QList<QTextLayout::FormatRange> fmt_list;
29 int highlight_start;
30 int highlight_length;
31 int kv_start;
32 int kv_length;
33};
34
38 struct TextBlock {
39 QList<TextLine> text_lines;
40};
41
45 class JsonDataSourceView : public BaseDataSourceView
46{
47 Q_OBJECT
48 public:
55 explicit JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent = nullptr);
56
60 ~JsonDataSourceView();
61
62signals:
67 void fieldSelected(FieldInformation *finfo);
68
73 void fieldHighlight(FieldInformation *finfo);
74
75 public 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
110 protected:
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
151 private:
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};
base_data_source_view.h
BaseDataSourceView::BaseDataSourceView
BaseDataSourceView(const QByteArray &data, QWidget *parent=nullptr)
Construct a BaseDataSourceView.
Definition base_data_source_view.h:31
FieldInformation
Represents information about a dissected packet field.
Definition field_information.h:26
JsonDataSourceView::leaveEvent
virtual void leaveEvent(QEvent *event) override
Handles leave events to clear hover states.
Definition json_data_source_view.cpp:292
JsonDataSourceView::unmarkField
void unmarkField() override
Clears the currently marked field.
Definition json_data_source_view.cpp:114
JsonDataSourceView::markField
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
JsonDataSourceView::fieldSelected
void fieldSelected(FieldInformation *finfo)
Signal emitted when a JSON field is selected.
JsonDataSourceView::markAppendix
void markAppendix(int start, int length) override
Marks the appendix in the view (unused for JSON view).
Definition json_data_source_view.h:108
JsonDataSourceView::showEvent
virtual void showEvent(QShowEvent *) override
Handles show events.
Definition json_data_source_view.cpp:183
JsonDataSourceView::~JsonDataSourceView
~JsonDataSourceView()
Destroys the JsonDataSourceView.
Definition json_data_source_view.cpp:63
JsonDataSourceView::keyPressEvent
virtual void keyPressEvent(QKeyEvent *) override
Handles key press events for navigation.
Definition json_data_source_view.cpp:193
JsonDataSourceView::markProtocol
void markProtocol(int start, int length) override
Marks a protocol in the view (unused for JSON view).
Definition json_data_source_view.h:101
JsonDataSourceView::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event) override
Handles mouse press events for selecting fields.
Definition json_data_source_view.cpp:260
JsonDataSourceView::setMonospaceFont
void setMonospaceFont(const QFont &mono_font) override
Sets the monospace font used for rendering the JSON text.
Definition json_data_source_view.cpp:69
JsonDataSourceView::fieldHighlight
void fieldHighlight(FieldInformation *finfo)
Signal emitted when a JSON field is hovered or highlighted.
JsonDataSourceView::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event) override
Handles mouse move events for hovering over fields.
Definition json_data_source_view.cpp:279
JsonDataSourceView::paintEvent
virtual void paintEvent(QPaintEvent *) override
Handles paint events to draw the JSON text.
Definition json_data_source_view.cpp:120
JsonDataSourceView::JsonDataSourceView
JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent=nullptr)
Constructs a new JsonDataSourceView.
Definition json_data_source_view.cpp:32
JsonDataSourceView::resizeEvent
virtual void resizeEvent(QResizeEvent *) override
Handles resize events to adjust the text layout.
Definition json_data_source_view.cpp:178
field_information.h
proto_node
struct _proto_node proto_node
TextBlock
Represents a logical block of text composed of one or more formatted lines.
Definition json_data_source_view.h:38
TextBlock::text_lines
QList< TextLine > text_lines
Definition json_data_source_view.h:39
TextLine
Represents a single line of text with associated formatting, highlight, and key-value span metadata.
Definition json_data_source_view.h:26
TextLine::highlight_start
int highlight_start
Definition json_data_source_view.h:29
TextLine::kv_length
int kv_length
Definition json_data_source_view.h:32
TextLine::highlight_length
int highlight_length
Definition json_data_source_view.h:30
TextLine::fmt_list
QList< QTextLayout::FormatRange > fmt_list
Definition json_data_source_view.h:28
TextLine::line
QString line
Definition json_data_source_view.h:27
TextLine::kv_start
int kv_start
Definition json_data_source_view.h:31