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