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