]>
Commit | Line | Data |
---|---|---|
f9101a91 JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
f9101a91 JH |
18 | */ |
19 | ||
d5e79020 SA |
20 | #include <cassert> |
21 | ||
cbb2e4da | 22 | #include "decoder.hpp" |
2acdb232 | 23 | #include "row.hpp" |
f9101a91 | 24 | |
88908838 JH |
25 | #include <libsigrokdecode/libsigrokdecode.h> |
26 | ||
f9101a91 JH |
27 | namespace pv { |
28 | namespace data { | |
29 | namespace decode { | |
30 | ||
31 | Row::Row() : | |
6a26fc44 | 32 | index_(0), |
4c60462b | 33 | decoder_(nullptr), |
6a26fc44 SA |
34 | srd_row_(nullptr), |
35 | visible_(true) | |
f9101a91 JH |
36 | { |
37 | } | |
38 | ||
6a26fc44 | 39 | Row::Row(uint32_t index, Decoder* decoder, const srd_decoder_annotation_row* srd_row) : |
f9807084 | 40 | index_(index), |
8dbbc7f0 | 41 | decoder_(decoder), |
6a26fc44 | 42 | srd_row_(srd_row), |
c6b4e925 | 43 | visible_(true) |
f9101a91 JH |
44 | { |
45 | } | |
46 | ||
cbb2e4da | 47 | const Decoder* Row::decoder() const |
f9101a91 | 48 | { |
8dbbc7f0 | 49 | return decoder_; |
f9101a91 JH |
50 | } |
51 | ||
6a26fc44 | 52 | const srd_decoder_annotation_row* Row::get_srd_row() const |
f9101a91 | 53 | { |
6a26fc44 | 54 | return srd_row_; |
f9101a91 JH |
55 | } |
56 | ||
88908838 JH |
57 | const QString Row::title() const |
58 | { | |
6a26fc44 | 59 | if (decoder_ && decoder_->name() && srd_row_ && srd_row_->desc) |
88908838 | 60 | return QString("%1: %2") |
cbb2e4da | 61 | .arg(QString::fromUtf8(decoder_->name()), |
6a26fc44 | 62 | QString::fromUtf8(srd_row_->desc)); |
cbb2e4da SA |
63 | if (decoder_ && decoder_->name()) |
64 | return QString::fromUtf8(decoder_->name()); | |
6a26fc44 SA |
65 | if (srd_row_ && srd_row_->desc) |
66 | return QString::fromUtf8(srd_row_->desc); | |
67 | ||
88908838 JH |
68 | return QString(); |
69 | } | |
70 | ||
6a26fc44 | 71 | const QString Row::description() const |
1ed996b4 | 72 | { |
6a26fc44 SA |
73 | if (srd_row_ && srd_row_->desc) |
74 | return QString::fromUtf8(srd_row_->desc); | |
1ed996b4 SA |
75 | return QString(); |
76 | } | |
77 | ||
6a26fc44 SA |
78 | vector<AnnotationClass*> Row::ann_classes() const |
79 | { | |
41293691 SA |
80 | assert(decoder_); |
81 | ||
6a26fc44 SA |
82 | vector<AnnotationClass*> result; |
83 | ||
41293691 SA |
84 | if (!srd_row_) { |
85 | if (index_ == 0) { | |
86 | // When operating as the fallback row, all annotation classes belong to it | |
87 | return decoder_->ann_classes(); | |
88 | } | |
6a26fc44 | 89 | return result; |
41293691 | 90 | } |
6a26fc44 SA |
91 | |
92 | for (GSList *l = srd_row_->ann_classes; l; l = l->next) { | |
93 | size_t class_id = (size_t)l->data; | |
94 | result.push_back(decoder_->get_ann_class_by_id(class_id)); | |
95 | } | |
96 | ||
97 | return result; | |
98 | } | |
99 | ||
100 | uint32_t Row::index() const | |
f9807084 SA |
101 | { |
102 | return index_; | |
103 | } | |
104 | ||
c6b4e925 SA |
105 | bool Row::visible() const |
106 | { | |
107 | return visible_; | |
108 | } | |
109 | ||
110 | void Row::set_visible(bool visible) | |
111 | { | |
112 | visible_ = visible; | |
02078aa1 SA |
113 | |
114 | visibility_changed(); | |
c6b4e925 SA |
115 | } |
116 | ||
ae30ff42 SA |
117 | void Row::set_base_color(QColor base_color) |
118 | { | |
119 | // For the row color, use the base color hue and add an offset that's | |
120 | // not a dividend of 360 | |
121 | ||
122 | const int h = (base_color.toHsv().hue() + 20 * index_) % 360; | |
123 | const int s = DECODE_COLOR_SATURATION; | |
124 | const int v = DECODE_COLOR_VALUE; | |
125 | color_.setHsl(h, s, v); | |
126 | ||
127 | vector<AnnotationClass*> classes = ann_classes(); | |
128 | for (const AnnotationClass* ann_class : classes) { | |
129 | ||
130 | // For each class color, use the row color hue and add an offset that's | |
131 | // not a dividend of 360 and not a multiple of the row offset | |
132 | ||
133 | QColor ann_color(color_); | |
134 | const int h = (ann_color.toHsv().hue() + 55 * ann_class->id) % 360; | |
135 | const int s = DECODE_COLOR_SATURATION; | |
136 | const int v = DECODE_COLOR_VALUE; | |
137 | ann_color.setHsl(h, s, v); | |
138 | ||
139 | ann_class_color_[ann_class->id] = ann_color; | |
140 | ann_bright_class_color_[ann_class->id] = ann_color.lighter(); | |
141 | ann_dark_class_color_[ann_class->id] = ann_color.darker(); | |
142 | } | |
143 | } | |
144 | ||
145 | const QColor Row::color() const | |
146 | { | |
147 | return color_; | |
148 | } | |
149 | ||
150 | const QColor Row::get_class_color(uint32_t ann_class_id) const | |
151 | { | |
152 | return ann_class_color_.at(ann_class_id); | |
153 | } | |
154 | ||
155 | const QColor Row::get_bright_class_color(uint32_t ann_class_id) const | |
156 | { | |
157 | return ann_bright_class_color_.at(ann_class_id); | |
158 | } | |
159 | ||
160 | const QColor Row::get_dark_class_color(uint32_t ann_class_id) const | |
161 | { | |
162 | return ann_dark_class_color_.at(ann_class_id); | |
163 | } | |
164 | ||
81dc0221 SA |
165 | bool Row::has_hidden_classes() const |
166 | { | |
167 | for (const AnnotationClass* c : ann_classes()) | |
02078aa1 | 168 | if (!c->visible()) |
81dc0221 SA |
169 | return true; |
170 | ||
171 | return false; | |
172 | } | |
173 | ||
86d4b8e3 SA |
174 | bool Row::class_is_visible(uint32_t ann_class_id) const |
175 | { | |
02078aa1 | 176 | return decoder_->get_ann_class_by_id(ann_class_id)->visible(); |
86d4b8e3 SA |
177 | } |
178 | ||
cbb2e4da | 179 | bool Row::operator<(const Row& other) const |
f9101a91 | 180 | { |
8dbbc7f0 | 181 | return (decoder_ < other.decoder_) || |
6a26fc44 | 182 | (decoder_ == other.decoder_ && srd_row_ < other.srd_row_); |
f9101a91 JH |
183 | } |
184 | ||
cbb2e4da | 185 | bool Row::operator==(const Row& other) const |
84002113 | 186 | { |
6a26fc44 | 187 | return ((decoder_ == other.decoder()) && (srd_row_ == other.srd_row_)); |
84002113 SA |
188 | } |
189 | ||
870ea3db UH |
190 | } // namespace decode |
191 | } // namespace data | |
192 | } // namespace pv |