2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
33 #include <QElapsedTimer>
35 #include <QPushButton>
36 #include <QSignalMapper>
39 #include <pv/binding/decoder.hpp>
40 #include <pv/data/decode/decoder.hpp>
41 #include <pv/data/decode/annotation.hpp>
42 #include <pv/data/decode/row.hpp>
43 #include <pv/data/signalbase.hpp>
45 #define DECODETRACE_SHOW_RENDER_TIME 0
52 using std::shared_ptr;
55 using pv::data::SignalBase;
56 using pv::data::decode::Annotation;
57 using pv::data::decode::Decoder;
58 using pv::data::decode::Row;
78 class DecoderGroupBox;
84 class ContainerWidget;
86 struct DecodeTraceRow {
87 // When adding a field, make sure it's initialized properly in
88 // DecodeTrace::update_rows()
91 unsigned int height, expanded_height, title_width, animation_step;
92 bool exists, currently_visible, has_hidden_classes;
93 bool expand_marker_highlighted, expanding, expanded, collapsing;
94 QPolygon expand_marker_shape;
95 float anim_height, anim_shape;
97 ContainerWidget* container;
98 QWidget* header_container;
99 QWidget* selector_container;
100 QCheckBox* row_visibility_checkbox;
101 vector<QCheckBox*> selectors;
104 map<uint32_t, QColor> ann_class_color;
105 map<uint32_t, QColor> ann_class_dark_color;
108 class ContainerWidget : public QWidget
113 ContainerWidget(QWidget *parent = nullptr);
115 virtual void resizeEvent(QResizeEvent* event);
118 void widgetResized(QWidget* sender);
121 class DecodeTrace : public Trace
126 static const QColor ErrorBgColor;
127 static const QColor NoDecodeColor;
128 static const QColor ExpandMarkerWarnColor;
129 static const QColor ExpandMarkerHiddenColor;
130 static const uint8_t ExpansionAreaHeaderAlpha;
131 static const uint8_t ExpansionAreaAlpha;
133 static const int ArrowSize;
134 static const double EndCapWidth;
135 static const int RowTitleMargin;
136 static const int DrawPadding;
138 static const int MaxTraceUpdateRate;
139 static const int AnimationDurationInTicks;
140 static const int HiddenRowHideDelay;
143 DecodeTrace(pv::Session &session, shared_ptr<SignalBase> signalbase,
148 bool enabled() const;
150 shared_ptr<SignalBase> base() const;
153 * Computes the vertical extents of the contents of this row item.
154 * @return A pair containing the minimum and maximum y-values.
156 pair<int, int> v_extents() const;
159 * Paints the background layer of the trace with a QPainter
160 * @param p the QPainter to paint into.
161 * @param pp the painting parameters object to paint with..
163 void paint_back(QPainter &p, ViewItemPaintParams &pp);
166 * Paints the mid-layer of the trace with a QPainter
167 * @param p the QPainter to paint into.
168 * @param pp the painting parameters object to paint with.
170 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
173 * Paints the foreground layer of the trace with a QPainter
174 * @param p the QPainter to paint into.
175 * @param pp the painting parameters object to paint with.
177 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
179 void populate_popup_form(QWidget *parent, QFormLayout *form);
181 QMenu* create_header_context_menu(QWidget *parent);
183 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
185 virtual void delete_pressed();
187 virtual void hover_point_changed(const QPoint &hp);
189 virtual void mouse_left_press_event(const QMouseEvent* event);
192 void draw_annotations(deque<const Annotation*>& annotations, QPainter &p,
193 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row);
195 void draw_annotation(const Annotation* a, QPainter &p,
196 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row) const;
198 void draw_annotation_block(qreal start, qreal end, Annotation::Class ann_class,
199 bool use_ann_format, QPainter &p, int y, const DecodeTraceRow& row) const;
201 void draw_instant(const Annotation* a, QPainter &p, qreal x, int y) const;
203 void draw_range(const Annotation* a, QPainter &p, qreal start, qreal end,
204 int y, const ViewItemPaintParams &pp, int row_title_width) const;
206 void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp);
208 void draw_unresolved_period(QPainter &p, int left, int right) const;
210 pair<double, double> get_pixels_offset_samples_per_pixel() const;
213 * Determines the start and end sample for a given pixel range.
214 * @param x_start the X coordinate of the start sample in the view
215 * @param x_end the X coordinate of the end sample in the view
216 * @return Returns a pair containing the start sample and the end
217 * sample that correspond to the start and end coordinates.
219 pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const;
221 QColor get_row_color(int row_index) const;
222 QColor get_annotation_color(QColor row_color, int annotation_index) const;
224 unsigned int get_row_y(const DecodeTraceRow* row) const;
226 DecodeTraceRow* get_row_at_point(const QPoint &point);
228 const QString get_annotation_at_point(const QPoint &point);
230 void update_stack_button();
232 void create_decoder_form(int index, shared_ptr<Decoder> &dec,
233 QWidget *parent, QFormLayout *form);
235 QComboBox* create_channel_selector(QWidget *parent,
236 const data::decode::DecodeChannel *ch);
237 QComboBox* create_channel_selector_init_state(QWidget *parent,
238 const data::decode::DecodeChannel *ch);
240 void export_annotations(deque<const Annotation*>& annotations) const;
242 void initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id);
246 * Sets row r to expanded state without forcing an update of the view
248 void set_row_expanded(DecodeTraceRow* r);
251 * Sets row r to collapsed state without forcing an update of the view
253 void set_row_collapsed(DecodeTraceRow* r);
255 void update_expanded_rows();
258 void on_setting_changed(const QString &key, const QVariant &value);
260 void on_new_annotations();
261 void on_delayed_trace_update();
262 void on_decode_reset();
263 void on_decode_finished();
264 void on_pause_decode();
268 void on_channel_selected(int);
270 void on_channels_updated();
272 void on_init_state_changed(int);
274 void on_stack_decoder(srd_decoder *decoder);
276 void on_delete_decoder(int index);
278 void on_show_hide_decoder(int index);
279 void on_show_hide_row(int row_id);
280 void on_show_hide_class(QWidget* sender);
281 void on_show_all_classes();
282 void on_hide_all_classes();
283 void on_row_container_resized(QWidget* sender);
285 void on_copy_annotation_to_clipboard();
287 void on_export_row();
288 void on_export_all_rows();
289 void on_export_row_with_cursor();
290 void on_export_all_rows_with_cursor();
291 void on_export_row_from_here();
292 void on_export_all_rows_from_here();
294 void on_animation_timer();
295 void on_hide_hidden_rows();
298 pv::Session &session_;
299 shared_ptr<data::DecodeSignal> decode_signal_;
301 deque<DecodeTraceRow> rows_;
302 mutable mutex row_modification_mutex_;
304 map<QComboBox*, uint16_t> channel_id_map_; // channel selector -> decode channel ID
305 map<QComboBox*, uint16_t> init_state_map_; // init state selector -> decode channel ID
306 list< shared_ptr<pv::binding::Decoder> > bindings_;
308 const Row* selected_row_;
309 pair<uint64_t, uint64_t> selected_sample_range_;
311 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
312 QPushButton* stack_button_;
314 unsigned int default_row_height_, annotation_height_;
315 unsigned int visible_rows_, max_visible_rows_;
317 int min_useful_label_width_;
318 bool always_show_all_rows_, show_hidden_rows_;
320 QSignalMapper delete_mapper_, show_hide_mapper_;
321 QSignalMapper row_show_hide_mapper_, class_show_hide_mapper_;
323 QTimer delayed_trace_updater_, animation_timer_, delayed_hidden_row_hider_;
325 QPolygon default_marker_shape_;
327 #if DECODETRACE_SHOW_RENDER_TIME
328 QElapsedTimer render_time_;
336 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP