]> sigrok.org Git - pulseview.git/blob - pv/data/signalbase.cpp
62881528a0c37faa47aba0f97a1ff242f95dcce4
[pulseview.git] / pv / data / signalbase.cpp
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include "analog.hpp"
23 #include "logic.hpp"
24 #include "signalbase.hpp"
25 #include "signaldata.hpp"
26
27 using std::dynamic_pointer_cast;
28 using std::shared_ptr;
29
30 using sigrok::Channel;
31 using sigrok::ChannelType;
32
33 namespace pv {
34 namespace data {
35
36 const int SignalBase::ColourBGAlpha = 8*256/100;
37
38 SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel) :
39         channel_(channel)
40 {
41 }
42
43 shared_ptr<sigrok::Channel> SignalBase::channel() const
44 {
45         return channel_;
46 }
47
48 QString SignalBase::name() const
49 {
50         return (channel_) ? QString::fromStdString(channel_->name()) : name_;
51 }
52
53 void SignalBase::set_name(QString name)
54 {
55         if (channel_)
56                 channel_->set_name(name.toUtf8().constData());
57
58         name_ = name;
59
60         name_changed(name);
61 }
62
63 bool SignalBase::enabled() const
64 {
65         return (channel_) ? channel_->enabled() : true;
66 }
67
68 void SignalBase::set_enabled(bool value)
69 {
70         if (channel_) {
71                 channel_->set_enabled(value);
72                 enabled_changed(value);
73         }
74 }
75
76 const ChannelType *SignalBase::type() const
77 {
78         return (channel_) ? channel_->type() : nullptr;
79 }
80
81 unsigned int SignalBase::index() const
82 {
83         return (channel_) ? channel_->index() : (unsigned int)-1;
84 }
85
86 QColor SignalBase::colour() const
87 {
88         return colour_;
89 }
90
91 void SignalBase::set_colour(QColor colour)
92 {
93         colour_ = colour;
94
95         bgcolour_ = colour;
96         bgcolour_.setAlpha(ColourBGAlpha);
97
98         colour_changed(colour);
99 }
100
101 QColor SignalBase::bgcolour() const
102 {
103         return bgcolour_;
104 }
105
106 void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
107 {
108         data_ = data;
109 }
110
111 shared_ptr<data::Analog> SignalBase::analog_data() const
112 {
113         if (type() == ChannelType::ANALOG)
114                 return dynamic_pointer_cast<data::Analog>(data_);
115         else
116                 return shared_ptr<data::Analog>();
117 }
118
119 shared_ptr<data::Logic> SignalBase::logic_data() const
120 {
121         if (type() == ChannelType::LOGIC)
122                 return dynamic_pointer_cast<data::Logic>(data_);
123         else
124                 return shared_ptr<data::Logic>();
125 }
126
127
128 } // namespace data
129 } // namespace pv