]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/viewbase.cpp
QHexView: Fix saved ASCII output
[pulseview.git] / pv / views / viewbase.cpp
... / ...
CommitLineData
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#include "pv/data/segment.hpp"
30
31using std::shared_ptr;
32
33namespace pv {
34namespace views {
35
36const char* ViewTypeNames[ViewTypeCount] = {
37 "Trace View",
38#ifdef ENABLE_DECODE
39 "Decoder Output View"
40#endif
41};
42
43const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz
44
45ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) :
46 // Note: Place defaults in ViewBase::reset_view_state(), not here
47 QWidget(parent),
48 session_(session),
49 is_main_view_(is_main_view)
50{
51 (void)parent;
52
53 connect(&session_, SIGNAL(signals_changed()),
54 this, SLOT(signals_changed()));
55 connect(&session_, SIGNAL(capture_state_changed(int)),
56 this, SLOT(capture_state_updated(int)));
57 connect(&session_, SIGNAL(new_segment(int)),
58 this, SLOT(on_new_segment(int)));
59
60 connect(&delayed_view_updater_, SIGNAL(timeout()),
61 this, SLOT(perform_delayed_view_update()));
62 delayed_view_updater_.setSingleShot(true);
63 delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
64}
65
66void ViewBase::reset_view_state()
67{
68 current_segment_ = 0;
69}
70
71Session& ViewBase::session()
72{
73 return session_;
74}
75
76const Session& ViewBase::session() const
77{
78 return session_;
79}
80
81void ViewBase::clear_signals()
82{
83 clear_signalbases();
84}
85
86unordered_set< shared_ptr<data::SignalBase> > ViewBase::signalbases() const
87{
88 return signalbases_;
89}
90
91void ViewBase::clear_signalbases()
92{
93 for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
94 disconnect(signalbase.get(), SIGNAL(samples_cleared()),
95 this, SLOT(on_data_updated()));
96 disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
97 this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
98 }
99
100 signalbases_.clear();
101}
102
103void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
104{
105 signalbases_.insert(signalbase);
106
107 connect(signalbase.get(), SIGNAL(samples_cleared()),
108 this, SLOT(on_data_updated()));
109 connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
110 this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
111}
112
113#ifdef ENABLE_DECODE
114void ViewBase::clear_decode_signals()
115{
116 decode_signals_.clear();
117}
118
119void ViewBase::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
120{
121 decode_signals_.insert(signal);
122}
123
124void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
125{
126 decode_signals_.erase(signal);
127}
128#endif
129
130void ViewBase::save_settings(QSettings &settings) const
131{
132 (void)settings;
133}
134
135void ViewBase::restore_settings(QSettings &settings)
136{
137 (void)settings;
138}
139
140void ViewBase::trigger_event(int segment_id, util::Timestamp location)
141{
142 (void)segment_id;
143 (void)location;
144}
145
146void ViewBase::signals_changed()
147{
148}
149
150void ViewBase::on_new_segment(int new_segment_id)
151{
152 (void)new_segment_id;
153}
154
155void ViewBase::on_segment_completed(int new_segment_id)
156{
157 (void)new_segment_id;
158}
159
160void ViewBase::capture_state_updated(int state)
161{
162 (void)state;
163}
164
165void ViewBase::perform_delayed_view_update()
166{
167}
168
169void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample,
170 uint64_t end_sample)
171{
172 (void)start_sample;
173 (void)end_sample;
174
175 if (segment_id != current_segment_)
176 return;
177
178 if (!delayed_view_updater_.isActive())
179 delayed_view_updater_.start();
180}
181
182void ViewBase::on_data_updated()
183{
184 if (!delayed_view_updater_.isActive())
185 delayed_view_updater_.start();
186}
187
188} // namespace views
189} // namespace pv