| 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
14#include "base_data_source_view.h"
15
16#include <ui/qt/utils/field_information.h>
17
18#include <QAbstractScrollArea>
19#include <QTextLayout>
20
21class QTextLayout;
22
23 struct 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
36 struct TextBlock {
37 QList<TextLine> text_lines;
38};
39
40 class JsonDataSourceView : public BaseDataSourceView
41{
42 Q_OBJECT
43public:
44 explicit JsonDataSourceView(const QByteArray &data, proto_node *root_node, QWidget *parent = nullptr);
45 ~JsonDataSourceView();
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 showEvent(QShowEvent *);
66 virtual void keyPressEvent(QKeyEvent *event);
67 virtual void mousePressEvent (QMouseEvent *event);
68 virtual void mouseMoveEvent (QMouseEvent * event);
69 virtual void leaveEvent(QEvent *event);
70
71private:
72 void updateLayoutMetrics();
73 int stringWidth(const QString &line);
74 void updateScrollbars();
75
76 void addTextLine(TextBlock &text_block, TextLine &text_line, const QString &next_line = QString());
77 bool prettyPrintPlain(const char *in_buf, QString &out_str);
78 bool addJsonObject();
79
80 int offsetChars(bool include_pad = true);
81 int offsetPixels();
82 const TextLine *findTextLine(int line);
83
84 QTextLayout *layout_;
85 QList<TextBlock> text_blocks_;
86
87 bool layout_dirty_;
88 bool show_offset_; // Should we show the byte offset?
89 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
90 int line_height_; // Font line spacing
91 qsizetype max_line_length_; // In characters
92
93 proto_node *root_node_;
94 const TextLine *selected_line_;
95 const TextLine *hovered_line_;
96};
base_data_source_view.h
BaseDataSourceView
Definition base_data_source_view.h:17
FieldInformation
Definition field_information.h:23
JsonDataSourceView
Definition json_data_source_view.h:41
field_information.h
_proto_node
Definition proto.h:907
TextBlock
Definition json_data_source_view.h:36
TextLine
Definition json_data_source_view.h:23