]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/trace/decodetrace.hpp
Introduce DecodeSignal class
[pulseview.git] / pv / views / trace / decodetrace.hpp
... / ...
CommitLineData
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#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
21#define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
22
23#include "trace.hpp"
24
25#include <list>
26#include <map>
27#include <memory>
28#include <vector>
29
30#include <QSignalMapper>
31
32#include <pv/binding/decoder.hpp>
33#include <pv/data/decode/row.hpp>
34#include <pv/data/signalbase.hpp>
35
36using std::list;
37using std::map;
38using std::pair;
39using std::shared_ptr;
40using std::vector;
41
42struct srd_channel;
43struct srd_decoder;
44
45class QComboBox;
46
47namespace pv {
48
49class Session;
50
51namespace data {
52class DecoderStack;
53class SignalBase;
54class DecodeSignal;
55
56namespace decode {
57class Annotation;
58class Decoder;
59class Row;
60}
61}
62
63namespace widgets {
64class DecoderGroupBox;
65}
66
67namespace views {
68namespace trace {
69
70class DecodeTrace : public Trace
71{
72 Q_OBJECT
73
74private:
75 struct ChannelSelector
76 {
77 const QComboBox *combo_;
78 const QComboBox *combo_initial_pin_;
79 const shared_ptr<pv::data::decode::Decoder> decoder_;
80 const srd_channel *pdch_;
81 };
82
83private:
84 static const QColor DecodeColours[4];
85 static const QColor ErrorBgColour;
86 static const QColor NoDecodeColour;
87
88 static const int ArrowSize;
89 static const double EndCapWidth;
90 static const int RowTitleMargin;
91 static const int DrawPadding;
92
93 static const QColor Colours[16];
94 static const QColor OutlineColours[16];
95
96public:
97 DecodeTrace(pv::Session &session, shared_ptr<data::SignalBase> signalbase,
98 int index);
99
100 bool enabled() const;
101
102 const shared_ptr<pv::data::DecoderStack>& decoder() const;
103
104 shared_ptr<data::SignalBase> base() const;
105
106 /**
107 * Computes the vertical extents of the contents of this row item.
108 * @return A pair containing the minimum and maximum y-values.
109 */
110 pair<int, int> v_extents() const;
111
112 /**
113 * Paints the background layer of the trace with a QPainter
114 * @param p the QPainter to paint into.
115 * @param pp the painting parameters object to paint with..
116 */
117 void paint_back(QPainter &p, ViewItemPaintParams &pp);
118
119 /**
120 * Paints the mid-layer of the trace with a QPainter
121 * @param p the QPainter to paint into.
122 * @param pp the painting parameters object to paint with.
123 */
124 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
125
126 /**
127 * Paints the foreground layer of the trace with a QPainter
128 * @param p the QPainter to paint into.
129 * @param pp the painting parameters object to paint with.
130 */
131 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
132
133 void populate_popup_form(QWidget *parent, QFormLayout *form);
134
135 QMenu* create_context_menu(QWidget *parent);
136
137 void delete_pressed();
138
139private:
140 void draw_annotations(vector<pv::data::decode::Annotation> annotations,
141 QPainter &p, int h, const ViewItemPaintParams &pp, int y,
142 size_t base_colour, int row_title_width);
143
144 void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
145 int h, const ViewItemPaintParams &pp, int y,
146 size_t base_colour, int row_title_width) const;
147
148 void draw_annotation_block(vector<pv::data::decode::Annotation> annotations,
149 QPainter &p, int h, int y, size_t base_colour) const;
150
151 void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
152 int h, double x, int y) const;
153
154 void draw_range(const pv::data::decode::Annotation &a, QPainter &p,
155 int h, double start, double end, int y, const ViewItemPaintParams &pp,
156 int row_title_width) const;
157
158 void draw_error(QPainter &p, const QString &message,
159 const ViewItemPaintParams &pp);
160
161 void draw_unresolved_period(QPainter &p, int h, int left,
162 int right) const;
163
164 pair<double, double> get_pixels_offset_samples_per_pixel() const;
165
166 /**
167 * Determines the start and end sample for a given pixel range.
168 * @param x_start the X coordinate of the start sample in the view
169 * @param x_end the X coordinate of the end sample in the view
170 * @return Returns a pair containing the start sample and the end
171 * sample that correspond to the start and end coordinates.
172 */
173 pair<uint64_t, uint64_t> get_sample_range(int x_start, int x_end) const;
174
175 int get_row_at_point(const QPoint &point);
176
177 const QString get_annotation_at_point(const QPoint &point);
178
179 void create_decoder_form(int index,
180 shared_ptr<pv::data::decode::Decoder> &dec,
181 QWidget *parent, QFormLayout *form);
182
183 QComboBox* create_channel_selector(QWidget *parent,
184 const shared_ptr<pv::data::decode::Decoder> &dec,
185 const srd_channel *const pdch);
186
187 QComboBox* create_channel_selector_initial_pin(QWidget *parent,
188 const shared_ptr<pv::data::decode::Decoder> &dec,
189 const srd_channel *const pdch);
190
191 void commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec);
192
193 void commit_channels();
194
195public:
196 void hover_point_changed();
197
198private Q_SLOTS:
199 void on_new_annotations();
200
201 void on_delete();
202
203 void on_channel_selected(int);
204
205 void on_initial_pin_selected(int);
206
207 void on_stack_decoder(srd_decoder *decoder);
208
209 void on_delete_decoder(int index);
210
211 void on_show_hide_decoder(int index);
212
213private:
214 pv::Session &session_;
215 shared_ptr<data::DecodeSignal> decode_signal_;
216
217 vector<data::decode::Row> visible_rows_;
218 uint64_t decode_start_, decode_end_;
219
220 list< shared_ptr<pv::binding::Decoder> > bindings_;
221
222 list<ChannelSelector> channel_selectors_;
223 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
224
225 map<data::decode::Row, int> row_title_widths_;
226 int row_height_, max_visible_rows_;
227
228 int min_useful_label_width_;
229
230 QSignalMapper delete_mapper_, show_hide_mapper_;
231};
232
233} // namespace trace
234} // namespace views
235} // namespace pv
236
237#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP