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