]> sigrok.org Git - pulseview.git/blame - pv/views/trace/decodetrace.hpp
Backport recent changes from mainline.
[pulseview.git] / pv / views / trace / decodetrace.hpp
CommitLineData
55d3603d
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
55d3603d
JH
18 */
19
f4e57597
SA
20#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
21#define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
55d3603d 22
10f5e6f5 23#include <config.h>
2acdb232 24#include "trace.hpp"
55d3603d 25
7491a29f 26#include <list>
4e5a4405 27#include <map>
f9abf97e 28#include <memory>
50631798 29#include <vector>
4e5a4405 30
3782d860
UH
31#include <QColor>
32#include <QComboBox>
10f5e6f5
UH
33#include <QCheckBox>
34#include <QElapsedTimer>
35#include <QPolygon>
36#include <QPushButton>
613d097c 37#include <QSignalMapper>
3782d860 38#include <QTimer>
613d097c 39
3cc9ad7b 40#include <pv/binding/decoder.hpp>
10f5e6f5 41#include <pv/data/decode/decoder.hpp>
3782d860 42#include <pv/data/decode/annotation.hpp>
2acdb232 43#include <pv/data/decode/row.hpp>
aca9aa83 44#include <pv/data/signalbase.hpp>
4e5a4405 45
10f5e6f5
UH
46#define DECODETRACE_SHOW_RENDER_TIME 0
47
48using std::deque;
6f925ba9
UH
49using std::list;
50using std::map;
10f5e6f5 51using std::mutex;
6f925ba9
UH
52using std::pair;
53using std::shared_ptr;
54using std::vector;
55
10f5e6f5
UH
56using pv::data::SignalBase;
57using pv::data::decode::Annotation;
58using pv::data::decode::Decoder;
59using pv::data::decode::Row;
60
8bd26d8b 61struct srd_channel;
e563a7c0 62struct srd_decoder;
4e5a4405 63
55d3603d 64namespace pv {
119aff65 65
2b81ae46 66class Session;
83c23cc9 67
119aff65 68namespace data {
3782d860
UH
69struct DecodeChannel;
70class DecodeSignal;
7491a29f
JH
71
72namespace decode {
73class Decoder;
10f5e6f5 74class Row;
119aff65 75}
3782d860 76} // namespace data
119aff65 77
dd048a7e
JH
78namespace widgets {
79class DecoderGroupBox;
80}
81
f4e57597 82namespace views {
1573bf16 83namespace trace {
55d3603d 84
10f5e6f5
UH
85class ContainerWidget;
86
87struct DecodeTraceRow {
88 // When adding a field, make sure it's initialized properly in
89 // DecodeTrace::update_rows()
90
91 Row* decode_row;
92 unsigned int height, expanded_height, title_width, animation_step;
93 bool exists, currently_visible, has_hidden_classes;
94 bool expand_marker_highlighted, expanding, expanded, collapsing;
95 QPolygon expand_marker_shape;
96 float anim_height, anim_shape;
97
98 ContainerWidget* container;
99 QWidget* header_container;
100 QWidget* selector_container;
101 QCheckBox* row_visibility_checkbox;
102 vector<QCheckBox*> selectors;
103
104 QColor row_color;
105 map<uint32_t, QColor> ann_class_color;
106 map<uint32_t, QColor> ann_class_dark_color;
107};
108
109class ContainerWidget : public QWidget
110{
111 Q_OBJECT
112
113public:
114 ContainerWidget(QWidget *parent = nullptr);
115
116 virtual void resizeEvent(QResizeEvent* event);
117
118Q_SIGNALS:
119 void widgetResized(QWidget* sender);
120};
121
b9329558 122class DecodeTrace : public Trace
55d3603d 123{
e0fc5810
JH
124 Q_OBJECT
125
7491a29f 126private:
3782d860
UH
127 static const QColor ErrorBgColor;
128 static const QColor NoDecodeColor;
10f5e6f5
UH
129 static const QColor ExpandMarkerWarnColor;
130 static const QColor ExpandMarkerHiddenColor;
131 static const uint8_t ExpansionAreaHeaderAlpha;
132 static const uint8_t ExpansionAreaAlpha;
06bb4e6a 133
88908838 134 static const int ArrowSize;
06e810f2 135 static const double EndCapWidth;
aee9dcf3 136 static const int RowTitleMargin;
06e810f2
JH
137 static const int DrawPadding;
138
3782d860 139 static const int MaxTraceUpdateRate;
10f5e6f5
UH
140 static const int AnimationDurationInTicks;
141 static const int HiddenRowHideDelay;
06e810f2 142
55d3603d 143public:
10f5e6f5 144 DecodeTrace(pv::Session &session, shared_ptr<SignalBase> signalbase,
6e89374a 145 int index);
55d3603d 146
10f5e6f5
UH
147 ~DecodeTrace();
148
55d3603d
JH
149 bool enabled() const;
150
10f5e6f5
UH
151 shared_ptr<SignalBase> base() const;
152
153 /**
154 * Sets the owner this trace in the view trace hierachy.
155 * @param The new owner of the trace.
156 */
157 virtual void set_owner(TraceTreeItemOwner *owner);
bb7dd726 158
a5d93c27
JH
159 /**
160 * Computes the vertical extents of the contents of this row item.
161 * @return A pair containing the minimum and maximum y-values.
162 */
6f925ba9 163 pair<int, int> v_extents() const;
a5d93c27 164
55d3603d 165 /**
fe08b6e8
JH
166 * Paints the background layer of the trace with a QPainter
167 * @param p the QPainter to paint into.
3eb29afd 168 * @param pp the painting parameters object to paint with..
223d0c37 169 */
60938e04 170 void paint_back(QPainter &p, ViewItemPaintParams &pp);
fe08b6e8
JH
171
172 /**
173 * Paints the mid-layer of the trace with a QPainter
55d3603d 174 * @param p the QPainter to paint into.
3eb29afd 175 * @param pp the painting parameters object to paint with.
223d0c37 176 */
60938e04 177 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
55d3603d 178
88908838
JH
179 /**
180 * Paints the foreground layer of the trace with a QPainter
181 * @param p the QPainter to paint into.
3eb29afd 182 * @param pp the painting parameters object to paint with.
223d0c37 183 */
60938e04 184 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
88908838 185
4e5a4405
JH
186 void populate_popup_form(QWidget *parent, QFormLayout *form);
187
3782d860
UH
188 QMenu* create_header_context_menu(QWidget *parent);
189
190 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
c51482b3 191
10f5e6f5
UH
192 virtual void delete_pressed();
193
194 virtual void hover_point_changed(const QPoint &hp);
195
196 virtual void mouse_left_press_event(const QMouseEvent* event);
5ed1adf5 197
ad50ac1a 198private:
10f5e6f5
UH
199 void draw_annotations(deque<const Annotation*>& annotations, QPainter &p,
200 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row);
50631798 201
10f5e6f5
UH
202 void draw_annotation(const Annotation* a, QPainter &p,
203 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row) const;
06e810f2 204
10f5e6f5
UH
205 void draw_annotation_block(qreal start, qreal end, Annotation::Class ann_class,
206 bool use_ann_format, QPainter &p, int y, const DecodeTraceRow& row) const;
50631798 207
10f5e6f5 208 void draw_instant(const Annotation* a, QPainter &p, qreal x, int y) const;
06e810f2 209
10f5e6f5
UH
210 void draw_range(const Annotation* a, QPainter &p, qreal start, qreal end,
211 int y, const ViewItemPaintParams &pp, int row_title_width) const;
06e810f2 212
10f5e6f5 213 void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp);
ad50ac1a 214
10f5e6f5 215 void draw_unresolved_period(QPainter &p, int left, int right) const;
7f8517f6 216
6f925ba9 217 pair<double, double> get_pixels_offset_samples_per_pixel() const;
7f8517f6
SA
218
219 /**
220 * Determines the start and end sample for a given pixel range.
221 * @param x_start the X coordinate of the start sample in the view
222 * @param x_end the X coordinate of the end sample in the view
223 * @return Returns a pair containing the start sample and the end
224 * sample that correspond to the start and end coordinates.
225 */
3782d860
UH
226 pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const;
227
228 QColor get_row_color(int row_index) const;
229 QColor get_annotation_color(QColor row_color, int annotation_index) const;
5dfeb70f 230
10f5e6f5
UH
231 unsigned int get_row_y(const DecodeTraceRow* row) const;
232
233 DecodeTraceRow* get_row_at_point(const QPoint &point);
e2f90c50 234
117cdea3 235 const QString get_annotation_at_point(const QPoint &point);
e2f90c50 236
10f5e6f5
UH
237 void update_stack_button();
238
239 void create_decoder_form(int index, shared_ptr<Decoder> &dec,
7491a29f
JH
240 QWidget *parent, QFormLayout *form);
241
6ac6242b 242 QComboBox* create_channel_selector(QWidget *parent,
10f5e6f5 243 const data::decode::DecodeChannel *ch);
3782d860 244 QComboBox* create_channel_selector_init_state(QWidget *parent,
10f5e6f5 245 const data::decode::DecodeChannel *ch);
7491a29f 246
10f5e6f5 247 void export_annotations(deque<const Annotation*>& annotations) const;
4e5a4405 248
10f5e6f5
UH
249 void initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id);
250 void update_rows();
251
252 /**
253 * Sets row r to expanded state without forcing an update of the view
254 */
255 void set_row_expanded(DecodeTraceRow* r);
256
257 /**
258 * Sets row r to collapsed state without forcing an update of the view
259 */
260 void set_row_collapsed(DecodeTraceRow* r);
261
262 void update_expanded_rows();
33c62f44 263
e9213170 264private Q_SLOTS:
10f5e6f5
UH
265 void on_setting_changed(const QString &key, const QVariant &value);
266
3782d860
UH
267 void on_new_annotations();
268 void on_delayed_trace_update();
269 void on_decode_reset();
270 void on_decode_finished();
271 void on_pause_decode();
9cef9567 272
c51482b3
JH
273 void on_delete();
274
6ac6242b 275 void on_channel_selected(int);
4e5a4405 276
3782d860
UH
277 void on_channels_updated();
278
279 void on_init_state_changed(int);
407c9ebe 280
7491a29f
JH
281 void on_stack_decoder(srd_decoder *decoder);
282
613d097c
JH
283 void on_delete_decoder(int index);
284
dd048a7e 285 void on_show_hide_decoder(int index);
10f5e6f5
UH
286 void on_show_hide_row(int row_id);
287 void on_show_hide_class(QWidget* sender);
288 void on_show_all_classes();
289 void on_hide_all_classes();
290 void on_row_container_resized(QWidget* sender);
291
292 void on_copy_annotation_to_clipboard();
dd048a7e 293
3782d860
UH
294 void on_export_row();
295 void on_export_all_rows();
296 void on_export_row_with_cursor();
297 void on_export_all_rows_with_cursor();
298 void on_export_row_from_here();
299 void on_export_all_rows_from_here();
300
10f5e6f5
UH
301 void on_animation_timer();
302 void on_hide_hidden_rows();
303
55d3603d 304private:
2b81ae46 305 pv::Session &session_;
3782d860 306 shared_ptr<data::DecodeSignal> decode_signal_;
e0fc5810 307
10f5e6f5
UH
308 deque<DecodeTraceRow> rows_;
309 mutable mutex row_modification_mutex_;
4e5a4405 310
3782d860
UH
311 map<QComboBox*, uint16_t> channel_id_map_; // channel selector -> decode channel ID
312 map<QComboBox*, uint16_t> init_state_map_; // init state selector -> decode channel ID
6f925ba9 313 list< shared_ptr<pv::binding::Decoder> > bindings_;
4e5a4405 314
10f5e6f5 315 const Row* selected_row_;
3782d860
UH
316 pair<uint64_t, uint64_t> selected_sample_range_;
317
6f925ba9 318 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
10f5e6f5 319 QPushButton* stack_button_;
613d097c 320
10f5e6f5
UH
321 unsigned int default_row_height_, annotation_height_;
322 unsigned int visible_rows_;
88908838 323
752281db 324 int min_useful_label_width_;
10f5e6f5 325 bool always_show_all_rows_, show_hidden_rows_;
752281db 326
8dbbc7f0 327 QSignalMapper delete_mapper_, show_hide_mapper_;
10f5e6f5
UH
328 QSignalMapper row_show_hide_mapper_, class_show_hide_mapper_;
329
330 QTimer delayed_trace_updater_, animation_timer_, delayed_hidden_row_hider_;
331
332 QPolygon default_marker_shape_;
3782d860 333
10f5e6f5
UH
334#if DECODETRACE_SHOW_RENDER_TIME
335 QElapsedTimer render_time_;
336#endif
55d3603d
JH
337};
338
1573bf16 339} // namespace trace
f4e57597 340} // namespace views
55d3603d
JH
341} // namespace pv
342
f4e57597 343#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP