moved scroll functions from BranchObj to BranchItem
authorinsilmaril
Wed, 01 Apr 2009 15:06:57 +0000
changeset 7499ff332964015
parent 748 edb78a44240b
child 750 ff3b01ce0960
moved scroll functions from BranchObj to BranchItem
branchitem.cpp
branchitem.h
branchobj.cpp
branchobj.h
demos/vym-projectplan.vym
exports.cpp
mainwindow.cpp
mapcenteritem.cpp
mapcenteritem.h
mapcenterobj.cpp
mapeditor.cpp
treeitem.cpp
treeitem.h
vym.pro
vymmodel.cpp
vymmodel.h
xml-freemind.cpp
xml-freemind.h
xml-vym.cpp
xml-vym.h
     1.1 --- a/branchitem.cpp	Tue Mar 31 15:36:10 2009 +0000
     1.2 +++ b/branchitem.cpp	Wed Apr 01 15:06:57 2009 +0000
     1.3 @@ -6,7 +6,10 @@
     1.4  
     1.5  BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
     1.6  {
     1.7 -	cout << "Constr. BranchItem\n";
     1.8 +	//cout << "Constr. BranchItem\n";
     1.9 +
    1.10 +	scrolled=false;
    1.11 +	tmpUnscrolled=false;
    1.12  }
    1.13  
    1.14  BranchItem::~BranchItem()
    1.15 @@ -15,6 +18,12 @@
    1.16      qDeleteAll(childItems);
    1.17  }
    1.18  
    1.19 +void BranchItem::copy (BranchItem *other)
    1.20 +{
    1.21 +	scrolled=other->scrolled;
    1.22 +	tmpUnscrolled=other->tmpUnscrolled;
    1.23 +}
    1.24 +
    1.25  QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
    1.26  {
    1.27  	// Cloudy stuff can be hidden during exports
    1.28 @@ -113,4 +122,87 @@
    1.29      return s;
    1.30  }
    1.31  
    1.32 +void BranchItem::unScroll()
    1.33 +{
    1.34 +	if (tmpUnscrolled) resetTmpUnscroll();
    1.35 +	if (scrolled) toggleScroll();
    1.36 +}
    1.37  
    1.38 +void BranchItem::toggleScroll()
    1.39 +{
    1.40 +	if (scrolled)
    1.41 +	{
    1.42 +		scrolled=false;
    1.43 +		//FIXME-1 systemFlags->deactivate("scrolledright");
    1.44 +		/*
    1.45 +		for (int i=0; i<branch.size(); ++i)
    1.46 +			branch.at(i)->setVisibility(true);
    1.47 +		*/	
    1.48 +	} else
    1.49 +	{
    1.50 +		scrolled=true;
    1.51 +		/*
    1.52 +		//FIXME-1 systemFlags->activate("scrolledright");
    1.53 +		for (int i=0; i<branch.size(); ++i)
    1.54 +			branch.at(i)->setVisibility(false);
    1.55 +		*/	
    1.56 +	}
    1.57 +	/*
    1.58 +	calcBBoxSize();
    1.59 +	positionBBox();	
    1.60 +	move (absPos.x(), absPos.y() );
    1.61 +	forceReposition();
    1.62 +	*/
    1.63 +}
    1.64 +
    1.65 +bool BranchItem::isScrolled()
    1.66 +{
    1.67 +	return scrolled;
    1.68 +}
    1.69 +
    1.70 +bool BranchItem::hasScrolledParent(BranchItem *start)
    1.71 +{
    1.72 +	// Calls parents recursivly to
    1.73 +	// find out, if we are scrolled at all.
    1.74 +	// But ignore myself, just look at parents.
    1.75 +
    1.76 +	if (this !=start && scrolled) return true;
    1.77 +
    1.78 +	BranchItem* bi=(BranchItem*)parentItem;
    1.79 +	if (bi) 
    1.80 +		return bi->hasScrolledParent(start);
    1.81 +	else
    1.82 +		return false;
    1.83 +}
    1.84 +
    1.85 +void BranchItem::tmpUnscroll()
    1.86 +{
    1.87 +	// Unscroll parent (recursivly)
    1.88 +	BranchItem * bi=(BranchItem*)parentItem;
    1.89 +	if (bi) bi->tmpUnscroll();
    1.90 +		
    1.91 +	// Unscroll myself
    1.92 +	if (scrolled)
    1.93 +	{
    1.94 +		tmpUnscrolled=true;
    1.95 +		// FIXME-1 systemFlags->activate("tmpUnscrolledright");
    1.96 +		toggleScroll();
    1.97 +	}	
    1.98 +}
    1.99 +
   1.100 +void BranchItem::resetTmpUnscroll()
   1.101 +{
   1.102 +	// Unscroll parent (recursivly)
   1.103 +	BranchItem * bi=(BranchItem*)parentItem;
   1.104 +	if (bi) bi->resetTmpUnscroll();
   1.105 +		
   1.106 +	// Unscroll myself
   1.107 +	if (tmpUnscrolled)
   1.108 +	{
   1.109 +		tmpUnscrolled=false;
   1.110 +		// FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
   1.111 +		toggleScroll();
   1.112 +	}	
   1.113 +}
   1.114 +
   1.115 +
     2.1 --- a/branchitem.h	Tue Mar 31 15:36:10 2009 +0000
     2.2 +++ b/branchitem.h	Wed Apr 01 15:06:57 2009 +0000
     2.3 @@ -10,9 +10,22 @@
     2.4  public:
     2.5      BranchItem(const QList<QVariant> &data, TreeItem *parent = 0);
     2.6      ~BranchItem();
     2.7 +	void copy (BranchItem *item);
     2.8  
     2.9  	QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset);
    2.10  
    2.11 +	virtual void unScroll();				
    2.12 +	virtual void toggleScroll();			// scroll or unscroll
    2.13 +	virtual bool isScrolled();				// returns scroll state
    2.14 +	virtual bool hasScrolledParent(BranchItem*);	// true, if any of the parents is scrolled
    2.15 +	virtual void tmpUnscroll();				// unscroll scrolled parents temporary e.g. during "find" process
    2.16 +	virtual void resetTmpUnscroll();		// scroll all tmp scrolled parents again e.g. when unselecting
    2.17 +
    2.18 +
    2.19 +protected:	
    2.20 +	bool scrolled;			// true if all children are scrolled and thus invisible
    2.21 +	bool tmpUnscrolled;		// can only be true (temporary) for a scrolled subtree
    2.22 +
    2.23  };
    2.24  
    2.25  #endif
     3.1 --- a/branchobj.cpp	Tue Mar 31 15:36:10 2009 +0000
     3.2 +++ b/branchobj.cpp	Wed Apr 01 15:06:57 2009 +0000
     3.3 @@ -1,6 +1,7 @@
     3.4  #include "branchobj.h"
     3.5  
     3.6  // #include "texteditor.h"
     3.7 +#include "branchitem.h"
     3.8  #include "geometry.h"
     3.9  #include "mapeditor.h"
    3.10  #include "mainwindow.h"
    3.11 @@ -58,8 +59,9 @@
    3.12  
    3.13  	cout << "Destr BranchObj of "<<this<<" ("<<getHeading().toStdString()<<")"<<endl;
    3.14  	// Check, if this branch was the last child to be deleted
    3.15 -	// If so, unset the scrolled flags
    3.16 +	// If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
    3.17  
    3.18 +	/*
    3.19  	BranchObj *po=(BranchObj*)parObj;
    3.20  	BranchObj *bo;
    3.21  	if (po)
    3.22 @@ -67,6 +69,7 @@
    3.23  		bo=((BranchObj*)parObj)->getLastBranch();
    3.24  		if (bo) po->unScroll();
    3.25  	}
    3.26 +	*/
    3.27  	clear();
    3.28  }
    3.29  
    3.30 @@ -90,9 +93,6 @@
    3.31  
    3.32      setChildObj(this);
    3.33  
    3.34 -	scrolled=false;
    3.35 -	tmpUnscrolled=false;
    3.36 -
    3.37  	includeImagesVer=false;
    3.38  	includeImagesHor=false;
    3.39  }
    3.40 @@ -110,8 +110,7 @@
    3.41  
    3.42  	for (int i=0; i<other->floatimage.size(); ++i)
    3.43  		addFloatImage  (other->floatimage.at(i));
    3.44 -	scrolled=other->scrolled;
    3.45 -	tmpUnscrolled=other->tmpUnscrolled;
    3.46 +	
    3.47  	setVisibility (other->visible);
    3.48  
    3.49  	angle=other->angle;
    3.50 @@ -141,39 +140,6 @@
    3.51  		return false;
    3.52  }
    3.53  
    3.54 -int BranchObj::getNum()
    3.55 -{
    3.56 -	if (parObj)
    3.57 -		return ((BranchObj*)parObj)->getNum (this);
    3.58 -	else
    3.59 -		return 0;
    3.60 -}
    3.61 -
    3.62 -int BranchObj::getNum(BranchObj *bo)
    3.63 -{
    3.64 -	return branch.indexOf (bo);
    3.65 -}
    3.66 -
    3.67 -int BranchObj::getFloatImageNum(FloatImageObj *fio)
    3.68 -{
    3.69 -	return floatimage.indexOf(fio);
    3.70 -}
    3.71 -
    3.72 -int BranchObj::countBranches()
    3.73 -{
    3.74 -	return branch.count();
    3.75 -}
    3.76 -
    3.77 -int BranchObj::countFloatImages()
    3.78 -{
    3.79 -	return floatimage.count();
    3.80 -}
    3.81 -
    3.82 -int BranchObj::countXLinks()
    3.83 -{
    3.84 -	return xlink.count();
    3.85 -}
    3.86 -
    3.87  void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
    3.88  {
    3.89  	// Temporary link to lmo
    3.90 @@ -256,86 +222,9 @@
    3.91  	}		
    3.92  }
    3.93  
    3.94 -void BranchObj::unScroll()
    3.95 -{
    3.96 -	if (tmpUnscrolled) resetTmpUnscroll();
    3.97 -	if (scrolled) toggleScroll();
    3.98 -}
    3.99 -
   3.100 -void BranchObj::toggleScroll()
   3.101 -{
   3.102 -	if (scrolled)
   3.103 -	{
   3.104 -		scrolled=false;
   3.105 -		systemFlags->deactivate("scrolledright");
   3.106 -		for (int i=0; i<branch.size(); ++i)
   3.107 -			branch.at(i)->setVisibility(true);
   3.108 -	} else
   3.109 -	{
   3.110 -		scrolled=true;
   3.111 -		systemFlags->activate("scrolledright");
   3.112 -		for (int i=0; i<branch.size(); ++i)
   3.113 -			branch.at(i)->setVisibility(false);
   3.114 -	}
   3.115 -	calcBBoxSize();
   3.116 -	positionBBox();	
   3.117 -	move (absPos.x(), absPos.y() );
   3.118 -	forceReposition();
   3.119 -}
   3.120 -
   3.121 -bool BranchObj::isScrolled()
   3.122 -{
   3.123 -	return scrolled;
   3.124 -}
   3.125 -
   3.126 -bool BranchObj::hasScrolledParent(BranchObj *start)
   3.127 -{
   3.128 -	// Calls parents recursivly to
   3.129 -	// find out, if we are scrolled at all.
   3.130 -	// But ignore myself, just look at parents.
   3.131 -
   3.132 -	if (this !=start && scrolled) return true;
   3.133 -
   3.134 -	BranchObj* bo=(BranchObj*)(parObj);
   3.135 -	if (bo) 
   3.136 -		return bo->hasScrolledParent(start);
   3.137 -	else
   3.138 -		return false;
   3.139 -}
   3.140 -
   3.141 -void BranchObj::tmpUnscroll()
   3.142 -{
   3.143 -	// Unscroll parent (recursivly)
   3.144 -	BranchObj* bo=(BranchObj*)(parObj);
   3.145 -	if (bo) bo->tmpUnscroll();
   3.146 -		
   3.147 -	// Unscroll myself
   3.148 -	if (scrolled)
   3.149 -	{
   3.150 -		tmpUnscrolled=true;
   3.151 -		systemFlags->activate("tmpUnscrolledright");
   3.152 -		toggleScroll();
   3.153 -	}	
   3.154 -}
   3.155 -
   3.156 -void BranchObj::resetTmpUnscroll()
   3.157 -{
   3.158 -	// Unscroll parent (recursivly)
   3.159 -	BranchObj* bo=(BranchObj*)(parObj);
   3.160 -	if (bo)
   3.161 -		bo->resetTmpUnscroll();
   3.162 -		
   3.163 -	// Unscroll myself
   3.164 -	if (tmpUnscrolled)
   3.165 -	{
   3.166 -		tmpUnscrolled=false;
   3.167 -		systemFlags->deactivate("tmpUnscrolledright");
   3.168 -		toggleScroll();
   3.169 -	}	
   3.170 -}
   3.171 -
   3.172  void BranchObj::setVisibility(bool v, int toDepth)
   3.173  {
   3.174 +	BranchItem *bi=(BranchItem*)treeItem;
   3.175      if (depth <= toDepth)
   3.176      {
   3.177  		frame->setVisibility(v);
   3.178 @@ -343,7 +232,6 @@
   3.179  		systemFlags->setVisibility(v);
   3.180  		standardFlags->setVisibility(v);
   3.181  		LinkableMapObj::setVisibility (v);
   3.182 -		
   3.183  		int i;
   3.184  		for (i=0; i<floatimage.size(); ++i)
   3.185  			floatimage.at(i)->setVisibility (v);
   3.186 @@ -351,7 +239,7 @@
   3.187  			xlink.at(i)->setVisibility ();	
   3.188  
   3.189  		// Only change children, if I am not scrolled
   3.190 -		if (!scrolled && (depth < toDepth))
   3.191 +		if (! bi->isScrolled() && (bi->depth() < toDepth))
   3.192  		{
   3.193  			// Now go recursivly through all children
   3.194  			for (i=0; i<branch.size(); ++i)
   3.195 @@ -468,7 +356,7 @@
   3.196  	topPad=botPad=leftPad=rightPad=0;
   3.197  	if (includeImagesVer || includeImagesHor)
   3.198  	{
   3.199 -		if (countFloatImages()>0)
   3.200 +		if (treeItem->imageCount()>0)
   3.201  		{
   3.202  			for (int i=0; i<floatimage.size(); ++i )
   3.203  			{
   3.204 @@ -602,7 +490,7 @@
   3.205  	}else
   3.206  	{
   3.207  		// Do not hide, but still take care of scrolled status
   3.208 -		if (hasScrolledParent(this))
   3.209 +		if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
   3.210  			setVisibility (false);
   3.211  		else
   3.212  			setVisibility (true);
   3.213 @@ -638,14 +526,14 @@
   3.214  	
   3.215      QString s,a;
   3.216  	QString scrolledAttr;
   3.217 -	if (scrolled) 
   3.218 +	if ( ((BranchItem*)treeItem)->isScrolled() ) 
   3.219  		scrolledAttr=attribut ("scrolled","yes");
   3.220  	else
   3.221  		scrolledAttr="";
   3.222  
   3.223  	// save area, if not scrolled
   3.224  	QString areaAttr;
   3.225 -	if (!((BranchObj*)(parObj))->isScrolled() )
   3.226 +	if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
   3.227  	{
   3.228  		areaAttr=
   3.229  			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   3.230 @@ -658,7 +546,7 @@
   3.231  	
   3.232  	// Providing an ID for a branch makes export to XHTML easier
   3.233  	QString idAttr;
   3.234 -	if (countXLinks()>0)
   3.235 +	if (treeItem->xlinkCount()>0)
   3.236  		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
   3.237  	else
   3.238  		idAttr="";
   3.239 @@ -744,12 +632,6 @@
   3.240  	return xlink.at(i);
   3.241  }
   3.242  
   3.243 -int BranchObj::countXLink()
   3.244 -{
   3.245 -	return xlink.count();
   3.246 -}
   3.247 -
   3.248 -
   3.249  BranchObj* BranchObj::XLinkTargetAt (int i)
   3.250  {
   3.251  	if (i>=0 && i<xlink.size())
   3.252 @@ -804,7 +686,7 @@
   3.253  {
   3.254  	FloatImageObj *newfi=new FloatImageObj (scene,this);
   3.255  	floatimage.append (newfi);
   3.256 -	if (hasScrolledParent(this) )
   3.257 +	if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   3.258  		newfi->setVisibility (false);
   3.259  	else	
   3.260  		newfi->setVisibility(visible);
   3.261 @@ -821,7 +703,7 @@
   3.262  	FloatImageObj *newfi=new FloatImageObj (scene,this);
   3.263  	floatimage.append (newfi);
   3.264  	newfi->copy (fio);
   3.265 -	if (hasScrolledParent(this) )
   3.266 +	if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   3.267  		newfi->setVisibility (false);
   3.268  	else	
   3.269  		newfi->setVisibility(visible);
   3.270 @@ -893,10 +775,12 @@
   3.271      newbo->setParObj(this);
   3.272  	newbo->setDefAttr(NewBranch);
   3.273      newbo->setHeading ("new");
   3.274 -	if (scrolled)
   3.275 +	/* FIXME-2 treeItem not set yet!!!
   3.276 +	if ( ((BranchItem*)treeItem)->isScrolled() )
   3.277  		newbo->setVisibility (false);
   3.278  	else	
   3.279  		newbo->setVisibility(visible);
   3.280 +	*/	
   3.281  	newbo->updateLink();	
   3.282  	requestReposition();
   3.283  	return newbo;
   3.284 @@ -909,7 +793,7 @@
   3.285      newbo->copy(bo);
   3.286      newbo->setParObj(this);
   3.287  	newbo->setDefAttr(MovedBranch);
   3.288 -	if (scrolled)
   3.289 +	if ( ((BranchItem*)treeItem)->isScrolled() )
   3.290  		newbo->setVisibility (false);
   3.291  	else	
   3.292  		newbo->setVisibility(bo->visible);
   3.293 @@ -924,7 +808,8 @@
   3.294  	bo->setParObj (this);
   3.295  	bo->depth=depth+1;
   3.296  	bo->setDefAttr(MovedBranch);
   3.297 -	if (scrolled) tmpUnscroll();
   3.298 +	BranchItem *bi=(BranchItem*)treeItem;
   3.299 +	if ( bi->isScrolled() ) bi->tmpUnscroll();
   3.300  	//setLastSelectedBranch (bo);	//FIXME-3 needed?
   3.301  	return bo;
   3.302  }
   3.303 @@ -958,14 +843,16 @@
   3.304  	bo->setParObj (this);
   3.305  	bo->depth=depth+1;
   3.306  	bo->setDefAttr (MovedBranch);
   3.307 -	if (scrolled) tmpUnscroll();
   3.308 +	BranchItem *bi=(BranchItem*)treeItem;
   3.309 +	if ( bi->isScrolled() ) bi->tmpUnscroll();
   3.310  	//setLastSelectedBranch (bo); //FIXME-3 needed?
   3.311  	qSort (branch.begin(),branch.end(), isAbove);
   3.312  	return bo;
   3.313  }
   3.314  
   3.315 -void BranchObj::removeBranchHere(BranchObj* borem)
   3.316 +void BranchObj::removeBranchHere(BranchObj* borem)	// FIXME-1 getNum no longer available
   3.317  {
   3.318 +/*
   3.319  	// This removes the branch bo from list, but 
   3.320  	// inserts its children at the place of bo
   3.321  	BranchObj *bo;
   3.322 @@ -977,6 +864,7 @@
   3.323  		bo=borem->getLastBranch();
   3.324  	}	
   3.325  	removeBranch (borem);
   3.326 +	*/
   3.327  }
   3.328  
   3.329  void BranchObj::removeChildren()
   3.330 @@ -1084,9 +972,10 @@
   3.331  		return NULL;
   3.332  }
   3.333  
   3.334 -void BranchObj::sortChildren()
   3.335 +void BranchObj::sortChildren() //FIXME-1  
   3.336  {
   3.337 -	int childCount=branch.count();
   3.338 +/*
   3.339 +	int childCount=branch.count(); 
   3.340  	int curChildIndex;
   3.341  	bool madeChanges=false;
   3.342  	do
   3.343 @@ -1102,6 +991,7 @@
   3.344  			}
   3.345  		}
   3.346  	}while(madeChanges);
   3.347 +*/
   3.348  }
   3.349  
   3.350  
   3.351 @@ -1206,7 +1096,7 @@
   3.352  		}
   3.353      }		
   3.354  
   3.355 -	if (scrolled) return;
   3.356 +	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
   3.357  
   3.358      // Set reference point for alignment of children
   3.359      QPointF ref2;
   3.360 @@ -1301,7 +1191,7 @@
   3.361  {
   3.362  	QRectF r=bbox;
   3.363  
   3.364 -	if (scrolled) return r;
   3.365 +	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
   3.366  
   3.367  	for (int i=0; i<branch.size(); ++i)
   3.368  		if (!branch.at(i)->isHidden())
   3.369 @@ -1332,7 +1222,7 @@
   3.370  	bboxTotal.setY(bbox.y() );
   3.371  
   3.372  	// if branch is scrolled, ignore children, but still consider floatimages
   3.373 -	if (scrolled)
   3.374 +	if ( ((BranchItem*)treeItem)->isScrolled() ) 
   3.375  	{
   3.376  		bboxTotal.setWidth (bbox.width());
   3.377  		bboxTotal.setHeight(bbox.height());
     4.1 --- a/branchobj.h	Tue Mar 31 15:36:10 2009 +0000
     4.2 +++ b/branchobj.h	Wed Apr 01 15:06:57 2009 +0000
     4.3 @@ -31,22 +31,10 @@
     4.4      virtual void init ();
     4.5      virtual void copy (BranchObj*);
     4.6      void clear();
     4.7 -	virtual int getNum();				// return number of this in parent
     4.8 -	virtual int getNum(BranchObj*);		// return number of this in parent
     4.9 -	virtual int getFloatImageNum(FloatImageObj*);		
    4.10 -	virtual int countBranches();		
    4.11 -	virtual int countFloatImages();		
    4.12 -	virtual int countXLinks();		
    4.13 +
    4.14      virtual void setParObjTmp (LinkableMapObj*,QPointF,int);// Only for moving Obj around
    4.15  	virtual void unsetParObjTmp();			// reuse original ParObj
    4.16  
    4.17 -	virtual void unScroll();				
    4.18 -	virtual void toggleScroll();			// scroll or unscroll
    4.19 -	virtual bool isScrolled();				// returns scroll state
    4.20 -	virtual bool hasScrolledParent(BranchObj*);	// true, if any of the parents is scrolled
    4.21 -	virtual void tmpUnscroll();				// unscroll scrolled parents temporary e.g. during "find" process
    4.22 -	virtual void resetTmpUnscroll();		// scroll all tmp scrolled parents again e.g. when unselecting
    4.23 -
    4.24  	virtual void setVisibility(bool,int);	// set visibility
    4.25      virtual void setVisibility(bool);	    // set vis. for w
    4.26  	virtual void setLinkColor();			// set the color of link
    4.27 @@ -68,18 +56,20 @@
    4.28  	virtual bool hasHiddenExportParent ();
    4.29  
    4.30  	virtual QString saveToDir (const QString&,const QString&, const QPointF&);// Save data recursivly to tempdir
    4.31 +
    4.32  	virtual void addXLink (XLinkObj*);
    4.33  	virtual void removeXLinkRef (XLinkObj*);// Remove ref in list
    4.34  	virtual void deleteXLink (XLinkObj*);	// remove references and delete XLinkObj 
    4.35  	virtual void deleteXLinkAt (int);		// remove references and delete XLinkObj 
    4.36  	virtual XLinkObj* XLinkAt (int);		// return reference of XLinkObj 
    4.37 -	virtual int countXLink ();
    4.38  	virtual BranchObj* XLinkTargetAt (int);
    4.39 +
    4.40  	void setIncludeImagesVer(bool);
    4.41  	bool getIncludeImagesVer();
    4.42  	void setIncludeImagesHor(bool);
    4.43  	bool getIncludeImagesHor();
    4.44  	QString getIncludeImageAttr();
    4.45 +
    4.46  	virtual FloatImageObj* addFloatImage();
    4.47  	virtual FloatImageObj* addFloatImage(FloatImageObj*);
    4.48  	virtual void removeFloatImage(FloatImageObj*);
    4.49 @@ -100,13 +90,16 @@
    4.50      virtual void removeChildren();  
    4.51      virtual void removeBranch(BranchObj*);  
    4.52      virtual void removeBranchPtr (BranchObj*);  
    4.53 +
    4.54      virtual BranchObj* getFirstBranch();
    4.55      virtual BranchObj* getLastBranch();
    4.56  	virtual BranchObj* getBranchNum(int);
    4.57 +
    4.58      virtual bool canMoveBranchUp();
    4.59      virtual BranchObj* moveBranchUp(BranchObj*);
    4.60      virtual bool canMoveBranchDown();
    4.61      virtual BranchObj* moveBranchDown(BranchObj*);
    4.62 +
    4.63      virtual void sortChildren();
    4.64      virtual BranchObj* linkTo (BranchObj*, int);
    4.65      virtual void alignRelativeTo(const QPointF, bool alignSelf=false );
    4.66 @@ -134,11 +127,10 @@
    4.67  public:	
    4.68  	float angle;					// used in mainbranch to reorder mainbranches
    4.69  protected:	
    4.70 -	bool scrolled;					// true if all children are scrolled and thus invisible
    4.71 -	bool tmpUnscrolled;				// can only be true (temporary) for a scrolled subtree
    4.72 +//	bool scrolled;					// true if all children are scrolled and thus invisible
    4.73 +//	bool tmpUnscrolled;				// can only be true (temporary) for a scrolled subtree
    4.74  	bool includeImagesVer;			// include floatimages in bbox vertically
    4.75  	bool includeImagesHor;			// include floatimages in bbox horizontally
    4.76 -
    4.77  };
    4.78  
    4.79  
     5.1 Binary file demos/vym-projectplan.vym has changed
     6.1 --- a/exports.cpp	Tue Mar 31 15:36:10 2009 +0000
     6.2 +++ b/exports.cpp	Wed Apr 01 15:06:57 2009 +0000
     6.3 @@ -108,13 +108,13 @@
     6.4  {
     6.5  	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
     6.6  	QString r;
     6.7 -	BranchObj *bo=bostart;
     6.8 -	int depth=bo->getDepth();
     6.9 +	TreeItem *ti=bostart->getTreeItem();
    6.10 +	int depth=ti->depth();
    6.11  	while (depth>0)
    6.12  	{
    6.13 -		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
    6.14 -		bo=(BranchObj*)(bo->getParObj());
    6.15 -		depth=bo->getDepth();
    6.16 +		r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
    6.17 +		ti=ti->parent(); 
    6.18 +		depth=ti->depth();
    6.19  	}	
    6.20  	if (r.isEmpty())
    6.21  		return r;
     7.1 --- a/mainwindow.cpp	Tue Mar 31 15:36:10 2009 +0000
     7.2 +++ b/mainwindow.cpp	Wed Apr 01 15:06:57 2009 +0000
     7.3 @@ -8,6 +8,7 @@
     7.4  
     7.5  #include "aboutdialog.h"
     7.6  #include "branchpropwindow.h"
     7.7 +#include "branchitem.h"
     7.8  #include "exportoofiledialog.h"
     7.9  #include "exports.h"
    7.10  #include "file.h"
    7.11 @@ -2888,7 +2889,7 @@
    7.12      stats+=QString ("%1 notes\n").arg (n,6);
    7.13      stats+=QString ("%1 images\n").arg (f,6);
    7.14  */
    7.15 -    stats+=QString ("%1 branches\n").arg (m->countBranches(),6);
    7.16 +    stats+=QString ("%1 branches\n").arg (m->branchCount(),6);
    7.17  	dia.setStats (stats);
    7.18  
    7.19  	// Finally show dialog
    7.20 @@ -3608,8 +3609,10 @@
    7.21  		if ( (typeid(*selection) == typeid(BranchObj)) || 
    7.22  			(typeid(*selection) == typeid(MapCenterObj))  )
    7.23  		{
    7.24 +			BranchItem *bi=(BranchItem*)(selection->getTreeItem() );
    7.25  			BranchObj *bo=(BranchObj*)selection;
    7.26 -			// Take care of links
    7.27 +			// Take care of links  // FIXME-1
    7.28 +			/*
    7.29  			if (bo->countXLinks()==0)
    7.30  			{
    7.31  				branchXLinksContextMenuEdit->clear();
    7.32 @@ -3633,11 +3636,12 @@
    7.33  					}	
    7.34  				}
    7.35  			}
    7.36 +			*/
    7.37  
    7.38  			standardFlagsDefault->setEnabled (true);
    7.39  
    7.40  			actionToggleScroll->setEnabled (true);
    7.41 -			if ( bo->isScrolled() )
    7.42 +			if ( bi->isScrolled() )
    7.43  				actionToggleScroll->setOn(true);
    7.44  			else	
    7.45  				actionToggleScroll->setOn(false);
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/mapcenteritem.cpp	Wed Apr 01 15:06:57 2009 +0000
     8.3 @@ -0,0 +1,118 @@
     8.4 +#include "mapcenteritem.h"
     8.5 +#include "mapcenterobj.h"
     8.6 +
     8.7 +#include <iostream>
     8.8 +using namespace std;
     8.9 +
    8.10 +MapCenterItem::MapCenterItem(const QList<QVariant> &data, TreeItem *parent):BranchItem (data,parent)
    8.11 +{
    8.12 +	scrolled=false;
    8.13 +	tmpUnscrolled=false;
    8.14 +}
    8.15 +
    8.16 +MapCenterItem::~MapCenterItem()
    8.17 +{
    8.18 +	cout << "Destr. MapCenterItem\n";
    8.19 +    qDeleteAll(childItems);
    8.20 +}
    8.21 +
    8.22 +QString MapCenterItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
    8.23 +{
    8.24 +	// Cloudy stuff can be hidden during exports
    8.25 +	if (hidden) return QString();
    8.26 +
    8.27 +    QString s,a;
    8.28 +	BranchObj *bo=(BranchObj*)lmo;
    8.29 +
    8.30 +	/* FIXME-1
    8.31 +	// Update of note is usually done while unselecting a branch
    8.32 +	if (isNoteInEditor) getNoteFromTextEditor();
    8.33 +	
    8.34 +	QString scrolledAttr;
    8.35 +	if (scrolled) 
    8.36 +		scrolledAttr=attribut ("scrolled","yes");
    8.37 +	else
    8.38 +		scrolledAttr="";
    8.39 +
    8.40 +	// save area, if not scrolled
    8.41 +	QString areaAttr;
    8.42 +	if (!((BranchObj*)(parObj))->isScrolled() )
    8.43 +	{
    8.44 +		areaAttr=
    8.45 +			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
    8.46 +			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
    8.47 +			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
    8.48 +			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
    8.49 +
    8.50 +	} else
    8.51 +		areaAttr="";
    8.52 +	
    8.53 +	// Providing an ID for a branch makes export to XHTML easier
    8.54 +	QString idAttr;
    8.55 +	if (countXLinks()>0)
    8.56 +		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
    8.57 +	else
    8.58 +		idAttr="";
    8.59 +
    8.60 +	*/
    8.61 +    s=beginElement ("branch" 
    8.62 +	//	+getOrnXMLAttr() 
    8.63 +	//	+scrolledAttr 
    8.64 +	//	+areaAttr 
    8.65 +	//	+idAttr 
    8.66 +	//	+getIncludeImageAttr() 
    8.67 +		);
    8.68 +    incIndent();
    8.69 +
    8.70 +	// save heading
    8.71 +    s+=valueElement("heading", getHeading(),
    8.72 +		attribut ("textColor",QColor( bo->getColor()).name()));
    8.73 +
    8.74 +/*
    8.75 +	// Save frame
    8.76 +	if (frame->getFrameType()!=FrameObj::NoFrame) 
    8.77 +		s+=frame->saveToDir ();
    8.78 +
    8.79 +	// save names of flags set
    8.80 +	s+=standardFlags->saveToDir(tmpdir,prefix,0);
    8.81 +	
    8.82 +	// Save FloatImages
    8.83 +	for (int i=0; i<floatimage.size(); ++i)
    8.84 +		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
    8.85 +*/
    8.86 +
    8.87 +	// save note
    8.88 +	if (!note.isEmpty() )
    8.89 +		s+=note.saveToDir();
    8.90 +	
    8.91 +	// Save branches
    8.92 +	TreeItem *ti=getFirstBranch();
    8.93 +	TreeItem *last=getLastBranch();
    8.94 +	while (ti && ti!=last) 
    8.95 +		s+=ti->saveToDir(tmpdir,prefix,offset);
    8.96 +
    8.97 +	/*
    8.98 +	// Save XLinks
    8.99 +	QString ol;	// old link
   8.100 +	QString cl;	// current link
   8.101 +	for (int i=0; i<xlink.size(); ++i)
   8.102 +	{
   8.103 +		cl=xlink.at(i)->saveToDir();
   8.104 +		if (cl!=ol)
   8.105 +		{
   8.106 +			s+=cl;
   8.107 +			ol=cl;
   8.108 +		} else
   8.109 +		{
   8.110 +			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
   8.111 +		}
   8.112 +	}	
   8.113 +	*/
   8.114 +
   8.115 +    decIndent();
   8.116 +    s+=endElement   ("branch");
   8.117 +    return s;
   8.118 +}
   8.119 +
   8.120 +
   8.121 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/mapcenteritem.h	Wed Apr 01 15:06:57 2009 +0000
     9.3 @@ -0,0 +1,16 @@
     9.4 +#ifndef MAPCENTERITEM_H
     9.5 +#define MAPCENTERITEM_H
     9.6 +
     9.7 +#include "branchitem.h"
     9.8 +
     9.9 +
    9.10 +class MapCenterItem:public BranchItem
    9.11 +{
    9.12 +public:
    9.13 +    MapCenterItem(const QList<QVariant> &data, TreeItem *parent = 0);
    9.14 +    ~MapCenterItem();
    9.15 +
    9.16 +	QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset);
    9.17 +};
    9.18 +
    9.19 +#endif
    10.1 --- a/mapcenterobj.cpp	Tue Mar 31 15:36:10 2009 +0000
    10.2 +++ b/mapcenterobj.cpp	Wed Apr 01 15:06:57 2009 +0000
    10.3 @@ -145,7 +145,7 @@
    10.4  	
    10.5  	// Providing an ID for a branch makes export to XHTML easier
    10.6  	QString idAttr;
    10.7 -	if (countXLinks()>0)
    10.8 +	if (treeItem->xlinkCount()>0)
    10.9  		idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
   10.10  
   10.11  	else
    11.1 --- a/mapeditor.cpp	Tue Mar 31 15:36:10 2009 +0000
    11.2 +++ b/mapeditor.cpp	Wed Apr 01 15:06:57 2009 +0000
    11.3 @@ -870,22 +870,24 @@
    11.4  				// We have a destination, relink to that
    11.5  
    11.6  				BranchObj* bsel=model->getSelectedBranch();
    11.7 +				TreeItem * tisel=model->getSelectedItem();
    11.8  				BranchObj* bdst=(BranchObj*)dst;
    11.9 +				TreeItem* tidst=dst->getTreeItem();
   11.10  
   11.11  				QString preParStr=model->getSelectString (bsel->getParObj());
   11.12 -				QString preNum=QString::number (bsel->getNum(),10);
   11.13 +				QString preNum=QString::number (tisel->num(),10);
   11.14  				QString preDstParStr;
   11.15  
   11.16  				if (e->state() & Qt::ShiftModifier && dst->getParObj())
   11.17  				{	// Link above dst
   11.18  					preDstParStr=model->getSelectString (dst->getParObj());
   11.19 -					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
   11.20 +					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num());
   11.21  				} else 
   11.22  				if (e->state() & Qt::ControlModifier && dst->getParObj())
   11.23  				{
   11.24  					// Link below dst
   11.25  					preDstParStr=model->getSelectString (dst->getParObj());
   11.26 -					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
   11.27 +					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num()+1);
   11.28  				} else	
   11.29  				{	// Append to dst
   11.30  					preDstParStr=model->getSelectString(dst);
   11.31 @@ -893,7 +895,7 @@
   11.32  					if (dst->getDepth()==0) bsel->move (savePos);
   11.33  				} 
   11.34  				QString postSelStr=model->getSelectString(lmosel);
   11.35 -				QString postNum=QString::number (bsel->getNum(),10);
   11.36 +				QString postNum=QString::number (tisel->num(),10);
   11.37  
   11.38  				QString undoCom="linkTo (\""+ 
   11.39  					preParStr+ "\"," + preNum  +"," + 
    12.1 --- a/treeitem.cpp	Tue Mar 31 15:36:10 2009 +0000
    12.2 +++ b/treeitem.cpp	Wed Apr 01 15:06:57 2009 +0000
    12.3 @@ -22,8 +22,6 @@
    12.4  	note.setNote(""); 
    12.5  	// note.setFontHint (textEditor->getFontHintDefault() );	//FIXME-2
    12.6  	// isNoteInEditor=false;
    12.7 -
    12.8 -
    12.9  }
   12.10  
   12.11  TreeItem::~TreeItem()
   12.12 @@ -108,6 +106,19 @@
   12.13  {
   12.14      return branchCounter;
   12.15  }
   12.16 +
   12.17 +int TreeItem::imageCount() const
   12.18 +{
   12.19 +	int imageCounter=0;
   12.20 +    return imageCounter; // FIXME-1 imageCounter needs to be calculated...
   12.21 +}
   12.22 +
   12.23 +int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?)
   12.24 +{
   12.25 +	int xlinkCounter=0;
   12.26 +    return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated...
   12.27 +}
   12.28 +
   12.29  int TreeItem::row() const
   12.30  {
   12.31      if (parentItem)
   12.32 @@ -148,7 +159,19 @@
   12.33  		case Image: return -1; // FIXME-2
   12.34  		default: return -1;
   12.35  	}
   12.36 -	
   12.37 +}
   12.38 +
   12.39 +int TreeItem::num (TreeItem *item)
   12.40 +{
   12.41 +	if (!item) return -1;
   12.42 +	switch (item->getType())
   12.43 +	{
   12.44 +		case Undefined: return -1;
   12.45 +		case MapCenter: return childItems.indexOf (this) - branchOffset;
   12.46 +		case Branch: return childItems.indexOf (this) - branchOffset;
   12.47 +		case Image: return -1; // FIXME-2
   12.48 +		default: return -1;
   12.49 +	}
   12.50  }
   12.51  
   12.52  QVariant TreeItem::data(int column) const
    13.1 --- a/treeitem.h	Tue Mar 31 15:36:10 2009 +0000
    13.2 +++ b/treeitem.h	Wed Apr 01 15:06:57 2009 +0000
    13.3 @@ -31,12 +31,18 @@
    13.4      int childNumber() const;
    13.5      int columnCount() const;
    13.6  	int branchCount() const;
    13.7 +	int imageCount() const;
    13.8 +	int xlinkCount() const;
    13.9  
   13.10      int row() const;
   13.11  	int column() const;
   13.12  	int depth() ;
   13.13      TreeItem *parent();
   13.14 -	int num();		// object index, e.g. branch number
   13.15 +
   13.16 +	/*! Return number of item in parent by type, 
   13.17 +	    e.g. first branch has number 0           */
   13.18 +	int num();		
   13.19 +	int num (TreeItem *item);	//! Return number of item by type
   13.20  
   13.21  	// Accessing data
   13.22      QVariant data(int column) const;
    14.1 --- a/vym.pro	Tue Mar 31 15:36:10 2009 +0000
    14.2 +++ b/vym.pro	Wed Apr 01 15:06:57 2009 +0000
    14.3 @@ -55,6 +55,7 @@
    14.4  	linkablemapobj.h \
    14.5  	mainwindow.h \
    14.6  	mapcenterobj.h \
    14.7 +	mapcenteritem.h \
    14.8  	mapeditor.h \
    14.9  	mapobj.h \
   14.10  	misc.h \
   14.11 @@ -112,6 +113,7 @@
   14.12  	linkablemapobj.cpp \
   14.13  	main.cpp \
   14.14  	mainwindow.cpp \
   14.15 +	mapcenteritem.cpp \
   14.16  	mapcenterobj.cpp \
   14.17  	mapeditor.cpp \
   14.18  	mapobj.cpp \
    15.1 --- a/vymmodel.cpp	Tue Mar 31 15:36:10 2009 +0000
    15.2 +++ b/vymmodel.cpp	Wed Apr 01 15:06:57 2009 +0000
    15.3 @@ -3,6 +3,8 @@
    15.4  
    15.5  #include "vymmodel.h"
    15.6  
    15.7 +#include "branchitem.h"
    15.8 +#include "mapcenteritem.h"
    15.9  #include "editxlinkdialog.h"
   15.10  #include "exports.h"
   15.11  #include "exportxhtmldialog.h"
   15.12 @@ -223,7 +225,7 @@
   15.13  		mapAttr+= xml.attribut("author",author) +
   15.14  				  xml.attribut("comment",comment) +
   15.15  			      xml.attribut("date",getDate()) +
   15.16 -				  xml.attribut("countBranches", QString().number(countBranches())) +
   15.17 +				  xml.attribut("branchCount", QString().number(branchCount())) +
   15.18  		          xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
   15.19  		          xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
   15.20  		          xml.attribut("linkStyle", ls ) +
   15.21 @@ -830,9 +832,10 @@
   15.22  			{
   15.23  				dst->addBranch();
   15.24  				bo=dst->getLastBranch();
   15.25 -				bo->setHeading (fi.fileName() );
   15.26 +				BranchItem *bi=(BranchItem*)(bo->getTreeItem());
   15.27 +				bi->setHeading (fi.fileName() );	// FIXME-3 check this
   15.28  				bo->setColor (QColor("blue"));
   15.29 -				bo->toggleScroll();
   15.30 +				bi->toggleScroll();
   15.31  				if ( !d.cd(fi.fileName()) ) 
   15.32  					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
   15.33  				else 
   15.34 @@ -1318,7 +1321,7 @@
   15.35  	{
   15.36  		// save the selected branch of the map, Undo will insert part of map 
   15.37  		saveState (PartOfMap,
   15.38 -			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
   15.39 +			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->getTreeItem()->num()),
   15.40  			redoSelection, "delete ()", 
   15.41  			comment, 
   15.42  			redoSel);
   15.43 @@ -1464,7 +1467,7 @@
   15.44  	return QDate::currentDate().toString ("yyyy-MM-dd");
   15.45  }
   15.46  
   15.47 -int VymModel::countBranches()	// FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
   15.48 +int VymModel::branchCount()	// FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
   15.49  {
   15.50  	int c=0;
   15.51  	TreeItem *cur=NULL;
   15.52 @@ -1955,12 +1958,13 @@
   15.53  	}	
   15.54  }
   15.55  
   15.56 -void VymModel::sortChildren()
   15.57 -{
   15.58 +void VymModel::sortChildren()	// FIXME-1 not implemented yet
   15.59 +{
   15.60 +/*
   15.61  	BranchObj* bo=getSelectedBranch();
   15.62  	if (bo)
   15.63  	{
   15.64 -		if(bo->countBranches()>1)
   15.65 +		if(treeItem->branchCount()>1)
   15.66  		{
   15.67  			saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
   15.68  			bo->sortChildren();
   15.69 @@ -1968,6 +1972,7 @@
   15.70  			ensureSelectionVisible();
   15.71  		}
   15.72  	}
   15.73 +*/
   15.74  }
   15.75  
   15.76  void VymModel::createMapCenter()
   15.77 @@ -2026,33 +2031,35 @@
   15.78  
   15.79  MapCenterObj* VymModel::addMapCenter(QPointF absPos)
   15.80  {
   15.81 +
   15.82 +	// Create TreeItem
   15.83 +	QModelIndex parix=index(rootItem);
   15.84 +
   15.85 +	int n=rootItem->branchCount();
   15.86 +
   15.87 +	emit (layoutAboutToBeChanged() );
   15.88 +	beginInsertRows (parix,n,n+1);
   15.89 +
   15.90 +	QList<QVariant> cData;
   15.91 +	cData << "VM:addMapCenter" << "undef"<<"undef";
   15.92 +	MapCenterItem *ti=new MapCenterItem (cData,rootItem);
   15.93 +	cout << "VM::addMapCenter  ti="<<ti<<endl;
   15.94 +	ti->setType (TreeItem::MapCenter);
   15.95 +	rootItem->appendChild (ti);
   15.96 +
   15.97 +	endInsertRows();
   15.98 +	emit (newChildObject (parix));
   15.99 +	emit (layoutChanged() );
  15.100 +
  15.101 +	// Create MapObj
  15.102  	MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
  15.103  	mapCenter->setMapEditor(mapEditor);		//FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
  15.104 +	mapCenter->setTreeItem (ti);	// TreeItem needs to exist before setVisibility
  15.105 +	ti->setLMO (mapCenter);
  15.106  	mapCenter->move (absPos);
  15.107      mapCenter->setVisibility (true);
  15.108  	mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
  15.109  	mapCenters.append(mapCenter);
  15.110 -
  15.111 -	// Create TreeItem
  15.112 -	QModelIndex parix=index(rootItem);
  15.113 -
  15.114 -	int n=rootItem->branchCount();
  15.115 -
  15.116 -	emit (layoutAboutToBeChanged() );
  15.117 -	beginInsertRows (parix,n,n+1);
  15.118 -
  15.119 -	QList<QVariant> cData;
  15.120 -	cData << "VM:addMapCenter" << "undef"<<"undef";
  15.121 -	TreeItem *ti=new TreeItem (cData,rootItem);
  15.122 -	ti->setLMO (mapCenter);
  15.123 -	ti->setType (TreeItem::MapCenter);
  15.124 -	mapCenter->setTreeItem (ti);
  15.125 -	rootItem->appendChild (ti);
  15.126 -
  15.127 -	endInsertRows();
  15.128 -	emit (newChildObject (parix));
  15.129 -	emit (layoutChanged() );
  15.130 -
  15.131  	// Testing
  15.132  /*
  15.133  	qWarning ("MW::insertRow a");
  15.134 @@ -2097,47 +2104,48 @@
  15.135  	// 0..n		insert in children of parent at pos
  15.136  	BranchObj *newbo=NULL;
  15.137  	BranchObj *bo=getSelectedBranch();
  15.138 +	BranchItem *bi=getSelectedBranchItem();
  15.139  	if (bo)
  15.140  	{
  15.141  		if (num==-2)
  15.142  		{
  15.143 +			// Create TreeItem
  15.144 +			QList<QVariant> cData;
  15.145 +			cData << "new" << "undef"<<"undef";
  15.146 +
  15.147 +			BranchItem *parbi=bi;
  15.148 +			QModelIndex parix=index(parbi);
  15.149 +			int n=parbi->branchCount();
  15.150 +
  15.151 +			emit (layoutAboutToBeChanged() );
  15.152 +			beginInsertRows (parix,n,n+1);
  15.153 +			bi=new BranchItem (cData,parbi);
  15.154 +			bi->setType (TreeItem::Branch);
  15.155 +
  15.156 +			parbi->appendChild (bi);
  15.157 +			endInsertRows ();
  15.158 +			emit (newChildObject (parix));
  15.159 +			emit (layoutChanged() );
  15.160 +
  15.161  			// save scroll state. If scrolled, automatically select
  15.162  			// new branch in order to tmp unscroll parent...
  15.163  			newbo=bo->addBranch();
  15.164  
  15.165 -			// Create TreeItem
  15.166 -			QList<QVariant> cData;
  15.167 -			cData << "new" << "undef"<<"undef";
  15.168 -
  15.169 -			TreeItem *parti=bo->getTreeItem();
  15.170 -			QModelIndex parix=index(parti);
  15.171 -			int n=parti->branchCount();
  15.172 -
  15.173 -			emit (layoutAboutToBeChanged() );
  15.174 -			beginInsertRows (parix,n,n+1);
  15.175 -			TreeItem *ti=new TreeItem (cData,parti);
  15.176 -			ti->setLMO (newbo);
  15.177 -			ti->setType (TreeItem::Branch);
  15.178 -
  15.179 -			parti->appendChild (ti);
  15.180 -			endInsertRows ();
  15.181 -			emit (newChildObject (parix));
  15.182 -			emit (layoutChanged() );
  15.183 -
  15.184  			if (newbo)
  15.185  			{
  15.186 -				newbo->setTreeItem (ti);
  15.187 +				bi->setLMO (newbo);
  15.188 +				newbo->setTreeItem (bi);
  15.189  				select (newbo); // FIXME-2 VM really needed here?
  15.190  			}
  15.191  			
  15.192  		}else if (num==-1)
  15.193  		{
  15.194 -			num=bo->getNum()+1;
  15.195 +			num=bi->num()+1;
  15.196  			bo=(BranchObj*)bo->getParObj();
  15.197  			if (bo) newbo=bo->insertBranch(num);	//FIXME-1 VM still missing 
  15.198  		}else if (num==-3)
  15.199  		{
  15.200 -			num=bo->getNum();
  15.201 +			num=bi->num();
  15.202  			bo=(BranchObj*)bo->getParObj();
  15.203  			if (bo) newbo=bo->insertBranch(num);	//FIXME-1 VM still missing
  15.204  		}
  15.205 @@ -2156,7 +2164,7 @@
  15.206  
  15.207  	if (bo)
  15.208  	{
  15.209 -		// FIXME-1 VM  do we still need this in model? setCursor (Qt::ArrowCursor);
  15.210 +		// FIXME-2 VM  do we still need this in model? setCursor (Qt::ArrowCursor);
  15.211  
  15.212  		newbo=addNewBranchInt (pos-2);
  15.213  
  15.214 @@ -2198,7 +2206,7 @@
  15.215  		BranchObj *parbo=(BranchObj*)(bo->getParObj());
  15.216  
  15.217  		// add below selection
  15.218 -		newbo=parbo->insertBranch(bo->getNum()+1);		//FIXME-1 VM still missing
  15.219 +		newbo=parbo->insertBranch(bo->getTreeItem()->num()+1);		//FIXME-1 VM still missing
  15.220  
  15.221  		if (newbo)
  15.222  		{
  15.223 @@ -2276,8 +2284,8 @@
  15.224  		int n=ix.row();
  15.225  		beginRemoveRows (parentIndex,n,n);
  15.226  		removeRows (n,1,parentIndex);
  15.227 +		endRemoveRows();
  15.228  		par->removeBranch(bo);	// remove from BranchObj lists...
  15.229 -		endRemoveRows();
  15.230  		select (par);
  15.231  		ensureSelectionVisible();
  15.232  		reposition();
  15.233 @@ -2285,7 +2293,7 @@
  15.234  		emit (layoutChanged() );
  15.235  		return;
  15.236  	}
  15.237 -	FloatImageObj *fio=selection.getFloatImage(); 	//FIXME-1 VM still missing
  15.238 +	//FloatImageObj *fio=selection.getFloatImage(); 	//FIXME-1 VM still missing
  15.239  
  15.240  /*
  15.241  	if (fio)
  15.242 @@ -2320,7 +2328,7 @@
  15.243  		if (!par) return;
  15.244  
  15.245  		// Check if we have childs at all to keep
  15.246 -		if (bo->countBranches()==0) 
  15.247 +		if (bo->getTreeItem()->branchCount()==0) 
  15.248  		{
  15.249  			deleteSelection();
  15.250  			return;
  15.251 @@ -2362,16 +2370,17 @@
  15.252  }
  15.253  
  15.254  
  15.255 -bool VymModel::scrollBranch(BranchObj *bo)
  15.256 -{
  15.257 -	if (bo)
  15.258 +bool VymModel::scrollBranch(BranchItem *bi)
  15.259 +{
  15.260 +	if (bi)	
  15.261  	{
  15.262 -		if (bo->isScrolled()) return false;
  15.263 -		if (bo->countBranches()==0) return false;
  15.264 -		if (bo->getDepth()==0) return false;
  15.265 +		if (bi->isScrolled()) return false;
  15.266 +		if (bi->branchCount()==0) return false;
  15.267 +		if (bi->depth()==0) return false;
  15.268  		QString u,r;
  15.269  		r="scroll";
  15.270  		u="unscroll";
  15.271 +		/* FIXME-1 no savestate yet
  15.272  		saveState(
  15.273  			bo,
  15.274  			QString ("%1 ()").arg(u),
  15.275 @@ -2379,24 +2388,27 @@
  15.276  			QString ("%1 ()").arg(r),
  15.277  			QString ("%1 %2").arg(r).arg(getObjectName(bo))
  15.278  		);
  15.279 -		bo->toggleScroll();
  15.280 -		selection.update();
  15.281 +		*/
  15.282 +		bi->toggleScroll();
  15.283 +		//selection.update();
  15.284  		// FIXME-3 VM needed? scene()->update();
  15.285  		return true;
  15.286  	}	
  15.287  	return false;
  15.288  }
  15.289  
  15.290 -bool VymModel::unscrollBranch(BranchObj *bo)
  15.291 -{
  15.292 -	if (bo)
  15.293 +bool VymModel::unscrollBranch(BranchItem *bi)
  15.294 +{
  15.295 +	if (bi)
  15.296  	{
  15.297 -		if (!bo->isScrolled()) return false;
  15.298 -		if (bo->countBranches()==0) return false;
  15.299 -		if (bo->getDepth()==0) return false;
  15.300 +		if (bi->isScrolled()) return false;
  15.301 +		if (bi->branchCount()==0) return false;
  15.302 +		if (bi->depth()==0) return false;
  15.303 +
  15.304  		QString u,r;
  15.305  		u="scroll";
  15.306  		r="unscroll";
  15.307 +		/* FIXME-1 no savestate yet
  15.308  		saveState(
  15.309  			bo,
  15.310  			QString ("%1 ()").arg(u),
  15.311 @@ -2404,8 +2416,9 @@
  15.312  			QString ("%1 ()").arg(r),
  15.313  			QString ("%1 %2").arg(r).arg(getObjectName(bo))
  15.314  		);
  15.315 -		bo->toggleScroll();
  15.316 -		selection.update();
  15.317 +		*/
  15.318 +		bi->toggleScroll();
  15.319 +		// selection.update();
  15.320  		// FIXME-3 VM needed? scene()->update();
  15.321  		return true;
  15.322  	}	
  15.323 @@ -2414,13 +2427,13 @@
  15.324  
  15.325  void VymModel::toggleScroll()
  15.326  {
  15.327 -	BranchObj *bo=getSelectedBranch();
  15.328 -	if (selectionType()==TreeItem::Branch )
  15.329 +	BranchItem *bi=(BranchItem*)getSelectedBranchItem();
  15.330 +	if (bi && bi->getType()==TreeItem::Branch )
  15.331  	{
  15.332 -		if (bo->isScrolled())
  15.333 -			unscrollBranch (bo);
  15.334 +		if (bi->isScrolled())
  15.335 +			unscrollBranch (bi);
  15.336  		else
  15.337 -			scrollBranch (bo);
  15.338 +			scrollBranch (bi);
  15.339  	}
  15.340  }
  15.341  
  15.342 @@ -2722,6 +2735,7 @@
  15.343  void VymModel::parseAtom(const QString &atom)
  15.344  {
  15.345  	BranchObj *selb=getSelectedBranch();
  15.346 +	BranchItem *bi=getSelectedBranchItem();
  15.347  	QString s,t;
  15.348  	double x,y;
  15.349  	int n;
  15.350 @@ -3260,7 +3274,7 @@
  15.351  			parser.setError (Aborted,"Type of selection is not a branch");
  15.352  		} else if (parser.checkParCount(0))
  15.353  		{	
  15.354 -			if (!scrollBranch (selb))	
  15.355 +			if (!scrollBranch (bi))	
  15.356  				parser.setError (Aborted,"Could not scroll branch");
  15.357  		}	
  15.358  	/////////////////////////////////////////////////////////////////////
  15.359 @@ -3611,7 +3625,7 @@
  15.360  			parser.setError (Aborted,"Type of selection is not a branch");
  15.361  		} else if (parser.checkParCount(0))
  15.362  		{	
  15.363 -			if (!unscrollBranch (selb))	
  15.364 +			if (!unscrollBranch (bi))	
  15.365  				parser.setError (Aborted,"Could not unscroll branch");
  15.366  		}	
  15.367  	/////////////////////////////////////////////////////////////////////
  15.368 @@ -4669,7 +4683,7 @@
  15.369  					b=select (s);
  15.370  					if (b)
  15.371  					{	
  15.372 -						if ( getSelectedBranch()->countBranches()>0)
  15.373 +						if ( getSelectedItem()->branchCount()>0)
  15.374  							s+=",bo:0";
  15.375  						else	
  15.376  							break;
  15.377 @@ -4749,8 +4763,8 @@
  15.378  				{
  15.379  					b=select (s);
  15.380  					if (b)
  15.381 -						if ( getSelectedBranch()->countBranches()>0)
  15.382 -							s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 );
  15.383 +						if ( getSelectedItem()->branchCount()>0)
  15.384 +							s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 );
  15.385  						else	
  15.386  							break;
  15.387  					else
  15.388 @@ -4974,7 +4988,7 @@
  15.389  		return NULL;
  15.390  }
  15.391  
  15.392 -TreeItem* VymModel::getSelectedBranchItem()
  15.393 +BranchItem* VymModel::getSelectedBranchItem()
  15.394  {
  15.395  	QModelIndexList list=selModel->selectedIndexes();
  15.396  	if (!list.isEmpty() )
  15.397 @@ -4982,7 +4996,7 @@
  15.398  		TreeItem *ti = getItem (list.first() );
  15.399  		TreeItem::Type type=ti->getType();
  15.400  		if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
  15.401 -			return ti;
  15.402 +			return (BranchItem*)ti;
  15.403  	}
  15.404  	return NULL;
  15.405  }
  15.406 @@ -5019,26 +5033,32 @@
  15.407  		return QString();
  15.408  }
  15.409  
  15.410 -QString VymModel::getSelectString (LinkableMapObj *lmo)	// FIXME-2 VM needs to use TreeModel
  15.411 +QString VymModel::getSelectString (LinkableMapObj *lmo)	// FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
  15.412 +{
  15.413 +	if (!lmo) return QString();
  15.414 +	return getSelectString (lmo->getTreeItem() );
  15.415 +}
  15.416 +
  15.417 +QString VymModel::getSelectString (TreeItem *ti)
  15.418  {
  15.419  	QString s;
  15.420 -	if (!lmo) return s;
  15.421 -	if (typeid(*lmo)==typeid(BranchObj) ||
  15.422 -		typeid(*lmo)==typeid(MapCenterObj) )
  15.423 +	if (!ti) return s;
  15.424 +	if (ti->getType() == TreeItem::Branch ||
  15.425 +	    ti->getType() == TreeItem::MapCenter)
  15.426  	{	
  15.427 -		LinkableMapObj *par=lmo->getParObj();
  15.428 +		TreeItem *par=ti->parent();
  15.429  		if (par)
  15.430  		{
  15.431 -			if (lmo->getDepth() ==1)
  15.432 +			if (ti->depth() ==1)
  15.433  				// Mainbranch, return 
  15.434 -				s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
  15.435 +				s= "bo:" + QString("%1").arg(ti->num() );
  15.436  			else	
  15.437  				// Branch, call myself recursively
  15.438 -				s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
  15.439 +				s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
  15.440  		} else
  15.441  		{
  15.442  			// MapCenter
  15.443 -			int i=mapCenters.indexOf ((MapCenterObj*)lmo);
  15.444 +			int i=rootItem->num(ti);
  15.445  			if (i>=0) s=QString("mc:%1").arg(i);
  15.446  		}	
  15.447  	}	
    16.1 --- a/vymmodel.h	Tue Mar 31 15:36:10 2009 +0000
    16.2 +++ b/vymmodel.h	Wed Apr 01 15:06:57 2009 +0000
    16.3 @@ -12,6 +12,8 @@
    16.4  #include "treeitem.h"
    16.5  #include "treemodel.h"
    16.6  
    16.7 +class BranchItem;
    16.8 +
    16.9  class VymModel : public TreeModel {		
   16.10  	Q_OBJECT
   16.11  
   16.12 @@ -231,7 +233,7 @@
   16.13  	void setComment (const QString &);
   16.14  	QString getComment ();
   16.15  	QString getDate();
   16.16 -	int countBranches();
   16.17 +	int branchCount();
   16.18  
   16.19  public:	
   16.20  	void setHeading(const QString &);		//!< Set heading of branch	
   16.21 @@ -322,8 +324,8 @@
   16.22  	void deleteChildren();					//!< keep branch, but remove children
   16.23  
   16.24  private:	
   16.25 -	bool scrollBranch(BranchObj*);
   16.26 -	bool unscrollBranch(BranchObj*);
   16.27 +	bool scrollBranch(BranchItem *);
   16.28 +	bool unscrollBranch(BranchItem *);
   16.29  public:	
   16.30      void toggleScroll();
   16.31      void unscrollChildren();
   16.32 @@ -568,12 +570,13 @@
   16.33  	TreeItem::Type selectionType();
   16.34  	LinkableMapObj* getSelectedLMO();
   16.35  	BranchObj* getSelectedBranch();
   16.36 -	TreeItem* getSelectedBranchItem();
   16.37 +	BranchItem* getSelectedBranchItem();
   16.38  	TreeItem* getSelectedItem();
   16.39  	QModelIndex getSelectedIndex();
   16.40  	FloatImageObj* getSelectedFloatImage();
   16.41  	QString getSelectString ();
   16.42  	QString getSelectString (LinkableMapObj *lmo);
   16.43 +	QString getSelectString (TreeItem *item);
   16.44  	
   16.45  	
   16.46  	/*
    17.1 --- a/xml-freemind.cpp	Tue Mar 31 15:36:10 2009 +0000
    17.2 +++ b/xml-freemind.cpp	Wed Apr 01 15:06:57 2009 +0000
    17.3 @@ -5,12 +5,12 @@
    17.4  #include <QTextStream>
    17.5  #include <iostream>
    17.6  
    17.7 +#include "branchitem.h"
    17.8  #include "misc.h"
    17.9  #include "settings.h"
   17.10  #include "linkablemapobj.h"
   17.11  #include "version.h"
   17.12  
   17.13 -static BranchObj *lastBranch;
   17.14  //static FloatObj *lastFloat;
   17.15  static OrnamentedObj *lastOO;
   17.16  
   17.17 @@ -266,9 +266,10 @@
   17.18  bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)
   17.19  {
   17.20  	lastOO=lastBranch;
   17.21 +	lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() );
   17.22  
   17.23  	if (a.value( "FOLDED")=="true" )
   17.24 -		lastBranch->toggleScroll();
   17.25 +		lastBranchItem->toggleScroll();
   17.26  	if (!a.value( "TEXT").isEmpty() )
   17.27  		lastBranch->setHeading (a.value ("TEXT"));
   17.28  
    18.1 --- a/xml-freemind.h	Tue Mar 31 15:36:10 2009 +0000
    18.2 +++ b/xml-freemind.h	Wed Apr 01 15:06:57 2009 +0000
    18.3 @@ -37,5 +37,7 @@
    18.4  	State state;			 
    18.5  	State laststate;
    18.6  	QList <State> stateStack;
    18.7 +	BranchItem *lastBranchItem;
    18.8 +	BranchObj *lastBranch;
    18.9  }; 
   18.10  #endif
    19.1 --- a/xml-vym.cpp	Tue Mar 31 15:36:10 2009 +0000
    19.2 +++ b/xml-vym.cpp	Wed Apr 01 15:06:57 2009 +0000
    19.3 @@ -6,13 +6,13 @@
    19.4  #include <iostream>
    19.5  #include <typeinfo>
    19.6  
    19.7 +#include "branchitem.h"
    19.8  #include "misc.h"
    19.9  #include "settings.h"
   19.10  #include "linkablemapobj.h"
   19.11  #include "mainwindow.h"
   19.12  #include "version.h"
   19.13  
   19.14 -static BranchObj *lastBranch;
   19.15  static FloatObj *lastFloat;
   19.16  static OrnamentedObj *lastOO;
   19.17  
   19.18 @@ -55,14 +55,15 @@
   19.19  			// Create mapCenter
   19.20  			model->clear();
   19.21  			lastBranch=NULL;
   19.22 +			lastBranchItem=NULL;
   19.23  
   19.24  			if (!atts.value( "author").isEmpty() )
   19.25  				model->setAuthor(atts.value( "author" ) );
   19.26  			if (!atts.value( "comment").isEmpty() )
   19.27  				model->setComment (atts.value( "comment" ) );
   19.28 -			if (!atts.value( "countBranches").isEmpty() )
   19.29 +			if (!atts.value( "branchCount").isEmpty() )
   19.30  			{
   19.31 -				branchesTotal=atts.value("countBranches").toInt();
   19.32 +				branchesTotal=atts.value("branchCount").toInt();
   19.33  				if (branchesTotal>10)
   19.34  				{
   19.35  					mainWindow->setProgressMinimum (0);
   19.36 @@ -356,10 +357,12 @@
   19.37  	branchesCurrent++;
   19.38  	mainWindow->setProgressValue (branchesCurrent);
   19.39  	lastOO=lastBranch;
   19.40 +	lastBranchItem=(BranchItem*)(lastBranch->getTreeItem());
   19.41 +
   19.42  	if (!readOOAttr(a)) return false;
   19.43  
   19.44  	if (!a.value( "scrolled").isEmpty() )
   19.45 -		lastBranch->toggleScroll();
   19.46 +		lastBranchItem->toggleScroll();
   19.47  	if (!a.value( "frameType").isEmpty() ) 
   19.48  		lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1
   19.49  
    20.1 --- a/xml-vym.h	Tue Mar 31 15:36:10 2009 +0000
    20.2 +++ b/xml-vym.h	Wed Apr 01 15:06:57 2009 +0000
    20.3 @@ -3,6 +3,8 @@
    20.4  
    20.5  #include "xml-base.h"
    20.6  
    20.7 +class BranchItem;
    20.8 +
    20.9  /*! \brief Parsing VYM maps from XML documents */
   20.10  
   20.11  class parseVYMHandler  : public parseBaseHandler
   20.12 @@ -50,5 +52,8 @@
   20.13  	QList <State> stateStack;
   20.14  	QString htmldata;
   20.15  	NoteObj no;
   20.16 +
   20.17 +	BranchObj* lastBranch;
   20.18 +	BranchItem* lastBranchItem;
   20.19  }; 
   20.20  #endif