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"
62 class View : public QAbstractScrollArea, public TraceTreeItemOwner {
67 TraceTreeItemHExtentsChanged = 1,
68 TraceTreeItemVExtentsChanged = 2
72 static const pv::util::Timestamp MaxScale;
73 static const pv::util::Timestamp MinScale;
75 static const int MaxScrollValue;
76 static const int MaxViewAutoUpdateRate;
78 static const int ScaleUnits[3];
81 explicit View(Session &session, QWidget *parent = 0);
84 const Session& session() const;
87 * Returns the signals contained in this view.
89 std::unordered_set< std::shared_ptr<view::Signal> > signals() const;
93 void add_signal(const std::shared_ptr<view::Signal> signal);
96 void clear_decode_traces();
98 void add_decode_trace(std::shared_ptr<data::SignalBase> signalbase);
100 void remove_decode_trace(std::shared_ptr<data::SignalBase> signalbase);
104 * Returns the view of the owner.
106 virtual pv::view::View* view();
109 * Returns the view of the owner.
111 virtual const pv::view::View* view() const;
113 Viewport* viewport();
115 const Viewport* viewport() const;
117 void save_settings(QSettings &settings) const;
119 void restore_settings(QSettings &settings);
122 * Gets a list of time markers.
124 std::vector< std::shared_ptr<TimeItem> > time_items() const;
127 * Returns the view time scale in seconds per pixel.
129 double scale() const;
132 * Returns the time offset of the left edge of the view in
135 const pv::util::Timestamp& offset() const;
138 * Returns the vertical scroll offset.
140 int owner_visual_v_offset() const;
143 * Sets the visual v-offset.
145 void set_v_offset(int offset);
148 * Returns the SI prefix to apply to the graticule time markings.
150 pv::util::SIPrefix tick_prefix() const;
153 * Returns the number of fractional digits shown for the time markings.
155 unsigned int tick_precision() const;
158 * Returns period of the graticule time markings.
160 const pv::util::Timestamp& tick_period() const;
163 * Returns the unit of time currently used.
165 util::TimeUnit time_unit() const;
168 * Returns the number of nested parents that this row item owner has.
170 unsigned int depth() const;
172 void zoom(double steps);
173 void zoom(double steps, int offset);
175 void zoom_fit(bool gui_state);
177 void zoom_one_to_one();
180 * Sets the scale and offset.
181 * @param scale The new view scale in seconds per pixel.
182 * @param offset The view time offset in seconds.
184 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
186 std::set< std::shared_ptr<pv::data::SignalData> >
187 get_visible_data() const;
189 std::pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
192 * Enables or disables sticky scrolling, i.e. the view always shows
193 * the most recent samples when capturing data.
195 void enable_sticky_scrolling(bool state);
198 * Enables or disables coloured trace backgrounds. If they're not
199 * coloured then they will use alternating colors.
201 void enable_coloured_bg(bool state);
204 * Returns true if cursors are displayed. false otherwise.
206 bool cursors_shown() const;
209 * Shows or hides the cursors.
211 void show_cursors(bool show = true);
214 * Moves the cursors to a convenient position in the view.
216 void centre_cursors();
219 * Returns a reference to the pair of cursors.
221 std::shared_ptr<CursorPair> cursors() const;
224 * Adds a new flag at a specified time.
226 void add_flag(const pv::util::Timestamp& time);
229 * Removes a flag from the list.
231 void remove_flag(std::shared_ptr<Flag> flag);
234 * Gets the list of flags.
236 std::vector< std::shared_ptr<Flag> > flags() const;
238 const QPoint& hover_point() const;
240 void restack_all_trace_tree_items();
243 void hover_point_changed();
245 void selection_changed();
247 /// Emitted when the offset changed.
248 void offset_changed();
250 /// Emitted when the scale changed.
251 void scale_changed();
253 void sticky_scrolling_changed(bool state);
255 void always_zoom_to_fit_changed(bool state);
257 /// Emitted when the tick_prefix changed.
258 void tick_prefix_changed();
260 /// Emitted when the tick_precision changed.
261 void tick_precision_changed();
263 /// Emitted when the tick_period changed.
264 void tick_period_changed();
266 /// Emitted when the time_unit changed.
267 void time_unit_changed();
270 void trigger_event(util::Timestamp location);
273 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
276 * Simultaneously sets the zoom and offset.
277 * @param scale The scale to set the view to in seconds per pixel. This
278 * value is clamped between MinScale and MaxScale.
279 * @param offset The offset of the left edge of the view in seconds.
281 void set_zoom(double scale, int offset);
284 * Find a tick spacing and number formatting that does not cause
285 * the values to collide.
287 void calculate_tick_spacing();
289 void update_scroll();
293 void set_scroll_default();
295 void update_layout();
297 TraceTreeItemOwner* find_prevalent_trace_group(
298 const std::shared_ptr<sigrok::ChannelGroup> &group,
299 const std::unordered_map<std::shared_ptr<data::SignalBase>,
300 std::shared_ptr<Signal> > &signal_map);
302 static std::vector< std::shared_ptr<Trace> >
303 extract_new_traces_for_channels(
304 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
305 const std::unordered_map<std::shared_ptr<data::SignalBase>,
306 std::shared_ptr<Signal> > &signal_map,
307 std::set< std::shared_ptr<Trace> > &add_list);
309 void determine_time_unit();
311 bool eventFilter(QObject *object, QEvent *event);
313 bool viewportEvent(QEvent *event);
315 void resizeEvent(QResizeEvent *event);
318 void row_item_appearance_changed(bool label, bool content);
319 void time_item_appearance_changed(bool label, bool content);
321 void extents_changed(bool horz, bool vert);
325 void h_scroll_value_changed(int value);
326 void v_scroll_value_changed();
328 void signals_changed();
329 void capture_state_updated(int state);
332 void perform_delayed_view_update();
334 void process_sticky_events();
336 void on_hover_point_changed();
339 * Sets the 'offset_' member and emits the 'offset_changed'
342 void set_offset(const pv::util::Timestamp& offset);
345 * Sets the 'scale_' member and emits the 'scale_changed'
348 void set_scale(double scale);
351 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
354 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
357 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
360 void set_tick_precision(unsigned tick_precision);
363 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
366 void set_tick_period(const pv::util::Timestamp& tick_period);
369 * Sets the 'time_unit' member and emits the 'time_unit_changed'
372 void set_time_unit(pv::util::TimeUnit time_unit);
381 std::unordered_set< std::shared_ptr<view::Signal> > signals_;
384 std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
387 /// The view time scale in seconds per pixel.
390 /// The view time offset in seconds.
391 pv::util::Timestamp offset_;
393 bool updating_scroll_;
394 bool sticky_scrolling_;
395 bool always_zoom_to_fit_;
396 QTimer delayed_view_updater_;
398 pv::util::Timestamp tick_period_;
399 pv::util::SIPrefix tick_prefix_;
400 unsigned int tick_precision_;
401 util::TimeUnit time_unit_;
404 std::shared_ptr<CursorPair> cursors_;
406 std::list< std::shared_ptr<Flag> > flags_;
407 char next_flag_text_;
409 std::vector< std::shared_ptr<TriggerMarker> > trigger_markers_;
413 unsigned int sticky_events_;
414 QTimer lazy_event_handler_;
416 // This is true when the defaults couldn't be set due to insufficient info
417 bool scroll_needs_defaults;
423 #endif // PULSEVIEW_PV_VIEW_VIEW_HPP