Project

General

Profile

Actions

Bug #1863

open

WObject::swapChildren(WObject *A, WObject *B)

Added by Jan Hrubeš about 11 years ago. Updated almost 11 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
04/23/2013
Due date:
% Done:

0%

Estimated time:

Description

Hi,

I'm missing a possibility of swapping individual curves in graph to change z-axis order. In Matlab you can simple swap curve handlers in children vector to do this. In wt WObject::children() method returns const vector, so it can't be used directly and children_ is private of WObject. Using WObject::addChild() and WObject::removeChild() seems to be overhead for this. Can simple WObject::swapChildren(WObject *A, WObject *B) do any hurt? Maybe it wouldn't be so simple if the method should be virtual and reimplemented in descendant classes.

It can be useful when reordering widgets too.

// maybe return bool - indication of successful swap
void WObject::swapChildren(WObject *A, WObject *B) 
{
    if ( A->parent_ != this || B->parent_ != this )
        throw WException("WObject::swapChildren() called with non-child");

    std::vector<WObject*>::iterator iBegin, iEnd, iA, iB;
    iBegin = children_->begin();
    iEnd = children_->end();

    // should optimize for one iteration over vector
    iA = std::find(iBegin, iEnd, A);
    iB = std::find(iBegin, iEnd, B);

    if ( (iA != iEnd) && (iB != iEnd) )
    {
        std::iter_swap(iA,iB);
    }

    // some propagation to web page renderer probably needed
}

regards,

Jan

Actions #1

Updated by Koen Deforche almost 11 years ago

  • Status changed from New to Feedback

Hey Jan,

The re-rendering that follows the swapping will be a much larger operation anyway, diminishing the need to performance optimize the swapping step itself?

Koen

Actions

Also available in: Atom PDF