2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
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.
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.
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
24 #include "signalbase.hpp"
25 #include "signaldata.hpp"
26 #include "decode/row.hpp"
28 #include <pv/binding/decoder.hpp>
30 using std::dynamic_pointer_cast;
31 using std::shared_ptr;
33 using sigrok::Channel;
34 using sigrok::ChannelType;
39 const int SignalBase::ColourBGAlpha = 8*256/100;
41 SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel) :
45 internal_name_ = QString::fromStdString(channel_->name());
48 shared_ptr<sigrok::Channel> SignalBase::channel() const
53 QString SignalBase::name() const
55 return (channel_) ? QString::fromStdString(channel_->name()) : name_;
58 QString SignalBase::internal_name() const
60 return internal_name_;
63 void SignalBase::set_name(QString name)
66 channel_->set_name(name.toUtf8().constData());
73 bool SignalBase::enabled() const
75 return (channel_) ? channel_->enabled() : true;
78 void SignalBase::set_enabled(bool value)
81 channel_->set_enabled(value);
82 enabled_changed(value);
86 const ChannelType *SignalBase::type() const
88 return (channel_) ? channel_->type() : nullptr;
91 unsigned int SignalBase::index() const
93 return (channel_) ? channel_->index() : (unsigned int)-1;
96 QColor SignalBase::colour() const
101 void SignalBase::set_colour(QColor colour)
106 bgcolour_.setAlpha(ColourBGAlpha);
108 colour_changed(colour);
111 QColor SignalBase::bgcolour() const
116 void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
121 shared_ptr<data::Analog> SignalBase::analog_data() const
123 if (type() == ChannelType::ANALOG)
124 return dynamic_pointer_cast<data::Analog>(data_);
126 return shared_ptr<data::Analog>();
129 shared_ptr<data::Logic> SignalBase::logic_data() const
131 if (type() == ChannelType::LOGIC)
132 return dynamic_pointer_cast<data::Logic>(data_);
134 return shared_ptr<data::Logic>();
138 bool SignalBase::is_decode_signal() const
140 return (decoder_stack_ != nullptr);
143 std::shared_ptr<pv::data::DecoderStack> SignalBase::decoder_stack() const
145 return decoder_stack_;
148 void SignalBase::set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
151 decoder_stack_ = decoder_stack;
155 void SignalBase::save_settings(QSettings &settings) const
157 settings.setValue("name", name());
158 settings.setValue("enabled", enabled());
159 settings.setValue("colour", colour());
162 void SignalBase::restore_settings(QSettings &settings)
164 set_name(settings.value("name").toString());
165 set_enabled(settings.value("enabled").toBool());
166 set_colour(settings.value("colour").value<QColor>());