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