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
34 #include <QElapsedTimer>
36 #include <QPushButton>
37 #include <QSignalMapper>
40 #include <pv/binding/decoder.hpp>
41 #include <pv/data/decode/decoder.hpp>
42 #include <pv/data/decode/annotation.hpp>
43 #include <pv/data/decode/row.hpp>
44 #include <pv/data/signalbase.hpp>
46 #define DECODETRACE_SHOW_RENDER_TIME 0
53 using std::shared_ptr;
56 using pv::data::SignalBase;
57 using pv::data::decode::Annotation;
58 using pv::data::decode::Decoder;
59 using pv::data::decode::Row;
79 class DecoderGroupBox;
85 class ContainerWidget;
87 struct DecodeTraceRow {
88 // When adding a field, make sure it's initialized properly in
89 // DecodeTrace::update_rows()
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;
98 ContainerWidget* container;
99 QWidget* header_container;
100 QWidget* selector_container;
101 QCheckBox* row_visibility_checkbox;
102 vector<QCheckBox*> selectors;
105 map<uint32_t, QColor> ann_class_color;
106 map<uint32_t, QColor> ann_class_dark_color;
109 class ContainerWidget : public QWidget
114 ContainerWidget(QWidget *parent = nullptr);
116 virtual void resizeEvent(QResizeEvent* event);
119 void widgetResized(QWidget* sender);
122 class DecodeTrace : public Trace
127 static const QColor ErrorBgColor;
128 static const QColor NoDecodeColor;
129 static const QColor ExpandMarkerWarnColor;
130 static const QColor ExpandMarkerHiddenColor;
131 static const uint8_t ExpansionAreaHeaderAlpha;
132 static const uint8_t ExpansionAreaAlpha;
134 static const int ArrowSize;
135 static const double EndCapWidth;
136 static const int RowTitleMargin;
137 static const int DrawPadding;
139 static const int MaxTraceUpdateRate;
140 static const int AnimationDurationInTicks;
141 static const int HiddenRowHideDelay;
144 DecodeTrace(pv::Session &session, shared_ptr<SignalBase> signalbase,
149 bool enabled() const;
151 shared_ptr<SignalBase> base() const;
154 * Sets the owner this trace in the view trace hierachy.
155 * @param The new owner of the trace.
157 virtual void set_owner(TraceTreeItemOwner *owner);
160 * Computes the vertical extents of the contents of this row item.
161 * @return A pair containing the minimum and maximum y-values.
163 pair<int, int> v_extents() const;
166 * Paints the background 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_back(QPainter &p, ViewItemPaintParams &pp);
173 * Paints the mid-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_mid(QPainter &p, ViewItemPaintParams &pp);
180 * Paints the foreground layer of the trace with a QPainter
181 * @param p the QPainter to paint into.
182 * @param pp the painting parameters object to paint with.
184 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
186 void populate_popup_form(QWidget *parent, QFormLayout *form);
188 QMenu* create_header_context_menu(QWidget *parent);
190 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
192 virtual void delete_pressed();
194 virtual void hover_point_changed(const QPoint &hp);
196 virtual void mouse_left_press_event(const QMouseEvent* event);
199 void draw_annotations(deque<const Annotation*>& annotations, QPainter &p,
200 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row);
202 void draw_annotation(const Annotation* a, QPainter &p,
203 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row) const;
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;
208 void draw_instant(const Annotation* a, QPainter &p, qreal x, int y) const;
210 void draw_range(const Annotation* a, QPainter &p, qreal start, qreal end,
211 int y, const ViewItemPaintParams &pp, int row_title_width) const;
213 void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp);
215 void draw_unresolved_period(QPainter &p, int left, int right) const;
217 pair<double, double> get_pixels_offset_samples_per_pixel() const;
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.
226 pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const;
228 QColor get_row_color(int row_index) const;
229 QColor get_annotation_color(QColor row_color, int annotation_index) const;
231 unsigned int get_row_y(const DecodeTraceRow* row) const;
233 DecodeTraceRow* get_row_at_point(const QPoint &point);
235 const QString get_annotation_at_point(const QPoint &point);
237 void update_stack_button();
239 void create_decoder_form(int index, shared_ptr<Decoder> &dec,
240 QWidget *parent, QFormLayout *form);
242 QComboBox* create_channel_selector(QWidget *parent,
243 const data::decode::DecodeChannel *ch);
244 QComboBox* create_channel_selector_init_state(QWidget *parent,
245 const data::decode::DecodeChannel *ch);
247 void export_annotations(deque<const Annotation*>& annotations) const;
249 void initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id);
253 * Sets row r to expanded state without forcing an update of the view
255 void set_row_expanded(DecodeTraceRow* r);
258 * Sets row r to collapsed state without forcing an update of the view
260 void set_row_collapsed(DecodeTraceRow* r);
262 void update_expanded_rows();
265 void on_setting_changed(const QString &key, const QVariant &value);
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();
275 void on_channel_selected(int);
277 void on_channels_updated();
279 void on_init_state_changed(int);
281 void on_stack_decoder(srd_decoder *decoder);
283 void on_delete_decoder(int index);
285 void on_show_hide_decoder(int index);
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);
292 void on_copy_annotation_to_clipboard();
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();
301 void on_animation_timer();
302 void on_hide_hidden_rows();
305 pv::Session &session_;
306 shared_ptr<data::DecodeSignal> decode_signal_;
308 deque<DecodeTraceRow> rows_;
309 mutable mutex row_modification_mutex_;
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
313 list< shared_ptr<pv::binding::Decoder> > bindings_;
315 const Row* selected_row_;
316 pair<uint64_t, uint64_t> selected_sample_range_;
318 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
319 QPushButton* stack_button_;
321 unsigned int default_row_height_, annotation_height_;
322 unsigned int visible_rows_;
324 int min_useful_label_width_;
325 bool always_show_all_rows_, show_hidden_rows_;
327 QSignalMapper delete_mapper_, show_hide_mapper_;
328 QSignalMapper row_show_hide_mapper_, class_show_hide_mapper_;
330 QTimer delayed_trace_updater_, animation_timer_, delayed_hidden_row_hider_;
332 QPolygon default_marker_shape_;
334 #if DECODETRACE_SHOW_RENDER_TIME
335 QElapsedTimer render_time_;
343 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP