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