Rework signaling mechanism for trace repainting
[pulseview.git] / pv / views / viewbase.cpp
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 #ifdef ENABLE_DECODE
22 #include <libsigrokdecode/libsigrokdecode.h>
23 #endif
24
25 #include <libsigrokcxx/libsigrokcxx.hpp>
26
27 #include "pv/session.hpp"
28 #include "pv/util.hpp"
29
30 using std::shared_ptr;
31
32 namespace pv {
33 namespace views {
34
35 const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz
36
37 ViewBase::ViewBase(Session &session, bool is_main_view, QWidget *parent) :
38         session_(session),
39         is_main_view_(is_main_view)
40 {
41         (void)parent;
42
43         connect(&session_, SIGNAL(signals_changed()),
44                 this, SLOT(signals_changed()));
45         connect(&session_, SIGNAL(capture_state_changed(int)),
46                 this, SLOT(capture_state_updated(int)));
47
48         connect(&delayed_view_updater_, SIGNAL(timeout()),
49                 this, SLOT(perform_delayed_view_update()));
50         delayed_view_updater_.setSingleShot(true);
51         delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
52 }
53
54 Session& ViewBase::session()
55 {
56         return session_;
57 }
58
59 const Session& ViewBase::session() const
60 {
61         return session_;
62 }
63
64 void ViewBase::clear_signals()
65 {
66 }
67
68 unordered_set< shared_ptr<data::SignalBase> > ViewBase::signalbases() const
69 {
70         return signalbases_;
71 }
72
73 void ViewBase::clear_signalbases()
74 {
75         for (shared_ptr<data::SignalBase> signalbase : signalbases_) {
76                 disconnect(signalbase.get(), SIGNAL(samples_cleared()),
77                         this, SLOT(on_data_updated()));
78                 disconnect(signalbase.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
79                         this, SLOT(on_data_updated()));
80         }
81
82         signalbases_.clear();
83 }
84
85 void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
86 {
87         signalbases_.insert(signalbase);
88
89         connect(signalbase.get(), SIGNAL(samples_cleared()),
90                 this, SLOT(on_data_updated()));
91         connect(signalbase.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
92                 this, SLOT(on_data_updated()));
93 }
94
95 #ifdef ENABLE_DECODE
96 void ViewBase::clear_decode_signals()
97 {
98 }
99
100 void ViewBase::add_decode_signal(shared_ptr<data::SignalBase> signalbase)
101 {
102         (void)signalbase;
103 }
104
105 void ViewBase::remove_decode_signal(shared_ptr<data::SignalBase> signalbase)
106 {
107         (void)signalbase;
108 }
109 #endif
110
111 void ViewBase::save_settings(QSettings &settings) const
112 {
113         (void)settings;
114 }
115
116 void ViewBase::restore_settings(QSettings &settings)
117 {
118         (void)settings;
119 }
120
121 void ViewBase::trigger_event(util::Timestamp location)
122 {
123         (void)location;
124 }
125
126 void ViewBase::signals_changed()
127 {
128 }
129
130 void ViewBase::capture_state_updated(int state)
131 {
132         (void)state;
133 }
134
135 void ViewBase::perform_delayed_view_update()
136 {
137 }
138
139 void ViewBase::on_data_updated()
140 {
141         if (!delayed_view_updater_.isActive())
142                 delayed_view_updater_.start();
143 }
144
145 }  // namespace views
146 } // namespace pv