From: Soeren Apel Date: Sun, 3 Apr 2016 18:35:57 +0000 (+0200) Subject: View: Make signals_changed() more predictable X-Git-Tag: pulseview-0.4.0~323 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=d6128866e740f496a1bb3c9636e188648507fc3a;hp=d9177e6cfafcbb3bdca8f8529e7c74f6a56d0a1a View: Make signals_changed() more predictable Newly created trace groups have their traces restacked immediately to make sure we can rely on the group's v_extents. We no longer unconditionally add trace groups that could actually be empty. The code that adds the new top-level items is more straightforward now. --- diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 9a46bab8..8e48ae44 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -911,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()); @@ -992,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) @@ -1003,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()); @@ -1032,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();