PulseView  unreleased development snapshot
A Qt-based sigrok GUI
viewbase.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  * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef PULSEVIEW_PV_VIEWS_VIEWBASE_HPP
22 #define PULSEVIEW_PV_VIEWS_VIEWBASE_HPP
23 
24 #include <cstdint>
25 #include <memory>
26 #include <unordered_set>
27 #include <vector>
28 
29 #include <QMainWindow>
30 #include <QTimer>
31 #include <QWidget>
32 
33 #include <pv/data/signalbase.hpp>
34 #include <pv/util.hpp>
35 
36 #ifdef ENABLE_DECODE
37 #include <pv/data/decodesignal.hpp>
38 #endif
39 
40 using std::shared_ptr;
41 using std::vector;
42 
43 namespace pv {
44 
45 class Session;
46 
47 namespace view {
48 class DecodeTrace;
49 class Signal;
50 }
51 
52 namespace views {
53 
54 // When adding an entry here, don't forget to update ViewTypeNames as well
55 enum ViewType {
57 #ifdef ENABLE_DECODE
58  ViewTypeDecoderBinary,
59  ViewTypeTabularDecoder,
60 #endif
61  ViewTypeCount // Indicates how many view types there are, must always be last
62 };
63 
64 extern const char* ViewTypeNames[ViewTypeCount];
65 
66 class ViewBase : public QWidget
67 {
68  Q_OBJECT
69 
70 public:
71  static const int MaxViewAutoUpdateRate;
72 
73 public:
74  explicit ViewBase(Session &session, bool is_main_view = false, QMainWindow *parent = nullptr);
75 
76  virtual ViewType get_type() const = 0;
77  bool is_main_view() const;
78 
83  virtual void reset_view_state();
84 
85  Session& session();
86  const Session& session() const;
87 
91  vector< shared_ptr<data::SignalBase> > signalbases() const;
92 
93  virtual void clear_signalbases();
94  virtual void add_signalbase(const shared_ptr<data::SignalBase> signalbase);
95  virtual void remove_signalbase(const shared_ptr<data::SignalBase> signalbase);
96 
97 #ifdef ENABLE_DECODE
98  virtual void clear_decode_signals();
99  virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
100  virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
101 #endif
102 
103  virtual void save_settings(QSettings &settings) const;
104  virtual void restore_settings(QSettings &settings);
105 
106  virtual void focus_on_range(uint64_t start_sample, uint64_t end_sample);
107 
108 public Q_SLOTS:
109  virtual void trigger_event(int segment_id, util::Timestamp location);
110  virtual void signals_changed();
111  virtual void capture_state_updated(int state);
112  virtual void on_new_segment(int new_segment_id);
113  virtual void on_segment_completed(int new_segment_id);
114  virtual void perform_delayed_view_update();
115 
116 private Q_SLOTS:
117  void on_samples_added(uint64_t segment_id, uint64_t start_sample,
118  uint64_t end_sample);
119 
120  void on_data_updated();
121 
122 protected:
124 
125  const bool is_main_view_;
126 
128 
129  vector< shared_ptr<data::SignalBase> > signalbases_;
130 #ifdef ENABLE_DECODE
131  vector< shared_ptr<data::DecodeSignal> > decode_signals_;
132 #endif
133 
136 
138 };
139 
140 } // namespace views
141 } // namespace pv
142 
143 #endif // PULSEVIEW_PV_VIEWS_VIEWBASE_HPP
QTimer delayed_view_updater_
Definition: viewbase.hpp:137
const char * ViewTypeNames[ViewTypeCount]
Definition: viewbase.cpp:36
const bool is_main_view_
Definition: viewbase.hpp:125
Session & session_
Definition: viewbase.hpp:123
util::TimeUnit time_unit_
Definition: viewbase.hpp:127
uint32_t current_segment_
The ID of the currently displayed segment.
Definition: viewbase.hpp:135
vector< shared_ptr< data::SignalBase > > signalbases_
Definition: viewbase.hpp:129
TimeUnit
Definition: util.hpp:44
static const int MaxViewAutoUpdateRate
Definition: viewbase.hpp:71
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:67