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;
70 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
86 TraceTreeItemHExtentsChanged = 1,
87 TraceTreeItemVExtentsChanged = 2
91 static const pv::util::Timestamp MaxScale;
92 static const pv::util::Timestamp MinScale;
94 static const int MaxScrollValue;
95 static const int MaxViewAutoUpdateRate;
97 static const int ScaleUnits[3];
100 explicit View(Session &session, bool is_main_view=false, QWidget *parent = nullptr);
103 const Session& session() const;
106 * Returns the signals contained in this view.
108 unordered_set< shared_ptr<Signal> > signals() const;
110 virtual void clear_signals();
112 virtual void add_signal(const shared_ptr<Signal> signal);
115 virtual void clear_decode_signals();
117 virtual void add_decode_signal(shared_ptr<data::SignalBase> signalbase);
119 virtual void remove_decode_signal(shared_ptr<data::SignalBase> signalbase);
123 * Returns the view of the owner.
125 virtual View* view();
128 * Returns the view of the owner.
130 virtual const View* view() const;
132 Viewport* viewport();
134 const Viewport* viewport() const;
136 virtual void save_settings(QSettings &settings) const;
138 virtual void restore_settings(QSettings &settings);
141 * Gets a list of time markers.
143 vector< shared_ptr<TimeItem> > time_items() const;
146 * Returns the view time scale in seconds per pixel.
148 double scale() const;
151 * Returns the time offset of the left edge of the view in
154 const pv::util::Timestamp& offset() const;
157 * Returns the vertical scroll offset.
159 int owner_visual_v_offset() const;
162 * Sets the visual v-offset.
164 void set_v_offset(int offset);
167 * Returns the SI prefix to apply to the graticule time markings.
169 pv::util::SIPrefix tick_prefix() const;
172 * Returns the number of fractional digits shown for the time markings.
174 unsigned int tick_precision() const;
177 * Returns period of the graticule time markings.
179 const pv::util::Timestamp& tick_period() const;
182 * Returns the unit of time currently used.
184 util::TimeUnit time_unit() const;
187 * Returns the number of nested parents that this row item owner has.
189 unsigned int depth() const;
191 void zoom(double steps);
192 void zoom(double steps, int offset);
194 void zoom_fit(bool gui_state);
196 void zoom_one_to_one();
199 * Sets the scale and offset.
200 * @param scale The new view scale in seconds per pixel.
201 * @param offset The view time offset in seconds.
203 void set_scale_offset(double scale, const pv::util::Timestamp& offset);
205 set< shared_ptr<pv::data::SignalData> > get_visible_data() const;
207 pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
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 * Enable or disable showing sampling points.
218 void enable_show_sampling_points(bool state);
221 * Returns true if cursors are displayed. false otherwise.
223 bool cursors_shown() const;
226 * Shows or hides the cursors.
228 void show_cursors(bool show = true);
231 * Moves the cursors to a convenient position in the view.
233 void centre_cursors();
236 * Returns a reference to the pair of cursors.
238 shared_ptr<CursorPair> cursors() const;
241 * Adds a new flag at a specified time.
243 void add_flag(const pv::util::Timestamp& time);
246 * Removes a flag from the list.
248 void remove_flag(shared_ptr<Flag> flag);
251 * Gets the list of flags.
253 vector< shared_ptr<Flag> > flags() const;
255 const QPoint& hover_point() const;
257 void restack_all_trace_tree_items();
260 void hover_point_changed();
262 void selection_changed();
264 /// Emitted when the offset changed.
265 void offset_changed();
267 /// Emitted when the scale changed.
268 void scale_changed();
270 void sticky_scrolling_changed(bool state);
272 void always_zoom_to_fit_changed(bool state);
274 /// Emitted when the tick_prefix changed.
275 void tick_prefix_changed();
277 /// Emitted when the tick_precision changed.
278 void tick_precision_changed();
280 /// Emitted when the tick_period changed.
281 void tick_period_changed();
283 /// Emitted when the time_unit changed.
284 void time_unit_changed();
287 void trigger_event(util::Timestamp location);
290 void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;
293 * Simultaneously sets the zoom and offset.
294 * @param scale The scale to set the view to in seconds per pixel. This
295 * value is clamped between MinScale and MaxScale.
296 * @param offset The offset of the left edge of the view in seconds.
298 void set_zoom(double scale, int offset);
301 * Find a tick spacing and number formatting that does not cause
302 * the values to collide.
304 void calculate_tick_spacing();
306 void update_scroll();
310 void set_scroll_default();
312 void update_layout();
314 TraceTreeItemOwner* find_prevalent_trace_group(
315 const shared_ptr<sigrok::ChannelGroup> &group,
316 const unordered_map<shared_ptr<data::SignalBase>,
317 shared_ptr<Signal> > &signal_map);
319 static vector< shared_ptr<Trace> >
320 extract_new_traces_for_channels(
321 const vector< shared_ptr<sigrok::Channel> > &channels,
322 const unordered_map<shared_ptr<data::SignalBase>,
323 shared_ptr<Signal> > &signal_map,
324 set< shared_ptr<Trace> > &add_list);
326 void determine_time_unit();
328 bool eventFilter(QObject *object, QEvent *event);
330 void resizeEvent(QResizeEvent *event);
333 void row_item_appearance_changed(bool label, bool content);
334 void time_item_appearance_changed(bool label, bool content);
336 void extents_changed(bool horz, bool vert);
340 void h_scroll_value_changed(int value);
341 void v_scroll_value_changed();
343 void signals_changed();
344 void capture_state_updated(int state);
347 void perform_delayed_view_update();
349 void process_sticky_events();
351 void on_hover_point_changed();
354 * Sets the 'offset_' member and emits the 'offset_changed'
357 void set_offset(const pv::util::Timestamp& offset);
360 * Sets the 'scale_' member and emits the 'scale_changed'
363 void set_scale(double scale);
366 * Sets the 'tick_prefix_' member and emits the 'tick_prefix_changed'
369 void set_tick_prefix(pv::util::SIPrefix tick_prefix);
372 * Sets the 'tick_precision_' member and emits the 'tick_precision_changed'
375 void set_tick_precision(unsigned tick_precision);
378 * Sets the 'tick_period_' member and emits the 'tick_period_changed'
381 void set_tick_period(const pv::util::Timestamp& tick_period);
384 * Sets the 'time_unit' member and emits the 'time_unit_changed'
387 void set_time_unit(pv::util::TimeUnit time_unit);
394 unordered_set< shared_ptr<Signal> > signals_;
397 vector< shared_ptr<DecodeTrace> > decode_traces_;
400 CustomAbstractScrollArea scrollarea_;
402 /// The view time scale in seconds per pixel.
405 /// The view time offset in seconds.
406 pv::util::Timestamp offset_;
408 bool updating_scroll_;
409 bool sticky_scrolling_;
411 bool always_zoom_to_fit_;
412 QTimer delayed_view_updater_;
414 pv::util::Timestamp tick_period_;
415 pv::util::SIPrefix tick_prefix_;
416 unsigned int tick_precision_;
417 util::TimeUnit time_unit_;
420 shared_ptr<CursorPair> cursors_;
422 list< shared_ptr<Flag> > flags_;
423 char next_flag_text_;
425 vector< shared_ptr<TriggerMarker> > trigger_markers_;
429 unsigned int sticky_events_;
430 QTimer lazy_event_handler_;
432 // This is true when the defaults couldn't be set due to insufficient info
433 bool scroll_needs_defaults_;
435 // A nonzero value indicates the v offset to restore. See View::resizeEvent()
438 bool size_finalized_;
441 } // namespace TraceView
445 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_VIEW_HPP