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