PulseView  unreleased development snapshot
A Qt-based sigrok GUI
view.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the PulseView project.
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, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PULSEVIEW_PV_VIEWS_TRACE_VIEW_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACE_VIEW_HPP
22 
23 #include <cstdint>
24 #include <list>
25 #include <memory>
26 #include <mutex>
27 #include <set>
28 #include <vector>
29 
30 #include <QAbstractScrollArea>
31 #include <QShortcut>
32 #include <QSizeF>
33 #include <QSplitter>
34 
35 #include <pv/globalsettings.hpp>
36 #include <pv/util.hpp>
37 #include <pv/data/signaldata.hpp>
38 #include <pv/views/viewbase.hpp>
39 
40 #include "cursorpair.hpp"
41 #include "flag.hpp"
42 #include "trace.hpp"
43 #include "tracetreeitemowner.hpp"
44 
45 using std::list;
46 using std::map;
47 using std::set;
48 using std::shared_ptr;
49 using std::vector;
50 
51 namespace sigrok {
52 class ChannelGroup;
53 }
54 
55 namespace pv {
56 
57 class Session;
58 
59 namespace data {
60 class Logic;
61 }
62 
63 namespace views {
64 
65 namespace trace {
66 
67 class DecodeTrace;
68 class Header;
69 class Ruler;
70 class Signal;
71 class Viewport;
72 class TriggerMarker;
73 
75 {
76  Q_OBJECT
77 
78 public:
79  CustomScrollArea(QWidget *parent = nullptr);
80  bool viewportEvent(QEvent *event);
81 };
82 
84 {
85  Q_OBJECT
86 
87 private:
88  enum StickyEvents {
89  TraceTreeItemHExtentsChanged = 1,
90  TraceTreeItemVExtentsChanged = 2
91  };
92 
93 private:
96 
97  static const int MaxScrollValue;
98  static const int ViewScrollMargin;
99 
100  static const int ScaleUnits[3];
101 
102 public:
103  explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
104 
105  ~View();
106 
107  virtual ViewType get_type() const;
108 
113  virtual void reset_view_state();
114 
115  Session& session(); // This method is needed for TraceTreeItemOwner, not ViewBase
116  const Session& session() const; // This method is needed for TraceTreeItemOwner, not ViewBase
117 
121  vector< shared_ptr<Signal> > signals() const;
122 
123  shared_ptr<Signal> get_signal_by_signalbase(shared_ptr<data::SignalBase> base) const;
124 
125  virtual void clear_signalbases();
126  virtual void add_signalbase(const shared_ptr<data::SignalBase> signalbase);
127  virtual void remove_signalbase(const shared_ptr<data::SignalBase> signalbase);
128 
129 #ifdef ENABLE_DECODE
130  virtual void clear_decode_signals();
131 
132  virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
133 
134  virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
135 #endif
136 
137  void remove_trace(shared_ptr<Trace> trace);
138 
139  shared_ptr<Signal> get_signal_under_mouse_cursor() const;
140 
144  virtual View* view();
145 
149  virtual const View* view() const;
150 
151  Viewport* viewport();
152  const Viewport* viewport() const;
153 
154  QAbstractScrollArea* scrollarea() const;
155 
156  const Ruler* ruler() const;
157 
158  virtual void save_settings(QSettings &settings) const;
159  virtual void restore_settings(QSettings &settings);
160 
164  vector< shared_ptr<TimeItem> > time_items() const;
165 
169  double scale() const;
170 
175  const pv::util::Timestamp& offset() const;
176 
181  const pv::util::Timestamp& ruler_offset() const;
182 
183  void set_zero_position(const pv::util::Timestamp& position);
184 
185  void reset_zero_position();
186 
187  pv::util::Timestamp zero_offset() const;
188 
192  int owner_visual_v_offset() const;
193 
197  void set_v_offset(int offset);
198 
202  void set_h_offset(int offset);
203 
207  int get_h_scrollbar_maximum() const;
208 
212  pv::util::SIPrefix tick_prefix() const;
213 
217  unsigned int tick_precision() const;
218 
222  const pv::util::Timestamp& tick_period() const;
223 
227  unsigned int minor_tick_count() const;
228 
232  util::TimeUnit time_unit() const;
233 
237  unsigned int depth() const;
238 
242  uint32_t current_segment() const;
243 
248  bool segment_is_selectable() const;
249 
250  Trace::SegmentDisplayMode segment_display_mode() const;
251  void set_segment_display_mode(Trace::SegmentDisplayMode mode);
252 
253  void zoom(double steps);
254  void zoom(double steps, int offset);
255 
256  void zoom_fit(bool gui_state);
257 
258  virtual void focus_on_range(uint64_t start_sample, uint64_t end_sample);
259 
265  void set_scale_offset(double scale, const pv::util::Timestamp& offset);
266 
267  vector< shared_ptr<pv::data::SignalData> > get_visible_data() const;
268 
269  pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
270 
274  bool colored_bg() const;
275 
279  bool cursors_shown() const;
280 
284  void show_cursors(bool show = true);
285 
290  void set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second);
291 
296  void center_cursors();
297 
301  shared_ptr<CursorPair> cursors() const;
302 
306  shared_ptr<Flag> add_flag(const pv::util::Timestamp& time);
307 
311  void remove_flag(shared_ptr<Flag> flag);
312 
316  vector< shared_ptr<Flag> > flags() const;
317 
318  const QPoint& hover_point() const;
319  const QWidget* hover_widget() const;
320 
328  int64_t get_nearest_level_change(const QPoint &p);
329 
330  void restack_all_trace_tree_items();
331 
332  int header_width() const;
333 
334  void on_setting_changed(const QString &key, const QVariant &value);
335 
336 Q_SIGNALS:
337  void hover_point_changed(const QWidget* widget, const QPoint &hp);
338 
339  void selection_changed();
340 
342  void offset_changed();
343 
345  void scale_changed();
346 
347  void sticky_scrolling_changed(bool state);
348 
349  void always_zoom_to_fit_changed(bool state);
350 
352  void tick_prefix_changed();
353 
355  void tick_precision_changed();
356 
358  void tick_period_changed();
359 
361  void time_unit_changed();
362 
364  void segment_changed(int segment_id);
365 
368  void segment_display_mode_changed(int mode, bool segment_selectable);
369 
371  void cursor_state_changed(bool show);
372 
373 public Q_SLOTS:
374  void trigger_event(int segment_id, util::Timestamp location);
375 
376 private:
377  void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
378 
385  void set_zoom(double scale, int offset);
386 
391  void calculate_tick_spacing();
392 
393  void adjust_top_margin();
394 
395  void update_scroll();
396  void reset_scroll();
397  void set_scroll_default();
398 
399  void determine_if_header_was_shrunk();
400 
401  void resize_header_to_fit();
402 
403  void update_layout();
404 
405  TraceTreeItemOwner* find_prevalent_trace_group(
406  const shared_ptr<sigrok::ChannelGroup> &group,
407  const map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > &signal_map);
408 
409  static vector< shared_ptr<Trace> >
410  extract_new_traces_for_channels(
411  const vector< shared_ptr<sigrok::Channel> > &channels,
412  const map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > &signal_map,
413  set< shared_ptr<Trace> > &add_list);
414 
415  void determine_time_unit();
416 
417  bool eventFilter(QObject *object, QEvent *event);
418 
419  virtual void contextMenuEvent(QContextMenuEvent *event);
420 
421  void resizeEvent(QResizeEvent *event);
422 
423  void update_view_range_metaobject() const;
424  void update_hover_point();
425 
426 public:
427  void row_item_appearance_changed(bool label, bool content);
428  void time_item_appearance_changed(bool label, bool content);
429 
430  void extents_changed(bool horz, bool vert);
431 
432 private Q_SLOTS:
433  void on_signal_name_changed();
434  void on_splitter_moved();
435 
436  void on_zoom_in_shortcut_triggered();
437  void on_zoom_out_shortcut_triggered();
438  void on_scroll_to_start_shortcut_triggered();
439  void on_scroll_to_end_shortcut_triggered();
440 
441  void h_scroll_value_changed(int value);
442  void v_scroll_value_changed();
443 
444  void on_grab_ruler(int ruler_id);
445 
446  void signals_changed();
447  void capture_state_updated(int state);
448 
449  void on_new_segment(int new_segment_id);
450  void on_segment_completed(int new_segment_id);
451  void on_segment_changed(int segment);
452 
453  void on_settingViewTriggerIsZeroTime_changed(const QVariant new_value);
454 
455  void on_create_marker_here();
456 
457  virtual void perform_delayed_view_update();
458 
459  void process_sticky_events();
460 
465  void set_offset(const pv::util::Timestamp& offset, bool force_update = false);
466 
471  void set_scale(double scale);
472 
477  void set_tick_prefix(pv::util::SIPrefix tick_prefix);
478 
483  void set_tick_precision(unsigned tick_precision);
484 
489  void set_tick_period(const pv::util::Timestamp& tick_period);
490 
495  void set_time_unit(pv::util::TimeUnit time_unit);
496 
500  void set_current_segment(uint32_t segment_id);
501 
502 private:
507  QSplitter *splitter_;
508 
509  QShortcut *zoom_in_shortcut_, *zoom_in_shortcut_2_;
510  QShortcut *zoom_out_shortcut_, *zoom_out_shortcut_2_;
511  QShortcut *home_shortcut_, *end_shortcut_;
512  QShortcut *grab_ruler_left_shortcut_, *grab_ruler_right_shortcut_;
514 
515  mutable mutex signal_mutex_;
516  vector< shared_ptr<Signal> > signals_;
517 
518 #ifdef ENABLE_DECODE
519  vector< shared_ptr<DecodeTrace> > decode_traces_;
520 #endif
521 
523 
526 
528  double scale_;
529 
538 
542 
546 
549  unsigned int minor_tick_count_;
550  unsigned int tick_precision_;
552 
554  shared_ptr<CursorPair> cursors_;
555 
556  list< shared_ptr<Flag> > flags_;
558 
559  vector< shared_ptr<TriggerMarker> > trigger_markers_;
560 
561  QWidget* hover_widget_;
563  QPoint hover_point_;
564  shared_ptr<Signal> signal_under_mouse_cursor_;
565  uint16_t snap_distance_;
566 
567  unsigned int sticky_events_;
569 
570  // This is true when the defaults couldn't be set due to insufficient info
572 
573  // The v offset to restore. See View::eventFilter()
575 
576  // These are used to determine whether the view was altered after acq started
579 
580  // X coordinate of mouse cursor where the user clicked to open a context menu
582 };
583 
584 } // namespace trace
585 } // namespace views
586 } // namespace pv
587 
588 #endif // PULSEVIEW_PV_VIEWS_TRACE_VIEW_HPP
pv::util::Timestamp tick_period_
Definition: view.hpp:547
vector< shared_ptr< Signal > > signals_
Definition: view.hpp:516
vector< shared_ptr< TriggerMarker > > trigger_markers_
Definition: view.hpp:559
shared_ptr< Signal > signal_under_mouse_cursor_
Definition: view.hpp:564
SIPrefix
Definition: util.hpp:50
double scale_
The view time scale in seconds per pixel.
Definition: view.hpp:528
bool segment_selectable_
Signals whether the user can change the currently shown segment.
Definition: view.hpp:525
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12358
QShortcut * home_shortcut_
Definition: view.hpp:511
QShortcut * zoom_in_shortcut_2_
Definition: view.hpp:509
QShortcut * grab_ruler_right_shortcut_
Definition: view.hpp:512
bool custom_zero_offset_set_
Shows whether the user set a custom zero offset that we should keep.
Definition: view.hpp:537
QTimer lazy_event_handler_
Definition: view.hpp:568
unsigned int sticky_events_
Definition: view.hpp:567
TimeMarker * grabbed_widget_
Definition: view.hpp:562
pv::util::Timestamp zero_offset_
The offset of the zero point in seconds.
Definition: view.hpp:535
static std::string data()
Definition: exprtk.hpp:39024
list< shared_ptr< Flag > > flags_
Definition: view.hpp:556
static const int MaxScrollValue
Definition: view.hpp:97
QShortcut * zoom_out_shortcut_2_
Definition: view.hpp:510
CustomScrollArea * scrollarea_
Definition: view.hpp:503
static const int ViewScrollMargin
Definition: view.hpp:98
Trace::SegmentDisplayMode segment_display_mode_
Definition: view.hpp:522
pv::util::SIPrefix tick_prefix_
Definition: view.hpp:548
uint32_t context_menu_x_pos_
Definition: view.hpp:581
unsigned int minor_tick_count_
Definition: view.hpp:549
pv::util::Timestamp ruler_offset_
The ruler version of the time offset in seconds.
Definition: view.hpp:533
unsigned int tick_precision_
Definition: view.hpp:550
QShortcut * cancel_grab_shortcut_
Definition: view.hpp:513
manual txt set(MANUAL_OUT_HTML"${CMAKE_CURRENT_BINARY_DIR}/manual.html") set(MANUAL_OUT_PDF"$
Definition: CMakeLists.txt:36
pv::util::Timestamp offset_at_acq_start_
Definition: view.hpp:578
bool scroll_needs_defaults_
Definition: view.hpp:571
TimeUnit
Definition: util.hpp:44
QWidget * hover_widget_
Definition: view.hpp:561
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:67
static const pv::util::Timestamp MaxScale
Definition: view.hpp:94
pv::util::Timestamp offset_
The internal view version of the time offset in seconds.
Definition: view.hpp:531
util::TimeUnit time_unit_
Definition: view.hpp:551
shared_ptr< CursorPair > cursors_
Definition: view.hpp:554
QSplitter * splitter_
Definition: view.hpp:507
Viewport * viewport_
Definition: view.hpp:504
uint16_t snap_distance_
Definition: view.hpp:565
double scale_at_acq_start_
Definition: view.hpp:577
static const pv::util::Timestamp MinScale
Definition: view.hpp:95