Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

void Inkscape::XML::SimpleNode::addChild ( Node child,
Node after 
) [virtual, inherited]

Insert another node as a child of this node.

When after is NULL, the inserted node will be placed as the first child of this node. after must be a child of this node.

Parameters:
child The node to insert
after The node after which the inserted node should be placed, or NULL

Implements Inkscape::XML::Node.

Definition at line 360 of file simple-node.cpp.

References Inkscape::XML::SimpleNode::_cached_position, Inkscape::XML::SimpleNode::_next, Inkscape::XML::SimpleNode::_parent, Inkscape::XML::Node::document(), Inkscape::XML::Document::logger(), Inkscape::XML::SimpleNode::next(), Inkscape::XML::CompositeNodeObserver::notifyChildAdded(), and Inkscape::XML::NodeObserver::notifyChildAdded().

Referenced by Inkscape::XML::SimpleNode::appendChild().

                                                                {
    g_assert(generic_child);
    g_assert(generic_child->document() == _document);
    g_assert(!generic_ref || generic_ref->document() == _document);

    SimpleNode *child=dynamic_cast<SimpleNode *>(generic_child);
    SimpleNode *ref=dynamic_cast<SimpleNode *>(generic_ref);

    g_assert(!ref || ref->_parent == this);
    g_assert(!child->_parent);

    Debug::EventTracker<DebugAddChild> tracker(*this, *child, ref);

    SimpleNode *next;
    if (ref) {
        next = ref->_next;
        ref->_next = child;
    } else {
        next = _first_child;
        _first_child = child;
    }
    if (!next) { // appending?
        _last_child = child;
        // set cached position if possible when appending
        if (!ref) {
            // if !next && !ref, child is sole child
            child->_cached_position = 0;
            _cached_positions_valid = true;
        } else if (_cached_positions_valid) {
            child->_cached_position = ref->_cached_position + 1;
        }
    } else {
        // invalidate cached positions otherwise
        _cached_positions_valid = false;
    }

    child->_setParent(this);
    child->_next = next;
    _child_count++;

    _document->logger()->notifyChildAdded(*this, *child, ref);
    _observers.notifyChildAdded(*this, *child, ref);
}


Generated by  Doxygen 1.6.0   Back to index