| 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
21 class 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
43 public:
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
51 public slots:
52 void setMonospaceFont(const QFont &mono_font);
53
54 void markField(int start, int length, bool scroll_to = true, bool hover = false);
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
60 protected:
61 // virtual bool event(QEvent *event);
62 virtual void paintEvent(QPaintEvent *);
63 virtual void resizeEvent(QResizeEvent *);
64 virtual void showEvent(QShowEvent *);
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
70 private:
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 layout_dirty_;
87 bool show_offset_; // Should we show the byte offset?
88 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
89 int line_height_; // Font line spacing
90 qsizetype max_line_length_; // In characters
91
92 proto_node *root_node_;
93 const TextLine *selected_line_;
94 const TextLine *hovered_line_;
95};
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