Logo Search packages:      
Sourcecode: kdbg version File versions

bool KTreeView::insertItem ( KTreeViewItem referenceItem,
KTreeViewItem newItem,
bool  prefix 
) [protected]

Inserts a new item before or after a reference item. (That is, the new item will become a sibling of the reference item.) If the reference item is 0, the new item is appended at the topmost level. If the reference item is not 0, it must be an item that is already in this KTreeView. Internal data is updated and the display is refreshed as necessary. The inserted item may still be invisible if any of the parents is collapsed.

Parameters:
referenceItem specifies the reference item
newItem specifies the new item; must not be 0.
Returns:
true if the item has been successfully inserted in the tree, otherwise false.
See also:
insertItem

Definition at line 1410 of file ktreeview.cpp.

References KTreeViewItem::appendChild(), KTreeViewItem::childCount(), KTreeViewItem::childIndex(), KTreeViewItem::getParent(), KTreeViewItem::hasChild(), KTreeViewItem::insertChild(), KTreeViewItem::isVisible(), KTreeViewItem::owner, KTreeViewItem::setDrawExpandButton(), KTreeViewItem::setDrawText(), KTreeViewItem::setDrawTree(), and KTreeViewItem::setExpanded().

{
    assert(newItem != 0);
    assert(referenceItem == 0 || referenceItem->owner == this);

    /* set the new item's state */
    newItem->setDrawExpandButton(drawExpandButton);
    newItem->setDrawTree(drawTree);
    newItem->setDrawText(showText);
    KTreeViewItem* parentItem;
    if (referenceItem) {
      parentItem = referenceItem->getParent(); 
      int insertIndex = parentItem->childIndex(referenceItem);
      if (!prefix)
          insertIndex++;
      parentItem->insertChild(insertIndex, newItem);
    }
    else {
      // no reference item, append at end of visible tree
      // need to repaint
      parentItem = treeRoot;
      parentItem->appendChild(newItem);
    }

    // set item expansion
    if (level(newItem) < expansion)
      newItem->setExpanded(true);

    // fix up branch levels of any children
    if (newItem->hasChild())
      fixChildren(newItem);

    // if repaint necessary, do it if visible and auto update
    // enabled
    if (newItem->isVisible() || parentItem->childCount() == 1) {
      bool autoU = autoUpdate();
      setAutoUpdate(FALSE);
      updateVisibleItems();
      setAutoUpdate(autoU);
      if (autoU && isVisible())
          repaint();
    }
    return true;
}


Generated by  Doxygen 1.6.0   Back to index