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, see <http://www.gnu.org/licenses/>.
23 #include "signalbase.hpp"
24 #include "signaldata.hpp"
25 #include "decode/row.hpp"
27 #include <pv/binding/decoder.hpp>
29 using std::dynamic_pointer_cast;
30 using std::shared_ptr;
32 using sigrok::Channel;
33 using sigrok::ChannelType;
38 const int SignalBase::ColourBGAlpha = 8*256/100;
40 SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel) :
44 internal_name_ = QString::fromStdString(channel_->name());
47 shared_ptr<sigrok::Channel> SignalBase::channel() const
52 QString SignalBase::name() const
54 return (channel_) ? QString::fromStdString(channel_->name()) : name_;
57 QString SignalBase::internal_name() const
59 return internal_name_;
62 void SignalBase::set_name(QString name)
65 channel_->set_name(name.toUtf8().constData());
72 bool SignalBase::enabled() const
74 return (channel_) ? channel_->enabled() : true;
77 void SignalBase::set_enabled(bool value)
80 channel_->set_enabled(value);
81 enabled_changed(value);
85 const ChannelType *SignalBase::type() const
87 return (channel_) ? channel_->type() : nullptr;
90 unsigned int SignalBase::index() const
92 return (channel_) ? channel_->index() : (unsigned int)-1;
95 QColor SignalBase::colour() const
100 void SignalBase::set_colour(QColor colour)
105 bgcolour_.setAlpha(ColourBGAlpha);
107 colour_changed(colour);
110 QColor SignalBase::bgcolour() const
115 void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
120 shared_ptr<data::Analog> SignalBase::analog_data() const
122 if (type() == ChannelType::ANALOG)
123 return dynamic_pointer_cast<data::Analog>(data_);
125 return shared_ptr<data::Analog>();
128 shared_ptr<data::Logic> SignalBase::logic_data() const
130 if (type() == ChannelType::LOGIC)
131 return dynamic_pointer_cast<data::Logic>(data_);
133 return shared_ptr<data::Logic>();
137 bool SignalBase::is_decode_signal() const
139 return (decoder_stack_ != nullptr);
142 std::shared_ptr<pv::data::DecoderStack> SignalBase::decoder_stack() const
144 return decoder_stack_;
147 void SignalBase::set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
150 decoder_stack_ = decoder_stack;
154 void SignalBase::save_settings(QSettings &settings) const
156 settings.setValue("name", name());
157 settings.setValue("enabled", enabled());
158 settings.setValue("colour", colour());
161 void SignalBase::restore_settings(QSettings &settings)
163 set_name(settings.value("name").toString());
164 set_enabled(settings.value("enabled").toBool());
165 set_colour(settings.value("colour").value<QColor>());