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
22 #include <libsigrokdecode/libsigrokdecode.h>
33 #include <unordered_set>
35 #include <QApplication>
37 #include <QFontMetrics>
38 #include <QMouseEvent>
41 #include <libsigrokcxx/libsigrokcxx.hpp>
43 #include "decodetrace.hpp"
45 #include "logicsignal.hpp"
48 #include "tracegroup.hpp"
50 #include "viewport.hpp"
52 #include "pv/session.hpp"
53 #include "pv/devices/device.hpp"
54 #include "pv/data/logic.hpp"
55 #include "pv/data/logicsegment.hpp"
56 #include "pv/util.hpp"
58 using boost::shared_lock;
59 using boost::shared_mutex;
61 using pv::data::SignalData;
62 using pv::data::Segment;
63 using pv::util::format_time;
64 using pv::util::TimeUnit;
65 using pv::util::Timestamp;
68 using std::dynamic_pointer_cast;
71 using std::lock_guard;
77 using std::set_difference;
78 using std::shared_ptr;
79 using std::unordered_map;
80 using std::unordered_set;
87 const Timestamp View::MaxScale("1e9");
88 const Timestamp View::MinScale("1e-12");
90 const int View::MaxScrollValue = INT_MAX / 2;
91 const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling
93 const int View::ScaleUnits[3] = {1, 2, 5};
95 View::View(Session &session, QWidget *parent) :
96 QAbstractScrollArea(parent),
98 viewport_(new Viewport(*this)),
99 ruler_(new Ruler(*this)),
100 header_(new Header(*this)),
103 updating_scroll_(false),
104 sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
105 always_zoom_to_fit_(false),
107 tick_prefix_(pv::util::SIPrefix::yocto),
109 time_unit_(util::TimeUnit::Time),
110 show_cursors_(false),
111 cursors_(new CursorPair(*this)),
112 next_flag_text_('A'),
115 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
116 this, SLOT(h_scroll_value_changed(int)));
117 connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
118 this, SLOT(v_scroll_value_changed()));
120 connect(&session_, SIGNAL(signals_changed()),
121 this, SLOT(signals_changed()));
122 connect(&session_, SIGNAL(capture_state_changed(int)),
123 this, SLOT(capture_state_updated(int)));
124 connect(&session_, SIGNAL(data_received()),
125 this, SLOT(data_updated()));
126 connect(&session_, SIGNAL(frame_ended()),
127 this, SLOT(data_updated()));
129 connect(header_, SIGNAL(selection_changed()),
130 ruler_, SLOT(clear_selection()));
131 connect(ruler_, SIGNAL(selection_changed()),
132 header_, SLOT(clear_selection()));
134 connect(header_, SIGNAL(selection_changed()),
135 this, SIGNAL(selection_changed()));
136 connect(ruler_, SIGNAL(selection_changed()),
137 this, SIGNAL(selection_changed()));
139 connect(this, SIGNAL(hover_point_changed()),
140 this, SLOT(on_hover_point_changed()));
142 connect(&lazy_event_handler_, SIGNAL(timeout()),
143 this, SLOT(process_sticky_events()));
144 lazy_event_handler_.setSingleShot(true);
146 connect(&delayed_view_updater_, SIGNAL(timeout()),
147 this, SLOT(perform_delayed_view_update()));
148 delayed_view_updater_.setSingleShot(true);
149 delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
151 setViewport(viewport_);
153 viewport_->installEventFilter(this);
154 ruler_->installEventFilter(this);
155 header_->installEventFilter(this);
157 // Trigger the initial event manually. The default device has signals
158 // which were created before this object came into being
161 // make sure the transparent widgets are on the top
165 // Update the zoom state
166 calculate_tick_spacing();
169 Session& View::session()
174 const Session& View::session() const
184 const View* View::view() const
189 Viewport* View::viewport()
194 const Viewport* View::viewport() const
199 vector< shared_ptr<TimeItem> > View::time_items() const
201 const vector<shared_ptr<Flag>> f(flags());
202 vector<shared_ptr<TimeItem>> items(f.begin(), f.end());
203 items.push_back(cursors_);
204 items.push_back(cursors_->first());
205 items.push_back(cursors_->second());
209 double View::scale() const
214 void View::set_scale(double scale)
216 if (scale_ != scale) {
218 Q_EMIT scale_changed();
222 const Timestamp& View::offset() const
227 void View::set_offset(const pv::util::Timestamp& offset)
229 if (offset_ != offset) {
231 Q_EMIT offset_changed();
235 int View::owner_visual_v_offset() const
237 return -verticalScrollBar()->sliderPosition();
240 void View::set_v_offset(int offset)
242 verticalScrollBar()->setSliderPosition(offset);
247 unsigned int View::depth() const
252 pv::util::SIPrefix View::tick_prefix() const
257 void View::set_tick_prefix(pv::util::SIPrefix tick_prefix)
259 if (tick_prefix_ != tick_prefix) {
260 tick_prefix_ = tick_prefix;
261 Q_EMIT tick_prefix_changed();
265 unsigned int View::tick_precision() const
267 return tick_precision_;
270 void View::set_tick_precision(unsigned tick_precision)
272 if (tick_precision_ != tick_precision) {
273 tick_precision_ = tick_precision;
274 Q_EMIT tick_precision_changed();
278 const pv::util::Timestamp& View::tick_period() const
283 void View::set_tick_period(const pv::util::Timestamp& tick_period)
285 if (tick_period_ != tick_period) {
286 tick_period_ = tick_period;
287 Q_EMIT tick_period_changed();
291 TimeUnit View::time_unit() const
296 void View::set_time_unit(pv::util::TimeUnit time_unit)
298 if (time_unit_ != time_unit) {
299 time_unit_ = time_unit;
300 Q_EMIT time_unit_changed();
304 void View::zoom(double steps)
306 zoom(steps, viewport_->width() / 2);
309 void View::zoom(double steps, int offset)
311 set_zoom(scale_ * pow(3.0/2.0, -steps), offset);
314 void View::zoom_fit(bool gui_state)
316 // Act as one-shot when stopped, toggle along with the GUI otherwise
317 if (session_.get_capture_state() == Session::Stopped) {
318 always_zoom_to_fit_ = false;
319 always_zoom_to_fit_changed(false);
321 always_zoom_to_fit_ = gui_state;
322 always_zoom_to_fit_changed(gui_state);
325 const pair<Timestamp, Timestamp> extents = get_time_extents();
326 const Timestamp delta = extents.second - extents.first;
327 if (delta < Timestamp("1e-12"))
331 const int w = viewport_->width();
335 const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
336 set_scale_offset(scale.convert_to<double>(), extents.first);
339 void View::zoom_one_to_one()
341 using pv::data::SignalData;
343 // Make a set of all the visible data objects
344 set< shared_ptr<SignalData> > visible_data = get_visible_data();
345 if (visible_data.empty())
348 double samplerate = 0.0;
349 for (const shared_ptr<SignalData> d : visible_data) {
351 const vector< shared_ptr<Segment> > segments =
353 for (const shared_ptr<Segment> &s : segments)
354 samplerate = max(samplerate, s->samplerate());
357 if (samplerate == 0.0)
361 const int w = viewport_->width();
365 set_zoom(1.0 / samplerate, w / 2);
368 void View::set_scale_offset(double scale, const Timestamp& offset)
370 // Disable sticky scrolling / always zoom to fit when acquisition runs
371 // and user drags the viewport
372 if ((scale_ == scale) && (offset_ != offset) &&
373 (session_.get_capture_state() == Session::Running)) {
375 if (sticky_scrolling_) {
376 sticky_scrolling_ = false;
377 sticky_scrolling_changed(false);
380 if (always_zoom_to_fit_) {
381 always_zoom_to_fit_ = false;
382 always_zoom_to_fit_changed(false);
389 calculate_tick_spacing();
396 set< shared_ptr<SignalData> > View::get_visible_data() const
398 shared_lock<shared_mutex> lock(session().signals_mutex());
399 const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
401 // Make a set of all the visible data objects
402 set< shared_ptr<SignalData> > visible_data;
403 for (const shared_ptr<Signal> sig : sigs)
405 visible_data.insert(sig->data());
410 pair<Timestamp, Timestamp> View::get_time_extents() const
412 boost::optional<Timestamp> left_time, right_time;
413 const set< shared_ptr<SignalData> > visible_data = get_visible_data();
414 for (const shared_ptr<SignalData> d : visible_data)
416 const vector< shared_ptr<Segment> > segments =
418 for (const shared_ptr<Segment> &s : segments) {
419 double samplerate = s->samplerate();
420 samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
422 const Timestamp start_time = s->start_time();
423 left_time = left_time ?
424 min(*left_time, start_time) :
426 right_time = right_time ?
427 max(*right_time, start_time + d->max_sample_count() / samplerate) :
428 start_time + d->max_sample_count() / samplerate;
432 if (!left_time || !right_time)
433 return make_pair(0, 0);
435 assert(*left_time < *right_time);
436 return make_pair(*left_time, *right_time);
439 void View::enable_sticky_scrolling(bool state)
441 sticky_scrolling_ = state;
444 bool View::cursors_shown() const
446 return show_cursors_;
449 void View::show_cursors(bool show)
451 show_cursors_ = show;
456 void View::centre_cursors()
458 const double time_width = scale_ * viewport_->width();
459 cursors_->first()->set_time(offset_ + time_width * 0.4);
460 cursors_->second()->set_time(offset_ + time_width * 0.6);
465 std::shared_ptr<CursorPair> View::cursors() const
470 void View::add_flag(const Timestamp& time)
472 flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
473 QString("%1").arg(next_flag_text_))));
474 next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
475 (next_flag_text_ + 1);
476 time_item_appearance_changed(true, true);
479 void View::remove_flag(std::shared_ptr<Flag> flag)
482 time_item_appearance_changed(true, true);
485 vector< std::shared_ptr<Flag> > View::flags() const
487 vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end());
488 stable_sort(flags.begin(), flags.end(),
489 [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) {
490 return a->time() < b->time();
496 const QPoint& View::hover_point() const
501 void View::update_viewport()
508 void View::restack_all_row_items()
510 // Make a list of owners that is sorted from deepest first
511 const auto owners = list_row_item_owners();
512 vector< RowItemOwner* > sorted_owners(owners.begin(), owners.end());
513 sort(sorted_owners.begin(), sorted_owners.end(),
514 [](const RowItemOwner* a, const RowItemOwner *b) {
515 return a->depth() > b->depth(); });
517 // Restack the items recursively
518 for (auto &o : sorted_owners)
521 // Animate the items to their destination
522 for (const auto &r : *this)
523 r->animate_to_layout_v_offset();
526 void View::get_scroll_layout(double &length, Timestamp &offset) const
528 const pair<Timestamp, Timestamp> extents = get_time_extents();
529 length = ((extents.second - extents.first) / scale_).convert_to<double>();
530 offset = offset_ / scale_;
533 void View::set_zoom(double scale, int offset)
535 // Reset the "always zoom to fit" feature as the user changed the zoom
536 always_zoom_to_fit_ = false;
537 always_zoom_to_fit_changed(false);
539 const Timestamp cursor_offset = offset_ + scale_ * offset;
540 const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale);
541 const Timestamp new_offset = cursor_offset - new_scale * offset;
542 set_scale_offset(new_scale.convert_to<double>(), new_offset);
545 void View::calculate_tick_spacing()
547 const double SpacingIncrement = 10.0f;
548 const double MinValueSpacing = 40.0f;
550 // Figure out the highest numeric value visible on a label
551 const QSize areaSize = viewport_->size();
552 const Timestamp max_time = max(fabs(offset_),
553 fabs(offset_ + scale_ * areaSize.width()));
555 double min_width = SpacingIncrement;
556 double label_width, tick_period_width;
558 QFontMetrics m(QApplication::font());
560 // Copies of the member variables with the same name, used in the calculation
561 // and written back afterwards, so that we don't emit signals all the time
562 // during the calculation.
563 pv::util::Timestamp tick_period = tick_period_;
564 pv::util::SIPrefix tick_prefix = tick_prefix_;
565 unsigned tick_precision = tick_precision_;
568 const double min_period = scale_ * min_width;
570 const int order = (int)floorf(log10f(min_period));
571 const pv::util::Timestamp order_decimal =
572 pow(pv::util::Timestamp(10), order);
574 // Allow for a margin of error so that a scale unit of 1 can be used.
575 // Otherwise, for a SU of 1 the tick period will almost always be below
576 // the min_period by a small amount - and thus skipped in favor of 2.
577 // Note: margin assumes that SU[0] and SU[1] contain the smallest values
578 double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0;
579 double tp_with_margin;
580 unsigned int unit = 0;
583 tp_with_margin = order_decimal.convert_to<double>() *
584 (ScaleUnits[unit++] + tp_margin);
585 } while (tp_with_margin < min_period && unit < countof(ScaleUnits));
587 tick_period = order_decimal * ScaleUnits[unit - 1];
588 tick_prefix = static_cast<pv::util::SIPrefix>(
589 (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3);
591 // Precision is the number of fractional digits required, not
592 // taking the prefix into account (and it must never be negative)
593 tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0);
595 tick_period_width = (tick_period / scale_).convert_to<double>();
597 const QString label_text =
598 format_time(max_time, tick_prefix, time_unit_, tick_precision);
600 label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
601 Qt::AlignLeft | Qt::AlignTop, label_text).width() +
604 min_width += SpacingIncrement;
605 } while (tick_period_width < label_width);
607 set_tick_period(tick_period);
608 set_tick_prefix(tick_prefix);
609 set_tick_precision(tick_precision);
612 void View::update_scroll()
616 const QSize areaSize = viewport_->size();
618 // Set the horizontal scroll bar
621 get_scroll_layout(length, offset);
622 length = max(length - areaSize.width(), 0.0);
624 int major_tick_distance = (tick_period_ / scale_).convert_to<int>();
626 horizontalScrollBar()->setPageStep(areaSize.width() / 2);
627 horizontalScrollBar()->setSingleStep(major_tick_distance);
629 updating_scroll_ = true;
631 if (length < MaxScrollValue) {
632 horizontalScrollBar()->setRange(0, length);
633 horizontalScrollBar()->setSliderPosition(offset.convert_to<double>());
635 horizontalScrollBar()->setRange(0, MaxScrollValue);
636 horizontalScrollBar()->setSliderPosition(
637 (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>());
640 updating_scroll_ = false;
642 // Set the vertical scrollbar
643 verticalScrollBar()->setPageStep(areaSize.height());
644 verticalScrollBar()->setSingleStep(areaSize.height() / 8);
646 const pair<int, int> extents = v_extents();
647 verticalScrollBar()->setRange(extents.first - (areaSize.height() / 2),
648 extents.second - (areaSize.height() / 2));
651 void View::update_layout()
654 header_->sizeHint().width() - pv::view::Header::BaselineOffset,
655 ruler_->sizeHint().height(), 0, 0);
656 ruler_->setGeometry(viewport_->x(), 0,
657 viewport_->width(), ruler_->extended_size_hint().height());
658 header_->setGeometry(0, viewport_->y(),
659 header_->extended_size_hint().width(), viewport_->height());
663 void View::paint_label(QPainter &p, const QRect &rect, bool hover)
670 QRectF View::label_rect(const QRectF &rect)
676 RowItemOwner* View::find_prevalent_trace_group(
677 const shared_ptr<sigrok::ChannelGroup> &group,
678 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
683 unordered_set<RowItemOwner*> owners;
684 vector<RowItemOwner*> owner_list;
686 // Make a set and a list of all the owners
687 for (const auto &channel : group->channels()) {
688 const auto iter = signal_map.find(channel);
689 if (iter == signal_map.end())
692 RowItemOwner *const o = (*iter).second->owner();
693 owner_list.push_back(o);
697 // Iterate through the list of owners, and find the most prevalent
698 size_t max_prevalence = 0;
699 RowItemOwner *prevalent_owner = nullptr;
700 for (RowItemOwner *owner : owners) {
701 const size_t prevalence = std::count_if(
702 owner_list.begin(), owner_list.end(),
703 [&](RowItemOwner *o) { return o == owner; });
704 if (prevalence > max_prevalence) {
705 max_prevalence = prevalence;
706 prevalent_owner = owner;
710 return prevalent_owner;
713 vector< shared_ptr<Trace> > View::extract_new_traces_for_channels(
714 const vector< shared_ptr<sigrok::Channel> > &channels,
715 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
717 set< shared_ptr<Trace> > &add_list)
719 vector< shared_ptr<Trace> > filtered_traces;
721 for (const auto &channel : channels)
723 const auto map_iter = signal_map.find(channel);
724 if (map_iter == signal_map.end())
727 shared_ptr<Trace> trace = (*map_iter).second;
728 const auto list_iter = add_list.find(trace);
729 if (list_iter == add_list.end())
732 filtered_traces.push_back(trace);
733 add_list.erase(list_iter);
736 return filtered_traces;
739 void View::determine_time_unit()
741 // Check whether we know the sample rate and hence can use time as the unit
742 if (time_unit_ == util::TimeUnit::Samples) {
743 shared_lock<shared_mutex> lock(session().signals_mutex());
744 const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
746 // Check all signals but...
747 for (const shared_ptr<Signal> signal : sigs) {
748 const shared_ptr<SignalData> data = signal->data();
750 // ...only check first segment of each
751 const vector< shared_ptr<Segment> > segments = data->segments();
752 if (!segments.empty())
753 if (segments[0]->samplerate()) {
754 set_time_unit(util::TimeUnit::Time);
761 bool View::eventFilter(QObject *object, QEvent *event)
763 const QEvent::Type type = event->type();
764 if (type == QEvent::MouseMove) {
766 const QMouseEvent *const mouse_event = (QMouseEvent*)event;
767 if (object == viewport_)
768 hover_point_ = mouse_event->pos();
769 else if (object == ruler_)
770 hover_point_ = QPoint(mouse_event->x(), 0);
771 else if (object == header_)
772 hover_point_ = QPoint(0, mouse_event->y());
774 hover_point_ = QPoint(-1, -1);
776 hover_point_changed();
778 } else if (type == QEvent::Leave) {
779 hover_point_ = QPoint(-1, -1);
780 hover_point_changed();
783 return QObject::eventFilter(object, event);
786 bool View::viewportEvent(QEvent *e)
790 case QEvent::MouseButtonPress:
791 case QEvent::MouseButtonRelease:
792 case QEvent::MouseButtonDblClick:
793 case QEvent::MouseMove:
795 case QEvent::TouchBegin:
796 case QEvent::TouchUpdate:
797 case QEvent::TouchEnd:
801 return QAbstractScrollArea::viewportEvent(e);
805 void View::resizeEvent(QResizeEvent*)
810 void View::row_item_appearance_changed(bool label, bool content)
818 void View::time_item_appearance_changed(bool label, bool content)
826 void View::extents_changed(bool horz, bool vert)
829 (horz ? RowItemHExtentsChanged : 0) |
830 (vert ? RowItemVExtentsChanged : 0);
831 lazy_event_handler_.start();
834 void View::h_scroll_value_changed(int value)
836 if (updating_scroll_)
839 // Disable sticky scrolling when user moves the horizontal scroll bar
840 // during a running acquisition
841 if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) {
842 sticky_scrolling_ = false;
843 sticky_scrolling_changed(false);
846 const int range = horizontalScrollBar()->maximum();
847 if (range < MaxScrollValue)
848 set_offset(scale_ * value);
852 get_scroll_layout(length, offset);
853 set_offset(scale_ * length * value / MaxScrollValue);
860 void View::v_scroll_value_changed()
866 void View::signals_changed()
868 vector< shared_ptr<RowItem> > new_top_level_items;
870 const auto device = session_.device();
874 shared_ptr<sigrok::Device> sr_dev = device->device();
877 // Make a list of traces that are being added, and a list of traces
878 // that are being removed
879 const set<shared_ptr<Trace>> prev_traces = list_by_type<Trace>();
881 shared_lock<shared_mutex> lock(session_.signals_mutex());
882 const unordered_set< shared_ptr<Signal> > &sigs(session_.signals());
884 set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end());
887 const vector< shared_ptr<DecodeTrace> > decode_traces(
888 session().get_decode_signals());
889 traces.insert(decode_traces.begin(), decode_traces.end());
892 set< shared_ptr<Trace> > add_traces;
893 set_difference(traces.begin(), traces.end(),
894 prev_traces.begin(), prev_traces.end(),
895 inserter(add_traces, add_traces.begin()));
897 set< shared_ptr<Trace> > remove_traces;
898 set_difference(prev_traces.begin(), prev_traces.end(),
899 traces.begin(), traces.end(),
900 inserter(remove_traces, remove_traces.begin()));
902 // Make a look-up table of sigrok Channels to pulseview Signals
903 unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
905 for (const shared_ptr<Signal> &sig : sigs)
906 signal_map[sig->channel()] = sig;
908 // Populate channel groups
909 for (auto entry : sr_dev->channel_groups())
911 const shared_ptr<sigrok::ChannelGroup> &group = entry.second;
913 if (group->channels().size() <= 1)
916 // Find best trace group to add to
917 RowItemOwner *owner = find_prevalent_trace_group(
920 // If there is no trace group, create one
921 shared_ptr<TraceGroup> new_trace_group;
923 new_trace_group.reset(new TraceGroup());
924 owner = new_trace_group.get();
927 // Extract traces for the trace group, removing them from
929 const vector< shared_ptr<Trace> > new_traces_in_group =
930 extract_new_traces_for_channels(group->channels(),
931 signal_map, add_traces);
933 // Add the traces to the group
934 const pair<int, int> prev_v_extents = owner->v_extents();
935 int offset = prev_v_extents.second - prev_v_extents.first;
936 for (shared_ptr<Trace> trace : new_traces_in_group) {
938 owner->add_child_item(trace);
940 const pair<int, int> extents = trace->v_extents();
941 if (trace->enabled())
942 offset += -extents.first;
943 trace->force_to_v_offset(offset);
944 if (trace->enabled())
945 offset += extents.second;
948 // If this is a new group, enqueue it in the new top level
950 if (!new_traces_in_group.empty() && new_trace_group)
951 new_top_level_items.push_back(new_trace_group);
954 // Enqueue the remaining channels as free ungrouped traces
955 const vector< shared_ptr<Trace> > new_top_level_signals =
956 extract_new_traces_for_channels(sr_dev->channels(),
957 signal_map, add_traces);
958 new_top_level_items.insert(new_top_level_items.end(),
959 new_top_level_signals.begin(), new_top_level_signals.end());
961 // Enqueue any remaining traces i.e. decode traces
962 new_top_level_items.insert(new_top_level_items.end(),
963 add_traces.begin(), add_traces.end());
965 // Remove any removed traces
966 for (shared_ptr<Trace> trace : remove_traces) {
967 RowItemOwner *const owner = trace->owner();
969 owner->remove_child_item(trace);
972 // Add and position the pending top levels items
973 for (auto item : new_top_level_items) {
974 add_child_item(item);
976 // Position the item after the last present item
977 int offset = v_extents().second;
978 const pair<int, int> extents = item->v_extents();
980 offset += -extents.first;
981 item->force_to_v_offset(offset);
983 offset += extents.second;
992 void View::capture_state_updated(int state)
994 if (state == Session::Running)
995 set_time_unit(util::TimeUnit::Samples);
997 if (state == Session::Stopped) {
998 // After acquisition has stopped we need to re-calculate the ticks once
999 // as it's otherwise done when the user pans or zooms, which is too late
1000 calculate_tick_spacing();
1002 // Reset "always zoom to fit", the acquisition has stopped
1003 if (always_zoom_to_fit_) {
1004 always_zoom_to_fit_ = false;
1005 always_zoom_to_fit_changed(false);
1010 void View::data_updated()
1012 if (always_zoom_to_fit_ || sticky_scrolling_) {
1013 if (!delayed_view_updater_.isActive())
1014 delayed_view_updater_.start();
1016 determine_time_unit();
1019 viewport_->update();
1023 void View::perform_delayed_view_update()
1025 if (always_zoom_to_fit_)
1028 if (sticky_scrolling_) {
1029 // Make right side of the view sticky
1032 get_scroll_layout(length, offset);
1034 const QSize areaSize = viewport_->size();
1035 length = max(length - areaSize.width(), 0.0);
1037 set_offset(scale_ * length);
1040 determine_time_unit();
1043 viewport_->update();
1046 void View::process_sticky_events()
1048 if (sticky_events_ & RowItemHExtentsChanged)
1050 if (sticky_events_ & RowItemVExtentsChanged) {
1051 restack_all_row_items();
1055 // Clear the sticky events
1059 void View::on_hover_point_changed()
1061 for (shared_ptr<RowItem> r : *this)
1062 r->hover_point_changed();