]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/viewbase.hpp
Save/restore view type
[pulseview.git] / pv / views / viewbase.hpp
... / ...
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#ifndef PULSEVIEW_PV_VIEWS_VIEWBASE_HPP
22#define PULSEVIEW_PV_VIEWS_VIEWBASE_HPP
23
24#include <cstdint>
25#include <memory>
26#include <unordered_set>
27#include <vector>
28
29#include <QMainWindow>
30#include <QTimer>
31#include <QWidget>
32
33#include <pv/data/signalbase.hpp>
34#include <pv/util.hpp>
35
36#ifdef ENABLE_DECODE
37#include <pv/data/decodesignal.hpp>
38#endif
39
40using std::shared_ptr;
41using std::unordered_set;
42
43namespace pv {
44
45class Session;
46
47namespace view {
48class DecodeTrace;
49class Signal;
50}
51
52namespace views {
53
54// When adding an entry here, don't forget to update ViewTypeNames as well
55enum ViewType {
56 ViewTypeTrace,
57#ifdef ENABLE_DECODE
58 ViewTypeDecoderOutput,
59#endif
60 ViewTypeCount // Indicates how many view types there are, must always be last
61};
62
63extern const char* ViewTypeNames[ViewTypeCount];
64
65class ViewBase : public QWidget
66{
67 Q_OBJECT
68
69private:
70 static const int MaxViewAutoUpdateRate;
71
72public:
73 explicit ViewBase(Session &session, bool is_main_view = false, QMainWindow *parent = nullptr);
74
75 virtual ViewType get_type() const = 0;
76
77 /**
78 * Resets the view to its default state after construction. It does however
79 * not reset the signal bases or any other connections with the session.
80 */
81 virtual void reset_view_state();
82
83 Session& session();
84 const Session& session() const;
85
86 virtual void clear_signals();
87
88 /**
89 * Returns the signal bases contained in this view.
90 */
91 unordered_set< shared_ptr<data::SignalBase> > signalbases() const;
92
93 virtual void clear_signalbases();
94
95 virtual void add_signalbase(const shared_ptr<data::SignalBase> signalbase);
96
97#ifdef ENABLE_DECODE
98 virtual void clear_decode_signals();
99
100 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
101
102 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
103#endif
104
105 virtual void save_settings(QSettings &settings) const;
106
107 virtual void restore_settings(QSettings &settings);
108
109public Q_SLOTS:
110 virtual void trigger_event(int segment_id, util::Timestamp location);
111 virtual void signals_changed();
112 virtual void capture_state_updated(int state);
113 virtual void on_new_segment(int new_segment_id);
114 virtual void on_segment_completed(int new_segment_id);
115 virtual void perform_delayed_view_update();
116
117private Q_SLOTS:
118 void on_samples_added(uint64_t segment_id, uint64_t start_sample,
119 uint64_t end_sample);
120
121 void on_data_updated();
122
123protected:
124 Session &session_;
125
126 const bool is_main_view_;
127
128 util::TimeUnit time_unit_;
129
130 unordered_set< shared_ptr<data::SignalBase> > signalbases_;
131
132 /// The ID of the currently displayed segment
133 uint32_t current_segment_;
134
135 QTimer delayed_view_updater_;
136};
137
138} // namespace views
139} // namespace pv
140
141#endif // PULSEVIEW_PV_VIEWS_VIEWBASE_HPP