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