]>
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 | ||
cbb2e4da | 20 | #include "decoder.hpp" |
2acdb232 | 21 | #include "row.hpp" |
f9101a91 | 22 | |
88908838 JH |
23 | #include <libsigrokdecode/libsigrokdecode.h> |
24 | ||
f9101a91 JH |
25 | namespace pv { |
26 | namespace data { | |
27 | namespace decode { | |
28 | ||
29 | Row::Row() : | |
6a26fc44 | 30 | index_(0), |
4c60462b | 31 | decoder_(nullptr), |
6a26fc44 SA |
32 | srd_row_(nullptr), |
33 | visible_(true) | |
f9101a91 JH |
34 | { |
35 | } | |
36 | ||
6a26fc44 | 37 | Row::Row(uint32_t index, Decoder* decoder, const srd_decoder_annotation_row* srd_row) : |
f9807084 | 38 | index_(index), |
8dbbc7f0 | 39 | decoder_(decoder), |
6a26fc44 | 40 | srd_row_(srd_row), |
c6b4e925 | 41 | visible_(true) |
f9101a91 JH |
42 | { |
43 | } | |
44 | ||
cbb2e4da | 45 | const Decoder* Row::decoder() const |
f9101a91 | 46 | { |
8dbbc7f0 | 47 | return decoder_; |
f9101a91 JH |
48 | } |
49 | ||
6a26fc44 | 50 | const srd_decoder_annotation_row* Row::get_srd_row() const |
f9101a91 | 51 | { |
6a26fc44 | 52 | return srd_row_; |
f9101a91 JH |
53 | } |
54 | ||
88908838 JH |
55 | const QString Row::title() const |
56 | { | |
6a26fc44 | 57 | if (decoder_ && decoder_->name() && srd_row_ && srd_row_->desc) |
88908838 | 58 | return QString("%1: %2") |
cbb2e4da | 59 | .arg(QString::fromUtf8(decoder_->name()), |
6a26fc44 | 60 | QString::fromUtf8(srd_row_->desc)); |
cbb2e4da SA |
61 | if (decoder_ && decoder_->name()) |
62 | return QString::fromUtf8(decoder_->name()); | |
6a26fc44 SA |
63 | if (srd_row_ && srd_row_->desc) |
64 | return QString::fromUtf8(srd_row_->desc); | |
65 | ||
88908838 JH |
66 | return QString(); |
67 | } | |
68 | ||
6a26fc44 | 69 | const QString Row::description() const |
1ed996b4 | 70 | { |
6a26fc44 SA |
71 | if (srd_row_ && srd_row_->desc) |
72 | return QString::fromUtf8(srd_row_->desc); | |
1ed996b4 SA |
73 | return QString(); |
74 | } | |
75 | ||
6a26fc44 SA |
76 | vector<AnnotationClass*> Row::ann_classes() const |
77 | { | |
78 | vector<AnnotationClass*> result; | |
79 | ||
80 | if (!srd_row_) | |
81 | return result; | |
82 | assert(decoder_); | |
83 | ||
84 | for (GSList *l = srd_row_->ann_classes; l; l = l->next) { | |
85 | size_t class_id = (size_t)l->data; | |
86 | result.push_back(decoder_->get_ann_class_by_id(class_id)); | |
87 | } | |
88 | ||
89 | return result; | |
90 | } | |
91 | ||
92 | uint32_t Row::index() const | |
f9807084 SA |
93 | { |
94 | return index_; | |
95 | } | |
96 | ||
c6b4e925 SA |
97 | bool Row::visible() const |
98 | { | |
99 | return visible_; | |
100 | } | |
101 | ||
102 | void Row::set_visible(bool visible) | |
103 | { | |
104 | visible_ = visible; | |
105 | } | |
106 | ||
81dc0221 SA |
107 | bool Row::has_hidden_classes() const |
108 | { | |
109 | for (const AnnotationClass* c : ann_classes()) | |
110 | if (!c->visible) | |
111 | return true; | |
112 | ||
113 | return false; | |
114 | } | |
115 | ||
cbb2e4da | 116 | bool Row::operator<(const Row& other) const |
f9101a91 | 117 | { |
8dbbc7f0 | 118 | return (decoder_ < other.decoder_) || |
6a26fc44 | 119 | (decoder_ == other.decoder_ && srd_row_ < other.srd_row_); |
f9101a91 JH |
120 | } |
121 | ||
cbb2e4da | 122 | bool Row::operator==(const Row& other) const |
84002113 | 123 | { |
6a26fc44 | 124 | return ((decoder_ == other.decoder()) && (srd_row_ == other.srd_row_)); |
84002113 SA |
125 | } |
126 | ||
870ea3db UH |
127 | } // namespace decode |
128 | } // namespace data | |
129 | } // namespace pv |