File: viewbase.cpp

package info (click to toggle)
pulseview 0.4.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,092 kB
  • sloc: cpp: 25,958; xml: 215; java: 42; makefile: 2
file content (197 lines) | stat: -rw-r--r-- 4,574 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * This file is part of the PulseView project.
 *
 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifdef ENABLE_DECODE
#include <libsigrokdecode/libsigrokdecode.h>
#endif

#include <libsigrokcxx/libsigrokcxx.hpp>

#include "pv/session.hpp"
#include "pv/util.hpp"
#include "pv/data/segment.hpp"

using std::shared_ptr;

namespace pv {
namespace views {

const char* ViewTypeNames[ViewTypeCount] = {
	"Trace View",
#ifdef ENABLE_DECODE
	"Binary Decoder Output View"
#endif
};

const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz

ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) :
	// Note: Place defaults in ViewBase::reset_view_state(), not here
	QWidget(parent),
	session_(session),
	is_main_view_(is_main_view)
{
	(void)parent;

	connect(&session_, SIGNAL(signals_changed()),
		this, SLOT(signals_changed()));
	connect(&session_, SIGNAL(capture_state_changed(int)),
		this, SLOT(capture_state_updated(int)));
	connect(&session_, SIGNAL(new_segment(int)),
		this, SLOT(on_new_segment(int)));

	connect(&delayed_view_updater_, SIGNAL(timeout()),
		this, SLOT(perform_delayed_view_update()));
	delayed_view_updater_.setSingleShot(true);
	delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
}

bool ViewBase::is_main_view() const
{
	return is_main_view_;
}

void ViewBase::reset_view_state()
{
	current_segment_ = 0;
}

Session& ViewBase::session()
{
	return session_;
}

const Session& ViewBase::session() const
{
	return session_;
}

void ViewBase::clear_signals()
{
	clear_signalbases();
}

vector< shared_ptr<data::SignalBase> > ViewBase::signalbases() const
{
	return signalbases_;
}

void ViewBase::clear_signalbases()
{
	for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
		disconnect(signalbase.get(), SIGNAL(samples_cleared()),
			this, SLOT(on_data_updated()));
		disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
			this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
	}

	signalbases_.clear();
}

void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
{
	signalbases_.push_back(signalbase);

	connect(signalbase.get(), SIGNAL(samples_cleared()),
		this, SLOT(on_data_updated()));
	connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
		this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
}

#ifdef ENABLE_DECODE
void ViewBase::clear_decode_signals()
{
	decode_signals_.clear();
}

void ViewBase::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
{
	decode_signals_.push_back(signal);
}

void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
{
	decode_signals_.erase(std::remove_if(
		decode_signals_.begin(), decode_signals_.end(),
		[&](shared_ptr<data::DecodeSignal> s) { return s == signal; }),
		decode_signals_.end());
}
#endif

void ViewBase::save_settings(QSettings &settings) const
{
	(void)settings;
}

void ViewBase::restore_settings(QSettings &settings)
{
	(void)settings;
}

void ViewBase::trigger_event(int segment_id, util::Timestamp location)
{
	(void)segment_id;
	(void)location;
}

void ViewBase::signals_changed()
{
}

void ViewBase::on_new_segment(int new_segment_id)
{
	(void)new_segment_id;
}

void ViewBase::on_segment_completed(int new_segment_id)
{
	(void)new_segment_id;
}

void ViewBase::capture_state_updated(int state)
{
	(void)state;
}

void ViewBase::perform_delayed_view_update()
{
}

void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample,
	uint64_t end_sample)
{
	(void)start_sample;
	(void)end_sample;

	if (segment_id != current_segment_)
		return;

	if (!delayed_view_updater_.isActive())
		delayed_view_updater_.start();
}

void ViewBase::on_data_updated()
{
	if (!delayed_view_updater_.isActive())
		delayed_view_updater_.start();
}

}  // namespace views
} // namespace pv