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