]> sigrok.org Git - pulseview.git/blame - pv/view/view.h
Refactoring in View and SigSession
[pulseview.git] / pv / view / view.h
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
640d091b
UH
21#ifndef PULSEVIEW_PV_VIEW_VIEW_H
22#define PULSEVIEW_PV_VIEW_VIEW_H
adb4b10c
JH
23
24#include <stdint.h>
25
1bc6525b 26#include <set>
38eeddea
JH
27#include <vector>
28
29#include <boost/shared_ptr.hpp>
94936133
JH
30#include <boost/weak_ptr.hpp>
31
adb4b10c 32#include <QAbstractScrollArea>
2e04f9bd 33#include <QSizeF>
adb4b10c 34
1bc6525b
JH
35#include <pv/data/signaldata.h>
36
b42d25c4 37#include "cursorpair.h"
f76af637 38
51e77110
JH
39namespace pv {
40
adb4b10c 41class SigSession;
adb4b10c 42
cdf7bea7
JH
43namespace view {
44
1d8dca91 45class Header;
ccdd3ef5 46class Ruler;
38eeddea 47class Trace;
cdf7bea7
JH
48class Viewport;
49
50class View : public QAbstractScrollArea {
adb4b10c
JH
51 Q_OBJECT
52
53private:
54 static const double MaxScale;
55 static const double MinScale;
56
f25770e2
JH
57 static const int MaxScrollValue;
58
1d8dca91
JH
59public:
60 static const int SignalHeight;
8d44d030 61 static const int SignalMargin;
49153683 62 static const int SignalSnapGridSize;
1d8dca91 63
f76af637
JH
64 static const QColor CursorAreaColour;
65
2e04f9bd
JH
66 static const QSizeF LabelPadding;
67
adb4b10c 68public:
cdf7bea7 69 explicit View(SigSession &session, QWidget *parent = 0);
adb4b10c 70
1d19ef83 71 SigSession& session();
38eeddea 72 const SigSession& session() const;
1d19ef83 73
e2f5223b
JH
74 /**
75 * Returns the view time scale in seconds per pixel.
76 */
adb4b10c 77 double scale() const;
e2f5223b
JH
78
79 /**
80 * Returns the time offset of the left edge of the view in
81 * seconds.
82 */
adb4b10c
JH
83 double offset() const;
84 int v_offset() const;
85
86 void zoom(double steps);
17c0f398 87 void zoom(double steps, int offset);
adb4b10c 88
ca46b534
JH
89 void zoom_fit();
90
d1e7d82c
JH
91 void zoom_one_to_one();
92
e2f5223b
JH
93 /**
94 * Sets the scale and offset.
95 * @param scale The new view scale in seconds per pixel.
96 * @param offset The view time offset in seconds.
97 */
adb4b10c
JH
98 void set_scale_offset(double scale, double offset);
99
38eeddea
JH
100 std::vector< boost::shared_ptr<Trace> > get_traces() const;
101
94936133
JH
102 std::list<boost::weak_ptr<SelectableItem> > selected_items() const;
103
1bc6525b
JH
104 std::set< boost::shared_ptr<pv::data::SignalData> >
105 get_visible_data() const;
106
107 std::pair<double, double> get_time_extents() const;
108
f76af637
JH
109 /**
110 * Returns true if cursors are displayed. false otherwise.
111 */
112 bool cursors_shown() const;
113
114 /**
115 * Shows or hides the cursors.
116 */
117 void show_cursors(bool show = true);
118
b4d91e56
JH
119 /**
120 * Moves the cursors to a convenient position in the view.
121 */
122 void centre_cursors();
123
f76af637
JH
124 /**
125 * Returns a reference to the pair of cursors.
126 */
b42d25c4 127 CursorPair& cursors();
f76af637 128
58864c5c
JH
129 /**
130 * Returns a reference to the pair of cursors.
131 */
132 const CursorPair& cursors() const;
133
cbd80f64
JH
134 const QPoint& hover_point() const;
135
4b192962
JH
136 void normalize_layout();
137
9cef9567
JH
138 void update_viewport();
139
cbd80f64
JH
140signals:
141 void hover_point_changed();
142
07204819
JH
143 void signals_moved();
144
8b454527
JH
145 void selection_changed();
146
e0fc5810
JH
147 void scale_offset_changed();
148
adb4b10c 149private:
f25770e2
JH
150 void get_scroll_layout(double &length, double &offset) const;
151
d1e7d82c
JH
152 void set_zoom(double scale, int offset);
153
adb4b10c
JH
154 void update_scroll();
155
d7c0ca4a
JH
156 void update_layout();
157
38eeddea
JH
158 static bool compare_trace_v_offsets(
159 const boost::shared_ptr<pv::view::Trace> &a,
160 const boost::shared_ptr<pv::view::Trace> &b);
161
adb4b10c 162private:
cbd80f64
JH
163 bool eventFilter(QObject *object, QEvent *event);
164
adb4b10c
JH
165 bool viewportEvent(QEvent *e);
166
167 void resizeEvent(QResizeEvent *e);
168
169private slots:
cbd80f64 170
b16907d3 171 void h_scroll_value_changed(int value);
adb4b10c
JH
172 void v_scroll_value_changed(int value);
173
69dd2b03 174 void signals_changed();
adb4b10c
JH
175 void data_updated();
176
ca4ec3ea
JH
177 void marker_time_changed();
178
07204819 179 void on_signals_moved();
54401bbb 180
d7c0ca4a
JH
181 void on_geometry_updated();
182
adb4b10c
JH
183private:
184 SigSession &_session;
185
cdf7bea7 186 Viewport *_viewport;
ccdd3ef5 187 Ruler *_ruler;
1d8dca91 188 Header *_header;
adb4b10c 189
e2f5223b 190 /// The view time scale in seconds per pixel.
adb4b10c 191 double _scale;
e2f5223b
JH
192
193 /// The view time offset in seconds.
adb4b10c
JH
194 double _offset;
195
196 int _v_offset;
528bd8a1 197 bool _updating_scroll;
cbd80f64 198
f76af637 199 bool _show_cursors;
b42d25c4 200 CursorPair _cursors;
f76af637 201
cbd80f64 202 QPoint _hover_point;
adb4b10c
JH
203};
204
cdf7bea7
JH
205} // namespace view
206} // namespace pv
207
640d091b 208#endif // PULSEVIEW_PV_VIEW_VIEW_H