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"
51 #include "triggermarker.hpp"
53 #include "viewport.hpp"
55 #include "pv/session.hpp"
56 #include "pv/devices/device.hpp"
57 #include "pv/data/logic.hpp"
58 #include "pv/data/logicsegment.hpp"
59 #include "pv/util.hpp"
61 using boost::shared_lock;
62 using boost::shared_mutex;
64 using pv::data::SignalData;
65 using pv::data::Segment;
66 using pv::util::TimeUnit;
67 using pv::util::Timestamp;
69 using std::back_inserter;
72 using std::dynamic_pointer_cast;
75 using std::lock_guard;
78 using std::make_shared;
82 using std::set_difference;
83 using std::shared_ptr;
84 using std::unordered_map;
85 using std::unordered_set;
92 const Timestamp View::MaxScale("1e9");
93 const Timestamp View::MinScale("1e-12");
95 const int View::MaxScrollValue = INT_MAX / 2;
96 const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling
98 const int View::ScaleUnits[3] = {1, 2, 5};
100 View::View(Session &session, QWidget *parent) :
101 QAbstractScrollArea(parent),
103 viewport_(new Viewport(*this)),
104 ruler_(new Ruler(*this)),
105 header_(new Header(*this)),
108 updating_scroll_(false),
109 sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
110 always_zoom_to_fit_(false),
112 tick_prefix_(pv::util::SIPrefix::yocto),
114 time_unit_(util::TimeUnit::Time),
115 show_cursors_(false),
116 cursors_(new CursorPair(*this)),
117 next_flag_text_('A'),
121 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
122 this, SLOT(h_scroll_value_changed(int)));
123 connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
124 this, SLOT(v_scroll_value_changed()));
126 connect(&session_, SIGNAL(signals_changed()),
127 this, SLOT(signals_changed()));
128 connect(&session_, SIGNAL(capture_state_changed(int)),
129 this, SLOT(capture_state_updated(int)));
130 connect(&session_, SIGNAL(data_received()),
131 this, SLOT(data_updated()));
132 connect(&session_, SIGNAL(frame_ended()),
133 this, SLOT(data_updated()));
135 connect(header_, SIGNAL(selection_changed()),
136 ruler_, SLOT(clear_selection()));
137 connect(ruler_, SIGNAL(selection_changed()),
138 header_, SLOT(clear_selection()));
140 connect(header_, SIGNAL(selection_changed()),
141 this, SIGNAL(selection_changed()));
142 connect(ruler_, SIGNAL(selection_changed()),
143 this, SIGNAL(selection_changed()));
145 connect(this, SIGNAL(hover_point_changed()),
146 this, SLOT(on_hover_point_changed()));
148 connect(&lazy_event_handler_, SIGNAL(timeout()),
149 this, SLOT(process_sticky_events()));
150 lazy_event_handler_.setSingleShot(true);
152 connect(&delayed_view_updater_, SIGNAL(timeout()),
153 this, SLOT(perform_delayed_view_update()));
154 delayed_view_updater_.setSingleShot(true);
155 delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate);
157 setViewport(viewport_);
159 viewport_->installEventFilter(this);
160 ruler_->installEventFilter(this);
161 header_->installEventFilter(this);
163 // Trigger the initial event manually. The default device has signals
164 // which were created before this object came into being
167 // make sure the transparent widgets are on the top
171 // Update the zoom state
172 calculate_tick_spacing();
175 Session& View::session()
180 const Session& View::session() const
190 const View* View::view() const
195 Viewport* View::viewport()
200 const Viewport* View::viewport() const
205 vector< shared_ptr<TimeItem> > View::time_items() const
207 const vector<shared_ptr<Flag>> f(flags());
208 vector<shared_ptr<TimeItem>> items(f.begin(), f.end());
209 items.push_back(cursors_);
210 items.push_back(cursors_->first());
211 items.push_back(cursors_->second());
213 for (auto trigger_marker : trigger_markers_)
214 items.push_back(trigger_marker);
219 double View::scale() const
224 void View::set_scale(double scale)
226 if (scale_ != scale) {
228 Q_EMIT scale_changed();
232 const Timestamp& View::offset() const
237 void View::set_offset(const pv::util::Timestamp& offset)
239 if (offset_ != offset) {
241 Q_EMIT offset_changed();
245 int View::owner_visual_v_offset() const
247 return -verticalScrollBar()->sliderPosition();
250 void View::set_v_offset(int offset)
252 verticalScrollBar()->setSliderPosition(offset);
257 unsigned int View::depth() const
262 pv::util::SIPrefix View::tick_prefix() const
267 void View::set_tick_prefix(pv::util::SIPrefix tick_prefix)
269 if (tick_prefix_ != tick_prefix) {
270 tick_prefix_ = tick_prefix;
271 Q_EMIT tick_prefix_changed();
275 unsigned int View::tick_precision() const
277 return tick_precision_;
280 void View::set_tick_precision(unsigned tick_precision)
282 if (tick_precision_ != tick_precision) {
283 tick_precision_ = tick_precision;
284 Q_EMIT tick_precision_changed();
288 const pv::util::Timestamp& View::tick_period() const
293 void View::set_tick_period(const pv::util::Timestamp& tick_period)
295 if (tick_period_ != tick_period) {
296 tick_period_ = tick_period;
297 Q_EMIT tick_period_changed();
301 TimeUnit View::time_unit() const
306 void View::set_time_unit(pv::util::TimeUnit time_unit)
308 if (time_unit_ != time_unit) {
309 time_unit_ = time_unit;
310 Q_EMIT time_unit_changed();
314 void View::zoom(double steps)
316 zoom(steps, viewport_->width() / 2);
319 void View::zoom(double steps, int offset)
321 set_zoom(scale_ * pow(3.0/2.0, -steps), offset);
324 void View::zoom_fit(bool gui_state)
326 // Act as one-shot when stopped, toggle along with the GUI otherwise
327 if (session_.get_capture_state() == Session::Stopped) {
328 always_zoom_to_fit_ = false;
329 always_zoom_to_fit_changed(false);
331 always_zoom_to_fit_ = gui_state;
332 always_zoom_to_fit_changed(gui_state);
335 const pair<Timestamp, Timestamp> extents = get_time_extents();
336 const Timestamp delta = extents.second - extents.first;
337 if (delta < Timestamp("1e-12"))
341 const int w = viewport_->width();
345 const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
346 set_scale_offset(scale.convert_to<double>(), extents.first);
349 void View::zoom_one_to_one()
351 using pv::data::SignalData;
353 // Make a set of all the visible data objects
354 set< shared_ptr<SignalData> > visible_data = get_visible_data();
355 if (visible_data.empty())
359 const int w = viewport_->width();
363 set_zoom(1.0 / session_.get_samplerate(), w / 2);
366 void View::set_scale_offset(double scale, const Timestamp& offset)
368 // Disable sticky scrolling / always zoom to fit when acquisition runs
369 // and user drags the viewport
370 if ((scale_ == scale) && (offset_ != offset) &&
371 (session_.get_capture_state() == Session::Running)) {
373 if (sticky_scrolling_) {
374 sticky_scrolling_ = false;
375 sticky_scrolling_changed(false);
378 if (always_zoom_to_fit_) {
379 always_zoom_to_fit_ = false;
380 always_zoom_to_fit_changed(false);
387 calculate_tick_spacing();
394 set< shared_ptr<SignalData> > View::get_visible_data() const
396 const unordered_set< shared_ptr<Signal> > sigs(session().signals());
398 // Make a set of all the visible data objects
399 set< shared_ptr<SignalData> > visible_data;
400 for (const shared_ptr<Signal> sig : sigs)
402 visible_data.insert(sig->data());
407 pair<Timestamp, Timestamp> View::get_time_extents() const
409 boost::optional<Timestamp> left_time, right_time;
410 const set< shared_ptr<SignalData> > visible_data = get_visible_data();
411 for (const shared_ptr<SignalData> d : visible_data) {
412 const vector< shared_ptr<Segment> > segments =
414 for (const shared_ptr<Segment> &s : segments) {
415 double samplerate = s->samplerate();
416 samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
418 const Timestamp start_time = s->start_time();
419 left_time = left_time ?
420 min(*left_time, start_time) :
422 right_time = right_time ?
423 max(*right_time, start_time + d->max_sample_count() / samplerate) :
424 start_time + d->max_sample_count() / samplerate;
428 if (!left_time || !right_time)
429 return make_pair(0, 0);
431 assert(*left_time < *right_time);
432 return make_pair(*left_time, *right_time);
435 void View::enable_sticky_scrolling(bool state)
437 sticky_scrolling_ = state;
440 bool View::cursors_shown() const
442 return show_cursors_;
445 void View::show_cursors(bool show)
447 show_cursors_ = show;
452 void View::centre_cursors()
454 const double time_width = scale_ * viewport_->width();
455 cursors_->first()->set_time(offset_ + time_width * 0.4);
456 cursors_->second()->set_time(offset_ + time_width * 0.6);
461 std::shared_ptr<CursorPair> View::cursors() const
466 void View::add_flag(const Timestamp& time)
468 flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
469 QString("%1").arg(next_flag_text_))));
471 next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
472 (next_flag_text_ + 1);
474 time_item_appearance_changed(true, true);
477 void View::remove_flag(std::shared_ptr<Flag> flag)
480 time_item_appearance_changed(true, true);
483 vector< std::shared_ptr<Flag> > View::flags() const
485 vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end());
486 stable_sort(flags.begin(), flags.end(),
487 [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) {
488 return a->time() < b->time();
494 const QPoint& View::hover_point() const
499 void View::update_viewport()
506 void View::restack_all_trace_tree_items()
508 // Make a list of owners that is sorted from deepest first
509 const vector<shared_ptr<TraceTreeItem>> items(
510 list_by_type<TraceTreeItem>());
511 set< TraceTreeItemOwner* > owners;
512 for (const auto &r : items)
513 owners.insert(r->owner());
514 vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end());
515 sort(sorted_owners.begin(), sorted_owners.end(),
516 [](const TraceTreeItemOwner* a, const TraceTreeItemOwner *b) {
517 return a->depth() > b->depth(); });
519 // Restack the items recursively
520 for (auto &o : sorted_owners)
523 // Animate the items to their destination
524 for (const auto &i : items)
525 i->animate_to_layout_v_offset();
528 void View::trigger_event(util::Timestamp location)
530 trigger_markers_.push_back(shared_ptr<TriggerMarker>(
531 new TriggerMarker(*this, location)));
534 void View::get_scroll_layout(double &length, Timestamp &offset) const
536 const pair<Timestamp, Timestamp> extents = get_time_extents();
537 length = ((extents.second - extents.first) / scale_).convert_to<double>();
538 offset = offset_ / scale_;
541 void View::set_zoom(double scale, int offset)
543 // Reset the "always zoom to fit" feature as the user changed the zoom
544 always_zoom_to_fit_ = false;
545 always_zoom_to_fit_changed(false);
547 const Timestamp cursor_offset = offset_ + scale_ * offset;
548 const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale);
549 const Timestamp new_offset = cursor_offset - new_scale * offset;
550 set_scale_offset(new_scale.convert_to<double>(), new_offset);
553 void View::calculate_tick_spacing()
555 const double SpacingIncrement = 10.0f;
556 const double MinValueSpacing = 40.0f;
558 // Figure out the highest numeric value visible on a label
559 const QSize areaSize = viewport_->size();
560 const Timestamp max_time = max(fabs(offset_),
561 fabs(offset_ + scale_ * areaSize.width()));
563 double min_width = SpacingIncrement;
564 double label_width, tick_period_width;
566 QFontMetrics m(QApplication::font());
568 // Copies of the member variables with the same name, used in the calculation
569 // and written back afterwards, so that we don't emit signals all the time
570 // during the calculation.
571 pv::util::Timestamp tick_period = tick_period_;
572 pv::util::SIPrefix tick_prefix = tick_prefix_;
573 unsigned tick_precision = tick_precision_;
576 const double min_period = scale_ * min_width;
578 const int order = (int)floorf(log10f(min_period));
579 const pv::util::Timestamp order_decimal =
580 pow(pv::util::Timestamp(10), order);
582 // Allow for a margin of error so that a scale unit of 1 can be used.
583 // Otherwise, for a SU of 1 the tick period will almost always be below
584 // the min_period by a small amount - and thus skipped in favor of 2.
585 // Note: margin assumes that SU[0] and SU[1] contain the smallest values
586 double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0;
587 double tp_with_margin;
588 unsigned int unit = 0;
591 tp_with_margin = order_decimal.convert_to<double>() *
592 (ScaleUnits[unit++] + tp_margin);
593 } while (tp_with_margin < min_period && unit < countof(ScaleUnits));
595 tick_period = order_decimal * ScaleUnits[unit - 1];
596 tick_prefix = static_cast<pv::util::SIPrefix>(
597 (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3);
599 // Precision is the number of fractional digits required, not
600 // taking the prefix into account (and it must never be negative)
601 tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0);
603 tick_period_width = (tick_period / scale_).convert_to<double>();
605 const QString label_text = Ruler::format_time_with_distance(
606 tick_period, max_time, tick_prefix, time_unit_, tick_precision);
608 label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
609 Qt::AlignLeft | Qt::AlignTop, label_text).width() +
612 min_width += SpacingIncrement;
613 } while (tick_period_width < label_width);
615 set_tick_period(tick_period);
616 set_tick_prefix(tick_prefix);
617 set_tick_precision(tick_precision);
620 void View::update_scroll()
624 const QSize areaSize = viewport_->size();
626 // Set the horizontal scroll bar
629 get_scroll_layout(length, offset);
630 length = max(length - areaSize.width(), 0.0);
632 int major_tick_distance = (tick_period_ / scale_).convert_to<int>();
634 horizontalScrollBar()->setPageStep(areaSize.width() / 2);
635 horizontalScrollBar()->setSingleStep(major_tick_distance);
637 updating_scroll_ = true;
639 if (length < MaxScrollValue) {
640 horizontalScrollBar()->setRange(0, length);
641 horizontalScrollBar()->setSliderPosition(offset.convert_to<double>());
643 horizontalScrollBar()->setRange(0, MaxScrollValue);
644 horizontalScrollBar()->setSliderPosition(
645 (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>());
648 updating_scroll_ = false;
650 // Set the vertical scrollbar
651 verticalScrollBar()->setPageStep(areaSize.height());
652 verticalScrollBar()->setSingleStep(areaSize.height() / 8);
654 const pair<int, int> extents = v_extents();
655 verticalScrollBar()->setRange(extents.first - (areaSize.height() / 2),
656 extents.second - (areaSize.height() / 2));
659 void View::update_layout()
662 header_->sizeHint().width() - pv::view::Header::BaselineOffset,
663 ruler_->sizeHint().height(), 0, 0);
664 ruler_->setGeometry(viewport_->x(), 0,
665 viewport_->width(), ruler_->extended_size_hint().height());
666 header_->setGeometry(0, viewport_->y(),
667 header_->extended_size_hint().width(), viewport_->height());
671 void View::paint_label(QPainter &p, const QRect &rect, bool hover)
678 QRectF View::label_rect(const QRectF &rect)
684 TraceTreeItemOwner* View::find_prevalent_trace_group(
685 const shared_ptr<sigrok::ChannelGroup> &group,
686 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
691 unordered_set<TraceTreeItemOwner*> owners;
692 vector<TraceTreeItemOwner*> owner_list;
694 // Make a set and a list of all the owners
695 for (const auto &channel : group->channels()) {
696 const auto iter = signal_map.find(channel);
697 if (iter == signal_map.end())
700 TraceTreeItemOwner *const o = (*iter).second->owner();
701 owner_list.push_back(o);
705 // Iterate through the list of owners, and find the most prevalent
706 size_t max_prevalence = 0;
707 TraceTreeItemOwner *prevalent_owner = nullptr;
708 for (TraceTreeItemOwner *owner : owners) {
709 const size_t prevalence = std::count_if(
710 owner_list.begin(), owner_list.end(),
711 [&](TraceTreeItemOwner *o) { return o == owner; });
712 if (prevalence > max_prevalence) {
713 max_prevalence = prevalence;
714 prevalent_owner = owner;
718 return prevalent_owner;
721 vector< shared_ptr<Trace> > View::extract_new_traces_for_channels(
722 const vector< shared_ptr<sigrok::Channel> > &channels,
723 const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
725 set< shared_ptr<Trace> > &add_list)
727 vector< shared_ptr<Trace> > filtered_traces;
729 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:
806 return QAbstractScrollArea::viewportEvent(e);
810 void View::resizeEvent(QResizeEvent*)
815 void View::row_item_appearance_changed(bool label, bool content)
823 void View::time_item_appearance_changed(bool label, bool content)
831 void View::extents_changed(bool horz, bool vert)
834 (horz ? TraceTreeItemHExtentsChanged : 0) |
835 (vert ? TraceTreeItemVExtentsChanged : 0);
836 lazy_event_handler_.start();
839 void View::h_scroll_value_changed(int value)
841 if (updating_scroll_)
844 // Disable sticky scrolling when user moves the horizontal scroll bar
845 // during a running acquisition
846 if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) {
847 sticky_scrolling_ = false;
848 sticky_scrolling_changed(false);
851 const int range = horizontalScrollBar()->maximum();
852 if (range < MaxScrollValue)
853 set_offset(scale_ * value);
857 get_scroll_layout(length, offset);
858 set_offset(scale_ * length * value / MaxScrollValue);
865 void View::v_scroll_value_changed()
871 void View::signals_changed()
873 using sigrok::Channel;
875 vector< shared_ptr<TraceTreeItem> > new_top_level_items;
877 const auto device = session_.device();
881 shared_ptr<sigrok::Device> sr_dev = device->device();
884 const vector< shared_ptr<Channel> > channels(
887 // Make a list of traces that are being added, and a list of traces
888 // that are being removed
889 const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>();
890 const set<shared_ptr<Trace>> prev_traces(
891 prev_trace_list.begin(), prev_trace_list.end());
893 const unordered_set< shared_ptr<Signal> > sigs(session_.signals());
895 set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end());
898 const vector< shared_ptr<DecodeTrace> > decode_traces(
899 session().get_decode_signals());
900 traces.insert(decode_traces.begin(), decode_traces.end());
903 set< shared_ptr<Trace> > add_traces;
904 set_difference(traces.begin(), traces.end(),
905 prev_traces.begin(), prev_traces.end(),
906 inserter(add_traces, add_traces.begin()));
908 set< shared_ptr<Trace> > remove_traces;
909 set_difference(prev_traces.begin(), prev_traces.end(),
910 traces.begin(), traces.end(),
911 inserter(remove_traces, remove_traces.begin()));
913 // Make a look-up table of sigrok Channels to pulseview Signals
914 unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
916 for (const shared_ptr<Signal> &sig : sigs)
917 signal_map[sig->channel()] = sig;
919 // Populate channel groups
920 for (auto entry : sr_dev->channel_groups()) {
921 const shared_ptr<sigrok::ChannelGroup> &group = entry.second;
923 if (group->channels().size() <= 1)
926 // Find best trace group to add to
927 TraceTreeItemOwner *owner = find_prevalent_trace_group(
930 // If there is no trace group, create one
931 shared_ptr<TraceGroup> new_trace_group;
933 new_trace_group.reset(new TraceGroup());
934 owner = new_trace_group.get();
937 // Extract traces for the trace group, removing them from
939 const vector< shared_ptr<Trace> > new_traces_in_group =
940 extract_new_traces_for_channels(group->channels(),
941 signal_map, add_traces);
943 // Add the traces to the group
944 const pair<int, int> prev_v_extents = owner->v_extents();
945 int offset = prev_v_extents.second - prev_v_extents.first;
946 for (shared_ptr<Trace> trace : new_traces_in_group) {
948 owner->add_child_item(trace);
950 const pair<int, int> extents = trace->v_extents();
951 if (trace->enabled())
952 offset += -extents.first;
953 trace->force_to_v_offset(offset);
954 if (trace->enabled())
955 offset += extents.second;
958 // If this is a new group, enqueue it in the new top level
960 if (!new_traces_in_group.empty() && new_trace_group)
961 new_top_level_items.push_back(new_trace_group);
964 // Enqueue the remaining logic channels in a group
965 vector< shared_ptr<Channel> > logic_channels;
966 copy_if(channels.begin(), channels.end(), back_inserter(logic_channels),
967 [](const shared_ptr<Channel>& c) {
968 return c->type() == sigrok::ChannelType::LOGIC; });
969 const vector< shared_ptr<Trace> > non_grouped_logic_signals =
970 extract_new_traces_for_channels(logic_channels,
971 signal_map, add_traces);
972 const shared_ptr<TraceGroup> non_grouped_trace_group(
973 make_shared<TraceGroup>());
974 for (shared_ptr<Trace> trace : non_grouped_logic_signals)
975 non_grouped_trace_group->add_child_item(trace);
976 new_top_level_items.push_back(non_grouped_trace_group);
978 // Enqueue the remaining channels as free ungrouped traces
979 const vector< shared_ptr<Trace> > new_top_level_signals =
980 extract_new_traces_for_channels(channels,
981 signal_map, add_traces);
982 new_top_level_items.insert(new_top_level_items.end(),
983 new_top_level_signals.begin(), new_top_level_signals.end());
985 // Enqueue any remaining traces i.e. decode traces
986 new_top_level_items.insert(new_top_level_items.end(),
987 add_traces.begin(), add_traces.end());
989 // Remove any removed traces
990 for (shared_ptr<Trace> trace : remove_traces) {
991 TraceTreeItemOwner *const owner = trace->owner();
993 owner->remove_child_item(trace);
996 // Add and position the pending top levels items
997 for (auto item : new_top_level_items) {
998 add_child_item(item);
1000 // Position the item after the last present item
1001 int offset = v_extents().second;
1002 const pair<int, int> extents = item->v_extents();
1003 if (item->enabled())
1004 offset += -extents.first;
1005 item->force_to_v_offset(offset);
1006 if (item->enabled())
1007 offset += extents.second;
1013 viewport_->update();
1016 void View::capture_state_updated(int state)
1018 if (state == Session::Running) {
1019 set_time_unit(util::TimeUnit::Samples);
1021 trigger_markers_.clear();
1024 if (state == Session::Stopped) {
1025 // After acquisition has stopped we need to re-calculate the ticks once
1026 // as it's otherwise done when the user pans or zooms, which is too late
1027 calculate_tick_spacing();
1029 // Reset "always zoom to fit", the acquisition has stopped
1030 if (always_zoom_to_fit_) {
1031 always_zoom_to_fit_ = false;
1032 always_zoom_to_fit_changed(false);
1037 void View::data_updated()
1039 if (always_zoom_to_fit_ || sticky_scrolling_) {
1040 if (!delayed_view_updater_.isActive())
1041 delayed_view_updater_.start();
1043 determine_time_unit();
1046 viewport_->update();
1050 void View::perform_delayed_view_update()
1052 if (always_zoom_to_fit_)
1055 if (sticky_scrolling_) {
1056 // Make right side of the view sticky
1059 get_scroll_layout(length, offset);
1061 const QSize areaSize = viewport_->size();
1062 length = max(length - areaSize.width(), 0.0);
1064 set_offset(scale_ * length);
1067 determine_time_unit();
1070 viewport_->update();
1073 void View::process_sticky_events()
1075 if (sticky_events_ & TraceTreeItemHExtentsChanged)
1077 if (sticky_events_ & TraceTreeItemVExtentsChanged) {
1078 restack_all_trace_tree_items();
1082 // Clear the sticky events
1086 void View::on_hover_point_changed()
1088 const vector<shared_ptr<TraceTreeItem>> trace_tree_items(
1089 list_by_type<TraceTreeItem>());
1090 for (shared_ptr<TraceTreeItem> r : trace_tree_items)
1091 r->hover_point_changed();