Example #1
0
void TreeDiagram::computeLayout()
{
  QListIterator<DiagramRow> it(*this);
  DiagramRow *row;
  for (;(row=it.current()) && row->count()<maxTreeWidth;++it) {}
  if (row)
  {
    //printf("computeLayout() list row at %d\n",row->number());
    QListIterator<DiagramItem> rit(*row);
    DiagramItem *di;
    DiagramItem *opi=0;
    int delta=0;
    bool first=TRUE;
    for (;(di=rit.current());++rit)
    {
      DiagramItem *pi=di->parentItem();
      if (pi==opi && !first) { delta-=gridWidth; }
      first = pi!=opi;
      opi=pi;
      di->move(delta,0); // collapse all items in the same
                         // list (except the first)
      di->putInList();
    }
  }

  // re-organize the diagram items
  DiagramItem *root=getFirst()->getFirst();
  while (layoutTree(root,0)) { }

  // move first items of the lists
  if (row)
  {
    QListIterator<DiagramItem> rit(*row);
    DiagramItem *di;
    while ((di=rit.current()))
    {
      DiagramItem *pi=di->parentItem();
      if (pi->getChildren()->count()>1)
      {
        di->move(gridWidth,0);
        while (di && di->parentItem()==pi) { ++rit; di=rit.current(); }
      }
      else
      {
        ++rit;
      }
    }
  }
}
Example #2
0
void TreeDiagram::computeLayout()
{
  DiagramRow *row=first();
  while (row && row->count()<maxTreeWidth) row=next();
  if (row)
  {
    //printf("computeLayout() list row at %d\n",row->number());
    DiagramItem *di=row->first();
    DiagramItem *opi=0;
    int delta=0;
    bool first=TRUE;
    while (di)
    {
      DiagramItem *pi=di->parentItem();
      if (pi==opi && !first) { delta-=gridWidth; }
      first = pi!=opi;
      opi=pi;
      di->move(delta,0); // collapse all items in the same 
                         // list (except the first)
      di->putInList();
      di=row->next();
    }
  }

  // re-organize the diagram items
  DiagramItem *root=getFirst()->getFirst();
  while (layoutTree(root,0)) { }
  
  // move first items of the lists
  if (row)
  {
    DiagramItem *di=row->first();
    while (di)
    {
      DiagramItem *pi=di->parentItem();
      if (pi->getChildren()->count()>1)
      {
        di->move(gridWidth,0);
        while (di && di->parentItem()==pi) di=row->next();
      }
      else
      {
        di=row->next();
      }
    }
  }
}
Example #3
0
bool TreeDiagram::layoutTree(DiagramItem *root,int r)
{
  bool moved=FALSE;
  //printf("layoutTree(%s,%d)\n",root->label().data(),r);

  DiagramItemList *dil=root->getChildren(); 
  if (dil->count()>0)
  {
    uint k;
    int pPos=root->xPos();
    int cPos=root->avgChildPos();
    if (pPos>cPos) // move children
    {
      DiagramRow *row=at(r+1);
      //printf("Moving children %d-%d in row %d\n",
      //    dil->getFirst()->number(),row->count()-1,r+1);
      for (k=dil->getFirst()->number();k<row->count();k++)
        row->at(k)->move(pPos-cPos,0);
      moved=TRUE;
    }
    else if (pPos<cPos) // move parent
    {
      DiagramRow *row=at(r);
      //printf("Moving parents %d-%d in row %d\n",
      //    root->number(),row->count()-1,r);
      for (k=root->number();k<row->count();k++)
        row->at(k)->move(cPos-pPos,0);
      moved=TRUE;
    }

    // recurse to children
    DiagramItem *di=dil->first();
    while (di && !moved && !di->isInList())
    {
      moved = layoutTree(di,r+1);
      di=dil->next();
    }
  }
  return moved;
}