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::TimeUnit;
64 using pv::util::Timestamp;
67 using std::dynamic_pointer_cast;
70 using std::lock_guard;
76 using std::set_difference;
77 using std::shared_ptr;
78 using std::unordered_map;
79 using std::unordered_set;
86 const Timestamp View::MaxScale("1e9");
87 const Timestamp View::MinScale("1e-12");
89 const int View::MaxScrollValue = INT_MAX / 2;
90 const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling
92 const int View::ScaleUnits[3] = {1, 2, 5};
94 View::View(Session &session, QWidget *parent) :
95 QAbstractScrollArea(parent),
97 viewport_(new Viewport(*this)),
98 ruler_(new Ruler(*this)),
99 header_(new Header(*this)),
102 updating_scroll_(false),
103 sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
104 always_zoom_to_fit_(false),
106 tick_prefix_(pv::util::SIPrefix::yocto),
108 time_unit_(util::TimeUnit::Time),
109 show_cursors_(false),
110 cursors_(new CursorPair(*this)),
111 next_flag_text_('A'),
114 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
115 this, SLOT(h_scroll_value_changed(int)));
116 connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
117 this, SLOT(v_scroll_value_changed()));
119 connect(&session_, SIGNAL(signals_changed()),
120 this, SLOT(signals_changed()));
121 connect(&session_, SIGNAL(capture_state_changed(int)),
122 this, SLOT(capture_state_updated(int)));
123 connect(&session_, SIGNAL(data_received()),
124 this, SLOT(data_updated()));
125 connect(&session_, SIGNAL(frame_ended()),
126 this, SLOT(data_updated()));
128 connect(header_, SIGNAL(selection_changed()),
129 ruler_, SLOT(clear_selection()));
130 connect(ruler_, SIGNAL(selection_changed()),
131 header_, SLOT(clear_selection()));
133 connect(header_, SIGNAL(selection_changed()),
134 this, SIGNAL(selection_changed()));
135 connect(ruler_, SIGNAL(selection_changed()),
136 this, SIGNAL(selection_changed()));
138 connect(this, SIGNAL(hover_point_changed()),
139 this, SLOT(on_hover_point_changed()));
141 connect(&lazy_event_handler_, SIGNAL(timeout()),
142 this, SLOT(process_sticky_events()));
143 lazy_event_handler_.setSingleShot(true);
145 connect(&delayed_view_updater_, SIGNAL(timeout()),
146 this, SLOT(perform_delayed_view_update()));
147 delayed_view_updater_.setSingleShot(true);
148 delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
150 setViewport(viewport_);
152 viewport_->installEventFilter(this);
153 ruler_->installEventFilter(this);
154 header_->installEventFilter(this);
156 // Trigger the initial event manually. The default device has signals
157 // which were created before this object came into being
160 // make sure the transparent widgets are on the top
164 // Update the zoom state
165 calculate_tick_spacing();
168 Session& View::session()
173 const Session& View::session() const
183 const View* View::view() const
188 Viewport* View::viewport()
193 const Viewport* View::viewport() const
198 vector< shared_ptr<TimeItem> > View::time_items() const
200 const vector<shared_ptr<Flag>> f(flags());
201 vector<shared_ptr<TimeItem>> items(f.begin(), f.end());
202 items.push_back(cursors_);
203 items.push_back(cursors_->first());
204 items.push_back(cursors_->second());
208 double View::scale() const
213 void View::set_scale(double scale)
215 if (scale_ != scale) {
217 Q_EMIT scale_changed();
221 const Timestamp& View::offset() const
226 void View::set_offset(const pv::util::Timestamp& offset)
228 if (offset_ != offset) {
230 Q_EMIT offset_changed();
234 int View::owner_visual_v_offset() const
236 return -verticalScrollBar()->sliderPosition();
239 void View::set_v_offset(int offset)
241 verticalScrollBar()->setSliderPosition(offset);
246 unsigned int View::depth() const
251 pv::util::SIPrefix View::tick_prefix() const
256 void View::set_tick_prefix(pv::util::SIPrefix tick_prefix)
258 if (tick_prefix_ != tick_prefix) {
259 tick_prefix_ = tick_prefix;
260 Q_EMIT tick_prefix_changed();
264 unsigned int View::tick_precision() const
266 return tick_precision_;
269 void View::set_tick_precision(unsigned tick_precision)
271 if (tick_precision_ != tick_precision) {
272 tick_precision_ = tick_precision;
273 Q_EMIT tick_precision_changed();
277 const pv::util::Timestamp& View::tick_period() const
282 void View::set_tick_period(const pv::util::Timestamp& tick_period)
284 if (tick_period_ != tick_period) {
285 tick_period_ = tick_period;
286 Q_EMIT tick_period_changed();
290 TimeUnit View::time_unit() const
295 void View::set_time_unit(pv::util::TimeUnit time_unit)
297 if (time_unit_ != time_unit) {
298 time_unit_ = time_unit;
299 Q_EMIT time_unit_changed();
303 void View::zoom(double steps)
305 zoom(steps, viewport_->width() / 2);
308 void View::zoom(double steps, int offset)
310 set_zoom(scale_ * pow(3.0/2.0, -steps), offset);
313 void View::zoom_fit(bool gui_state)
315 // Act as one-shot when stopped, toggle along with the GUI otherwise
316 if (session_.get_capture_state() == Session::Stopped) {
317 always_zoom_to_fit_ = false;
318 always_zoom_to_fit_changed(false);
320 always_zoom_to_fit_ = gui_state;
321 always_zoom_to_fit_changed(gui_state);
324 const pair<Timestamp, Timestamp> extents = get_time_extents();
325 const Timestamp delta = extents.second - extents.first;
326 if (delta < Timestamp("1e-12"))
330 const int w = viewport_->width();
334 const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
335 set_scale_offset(scale.convert_to<double>(), extents.first);
338 void View::zoom_one_to_one()
340 using pv::data::SignalData;
342 // Make a set of all the visible data objects
343 set< shared_ptr<SignalData> > visible_data = get_visible_data();
344 if (visible_data.empty())
347 double samplerate = 0.0;
348 for (const shared_ptr<SignalData> d : visible_data) {
350 const vector< shared_ptr<Segment> > segments =
352 for (const shared_ptr<Segment> &s : segments)
353 samplerate = max(samplerate, s->samplerate());
356 if (samplerate == 0.0)
360 const int w = viewport_->width();
364 set_zoom(1.0 / samplerate, w / 2);
367 void View::set_scale_offset(double scale, const Timestamp& offset)
369 // Disable sticky scrolling / always zoom to fit when acquisition runs
370 // and user drags the viewport
371 if ((scale_ == scale) && (offset_ != offset) &&
372 (session_.get_capture_state() == Session::Running)) {
374 if (sticky_scrolling_) {
375 sticky_scrolling_ = false;
376 sticky_scrolling_changed(false);
379 if (always_zoom_to_fit_) {
380 always_zoom_to_fit_ = false;
381 always_zoom_to_fit_changed(false);
388 calculate_tick_spacing();
395 set< shared_ptr<SignalData> > View::get_visible_data() const
397 shared_lock<shared_mutex> lock(session().signals_mutex());
398 const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
400 // Make a set of all the visible data objects
401 set< shared_ptr<SignalData> > visible_data;
402 for (const shared_ptr<Signal> sig : sigs)
404 visible_data.insert(sig->data());
409 pair<Timestamp, Timestamp> View::get_time_extents() const
411 boost::optional<Timestamp> left_time, right_time;
412 const set< shared_ptr<SignalData> > visible_data = get_visible_data();
413 for (const shared_ptr<SignalData> d : visible_data)
415 const vector< shared_ptr<Segment> > segments =
417 for (const shared_ptr<Segment> &s : segments) {
418 double samplerate = s->samplerate();
419 samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
421 const Timestamp start_time = s->start_time();
422 left_time = left_time ?
423 min(*left_time, start_time) :
425 right_time = right_time ?
426 max(*right_time, start_time + d->max_sample_count() / samplerate) :
427 start_time + d->max_sample_count() / samplerate;
431 if (!left_time || !right_time)
432 return make_pair(0, 0);
434 assert(*left_time < *right_time);
435 return make_pair(*left_time, *right_time);
438 void View::enable_sticky_scrolling(bool state)
440 sticky_scrolling_ = state;
443 bool View::cursors_shown() const
445 return show_cursors_;
448 void View::show_cursors(bool show)
450 show_cursors_ = show;
455 void View::centre_cursors()
457 const double time_width = scale_ * viewport_->width();
458 cursors_->first()->set_time(offset_ + time_width * 0.4);
459 cursors_->second()->set_time(offset_ + time_width * 0.6);
464 std::shared_ptr<CursorPair> View::cursors() const
469 void View::add_flag(const Timestamp& time)
471 flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
472 QString("%1").arg(next_flag_text_))));
473 next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
474 (next_flag_text_ + 1);
475 time_item_appearance_changed(true, true);
478 void View::remove_flag(std::shared_ptr<Flag> flag)
481 time_item_appearance_changed(true, true);
484 vector< std::shared_ptr<Flag> > View::flags() const
486 vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end());
487 stable_sort(flags.begin(), flags.end(),
488 [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) {
489 return a->time() < b->time();
495 const QPoint& View::hover_point() const
500 void View::update_viewport()
507 void View::restack_all_trace_tree_items()
509 // Make a list of owners that is sorted from deepest first
510 const auto owners = list_row_item_owners();
511 vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end());
512 sort(sorted_owners.begin(), sorted_owners.end(),
513 [](const TraceTreeItemOwner* a, const TraceTreeItemOwner *b) {
514 return a->depth() > b->depth(); });
516 // Restack the items recursively
517 for (auto &o : sorted_owners)
520 // Animate the items to their destination
521 const vector< shared_ptr<TraceTreeItem> > items(
522 list_by_type<TraceTreeItem>());
523 for (const auto &i : items)
524 i->animate_to_layout_v_offset();
527 void View::get_scroll_layout(double &length, Timestamp &offset) const
529 const pair<Timestamp, Timestamp> extents = get_time_extents();
530 length = ((extents.second - extents.first) / scale_).convert_to<double>();
531 offset = offset_ / scale_;
534 void View::set_zoom(double scale, int offset)
536 // Reset the "always zoom to fit" feature as the user changed the zoom
537 always_zoom_to_fit_ = false;
538 always_zoom_to_fit_changed(false);
540 const Timestamp cursor_offset = offset_ + scale_ * offset;
541 const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale);
542 const Timestamp new_offset = cursor_offset - new_scale * offset;
543 set_scale_offset(new_scale.convert_to<double>(), new_offset);
546 void View::calculate_tick_spacing()
548 const double SpacingIncrement = 10.0f;
549 const double MinValueSpacing = 40.0f;
551 // Figure out the highest numeric value visible on a label
552 const QSize areaSize = viewport_->size();
553 const Timestamp max_time = max(fabs(offset_),
554 fabs(offset_ + scale_ * areaSize.width()));
556 double min_width = SpacingIncrement;
557 double label_width, tick_period_width;
559 QFontMetrics m(QApplication::font());
561 // Copies of the member variables with the same name, used in the calculation
562 // and written back afterwards, so that we don't emit signals all the time
563 // during the calculation.
564 pv::util::Timestamp tick_period = tick_period_;
565 pv::util::SIPrefix tick_prefix = tick_prefix_;
566 unsigned tick_precision = tick_precision_;
569 const double min_period = scale_ * min_width;
571 const int order = (int)floorf(log10f(min_period));
572 const pv::util::Timestamp order_decimal =
573 pow(pv::util::Timestamp(10), order);
575 // Allow for a margin of error so that a scale unit of 1 can be used.
576 // Otherwise, for a SU of 1 the tick period will almost always be below
577 // the min_period by a small amount - and thus skipped in favor of 2.
578 // Note: margin assumes that SU[0] and SU[1] contain the smallest values
579 double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0;
580 double tp_with_margin;
581 unsigned int unit = 0;
584 tp_with_margin = order_decimal.convert_to<double>() *
585 (ScaleUnits[unit++] + tp_margin);
586 } while (tp_with_margin < min_period && unit < countof(ScaleUnits));
588 tick_period = order_decimal * ScaleUnits[unit - 1];
589 tick_prefix = static_cast<pv::util::SIPrefix>(
590 (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3);
592 // Precision is the number of fractional digits required, not
593 // taking the prefix into account (and it must never be negative)
594 tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0);
596 tick_period_width = (tick_period / scale_).convert_to<double>();
598 const QString label_text = Ruler::format_time_with_distance(
599 tick_period, max_time, tick_prefix, time_unit_, tick_precision);
601 label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
602 Qt::AlignLeft | Qt::AlignTop, label_text).width() +
605 min_width += SpacingIncrement;
606 } while (tick_period_width < label_width);
608 set_tick_period(tick_period);
609 set_tick_prefix(tick_prefix);
610 set_tick_precision(tick_precision);
613 void View::update_scroll()
617 const QSize areaSize = viewport_->size();
619 // Set the horizontal scroll bar
622 get_scroll_layout(length, offset);
623 length = max(length - areaSize.width(), 0.0);
625 int major_tick_distance = (tick_period_ / scale_).convert_to<int>();
627 horizontalScrollBar()->setPageStep(areaSize.width() / 2);
628 horizontalScrollBar()->setSingleStep(major_tick_distance);
630 updating_scroll_ = true;
632 if (length < MaxScrollValue) {
633 horizontalScrollBar()->setRange(0, length);
634 horizontalScrollBar()->setSliderPosition(offset.convert_to<double>());
636 horizontalScrollBar()->setRange(0, MaxScrollValue);
637 horizontalScrollBar()->setSliderPosition(
638 (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>());
641 updating_scroll_ = false;
643 // Set the vertical scrollbar
644 verticalScrollBar()->setPageStep(areaSize.height());
645 verticalScrollBar()->setSingleStep(areaSize.height() / 8);
647 const pair<int, int> extents = v_extents();
648 verticalScrollBar()->setRange(extents.first - (areaSize.height() / 2),
649 extents.second - (areaSize.height() / 2));
652 void View::update_layout()
655 header_->sizeHint().width() - pv::view::Header::BaselineOffset,
656 ruler_->sizeHint().height(), 0, 0);
657 ruler_->setGeometry(viewport_->x(), 0,
658 viewport_->width(), ruler_->extended_size_hint().height());
659 header_->setGeometry(0, viewport_->y(),
660 header_->extended_size_hint().width(), viewport_->height());
664 void View::paint_label(QPainter &p, const QRect &rect, bool hover)
671 QRectF View::label_rect(const QRectF &rect)
677 TraceTreeItemOwner* View::find_prevalent_trace_group(
678 const shared_ptr<sigrok::ChannelGroup> &group,
679 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
684 unordered_set<TraceTreeItemOwner*> owners;
685 vector<TraceTreeItemOwner*> owner_list;
687 // Make a set and a list of all the owners
688 for (const auto &channel : group->channels()) {
689 const auto iter = signal_map.find(channel);
690 if (iter == signal_map.end())
693 TraceTreeItemOwner *const o = (*iter).second->owner();
694 owner_list.push_back(o);
698 // Iterate through the list of owners, and find the most prevalent
699 size_t max_prevalence = 0;
700 TraceTreeItemOwner *prevalent_owner = nullptr;
701 for (TraceTreeItemOwner *owner : owners) {
702 const size_t prevalence = std::count_if(
703 owner_list.begin(), owner_list.end(),
704 [&](TraceTreeItemOwner *o) { return o == owner; });
705 if (prevalence > max_prevalence) {
706 max_prevalence = prevalence;
707 prevalent_owner = owner;
711 return prevalent_owner;
714 vector< shared_ptr<Trace> > View::extract_new_traces_for_channels(
715 const vector< shared_ptr<sigrok::Channel> > &channels,
716 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
718 set< shared_ptr<Trace> > &add_list)
720 vector< shared_ptr<Trace> > filtered_traces;
722 for (const auto &channel : channels)
724 const auto map_iter = signal_map.find(channel);
725 if (map_iter == signal_map.end())
728 shared_ptr<Trace> trace = (*map_iter).second;
729 const auto list_iter = add_list.find(trace);
730 if (list_iter == add_list.end())
733 filtered_traces.push_back(trace);
734 add_list.erase(list_iter);
737 return filtered_traces;
740 void View::determine_time_unit()
742 // Check whether we know the sample rate and hence can use time as the unit
743 if (time_unit_ == util::TimeUnit::Samples) {
744 shared_lock<shared_mutex> lock(session().signals_mutex());
745 const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
747 // Check all signals but...
748 for (const shared_ptr<Signal> signal : sigs) {
749 const shared_ptr<SignalData> data = signal->data();
751 // ...only check first segment of each
752 const vector< shared_ptr<Segment> > segments = data->segments();
753 if (!segments.empty())
754 if (segments[0]->samplerate()) {
755 set_time_unit(util::TimeUnit::Time);
762 bool View::eventFilter(QObject *object, QEvent *event)
764 const QEvent::Type type = event->type();
765 if (type == QEvent::MouseMove) {
767 const QMouseEvent *const mouse_event = (QMouseEvent*)event;
768 if (object == viewport_)
769 hover_point_ = mouse_event->pos();
770 else if (object == ruler_)
771 hover_point_ = QPoint(mouse_event->x(), 0);
772 else if (object == header_)
773 hover_point_ = QPoint(0, mouse_event->y());
775 hover_point_ = QPoint(-1, -1);
777 hover_point_changed();
779 } else if (type == QEvent::Leave) {
780 hover_point_ = QPoint(-1, -1);
781 hover_point_changed();
784 return QObject::eventFilter(object, event);
787 bool View::viewportEvent(QEvent *e)
791 case QEvent::MouseButtonPress:
792 case QEvent::MouseButtonRelease:
793 case QEvent::MouseButtonDblClick:
794 case QEvent::MouseMove:
796 case QEvent::TouchBegin:
797 case QEvent::TouchUpdate:
798 case QEvent::TouchEnd:
802 return QAbstractScrollArea::viewportEvent(e);
806 void View::resizeEvent(QResizeEvent*)
811 void View::row_item_appearance_changed(bool label, bool content)
819 void View::time_item_appearance_changed(bool label, bool content)
827 void View::extents_changed(bool horz, bool vert)
830 (horz ? TraceTreeItemHExtentsChanged : 0) |
831 (vert ? TraceTreeItemVExtentsChanged : 0);
832 lazy_event_handler_.start();
835 void View::h_scroll_value_changed(int value)
837 if (updating_scroll_)
840 // Disable sticky scrolling when user moves the horizontal scroll bar
841 // during a running acquisition
842 if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) {
843 sticky_scrolling_ = false;
844 sticky_scrolling_changed(false);
847 const int range = horizontalScrollBar()->maximum();
848 if (range < MaxScrollValue)
849 set_offset(scale_ * value);
853 get_scroll_layout(length, offset);
854 set_offset(scale_ * length * value / MaxScrollValue);
861 void View::v_scroll_value_changed()
867 void View::signals_changed()
869 vector< shared_ptr<TraceTreeItem> > new_top_level_items;
871 const auto device = session_.device();
875 shared_ptr<sigrok::Device> sr_dev = device->device();
878 // Make a list of traces that are being added, and a list of traces
879 // that are being removed
880 const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>();
881 const set<shared_ptr<Trace>> prev_traces(
882 prev_trace_list.begin(), prev_trace_list.end());
884 shared_lock<shared_mutex> lock(session_.signals_mutex());
885 const unordered_set< shared_ptr<Signal> > &sigs(session_.signals());
887 set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end());
890 const vector< shared_ptr<DecodeTrace> > decode_traces(
891 session().get_decode_signals());
892 traces.insert(decode_traces.begin(), decode_traces.end());
895 set< shared_ptr<Trace> > add_traces;
896 set_difference(traces.begin(), traces.end(),
897 prev_traces.begin(), prev_traces.end(),
898 inserter(add_traces, add_traces.begin()));
900 set< shared_ptr<Trace> > remove_traces;
901 set_difference(prev_traces.begin(), prev_traces.end(),
902 traces.begin(), traces.end(),
903 inserter(remove_traces, remove_traces.begin()));
905 // Make a look-up table of sigrok Channels to pulseview Signals
906 unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
908 for (const shared_ptr<Signal> &sig : sigs)
909 signal_map[sig->channel()] = sig;
911 // Populate channel groups
912 for (auto entry : sr_dev->channel_groups())
914 const shared_ptr<sigrok::ChannelGroup> &group = entry.second;
916 if (group->channels().size() <= 1)
919 // Find best trace group to add to
920 TraceTreeItemOwner *owner = find_prevalent_trace_group(
923 // If there is no trace group, create one
924 shared_ptr<TraceGroup> new_trace_group;
926 new_trace_group.reset(new TraceGroup());
927 owner = new_trace_group.get();
930 // Extract traces for the trace group, removing them from
932 const vector< shared_ptr<Trace> > new_traces_in_group =
933 extract_new_traces_for_channels(group->channels(),
934 signal_map, add_traces);
936 // Add the traces to the group
937 const pair<int, int> prev_v_extents = owner->v_extents();
938 int offset = prev_v_extents.second - prev_v_extents.first;
939 for (shared_ptr<Trace> trace : new_traces_in_group) {
941 owner->add_child_item(trace);
943 const pair<int, int> extents = trace->v_extents();
944 if (trace->enabled())
945 offset += -extents.first;
946 trace->force_to_v_offset(offset);
947 if (trace->enabled())
948 offset += extents.second;
951 // If this is a new group, enqueue it in the new top level
953 if (!new_traces_in_group.empty() && new_trace_group)
954 new_top_level_items.push_back(new_trace_group);
957 // Enqueue the remaining channels as free ungrouped traces
958 const vector< shared_ptr<Trace> > new_top_level_signals =
959 extract_new_traces_for_channels(sr_dev->channels(),
960 signal_map, add_traces);
961 new_top_level_items.insert(new_top_level_items.end(),
962 new_top_level_signals.begin(), new_top_level_signals.end());
964 // Enqueue any remaining traces i.e. decode traces
965 new_top_level_items.insert(new_top_level_items.end(),
966 add_traces.begin(), add_traces.end());
968 // Remove any removed traces
969 for (shared_ptr<Trace> trace : remove_traces) {
970 TraceTreeItemOwner *const owner = trace->owner();
972 owner->remove_child_item(trace);
975 // Add and position the pending top levels items
976 for (auto item : new_top_level_items) {
977 add_child_item(item);
979 // Position the item after the last present item
980 int offset = v_extents().second;
981 const pair<int, int> extents = item->v_extents();
983 offset += -extents.first;
984 item->force_to_v_offset(offset);
986 offset += extents.second;
995 void View::capture_state_updated(int state)
997 if (state == Session::Running)
998 set_time_unit(util::TimeUnit::Samples);
1000 if (state == Session::Stopped) {
1001 // After acquisition has stopped we need to re-calculate the ticks once
1002 // as it's otherwise done when the user pans or zooms, which is too late
1003 calculate_tick_spacing();
1005 // Reset "always zoom to fit", the acquisition has stopped
1006 if (always_zoom_to_fit_) {
1007 always_zoom_to_fit_ = false;
1008 always_zoom_to_fit_changed(false);
1013 void View::data_updated()
1015 if (always_zoom_to_fit_ || sticky_scrolling_) {
1016 if (!delayed_view_updater_.isActive())
1017 delayed_view_updater_.start();
1019 determine_time_unit();
1022 viewport_->update();
1026 void View::perform_delayed_view_update()
1028 if (always_zoom_to_fit_)
1031 if (sticky_scrolling_) {
1032 // Make right side of the view sticky
1035 get_scroll_layout(length, offset);
1037 const QSize areaSize = viewport_->size();
1038 length = max(length - areaSize.width(), 0.0);
1040 set_offset(scale_ * length);
1043 determine_time_unit();
1046 viewport_->update();
1049 void View::process_sticky_events()
1051 if (sticky_events_ & TraceTreeItemHExtentsChanged)
1053 if (sticky_events_ & TraceTreeItemVExtentsChanged) {
1054 restack_all_trace_tree_items();
1058 // Clear the sticky events
1062 void View::on_hover_point_changed()
1064 for (shared_ptr<TraceTreeItem> r : *this)
1065 r->hover_point_changed();