]> sigrok.org Git - pulseview.git/blame_incremental - pv/data/decode/row.cpp
DecodeTrace: Disallow row hiding for the time being
[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 assert(decoder_);
79
80 vector<AnnotationClass*> result;
81
82 if (!srd_row_) {
83 if (index_ == 0) {
84 // When operating as the fallback row, all annotation classes belong to it
85 return decoder_->ann_classes();
86 }
87 return result;
88 }
89
90 for (GSList *l = srd_row_->ann_classes; l; l = l->next) {
91 size_t class_id = (size_t)l->data;
92 result.push_back(decoder_->get_ann_class_by_id(class_id));
93 }
94
95 return result;
96}
97
98uint32_t Row::index() const
99{
100 return index_;
101}
102
103bool Row::visible() const
104{
105 return visible_;
106}
107
108void Row::set_visible(bool visible)
109{
110 visible_ = visible;
111}
112
113bool Row::has_hidden_classes() const
114{
115 for (const AnnotationClass* c : ann_classes())
116 if (!c->visible)
117 return true;
118
119 return false;
120}
121
122bool Row::operator<(const Row& other) const
123{
124 return (decoder_ < other.decoder_) ||
125 (decoder_ == other.decoder_ && srd_row_ < other.srd_row_);
126}
127
128bool Row::operator==(const Row& other) const
129{
130 return ((decoder_ == other.decoder()) && (srd_row_ == other.srd_row_));
131}
132
133} // namespace decode
134} // namespace data
135} // namespace pv