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/util.hpp>
36 #include <pv/views/viewbase.hpp>
38 #include "cursorpair.hpp"
40 #include "tracetreeitemowner.hpp"
43 using std::unordered_map;
44 using std::unordered_set;
46 using std::shared_ptr;
74 class CustomScrollArea : public QAbstractScrollArea
79 CustomScrollArea(QWidget *parent = nullptr);
80 bool viewportEvent(QEvent *event);
83 class View : public ViewBase, public TraceTreeItemOwner
89 TraceTreeItemHExtentsChanged = 1,
90 TraceTreeItemVExtentsChanged = 2
94 static const pv::util::Timestamp MaxScale;
95 static const pv::util::Timestamp MinScale;
97 static const int MaxScrollValue;
99 static const int ScaleUnits[3];
102 explicit View(Session &session, bool is_main_view=false, QWidget *parent = nullptr);
105 const Session& session() const;
108 * Returns the signals contained in this view.
110 unordered_set< shared_ptr<Signal> > signals() const;
112 virtual void clear_signals();
114 void add_signal(const shared_ptr<Signal> signal);
117 virtual void clear_decode_signals();
119 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
121 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
125 * Returns the view of the owner.
127 virtual View* view();
130 * Returns the view of the owner.
132 virtual const View* view() const;
134 Viewport* viewport();
136 const Viewport* viewport() const;
138 virtual void save_settings(QSettings &settings) const;
140 virtual void restore_settings(QSettings &settings);
143 * Gets a list of time markers.
145 vector< shared_ptr<TimeItem> > time_items() const;
148 * Returns the view time scale in seconds per pixel.
150 double scale() const;
153 * Returns the time offset of the left edge of the view in
156 const pv::util::Timestamp& offset() const;
159 * Returns the vertical scroll offset.
161 int owner_visual_v_offset() const;
164 * Sets the visual v-offset.
166 void set_v_offset(int offset);
169 * Returns the SI prefix to apply to the graticule time markings.
171 pv::util::SIPrefix tick_prefix() const;
174 * Returns the number of fractional digits shown for the time markings.
176 unsigned int tick_precision() const;
179 * Returns period of the graticule time markings.
181 const pv::util::Timestamp& tick_period() const;
184 * Returns the unit of time currently used.
186 util::TimeUnit time_unit() const;
189 * Returns the number of nested parents that this row item owner has.
191 unsigned int depth() const;
193 void zoom(double steps);
194 void zoom(double steps, int offset);
196 void zoom_fit(bool gui_state);
198 void zoom_one_to_one();
201 * Sets the scale and offset.
202 * @param scale The new view scale in seconds per pixel.
203 * @param offset The view time offset in seconds.
205 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
207 set< shared_ptr<pv::data::SignalData> > get_visible_data() const;
209 pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
212 * Enables or disables coloured trace backgrounds. If they're not
213 * coloured then they will use alternating colors.
215 void enable_coloured_bg(bool state);
218 * Returns true if the trace background should be drawn with a coloured background.
220 bool coloured_bg() const;
223 * Enable or disable showing sampling points.
225 void enable_show_sampling_points(bool state);
228 * Enable or disable showing the analog minor grid.
230 void enable_show_analog_minor_grid(bool state);
233 * Returns true if cursors are displayed. false otherwise.
235 bool cursors_shown() const;
238 * Shows or hides the cursors.
240 void show_cursors(bool show = true);
243 * Moves the cursors to a convenient position in the view.
245 void centre_cursors();
248 * Returns a reference to the pair of cursors.
250 shared_ptr<CursorPair> cursors() const;
253 * Adds a new flag at a specified time.
255 void add_flag(const pv::util::Timestamp& time);
258 * Removes a flag from the list.
260 void remove_flag(shared_ptr<Flag> flag);
263 * Gets the list of flags.
265 vector< shared_ptr<Flag> > flags() const;
267 const QPoint& hover_point() const;
269 void restack_all_trace_tree_items();
272 void hover_point_changed();
274 void selection_changed();
276 /// Emitted when the offset changed.
277 void offset_changed();
279 /// Emitted when the scale changed.
280 void scale_changed();
282 void sticky_scrolling_changed(bool state);
284 void always_zoom_to_fit_changed(bool state);
286 /// Emitted when the tick_prefix changed.
287 void tick_prefix_changed();
289 /// Emitted when the tick_precision changed.
290 void tick_precision_changed();
292 /// Emitted when the tick_period changed.
293 void tick_period_changed();
295 /// Emitted when the time_unit changed.
296 void time_unit_changed();
299 void trigger_event(util::Timestamp location);
302 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
305 * Simultaneously sets the zoom and offset.
306 * @param scale The scale to set the view to in seconds per pixel. This
307 * value is clamped between MinScale and MaxScale.
308 * @param offset The offset of the left edge of the view in seconds.
310 void set_zoom(double scale, int offset);
313 * Find a tick spacing and number formatting that does not cause
314 * the values to collide.
316 void calculate_tick_spacing();
318 void adjust_top_margin();
320 void update_scroll();
324 void set_scroll_default();
326 bool header_was_shrunk() const;
328 void expand_header_to_fit();
330 void update_layout();
332 TraceTreeItemOwner* find_prevalent_trace_group(
333 const shared_ptr<sigrok::ChannelGroup> &group,
334 const unordered_map<shared_ptr<data::SignalBase>,
335 shared_ptr<Signal> > &signal_map);
337 static vector< shared_ptr<Trace> >
338 extract_new_traces_for_channels(
339 const vector< shared_ptr<sigrok::Channel> > &channels,
340 const unordered_map<shared_ptr<data::SignalBase>,
341 shared_ptr<Signal> > &signal_map,
342 set< shared_ptr<Trace> > &add_list);
344 void determine_time_unit();
346 bool eventFilter(QObject *object, QEvent *event);
348 void resizeEvent(QResizeEvent *event);
351 void row_item_appearance_changed(bool label, bool content);
352 void time_item_appearance_changed(bool label, bool content);
354 void extents_changed(bool horz, bool vert);
358 void on_splitter_moved();
360 void h_scroll_value_changed(int value);
361 void v_scroll_value_changed();
363 void signals_changed();
364 void capture_state_updated(int state);
366 virtual void perform_delayed_view_update();
368 void process_sticky_events();
370 void on_hover_point_changed();
373 * Sets the 'offset_' member and emits the 'offset_changed'
376 void set_offset(const pv::util::Timestamp& offset);
379 * Sets the 'scale_' member and emits the 'scale_changed'
382 void set_scale(double scale);
385 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
388 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
391 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
394 void set_tick_precision(unsigned tick_precision);
397 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
400 void set_tick_period(const pv::util::Timestamp& tick_period);
403 * Sets the 'time_unit' member and emits the 'time_unit_changed'
406 void set_time_unit(pv::util::TimeUnit time_unit);
409 CustomScrollArea *scrollarea_;
413 QSplitter *splitter_;
415 unordered_set< shared_ptr<Signal> > signals_;
418 vector< shared_ptr<DecodeTrace> > decode_traces_;
421 /// The view time scale in seconds per pixel.
424 /// The view time offset in seconds.
425 pv::util::Timestamp offset_;
427 bool updating_scroll_;
428 bool settings_restored_;
430 bool sticky_scrolling_;
432 bool always_zoom_to_fit_;
434 pv::util::Timestamp tick_period_;
435 pv::util::SIPrefix tick_prefix_;
436 unsigned int tick_precision_;
437 util::TimeUnit time_unit_;
440 shared_ptr<CursorPair> cursors_;
442 list< shared_ptr<Flag> > flags_;
443 char next_flag_text_;
445 vector< shared_ptr<TriggerMarker> > trigger_markers_;
449 unsigned int sticky_events_;
450 QTimer lazy_event_handler_;
452 // This is true when the defaults couldn't be set due to insufficient info
453 bool scroll_needs_defaults_;
455 // A nonzero value indicates the v offset to restore. See View::resizeEvent()
463 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP