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