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>
37 #include <pv/util.hpp>
39 #include "cursorpair.hpp"
41 #include "rowitemowner.hpp"
59 class View : public QAbstractScrollArea, public RowItemOwner {
64 RowItemHExtentsChanged = 1,
65 RowItemVExtentsChanged = 2
69 static const double MaxScale;
70 static const double MinScale;
72 static const int MaxScrollValue;
73 static const int MaxViewAutoUpdateRate;
75 static const int ScaleUnits[3];
78 explicit View(Session &session, QWidget *parent = 0);
81 const Session& session() const;
84 * Returns the view of the owner.
86 virtual pv::view::View* view();
89 * Returns the view of the owner.
91 virtual const pv::view::View* view() const;
95 const Viewport* viewport() const;
98 * Gets a list of time markers.
100 std::vector< std::shared_ptr<TimeItem> > time_items() const;
103 * Returns the view time scale in seconds per pixel.
105 double scale() const;
108 * Returns the time offset of the left edge of the view in
111 double offset() const;
114 * Returns the vertical scroll offset.
116 int owner_visual_v_offset() const;
119 * Sets the visual v-offset.
121 void set_v_offset(int offset);
124 * Returns the SI prefix to apply to the graticule time markings.
126 unsigned int tick_prefix() const;
129 * Returns the number of fractional digits shown for the time markings.
131 unsigned int tick_precision() const;
134 * Returns period of the graticule time markings.
136 double tick_period() const;
139 * Returns the unit of time currently used.
141 util::TimeUnit time_unit() const;
144 * Returns the number of nested parents that this row item owner has.
146 unsigned int depth() const;
148 void zoom(double steps);
149 void zoom(double steps, int offset);
151 void zoom_fit(bool gui_state);
153 void zoom_one_to_one();
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.
160 void set_scale_offset(double scale, double offset);
162 std::set< std::shared_ptr<pv::data::SignalData> >
163 get_visible_data() const;
165 std::pair<double, double> get_time_extents() const;
168 * Enables or disables sticky scrolling, i.e. the view always shows
169 * the most recent samples when capturing data.
171 void enable_sticky_scrolling(bool state);
174 * Returns true if cursors are displayed. false otherwise.
176 bool cursors_shown() const;
179 * Shows or hides the cursors.
181 void show_cursors(bool show = true);
184 * Moves the cursors to a convenient position in the view.
186 void centre_cursors();
189 * Returns a reference to the pair of cursors.
191 std::shared_ptr<CursorPair> cursors() const;
194 * Adds a new flag at a specified time.
196 void add_flag(double time);
199 * Removes a flag from the list.
201 void remove_flag(std::shared_ptr<Flag> flag);
204 * Gets the list of flags.
206 std::vector< std::shared_ptr<Flag> > flags() const;
208 const QPoint& hover_point() const;
210 void update_viewport();
212 void restack_all_row_items();
215 void hover_point_changed();
217 void selection_changed();
219 void scale_offset_changed();
221 void sticky_scrolling_changed(bool state);
223 void always_zoom_to_fit_changed(bool state);
226 void get_scroll_layout(double &length, double &offset) const;
229 * Simultaneously sets the zoom and offset.
230 * @param scale The scale to set the view to in seconds per pixel. This
231 * value is clamped between MinScale and MaxScale.
232 * @param offset The offset of the left edge of the view in seconds.
234 void set_zoom(double scale, int offset);
237 * Find a tick spacing and number formatting that does not cause
238 * the values to collide.
240 void calculate_tick_spacing();
242 void update_scroll();
244 void update_layout();
247 * Satisifies RowItem functionality.
248 * @param p the QPainter to paint into.
249 * @param rect the rectangle of the header area.
250 * @param hover true if the label is being hovered over by the mouse.
252 void paint_label(QPainter &p, const QRect &rect, bool hover);
255 * Computes the outline rectangle of a label.
256 * @param rect the rectangle of the header area.
257 * @return Returns the rectangle of the signal label.
259 QRectF label_rect(const QRectF &rect);
261 RowItemOwner* find_prevalent_trace_group(
262 const std::shared_ptr<sigrok::ChannelGroup> &group,
263 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
264 std::shared_ptr<Signal> > &signal_map);
266 static std::vector< std::shared_ptr<Trace> >
267 extract_new_traces_for_channels(
268 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
269 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
270 std::shared_ptr<Signal> > &signal_map,
271 std::set< std::shared_ptr<Trace> > &add_list);
273 void determine_time_unit();
276 bool eventFilter(QObject *object, QEvent *event);
278 bool viewportEvent(QEvent *e);
280 void resizeEvent(QResizeEvent *e);
283 void row_item_appearance_changed(bool label, bool content);
284 void time_item_appearance_changed(bool label, bool content);
286 void extents_changed(bool horz, bool vert);
290 void h_scroll_value_changed(int value);
291 void v_scroll_value_changed();
293 void signals_changed();
294 void capture_state_updated(int state);
297 void perform_delayed_view_update();
299 void process_sticky_events();
301 void on_hover_point_changed();
310 /// The view time scale in seconds per pixel.
313 /// The view time offset in seconds.
316 bool updating_scroll_;
317 bool sticky_scrolling_;
318 bool always_zoom_to_fit_;
319 QTimer delayed_view_updater_;
322 unsigned int tick_prefix_;
323 unsigned int tick_precision_;
324 util::TimeUnit time_unit_;
327 std::shared_ptr<CursorPair> cursors_;
329 std::list< std::shared_ptr<Flag> > flags_;
330 char next_flag_text_;
334 unsigned int sticky_events_;
335 QTimer lazy_event_handler_;
341 #endif // PULSEVIEW_PV_VIEW_VIEW_HPP