]> sigrok.org Git - pulseview.git/blame - pv/views/trace/decodetrace.hpp
Introduce DecodeSignal class
[pulseview.git] / pv / views / trace / decodetrace.hpp
CommitLineData
55d3603d
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/>.
55d3603d
JH
18 */
19
f4e57597
SA
20#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
21#define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
55d3603d 22
2acdb232 23#include "trace.hpp"
55d3603d 24
7491a29f 25#include <list>
4e5a4405 26#include <map>
f9abf97e 27#include <memory>
50631798 28#include <vector>
4e5a4405 29
613d097c
JH
30#include <QSignalMapper>
31
3cc9ad7b 32#include <pv/binding/decoder.hpp>
2acdb232 33#include <pv/data/decode/row.hpp>
aca9aa83 34#include <pv/data/signalbase.hpp>
4e5a4405 35
6f925ba9
UH
36using std::list;
37using std::map;
38using std::pair;
39using std::shared_ptr;
40using std::vector;
41
8bd26d8b 42struct srd_channel;
e563a7c0 43struct srd_decoder;
4e5a4405
JH
44
45class QComboBox;
46
55d3603d 47namespace pv {
119aff65 48
2b81ae46 49class Session;
83c23cc9 50
119aff65 51namespace data {
6e89374a 52class DecoderStack;
bb7dd726 53class SignalBase;
ad908057 54class DecodeSignal;
7491a29f
JH
55
56namespace decode {
06e810f2 57class Annotation;
7491a29f 58class Decoder;
287d607f 59class Row;
7491a29f 60}
119aff65
JH
61}
62
dd048a7e
JH
63namespace widgets {
64class DecoderGroupBox;
65}
66
f4e57597 67namespace views {
1573bf16 68namespace trace {
55d3603d 69
b9329558 70class DecodeTrace : public Trace
55d3603d 71{
e0fc5810
JH
72 Q_OBJECT
73
7491a29f 74private:
6ac6242b 75 struct ChannelSelector
7491a29f 76 {
8dbbc7f0 77 const QComboBox *combo_;
407c9ebe 78 const QComboBox *combo_initial_pin_;
6f925ba9 79 const shared_ptr<pv::data::decode::Decoder> decoder_;
8dbbc7f0 80 const srd_channel *pdch_;
7491a29f
JH
81 };
82
06bb4e6a
JH
83private:
84 static const QColor DecodeColours[4];
ad50ac1a 85 static const QColor ErrorBgColour;
5dfeb70f 86 static const QColor NoDecodeColour;
06bb4e6a 87
88908838 88 static const int ArrowSize;
06e810f2 89 static const double EndCapWidth;
aee9dcf3 90 static const int RowTitleMargin;
06e810f2
JH
91 static const int DrawPadding;
92
287d607f
JH
93 static const QColor Colours[16];
94 static const QColor OutlineColours[16];
06e810f2 95
55d3603d 96public:
6f925ba9 97 DecodeTrace(pv::Session &session, shared_ptr<data::SignalBase> signalbase,
6e89374a 98 int index);
55d3603d
JH
99
100 bool enabled() const;
101
6f925ba9 102 const shared_ptr<pv::data::DecoderStack>& decoder() const;
b6b267bb 103
6f925ba9 104 shared_ptr<data::SignalBase> base() const;
bb7dd726 105
a5d93c27
JH
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 */
6f925ba9 110 pair<int, int> v_extents() const;
a5d93c27 111
55d3603d 112 /**
fe08b6e8
JH
113 * Paints the background layer of the trace with a QPainter
114 * @param p the QPainter to paint into.
3eb29afd 115 * @param pp the painting parameters object to paint with..
223d0c37 116 */
60938e04 117 void paint_back(QPainter &p, ViewItemPaintParams &pp);
fe08b6e8
JH
118
119 /**
120 * Paints the mid-layer of the trace with a QPainter
55d3603d 121 * @param p the QPainter to paint into.
3eb29afd 122 * @param pp the painting parameters object to paint with.
223d0c37 123 */
60938e04 124 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
55d3603d 125
88908838
JH
126 /**
127 * Paints the foreground layer of the trace with a QPainter
128 * @param p the QPainter to paint into.
3eb29afd 129 * @param pp the painting parameters object to paint with.
223d0c37 130 */
60938e04 131 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
88908838 132
4e5a4405
JH
133 void populate_popup_form(QWidget *parent, QFormLayout *form);
134
c51482b3
JH
135 QMenu* create_context_menu(QWidget *parent);
136
5ed1adf5
JH
137 void delete_pressed();
138
ad50ac1a 139private:
6f925ba9 140 void draw_annotations(vector<pv::data::decode::Annotation> annotations,
50631798 141 QPainter &p, int h, const ViewItemPaintParams &pp, int y,
aee9dcf3 142 size_t base_colour, int row_title_width);
50631798 143
06e810f2 144 void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
520362f8 145 int h, const ViewItemPaintParams &pp, int y,
aee9dcf3 146 size_t base_colour, int row_title_width) const;
06e810f2 147
6f925ba9 148 void draw_annotation_block(vector<pv::data::decode::Annotation> annotations,
33707990 149 QPainter &p, int h, int y, size_t base_colour) const;
50631798 150
06e810f2 151 void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
f765c3db 152 int h, double x, int y) const;
06e810f2
JH
153
154 void draw_range(const pv::data::decode::Annotation &a, QPainter &p,
f765c3db 155 int h, double start, double end, int y, const ViewItemPaintParams &pp,
aee9dcf3 156 int row_title_width) const;
06e810f2 157
ad50ac1a 158 void draw_error(QPainter &p, const QString &message,
5b5fa4da 159 const ViewItemPaintParams &pp);
ad50ac1a 160
5dfeb70f 161 void draw_unresolved_period(QPainter &p, int h, int left,
7f8517f6
SA
162 int right) const;
163
6f925ba9 164 pair<double, double> get_pixels_offset_samples_per_pixel() const;
7f8517f6
SA
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 */
6f925ba9 173 pair<uint64_t, uint64_t> get_sample_range(int x_start, int x_end) const;
5dfeb70f 174
117cdea3 175 int get_row_at_point(const QPoint &point);
e2f90c50 176
117cdea3 177 const QString get_annotation_at_point(const QPoint &point);
e2f90c50 178
613d097c 179 void create_decoder_form(int index,
6f925ba9 180 shared_ptr<pv::data::decode::Decoder> &dec,
7491a29f
JH
181 QWidget *parent, QFormLayout *form);
182
6ac6242b 183 QComboBox* create_channel_selector(QWidget *parent,
6f925ba9 184 const shared_ptr<pv::data::decode::Decoder> &dec,
8bd26d8b 185 const srd_channel *const pdch);
7491a29f 186
407c9ebe
UH
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
c063290a 191 void commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec);
4e5a4405 192
6ac6242b 193 void commit_channels();
4e5a4405 194
33c62f44
JH
195public:
196 void hover_point_changed();
197
e9213170 198private Q_SLOTS:
ad908057 199 void on_new_annotations();
9cef9567 200
c51482b3
JH
201 void on_delete();
202
6ac6242b 203 void on_channel_selected(int);
4e5a4405 204
407c9ebe
UH
205 void on_initial_pin_selected(int);
206
7491a29f
JH
207 void on_stack_decoder(srd_decoder *decoder);
208
613d097c
JH
209 void on_delete_decoder(int index);
210
dd048a7e
JH
211 void on_show_hide_decoder(int index);
212
55d3603d 213private:
2b81ae46 214 pv::Session &session_;
ad908057 215 shared_ptr<data::DecodeSignal> decode_signal_;
e0fc5810 216
6f925ba9 217 vector<data::decode::Row> visible_rows_;
8dbbc7f0 218 uint64_t decode_start_, decode_end_;
4e5a4405 219
6f925ba9 220 list< shared_ptr<pv::binding::Decoder> > bindings_;
4e5a4405 221
6f925ba9
UH
222 list<ChannelSelector> channel_selectors_;
223 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
613d097c 224
6f925ba9 225 map<data::decode::Row, int> row_title_widths_;
eee89ff8 226 int row_height_, max_visible_rows_;
88908838 227
752281db
SA
228 int min_useful_label_width_;
229
8dbbc7f0 230 QSignalMapper delete_mapper_, show_hide_mapper_;
55d3603d
JH
231};
232
1573bf16 233} // namespace trace
f4e57597 234} // namespace views
55d3603d
JH
235} // namespace pv
236
f4e57597 237#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP