]> sigrok.org Git - pulseview.git/blob - pv/data/decode/row.cpp
12951556390c15f2a0ed5e2e647365cb567fb675
[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         decoder_(nullptr),
31         row_(nullptr)
32 {
33 }
34
35 Row::Row(int index, const Decoder* decoder, const srd_decoder_annotation_row* row) :
36         index_(index),
37         decoder_(decoder),
38         row_(row)
39 {
40 }
41
42 const Decoder* Row::decoder() const
43 {
44         return decoder_;
45 }
46
47 const srd_decoder_annotation_row* Row::srd_row() const
48 {
49         return row_;
50 }
51
52 const QString Row::title() const
53 {
54         if (decoder_ && decoder_->name() && row_ && row_->desc)
55                 return QString("%1: %2")
56                         .arg(QString::fromUtf8(decoder_->name()),
57                              QString::fromUtf8(row_->desc));
58         if (decoder_ && decoder_->name())
59                 return QString::fromUtf8(decoder_->name());
60         if (row_ && row_->desc)
61                 return QString::fromUtf8(row_->desc);
62         return QString();
63 }
64
65 const QString Row::class_name() const
66 {
67         if (row_ && row_->desc)
68                 return QString::fromUtf8(row_->desc);
69         return QString();
70 }
71
72 int Row::index() const
73 {
74         return index_;
75 }
76
77 bool Row::operator<(const Row& other) const
78 {
79         return (decoder_ < other.decoder_) ||
80                 (decoder_ == other.decoder_ && row_ < other.row_);
81 }
82
83 bool Row::operator==(const Row& other) const
84 {
85         return ((decoder_ == other.decoder()) && (row_ == other.srd_row()));
86 }
87
88 }  // namespace decode
89 }  // namespace data
90 }  // namespace pv