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