Exemple #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;
      }
    }
  }
}
Exemple #2
0
void TreeDiagram::moveChildren(DiagramItem *root,int dx)
{
  DiagramItemList *dil=root->getChildren();
  QListIterator<DiagramItem> it(*dil);
  DiagramItem *di;
  for (;(di=it.current());++it)
  {
    di->move(dx,0);
    moveChildren(di,dx);
  }
}
Exemple #3
0
ClassDiagram::ClassDiagram(ClassDef *root)
{
  clearVisitFlags();
  base  = new TreeDiagram(root,TRUE);
  base->computeLayout();
  clearVisitFlags();
  super = new TreeDiagram(root,FALSE);
  super->computeLayout();
  DiagramItem *baseItem  = base->first()->first();
  DiagramItem *superItem = super->first()->first();
  int xbase  = baseItem->xPos();
  int xsuper = superItem->xPos();
  if (xbase>xsuper)
  {
    superItem->move(xbase-xsuper,0);
    super->moveChildren(superItem,xbase-xsuper);
  }
  else if (xbase<xsuper)
  {
    baseItem->move(xsuper-xbase,0);
    base->moveChildren(baseItem,xsuper-xbase);
  }
}