]> sigrok.org Git - pulseview.git/blame - pv/data/decode/annotation.cpp
Introduce DecodeSignal::annotation_visibility_changed and use it
[pulseview.git] / pv / data / decode / annotation.cpp
CommitLineData
06e810f2
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 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/>.
06e810f2
JH
18 */
19
20extern "C" {
21#include <libsigrokdecode/libsigrokdecode.h>
22}
23
943edd76 24#include <cassert>
7c2838bd
JH
25#include <vector>
26
6a26fc44 27#include <pv/data/decode/annotation.hpp>
761f8302 28#include <pv/data/decode/decoder.hpp>
1dcd9b18 29#include "pv/data/decode/rowdata.hpp"
06e810f2 30
6f925ba9
UH
31using std::vector;
32
06e810f2
JH
33namespace pv {
34namespace data {
35namespace decode {
36
1dcd9b18
SA
37Annotation::Annotation(uint64_t start_sample, uint64_t end_sample,
38 const vector<QString>* texts, Class ann_class_id, const RowData *data) :
39 start_sample_(start_sample),
40 end_sample_(end_sample),
41 texts_(texts),
42 ann_class_id_(ann_class_id),
43 data_(data)
06e810f2 44{
462941e2
SA
45}
46
47Annotation::Annotation(Annotation&& a) :
48 start_sample_(a.start_sample_),
49 end_sample_(a.end_sample_),
1dcd9b18
SA
50 texts_(a.texts_),
51 ann_class_id_(a.ann_class_id_),
52 data_(a.data_)
462941e2 53{
462941e2
SA
54}
55
56Annotation& Annotation::operator=(Annotation&& a)
57{
58 if (&a != this) {
462941e2
SA
59 start_sample_ = a.start_sample_;
60 end_sample_ = a.end_sample_;
1dcd9b18 61 texts_ = a.texts_;
462941e2 62 ann_class_id_ = a.ann_class_id_;
1dcd9b18 63 data_ = a.data_;
462941e2
SA
64 }
65
66 return *this;
67}
68
88a25978
SA
69const RowData* Annotation::row_data() const
70{
71 return data_;
72}
73
ae30ff42 74const Row* Annotation::row() const
462941e2 75{
ae30ff42 76 return data_->row();
06e810f2
JH
77}
78
79uint64_t Annotation::start_sample() const
80{
8dbbc7f0 81 return start_sample_;
06e810f2
JH
82}
83
84uint64_t Annotation::end_sample() const
85{
8dbbc7f0 86 return end_sample_;
06e810f2
JH
87}
88
d656b010
SA
89uint64_t Annotation::length() const
90{
91 return end_sample_ - start_sample_;
92}
93
462941e2 94Annotation::Class Annotation::ann_class_id() const
06e810f2 95{
462941e2 96 return ann_class_id_;
06e810f2
JH
97}
98
761f8302
SA
99const QString Annotation::ann_class_name() const
100{
101 const AnnotationClass* ann_class =
1dcd9b18 102 data_->row()->decoder()->get_ann_class_by_id(ann_class_id_);
761f8302
SA
103
104 return QString(ann_class->name);
105}
106
88a25978
SA
107const QString Annotation::ann_class_description() const
108{
109 const AnnotationClass* ann_class =
110 data_->row()->decoder()->get_ann_class_by_id(ann_class_id_);
111
112 return QString(ann_class->description);
113}
114
462941e2 115const vector<QString>* Annotation::annotations() const
06e810f2 116{
1dcd9b18 117 return texts_;
06e810f2
JH
118}
119
f54e68b0
SA
120const QString Annotation::longest_annotation() const
121{
1dcd9b18 122 return texts_->front();
f54e68b0
SA
123}
124
86d4b8e3
SA
125bool Annotation::visible() const
126{
127 const Row* row = data_->row();
128
02078aa1
SA
129 return (row->visible() && row->class_is_visible(ann_class_id_)
130 && row->decoder()->visible());
86d4b8e3
SA
131}
132
ae30ff42 133const QColor Annotation::color() const
5a914348 134{
ae30ff42
SA
135 return data_->row()->get_class_color(ann_class_id_);
136}
137
138const QColor Annotation::bright_color() const
139{
140 return data_->row()->get_bright_class_color(ann_class_id_);
141}
142
143const QColor Annotation::dark_color() const
144{
145 return data_->row()->get_dark_class_color(ann_class_id_);
5a914348
SA
146}
147
148bool Annotation::operator<(const Annotation &other) const
149{
150 return (start_sample_ < other.start_sample_);
151}
152
06e810f2
JH
153} // namespace decode
154} // namespace data
155} // namespace pv