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, see <http://www.gnu.org/licenses/>.
20 #ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP
28 #include <unordered_map>
31 #include <QAbstractScrollArea>
35 #include <pv/data/signaldata.hpp>
36 #include <pv/views/viewbase.hpp>
37 #include <pv/util.hpp>
39 #include "cursorpair.hpp"
41 #include "tracetreeitemowner.hpp"
44 using std::unordered_map;
45 using std::unordered_set;
47 using std::shared_ptr;
71 class CustomAbstractScrollArea : public QAbstractScrollArea {
75 CustomAbstractScrollArea(QWidget *parent = nullptr);
76 void setViewportMargins(int left, int top, int right, int bottom);
77 bool viewportEvent(QEvent *event);
80 class View : public ViewBase, public TraceTreeItemOwner {
85 TraceTreeItemHExtentsChanged = 1,
86 TraceTreeItemVExtentsChanged = 2
90 static const pv::util::Timestamp MaxScale;
91 static const pv::util::Timestamp MinScale;
93 static const int MaxScrollValue;
94 static const int MaxViewAutoUpdateRate;
96 static const int ScaleUnits[3];
99 explicit View(Session &session, bool is_main_view=false, QWidget *parent = nullptr);
102 const Session& session() const;
105 * Returns the signals contained in this view.
107 unordered_set< shared_ptr<Signal> > signals() const;
109 virtual void clear_signals();
111 virtual void add_signal(const shared_ptr<Signal> signal);
114 virtual void clear_decode_signals();
116 virtual void add_decode_signal(shared_ptr<data::SignalBase> signalbase);
118 virtual void remove_decode_signal(shared_ptr<data::SignalBase> signalbase);
122 * Returns the view of the owner.
124 virtual View* view();
127 * Returns the view of the owner.
129 virtual const View* view() const;
131 Viewport* viewport();
133 const Viewport* viewport() const;
135 virtual void save_settings(QSettings &settings) const;
137 virtual void restore_settings(QSettings &settings);
140 * Gets a list of time markers.
142 vector< shared_ptr<TimeItem> > time_items() const;
145 * Returns the view time scale in seconds per pixel.
147 double scale() const;
150 * Returns the time offset of the left edge of the view in
153 const pv::util::Timestamp& offset() const;
156 * Returns the vertical scroll offset.
158 int owner_visual_v_offset() const;
161 * Sets the visual v-offset.
163 void set_v_offset(int offset);
166 * Returns the SI prefix to apply to the graticule time markings.
168 pv::util::SIPrefix tick_prefix() const;
171 * Returns the number of fractional digits shown for the time markings.
173 unsigned int tick_precision() const;
176 * Returns period of the graticule time markings.
178 const pv::util::Timestamp& tick_period() const;
181 * Returns the unit of time currently used.
183 util::TimeUnit time_unit() const;
186 * Returns the number of nested parents that this row item owner has.
188 unsigned int depth() const;
190 void zoom(double steps);
191 void zoom(double steps, int offset);
193 void zoom_fit(bool gui_state);
195 void zoom_one_to_one();
198 * Sets the scale and offset.
199 * @param scale The new view scale in seconds per pixel.
200 * @param offset The view time offset in seconds.
202 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
204 set< shared_ptr<pv::data::SignalData> > get_visible_data() const;
206 pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
209 * Enables or disables coloured trace backgrounds. If they're not
210 * coloured then they will use alternating colors.
212 void enable_coloured_bg(bool state);
215 * Enable or disable showing sampling points.
217 void enable_show_sampling_points(bool state);
220 * Returns true if cursors are displayed. false otherwise.
222 bool cursors_shown() const;
225 * Shows or hides the cursors.
227 void show_cursors(bool show = true);
230 * Moves the cursors to a convenient position in the view.
232 void centre_cursors();
235 * Returns a reference to the pair of cursors.
237 shared_ptr<CursorPair> cursors() const;
240 * Adds a new flag at a specified time.
242 void add_flag(const pv::util::Timestamp& time);
245 * Removes a flag from the list.
247 void remove_flag(shared_ptr<Flag> flag);
250 * Gets the list of flags.
252 vector< shared_ptr<Flag> > flags() const;
254 const QPoint& hover_point() const;
256 void restack_all_trace_tree_items();
259 void hover_point_changed();
261 void selection_changed();
263 /// Emitted when the offset changed.
264 void offset_changed();
266 /// Emitted when the scale changed.
267 void scale_changed();
269 void sticky_scrolling_changed(bool state);
271 void always_zoom_to_fit_changed(bool state);
273 /// Emitted when the tick_prefix changed.
274 void tick_prefix_changed();
276 /// Emitted when the tick_precision changed.
277 void tick_precision_changed();
279 /// Emitted when the tick_period changed.
280 void tick_period_changed();
282 /// Emitted when the time_unit changed.
283 void time_unit_changed();
286 void trigger_event(util::Timestamp location);
289 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
292 * Simultaneously sets the zoom and offset.
293 * @param scale The scale to set the view to in seconds per pixel. This
294 * value is clamped between MinScale and MaxScale.
295 * @param offset The offset of the left edge of the view in seconds.
297 void set_zoom(double scale, int offset);
300 * Find a tick spacing and number formatting that does not cause
301 * the values to collide.
303 void calculate_tick_spacing();
305 void update_scroll();
309 void set_scroll_default();
311 void update_layout();
313 TraceTreeItemOwner* find_prevalent_trace_group(
314 const shared_ptr<sigrok::ChannelGroup> &group,
315 const unordered_map<shared_ptr<data::SignalBase>,
316 shared_ptr<Signal> > &signal_map);
318 static vector< shared_ptr<Trace> >
319 extract_new_traces_for_channels(
320 const vector< shared_ptr<sigrok::Channel> > &channels,
321 const unordered_map<shared_ptr<data::SignalBase>,
322 shared_ptr<Signal> > &signal_map,
323 set< shared_ptr<Trace> > &add_list);
325 void determine_time_unit();
327 bool eventFilter(QObject *object, QEvent *event);
329 void resizeEvent(QResizeEvent *event);
332 void row_item_appearance_changed(bool label, bool content);
333 void time_item_appearance_changed(bool label, bool content);
335 void extents_changed(bool horz, bool vert);
339 void h_scroll_value_changed(int value);
340 void v_scroll_value_changed();
342 void signals_changed();
343 void capture_state_updated(int state);
346 void perform_delayed_view_update();
348 void process_sticky_events();
350 void on_hover_point_changed();
353 * Sets the 'offset_' member and emits the 'offset_changed'
356 void set_offset(const pv::util::Timestamp& offset);
359 * Sets the 'scale_' member and emits the 'scale_changed'
362 void set_scale(double scale);
365 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
368 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
371 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
374 void set_tick_precision(unsigned tick_precision);
377 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
380 void set_tick_period(const pv::util::Timestamp& tick_period);
383 * Sets the 'time_unit' member and emits the 'time_unit_changed'
386 void set_time_unit(pv::util::TimeUnit time_unit);
393 unordered_set< shared_ptr<Signal> > signals_;
396 vector< shared_ptr<DecodeTrace> > decode_traces_;
399 CustomAbstractScrollArea scrollarea_;
401 /// The view time scale in seconds per pixel.
404 /// The view time offset in seconds.
405 pv::util::Timestamp offset_;
407 bool updating_scroll_;
408 bool sticky_scrolling_;
410 bool always_zoom_to_fit_;
411 QTimer delayed_view_updater_;
413 pv::util::Timestamp tick_period_;
414 pv::util::SIPrefix tick_prefix_;
415 unsigned int tick_precision_;
416 util::TimeUnit time_unit_;
419 shared_ptr<CursorPair> cursors_;
421 list< shared_ptr<Flag> > flags_;
422 char next_flag_text_;
424 vector< shared_ptr<TriggerMarker> > trigger_markers_;
428 unsigned int sticky_events_;
429 QTimer lazy_event_handler_;
431 // This is true when the defaults couldn't be set due to insufficient info
432 bool scroll_needs_defaults_;
434 // A nonzero value indicates the v offset to restore. See View::resizeEvent()
437 bool size_finalized_;
440 } // namespace TraceView
444 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP