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