]>
Commit | Line | Data |
---|---|---|
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 | #include <libsigrokdecode/libsigrokdecode.h> | |
21 | ||
22 | #include <cassert> | |
23 | #include <vector> | |
24 | ||
25 | #include <pv/data/decode/annotation.hpp> | |
26 | #include <pv/data/decode/decoder.hpp> | |
27 | #include "pv/data/decode/rowdata.hpp" | |
28 | ||
29 | using std::vector; | |
30 | ||
31 | namespace pv { | |
32 | namespace data { | |
33 | namespace decode { | |
34 | ||
35 | Annotation::Annotation(uint64_t start_sample, uint64_t end_sample, | |
36 | const vector<QString>* texts, uint32_t ann_class_id, const RowData *data) : | |
37 | start_sample_(start_sample), | |
38 | end_sample_(end_sample), | |
39 | texts_(texts), | |
40 | ann_class_id_(ann_class_id), | |
41 | data_(data) | |
42 | { | |
43 | } | |
44 | ||
45 | Annotation::Annotation(Annotation&& a) : | |
46 | start_sample_(a.start_sample_), | |
47 | end_sample_(a.end_sample_), | |
48 | texts_(a.texts_), | |
49 | ann_class_id_(a.ann_class_id_), | |
50 | data_(a.data_) | |
51 | { | |
52 | } | |
53 | ||
54 | Annotation& Annotation::operator=(Annotation&& a) | |
55 | { | |
56 | if (&a != this) { | |
57 | start_sample_ = a.start_sample_; | |
58 | end_sample_ = a.end_sample_; | |
59 | texts_ = a.texts_; | |
60 | ann_class_id_ = a.ann_class_id_; | |
61 | data_ = a.data_; | |
62 | } | |
63 | ||
64 | return *this; | |
65 | } | |
66 | ||
67 | const RowData* Annotation::row_data() const | |
68 | { | |
69 | return data_; | |
70 | } | |
71 | ||
72 | const Row* Annotation::row() const | |
73 | { | |
74 | return data_->row(); | |
75 | } | |
76 | ||
77 | uint64_t Annotation::start_sample() const | |
78 | { | |
79 | return start_sample_; | |
80 | } | |
81 | ||
82 | uint64_t Annotation::end_sample() const | |
83 | { | |
84 | return end_sample_; | |
85 | } | |
86 | ||
87 | uint64_t Annotation::length() const | |
88 | { | |
89 | return end_sample_ - start_sample_; | |
90 | } | |
91 | ||
92 | uint32_t Annotation::ann_class_id() const | |
93 | { | |
94 | return ann_class_id_; | |
95 | } | |
96 | ||
97 | const QString Annotation::ann_class_name() const | |
98 | { | |
99 | const AnnotationClass* ann_class = | |
100 | data_->row()->decoder()->get_ann_class_by_id(ann_class_id_); | |
101 | ||
102 | return QString(ann_class->name); | |
103 | } | |
104 | ||
105 | const 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 | ||
113 | const vector<QString>* Annotation::annotations() const | |
114 | { | |
115 | return texts_; | |
116 | } | |
117 | ||
118 | const QString Annotation::longest_annotation() const | |
119 | { | |
120 | return texts_->front(); | |
121 | } | |
122 | ||
123 | bool Annotation::visible() const | |
124 | { | |
125 | const Row* row = data_->row(); | |
126 | ||
127 | return (row->visible() && row->class_is_visible(ann_class_id_) | |
128 | && row->decoder()->visible()); | |
129 | } | |
130 | ||
131 | const QColor Annotation::color() const | |
132 | { | |
133 | return data_->row()->get_class_color(ann_class_id_); | |
134 | } | |
135 | ||
136 | const QColor Annotation::bright_color() const | |
137 | { | |
138 | return data_->row()->get_bright_class_color(ann_class_id_); | |
139 | } | |
140 | ||
141 | const QColor Annotation::dark_color() const | |
142 | { | |
143 | return data_->row()->get_dark_class_color(ann_class_id_); | |
144 | } | |
145 | ||
146 | bool Annotation::operator<(const Annotation &other) const | |
147 | { | |
148 | return (start_sample_ < other.start_sample_); | |
149 | } | |
150 | ||
151 | } // namespace decode | |
152 | } // namespace data | |
153 | } // namespace pv |