My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | List of all members
TreeDiagram Class Reference
Inheritance diagram for TreeDiagram:

Public Member Functions

 TreeDiagram (ClassDef *root, bool doBases)
 
 ~TreeDiagram ()
 
void computeLayout ()
 
uint computeRows ()
 
void moveChildren (DiagramItem *root, int dx)
 
void computeExtremes (uint *labelWidth, uint *xpos)
 
void drawBoxes (FTextStream &t, Image *image, bool doBase, bool bitmap, uint baseRows, uint superRows, uint cellWidth, uint cellHeight, QCString relPath="", bool generateMap=TRUE)
 
void drawConnectors (FTextStream &t, Image *image, bool doBase, bool bitmap, uint baseRows, uint superRows, uint cellWidth, uint cellheight)
 

Private Member Functions

bool layoutTree (DiagramItem *root, int row)
 
TreeDiagramoperator= (const TreeDiagram &)
 
 TreeDiagram (const TreeDiagram &)
 

Detailed Description

Class represeting the tree layout for the built-in class diagram.

Definition at line 111 of file diagram.cpp.

Constructor & Destructor Documentation

TreeDiagram::TreeDiagram ( ClassDef root,
bool  doBases 
)

Definition at line 409 of file diagram.cpp.

References DiagramRow::insertClass(), Normal, and Public.

{
setAutoDelete(TRUE);
DiagramRow *row=new DiagramRow(this,0);
append(row);
row->insertClass(0,root,doBases,Public,Normal,0);
}
TreeDiagram::~TreeDiagram ( )

Definition at line 417 of file diagram.cpp.

{
}
TreeDiagram::TreeDiagram ( const TreeDiagram )
private

Member Function Documentation

void TreeDiagram::computeExtremes ( uint *  labelWidth,
uint *  xpos 
)

Definition at line 555 of file diagram.cpp.

References DiagramItem::isInList(), DiagramItem::label(), Image::stringLength, and DiagramItem::xPos().

Referenced by ClassDiagram::writeFigure(), and ClassDiagram::writeImage().

{
uint ml=0,mx=0;
QListIterator<DiagramRow> it(*this);
bool done=FALSE;
for (;(dr=it.current()) && !done;++it)
{
QListIterator<DiagramItem> rit(*dr);
for (;(di=rit.current());++rit)
{
if (di->isInList()) done=TRUE;
if (maxXPos) mx=QMAX(mx,(uint)di->xPos());
if (maxLabelLen) ml=QMAX(ml,Image::stringLength(di->label()));
}
}
if (maxLabelLen) *maxLabelLen=ml;
if (maxXPos) *maxXPos=mx;
}
void TreeDiagram::computeLayout ( )

Definition at line 475 of file diagram.cpp.

References DiagramItem::getChildren(), gridWidth, layoutTree(), maxTreeWidth, DiagramItem::move(), DiagramItem::parentItem(), and DiagramItem::putInList().

Referenced by ClassDiagram::ClassDiagram().

{
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 *opi=0;
int delta=0;
bool first=TRUE;
for (;(di=rit.current());++rit)
{
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);
while ((di=rit.current()))
{
if (pi->getChildren()->count()>1)
{
di->move(gridWidth,0);
while (di && di->parentItem()==pi) { ++rit; di=rit.current(); }
}
else
{
++rit;
}
}
}
}
uint TreeDiagram::computeRows ( )

Definition at line 525 of file diagram.cpp.

References DiagramItem::parentItem().

Referenced by ClassDiagram::writeFigure(), and ClassDiagram::writeImage().

{
//printf("TreeDiagram::computeRows()=%d\n",count());
int count=0;
QListIterator<DiagramRow> it(*this);
DiagramRow *row;
for (;(row=it.current()) && !row->getFirst()->isInList();++it)
{
count++;
}
//printf("count=%d row=%p\n",count,row);
if (row)
{
int maxListLen=0;
int curListLen=0;
DiagramItem *opi=0;
QListIterator<DiagramItem> rit(*row);
for (;(di=rit.current());++rit)
{
if (di->parentItem()!=opi) curListLen=1; else curListLen++;
if (curListLen>maxListLen) maxListLen=curListLen;
opi=di->parentItem();
}
//printf("maxListLen=%d\n",maxListLen);
count+=maxListLen;
}
return count;
}
void TreeDiagram::drawBoxes ( FTextStream t,
Image image,
bool  doBase,
bool  bitmap,
uint  baseRows,
uint  superRows,
uint  cellWidth,
uint  cellHeight,
QCString  relPath = "",
bool  generateMap = TRUE 
)

