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