]> sigrok.org Git - pulseview.git/blame - pv/view/view.hpp
Fix #602 by keeping track of device state internally
[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>
1bc6525b 37
2acdb232 38#include "cursorpair.hpp"
8914fe79 39#include "flag.hpp"
2acdb232 40#include "rowitemowner.hpp"
f76af637 41
cf124e47
JH
42namespace sigrok {
43class ChannelGroup;
44}
45
51e77110
JH
46namespace pv {
47
2b81ae46 48class Session;
adb4b10c 49
cdf7bea7
JH
50namespace view {
51
84a0d458 52class CursorHeader;
1d8dca91 53class Header;
ccdd3ef5 54class Ruler;
cf124e47 55class Trace;
cdf7bea7
JH
56class Viewport;
57
eae6e30a 58class View : public QAbstractScrollArea, public RowItemOwner {
adb4b10c
JH
59 Q_OBJECT
60
32218d3e
JH
61private:
62 enum StickyEvents {
76fea660
JH
63 RowItemHExtentsChanged = 1,
64 RowItemVExtentsChanged = 2
32218d3e
JH
65 };
66
adb4b10c
JH
67private:
68 static const double MaxScale;
69 static const double MinScale;
70
f25770e2
JH
71 static const int MaxScrollValue;
72
361c560e
JH
73 static const int ScaleUnits[3];
74
adb4b10c 75public:
2b81ae46 76 explicit View(Session &session, QWidget *parent = 0);
adb4b10c 77
2b81ae46
JH
78 Session& session();
79 const Session& session() const;
1d19ef83 80
eae6e30a
JH
81 /**
82 * Returns the view of the owner.
83 */
84 virtual pv::view::View* view();
85
86 /**
87 * Returns the view of the owner.
88 */
89 virtual const pv::view::View* view() const;
90
2ae445ba
SA
91 Viewport* viewport();
92
93 const Viewport* viewport() const;
94
2496bf45
JH
95 /**
96 * Gets a list of time markers.
97 */
98 std::vector< std::shared_ptr<TimeItem> > time_items() const;
99
e2f5223b
JH
100 /**
101 * Returns the view time scale in seconds per pixel.
102 */
adb4b10c 103 double scale() const;
e2f5223b
JH
104
105 /**
106 * Returns the time offset of the left edge of the view in
107 * seconds.
108 */
adb4b10c 109 double offset() const;
f8400017
JH
110
111 /**
112 * Returns the vertical scroll offset.
113 */
7ff0145f 114 int owner_visual_v_offset() const;
adb4b10c 115
4d476647
JH
116 /**
117 * Sets the visual v-offset.
118 */
119 void set_v_offset(int offset);
120
361c560e
JH
121 /**
122 * Returns the SI prefix to apply to the graticule time markings.
123 */
124 unsigned int tick_prefix() const;
125
126 /**
127 * Returns period of the graticule time markings.
128 */
129 double tick_period() const;
130
3e769a37
JH
131 /**
132 * Returns the number of nested parents that this row item owner has.
133 */
134 unsigned int depth() const;
135
adb4b10c 136 void zoom(double steps);
17c0f398 137 void zoom(double steps, int offset);
adb4b10c 138
ca46b534
JH
139 void zoom_fit();
140
d1e7d82c
JH
141 void zoom_one_to_one();
142
e2f5223b
JH
143 /**
144 * Sets the scale and offset.
145 * @param scale The new view scale in seconds per pixel.
146 * @param offset The view time offset in seconds.
147 */
adb4b10c
JH
148 void set_scale_offset(double scale, double offset);
149
f9abf97e 150 std::set< std::shared_ptr<pv::data::SignalData> >
1bc6525b
JH
151 get_visible_data() const;
152
153 std::pair<double, double> get_time_extents() const;
154
f76af637
JH
155 /**
156 * Returns true if cursors are displayed. false otherwise.
157 */
158 bool cursors_shown() const;
159
160 /**
161 * Shows or hides the cursors.
162 */
163 void show_cursors(bool show = true);
164
b4d91e56
JH
165 /**
166 * Moves the cursors to a convenient position in the view.
167 */
168 void centre_cursors();
169
f76af637
JH
170 /**
171 * Returns a reference to the pair of cursors.
172 */
5c5ce757 173 std::shared_ptr<CursorPair> cursors() const;
58864c5c 174
8914fe79
JH
175 /**
176 * Adds a new flag at a specified time.
177 */
178 void add_flag(double time);
179
180 /**
181 * Removes a flag from the list.
182 */
183 void remove_flag(std::shared_ptr<Flag> flag);
184
185 /**
186 * Gets the list of flags.
187 */
188 std::vector< std::shared_ptr<Flag> > flags() const;
189
cbd80f64
JH
190 const QPoint& hover_point() const;
191
9cef9567 192 void update_viewport();
7ff0145f
JH
193
194 void restack_all_row_items();
9cef9567 195
e9213170 196Q_SIGNALS:
cbd80f64
JH
197 void hover_point_changed();
198
8b454527
JH
199 void selection_changed();
200
e0fc5810
JH
201 void scale_offset_changed();
202
adb4b10c 203private:
f25770e2 204 void get_scroll_layout(double &length, double &offset) const;
3925091a
JH
205
206 /**
207 * Simultaneously sets the zoom and offset.
208 * @param scale The scale to set the view to in seconds per pixel. This
209 * value is clamped between MinScale and MaxScale.
210 * @param offset The offset of the left edge of the view in seconds.
211 */
d1e7d82c
JH
212 void set_zoom(double scale, int offset);
213
361c560e
JH
214 /**
215 * Find a tick spacing and number formatting that does not cause
216 * the values to collide.
217 */
218 void calculate_tick_spacing();
219
adb4b10c
JH
220 void update_scroll();
221
d7c0ca4a
JH
222 void update_layout();
223
eae6e30a
JH
224 /**
225 * Satisifies RowItem functionality.
226 * @param p the QPainter to paint into.
b3f44329 227 * @param rect the rectangle of the header area.
eae6e30a
JH
228 * @param hover true if the label is being hovered over by the mouse.
229 */
b3f44329 230 void paint_label(QPainter &p, const QRect &rect, bool hover);
eae6e30a
JH
231
232 /**
233 * Computes the outline rectangle of a label.
b3f44329 234 * @param rect the rectangle of the header area.
eae6e30a
JH
235 * @return Returns the rectangle of the signal label.
236 */
b3f44329 237 QRectF label_rect(const QRectF &rect);
eae6e30a 238
cf124e47
JH
239 RowItemOwner* find_prevalent_trace_group(
240 const std::shared_ptr<sigrok::ChannelGroup> &group,
241 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
242 std::shared_ptr<Signal> > &signal_map);
243
244 static std::vector< std::shared_ptr<Trace> >
245 extract_new_traces_for_channels(
448a72cf 246 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
cf124e47 247 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
448a72cf 248 std::shared_ptr<Signal> > &signal_map,
cf124e47 249 std::set< std::shared_ptr<Trace> > &add_list);
448a72cf 250
adb4b10c 251private:
cbd80f64
JH
252 bool eventFilter(QObject *object, QEvent *event);
253
adb4b10c
JH
254 bool viewportEvent(QEvent *e);
255
256 void resizeEvent(QResizeEvent *e);
257
32218d3e 258public:
6e2c3c85 259 void row_item_appearance_changed(bool label, bool content);
98cfe4e8 260 void time_item_appearance_changed(bool label, bool content);
32218d3e
JH
261
262 void extents_changed(bool horz, bool vert);
263
e9213170 264private Q_SLOTS:
cbd80f64 265
b16907d3 266 void h_scroll_value_changed(int value);
f8400017 267 void v_scroll_value_changed();
adb4b10c 268
69dd2b03 269 void signals_changed();
adb4b10c
JH
270 void data_updated();
271
32218d3e 272 void process_sticky_events();
d7c0ca4a 273
33c62f44
JH
274 void on_hover_point_changed();
275
adb4b10c 276private:
2b81ae46 277 Session &session_;
adb4b10c 278
8dbbc7f0
JH
279 Viewport *viewport_;
280 Ruler *ruler_;
8dbbc7f0 281 Header *header_;
adb4b10c 282
e2f5223b 283 /// The view time scale in seconds per pixel.
8dbbc7f0 284 double scale_;
e2f5223b
JH
285
286 /// The view time offset in seconds.
8dbbc7f0 287 double offset_;
adb4b10c 288
8dbbc7f0 289 bool updating_scroll_;
cbd80f64 290
361c560e
JH
291 double tick_period_;
292 unsigned int tick_prefix_;
293
8dbbc7f0 294 bool show_cursors_;
5c5ce757 295 std::shared_ptr<CursorPair> cursors_;
f76af637 296
8914fe79
JH
297 std::list< std::shared_ptr<Flag> > flags_;
298 char next_flag_text_;
299
8dbbc7f0 300 QPoint hover_point_;
32218d3e 301
8dbbc7f0
JH
302 unsigned int sticky_events_;
303 QTimer lazy_event_handler_;
adb4b10c
JH
304};
305
cdf7bea7
JH
306} // namespace view
307} // namespace pv
308
7a01bd36 309#endif // PULSEVIEW_PV_VIEW_VIEW_HPP