Definition at line 576 of file diagram.cpp.

References DiagramItem::getChildren(), DiagramItem::getClassDef(), Image::getHeight(), gridHeight, gridWidth, DiagramItem::isInList(), ClassDef::isLinkable(), labelHorSpacing, labelVertSpacing, DiagramItem::parentItem(), writeBitmapBox(), writeMapArea(), writeVectorBox(), DiagramItem::xPos(), and DiagramItem::yPos().

Referenced by ClassDiagram::writeFigure(), and ClassDiagram::writeImage().

{
QListIterator<DiagramRow> it(*this);
if (!doBase) ++it;
bool done=FALSE;
bool firstRow = doBase;
for (;(dr=it.current()) && !done;++it)
{
int x=0,y=0;
float xf=0.0f,yf=0.0f;
QListIterator<DiagramItem> rit(*dr);
DiagramItem *di = rit.current();
if (di->isInList()) // put boxes in a list
{
DiagramItem *opi=0;
if (doBase) rit.toLast(); else rit.toFirst();
while ((di=rit.current()))
{
if (di->parentItem()==opi)
{
if (bitmap)
{
if (doBase) y -= cellHeight+labelVertSpacing;
else y += cellHeight+labelVertSpacing;
}
else
{
if (doBase) yf += 1.0f;
else yf -= 1.0f;
}
}
else
{
if (bitmap)
{
x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth;
if (doBase)
{
y = image->getHeight()-
superRows*cellHeight-
(superRows-1)*labelVertSpacing-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
}
else
{
y = (baseRows-1)*(cellHeight+labelVertSpacing)+
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
}
}
else
{
xf = di->xPos()/(float)gridWidth;
if (doBase)
{
yf = di->yPos()/(float)gridHeight+superRows-1;
}
else
{
yf = superRows-1-di->yPos()/(float)gridHeight;
}
}
}
opi=di->parentItem();
if (bitmap)
{
bool hasDocs=di->getClassDef()->isLinkable();
writeBitmapBox(di,image,x,y,cellWidth,cellHeight,firstRow,
hasDocs,di->getChildren()->count()>0);
if (!firstRow && generateMap)
writeMapArea(t,di->getClassDef(),relPath,x,y,cellWidth,cellHeight);
}
else
{
writeVectorBox(t,di,xf,yf,di->getChildren()->count()>0);
}
if (doBase) --rit; else ++rit;
}
done=TRUE;
}
else // draw a tree of boxes
{
for (rit.toFirst();(di=rit.current());++rit)
{
if (bitmap)
{
x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth;
if (doBase)
{
y = image->getHeight()-
superRows*cellHeight-
(superRows-1)*labelVertSpacing-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
}
else
{
y = (baseRows-1)*(cellHeight+labelVertSpacing)+
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
}
bool hasDocs=di->getClassDef()->isLinkable();
writeBitmapBox(di,image,x,y,cellWidth,cellHeight,firstRow,hasDocs);
if (!firstRow && generateMap)
writeMapArea(t,di->getClassDef(),relPath,x,y,cellWidth,cellHeight);
}
else
{
xf=di->xPos()/(float)gridWidth;
if (doBase)
{
yf = di->yPos()/(float)gridHeight+superRows-1;
}
else
{
yf = superRows-1-di->yPos()/(float)gridHeight;
}
writeVectorBox(t,di,xf,yf);
}
}
}
firstRow=FALSE;
}
}
void TreeDiagram::drawConnectors ( FTextStream t,
Image image,
bool  doBase,
bool  bitmap,
uint  baseRows,
uint  superRows,
uint  cellWidth,
uint  cellheight 
)

Definition at line 706 of file diagram.cpp.

