]> sigrok.org Git - pulseview.git/blame - pv/data/signalbase.cpp
Move view-independent data from view::DecodeTrace to SignalBase
[pulseview.git] / pv / data / signalbase.cpp
CommitLineData
bf0edd2b
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
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
cbd2a2de
SA
22#include "analog.hpp"
23#include "logic.hpp"
bf0edd2b 24#include "signalbase.hpp"
cbd2a2de 25#include "signaldata.hpp"
bb7dd726
SA
26#include "decode/row.hpp"
27
28#include <pv/binding/decoder.hpp>
bf0edd2b 29
cbd2a2de 30using std::dynamic_pointer_cast;
bf0edd2b
SA
31using std::shared_ptr;
32
33using sigrok::Channel;
34using sigrok::ChannelType;
35
36namespace pv {
37namespace data {
38
39const int SignalBase::ColourBGAlpha = 8*256/100;
40
41SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel) :
42 channel_(channel)
43{
44}
45
46shared_ptr<sigrok::Channel> SignalBase::channel() const
47{
48 return channel_;
49}
50
51QString SignalBase::name() const
52{
53 return (channel_) ? QString::fromStdString(channel_->name()) : name_;
54}
55
56void SignalBase::set_name(QString name)
57{
58 if (channel_)
59 channel_->set_name(name.toUtf8().constData());
60
61 name_ = name;
62
63 name_changed(name);
64}
65
66bool SignalBase::enabled() const
67{
68 return (channel_) ? channel_->enabled() : true;
69}
70
71void SignalBase::set_enabled(bool value)
72{
73 if (channel_) {
74 channel_->set_enabled(value);
75 enabled_changed(value);
76 }
77}
78
79const ChannelType *SignalBase::type() const
80{
81 return (channel_) ? channel_->type() : nullptr;
82}
83
84unsigned int SignalBase::index() const
85{
86 return (channel_) ? channel_->index() : (unsigned int)-1;
87}
88
89QColor SignalBase::colour() const
90{
91 return colour_;
92}
93
94void SignalBase::set_colour(QColor colour)
95{
96 colour_ = colour;
97
98 bgcolour_ = colour;
99 bgcolour_.setAlpha(ColourBGAlpha);
100
101 colour_changed(colour);
102}
103
104QColor SignalBase::bgcolour() const
105{
106 return bgcolour_;
107}
108
cbd2a2de
SA
109void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
110{
111 data_ = data;
112}
113
114shared_ptr<data::Analog> SignalBase::analog_data() const
115{
116 if (type() == ChannelType::ANALOG)
117 return dynamic_pointer_cast<data::Analog>(data_);
118 else
119 return shared_ptr<data::Analog>();
120}
121
122shared_ptr<data::Logic> SignalBase::logic_data() const
123{
124 if (type() == ChannelType::LOGIC)
125 return dynamic_pointer_cast<data::Logic>(data_);
126 else
127 return shared_ptr<data::Logic>();
128}
129
bb7dd726
SA
130#ifdef ENABLE_DECODE
131bool SignalBase::is_decode_signal() const
132{
133 return (decoder_stack_ != nullptr);
134}
135
136std::shared_ptr<pv::data::DecoderStack> SignalBase::decoder_stack() const
137{
138 return decoder_stack_;
139}
140
141void SignalBase::set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
142 decoder_stack)
143{
144 decoder_stack_ = decoder_stack;
145}
146#endif
cbd2a2de 147
bf0edd2b
SA
148} // namespace data
149} // namespace pv