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