References Image::drawHorzArrow(), Image::drawHorzLine(), Image::drawVertArrow(), Image::drawVertLine(), endl(), DiagramItem::getChildren(), Image::getHeight(), getMinProtectionLevel(), gridHeight, gridWidth, DiagramItem::isInList(), labelHorSpacing, labelVertSpacing, DiagramItem::parentItem(), DiagramItem::protection(), protToColor(), protToMask(), protToString(), DiagramItem::xPos(), and DiagramItem::yPos().

Referenced by ClassDiagram::writeFigure(), and ClassDiagram::writeImage().

{
QListIterator<DiagramRow> it(*this);
bool done=FALSE;
for (;(dr=it.current()) && !done;++it) // for each row
{
QListIterator<DiagramItem> rit(*dr);
DiagramItem *di = rit.current();
if (di->isInList()) // row consists of list connectors
{
int x=0,y=0,ys=0;
float xf=0.0f,yf=0.0f,ysf=0.0f;
for (;(di=rit.current());++rit)
{
DiagramItem *last=dil->getLast();
if (di==last) // single child
{
if (bitmap) // draw pixels
{
x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2;
if (doBase) // base classes
{
y = image->getHeight()-
(superRows-1)*(cellHeight+labelVertSpacing)-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
}
else // super classes
{
y = (baseRows-1)*(cellHeight+labelVertSpacing)-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
}
}
else // draw vectors
{
t << protToString(di->protection()) << endl;
if (doBase)
{
t << "1 " << (di->xPos()/(float)gridWidth) << " "
<< (di->yPos()/(float)gridHeight+superRows-1) << " in\n";
}
else
{
t << "0 " << (di->xPos()/(float)gridWidth) << " "
<< ((float)superRows-0.25-di->yPos()/(float)gridHeight)
<< " in\n";
}
}
}
else // multiple children, put them in a vertical list
{
if (bitmap)
{
x = di->parentItem()->xPos()*
(cellWidth+labelHorSpacing)/gridWidth+cellWidth/2;
if (doBase) // base classes
{
ys = image->getHeight()-
(superRows-1)*(cellHeight+labelVertSpacing)-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
y = ys - cellHeight/2;
}
else // super classes
{
ys = (baseRows-1)*(cellHeight+labelVertSpacing)+
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
y = ys + cellHeight/2;
}
}
else
{
xf = di->parentItem()->xPos()/(float)gridWidth;
if (doBase)
{
ysf = di->yPos()/(float)gridHeight+superRows-1;
yf = ysf + 0.5f;
}
else
{
ysf = (float)superRows-0.25f-di->yPos()/(float)gridHeight;
yf = ysf - 0.25f;
}
}
while (di!=last) // more children to add
{
if (bitmap)
{
if (doBase) // base classes
{
image->drawHorzArrow(y,x,x+cellWidth/2+labelHorSpacing,
y -= cellHeight+labelVertSpacing;
}
else // super classes
{
image->drawHorzLine(y,x,x+cellWidth/2+labelHorSpacing,
y += cellHeight+labelVertSpacing;
}
}
else
{
t << protToString(di->protection()) << endl;
if (doBase)
{
t << "1 " << xf << " " << yf << " hedge\n";
yf += 1.0f;
}
else
{
t << "0 " << xf << " " << yf << " hedge\n";
yf -= 1.0f;
}
}
++rit; di=rit.current();
}
// add last horizonal line and a vertical connection line
if (bitmap)
{
if (doBase) // base classes
{
image->drawHorzArrow(y,x,x+cellWidth/2+labelHorSpacing,
image->drawVertLine(x,y,ys+labelVertSpacing/2,
}
else // super classes
{
image->drawHorzLine(y,x,x+cellWidth/2+labelHorSpacing,
image->drawVertLine(x,ys-labelVertSpacing/2,y,
}
}
else
{
t << protToString(di->protection()) << endl;
if (doBase)
{
t << "1 " << xf << " " << yf << " hedge\n";
}
else
{
t << "0 " << xf << " " << yf << " hedge\n";
}
if (doBase)
{
t << xf << " " << ysf << " " << yf << " vedge\n";
}
else
{
t << xf << " " << (ysf + 0.25) << " " << yf << " vedge\n";
}
}
}
}
done=TRUE; // the tree is drawn now
}
else // normal tree connector
{
for (;(di=rit.current());++rit)
{
int x=0,y=0;
DiagramItem *parent = di->parentItem();
if (parent) // item has a parent -> connect to it
{
if (bitmap) // draw pixels
{
x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2;
if (doBase) // base classes
{
y = image->getHeight()-
(superRows-1)*(cellHeight+labelVertSpacing)-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
/* write input line */
}
else // super classes
{
y = (baseRows-1)*(cellHeight+labelVertSpacing)-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
/* write output line */
}
}
else // draw pixels
{
t << protToString(di->protection()) << endl;
if (doBase)
{
t << "1 " << di->xPos()/(float)gridWidth << " "
<< (di->yPos()/(float)gridHeight+superRows-1) << " in\n";
}
else
{
t << "0 " << di->xPos()/(float)gridWidth << " "
<< ((float)superRows-0.25-di->yPos()/(float)gridHeight)
<< " in\n";
}
}
}
if (dil->count()>0)
{
uint mask=protToMask(p);
uint col=protToColor(p);
if (bitmap)
{
x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2;
if (doBase) // base classes
{
y = image->getHeight()-
(superRows-1)*(cellHeight+labelVertSpacing)-
cellHeight-labelVertSpacing/2-
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
image->drawVertLine(x,y,y+labelVertSpacing/2-1,col,mask);
}
else // super classes
{
y = (baseRows-1)*(cellHeight+labelVertSpacing)+
cellHeight+
di->yPos()*(cellHeight+labelVertSpacing)/gridHeight;
image->drawVertArrow(x,y,y+labelVertSpacing/2-1,col,mask);
}
}
else
{
t << protToString(p) << endl;
if (doBase)
{
t << "0 " << di->xPos()/(float)gridWidth << " "
<< (di->yPos()/(float)gridHeight+superRows-1) << " out\n";
}
else
{
t << "1 " << di->xPos()/(float)gridWidth << " "
<< ((float)superRows-1.75-di->yPos()/(float)gridHeight)
<< " out\n";
}
}
/* write input line */
DiagramItem *first = dil->getFirst();
DiagramItem *last = dil->getLast();
if (first!=last && !first->isInList()) /* connect with all base classes */
{
if (bitmap)
{
int xs = first->xPos()*(cellWidth+labelHorSpacing)/gridWidth
+ cellWidth/2;
int xe = last->xPos()*(cellWidth+labelHorSpacing)/gridWidth
+ cellWidth/2;
if (doBase) // base classes
{
image->drawHorzLine(y,xs,xe,col,mask);
}
else // super classes
{
image->drawHorzLine(y+labelVertSpacing/2,xs,xe,col,mask);
}
}
else
{
t << protToString(p) << endl;
if (doBase)
{
t << first->xPos()/(float)gridWidth << " "
<< last->xPos()/(float)gridWidth << " "
<< (first->yPos()/(float)gridHeight+superRows-1)
<< " conn\n";
}
else
{
t << first->xPos()/(float)gridWidth << " "
<< last->xPos()/(float)gridWidth << " "
<< ((float)superRows-first->yPos()/(float)gridHeight)
<< " conn\n";
}
}
}
}
}
}
}
}
bool TreeDiagram::layoutTree ( DiagramItem root,
int  row 
)
private

Definition at line 434 of file diagram.cpp.

References DiagramItem::avgChildPos(), DiagramItem::getChildren(), DiagramItem::isInList(), DiagramItem::number(), and DiagramItem::xPos().

Referenced by computeLayout().

{
bool moved=FALSE;
//printf("layoutTree(%s,%d)\n",root->label().data(),r);
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
QListIterator<DiagramItem> it(*dil);
for (;(di=it.current()) && !moved && !di->isInList();++it)
{
moved = layoutTree(di,r+1);
}
}
return moved;
}
void TreeDiagram::moveChildren ( DiagramItem root,
int  dx 
)

Definition at line 422 of file diagram.cpp.

References DiagramItem::getChildren(), and DiagramItem::move().

Referenced by ClassDiagram::ClassDiagram().

{
QListIterator<DiagramItem> it(*dil);
for (;(di=it.current());++it)
{
di->move(dx,0);
moveChildren(di,dx);
}
}
TreeDiagram& TreeDiagram::operator= ( const TreeDiagram )
private

The documentation for this class was generated from the following file: