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