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