branchobj.cpp
changeset 755 ed5b407975b3
parent 754 db0ec4bcf416
child 756 a8a5c7288f57
     1.1 --- a/branchobj.cpp	Mon Apr 20 10:42:05 2009 +0000
     1.2 +++ b/branchobj.cpp	Thu Apr 23 12:15:31 2009 +0000
     1.3 @@ -22,23 +22,22 @@
     1.4  //    cout << "Const BranchObj ()\n";
     1.5      setParObj (this);	
     1.6      init();
     1.7 -    depth=-1;
     1.8  }
     1.9  
    1.10 -BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
    1.11 +BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
    1.12  {
    1.13 -//    cout << "Const BranchObj (s)  called from MapCenterObj (s)\n";
    1.14 +//    cout << "Const BranchObj (s)  \n";
    1.15  	parObj=NULL;
    1.16      scene=s;
    1.17 +	init();
    1.18  }
    1.19  
    1.20 -BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
    1.21 +BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
    1.22  {
    1.23  //    cout << "Const BranchObj (s,p)\n";
    1.24      scene=s;
    1.25      setParObj (p);	
    1.26 -    depth=p->getDepth()+1;
    1.27 -	if (depth==1)
    1.28 +	if (treeItem->depth()==1)
    1.29  		// Calc angle to mapCenter if I am a mainbranch
    1.30  		// needed for reordering the mainbranches clockwise 
    1.31  		// around mapcenter 
    1.32 @@ -120,7 +119,7 @@
    1.33  
    1.34  void BranchObj::clear() 
    1.35  {
    1.36 -	setVisibility (true);
    1.37 +	//setVisibility (true); //FIXME-4 needed?
    1.38  
    1.39  	while (!floatimage.isEmpty())
    1.40  		delete floatimage.takeFirst();
    1.41 @@ -149,14 +148,14 @@
    1.42  		parObjTmpBuf=parObj;
    1.43  
    1.44  	// ignore mapcenter and mainbranch
    1.45 -	if (lmo->getDepth()<2) off=0;
    1.46 +	if (treeItem->depth()<2) off=0;
    1.47  	if (off==0)
    1.48  		link2ParPos=false;
    1.49  	else
    1.50  		link2ParPos=true;
    1.51  	parObj=o;
    1.52  
    1.53 -	depth=parObj->getDepth()+1;
    1.54 +	// FIXME-2 depth=parObj->getDepth()+1;
    1.55  
    1.56  	// setLinkStyle calls updateLink, only set it once
    1.57  	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
    1.58 @@ -165,7 +164,7 @@
    1.59  	// Usually the positioning would be done by reposition(),
    1.60  	// but then also the destination branch would "Jump" around...
    1.61  	// Better just do it approximately
    1.62 -	if (depth==1)
    1.63 +	if (treeItem->depth()==1)
    1.64  	{	// new parent is the mapcenter itself
    1.65  
    1.66  		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
    1.67 @@ -213,7 +212,7 @@
    1.68  		link2ParPos=false;
    1.69  		parObj=parObjTmpBuf;
    1.70  		parObjTmpBuf=NULL;
    1.71 -		depth=parObj->getDepth()+1;
    1.72 +		//FIXME-2 depth=parObj->getDepth()+1;
    1.73  		setLinkStyle (getDefLinkStyle() );
    1.74  		updateLink();
    1.75  	}		
    1.76 @@ -222,7 +221,7 @@
    1.77  void BranchObj::setVisibility(bool v, int toDepth)
    1.78  {
    1.79  	BranchItem *bi=(BranchItem*)treeItem;
    1.80 -    if (depth <= toDepth)
    1.81 +    if (bi->depth() <= toDepth)
    1.82      {
    1.83  		frame->setVisibility(v);
    1.84  		heading->setVisibility(v);
    1.85 @@ -669,7 +668,7 @@
    1.86  void BranchObj::setDefAttr (BranchModification mod)
    1.87  {
    1.88  	int fontsize;
    1.89 -	switch (depth)
    1.90 +	switch (treeItem->depth())
    1.91  	{
    1.92  		case 0: fontsize=16; break;
    1.93  		case 1: fontsize=12; break;
    1.94 @@ -688,7 +687,7 @@
    1.95  	calcBBoxSize();
    1.96  }
    1.97  
    1.98 -BranchObj* BranchObj::addBranch()
    1.99 +BranchObj* BranchObj::addBranch()	// FIXME-3 still needed?
   1.100  {
   1.101      BranchObj* newbo=new BranchObj(scene,this);
   1.102      newbo->setParObj(this);
   1.103 @@ -724,7 +723,7 @@
   1.104  {
   1.105  	//FIXME-1 branch.append (bo);
   1.106  	bo->setParObj (this);
   1.107 -	bo->depth=depth+1;
   1.108 +	//FIXME-2 bo->depth=depth+1;
   1.109  	bo->setDefAttr(MovedBranch);
   1.110  	BranchItem *bi=(BranchItem*)treeItem;
   1.111  	if ( bi->isScrolled() ) bi->tmpUnscroll();
   1.112 @@ -757,14 +756,14 @@
   1.113  	savePosInAngle();
   1.114  	// Add new bo and resort branches
   1.115  	bo->angle=pos-0.5;
   1.116 -	//FIXME-1 branch.append (bo);
   1.117 +	//FIXME-4 branch.append (bo);
   1.118  	bo->setParObj (this);
   1.119 -	bo->depth=depth+1;
   1.120 +	//FIXME-2 bo->depth=depth+1;
   1.121  	bo->setDefAttr (MovedBranch);
   1.122  	BranchItem *bi=(BranchItem*)treeItem;
   1.123  	if ( bi->isScrolled() ) bi->tmpUnscroll();
   1.124  	//setLastSelectedBranch (bo); //FIXME-3 needed?
   1.125 -	//FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
   1.126 +	//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   1.127  	return bo;
   1.128  }
   1.129  
   1.130 @@ -785,7 +784,7 @@
   1.131  	*/
   1.132  }
   1.133  
   1.134 -void BranchObj::removeChildren()
   1.135 +void BranchObj::removeChildren()	// FIXME-3 not needed here
   1.136  {
   1.137  	clear();
   1.138  }
   1.139 @@ -914,6 +913,7 @@
   1.140  	else
   1.141  		return NULL;
   1.142  
   1.143 +/* FIXME-1
   1.144  	// Create new pointer to myself at dst
   1.145  	if (pos<0||dst->getDepth()==0)
   1.146  	{	
   1.147 @@ -934,22 +934,25 @@
   1.148  		} else
   1.149  			return NULL;
   1.150  	}	
   1.151 +*/	
   1.152  }
   1.153  
   1.154  void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   1.155  {
   1.156  	qreal th = bboxTotal.height();	
   1.157 +	int depth=treeItem->depth();
   1.158  // TODO testing
   1.159  /*
   1.160 -	QString h=QString (treeItem->depth(),' ');
   1.161 +
   1.162 +	QString h=QString (depth,' ');
   1.163  	h+=treeItem->getHeading();
   1.164  	h+=QString (15,' ');
   1.165  	h.truncate (15);
   1.166  	QPointF pp; if (parObj) pp=parObj->getChildPos();
   1.167  	cout << "BO::alignRelTo ";
   1.168  	cout<<h.toStdString();
   1.169 -//	cout << "    d="<<treeItem->depth()<<
   1.170 -cout<<  "  ref="<<ref<<
   1.171 +	cout << "    d="<<depth<<
   1.172 +//cout<<  "  ref="<<ref<<
   1.173        	"  bbox.tL="<<bboxTotal.topLeft()<<
   1.174  		"  absPos="<<absPos<<
   1.175  //		"  relPos="<<relPos<<
   1.176 @@ -968,7 +971,7 @@
   1.177  	setOrientation();
   1.178  	//updateLink();
   1.179  
   1.180 -	if (depth==1)
   1.181 +	if (depth==1 && parObj)
   1.182  	{
   1.183  		// Position relatively, if needed
   1.184  		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   1.185 @@ -1046,7 +1049,7 @@
   1.186  //	cout << "  orient="<<orientation<<endl;
   1.187  */		
   1.188  
   1.189 -	if (depth==0)
   1.190 +	if (treeItem->depth()==0)
   1.191  	{
   1.192  		// only calculate the sizes once. If the deepest LMO 
   1.193  		// changes its height,
   1.194 @@ -1108,6 +1111,11 @@
   1.195  		if (!treeItem->getBranchNum(i)->isHidden())
   1.196  			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
   1.197  
   1.198 +/* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
   1.199 +            better check if they are not NULL and maybe simplify...
   1.200 +			(have been NULL at least in calcBBoxSizeWithChilds...)
   1.201 +*/			
   1.202 +
   1.203  /*
   1.204  	FIXME-1 for (int i=0; i<floatimage.size(); ++i)
   1.205  		if (!floatimage.at(i)->isHidden())
   1.206 @@ -1164,7 +1172,7 @@
   1.207  	// sum of heights 
   1.208  	// maximum of widths 
   1.209  	// minimum of y
   1.210 -	for (int i=0; i<treeItem->branchCount(); ++i)
   1.211 +	for (int i=0; i<treeItem->branchCount(); i++)
   1.212  	{
   1.213  		if (!bi->getBranchNum(i)->isHidden())
   1.214  		{