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