]>
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 | 20 | #include <cassert> |
eb31c238 | 21 | #include <QDebug> |
d5e79020 | 22 | |
cbb2e4da | 23 | #include "decoder.hpp" |
2acdb232 | 24 | #include "row.hpp" |
f9101a91 | 25 | |
88908838 JH |
26 | #include <libsigrokdecode/libsigrokdecode.h> |
27 | ||
f9101a91 JH |
28 | namespace pv { |
29 | namespace data { | |
30 | namespace decode { | |
31 | ||
32 | Row::Row() : | |
6a26fc44 | 33 | index_(0), |
4c60462b | 34 | decoder_(nullptr), |
6a26fc44 SA |
35 | srd_row_(nullptr), |
36 | visible_(true) | |
f9101a91 JH |
37 | { |
38 | } | |
39 | ||
6a26fc44 | 40 | Row::Row(uint32_t index, Decoder* decoder, const srd_decoder_annotation_row* srd_row) : |
f9807084 | 41 | index_(index), |
8dbbc7f0 | 42 | decoder_(decoder), |
6a26fc44 | 43 | srd_row_(srd_row), |
c6b4e925 | 44 | visible_(true) |
f9101a91 JH |
45 | { |
46 | } | |
47 | ||
cbb2e4da | 48 | const Decoder* Row::decoder() const |
f9101a91 | 49 | { |
8dbbc7f0 | 50 | return decoder_; |
f9101a91 JH |
51 | } |
52 | ||
6a26fc44 | 53 | const srd_decoder_annotation_row* Row::get_srd_row() const |
f9101a91 | 54 | { |
6a26fc44 | 55 | return srd_row_; |
f9101a91 JH |
56 | } |
57 | ||
88908838 JH |
58 | const QString Row::title() const |
59 | { | |
6a26fc44 | 60 | if (decoder_ && decoder_->name() && srd_row_ && srd_row_->desc) |
88908838 | 61 | return QString("%1: %2") |
cbb2e4da | 62 | .arg(QString::fromUtf8(decoder_->name()), |
6a26fc44 | 63 | QString::fromUtf8(srd_row_->desc)); |
cbb2e4da SA |
64 | if (decoder_ && decoder_->name()) |
65 | return QString::fromUtf8(decoder_->name()); | |
6a26fc44 SA |
66 | if (srd_row_ && srd_row_->desc) |
67 | return QString::fromUtf8(srd_row_->desc); | |
68 | ||
88908838 JH |
69 | return QString(); |
70 | } | |
71 | ||
6a26fc44 | 72 | const QString Row::description() const |
1ed996b4 | 73 | { |
6a26fc44 SA |
74 | if (srd_row_ && srd_row_->desc) |
75 | return QString::fromUtf8(srd_row_->desc); | |
1ed996b4 SA |
76 | return QString(); |
77 | } | |
78 | ||
6a26fc44 SA |
79 | vector<AnnotationClass*> Row::ann_classes() const |
80 | { | |
41293691 SA |
81 | assert(decoder_); |
82 | ||
6a26fc44 SA |
83 | vector<AnnotationClass*> result; |
84 | ||
41293691 SA |
85 | if (!srd_row_) { |
86 | if (index_ == 0) { | |
87 | // When operating as the fallback row, all annotation classes belong to it | |
88 | return decoder_->ann_classes(); | |
89 | } | |
6a26fc44 | 90 | return result; |
41293691 | 91 | } |
6a26fc44 SA |
92 | |
93 | for (GSList *l = srd_row_->ann_classes; l; l = l->next) { | |
94 | size_t class_id = (size_t)l->data; | |
95 | result.push_back(decoder_->get_ann_class_by_id(class_id)); | |
96 | } | |
97 | ||
98 | return result; | |
99 | } | |
100 | ||
101 | uint32_t Row::index() const | |
f9807084 SA |
102 | { |
103 | return index_; | |
104 | } | |
105 | ||
c6b4e925 SA |
106 | bool Row::visible() const |
107 | { | |
108 | return visible_; | |
109 | } | |
110 | ||
111 | void Row::set_visible(bool visible) | |
112 | { | |
113 | visible_ = visible; | |
02078aa1 SA |
114 | |
115 | visibility_changed(); | |
c6b4e925 SA |
116 | } |
117 | ||
ae30ff42 SA |
118 | void Row::set_base_color(QColor base_color) |
119 | { | |
120 | // For the row color, use the base color hue and add an offset that's | |
121 | // not a dividend of 360 | |
122 | ||
123 | const int h = (base_color.toHsv().hue() + 20 * index_) % 360; | |
124 | const int s = DECODE_COLOR_SATURATION; | |
125 | const int v = DECODE_COLOR_VALUE; | |
126 | color_.setHsl(h, s, v); | |
127 | ||
128 | vector<AnnotationClass*> classes = ann_classes(); | |
129 | for (const AnnotationClass* ann_class : classes) { | |
130 | ||
131 | // For each class color, use the row color hue and add an offset that's | |
132 | // not a dividend of 360 and not a multiple of the row offset | |
133 | ||
134 | QColor ann_color(color_); | |
135 | const int h = (ann_color.toHsv().hue() + 55 * ann_class->id) % 360; | |
136 | const int s = DECODE_COLOR_SATURATION; | |
137 | const int v = DECODE_COLOR_VALUE; | |
138 | ann_color.setHsl(h, s, v); | |
139 | ||
140 | ann_class_color_[ann_class->id] = ann_color; | |
141 | ann_bright_class_color_[ann_class->id] = ann_color.lighter(); | |
142 | ann_dark_class_color_[ann_class->id] = ann_color.darker(); | |
143 | } | |
144 | } | |
145 | ||
146 | const QColor Row::color() const | |
147 | { | |
148 | return color_; | |
149 | } | |
150 | ||
151 | const QColor Row::get_class_color(uint32_t ann_class_id) const | |
152 | { | |
eb31c238 SA |
153 | try { |
154 | return ann_class_color_.at(ann_class_id); | |
155 | } catch (std::out_of_range &e) { | |
156 | qWarning() << "Warning: annotation type" << decoder_->get_ann_class_by_id(ann_class_id)->name | |
157 | << "(" << ann_class_id << ")" << "not assigned to any annotation row!"; | |
158 | return QColor(20, 20, 20); | |
159 | } | |
ae30ff42 SA |
160 | } |
161 | ||
162 | const QColor Row::get_bright_class_color(uint32_t ann_class_id) const | |
163 | { | |
eb31c238 SA |
164 | try { |
165 | return ann_bright_class_color_.at(ann_class_id); | |
166 | } catch (std::out_of_range &e) { | |
167 | return QColor(20, 20, 20); | |
168 | } | |
ae30ff42 SA |
169 | } |
170 | ||
171 | const QColor Row::get_dark_class_color(uint32_t ann_class_id) const | |
172 | { | |
eb31c238 SA |
173 | try { |
174 | return ann_dark_class_color_.at(ann_class_id); | |
175 | } catch (std::out_of_range &e) { | |
176 | return QColor(20, 20, 20); | |
177 | } | |
ae30ff42 SA |
178 | } |
179 | ||
81dc0221 SA |
180 | bool Row::has_hidden_classes() const |
181 | { | |
182 | for (const AnnotationClass* c : ann_classes()) | |
02078aa1 | 183 | if (!c->visible()) |
81dc0221 SA |
184 | return true; |
185 | ||
186 | return false; | |
187 | } | |
188 | ||
86d4b8e3 SA |
189 | bool Row::class_is_visible(uint32_t ann_class_id) const |
190 | { | |
02078aa1 | 191 | return decoder_->get_ann_class_by_id(ann_class_id)->visible(); |
86d4b8e3 SA |
192 | } |
193 | ||
cbb2e4da | 194 | bool Row::operator<(const Row& other) const |
f9101a91 | 195 | { |
8dbbc7f0 | 196 | return (decoder_ < other.decoder_) || |
6a26fc44 | 197 | (decoder_ == other.decoder_ && srd_row_ < other.srd_row_); |
f9101a91 JH |
198 | } |
199 | ||
cbb2e4da | 200 | bool Row::operator==(const Row& other) const |
84002113 | 201 | { |
6a26fc44 | 202 | return ((decoder_ == other.decoder()) && (srd_row_ == other.srd_row_)); |
84002113 SA |
203 | } |
204 | ||
870ea3db UH |
205 | } // namespace decode |
206 | } // namespace data | |
207 | } // namespace pv |