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

KDirTreeViewItem * KDirTreeViewItem::locate ( KFileInfo wanted,
bool  lazy = true,
bool  doClone = true,
int  level = -1 
)

Locate the counterpart to an original tree item "wanted" somewhere within this view tree. Returns 0 on failure.

When "lazy" is set, only the open part of the tree is searched. "doClone" specifies whether or not to (deferred) clone nodes that are not cloned yet. This is only used if "lazy" is false. "Level" is just a hint for the current tree level for better performance. It will be calculated automatically if omitted.

Definition at line 1323 of file kdirtreeview.cpp.

References deferredClone(), firstChild(), KDirStat::KFileInfo::hasChildren(), locate(), KDirStat::KFileInfo::name(), next(), KDirStat::KFileInfo::treeLevel(), and KDirStat::KFileInfo::urlPart().

Referenced by deferredClone(), locate(), and KDirStat::KDirTreeView::locate().

{
    if ( lazy && ! isOpen() )
    {
      /*
       * In "lazy" mode, we don't bother searching all the children of this
       * item if they are not visible (i.e. the branch is open) anyway. In
       * this case, cloning that branch is deferred until the branch is
       * actually opened - which in most cases will never happen anyway (most
       * users don't manually open each and every subtree). If and when it
       * happens, we'll probably be fast enough bringing the view tree in
       * sync with the original tree since opening a branch requires manual
       * interaction which is a whole lot slower than copying a couple of
       * objects.
       *
       * Note that this mode is _independent_ of lazy cloning in general: The
       * caller explicitly specifies if he wants to locate an item at all
       * cost, even if that means deferred cloning children whose creation
       * has been delayed until now.
       */

      // kdDebug() << "Too lazy to search for " << wanted << " from " << this << endl;
      return 0;
    }

    if ( _orig == wanted )
    {
      return this;
    }

    if ( level < 0 )
      level = _orig->treeLevel();

    if ( wanted->urlPart( level ) == _orig->name() )
    {
      // Search all children

      KDirTreeViewItem *child = firstChild();

      if ( ! child && _orig->hasChildren() && doClone )
      {
          // kdDebug() << "Deferred cloning " << this << " for children search of " << wanted << endl;
          deferredClone();
          child = firstChild();
      }

      while ( child )
      {
          KDirTreeViewItem *foundChild = child->locate( wanted, lazy, doClone, level+1 );

          if ( foundChild )
            return foundChild;
          else
            child = child->next();
      }
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index