File: viewbase.hpp

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 (145 lines) | stat: -rw-r--r-- 3,609 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
/*
 * 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/>.
 */

#ifndef PULSEVIEW_PV_VIEWS_VIEWBASE_HPP
#define PULSEVIEW_PV_VIEWS_VIEWBASE_HPP

#include <cstdint>
#include <memory>
#include <unordered_set>
#include <vector>

#include <QMainWindow>
#include <QTimer>
#include <QWidget>

#include <pv/data/signalbase.hpp>
#include <pv/util.hpp>

#ifdef ENABLE_DECODE
#include <pv/data/decodesignal.hpp>
#endif

using std::shared_ptr;
using std::vector;

namespace pv {

class Session;

namespace view {
class DecodeTrace;
class Signal;
}

namespace views {

// When adding an entry here, don't forget to update ViewTypeNames as well
enum ViewType {
	ViewTypeTrace,
#ifdef ENABLE_DECODE
	ViewTypeDecoderBinary,
#endif
	ViewTypeCount  // Indicates how many view types there are, must always be last
};

extern const char* ViewTypeNames[ViewTypeCount];

class ViewBase : public QWidget
{
	Q_OBJECT

public:
	static const int MaxViewAutoUpdateRate;

public:
	explicit ViewBase(Session &session, bool is_main_view = false, QMainWindow *parent = nullptr);

	virtual ViewType get_type() const = 0;
	bool is_main_view() const;

	/**
	 * Resets the view to its default state after construction. It does however
	 * not reset the signal bases or any other connections with the session.
	 */
	virtual void reset_view_state();

	Session& session();
	const Session& session() const;

	virtual void clear_signals();

	/**
	 * Returns the signal bases contained in this view.
	 */
	vector< shared_ptr<data::SignalBase> > signalbases() const;

	virtual void clear_signalbases();

	virtual void add_signalbase(const shared_ptr<data::SignalBase> signalbase);

#ifdef ENABLE_DECODE
	virtual void clear_decode_signals();

	virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);

	virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
#endif

	virtual void save_settings(QSettings &settings) const;

	virtual void restore_settings(QSettings &settings);

public Q_SLOTS:
	virtual void trigger_event(int segment_id, util::Timestamp location);
	virtual void signals_changed();
	virtual void capture_state_updated(int state);
	virtual void on_new_segment(int new_segment_id);
	virtual void on_segment_completed(int new_segment_id);
	virtual void perform_delayed_view_update();

private Q_SLOTS:
	void on_samples_added(uint64_t segment_id, uint64_t start_sample,
		uint64_t end_sample);

	void on_data_updated();

protected:
	Session &session_;

	const bool is_main_view_;

	util::TimeUnit time_unit_;

	vector< shared_ptr<data::SignalBase> > signalbases_;
#ifdef ENABLE_DECODE
	vector< shared_ptr<data::DecodeSignal> > decode_signals_;
#endif

	/// The ID of the currently displayed segment
	uint32_t current_segment_;

	QTimer delayed_view_updater_;
};

} // namespace views
} // namespace pv

#endif // PULSEVIEW_PV_VIEWS_VIEWBASE_HPP