2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
22 #include <libsigrokdecode/libsigrokdecode.h>
25 #include <libsigrokcxx/libsigrokcxx.hpp>
27 #include "pv/session.hpp"
28 #include "pv/util.hpp"
29 #include "pv/data/segment.hpp"
31 using std::shared_ptr;
36 const char* ViewTypeNames[ViewTypeCount] = {
39 "Binary Decoder Output View",
40 "Tabular Decoder Output View"
44 const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz
46 ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) :
47 // Note: Place defaults in ViewBase::reset_view_state(), not here
50 is_main_view_(is_main_view)
54 connect(&session_, SIGNAL(signals_changed()),
55 this, SLOT(signals_changed()));
56 connect(&session_, SIGNAL(capture_state_changed(int)),
57 this, SLOT(capture_state_updated(int)));
58 connect(&session_, SIGNAL(new_segment(int)),
59 this, SLOT(on_new_segment(int)));
61 connect(&delayed_view_updater_, SIGNAL(timeout()),
62 this, SLOT(perform_delayed_view_update()));
63 delayed_view_updater_.setSingleShot(true);
64 delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
67 bool ViewBase::is_main_view() const
72 void ViewBase::reset_view_state()
77 Session& ViewBase::session()
82 const Session& ViewBase::session() const
87 void ViewBase::clear_signals()
92 vector< shared_ptr<data::SignalBase> > ViewBase::signalbases() const
97 void ViewBase::clear_signalbases()
99 for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
100 disconnect(signalbase.get(), SIGNAL(samples_cleared()),
101 this, SLOT(on_data_updated()));
102 disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
103 this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
106 signalbases_.clear();
109 void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
111 signalbases_.push_back(signalbase);
113 connect(signalbase.get(), SIGNAL(samples_cleared()),
114 this, SLOT(on_data_updated()));
115 connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
116 this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
120 void ViewBase::clear_decode_signals()
122 decode_signals_.clear();
125 void ViewBase::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
127 decode_signals_.push_back(signal);
130 void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
132 decode_signals_.erase(std::remove_if(
133 decode_signals_.begin(), decode_signals_.end(),
134 [&](shared_ptr<data::DecodeSignal> s) { return s == signal; }),
135 decode_signals_.end());
139 void ViewBase::save_settings(QSettings &settings) const
144 void ViewBase::restore_settings(QSettings &settings)
149 void ViewBase::trigger_event(int segment_id, util::Timestamp location)
155 void ViewBase::signals_changed()
159 void ViewBase::on_new_segment(int new_segment_id)
161 (void)new_segment_id;
164 void ViewBase::on_segment_completed(int new_segment_id)
166 (void)new_segment_id;
169 void ViewBase::capture_state_updated(int state)
174 void ViewBase::perform_delayed_view_update()
178 void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample,
184 if (segment_id != current_segment_)
187 if (!delayed_view_updater_.isActive())
188 delayed_view_updater_.start();
191 void ViewBase::on_data_updated()
193 if (!delayed_view_updater_.isActive())
194 delayed_view_updater_.start();