2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
21 #ifndef PULSEVIEW_PV_VIEW_VIEW_HPP
22 #define PULSEVIEW_PV_VIEW_VIEW_HPP
29 #include <unordered_map>
32 #include <QAbstractScrollArea>
36 #include <pv/data/signaldata.hpp>
38 #include "cursorpair.hpp"
40 #include "rowitemowner.hpp"
58 class View : public QAbstractScrollArea, public RowItemOwner {
63 RowItemHExtentsChanged = 1,
64 RowItemVExtentsChanged = 2
68 static const double MaxScale;
69 static const double MinScale;
71 static const int MaxScrollValue;
72 static const int MaxViewAutoUpdateRate;
74 static const int ScaleUnits[3];
77 explicit View(Session &session, QWidget *parent = 0);
80 const Session& session() const;
83 * Returns the view of the owner.
85 virtual pv::view::View* view();
88 * Returns the view of the owner.
90 virtual const pv::view::View* view() const;
94 const Viewport* viewport() const;
97 * Gets a list of time markers.
99 std::vector< std::shared_ptr<TimeItem> > time_items() const;
102 * Returns the view time scale in seconds per pixel.
104 double scale() const;
107 * Returns the time offset of the left edge of the view in
110 double offset() const;
113 * Returns the vertical scroll offset.
115 int owner_visual_v_offset() const;
118 * Sets the visual v-offset.
120 void set_v_offset(int offset);
123 * Returns the SI prefix to apply to the graticule time markings.
125 unsigned int tick_prefix() const;
128 * Returns period of the graticule time markings.
130 double tick_period() const;
133 * Returns the number of nested parents that this row item owner has.
135 unsigned int depth() const;
137 void zoom(double steps);
138 void zoom(double steps, int offset);
140 void zoom_fit(bool gui_state);
142 void zoom_one_to_one();
145 * Sets the scale and offset.
146 * @param scale The new view scale in seconds per pixel.
147 * @param offset The view time offset in seconds.
149 void set_scale_offset(double scale, double offset);
151 std::set< std::shared_ptr<pv::data::SignalData> >
152 get_visible_data() const;
154 std::pair<double, double> get_time_extents() const;
157 * Enables or disables sticky scrolling, i.e. the view always shows
158 * the most recent samples when capturing data.
160 void enable_sticky_scrolling(bool state);
163 * Returns true if cursors are displayed. false otherwise.
165 bool cursors_shown() const;
168 * Shows or hides the cursors.
170 void show_cursors(bool show = true);
173 * Moves the cursors to a convenient position in the view.
175 void centre_cursors();
178 * Returns a reference to the pair of cursors.
180 std::shared_ptr<CursorPair> cursors() const;
183 * Adds a new flag at a specified time.
185 void add_flag(double time);
188 * Removes a flag from the list.
190 void remove_flag(std::shared_ptr<Flag> flag);
193 * Gets the list of flags.
195 std::vector< std::shared_ptr<Flag> > flags() const;
197 const QPoint& hover_point() const;
199 void update_viewport();
201 void restack_all_row_items();
204 void hover_point_changed();
206 void selection_changed();
208 void scale_offset_changed();
210 void sticky_scrolling_changed(bool state);
212 void always_zoom_to_fit_changed(bool state);
215 void get_scroll_layout(double &length, double &offset) const;
218 * Simultaneously sets the zoom and offset.
219 * @param scale The scale to set the view to in seconds per pixel. This
220 * value is clamped between MinScale and MaxScale.
221 * @param offset The offset of the left edge of the view in seconds.
223 void set_zoom(double scale, int offset);
226 * Find a tick spacing and number formatting that does not cause
227 * the values to collide.
229 void calculate_tick_spacing();
231 void update_scroll();
233 void update_layout();
236 * Satisifies RowItem functionality.
237 * @param p the QPainter to paint into.
238 * @param rect the rectangle of the header area.
239 * @param hover true if the label is being hovered over by the mouse.
241 void paint_label(QPainter &p, const QRect &rect, bool hover);
244 * Computes the outline rectangle of a label.
245 * @param rect the rectangle of the header area.
246 * @return Returns the rectangle of the signal label.
248 QRectF label_rect(const QRectF &rect);
250 RowItemOwner* find_prevalent_trace_group(
251 const std::shared_ptr<sigrok::ChannelGroup> &group,
252 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
253 std::shared_ptr<Signal> > &signal_map);
255 static std::vector< std::shared_ptr<Trace> >
256 extract_new_traces_for_channels(
257 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
258 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
259 std::shared_ptr<Signal> > &signal_map,
260 std::set< std::shared_ptr<Trace> > &add_list);
263 bool eventFilter(QObject *object, QEvent *event);
265 bool viewportEvent(QEvent *e);
267 void resizeEvent(QResizeEvent *e);
270 void row_item_appearance_changed(bool label, bool content);
271 void time_item_appearance_changed(bool label, bool content);
273 void extents_changed(bool horz, bool vert);
277 void h_scroll_value_changed(int value);
278 void v_scroll_value_changed();
280 void signals_changed();
283 void perform_delayed_view_update();
285 void process_sticky_events();
287 void on_hover_point_changed();
296 /// The view time scale in seconds per pixel.
299 /// The view time offset in seconds.
302 bool updating_scroll_;
303 bool sticky_scrolling_;
304 bool always_zoom_to_fit_;
305 QTimer delayed_view_updater_;
308 unsigned int tick_prefix_;
311 std::shared_ptr<CursorPair> cursors_;
313 std::list< std::shared_ptr<Flag> > flags_;
314 char next_flag_text_;
318 unsigned int sticky_events_;
319 QTimer lazy_event_handler_;
325 #endif // PULSEVIEW_PV_VIEW_VIEW_HPP