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