]> sigrok.org Git - pulseview.git/blob - pv/data/decode/row.cpp
DecodeTrace: Highlight row expand markers when a class is hidden
[pulseview.git] / pv / data / decode / row.cpp
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
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "decoder.hpp"
21 #include "row.hpp"
22
23 #include <libsigrokdecode/libsigrokdecode.h>
24
25 namespace pv {
26 namespace data {
27 namespace decode {
28
29 Row::Row() :
30         index_(0),
31         decoder_(nullptr),
32         srd_row_(nullptr),
33         visible_(true)
34 {
35 }
36
37 Row::Row(uint32_t index, Decoder* decoder, const srd_decoder_annotation_row* srd_row) :
38         index_(index),
39         decoder_(decoder),
40         srd_row_(srd_row),
41         visible_(true)
42 {
43 }
44
45 const Decoder* Row::decoder() const
46 {
47         return decoder_;
48 }
49
50 const srd_decoder_annotation_row* Row::get_srd_row() const
51 {
52         return srd_row_;
53 }
54
55 const QString Row::title() const
56 {
57         if (decoder_ && decoder_->name() && srd_row_ && srd_row_->desc)
58                 return QString("%1: %2")
59                         .arg(QString::fromUtf8(decoder_->name()),
60                              QString::fromUtf8(srd_row_->desc));
61         if (decoder_ && decoder_->name())
62                 return QString::fromUtf8(decoder_->name());
63         if (srd_row_ && srd_row_->desc)
64                 return QString::fromUtf8(srd_row_->desc);
65
66         return QString();
67 }
68
69 const QString Row::description() const
70 {
71         if (srd_row_ && srd_row_->desc)
72                 return QString::fromUtf8(srd_row_->desc);
73         return QString();
74 }
75
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
93 {
94         return index_;
95 }
96
97 bool Row::visible() const
98 {
99         return visible_;
100 }
101
102 void Row::set_visible(bool visible)
103 {
104         visible_ = visible;
105 }
106
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
116 bool Row::operator<(const Row& other) const
117 {
118         return (decoder_ < other.decoder_) ||
119                 (decoder_ == other.decoder_ && srd_row_ < other.srd_row_);
120 }
121
122 bool Row::operator==(const Row& other) const
123 {
124         return ((decoder_ == other.decoder()) && (srd_row_ == other.srd_row_));
125 }
126
127 }  // namespace decode
128 }  // namespace data
129 }  // namespace pv