]> sigrok.org Git - pulseview.git/blob - pv/data/signalbase.hpp
Introduce PV-internal channel types
[pulseview.git] / pv / data / signalbase.hpp
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_DATA_SIGNALBASE_HPP
22 #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP
23
24 #include <QColor>
25 #include <QObject>
26 #include <QSettings>
27 #include <QString>
28
29 #include <libsigrokcxx/libsigrokcxx.hpp>
30
31 using std::shared_ptr;
32
33 namespace sigrok {
34 class Channel;
35 }
36
37 namespace pv {
38 namespace data {
39
40 class Analog;
41 class DecoderStack;
42 class Logic;
43 class SignalData;
44
45 class SignalBase : public QObject
46 {
47         Q_OBJECT
48
49 public:
50         enum ChannelType {
51                 AnalogChannel = 1,
52                 LogicChannel,
53                 DecodeChannel,
54                 A2LChannel,  // Analog converted to logic, joint representation
55                 MathChannel
56         };
57
58 private:
59         static const int ColourBGAlpha;
60
61 public:
62         SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type);
63         virtual ~SignalBase() {}
64
65 public:
66         /**
67          * Returns the underlying SR channel.
68          */
69         shared_ptr<sigrok::Channel> channel() const;
70
71         /**
72          * Returns enabled status of this channel.
73          */
74         bool enabled() const;
75
76         /**
77          * Sets the enabled status of this channel.
78          * @param value Boolean value to set.
79          */
80         void set_enabled(bool value);
81
82         /**
83          * Gets the type of this channel.
84          */
85         ChannelType type() const;
86
87         /**
88          * Gets the index number of this channel.
89          */
90         unsigned int index() const;
91
92         /**
93          * Gets the name of this signal.
94          */
95         QString name() const;
96
97         /**
98          * Gets the internal name of this signal, i.e. how the device calls it.
99          */
100         QString internal_name() const;
101
102         /**
103          * Sets the name of the signal.
104          */
105         virtual void set_name(QString name);
106
107         /**
108          * Get the colour of the signal.
109          */
110         QColor colour() const;
111
112         /**
113          * Set the colour of the signal.
114          */
115         void set_colour(QColor colour);
116
117         /**
118          * Get the background colour of the signal.
119          */
120         QColor bgcolour() const;
121
122         /**
123          * Sets the internal data object.
124          */
125         void set_data(shared_ptr<pv::data::SignalData> data);
126
127         /**
128          * Get the internal data as analog data object in case of analog type.
129          */
130         shared_ptr<pv::data::Analog> analog_data() const;
131
132         /**
133          * Get the internal data as logic data object in case of logic type.
134          */
135         shared_ptr<pv::data::Logic> logic_data() const;
136
137 #ifdef ENABLE_DECODE
138         bool is_decode_signal() const;
139
140         shared_ptr<pv::data::DecoderStack> decoder_stack() const;
141
142         void set_decoder_stack(shared_ptr<pv::data::DecoderStack> decoder_stack);
143 #endif
144
145         void save_settings(QSettings &settings) const;
146
147         void restore_settings(QSettings &settings);
148
149 Q_SIGNALS:
150         void enabled_changed(const bool &value);
151
152         void name_changed(const QString &name);
153
154         void colour_changed(const QColor &colour);
155
156 private:
157         shared_ptr<sigrok::Channel> channel_;
158         ChannelType channel_type_;
159         shared_ptr<pv::data::SignalData> data_;
160
161 #ifdef ENABLE_DECODE
162         shared_ptr<pv::data::DecoderStack> decoder_stack_;
163 #endif
164
165         QString internal_name_, name_;
166         QColor colour_, bgcolour_;
167 };
168
169 } // namespace data
170 } // namespace pv
171
172 #endif // PULSEVIEW_PV_DATA_SIGNALBASE_HPP