]> sigrok.org Git - pulseview.git/blame_incremental - pv/data/decode/row.cpp
DecodeTrace: Highlight row expand markers when a class is hidden
[pulseview.git] / pv / data / decode / row.cpp
... / ...
CommitLineData
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
25namespace pv {
26namespace data {
27namespace decode {
28
29Row::Row() :
30 index_(0),
31 decoder_(nullptr),
32 srd_row_(nullptr),
33 visible_(true)
34{
35}
36
37Row::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
45const Decoder* Row::decoder() const
46{
47 return decoder_;
48}
49
50const srd_decoder_annotation_row* Row::get_srd_row() const
51{
52 return srd_row_;
53}
54
55const 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
69const QString Row::description() const
70{
71 if (srd_row_ && srd_row_->desc)
72 return QString::fromUtf8(srd_row_->desc);
73 return QString();
74}
75
76vector<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
92uint32_t Row::index() const
93{
94 return index_;
95}
96
97bool Row::visible() const
98{
99 return visible_;
100}
101
102void Row::set_visible(bool visible)
103{
104 visible_ = visible;
105}
106
107bool 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
116bool Row::operator<(const Row& other) const
117{
118 return (decoder_ < other.decoder_) ||
119 (decoder_ == other.decoder_ && srd_row_ < other.srd_row_);
120}
121
122bool 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