]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/trace/decodetrace.hpp
DecodeTrace: Add profiling and some optimizations
[pulseview.git] / pv / views / trace / decodetrace.hpp
... / ...
CommitLineData
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
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
21#define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
22
23#include <config.h>
24#include "trace.hpp"
25
26#include <list>
27#include <map>
28#include <memory>
29#include <vector>
30
31#include <QColor>
32#include <QCheckBox>
33#include <QElapsedTimer>
34#include <QPolygon>
35#include <QPushButton>
36#include <QSignalMapper>
37#include <QTimer>
38
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>
44
45#define DECODETRACE_SHOW_RENDER_TIME 0
46
47using std::deque;
48using std::list;
49using std::map;
50using std::mutex;
51using std::pair;
52using std::shared_ptr;
53using std::vector;
54
55using pv::data::SignalBase;
56using pv::data::decode::Annotation;
57using pv::data::decode::Decoder;
58using pv::data::decode::Row;
59
60struct srd_channel;
61struct srd_decoder;
62
63namespace pv {
64
65class Session;
66
67namespace data {
68struct DecodeChannel;
69class DecodeSignal;
70
71namespace decode {
72class Decoder;
73class Row;
74}
75} // namespace data
76
77namespace widgets {
78class DecoderGroupBox;
79}
80
81namespace views {
82namespace trace {
83
84struct DecodeTraceRow {
85 // When adding a field, make sure it's initialized properly in
86 // DecodeTrace::update_rows()
87
88 Row* decode_row;
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;
94
95 QWidget* container;
96 QWidget* header_container;
97 QWidget* selector_container;
98 vector<QCheckBox*> selectors;
99};
100
101class DecodeTrace : public Trace
102{
103 Q_OBJECT
104
105private:
106 static const QColor ErrorBgColor;
107 static const QColor NoDecodeColor;
108 static const QColor ExpandMarkerWarnColor;
109 static const uint8_t ExpansionAreaHeaderAlpha;
110 static const uint8_t ExpansionAreaAlpha;
111
112 static const int ArrowSize;
113 static const double EndCapWidth;
114 static const int RowTitleMargin;
115 static const int DrawPadding;
116
117 static const int MaxTraceUpdateRate;
118 static const unsigned int AnimationDurationInTicks;
119
120public:
121 DecodeTrace(pv::Session &session, shared_ptr<SignalBase> signalbase,
122 int index);
123
124 ~DecodeTrace();
125
126 bool enabled() const;
127
128 shared_ptr<SignalBase> base() const;
129
130 /**
131 * Computes the vertical extents of the contents of this row item.
132 * @return A pair containing the minimum and maximum y-values.
133 */
134 pair<int, int> v_extents() const;
135
136 /**
137 * Paints the background layer of the trace with a QPainter
138 * @param p the QPainter to paint into.
139 * @param pp the painting parameters object to paint with..
140 */
141 void paint_back(QPainter &p, ViewItemPaintParams &pp);
142
143 /**
144 * Paints the mid-layer of the trace with a QPainter
145 * @param p the QPainter to paint into.
146 * @param pp the painting parameters object to paint with.
147 */
148 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
149
150 /**
151 * Paints the foreground layer of the trace with a QPainter
152 * @param p the QPainter to paint into.
153 * @param pp the painting parameters object to paint with.
154 */
155 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
156
157 void populate_popup_form(QWidget *parent, QFormLayout *form);
158
159 QMenu* create_header_context_menu(QWidget *parent);
160
161 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
162
163 virtual void delete_pressed();
164
165 virtual void hover_point_changed(const QPoint &hp);
166
167 virtual void mouse_left_press_event(const QMouseEvent* event);
168
169private:
170 void draw_annotations(vector<const Annotation*> annotations, QPainter &p,
171 int h, const ViewItemPaintParams &pp, int y, QColor row_color,
172 int row_title_width);
173
174 void draw_annotation(const Annotation* a, QPainter &p, int h,
175 const ViewItemPaintParams &pp, int y, QColor row_color,
176 int row_title_width) const;
177
178 void draw_annotation_block(qreal start, qreal end, Annotation::Class ann_class,
179 bool use_ann_format, QPainter &p, int h, int y, QColor row_color) const;
180
181 void draw_instant(const Annotation* a, QPainter &p, int h, qreal x, int y) const;
182
183 void draw_range(const Annotation* a, QPainter &p, int h, qreal start, qreal end,
184 int y, const ViewItemPaintParams &pp, int row_title_width) const;
185
186 void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp);
187
188 void draw_unresolved_period(QPainter &p, int h, int left, int right) const;
189
190 pair<double, double> get_pixels_offset_samples_per_pixel() const;
191
192 /**
193 * Determines the start and end sample for a given pixel range.
194 * @param x_start the X coordinate of the start sample in the view
195 * @param x_end the X coordinate of the end sample in the view
196 * @return Returns a pair containing the start sample and the end
197 * sample that correspond to the start and end coordinates.
198 */
199 pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const;
200
201 QColor get_row_color(int row_index) const;
202 QColor get_annotation_color(QColor row_color, int annotation_index) const;
203
204 unsigned int get_row_y(const DecodeTraceRow* row) const;
205
206 DecodeTraceRow* get_row_at_point(const QPoint &point);
207
208 const QString get_annotation_at_point(const QPoint &point);
209
210 void update_stack_button();
211
212 void create_decoder_form(int index, shared_ptr<Decoder> &dec,
213 QWidget *parent, QFormLayout *form);
214
215 QComboBox* create_channel_selector(QWidget *parent,
216 const data::decode::DecodeChannel *ch);
217 QComboBox* create_channel_selector_init_state(QWidget *parent,
218 const data::decode::DecodeChannel *ch);
219
220 void export_annotations(vector<const Annotation*> *annotations) const;
221
222 void initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id);
223 void update_rows();
224
225 /**
226 * Sets row r to expanded state without forcing an update of the view
227 */
228 void set_row_expanded(DecodeTraceRow* r);
229
230 /**
231 * Sets row r to collapsed state without forcing an update of the view
232 */
233 void set_row_collapsed(DecodeTraceRow* r);
234
235 void update_expanded_rows();
236
237private Q_SLOTS:
238 void on_setting_changed(const QString &key, const QVariant &value);
239
240 void on_new_annotations();
241 void on_delayed_trace_update();
242 void on_decode_reset();
243 void on_decode_finished();
244 void on_pause_decode();
245
246 void on_delete();
247
248 void on_channel_selected(int);
249
250 void on_channels_updated();
251
252 void on_init_state_changed(int);
253
254 void on_stack_decoder(srd_decoder *decoder);
255
256 void on_delete_decoder(int index);
257
258 void on_show_hide_decoder(int index);
259 void on_show_hide_row(int row_id);
260 void on_show_hide_class(QWidget* sender);
261
262 void on_copy_annotation_to_clipboard();
263
264 void on_export_row();
265 void on_export_all_rows();
266 void on_export_row_with_cursor();
267 void on_export_all_rows_with_cursor();
268 void on_export_row_from_here();
269 void on_export_all_rows_from_here();
270
271 void on_animation_timer();
272
273private:
274 pv::Session &session_;
275 shared_ptr<data::DecodeSignal> decode_signal_;
276
277 deque<DecodeTraceRow> rows_;
278 mutable mutex row_modification_mutex_;
279
280 map<QComboBox*, uint16_t> channel_id_map_; // channel selector -> decode channel ID
281 map<QComboBox*, uint16_t> init_state_map_; // init state selector -> decode channel ID
282 list< shared_ptr<pv::binding::Decoder> > bindings_;
283
284 const Row* selected_row_;
285 pair<uint64_t, uint64_t> selected_sample_range_;
286
287 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
288 QPushButton* stack_button_;
289
290 unsigned int default_row_height_, annotation_height_;
291 unsigned int visible_rows_, max_visible_rows_;
292
293 int min_useful_label_width_;
294 bool always_show_all_rows_;
295
296 QSignalMapper delete_mapper_, show_hide_mapper_;
297 QSignalMapper row_show_hide_mapper_, class_show_hide_mapper_;
298
299 QTimer delayed_trace_updater_, animation_timer_;
300
301 QPolygon default_marker_shape_;
302
303#if DECODETRACE_SHOW_RENDER_TIME
304 QElapsedTimer render_time_;
305#endif
306};
307
308} // namespace trace
309} // namespace views
310} // namespace pv
311
312#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP