Logo Search packages:      
Sourcecode: kdeadmin version File versions

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

Inserts the specified newItem before or after the specified referenceItem. If referenceItem is 0, the newItem is appended at the topmost level. If referenceItem is not 0, it must be an item that is already in the 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. newItem must not be 0.

Definition at line 1471 of file ktreeview.cpp.

References KTreeViewItem::appendChild(), autoUpdate(), KTreeViewItem::childCount(), KTreeViewItem::childIndex(), KTreeViewItem::getParent(), KTreeViewItem::hasChild(), KTreeViewItem::height(), KTreeViewItem::insertChild(), KTreeViewItem::isVisible(), KTreeViewItem::owner, setAutoUpdate(), 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);
    if (cellHeight() == 0)
    {
       setCellHeight(newItem->height(fontMetrics()));
    }
    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();
      if(autoU && isVisible())
          repaint();
      setAutoUpdate(autoU);
    }
    return true;
}


Generated by  Doxygen 1.6.0   Back to index