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
41{
42 Q_OBJECT
43public:
44 explicit JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent = nullptr);
46
47signals:
48 void fieldSelected(FieldInformation *);
49 void fieldHighlight(FieldInformation *);
50
51public slots:
52 void setMonospaceFont(const QFont &mono_font);
53
54 void markField(int start, int length, bool scroll_to = true);
55 void unmarkField();
56 // We're assuming that we have a 1:1 correspondence between the view and a single protocol.
57 void markProtocol(int start, int length) {Q_UNUSED(start) Q_UNUSED(length)}
58 void markAppendix(int start, int length) {Q_UNUSED(start) Q_UNUSED(length)}
59 void saveSelected(int start) {Q_UNUSED(start)}
60
61protected:
62 // virtual bool event(QEvent *event);
63 virtual void paintEvent(QPaintEvent *);
64 virtual void resizeEvent(QResizeEvent *);
65 virtual void keyPressEvent(QKeyEvent *event);
66 virtual void mousePressEvent (QMouseEvent *event);
67 virtual void mouseMoveEvent (QMouseEvent * event);
68 virtual void leaveEvent(QEvent *event);
69
70private:
71 void updateLayoutMetrics();
72 int stringWidth(const QString &line);
73 void updateScrollbars();
74
75 void addTextLine(TextBlock &text_block, TextLine &text_line, const QString &next_line = QString());
76 bool prettyPrintPlain(const char *in_buf, QString &out_str);
77 bool addJsonObject();
78
79 int offsetChars(bool include_pad = true);
80 int offsetPixels();
81 const TextLine *findTextLine(int line);
82
83 QTextLayout *layout_;
84 QList<TextBlock> text_blocks_;
85
86 bool show_offset_; // Should we show the byte offset?
87 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
88 int line_height_; // Font line spacing
89 qsizetype max_line_length_; // In characters
90
91 proto_node *root_node_;
92 const TextLine *selected_line_;
93 const TextLine *hovered_line_;
94};
Definition base_data_source_view.h:17
Definition field_information.h:23
Definition json_data_source_view.h:41
Definition proto.h:907
Definition json_data_source_view.h:36
Definition json_data_source_view.h:23