From: Soeren Apel Date: Fri, 14 Jul 2017 06:40:04 +0000 (+0200) Subject: Make restack_items() available to all TraceTreeItemOwners X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=92fdf33184a29c139a532e954cdd573649ad522d;hp=53b652bdde928b42a116e60f5c07800d0bd0b873 Make restack_items() available to all TraceTreeItemOwners Currently, TTIO:restack_items() is empty and only the TraceGroup actually implements it. For this reason, decode traces (and analog traces) are correctly pushing other traces around when their size changes. Top-level traces that are not part of a group however aren't handled properly, simply overlapping when they grow. This patch makes the code available to all TTIO-derived classes, allowing all owners (including View itself) to properly handle this event. --- diff --git a/pv/views/trace/tracegroup.cpp b/pv/views/trace/tracegroup.cpp index 9bcc29e9..daf0c670 100644 --- a/pv/views/trace/tracegroup.cpp +++ b/pv/views/trace/tracegroup.cpp @@ -156,40 +156,6 @@ int TraceGroup::owner_visual_v_offset() const return owner_ ? visual_v_offset() + owner_->owner_visual_v_offset() : 0; } -void TraceGroup::restack_items() -{ - vector> items(trace_tree_child_items()); - - // Sort by the centre line of the extents - stable_sort(items.begin(), items.end(), - [](const shared_ptr &a, const shared_ptr &b) { - const auto aext = a->v_extents(); - const auto bext = b->v_extents(); - return a->layout_v_offset() + - (aext.first + aext.second) / 2 < - b->layout_v_offset() + - (bext.first + bext.second) / 2; - }); - - int total_offset = 0; - for (shared_ptr r : items) { - const pair extents = r->v_extents(); - if (extents.first == 0 && extents.second == 0) - continue; - - // We position disabled traces, so that they are close to the - // animation target positon should they be re-enabled - if (r->enabled()) - total_offset += -extents.first; - - if (!r->dragging()) - r->set_layout_v_offset(total_offset); - - if (r->enabled()) - total_offset += extents.second; - } -} - unsigned int TraceGroup::depth() const { return owner_ ? owner_->depth() + 1 : 0; diff --git a/pv/views/trace/tracegroup.hpp b/pv/views/trace/tracegroup.hpp index 6a72318a..48b1bf23 100644 --- a/pv/views/trace/tracegroup.hpp +++ b/pv/views/trace/tracegroup.hpp @@ -111,8 +111,6 @@ public: */ int owner_visual_v_offset() const; - void restack_items(); - /** * Returns the number of nested parents that this row item owner has. */ diff --git a/pv/views/trace/tracetreeitemowner.cpp b/pv/views/trace/tracetreeitemowner.cpp index a65c6217..d2512332 100644 --- a/pv/views/trace/tracetreeitemowner.cpp +++ b/pv/views/trace/tracetreeitemowner.cpp @@ -112,6 +112,36 @@ pair TraceTreeItemOwner::v_extents() const void TraceTreeItemOwner::restack_items() { + vector> items(trace_tree_child_items()); + + // Sort by the centre line of the extents + stable_sort(items.begin(), items.end(), + [](const shared_ptr &a, const shared_ptr &b) { + const auto aext = a->v_extents(); + const auto bext = b->v_extents(); + return a->layout_v_offset() + + (aext.first + aext.second) / 2 < + b->layout_v_offset() + + (bext.first + bext.second) / 2; + }); + + int total_offset = 0; + for (shared_ptr r : items) { + const pair extents = r->v_extents(); + if (extents.first == 0 && extents.second == 0) + continue; + + // We position disabled traces, so that they are close to the + // animation target positon should they be re-enabled + if (r->enabled()) + total_offset += -extents.first; + + if (!r->dragging()) + r->set_layout_v_offset(total_offset); + + if (r->enabled()) + total_offset += extents.second; + } } } // namespace trace