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