]> sigrok.org Git - pulseview.git/blob - pv/data/decode/annotation.cpp
fe0350d03b1643a4aedba1623a27ba23981c83b0
[pulseview.git] / pv / data / decode / annotation.cpp
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
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 extern "C" {
21 #include <libsigrokdecode/libsigrokdecode.h>
22 }
23
24 #include <cassert>
25 #include <vector>
26
27 #include <pv/data/decode/annotation.hpp>
28 #include <pv/data/decode/decoder.hpp>
29 #include "pv/data/decode/rowdata.hpp"
30
31 using std::vector;
32
33 namespace pv {
34 namespace data {
35 namespace decode {
36
37 Annotation::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)
44 {
45 }
46
47 Annotation::Annotation(Annotation&& a) :
48         start_sample_(a.start_sample_),
49         end_sample_(a.end_sample_),
50         texts_(a.texts_),
51         ann_class_id_(a.ann_class_id_),
52         data_(a.data_)
53 {
54 }
55
56 Annotation& Annotation::operator=(Annotation&& a)
57 {
58         if (&a != this) {
59                 start_sample_ = a.start_sample_;
60                 end_sample_ = a.end_sample_;
61                 texts_ = a.texts_;
62                 ann_class_id_ = a.ann_class_id_;
63                 data_ = a.data_;
64         }
65
66         return *this;
67 }
68
69 const RowData* Annotation::row_data() const
70 {
71         return data_;
72 }
73
74 const Row* Annotation::row() const
75 {
76         return data_->row();
77 }
78
79 uint64_t Annotation::start_sample() const
80 {
81         return start_sample_;
82 }
83
84 uint64_t Annotation::end_sample() const
85 {
86         return end_sample_;
87 }
88
89 Annotation::Class Annotation::ann_class_id() const
90 {
91         return ann_class_id_;
92 }
93
94 const QString Annotation::ann_class_name() const
95 {
96         const AnnotationClass* ann_class =
97                 data_->row()->decoder()->get_ann_class_by_id(ann_class_id_);
98
99         return QString(ann_class->name);
100 }
101
102 const QString Annotation::ann_class_description() const
103 {
104         const AnnotationClass* ann_class =
105                 data_->row()->decoder()->get_ann_class_by_id(ann_class_id_);
106
107         return QString(ann_class->description);
108 }
109
110 const vector<QString>* Annotation::annotations() const
111 {
112         return texts_;
113 }
114
115 const QString Annotation::longest_annotation() const
116 {
117         return texts_->front();
118 }
119
120 const QColor Annotation::color() const
121 {
122         return data_->row()->get_class_color(ann_class_id_);
123 }
124
125 const QColor Annotation::bright_color() const
126 {
127         return data_->row()->get_bright_class_color(ann_class_id_);
128 }
129
130 const QColor Annotation::dark_color() const
131 {
132         return data_->row()->get_dark_class_color(ann_class_id_);
133 }
134
135 bool Annotation::operator<(const Annotation &other) const
136 {
137         return (start_sample_ < other.start_sample_);
138 }
139
140 } // namespace decode
141 } // namespace data
142 } // namespace pv