X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fview.cpp;h=8e48ae444582ffd96b9f3d5af407dcd28b3abe17;hp=15dd05812637d054287b605fc919374e7c150edd;hb=d6128866e740f496a1bb3c9636e188648507fc3a;hpb=1a2288a1b2479be9001fab6ced8385cfc86c3f69 diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 15dd0581..8e48ae44 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -42,7 +42,7 @@ #include -#include "decodetrace.hpp" +#include "analogsignal.hpp" #include "header.hpp" #include "logicsignal.hpp" #include "ruler.hpp" @@ -58,6 +58,10 @@ #include "pv/data/logicsegment.hpp" #include "pv/util.hpp" +#ifdef ENABLE_DECODE +#include "decodetrace.hpp" +#endif + using boost::shared_lock; using boost::shared_mutex; @@ -115,7 +119,7 @@ View::View(Session &session, QWidget *parent) : show_cursors_(false), cursors_(new CursorPair(*this)), next_flag_text_('A'), - trigger_marker_(nullptr), + trigger_markers_(), hover_point_(-1, -1) { connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), @@ -210,8 +214,8 @@ vector< shared_ptr > View::time_items() const items.push_back(cursors_->first()); items.push_back(cursors_->second()); - if (trigger_marker_) - items.push_back(trigger_marker_); + for (auto trigger_marker : trigger_markers_) + items.push_back(trigger_marker); return items; } @@ -408,8 +412,7 @@ pair View::get_time_extents() const { boost::optional left_time, right_time; const set< shared_ptr > visible_data = get_visible_data(); - for (const shared_ptr d : visible_data) - { + for (const shared_ptr d : visible_data) { const vector< shared_ptr > segments = d->segments(); for (const shared_ptr &s : segments) { @@ -438,6 +441,33 @@ void View::enable_sticky_scrolling(bool state) sticky_scrolling_ = state; } +void View::enable_coloured_bg(bool state) +{ + const vector> items( + list_by_type()); + + for (shared_ptr i : items) { + // Can't cast to Trace because it's abstract, so we need to + // check for any derived classes individually + + shared_ptr a = dynamic_pointer_cast(i); + if (a) + a->set_coloured_bg(state); + + shared_ptr l = dynamic_pointer_cast(i); + if (l) + l->set_coloured_bg(state); + +#ifdef ENABLE_DECODE + shared_ptr d = dynamic_pointer_cast(i); + if (d) + d->set_coloured_bg(state); +#endif + } + + viewport_->update(); +} + bool View::cursors_shown() const { return show_cursors_; @@ -521,6 +551,12 @@ void View::restack_all_trace_tree_items() for (auto &o : sorted_owners) o->restack_items(); + // Re-assign background colors + bool next_bgcolour_state = 0; + + for (auto &o : sorted_owners) + next_bgcolour_state = o->reassign_bgcolour_states(next_bgcolour_state); + // Animate the items to their destination for (const auto &i : items) i->animate_to_layout_v_offset(); @@ -528,10 +564,8 @@ void View::restack_all_trace_tree_items() void View::trigger_event(util::Timestamp location) { - if (trigger_marker_) - trigger_marker_->set_time(location); - else - trigger_marker_ = std::shared_ptr(new TriggerMarker(*this, location)); + trigger_markers_.push_back(shared_ptr( + new TriggerMarker(*this, location))); } void View::get_scroll_layout(double &length, Timestamp &offset) const @@ -729,8 +763,7 @@ vector< shared_ptr > View::extract_new_traces_for_channels( { vector< shared_ptr > filtered_traces; - for (const auto &channel : channels) - { + for (const auto &channel : channels) { const auto map_iter = signal_map.find(channel); if (map_iter == signal_map.end()) continue; @@ -793,9 +826,9 @@ bool View::eventFilter(QObject *object, QEvent *event) return QObject::eventFilter(object, event); } -bool View::viewportEvent(QEvent *e) +bool View::viewportEvent(QEvent *event) { - switch(e->type()) { + switch (event->type()) { case QEvent::Paint: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: @@ -806,9 +839,8 @@ bool View::viewportEvent(QEvent *e) case QEvent::TouchUpdate: case QEvent::TouchEnd: return false; - default: - return QAbstractScrollArea::viewportEvent(e); + return QAbstractScrollArea::viewportEvent(event); } } @@ -879,13 +911,11 @@ void View::signals_changed() vector< shared_ptr > new_top_level_items; - const auto device = session_.device(); - if (!device) + if (!session_.device()) return; - shared_ptr sr_dev = device->device(); + shared_ptr sr_dev = session_.device()->device(); assert(sr_dev); - const vector< shared_ptr > channels( sr_dev->channels()); @@ -922,8 +952,7 @@ void View::signals_changed() signal_map[sig->channel()] = sig; // Populate channel groups - for (auto entry : sr_dev->channel_groups()) - { + for (auto entry : sr_dev->channel_groups()) { const shared_ptr &group = entry.second; if (group->channels().size() <= 1) @@ -961,6 +990,9 @@ void View::signals_changed() offset += extents.second; } + // Assign proper vertical offsets to each channel in the group + new_trace_group->restack_items(); + // If this is a new group, enqueue it in the new top level // items list if (!new_traces_in_group.empty() && new_trace_group) @@ -972,19 +1004,23 @@ void View::signals_changed() copy_if(channels.begin(), channels.end(), back_inserter(logic_channels), [](const shared_ptr& c) { return c->type() == sigrok::ChannelType::LOGIC; }); + const vector< shared_ptr > non_grouped_logic_signals = - extract_new_traces_for_channels(logic_channels, - signal_map, add_traces); - const shared_ptr non_grouped_trace_group( - make_shared()); - for (shared_ptr trace : non_grouped_logic_signals) - non_grouped_trace_group->add_child_item(trace); - new_top_level_items.push_back(non_grouped_trace_group); + extract_new_traces_for_channels(logic_channels, signal_map, add_traces); + + if (non_grouped_logic_signals.size() > 0) { + const shared_ptr non_grouped_trace_group( + make_shared()); + for (shared_ptr trace : non_grouped_logic_signals) + non_grouped_trace_group->add_child_item(trace); + + non_grouped_trace_group->restack_items(); + new_top_level_items.push_back(non_grouped_trace_group); + } // Enqueue the remaining channels as free ungrouped traces const vector< shared_ptr > new_top_level_signals = - extract_new_traces_for_channels(channels, - signal_map, add_traces); + extract_new_traces_for_channels(channels, signal_map, add_traces); new_top_level_items.insert(new_top_level_items.end(), new_top_level_signals.begin(), new_top_level_signals.end()); @@ -1001,16 +1037,15 @@ void View::signals_changed() // Add and position the pending top levels items for (auto item : new_top_level_items) { + // Position the item after the last item or at the top if there is none + int offset = v_extents().second; + add_child_item(item); + item->force_to_v_offset(offset); - // Position the item after the last present item - int offset = v_extents().second; const pair extents = item->v_extents(); if (item->enabled()) - offset += -extents.first; - item->force_to_v_offset(offset); - if (item->enabled()) - offset += extents.second; + offset += (extents.second - extents.first); } update_layout(); @@ -1021,9 +1056,12 @@ void View::signals_changed() void View::capture_state_updated(int state) { - if (state == Session::Running) + if (state == Session::Running) { set_time_unit(util::TimeUnit::Samples); + trigger_markers_.clear(); + } + if (state == Session::Stopped) { // After acquisition has stopped we need to re-calculate the ticks once // as it's otherwise done when the user pans or zooms, which is too late