]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | #include "signalbase.hpp" | |
23 | ||
24 | using std::shared_ptr; | |
25 | ||
26 | using sigrok::Channel; | |
27 | using sigrok::ChannelType; | |
28 | ||
29 | namespace pv { | |
30 | namespace data { | |
31 | ||
32 | const int SignalBase::ColourBGAlpha = 8*256/100; | |
33 | ||
34 | SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel) : | |
35 | channel_(channel) | |
36 | { | |
37 | } | |
38 | ||
39 | shared_ptr<sigrok::Channel> SignalBase::channel() const | |
40 | { | |
41 | return channel_; | |
42 | } | |
43 | ||
44 | QString SignalBase::name() const | |
45 | { | |
46 | return (channel_) ? QString::fromStdString(channel_->name()) : name_; | |
47 | } | |
48 | ||
49 | void SignalBase::set_name(QString name) | |
50 | { | |
51 | if (channel_) | |
52 | channel_->set_name(name.toUtf8().constData()); | |
53 | ||
54 | name_ = name; | |
55 | ||
56 | name_changed(name); | |
57 | } | |
58 | ||
59 | bool SignalBase::enabled() const | |
60 | { | |
61 | return (channel_) ? channel_->enabled() : true; | |
62 | } | |
63 | ||
64 | void SignalBase::set_enabled(bool value) | |
65 | { | |
66 | if (channel_) { | |
67 | channel_->set_enabled(value); | |
68 | enabled_changed(value); | |
69 | } | |
70 | } | |
71 | ||
72 | const ChannelType *SignalBase::type() const | |
73 | { | |
74 | return (channel_) ? channel_->type() : nullptr; | |
75 | } | |
76 | ||
77 | unsigned int SignalBase::index() const | |
78 | { | |
79 | return (channel_) ? channel_->index() : (unsigned int)-1; | |
80 | } | |
81 | ||
82 | QColor SignalBase::colour() const | |
83 | { | |
84 | return colour_; | |
85 | } | |
86 | ||
87 | void SignalBase::set_colour(QColor colour) | |
88 | { | |
89 | colour_ = colour; | |
90 | ||
91 | bgcolour_ = colour; | |
92 | bgcolour_.setAlpha(ColourBGAlpha); | |
93 | ||
94 | colour_changed(colour); | |
95 | } | |
96 | ||
97 | QColor SignalBase::bgcolour() const | |
98 | { | |
99 | return bgcolour_; | |
100 | } | |
101 | ||
102 | } // namespace data | |
103 | } // namespace pv |