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
27 #include <unordered_map>
30 #include <QAbstractScrollArea>
34 #include <pv/data/signaldata.hpp>
35 #include <pv/views/viewbase.hpp>
36 #include <pv/util.hpp>
38 #include "cursorpair.hpp"
40 #include "tracetreeitemowner.hpp"
43 using std::unordered_map;
44 using std::unordered_set;
46 using std::shared_ptr;
70 class CustomAbstractScrollArea : public QAbstractScrollArea {
74 CustomAbstractScrollArea(QWidget *parent = nullptr);
75 void setViewportMargins(int left, int top, int right, int bottom);
76 bool viewportEvent(QEvent *event);
79 class View : public ViewBase, public TraceTreeItemOwner {
84 TraceTreeItemHExtentsChanged = 1,
85 TraceTreeItemVExtentsChanged = 2
89 static const pv::util::Timestamp MaxScale;
90 static const pv::util::Timestamp MinScale;
92 static const int MaxScrollValue;
93 static const int MaxViewAutoUpdateRate;
95 static const int ScaleUnits[3];
98 explicit View(Session &session, bool is_main_view=false, QWidget *parent = nullptr);
101 const Session& session() const;
104 * Returns the signals contained in this view.
106 unordered_set< shared_ptr<Signal> > signals() const;
108 virtual void clear_signals();
110 virtual void add_signal(const shared_ptr<Signal> signal);
113 virtual void clear_decode_signals();
115 virtual void add_decode_signal(shared_ptr<data::SignalBase> signalbase);
117 virtual void remove_decode_signal(shared_ptr<data::SignalBase> signalbase);
121 * Returns the view of the owner.
123 virtual View* view();
126 * Returns the view of the owner.
128 virtual const View* view() const;
130 Viewport* viewport();
132 const Viewport* viewport() const;
134 virtual void save_settings(QSettings &settings) const;
136 virtual void restore_settings(QSettings &settings);
139 * Gets a list of time markers.
141 vector< shared_ptr<TimeItem> > time_items() const;
144 * Returns the view time scale in seconds per pixel.
146 double scale() const;
149 * Returns the time offset of the left edge of the view in
152 const pv::util::Timestamp& offset() const;
155 * Returns the vertical scroll offset.
157 int owner_visual_v_offset() const;
160 * Sets the visual v-offset.
162 void set_v_offset(int offset);
165 * Returns the SI prefix to apply to the graticule time markings.
167 pv::util::SIPrefix tick_prefix() const;
170 * Returns the number of fractional digits shown for the time markings.
172 unsigned int tick_precision() const;
175 * Returns period of the graticule time markings.
177 const pv::util::Timestamp& tick_period() const;
180 * Returns the unit of time currently used.
182 util::TimeUnit time_unit() const;
185 * Returns the number of nested parents that this row item owner has.
187 unsigned int depth() const;
189 void zoom(double steps);
190 void zoom(double steps, int offset);
192 void zoom_fit(bool gui_state);
194 void zoom_one_to_one();
197 * Sets the scale and offset.
198 * @param scale The new view scale in seconds per pixel.
199 * @param offset The view time offset in seconds.
201 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
203 set< shared_ptr<pv::data::SignalData> > get_visible_data() const;
205 pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
208 * Enables or disables coloured trace backgrounds. If they're not
209 * coloured then they will use alternating colors.
211 void enable_coloured_bg(bool state);
214 * Enable or disable showing sampling points.
216 void enable_show_sampling_points(bool state);
219 * Returns true if cursors are displayed. false otherwise.
221 bool cursors_shown() const;
224 * Shows or hides the cursors.
226 void show_cursors(bool show = true);
229 * Moves the cursors to a convenient position in the view.
231 void centre_cursors();
234 * Returns a reference to the pair of cursors.
236 shared_ptr<CursorPair> cursors() const;
239 * Adds a new flag at a specified time.
241 void add_flag(const pv::util::Timestamp& time);
244 * Removes a flag from the list.
246 void remove_flag(shared_ptr<Flag> flag);
249 * Gets the list of flags.
251 vector< shared_ptr<Flag> > flags() const;
253 const QPoint& hover_point() const;
255 void restack_all_trace_tree_items();
258 void hover_point_changed();
260 void selection_changed();
262 /// Emitted when the offset changed.
263 void offset_changed();
265 /// Emitted when the scale changed.
266 void scale_changed();
268 void sticky_scrolling_changed(bool state);
270 void always_zoom_to_fit_changed(bool state);
272 /// Emitted when the tick_prefix changed.
273 void tick_prefix_changed();
275 /// Emitted when the tick_precision changed.
276 void tick_precision_changed();
278 /// Emitted when the tick_period changed.
279 void tick_period_changed();
281 /// Emitted when the time_unit changed.
282 void time_unit_changed();
285 void trigger_event(util::Timestamp location);
288 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
291 * Simultaneously sets the zoom and offset.
292 * @param scale The scale to set the view to in seconds per pixel. This
293 * value is clamped between MinScale and MaxScale.
294 * @param offset The offset of the left edge of the view in seconds.
296 void set_zoom(double scale, int offset);
299 * Find a tick spacing and number formatting that does not cause
300 * the values to collide.
302 void calculate_tick_spacing();
304 void update_scroll();
308 void set_scroll_default();
310 void update_layout();
312 TraceTreeItemOwner* find_prevalent_trace_group(
313 const shared_ptr<sigrok::ChannelGroup> &group,
314 const unordered_map<shared_ptr<data::SignalBase>,
315 shared_ptr<Signal> > &signal_map);
317 static vector< shared_ptr<Trace> >
318 extract_new_traces_for_channels(
319 const vector< shared_ptr<sigrok::Channel> > &channels,
320 const unordered_map<shared_ptr<data::SignalBase>,
321 shared_ptr<Signal> > &signal_map,
322 set< shared_ptr<Trace> > &add_list);
324 void determine_time_unit();
326 bool eventFilter(QObject *object, QEvent *event);
328 void resizeEvent(QResizeEvent *event);
331 void row_item_appearance_changed(bool label, bool content);
332 void time_item_appearance_changed(bool label, bool content);
334 void extents_changed(bool horz, bool vert);
338 void h_scroll_value_changed(int value);
339 void v_scroll_value_changed();
341 void signals_changed();
342 void capture_state_updated(int state);
345 void perform_delayed_view_update();
347 void process_sticky_events();
349 void on_hover_point_changed();
352 * Sets the 'offset_' member and emits the 'offset_changed'
355 void set_offset(const pv::util::Timestamp& offset);
358 * Sets the 'scale_' member and emits the 'scale_changed'
361 void set_scale(double scale);
364 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
367 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
370 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
373 void set_tick_precision(unsigned tick_precision);
376 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
379 void set_tick_period(const pv::util::Timestamp& tick_period);
382 * Sets the 'time_unit' member and emits the 'time_unit_changed'
385 void set_time_unit(pv::util::TimeUnit time_unit);
392 unordered_set< shared_ptr<Signal> > signals_;
395 vector< shared_ptr<DecodeTrace> > decode_traces_;
398 CustomAbstractScrollArea scrollarea_;
400 /// The view time scale in seconds per pixel.
403 /// The view time offset in seconds.
404 pv::util::Timestamp offset_;
406 bool updating_scroll_;
407 bool sticky_scrolling_;
409 bool always_zoom_to_fit_;
410 QTimer delayed_view_updater_;
412 pv::util::Timestamp tick_period_;
413 pv::util::SIPrefix tick_prefix_;
414 unsigned int tick_precision_;
415 util::TimeUnit time_unit_;
418 shared_ptr<CursorPair> cursors_;
420 list< shared_ptr<Flag> > flags_;
421 char next_flag_text_;
423 vector< shared_ptr<TriggerMarker> > trigger_markers_;
427 unsigned int sticky_events_;
428 QTimer lazy_event_handler_;
430 // This is true when the defaults couldn't be set due to insufficient info
431 bool scroll_needs_defaults_;
433 // A nonzero value indicates the v offset to restore. See View::resizeEvent()
436 bool size_finalized_;
439 } // namespace TraceView
443 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP