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 <boost/thread/locks.hpp>
37 #include <QApplication>
39 #include <QFontMetrics>
40 #include <QMouseEvent>
43 #include <libsigrokcxx/libsigrokcxx.hpp>
45 #include "decodetrace.hpp"
47 #include "logicsignal.hpp"
50 #include "tracegroup.hpp"
52 #include "viewport.hpp"
54 #include "pv/session.hpp"
55 #include "pv/devices/device.hpp"
56 #include "pv/data/logic.hpp"
57 #include "pv/data/logicsegment.hpp"
58 #include "pv/util.hpp"
60 using boost::shared_lock;
61 using boost::shared_mutex;
63 using pv::data::SignalData;
64 using pv::data::Segment;
65 using pv::util::TimeUnit;
66 using pv::util::Timestamp;
68 using std::back_inserter;
71 using std::dynamic_pointer_cast;
74 using std::lock_guard;
77 using std::make_shared;
81 using std::set_difference;
82 using std::shared_ptr;
83 using std::unordered_map;
84 using std::unordered_set;
91 const Timestamp View::MaxScale("1e9");
92 const Timestamp View::MinScale("1e-12");
94 const int View::MaxScrollValue = INT_MAX / 2;
95 const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling
97 const int View::ScaleUnits[3] = {1, 2, 5};
99 View::View(Session &session, QWidget *parent) :
100 QAbstractScrollArea(parent),
102 viewport_(new Viewport(*this)),
103 ruler_(new Ruler(*this)),
104 header_(new Header(*this)),
107 updating_scroll_(false),
108 sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
109 always_zoom_to_fit_(false),
111 tick_prefix_(pv::util::SIPrefix::yocto),
113 time_unit_(util::TimeUnit::Time),
114 show_cursors_(false),
115 cursors_(new CursorPair(*this)),
116 next_flag_text_('A'),
119 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
120 this, SLOT(h_scroll_value_changed(int)));
121 connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
122 this, SLOT(v_scroll_value_changed()));
124 connect(&session_, SIGNAL(signals_changed()),
125 this, SLOT(signals_changed()));
126 connect(&session_, SIGNAL(capture_state_changed(int)),
127 this, SLOT(capture_state_updated(int)));
128 connect(&session_, SIGNAL(data_received()),
129 this, SLOT(data_updated()));
130 connect(&session_, SIGNAL(frame_ended()),
131 this, SLOT(data_updated()));
133 connect(header_, SIGNAL(selection_changed()),
134 ruler_, SLOT(clear_selection()));
135 connect(ruler_, SIGNAL(selection_changed()),
136 header_, SLOT(clear_selection()));
138 connect(header_, SIGNAL(selection_changed()),
139 this, SIGNAL(selection_changed()));
140 connect(ruler_, SIGNAL(selection_changed()),
141 this, SIGNAL(selection_changed()));
143 connect(this, SIGNAL(hover_point_changed()),
144 this, SLOT(on_hover_point_changed()));
146 connect(&lazy_event_handler_, SIGNAL(timeout()),
147 this, SLOT(process_sticky_events()));
148 lazy_event_handler_.setSingleShot(true);
150 connect(&delayed_view_updater_, SIGNAL(timeout()),
151 this, SLOT(perform_delayed_view_update()));
152 delayed_view_updater_.setSingleShot(true);
153 delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
155 setViewport(viewport_);
157 viewport_->installEventFilter(this);
158 ruler_->installEventFilter(this);
159 header_->installEventFilter(this);
161 // Trigger the initial event manually. The default device has signals
162 // which were created before this object came into being
165 // make sure the transparent widgets are on the top
169 // Update the zoom state
170 calculate_tick_spacing();
173 Session& View::session()
178 const Session& View::session() const
188 const View* View::view() const
193 Viewport* View::viewport()
198 const Viewport* View::viewport() const
203 vector< shared_ptr<TimeItem> > View::time_items() const
205 const vector<shared_ptr<Flag>> f(flags());
206 vector<shared_ptr<TimeItem>> items(f.begin(), f.end());
207 items.push_back(cursors_);
208 items.push_back(cursors_->first());
209 items.push_back(cursors_->second());
213 double View::scale() const
218 void View::set_scale(double scale)
220 if (scale_ != scale) {
222 Q_EMIT scale_changed();
226 const Timestamp& View::offset() const
231 void View::set_offset(const pv::util::Timestamp& offset)
233 if (offset_ != offset) {
235 Q_EMIT offset_changed();
239 int View::owner_visual_v_offset() const
241 return -verticalScrollBar()->sliderPosition();
244 void View::set_v_offset(int offset)
246 verticalScrollBar()->setSliderPosition(offset);
251 unsigned int View::depth() const
256 pv::util::SIPrefix View::tick_prefix() const
261 void View::set_tick_prefix(pv::util::SIPrefix tick_prefix)
263 if (tick_prefix_ != tick_prefix) {
264 tick_prefix_ = tick_prefix;
265 Q_EMIT tick_prefix_changed();
269 unsigned int View::tick_precision() const
271 return tick_precision_;
274 void View::set_tick_precision(unsigned tick_precision)
276 if (tick_precision_ != tick_precision) {
277 tick_precision_ = tick_precision;
278 Q_EMIT tick_precision_changed();
282 const pv::util::Timestamp& View::tick_period() const
287 void View::set_tick_period(const pv::util::Timestamp& tick_period)
289 if (tick_period_ != tick_period) {
290 tick_period_ = tick_period;
291 Q_EMIT tick_period_changed();
295 TimeUnit View::time_unit() const
300 void View::set_time_unit(pv::util::TimeUnit time_unit)
302 if (time_unit_ != time_unit) {
303 time_unit_ = time_unit;
304 Q_EMIT time_unit_changed();
308 void View::zoom(double steps)
310 zoom(steps, viewport_->width() / 2);
313 void View::zoom(double steps, int offset)
315 set_zoom(scale_ * pow(3.0/2.0, -steps), offset);
318 void View::zoom_fit(bool gui_state)
320 // Act as one-shot when stopped, toggle along with the GUI otherwise
321 if (session_.get_capture_state() == Session::Stopped) {
322 always_zoom_to_fit_ = false;
323 always_zoom_to_fit_changed(false);
325 always_zoom_to_fit_ = gui_state;
326 always_zoom_to_fit_changed(gui_state);
329 const pair<Timestamp, Timestamp> extents = get_time_extents();
330 const Timestamp delta = extents.second - extents.first;
331 if (delta < Timestamp("1e-12"))
335 const int w = viewport_->width();
339 const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
340 set_scale_offset(scale.convert_to<double>(), extents.first);
343 void View::zoom_one_to_one()
345 using pv::data::SignalData;
347 // Make a set of all the visible data objects
348 set< shared_ptr<SignalData> > visible_data = get_visible_data();
349 if (visible_data.empty())
352 double samplerate = 0.0;
353 for (const shared_ptr<SignalData> d : visible_data) {
355 const vector< shared_ptr<Segment> > segments =
357 for (const shared_ptr<Segment> &s : segments)
358 samplerate = max(samplerate, s->samplerate());
361 if (samplerate == 0.0)
365 const int w = viewport_->width();
369 set_zoom(1.0 / samplerate, w / 2);
372 void View::set_scale_offset(double scale, const Timestamp& offset)
374 // Disable sticky scrolling / always zoom to fit when acquisition runs
375 // and user drags the viewport
376 if ((scale_ == scale) && (offset_ != offset) &&
377 (session_.get_capture_state() == Session::Running)) {
379 if (sticky_scrolling_) {
380 sticky_scrolling_ = false;
381 sticky_scrolling_changed(false);
384 if (always_zoom_to_fit_) {
385 always_zoom_to_fit_ = false;
386 always_zoom_to_fit_changed(false);
393 calculate_tick_spacing();
400 set< shared_ptr<SignalData> > View::get_visible_data() const
402 const unordered_set< shared_ptr<Signal> > sigs(session().signals());
404 // Make a set of all the visible data objects
405 set< shared_ptr<SignalData> > visible_data;
406 for (const shared_ptr<Signal> sig : sigs)
408 visible_data.insert(sig->data());
413 pair<Timestamp, Timestamp> View::get_time_extents() const
415 boost::optional<Timestamp> left_time, right_time;
416 const set< shared_ptr<SignalData> > visible_data = get_visible_data();
417 for (const shared_ptr<SignalData> d : visible_data)
419 const vector< shared_ptr<Segment> > segments =
421 for (const shared_ptr<Segment> &s : segments) {
422 double samplerate = s->samplerate();
423 samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
425 const Timestamp start_time = s->start_time();
426 left_time = left_time ?
427 min(*left_time, start_time) :
429 right_time = right_time ?
430 max(*right_time, start_time + d->max_sample_count() / samplerate) :
431 start_time + d->max_sample_count() / samplerate;
435 if (!left_time || !right_time)
436 return make_pair(0, 0);
438 assert(*left_time < *right_time);
439 return make_pair(*left_time, *right_time);
442 void View::enable_sticky_scrolling(bool state)
444 sticky_scrolling_ = state;
447 bool View::cursors_shown() const
449 return show_cursors_;
452 void View::show_cursors(bool show)
454 show_cursors_ = show;
459 void View::centre_cursors()
461 const double time_width = scale_ * viewport_->width();
462 cursors_->first()->set_time(offset_ + time_width * 0.4);
463 cursors_->second()->set_time(offset_ + time_width * 0.6);
468 std::shared_ptr<CursorPair> View::cursors() const
473 void View::add_flag(const Timestamp& time)
475 flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
476 QString("%1").arg(next_flag_text_))));
477 next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
478 (next_flag_text_ + 1);
479 time_item_appearance_changed(true, true);
482 void View::remove_flag(std::shared_ptr<Flag> flag)
485 time_item_appearance_changed(true, true);
488 vector< std::shared_ptr<Flag> > View::flags() const
490 vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end());
491 stable_sort(flags.begin(), flags.end(),
492 [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) {
493 return a->time() < b->time();
499 const QPoint& View::hover_point() const
504 void View::update_viewport()
511 void View::restack_all_trace_tree_items()
513 // Make a list of owners that is sorted from deepest first
514 const vector<shared_ptr<TraceTreeItem>> items(
515 list_by_type<TraceTreeItem>());
516 set< TraceTreeItemOwner* > owners;
517 for (const auto &r : items)
518 owners.insert(r->owner());
519 vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end());
520 sort(sorted_owners.begin(), sorted_owners.end(),
521 [](const TraceTreeItemOwner* a, const TraceTreeItemOwner *b) {
522 return a->depth() > b->depth(); });
524 // Restack the items recursively
525 for (auto &o : sorted_owners)
528 // Animate the items to their destination
529 for (const auto &i : items)
530 i->animate_to_layout_v_offset();
533 void View::get_scroll_layout(double &length, Timestamp &offset) const
535 const pair<Timestamp, Timestamp> extents = get_time_extents();
536 length = ((extents.second - extents.first) / scale_).convert_to<double>();
537 offset = offset_ / scale_;
540 void View::set_zoom(double scale, int offset)
542 // Reset the "always zoom to fit" feature as the user changed the zoom
543 always_zoom_to_fit_ = false;
544 always_zoom_to_fit_changed(false);
546 const Timestamp cursor_offset = offset_ + scale_ * offset;
547 const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale);
548 const Timestamp new_offset = cursor_offset - new_scale * offset;
549 set_scale_offset(new_scale.convert_to<double>(), new_offset);
552 void View::calculate_tick_spacing()
554 const double SpacingIncrement = 10.0f;
555 const double MinValueSpacing = 40.0f;
557 // Figure out the highest numeric value visible on a label
558 const QSize areaSize = viewport_->size();
559 const Timestamp max_time = max(fabs(offset_),
560 fabs(offset_ + scale_ * areaSize.width()));
562 double min_width = SpacingIncrement;
563 double label_width, tick_period_width;
565 QFontMetrics m(QApplication::font());
567 // Copies of the member variables with the same name, used in the calculation
568 // and written back afterwards, so that we don't emit signals all the time
569 // during the calculation.
570 pv::util::Timestamp tick_period = tick_period_;
571 pv::util::SIPrefix tick_prefix = tick_prefix_;
572 unsigned tick_precision = tick_precision_;
575 const double min_period = scale_ * min_width;
577 const int order = (int)floorf(log10f(min_period));
578 const pv::util::Timestamp order_decimal =
579 pow(pv::util::Timestamp(10), order);
581 // Allow for a margin of error so that a scale unit of 1 can be used.
582 // Otherwise, for a SU of 1 the tick period will almost always be below
583 // the min_period by a small amount - and thus skipped in favor of 2.
584 // Note: margin assumes that SU[0] and SU[1] contain the smallest values
585 double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0;
586 double tp_with_margin;
587 unsigned int unit = 0;
590 tp_with_margin = order_decimal.convert_to<double>() *
591 (ScaleUnits[unit++] + tp_margin);
592 } while (tp_with_margin < min_period && unit < countof(ScaleUnits));
594 tick_period = order_decimal * ScaleUnits[unit - 1];
595 tick_prefix = static_cast<pv::util::SIPrefix>(
596 (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3);
598 // Precision is the number of fractional digits required, not
599 // taking the prefix into account (and it must never be negative)
600 tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0);
602 tick_period_width = (tick_period / scale_).convert_to<double>();
604 const QString label_text = Ruler::format_time_with_distance(
605 tick_period, max_time, tick_prefix, time_unit_, tick_precision);
607 label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
608 Qt::AlignLeft | Qt::AlignTop, label_text).width() +
611 min_width += SpacingIncrement;
612 } while (tick_period_width < label_width);
614 set_tick_period(tick_period);
615 set_tick_prefix(tick_prefix);
616 set_tick_precision(tick_precision);
619 void View::update_scroll()
623 const QSize areaSize = viewport_->size();
625 // Set the horizontal scroll bar
628 get_scroll_layout(length, offset);
629 length = max(length - areaSize.width(), 0.0);
631 int major_tick_distance = (tick_period_ / scale_).convert_to<int>();
633 horizontalScrollBar()->setPageStep(areaSize.width() / 2);
634 horizontalScrollBar()->setSingleStep(major_tick_distance);
636 updating_scroll_ = true;
638 if (length < MaxScrollValue) {
639 horizontalScrollBar()->setRange(0, length);
640 horizontalScrollBar()->setSliderPosition(offset.convert_to<double>());
642 horizontalScrollBar()->setRange(0, MaxScrollValue);
643 horizontalScrollBar()->setSliderPosition(
644 (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>());
647 updating_scroll_ = false;
649 // Set the vertical scrollbar
650 verticalScrollBar()->setPageStep(areaSize.height());
651 verticalScrollBar()->setSingleStep(areaSize.height() / 8);
653 const pair<int, int> extents = v_extents();
654 verticalScrollBar()->setRange(extents.first - (areaSize.height() / 2),
655 extents.second - (areaSize.height() / 2));
658 void View::update_layout()
661 header_->sizeHint().width() - pv::view::Header::BaselineOffset,
662 ruler_->sizeHint().height(), 0, 0);
663 ruler_->setGeometry(viewport_->x(), 0,
664 viewport_->width(), ruler_->extended_size_hint().height());
665 header_->setGeometry(0, viewport_->y(),
666 header_->extended_size_hint().width(), viewport_->height());
670 void View::paint_label(QPainter &p, const QRect &rect, bool hover)
677 QRectF View::label_rect(const QRectF &rect)
683 TraceTreeItemOwner* View::find_prevalent_trace_group(
684 const shared_ptr<sigrok::ChannelGroup> &group,
685 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
690 unordered_set<TraceTreeItemOwner*> owners;
691 vector<TraceTreeItemOwner*> owner_list;
693 // Make a set and a list of all the owners
694 for (const auto &channel : group->channels()) {
695 const auto iter = signal_map.find(channel);
696 if (iter == signal_map.end())
699 TraceTreeItemOwner *const o = (*iter).second->owner();
700 owner_list.push_back(o);
704 // Iterate through the list of owners, and find the most prevalent
705 size_t max_prevalence = 0;
706 TraceTreeItemOwner *prevalent_owner = nullptr;
707 for (TraceTreeItemOwner *owner : owners) {
708 const size_t prevalence = std::count_if(
709 owner_list.begin(), owner_list.end(),
710 [&](TraceTreeItemOwner *o) { return o == owner; });
711 if (prevalence > max_prevalence) {
712 max_prevalence = prevalence;
713 prevalent_owner = owner;
717 return prevalent_owner;
720 vector< shared_ptr<Trace> > View::extract_new_traces_for_channels(
721 const vector< shared_ptr<sigrok::Channel> > &channels,
722 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
724 set< shared_ptr<Trace> > &add_list)
726 vector< shared_ptr<Trace> > filtered_traces;
728 for (const auto &channel : channels)
730 const auto map_iter = signal_map.find(channel);
731 if (map_iter == signal_map.end())
734 shared_ptr<Trace> trace = (*map_iter).second;
735 const auto list_iter = add_list.find(trace);
736 if (list_iter == add_list.end())
739 filtered_traces.push_back(trace);
740 add_list.erase(list_iter);
743 return filtered_traces;
746 void View::determine_time_unit()
748 // Check whether we know the sample rate and hence can use time as the unit
749 if (time_unit_ == util::TimeUnit::Samples) {
750 const unordered_set< shared_ptr<Signal> > sigs(session().signals());
752 // Check all signals but...
753 for (const shared_ptr<Signal> signal : sigs) {
754 const shared_ptr<SignalData> data = signal->data();
756 // ...only check first segment of each
757 const vector< shared_ptr<Segment> > segments = data->segments();
758 if (!segments.empty())
759 if (segments[0]->samplerate()) {
760 set_time_unit(util::TimeUnit::Time);
767 bool View::eventFilter(QObject *object, QEvent *event)
769 const QEvent::Type type = event->type();
770 if (type == QEvent::MouseMove) {
772 const QMouseEvent *const mouse_event = (QMouseEvent*)event;
773 if (object == viewport_)
774 hover_point_ = mouse_event->pos();
775 else if (object == ruler_)
776 hover_point_ = QPoint(mouse_event->x(), 0);
777 else if (object == header_)
778 hover_point_ = QPoint(0, mouse_event->y());
780 hover_point_ = QPoint(-1, -1);
782 hover_point_changed();
784 } else if (type == QEvent::Leave) {
785 hover_point_ = QPoint(-1, -1);
786 hover_point_changed();
789 return QObject::eventFilter(object, event);
792 bool View::viewportEvent(QEvent *e)
796 case QEvent::MouseButtonPress:
797 case QEvent::MouseButtonRelease:
798 case QEvent::MouseButtonDblClick:
799 case QEvent::MouseMove:
801 case QEvent::TouchBegin:
802 case QEvent::TouchUpdate:
803 case QEvent::TouchEnd:
807 return QAbstractScrollArea::viewportEvent(e);
811 void View::resizeEvent(QResizeEvent*)
816 void View::row_item_appearance_changed(bool label, bool content)
824 void View::time_item_appearance_changed(bool label, bool content)
832 void View::extents_changed(bool horz, bool vert)
835 (horz ? TraceTreeItemHExtentsChanged : 0) |
836 (vert ? TraceTreeItemVExtentsChanged : 0);
837 lazy_event_handler_.start();
840 void View::h_scroll_value_changed(int value)
842 if (updating_scroll_)
845 // Disable sticky scrolling when user moves the horizontal scroll bar
846 // during a running acquisition
847 if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) {
848 sticky_scrolling_ = false;
849 sticky_scrolling_changed(false);
852 const int range = horizontalScrollBar()->maximum();
853 if (range < MaxScrollValue)
854 set_offset(scale_ * value);
858 get_scroll_layout(length, offset);
859 set_offset(scale_ * length * value / MaxScrollValue);
866 void View::v_scroll_value_changed()
872 void View::signals_changed()
874 using sigrok::Channel;
876 vector< shared_ptr<TraceTreeItem> > new_top_level_items;
878 const auto device = session_.device();
882 shared_ptr<sigrok::Device> sr_dev = device->device();
885 const vector< shared_ptr<Channel> > channels(
888 // Make a list of traces that are being added, and a list of traces
889 // that are being removed
890 const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>();
891 const set<shared_ptr<Trace>> prev_traces(
892 prev_trace_list.begin(), prev_trace_list.end());
894 const unordered_set< shared_ptr<Signal> > sigs(session_.signals());
896 set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end());
899 const vector< shared_ptr<DecodeTrace> > decode_traces(
900 session().get_decode_signals());
901 traces.insert(decode_traces.begin(), decode_traces.end());
904 set< shared_ptr<Trace> > add_traces;
905 set_difference(traces.begin(), traces.end(),
906 prev_traces.begin(), prev_traces.end(),
907 inserter(add_traces, add_traces.begin()));
909 set< shared_ptr<Trace> > remove_traces;
910 set_difference(prev_traces.begin(), prev_traces.end(),
911 traces.begin(), traces.end(),
912 inserter(remove_traces, remove_traces.begin()));
914 // Make a look-up table of sigrok Channels to pulseview Signals
915 unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
917 for (const shared_ptr<Signal> &sig : sigs)
918 signal_map[sig->channel()] = sig;
920 // Populate channel groups
921 for (auto entry : sr_dev->channel_groups())
923 const shared_ptr<sigrok::ChannelGroup> &group = entry.second;
925 if (group->channels().size() <= 1)
928 // Find best trace group to add to
929 TraceTreeItemOwner *owner = find_prevalent_trace_group(
932 // If there is no trace group, create one
933 shared_ptr<TraceGroup> new_trace_group;
935 new_trace_group.reset(new TraceGroup());
936 owner = new_trace_group.get();
939 // Extract traces for the trace group, removing them from
941 const vector< shared_ptr<Trace> > new_traces_in_group =
942 extract_new_traces_for_channels(group->channels(),
943 signal_map, add_traces);
945 // Add the traces to the group
946 const pair<int, int> prev_v_extents = owner->v_extents();
947 int offset = prev_v_extents.second - prev_v_extents.first;
948 for (shared_ptr<Trace> trace : new_traces_in_group) {
950 owner->add_child_item(trace);
952 const pair<int, int> extents = trace->v_extents();
953 if (trace->enabled())
954 offset += -extents.first;
955 trace->force_to_v_offset(offset);
956 if (trace->enabled())
957 offset += extents.second;
960 // If this is a new group, enqueue it in the new top level
962 if (!new_traces_in_group.empty() && new_trace_group)
963 new_top_level_items.push_back(new_trace_group);
966 // Enqueue the remaining logic channels in a group
967 vector< shared_ptr<Channel> > logic_channels;
968 copy_if(channels.begin(), channels.end(), back_inserter(logic_channels),
969 [](const shared_ptr<Channel>& c) {
970 return c->type() == sigrok::ChannelType::LOGIC; });
971 const vector< shared_ptr<Trace> > non_grouped_logic_signals =
972 extract_new_traces_for_channels(logic_channels,
973 signal_map, add_traces);
974 const shared_ptr<TraceGroup> non_grouped_trace_group(
975 make_shared<TraceGroup>());
976 for (shared_ptr<Trace> trace : non_grouped_logic_signals)
977 non_grouped_trace_group->add_child_item(trace);
978 new_top_level_items.push_back(non_grouped_trace_group);
980 // Enqueue the remaining channels as free ungrouped traces
981 const vector< shared_ptr<Trace> > new_top_level_signals =
982 extract_new_traces_for_channels(channels,
983 signal_map, add_traces);
984 new_top_level_items.insert(new_top_level_items.end(),
985 new_top_level_signals.begin(), new_top_level_signals.end());
987 // Enqueue any remaining traces i.e. decode traces
988 new_top_level_items.insert(new_top_level_items.end(),
989 add_traces.begin(), add_traces.end());
991 // Remove any removed traces
992 for (shared_ptr<Trace> trace : remove_traces) {
993 TraceTreeItemOwner *const owner = trace->owner();
995 owner->remove_child_item(trace);
998 // Add and position the pending top levels items
999 for (auto item : new_top_level_items) {
1000 add_child_item(item);
1002 // Position the item after the last present item
1003 int offset = v_extents().second;
1004 const pair<int, int> extents = item->v_extents();
1005 if (item->enabled())
1006 offset += -extents.first;
1007 item->force_to_v_offset(offset);
1008 if (item->enabled())
1009 offset += extents.second;
1015 viewport_->update();
1018 void View::capture_state_updated(int state)
1020 if (state == Session::Running)
1021 set_time_unit(util::TimeUnit::Samples);
1023 if (state == Session::Stopped) {
1024 // After acquisition has stopped we need to re-calculate the ticks once
1025 // as it's otherwise done when the user pans or zooms, which is too late
1026 calculate_tick_spacing();
1028 // Reset "always zoom to fit", the acquisition has stopped
1029 if (always_zoom_to_fit_) {
1030 always_zoom_to_fit_ = false;
1031 always_zoom_to_fit_changed(false);
1036 void View::data_updated()
1038 if (always_zoom_to_fit_ || sticky_scrolling_) {
1039 if (!delayed_view_updater_.isActive())
1040 delayed_view_updater_.start();
1042 determine_time_unit();
1045 viewport_->update();
1049 void View::perform_delayed_view_update()
1051 if (always_zoom_to_fit_)
1054 if (sticky_scrolling_) {
1055 // Make right side of the view sticky
1058 get_scroll_layout(length, offset);
1060 const QSize areaSize = viewport_->size();
1061 length = max(length - areaSize.width(), 0.0);
1063 set_offset(scale_ * length);
1066 determine_time_unit();
1069 viewport_->update();
1072 void View::process_sticky_events()
1074 if (sticky_events_ & TraceTreeItemHExtentsChanged)
1076 if (sticky_events_ & TraceTreeItemVExtentsChanged) {
1077 restack_all_trace_tree_items();
1081 // Clear the sticky events
1085 void View::on_hover_point_changed()
1087 const vector<shared_ptr<TraceTreeItem>> trace_tree_items(
1088 list_by_type<TraceTreeItem>());
1089 for (shared_ptr<TraceTreeItem> r : trace_tree_items)
1090 r->hover_point_changed();