]> sigrok.org Git - pulseview.git/blame - pv/view/view.hpp
Fix a build issue with std::roundf() on Android.
[pulseview.git] / pv / view / view.hpp
CommitLineData
adb4b10c 1/*
b3f22de0 2 * This file is part of the PulseView project.
adb4b10c
JH
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/>.
adb4b10c
JH
18 */
19
f4e57597
SA
20#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP
21#define PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP
adb4b10c 22
cafe470e 23#include <cstdint>
8914fe79 24#include <list>
f9abf97e 25#include <memory>
1bc6525b 26#include <set>
448a72cf 27#include <unordered_map>
38eeddea
JH
28#include <vector>
29
adb4b10c 30#include <QAbstractScrollArea>
2e04f9bd 31#include <QSizeF>
32218d3e 32#include <QTimer>
adb4b10c 33
2acdb232 34#include <pv/data/signaldata.hpp>
ef454ad5 35#include <pv/util.hpp>
aca9aa83 36#include <pv/views/viewbase.hpp>
1bc6525b 37
2acdb232 38#include "cursorpair.hpp"
8914fe79 39#include "flag.hpp"
af503b10 40#include "tracetreeitemowner.hpp"
f76af637 41
6f925ba9
UH
42using std::list;
43using std::unordered_map;
44using std::unordered_set;
45using std::set;
46using std::shared_ptr;
47using std::vector;
48
cf124e47
JH
49namespace sigrok {
50class ChannelGroup;
51}
52
51e77110
JH
53namespace pv {
54
2b81ae46 55class Session;
adb4b10c 56
f4e57597
SA
57namespace views {
58
59namespace TraceView {
cdf7bea7 60
84a0d458 61class CursorHeader;
bb7dd726 62class DecodeTrace;
1d8dca91 63class Header;
ccdd3ef5 64class Ruler;
47e9e7bb 65class Signal;
cf124e47 66class Trace;
cdf7bea7 67class Viewport;
1a2288a1 68class TriggerMarker;
cdf7bea7 69
c063290a
UH
70class CustomAbstractScrollArea : public QAbstractScrollArea
71{
f4e57597
SA
72 Q_OBJECT
73
74public:
f54fc97e 75 CustomAbstractScrollArea(QWidget *parent = nullptr);
f4e57597
SA
76 void setViewportMargins(int left, int top, int right, int bottom);
77 bool viewportEvent(QEvent *event);
78};
79
c063290a
UH
80class View : public ViewBase, public TraceTreeItemOwner
81{
adb4b10c
JH
82 Q_OBJECT
83
32218d3e
JH
84private:
85 enum StickyEvents {
af503b10
JH
86 TraceTreeItemHExtentsChanged = 1,
87 TraceTreeItemVExtentsChanged = 2
32218d3e
JH
88 };
89
adb4b10c 90private:
60d9b99a
JS
91 static const pv::util::Timestamp MaxScale;
92 static const pv::util::Timestamp MinScale;
adb4b10c 93
f25770e2 94 static const int MaxScrollValue;
c7b03d9d 95 static const int MaxViewAutoUpdateRate;
f25770e2 96
361c560e
JH
97 static const int ScaleUnits[3];
98
adb4b10c 99public:
f54fc97e 100 explicit View(Session &session, bool is_main_view=false, QWidget *parent = nullptr);
adb4b10c 101
2b81ae46
JH
102 Session& session();
103 const Session& session() const;
1d19ef83 104
47e9e7bb
SA
105 /**
106 * Returns the signals contained in this view.
107 */
6f925ba9 108 unordered_set< shared_ptr<Signal> > signals() const;
47e9e7bb 109
f4e57597 110 virtual void clear_signals();
47e9e7bb 111
6f925ba9 112 virtual void add_signal(const shared_ptr<Signal> signal);
47e9e7bb 113
bb7dd726 114#ifdef ENABLE_DECODE
f4e57597 115 virtual void clear_decode_signals();
bb7dd726 116
6f925ba9 117 virtual void add_decode_signal(shared_ptr<data::SignalBase> signalbase);
bb7dd726 118
6f925ba9 119 virtual void remove_decode_signal(shared_ptr<data::SignalBase> signalbase);
bb7dd726
SA
120#endif
121
eae6e30a
JH
122 /**
123 * Returns the view of the owner.
124 */
f4e57597 125 virtual View* view();
eae6e30a
JH
126
127 /**
128 * Returns the view of the owner.
129 */
f4e57597 130 virtual const View* view() const;
eae6e30a 131
2ae445ba
SA
132 Viewport* viewport();
133
134 const Viewport* viewport() const;
135
f4e57597 136 virtual void save_settings(QSettings &settings) const;
3a21afa6 137
f4e57597 138 virtual void restore_settings(QSettings &settings);
3a21afa6 139
2496bf45
JH
140 /**
141 * Gets a list of time markers.
142 */
6f925ba9 143 vector< shared_ptr<TimeItem> > time_items() const;
2496bf45 144
e2f5223b
JH
145 /**
146 * Returns the view time scale in seconds per pixel.
147 */
adb4b10c 148 double scale() const;
e2f5223b
JH
149
150 /**
151 * Returns the time offset of the left edge of the view in
152 * seconds.
153 */
60d9b99a 154 const pv::util::Timestamp& offset() const;
f8400017
JH
155
156 /**
157 * Returns the vertical scroll offset.
158 */
7ff0145f 159 int owner_visual_v_offset() const;
adb4b10c 160
4d476647
JH
161 /**
162 * Sets the visual v-offset.
163 */
164 void set_v_offset(int offset);
165
361c560e
JH
166 /**
167 * Returns the SI prefix to apply to the graticule time markings.
168 */
d001f416 169 pv::util::SIPrefix tick_prefix() const;
361c560e 170
d40f4db7
SA
171 /**
172 * Returns the number of fractional digits shown for the time markings.
173 */
174 unsigned int tick_precision() const;
175
361c560e
JH
176 /**
177 * Returns period of the graticule time markings.
178 */
c677193d 179 const pv::util::Timestamp& tick_period() const;
361c560e 180
ef454ad5
SA
181 /**
182 * Returns the unit of time currently used.
183 */
184 util::TimeUnit time_unit() const;
185
3e769a37
JH
186 /**
187 * Returns the number of nested parents that this row item owner has.
188 */
189 unsigned int depth() const;
190
adb4b10c 191 void zoom(double steps);
17c0f398 192 void zoom(double steps, int offset);
adb4b10c 193
ce11b2ea 194 void zoom_fit(bool gui_state);
ca46b534 195
d1e7d82c
JH
196 void zoom_one_to_one();
197
e2f5223b
JH
198 /**
199 * Sets the scale and offset.
200 * @param scale The new view scale in seconds per pixel.
201 * @param offset The view time offset in seconds.
202 */
60d9b99a 203 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
adb4b10c 204
6f925ba9 205 set< shared_ptr<pv::data::SignalData> > get_visible_data() const;
1bc6525b 206
6f925ba9 207 pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
1bc6525b 208
574c568d
SA
209 /**
210 * Enables or disables coloured trace backgrounds. If they're not
211 * coloured then they will use alternating colors.
212 */
213 void enable_coloured_bg(bool state);
214
48995388
JH
215 /**
216 * Returns true if the trace background should be drawn with a coloured background.
217 */
218 bool coloured_bg() const;
219
051ba3b3
UH
220 /**
221 * Enable or disable showing sampling points.
222 */
223 void enable_show_sampling_points(bool state);
224
8ad61f40
UH
225 /**
226 * Enable or disable showing the analog minor grid.
227 */
228 void enable_show_analog_minor_grid(bool state);
229
f76af637
JH
230 /**
231 * Returns true if cursors are displayed. false otherwise.
232 */
233 bool cursors_shown() const;
234
235 /**
236 * Shows or hides the cursors.
237 */
238 void show_cursors(bool show = true);
239
b4d91e56
JH
240 /**
241 * Moves the cursors to a convenient position in the view.
242 */
243 void centre_cursors();
244
f76af637
JH
245 /**
246 * Returns a reference to the pair of cursors.
247 */
6f925ba9 248 shared_ptr<CursorPair> cursors() const;
58864c5c 249
8914fe79
JH
250 /**
251 * Adds a new flag at a specified time.
252 */
60d9b99a 253 void add_flag(const pv::util::Timestamp& time);
8914fe79
JH
254
255 /**
256 * Removes a flag from the list.
257 */
6f925ba9 258 void remove_flag(shared_ptr<Flag> flag);
8914fe79
JH
259
260 /**
261 * Gets the list of flags.
262 */
6f925ba9 263 vector< shared_ptr<Flag> > flags() const;
8914fe79 264
cbd80f64
JH
265 const QPoint& hover_point() const;
266
af503b10 267 void restack_all_trace_tree_items();
9cef9567 268
e9213170 269Q_SIGNALS:
cbd80f64
JH
270 void hover_point_changed();
271
8b454527
JH
272 void selection_changed();
273
4b0af0b6
JS
274 /// Emitted when the offset changed.
275 void offset_changed();
276
277 /// Emitted when the scale changed.
278 void scale_changed();
e0fc5810 279
c7b03d9d
SA
280 void sticky_scrolling_changed(bool state);
281
ce11b2ea
SA
282 void always_zoom_to_fit_changed(bool state);
283
4b0af0b6
JS
284 /// Emitted when the tick_prefix changed.
285 void tick_prefix_changed();
286
287 /// Emitted when the tick_precision changed.
288 void tick_precision_changed();
289
290 /// Emitted when the tick_period changed.
291 void tick_period_changed();
292
293 /// Emitted when the time_unit changed.
294 void time_unit_changed();
295
48257a69
SA
296public Q_SLOTS:
297 void trigger_event(util::Timestamp location);
298
adb4b10c 299private:
60d9b99a 300 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
3925091a
JH
301
302 /**
303 * Simultaneously sets the zoom and offset.
304 * @param scale The scale to set the view to in seconds per pixel. This
305 * value is clamped between MinScale and MaxScale.
306 * @param offset The offset of the left edge of the view in seconds.
307 */
d1e7d82c
JH
308 void set_zoom(double scale, int offset);
309
361c560e
JH
310 /**
311 * Find a tick spacing and number formatting that does not cause
312 * the values to collide.
313 */
314 void calculate_tick_spacing();
315
adb4b10c
JH
316 void update_scroll();
317
925763b0
SA
318 void reset_scroll();
319
320 void set_scroll_default();
321
d7c0ca4a
JH
322 void update_layout();
323
af503b10 324 TraceTreeItemOwner* find_prevalent_trace_group(
6f925ba9
UH
325 const shared_ptr<sigrok::ChannelGroup> &group,
326 const unordered_map<shared_ptr<data::SignalBase>,
327 shared_ptr<Signal> > &signal_map);
cf124e47 328
6f925ba9 329 static vector< shared_ptr<Trace> >
cf124e47 330 extract_new_traces_for_channels(
6f925ba9
UH
331 const vector< shared_ptr<sigrok::Channel> > &channels,
332 const unordered_map<shared_ptr<data::SignalBase>,
333 shared_ptr<Signal> > &signal_map,
334 set< shared_ptr<Trace> > &add_list);
448a72cf 335
ef454ad5
SA
336 void determine_time_unit();
337
cbd80f64
JH
338 bool eventFilter(QObject *object, QEvent *event);
339
d9ea9628 340 void resizeEvent(QResizeEvent *event);
adb4b10c 341
32218d3e 342public:
6e2c3c85 343 void row_item_appearance_changed(bool label, bool content);
98cfe4e8 344 void time_item_appearance_changed(bool label, bool content);
32218d3e
JH
345
346 void extents_changed(bool horz, bool vert);
347
e9213170 348private Q_SLOTS:
cbd80f64 349
b16907d3 350 void h_scroll_value_changed(int value);
f8400017 351 void v_scroll_value_changed();
adb4b10c 352
69dd2b03 353 void signals_changed();
7ee199a7 354 void capture_state_updated(int state);
adb4b10c
JH
355 void data_updated();
356
c7b03d9d
SA
357 void perform_delayed_view_update();
358
32218d3e 359 void process_sticky_events();
d7c0ca4a 360
33c62f44
JH
361 void on_hover_point_changed();
362
4b0af0b6
JS
363 /**
364 * Sets the 'offset_' member and emits the 'offset_changed'
365 * signal if needed.
366 */
367 void set_offset(const pv::util::Timestamp& offset);
368
369 /**
370 * Sets the 'scale_' member and emits the 'scale_changed'
371 * signal if needed.
372 */
373 void set_scale(double scale);
374
375 /**
376 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
377 * signal if needed.
378 */
379 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
380
381 /**
382 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
383 * signal if needed.
384 */
385 void set_tick_precision(unsigned tick_precision);
386
387 /**
388 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
389 * signal if needed.
390 */
c677193d 391 void set_tick_period(const pv::util::Timestamp& tick_period);
4b0af0b6
JS
392
393 /**
394 * Sets the 'time_unit' member and emits the 'time_unit_changed'
395 * signal if needed.
396 */
397 void set_time_unit(pv::util::TimeUnit time_unit);
398
adb4b10c 399private:
8dbbc7f0
JH
400 Viewport *viewport_;
401 Ruler *ruler_;
8dbbc7f0 402 Header *header_;
adb4b10c 403
6f925ba9 404 unordered_set< shared_ptr<Signal> > signals_;
47e9e7bb 405
bb7dd726 406#ifdef ENABLE_DECODE
6f925ba9 407 vector< shared_ptr<DecodeTrace> > decode_traces_;
bb7dd726
SA
408#endif
409
f4e57597
SA
410 CustomAbstractScrollArea scrollarea_;
411
e2f5223b 412 /// The view time scale in seconds per pixel.
8dbbc7f0 413 double scale_;
e2f5223b
JH
414
415 /// The view time offset in seconds.
60d9b99a 416 pv::util::Timestamp offset_;
adb4b10c 417
8dbbc7f0 418 bool updating_scroll_;
c7b03d9d 419 bool sticky_scrolling_;
9eae6de4 420 bool coloured_bg_;
ce11b2ea 421 bool always_zoom_to_fit_;
c7b03d9d 422 QTimer delayed_view_updater_;
cbd80f64 423
c677193d 424 pv::util::Timestamp tick_period_;
d001f416 425 pv::util::SIPrefix tick_prefix_;
d40f4db7 426 unsigned int tick_precision_;
ef454ad5 427 util::TimeUnit time_unit_;
361c560e 428
8dbbc7f0 429 bool show_cursors_;
6f925ba9 430 shared_ptr<CursorPair> cursors_;
f76af637 431
6f925ba9 432 list< shared_ptr<Flag> > flags_;
8914fe79
JH
433 char next_flag_text_;
434
6f925ba9 435 vector< shared_ptr<TriggerMarker> > trigger_markers_;
1a2288a1 436
8dbbc7f0 437 QPoint hover_point_;
32218d3e 438
8dbbc7f0
JH
439 unsigned int sticky_events_;
440 QTimer lazy_event_handler_;
925763b0
SA
441
442 // This is true when the defaults couldn't be set due to insufficient info
e62bee73 443 bool scroll_needs_defaults_;
39ab01e7
SA
444
445 // A nonzero value indicates the v offset to restore. See View::resizeEvent()
446 int saved_v_offset_;
ae5f6628
SA
447
448 bool size_finalized_;
adb4b10c
JH
449};
450
f4e57597
SA
451} // namespace TraceView
452} // namespace views
cdf7bea7
JH
453} // namespace pv
454
f4e57597 455#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP