]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/view.hpp
Revert "Make traces only selectable in the header area"
[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#include <pv/util.hpp>
38
39#include "cursorpair.hpp"
40#include "flag.hpp"
41#include "tracetreeitemowner.hpp"
42
43namespace sigrok {
44class ChannelGroup;
45}
46
47namespace pv {
48
49class Session;
50
51namespace view {
52
53class CursorHeader;
54class Header;
55class Ruler;
56class Trace;
57class Viewport;
58class TriggerMarker;
59
60class View : public QAbstractScrollArea, public TraceTreeItemOwner {
61 Q_OBJECT
62
63private:
64 enum StickyEvents {
65 TraceTreeItemHExtentsChanged = 1,
66 TraceTreeItemVExtentsChanged = 2
67 };
68
69private:
70 static const pv::util::Timestamp MaxScale;
71 static const pv::util::Timestamp MinScale;
72
73 static const int MaxScrollValue;
74 static const int MaxViewAutoUpdateRate;
75
76 static const int ScaleUnits[3];
77
78public:
79 explicit View(Session &session, QWidget *parent = 0);
80
81 Session& session();
82 const Session& session() const;
83
84 /**
85 * Returns the view of the owner.
86 */
87 virtual pv::view::View* view();
88
89 /**
90 * Returns the view of the owner.
91 */
92 virtual const pv::view::View* view() const;
93
94 Viewport* viewport();
95
96 const Viewport* viewport() const;
97
98 const QSize header_size() const;
99
100 /**
101 * Gets a list of time markers.
102 */
103 std::vector< std::shared_ptr<TimeItem> > time_items() const;
104
105 /**
106 * Returns the view time scale in seconds per pixel.
107 */
108 double scale() const;
109
110 /**
111 * Returns the time offset of the left edge of the view in
112 * seconds.
113 */
114 const pv::util::Timestamp& offset() const;
115
116 /**
117 * Returns the vertical scroll offset.
118 */
119 int owner_visual_v_offset() const;
120
121 /**
122 * Sets the visual v-offset.
123 */
124 void set_v_offset(int offset);
125
126 /**
127 * Returns the SI prefix to apply to the graticule time markings.
128 */
129 pv::util::SIPrefix tick_prefix() const;
130
131 /**
132 * Returns the number of fractional digits shown for the time markings.
133 */
134 unsigned int tick_precision() const;
135
136 /**
137 * Returns period of the graticule time markings.
138 */
139 const pv::util::Timestamp& tick_period() const;
140
141 /**
142 * Returns the unit of time currently used.
143 */
144 util::TimeUnit time_unit() const;
145
146 /**
147 * Returns the number of nested parents that this row item owner has.
148 */
149 unsigned int depth() const;
150
151 void zoom(double steps);
152 void zoom(double steps, int offset);
153
154 void zoom_fit(bool gui_state);
155
156 void zoom_one_to_one();
157
158 /**
159 * Sets the scale and offset.
160 * @param scale The new view scale in seconds per pixel.
161 * @param offset The view time offset in seconds.
162 */
163 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
164
165 std::set< std::shared_ptr<pv::data::SignalData> >
166 get_visible_data() const;
167
168 std::pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
169
170 /**
171 * Enables or disables sticky scrolling, i.e. the view always shows
172 * the most recent samples when capturing data.
173 */
174 void enable_sticky_scrolling(bool state);
175
176 /**
177 * Enables or disables coloured trace backgrounds. If they're not
178 * coloured then they will use alternating colors.
179 */
180 void enable_coloured_bg(bool state);
181
182 /**
183 * Returns true if cursors are displayed. false otherwise.
184 */
185 bool cursors_shown() const;
186
187 /**
188 * Shows or hides the cursors.
189 */
190 void show_cursors(bool show = true);
191
192 /**
193 * Moves the cursors to a convenient position in the view.
194 */
195 void centre_cursors();
196
197 /**
198 * Returns a reference to the pair of cursors.
199 */
200 std::shared_ptr<CursorPair> cursors() const;
201
202 /**
203 * Adds a new flag at a specified time.
204 */
205 void add_flag(const pv::util::Timestamp& time);
206
207 /**
208 * Removes a flag from the list.
209 */
210 void remove_flag(std::shared_ptr<Flag> flag);
211
212 /**
213 * Gets the list of flags.
214 */
215 std::vector< std::shared_ptr<Flag> > flags() const;
216
217 const QPoint& hover_point() const;
218
219 void update_viewport();
220
221 void restack_all_trace_tree_items();
222
223Q_SIGNALS:
224 void hover_point_changed();
225
226 void selection_changed();
227
228 /// Emitted when the offset changed.
229 void offset_changed();
230
231 /// Emitted when the scale changed.
232 void scale_changed();
233
234 void sticky_scrolling_changed(bool state);
235
236 void always_zoom_to_fit_changed(bool state);
237
238 /// Emitted when the tick_prefix changed.
239 void tick_prefix_changed();
240
241 /// Emitted when the tick_precision changed.
242 void tick_precision_changed();
243
244 /// Emitted when the tick_period changed.
245 void tick_period_changed();
246
247 /// Emitted when the time_unit changed.
248 void time_unit_changed();
249
250public Q_SLOTS:
251 void trigger_event(util::Timestamp location);
252
253private:
254 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
255
256 /**
257 * Simultaneously sets the zoom and offset.
258 * @param scale The scale to set the view to in seconds per pixel. This
259 * value is clamped between MinScale and MaxScale.
260 * @param offset The offset of the left edge of the view in seconds.
261 */
262 void set_zoom(double scale, int offset);
263
264 /**
265 * Find a tick spacing and number formatting that does not cause
266 * the values to collide.
267 */
268 void calculate_tick_spacing();
269
270 void update_scroll();
271
272 void update_layout();
273
274 /**
275 * Satisifies TraceTreeItem functionality.
276 * @param p the QPainter to paint into.
277 * @param rect the rectangle of the header area.
278 * @param hover true if the label is being hovered over by the mouse.
279 */
280 void paint_label(QPainter &p, const QRect &rect, bool hover);
281
282 /**
283 * Computes the outline rectangle of a label.
284 * @param rect the rectangle of the header area.
285 * @return Returns the rectangle of the signal label.
286 */
287 QRectF label_rect(const QRectF &rect);
288
289 TraceTreeItemOwner* find_prevalent_trace_group(
290 const std::shared_ptr<sigrok::ChannelGroup> &group,
291 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
292 std::shared_ptr<Signal> > &signal_map);
293
294 static std::vector< std::shared_ptr<Trace> >
295 extract_new_traces_for_channels(
296 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
297 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
298 std::shared_ptr<Signal> > &signal_map,
299 std::set< std::shared_ptr<Trace> > &add_list);
300
301 void determine_time_unit();
302
303 bool eventFilter(QObject *object, QEvent *event);
304
305 bool viewportEvent(QEvent *e);
306
307 void resizeEvent(QResizeEvent *e);
308
309public:
310 void row_item_appearance_changed(bool label, bool content);
311 void time_item_appearance_changed(bool label, bool content);
312
313 void extents_changed(bool horz, bool vert);
314
315private Q_SLOTS:
316
317 void h_scroll_value_changed(int value);
318 void v_scroll_value_changed();
319
320 void signals_changed();
321 void capture_state_updated(int state);
322 void data_updated();
323
324 void perform_delayed_view_update();
325
326 void process_sticky_events();
327
328 void on_hover_point_changed();
329
330 /**
331 * Sets the 'offset_' member and emits the 'offset_changed'
332 * signal if needed.
333 */
334 void set_offset(const pv::util::Timestamp& offset);
335
336 /**
337 * Sets the 'scale_' member and emits the 'scale_changed'
338 * signal if needed.
339 */
340 void set_scale(double scale);
341
342 /**
343 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
344 * signal if needed.
345 */
346 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
347
348 /**
349 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
350 * signal if needed.
351 */
352 void set_tick_precision(unsigned tick_precision);
353
354 /**
355 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
356 * signal if needed.
357 */
358 void set_tick_period(const pv::util::Timestamp& tick_period);
359
360 /**
361 * Sets the 'time_unit' member and emits the 'time_unit_changed'
362 * signal if needed.
363 */
364 void set_time_unit(pv::util::TimeUnit time_unit);
365
366private:
367 Session &session_;
368
369 Viewport *viewport_;
370 Ruler *ruler_;
371 Header *header_;
372
373 /// The view time scale in seconds per pixel.
374 double scale_;
375
376 /// The view time offset in seconds.
377 pv::util::Timestamp offset_;
378
379 bool updating_scroll_;
380 bool sticky_scrolling_;
381 bool always_zoom_to_fit_;
382 QTimer delayed_view_updater_;
383
384 pv::util::Timestamp tick_period_;
385 pv::util::SIPrefix tick_prefix_;
386 unsigned int tick_precision_;
387 util::TimeUnit time_unit_;
388
389 bool show_cursors_;
390 std::shared_ptr<CursorPair> cursors_;
391
392 std::list< std::shared_ptr<Flag> > flags_;
393 char next_flag_text_;
394
395 std::vector< std::shared_ptr<TriggerMarker> > trigger_markers_;
396
397 QPoint hover_point_;
398
399 unsigned int sticky_events_;
400 QTimer lazy_event_handler_;
401};
402
403} // namespace view
404} // namespace pv
405
406#endif // PULSEVIEW_PV_VIEW_VIEW_HPP