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