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