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