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_VIEWS_TRACEVIEW_VIEW_HPP
22 #define PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP
29 #include <unordered_map>
32 #include <QAbstractScrollArea>
36 #include <pv/data/signaldata.hpp>
37 #include <pv/views/viewbase.hpp>
38 #include <pv/util.hpp>
40 #include "cursorpair.hpp"
42 #include "tracetreeitemowner.hpp"
65 class CustomAbstractScrollArea : public QAbstractScrollArea {
69 CustomAbstractScrollArea(QWidget *parent = 0);
70 void setViewportMargins(int left, int top, int right, int bottom);
71 bool viewportEvent(QEvent *event);
74 class View : public ViewBase, public TraceTreeItemOwner {
79 TraceTreeItemHExtentsChanged = 1,
80 TraceTreeItemVExtentsChanged = 2
84 static const pv::util::Timestamp MaxScale;
85 static const pv::util::Timestamp MinScale;
87 static const int MaxScrollValue;
88 static const int MaxViewAutoUpdateRate;
90 static const int ScaleUnits[3];
93 explicit View(Session &session, QWidget *parent = 0);
96 const Session& session() const;
99 * Returns the signals contained in this view.
101 std::unordered_set< std::shared_ptr<Signal> > signals() const;
103 virtual void clear_signals();
105 virtual void add_signal(const std::shared_ptr<Signal> signal);
108 virtual void clear_decode_signals();
110 virtual void add_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
112 virtual void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
116 * Returns the view of the owner.
118 virtual View* view();
121 * Returns the view of the owner.
123 virtual const View* view() const;
125 Viewport* viewport();
127 const Viewport* viewport() const;
129 virtual void save_settings(QSettings &settings) const;
131 virtual void restore_settings(QSettings &settings);
134 * Gets a list of time markers.
136 std::vector< std::shared_ptr<TimeItem> > time_items() const;
139 * Returns the view time scale in seconds per pixel.
141 double scale() const;
144 * Returns the time offset of the left edge of the view in
147 const pv::util::Timestamp& offset() const;
150 * Returns the vertical scroll offset.
152 int owner_visual_v_offset() const;
155 * Sets the visual v-offset.
157 void set_v_offset(int offset);
160 * Returns the SI prefix to apply to the graticule time markings.
162 pv::util::SIPrefix tick_prefix() const;
165 * Returns the number of fractional digits shown for the time markings.
167 unsigned int tick_precision() const;
170 * Returns period of the graticule time markings.
172 const pv::util::Timestamp& tick_period() const;
175 * Returns the unit of time currently used.
177 util::TimeUnit time_unit() const;
180 * Returns the number of nested parents that this row item owner has.
182 unsigned int depth() const;
184 void zoom(double steps);
185 void zoom(double steps, int offset);
187 void zoom_fit(bool gui_state);
189 void zoom_one_to_one();
192 * Sets the scale and offset.
193 * @param scale The new view scale in seconds per pixel.
194 * @param offset The view time offset in seconds.
196 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
198 std::set< std::shared_ptr<pv::data::SignalData> >
199 get_visible_data() const;
201 std::pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
204 * Enables or disables sticky scrolling, i.e. the view always shows
205 * the most recent samples when capturing data.
207 void enable_sticky_scrolling(bool state);
210 * Enables or disables coloured trace backgrounds. If they're not
211 * coloured then they will use alternating colors.
213 void enable_coloured_bg(bool state);
216 * Returns true if cursors are displayed. false otherwise.
218 bool cursors_shown() const;
221 * Shows or hides the cursors.
223 void show_cursors(bool show = true);
226 * Moves the cursors to a convenient position in the view.
228 void centre_cursors();
231 * Returns a reference to the pair of cursors.
233 std::shared_ptr<CursorPair> cursors() const;
236 * Adds a new flag at a specified time.
238 void add_flag(const pv::util::Timestamp& time);
241 * Removes a flag from the list.
243 void remove_flag(std::shared_ptr<Flag> flag);
246 * Gets the list of flags.
248 std::vector< std::shared_ptr<Flag> > flags() const;
250 const QPoint& hover_point() const;
252 void restack_all_trace_tree_items();
255 void hover_point_changed();
257 void selection_changed();
259 /// Emitted when the offset changed.
260 void offset_changed();
262 /// Emitted when the scale changed.
263 void scale_changed();
265 void sticky_scrolling_changed(bool state);
267 void always_zoom_to_fit_changed(bool state);
269 /// Emitted when the tick_prefix changed.
270 void tick_prefix_changed();
272 /// Emitted when the tick_precision changed.
273 void tick_precision_changed();
275 /// Emitted when the tick_period changed.
276 void tick_period_changed();
278 /// Emitted when the time_unit changed.
279 void time_unit_changed();
282 void trigger_event(util::Timestamp location);
285 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
288 * Simultaneously sets the zoom and offset.
289 * @param scale The scale to set the view to in seconds per pixel. This
290 * value is clamped between MinScale and MaxScale.
291 * @param offset The offset of the left edge of the view in seconds.
293 void set_zoom(double scale, int offset);
296 * Find a tick spacing and number formatting that does not cause
297 * the values to collide.
299 void calculate_tick_spacing();
301 void update_scroll();
305 void set_scroll_default();
307 void update_layout();
309 TraceTreeItemOwner* find_prevalent_trace_group(
310 const std::shared_ptr<sigrok::ChannelGroup> &group,
311 const std::unordered_map<std::shared_ptr<data::SignalBase>,
312 std::shared_ptr<Signal> > &signal_map);
314 static std::vector< std::shared_ptr<Trace> >
315 extract_new_traces_for_channels(
316 const std::vector< std::shared_ptr<sigrok::Channel> > &channels,
317 const std::unordered_map<std::shared_ptr<data::SignalBase>,
318 std::shared_ptr<Signal> > &signal_map,
319 std::set< std::shared_ptr<Trace> > &add_list);
321 void determine_time_unit();
323 bool eventFilter(QObject *object, QEvent *event);
325 void resizeEvent(QResizeEvent *event);
328 void row_item_appearance_changed(bool label, bool content);
329 void time_item_appearance_changed(bool label, bool content);
331 void extents_changed(bool horz, bool vert);
335 void h_scroll_value_changed(int value);
336 void v_scroll_value_changed();
338 void signals_changed();
339 void capture_state_updated(int state);
342 void perform_delayed_view_update();
344 void process_sticky_events();
346 void on_hover_point_changed();
349 * Sets the 'offset_' member and emits the 'offset_changed'
352 void set_offset(const pv::util::Timestamp& offset);
355 * Sets the 'scale_' member and emits the 'scale_changed'
358 void set_scale(double scale);
361 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
364 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
367 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
370 void set_tick_precision(unsigned tick_precision);
373 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
376 void set_tick_period(const pv::util::Timestamp& tick_period);
379 * Sets the 'time_unit' member and emits the 'time_unit_changed'
382 void set_time_unit(pv::util::TimeUnit time_unit);
389 std::unordered_set< std::shared_ptr<Signal> > signals_;
392 std::vector< std::shared_ptr<DecodeTrace> > decode_traces_;
395 CustomAbstractScrollArea scrollarea_;
397 /// The view time scale in seconds per pixel.
400 /// The view time offset in seconds.
401 pv::util::Timestamp offset_;
403 bool updating_scroll_;
404 bool sticky_scrolling_;
405 bool always_zoom_to_fit_;
406 QTimer delayed_view_updater_;
408 pv::util::Timestamp tick_period_;
409 pv::util::SIPrefix tick_prefix_;
410 unsigned int tick_precision_;
411 util::TimeUnit time_unit_;
414 std::shared_ptr<CursorPair> cursors_;
416 std::list< std::shared_ptr<Flag> > flags_;
417 char next_flag_text_;
419 std::vector< std::shared_ptr<TriggerMarker> > trigger_markers_;
423 unsigned int sticky_events_;
424 QTimer lazy_event_handler_;
426 // This is true when the defaults couldn't be set due to insufficient info
427 bool scroll_needs_defaults;
430 } // namespace TraceView
434 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP