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 struct DecodeTraceRow {
85 // When adding a field, make sure it's initialized properly in
86 // DecodeTrace::update_rows()
89 unsigned int height, expanded_height, title_width, animation_step;
90 bool exists, currently_visible, has_hidden_classes;
91 bool expand_marker_highlighted, expanding, expanded, collapsing;
92 QPolygon expand_marker_shape;
93 float anim_height, anim_shape;
96 QWidget* header_container;
97 QWidget* selector_container;
98 vector<QCheckBox*> selectors;
101 map<uint32_t, QColor> ann_class_color;
104 class DecodeTrace : public Trace
109 static const QColor ErrorBgColor;
110 static const QColor NoDecodeColor;
111 static const QColor ExpandMarkerWarnColor;
112 static const uint8_t ExpansionAreaHeaderAlpha;
113 static const uint8_t ExpansionAreaAlpha;
115 static const int ArrowSize;
116 static const double EndCapWidth;
117 static const int RowTitleMargin;
118 static const int DrawPadding;
120 static const int MaxTraceUpdateRate;
121 static const unsigned int AnimationDurationInTicks;
124 DecodeTrace(pv::Session &session, shared_ptr<SignalBase> signalbase,
129 bool enabled() const;
131 shared_ptr<SignalBase> base() const;
134 * Computes the vertical extents of the contents of this row item.
135 * @return A pair containing the minimum and maximum y-values.
137 pair<int, int> v_extents() const;
140 * Paints the background layer of the trace with a QPainter
141 * @param p the QPainter to paint into.
142 * @param pp the painting parameters object to paint with..
144 void paint_back(QPainter &p, ViewItemPaintParams &pp);
147 * Paints the mid-layer of the trace with a QPainter
148 * @param p the QPainter to paint into.
149 * @param pp the painting parameters object to paint with.
151 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
154 * Paints the foreground layer of the trace with a QPainter
155 * @param p the QPainter to paint into.
156 * @param pp the painting parameters object to paint with.
158 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
160 void populate_popup_form(QWidget *parent, QFormLayout *form);
162 QMenu* create_header_context_menu(QWidget *parent);
164 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
166 virtual void delete_pressed();
168 virtual void hover_point_changed(const QPoint &hp);
170 virtual void mouse_left_press_event(const QMouseEvent* event);
173 void draw_annotations(vector<const Annotation*> annotations, QPainter &p,
174 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row);
176 void draw_annotation(const Annotation* a, QPainter &p,
177 const ViewItemPaintParams &pp, int y, const DecodeTraceRow& row) const;
179 void draw_annotation_block(qreal start, qreal end, Annotation::Class ann_class,
180 bool use_ann_format, QPainter &p, int y, const DecodeTraceRow& row) const;
182 void draw_instant(const Annotation* a, QPainter &p, qreal x, int y) const;
184 void draw_range(const Annotation* a, QPainter &p, qreal start, qreal end,
185 int y, const ViewItemPaintParams &pp, int row_title_width) const;
187 void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp);
189 void draw_unresolved_period(QPainter &p, int left, int right) const;
191 pair<double, double> get_pixels_offset_samples_per_pixel() const;
194 * Determines the start and end sample for a given pixel range.
195 * @param x_start the X coordinate of the start sample in the view
196 * @param x_end the X coordinate of the end sample in the view
197 * @return Returns a pair containing the start sample and the end
198 * sample that correspond to the start and end coordinates.
200 pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const;
202 QColor get_row_color(int row_index) const;
203 QColor get_annotation_color(QColor row_color, int annotation_index) const;
205 unsigned int get_row_y(const DecodeTraceRow* row) const;
207 DecodeTraceRow* get_row_at_point(const QPoint &point);
209 const QString get_annotation_at_point(const QPoint &point);
211 void update_stack_button();
213 void create_decoder_form(int index, shared_ptr<Decoder> &dec,
214 QWidget *parent, QFormLayout *form);
216 QComboBox* create_channel_selector(QWidget *parent,
217 const data::decode::DecodeChannel *ch);
218 QComboBox* create_channel_selector_init_state(QWidget *parent,
219 const data::decode::DecodeChannel *ch);
221 void export_annotations(vector<const Annotation*> *annotations) const;
223 void initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id);
227 * Sets row r to expanded state without forcing an update of the view
229 void set_row_expanded(DecodeTraceRow* r);
232 * Sets row r to collapsed state without forcing an update of the view
234 void set_row_collapsed(DecodeTraceRow* r);
236 void update_expanded_rows();
239 void on_setting_changed(const QString &key, const QVariant &value);
241 void on_new_annotations();
242 void on_delayed_trace_update();
243 void on_decode_reset();
244 void on_decode_finished();
245 void on_pause_decode();
249 void on_channel_selected(int);
251 void on_channels_updated();
253 void on_init_state_changed(int);
255 void on_stack_decoder(srd_decoder *decoder);
257 void on_delete_decoder(int index);
259 void on_show_hide_decoder(int index);
260 void on_show_hide_row(int row_id);
261 void on_show_hide_class(QWidget* sender);
263 void on_copy_annotation_to_clipboard();
265 void on_export_row();
266 void on_export_all_rows();
267 void on_export_row_with_cursor();
268 void on_export_all_rows_with_cursor();
269 void on_export_row_from_here();
270 void on_export_all_rows_from_here();
272 void on_animation_timer();
275 pv::Session &session_;
276 shared_ptr<data::DecodeSignal> decode_signal_;
278 deque<DecodeTraceRow> rows_;
279 mutable mutex row_modification_mutex_;
281 map<QComboBox*, uint16_t> channel_id_map_; // channel selector -> decode channel ID
282 map<QComboBox*, uint16_t> init_state_map_; // init state selector -> decode channel ID
283 list< shared_ptr<pv::binding::Decoder> > bindings_;
285 const Row* selected_row_;
286 pair<uint64_t, uint64_t> selected_sample_range_;
288 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
289 QPushButton* stack_button_;
291 unsigned int default_row_height_, annotation_height_;
292 unsigned int visible_rows_, max_visible_rows_;
294 int min_useful_label_width_;
295 bool always_show_all_rows_;
297 QSignalMapper delete_mapper_, show_hide_mapper_;
298 QSignalMapper row_show_hide_mapper_, class_show_hide_mapper_;
300 QTimer delayed_trace_updater_, animation_timer_;
302 QPolygon default_marker_shape_;
304 #if DECODETRACE_SHOW_RENDER_TIME
305 QElapsedTimer render_time_;
313 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP