]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/view.hpp
Append "-git" to the version string.
[pulseview.git] / pv / view / view.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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef PULSEVIEW_PV_VIEW_VIEW_HPP
22#define PULSEVIEW_PV_VIEW_VIEW_HPP
23
24#include <stdint.h>
25
26#include <list>
27#include <memory>
28#include <set>
29#include <unordered_map>
30#include <vector>
31
32#include <QAbstractScrollArea>
33#include <QSizeF>
34#include <QTimer>
35
36#include <pv/data/signaldata.hpp>
37
38#include "cursorpair.hpp"
39#include "flag.hpp"
40#include "rowitemowner.hpp"
41
42namespace sigrok {
43class ChannelGroup;
44}
45
46namespace pv {
47
48class Session;
49
50namespace view {
51
52class CursorHeader;
53class Header;
54class Ruler;
55class Trace;
56class Viewport;
57
58class View : public QAbstractScrollArea, public RowItemOwner {
59 Q_OBJECT
60
61private:
62 enum StickyEvents {
63 RowItemHExtentsChanged = 1,
64 RowItemVExtentsChanged = 2
65 };
66
67private:
68 static const double MaxScale;
69 static const double MinScale;
70
71 static const int MaxScrollValue;
72
73 static const int ScaleUnits[3];
74
75public:
76 explicit View(Session &session, QWidget *parent = 0);
77
78 Session& session();
79 const Session& session() const;
80
81 /**
82 * Returns the view of the owner.
83 */
84 virtual pv::view::View* view();
85
86 /**
87 * Returns the view of the owner.
88 */
89 virtual const pv::view::View* view() const;
90
91 Viewport* viewport();
92
93 const Viewport* viewport() const;
94
95 /**
96 * Gets a list of time markers.
97 */
98 std::vector< std::shared_ptr<TimeItem> > time_items() const;
99
100 /**
101 * Returns the view time scale in seconds per pixel.
102 */
103 double scale() const;
104
105 /**
106 * Returns the time offset of the left edge of the view in
107 * seconds.
108 */
109 double offset() const;
110
111 /**
112 * Returns the vertical scroll offset.
113 */
114 int owner_visual_v_offset() const;
115
116 /**
117 * Sets the visual v-offset.
118 */
119 void set_v_offset(int offset);
120
121 /**
122 * Returns the SI prefix to apply to the graticule time markings.
123 */
124 unsigned int tick_prefix() const;
125
126 /**
127 * Returns period of the graticule time markings.
128 */
129 double tick_period() const;
130
131 /**
132 * Returns the number of nested parents that this row item owner has.
133 */
134 unsigned int depth() const;
135
136 void zoom(double steps);
137 void zoom(double steps, int offset);
138
139 void zoom_fit();
140
141 void zoom_one_to_one();
142
143 /**
144 * Sets the scale and offset.
145 * @param scale The new view scale in seconds per pixel.
146 * @param offset The view time offset in seconds.
147 */
148 void set_scale_offset(double scale, double offset);
149
150 std::set< std::shared_ptr<pv::data::SignalData> >
151 get_visible_data() const;
152
153 std::pair<double, double> get_time_extents() const;
154
155 /**
156 * Returns true if cursors are displayed. false otherwise.
157 */
158 bool cursors_shown() const;
159
160 /**
161 * Shows or hides the cursors.
162 */
163 void show_cursors(bool show = true);
164
165 /**
166 * Moves the cursors to a convenient position in the view.
167 */
168 void centre_cursors();
169
170 /**
171 * Returns a reference to the pair of cursors.
172 */
173 std::shared_ptr<CursorPair> cursors() const;
174
175 /**
176 * Adds a new flag at a specified time.
177 */
178 void add_flag(double time);
179
180 /**
181 * Removes a flag from the list.
182 */
183 void remove_flag(std::shared_ptr<Flag> flag);
184
185 /**
186 * Gets the list of flags.
187 */
188 std::vector< std::shared_ptr<Flag> > flags() const;
189
190 const QPoint& hover_point() const;
191
192 void update_viewport();
193
194 void restack_all_row_items();
195
196Q_SIGNALS:
197 void hover_point_changed();
198
199 void selection_changed();
200
201 void scale_offset_changed();
202
203private:
204 void get_scroll_layout(double &length, double &offset) const;
205
206 /**
207 * Simultaneously sets the zoom and offset.
208 * @param scale The scale to set the view to in seconds per pixel. This
209 * value is clamped between MinScale and MaxScale.
210 * @param offset The offset of the left edge of the view in seconds.
211 */
212 void set_zoom(double scale, int offset);
213
214 /**
215 * Find a tick spacing and number formatting that does not cause
216 * the values to collide.
217 */
218 void calculate_tick_spacing();
219
220 void update_scroll();
221
222 void update_layout();
223
224 /**
225 * Satisifies RowItem functionality.
226 * @param p the QPainter to paint into.
227 * @param rect the rectangle of the header area.
228 * @param hover true if the label is being hovered over by the mouse.
229 */
230 void paint_label(QPainter &p, const QRect &rect, bool hover);
231
232 /**
233 * Computes the outline rectangle of a label.
234 * @param rect the rectangle of the header area.
235 * @return Returns the rectangle of the signal label.
236 */
237 QRectF label_rect(const QRectF &rect);
238
239 RowItemOwner* find_prevalent_trace_group(
240 const std::shared_ptr<sigrok::ChannelGroup> &group,
241 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
242 std::shared_ptr<Signal> > &signal_map);
243
244 static std::vector< std::shared_ptr<Trace> >
245 extract_new_traces_for_channels(
246 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
247 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
248 std::shared_ptr<Signal> > &signal_map,
249 std::set< std::shared_ptr<Trace> > &add_list);
250
251private:
252 bool eventFilter(QObject *object, QEvent *event);
253
254 bool viewportEvent(QEvent *e);
255
256 void resizeEvent(QResizeEvent *e);
257
258public:
259 void row_item_appearance_changed(bool label, bool content);
260 void time_item_appearance_changed(bool label, bool content);
261
262 void extents_changed(bool horz, bool vert);
263
264private Q_SLOTS:
265
266 void h_scroll_value_changed(int value);
267 void v_scroll_value_changed();
268
269 void signals_changed();
270 void data_updated();
271
272 void process_sticky_events();
273
274 void on_hover_point_changed();
275
276private:
277 Session &session_;
278
279 Viewport *viewport_;
280 Ruler *ruler_;
281 Header *header_;
282
283 /// The view time scale in seconds per pixel.
284 double scale_;
285
286 /// The view time offset in seconds.
287 double offset_;
288
289 bool updating_scroll_;
290
291 double tick_period_;
292 unsigned int tick_prefix_;
293
294 bool show_cursors_;
295 std::shared_ptr<CursorPair> cursors_;
296
297 std::list< std::shared_ptr<Flag> > flags_;
298 char next_flag_text_;
299
300 QPoint hover_point_;
301
302 unsigned int sticky_events_;
303 QTimer lazy_event_handler_;
304};
305
306} // namespace view
307} // namespace pv
308
309#endif // PULSEVIEW_PV_VIEW_VIEW_HPP