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 "tracetreeitemowner.hpp"
60 class View : public QAbstractScrollArea, public TraceTreeItemOwner {
65 TraceTreeItemHExtentsChanged = 1,
66 TraceTreeItemVExtentsChanged = 2
70 static const pv::util::Timestamp MaxScale;
71 static const pv::util::Timestamp MinScale;
73 static const int MaxScrollValue;
74 static const int MaxViewAutoUpdateRate;
76 static const int ScaleUnits[3];
79 explicit View(Session &session, QWidget *parent = 0);
82 const Session& session() const;
85 * Returns the view of the owner.
87 virtual pv::view::View* view();
90 * Returns the view of the owner.
92 virtual const pv::view::View* view() const;
96 const Viewport* viewport() const;
99 * Gets a list of time markers.
101 std::vector< std::shared_ptr<TimeItem> > time_items() const;
104 * Returns the view time scale in seconds per pixel.
106 double scale() const;
109 * Returns the time offset of the left edge of the view in
112 const pv::util::Timestamp& offset() const;
115 * Returns the vertical scroll offset.
117 int owner_visual_v_offset() const;
120 * Sets the visual v-offset.
122 void set_v_offset(int offset);
125 * Returns the SI prefix to apply to the graticule time markings.
127 pv::util::SIPrefix tick_prefix() const;
130 * Returns the number of fractional digits shown for the time markings.
132 unsigned int tick_precision() const;
135 * Returns period of the graticule time markings.
137 const pv::util::Timestamp& tick_period() const;
140 * Returns the unit of time currently used.
142 util::TimeUnit time_unit() const;
145 * Returns the number of nested parents that this row item owner has.
147 unsigned int depth() const;
149 void zoom(double steps);
150 void zoom(double steps, int offset);
152 void zoom_fit(bool gui_state);
154 void zoom_one_to_one();
157 * Sets the scale and offset.
158 * @param scale The new view scale in seconds per pixel.
159 * @param offset The view time offset in seconds.
161 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
163 std::set< std::shared_ptr<pv::data::SignalData> >
164 get_visible_data() const;
166 std::pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
169 * Enables or disables sticky scrolling, i.e. the view always shows
170 * the most recent samples when capturing data.
172 void enable_sticky_scrolling(bool state);
175 * Returns true if cursors are displayed. false otherwise.
177 bool cursors_shown() const;
180 * Shows or hides the cursors.
182 void show_cursors(bool show = true);
185 * Moves the cursors to a convenient position in the view.
187 void centre_cursors();
190 * Returns a reference to the pair of cursors.
192 std::shared_ptr<CursorPair> cursors() const;
195 * Adds a new flag at a specified time.
197 void add_flag(const pv::util::Timestamp& time);
200 * Removes a flag from the list.
202 void remove_flag(std::shared_ptr<Flag> flag);
205 * Gets the list of flags.
207 std::vector< std::shared_ptr<Flag> > flags() const;
209 const QPoint& hover_point() const;
211 void update_viewport();
213 void restack_all_trace_tree_items();
216 void hover_point_changed();
218 void selection_changed();
220 /// Emitted when the offset changed.
221 void offset_changed();
223 /// Emitted when the scale changed.
224 void scale_changed();
226 void sticky_scrolling_changed(bool state);
228 void always_zoom_to_fit_changed(bool state);
230 /// Emitted when the tick_prefix changed.
231 void tick_prefix_changed();
233 /// Emitted when the tick_precision changed.
234 void tick_precision_changed();
236 /// Emitted when the tick_period changed.
237 void tick_period_changed();
239 /// Emitted when the time_unit changed.
240 void time_unit_changed();
243 void trigger_event(util::Timestamp location);
246 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
249 * Simultaneously sets the zoom and offset.
250 * @param scale The scale to set the view to in seconds per pixel. This
251 * value is clamped between MinScale and MaxScale.
252 * @param offset The offset of the left edge of the view in seconds.
254 void set_zoom(double scale, int offset);
257 * Find a tick spacing and number formatting that does not cause
258 * the values to collide.
260 void calculate_tick_spacing();
262 void update_scroll();
264 void update_layout();
267 * Satisifies TraceTreeItem functionality.
268 * @param p the QPainter to paint into.
269 * @param rect the rectangle of the header area.
270 * @param hover true if the label is being hovered over by the mouse.
272 void paint_label(QPainter &p, const QRect &rect, bool hover);
275 * Computes the outline rectangle of a label.
276 * @param rect the rectangle of the header area.
277 * @return Returns the rectangle of the signal label.
279 QRectF label_rect(const QRectF &rect);
281 TraceTreeItemOwner* find_prevalent_trace_group(
282 const std::shared_ptr<sigrok::ChannelGroup> &group,
283 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
284 std::shared_ptr<Signal> > &signal_map);
286 static std::vector< std::shared_ptr<Trace> >
287 extract_new_traces_for_channels(
288 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
289 const std::unordered_map<std::shared_ptr<sigrok::Channel>,
290 std::shared_ptr<Signal> > &signal_map,
291 std::set< std::shared_ptr<Trace> > &add_list);
293 void determine_time_unit();
295 bool eventFilter(QObject *object, QEvent *event);
297 bool viewportEvent(QEvent *e);
299 void resizeEvent(QResizeEvent *e);
302 void row_item_appearance_changed(bool label, bool content);
303 void time_item_appearance_changed(bool label, bool content);
305 void extents_changed(bool horz, bool vert);
309 void h_scroll_value_changed(int value);
310 void v_scroll_value_changed();
312 void signals_changed();
313 void capture_state_updated(int state);
316 void perform_delayed_view_update();
318 void process_sticky_events();
320 void on_hover_point_changed();
323 * Sets the 'offset_' member and emits the 'offset_changed'
326 void set_offset(const pv::util::Timestamp& offset);
329 * Sets the 'scale_' member and emits the 'scale_changed'
332 void set_scale(double scale);
335 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
338 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
341 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
344 void set_tick_precision(unsigned tick_precision);
347 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
350 void set_tick_period(const pv::util::Timestamp& tick_period);
353 * Sets the 'time_unit' member and emits the 'time_unit_changed'
356 void set_time_unit(pv::util::TimeUnit time_unit);
365 /// The view time scale in seconds per pixel.
368 /// The view time offset in seconds.
369 pv::util::Timestamp offset_;
371 bool updating_scroll_;
372 bool sticky_scrolling_;
373 bool always_zoom_to_fit_;
374 QTimer delayed_view_updater_;
376 pv::util::Timestamp tick_period_;
377 pv::util::SIPrefix tick_prefix_;
378 unsigned int tick_precision_;
379 util::TimeUnit time_unit_;
382 std::shared_ptr<CursorPair> cursors_;
384 std::list< std::shared_ptr<Flag> > flags_;
385 char next_flag_text_;
387 std::vector< std::shared_ptr<TriggerMarker> > trigger_markers_;
391 unsigned int sticky_events_;
392 QTimer lazy_event_handler_;
398 #endif // PULSEVIEW_PV_VIEW_VIEW_HPP