vymmodel.cpp
changeset 755 ed5b407975b3
parent 754 db0ec4bcf416
child 756 a8a5c7288f57
     1.1 --- a/vymmodel.cpp	Mon Apr 20 10:42:05 2009 +0000
     1.2 +++ b/vymmodel.cpp	Thu Apr 23 12:15:31 2009 +0000
     1.3 @@ -2008,10 +2008,9 @@
     1.4  	return mci;
     1.5  }
     1.6  
     1.7 -BranchItem* VymModel::createBranch()	// FIXME-2 switcht addNewBrancInt to BranchItem...
     1.8 -{
     1.9 -	BranchObj* bo=addNewBranchInt (-2);
    1.10 -	return (BranchItem*)bo->getTreeItem();
    1.11 +BranchItem* VymModel::createBranch()	
    1.12 +{
    1.13 +	return addNewBranchInt (-2);
    1.14  }
    1.15  
    1.16  TreeItem* VymModel::createImage()	//FIXME-2
    1.17 @@ -2123,7 +2122,7 @@
    1.18  }
    1.19  
    1.20  
    1.21 -BranchObj* VymModel::addNewBranchInt(int num)
    1.22 +BranchItem* VymModel::addNewBranchInt(int num)
    1.23  {
    1.24  	// Depending on pos:
    1.25  	// -3		insert in children of parent  above selection 
    1.26 @@ -2158,6 +2157,8 @@
    1.27  
    1.28  			// save scroll state. If scrolled, automatically select
    1.29  			// new branch in order to tmp unscroll parent...
    1.30 +			newbo=bi->createMapObj(mapScene);
    1.31 +			/*
    1.32  			newbo=bo->addBranch();
    1.33  
    1.34  			if (newbo)
    1.35 @@ -2166,63 +2167,70 @@
    1.36  				newbo->setTreeItem (bi);
    1.37  				select (bi); 
    1.38  			}
    1.39 +			*/
    1.40 +			select (bi);
    1.41  			
    1.42  		}else if (num==-1)
    1.43  		{
    1.44 +		/*
    1.45  			num=bi->num()+1;
    1.46  			bo=(BranchObj*)bo->getParObj();
    1.47  			if (bo) newbo=bo->insertBranch(num);	//FIXME-1 VM still missing 
    1.48 +		*/	
    1.49  		}else if (num==-3)
    1.50  		{
    1.51 +		/*
    1.52  			num=bi->num();
    1.53  			bo=(BranchObj*)bo->getParObj();
    1.54  			if (bo) newbo=bo->insertBranch(num);	//FIXME-1 VM still missing
    1.55 +		*/	
    1.56  		}
    1.57  	}	
    1.58 -	return newbo;
    1.59 +	return bi;
    1.60  }	
    1.61  
    1.62 -BranchObj* VymModel::addNewBranch(int pos)
    1.63 +BranchItem* VymModel::addNewBranch(int pos)
    1.64  {
    1.65  	// Different meaning than num in addNewBranchInt!
    1.66  	// -1	add above
    1.67  	//  0	add as child
    1.68  	// +1	add below
    1.69 -	BranchObj *bo = getSelectedBranchObj();	//FIXME-2
    1.70 -	BranchObj *newbo=NULL;
    1.71 -
    1.72 -	if (bo)
    1.73 +	BranchItem *newbi=NULL;
    1.74 +	BranchItem *selbi=getSelectedBranchItem();
    1.75 +
    1.76 +	if (selbi)
    1.77  	{
    1.78  		// FIXME-2 VM  do we still need this in model? setCursor (Qt::ArrowCursor);
    1.79  
    1.80 -		newbo=addNewBranchInt (pos-2);
    1.81 -
    1.82 -		if (newbo)
    1.83 +		newbi=addNewBranchInt (pos-2);
    1.84 +
    1.85 +		if (newbi)
    1.86  		{
    1.87  			saveState(
    1.88 -				newbo->getTreeItem(),		
    1.89 +				newbi,		
    1.90  				"delete ()",
    1.91 -				bo->getTreeItem(),
    1.92 +				selbi,
    1.93  				QString ("addBranch (%1)").arg(pos),
    1.94 -				QString ("Add new branch to %1").arg(getObjectName(bo)));	
    1.95 +				QString ("Add new branch to %1").arg(getObjectName(selbi)));	
    1.96  
    1.97  			reposition();
    1.98  			// selection.update(); FIXME-3
    1.99 -			latestSelectionString=getSelectString(newbo);
   1.100 +			latestSelectionString=getSelectString(newbi);
   1.101  			// In Network mode, the client needs to know where the new branch is,
   1.102  			// so we have to pass on this information via saveState.
   1.103  			// TODO: Get rid of this positioning workaround
   1.104 -			QString ps=qpointfToString (newbo->getAbsPos());
   1.105 +			/* FIXME-4  network problem:  QString ps=qpointfToString (newbo->getAbsPos());
   1.106  			sendData ("selectLatestAdded ()");
   1.107  			sendData (QString("move %1").arg(ps));
   1.108  			sendSelection();
   1.109 +			*/
   1.110  		}
   1.111  	}	
   1.112 -	return newbo;
   1.113 +	return newbi;
   1.114  }
   1.115  
   1.116  
   1.117 -BranchObj* VymModel::addNewBranchBefore()	//FIXME-2
   1.118 +BranchItem* VymModel::addNewBranchBefore()	//FIXME-2
   1.119  {
   1.120  /*
   1.121  	BranchObj *newbo=NULL;
   1.122 @@ -2258,6 +2266,22 @@
   1.123  	return NULL;
   1.124  }
   1.125  
   1.126 +BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
   1.127 +{
   1.128 +	cout << "VM::relinkBranch  "<<branch->getHeadingStd()<<"  to "<<dst->getHeadingStd()<<"  at pos="<<pos<<endl;
   1.129 +	if (branch && dst)
   1.130 +	{
   1.131 +		BranchItem *branchpi=(BranchItem*)branch->parent();
   1.132 +		BranchItem *dstpi=(BranchItem*)dst->parent();
   1.133 +		if (pos<0)
   1.134 +		{
   1.135 +			// Append as last branch to dst
   1.136 +			branchpi->removeChild (branch->childNum() );
   1.137 +			dst->appendChild (branch);
   1.138 +		}
   1.139 +	}
   1.140 +}
   1.141 +
   1.142  void VymModel::deleteSelection()
   1.143  {
   1.144  	BranchObj *bo = getSelectedBranchObj();	// FIXME-2 VM should not be necessary
   1.145 @@ -2319,7 +2343,7 @@
   1.146  		beginRemoveRows (parentIndex,n,n);
   1.147  		removeRows (n,1,parentIndex);
   1.148  		endRemoveRows();
   1.149 -		par->removeBranch(bo);	// remove from BranchObj lists...
   1.150 +		//	delete (selbi->getLMO() );	// FIXME-0 selbi is removed implicetely, destructor is called. from there BO is deleted, but somhow still segfaulting :-(
   1.151  		select (par);
   1.152  		ensureSelectionVisible();
   1.153  		reposition();
   1.154 @@ -3964,8 +3988,9 @@
   1.155  		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
   1.156  }
   1.157  
   1.158 -QPolygonF VymModel::shape(BranchObj *bo)
   1.159 -{
   1.160 +QPolygonF VymModel::shape(BranchObj *bo)	//FIXME-4
   1.161 +{
   1.162 +/*
   1.163  	// Creating (arbitrary) shapes
   1.164  
   1.165  	QPolygonF p;
   1.166 @@ -3995,7 +4020,7 @@
   1.167  			<<rb.bottomLeft()
   1.168  			<<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
   1.169  	return p;		
   1.170 -
   1.171 +	*/
   1.172  }
   1.173  
   1.174  void VymModel::moveAway(LinkableMapObj *lmo)	//FIXME-5
   1.175 @@ -4354,7 +4379,7 @@
   1.176  
   1.177  void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
   1.178  {
   1.179 -	if (bo && bo->getDepth()>0) 
   1.180 +	if (bo && bo->getTreeItem()->depth()>0) 
   1.181  	{
   1.182  		AnimPoint ap;
   1.183  		ap.setStart (start);
   1.184 @@ -4710,197 +4735,136 @@
   1.185  
   1.186  void VymModel::selectNextBranchInt()
   1.187  {
   1.188 -	// Increase number of branch
   1.189 -	BranchItem *selbi=getSelectedBranchItem();
   1.190 -	if (selbi)
   1.191 +	BranchItem *bi=getSelectedBranchItem();
   1.192 +	if (bi)
   1.193  	{
   1.194 -		QString s=getSelectString();
   1.195 -		QString part;
   1.196 -		QString typ;
   1.197 -		QString num;
   1.198 -
   1.199 -		// Where am I? 
   1.200 -		part=s.section(",",-1);
   1.201 -		typ=part.left (3);
   1.202 -		num=part.right(part.length() - 3);
   1.203 -
   1.204 -		s=s.left (s.length() -num.length());
   1.205 -
   1.206 -		// Go to next lmo
   1.207 -		num=QString ("%1").arg(num.toUInt()+1);
   1.208 -
   1.209 -		s=s+num;
   1.210 +		TreeItem *pi=bi->parent();
   1.211 +		if (bi!=rootItem)
   1.212 +		{
   1.213 +			int i=bi->num();
   1.214 +			if (i<pi->branchCount() )
   1.215 +			{
   1.216 +				// select previous branch with same parent
   1.217 +				i++;
   1.218 +				select (pi->getBranchNum(i));
   1.219 +				return;
   1.220 +			}
   1.221 +		}
   1.222  		
   1.223 -		// Try to select this one
   1.224 -		if (select (s)) return;
   1.225 -
   1.226 -		// We have no direct successor, 
   1.227 -		// try to increase the parental number in order to
   1.228 -		// find a successor with same depth
   1.229 -
   1.230 -		int d=getSelectedBranchItem()->depth();
   1.231 -		int oldDepth=d;
   1.232 -		int i;
   1.233 -		bool found=false;
   1.234 -		bool b;
   1.235 -		while (!found && d>0)
   1.236 -		{
   1.237 -			s=s.section (",",0,d-1);
   1.238 -			// replace substring of current depth in s with "1"
   1.239 -			part=s.section(",",-1);
   1.240 -			typ=part.left (3);
   1.241 -			num=part.right(part.length() - 3);
   1.242 -
   1.243 -			if (d>1)
   1.244 -			{	
   1.245 -				// increase number of parent
   1.246 -				num=QString ("%1").arg(num.toUInt()+1);
   1.247 -				s=s.section (",",0,d-2) + ","+ typ+num;
   1.248 -			} else
   1.249 -			{
   1.250 -				// Special case, look at orientation
   1.251 -				if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)	// FIXME-3 check access to LMO
   1.252 -					num=QString ("%1").arg(num.toUInt()+1);
   1.253 -				else	
   1.254 -					num=QString ("%1").arg(num.toUInt()-1);
   1.255 -				s=typ+num;
   1.256 -			}	
   1.257 -
   1.258 -			if (select (s))
   1.259 -				// pad to oldDepth, select the first branch for each depth
   1.260 -				for (i=d;i<oldDepth;i++)
   1.261 -				{
   1.262 -					b=select (s);
   1.263 -					if (b)
   1.264 -					{	
   1.265 -						if ( getSelectedItem()->branchCount()>0)
   1.266 -							s+=",bo:0";
   1.267 -						else	
   1.268 -							break;
   1.269 -					} else
   1.270 -						break;
   1.271 -				}	
   1.272 -
   1.273 -			// try to select the freshly built string
   1.274 -			found=select(s);
   1.275 -			d--;
   1.276 -		}
   1.277 -		return;
   1.278 -	}	
   1.279 -}
   1.280 -
   1.281 -void VymModel::selectPrevBranchInt()
   1.282 -{
   1.283 -	// Decrease number of branch
   1.284 -	if (selectionType()==TreeItem::Branch)
   1.285 -	{
   1.286 -		QString s=getSelectString();
   1.287 -		QString part;
   1.288 -		QString typ;
   1.289 -		QString num;
   1.290 -
   1.291 -		// Where am I? 
   1.292 -		part=s.section(",",-1);
   1.293 -		typ=part.left (3);
   1.294 -		num=part.right(part.length() - 3);
   1.295 -
   1.296 -		s=s.left (s.length() -num.length());
   1.297 -
   1.298 -		int n=num.toInt()-1;
   1.299 -		
   1.300 -		// Go to next lmo
   1.301 -		num=QString ("%1").arg(n);
   1.302 -		s=s+num;
   1.303 -		
   1.304 -		// Try to select this one
   1.305 -		if (n>=0 && select (s)) return;
   1.306 -
   1.307 -		// We have no direct precessor, 
   1.308 -		// try to decrease the parental number in order to
   1.309 -		// find a precessor with same depth
   1.310 -
   1.311 -		int d=getSelectedBranchItem()->depth();
   1.312 -		int oldDepth=d;
   1.313 -		int i;
   1.314 -		bool found=false;
   1.315 -		bool b;
   1.316 -		while (!found && d>0)
   1.317 -		{
   1.318 -			s=s.section (",",0,d-1);
   1.319 -			// replace substring of current depth in s with "1"
   1.320 -			part=s.section(",",-1);
   1.321 -			typ=part.left (3);
   1.322 -			num=part.right(part.length() - 3);
   1.323 -
   1.324 -			if (d>1)
   1.325 -			{
   1.326 -				// decrease number of parent
   1.327 -				num=QString ("%1").arg(num.toInt()-1);
   1.328 -				s=s.section (",",0,d-2) + ","+ typ+num;
   1.329 -			} else
   1.330 -			{
   1.331 -				// Special case, look at orientation
   1.332 -				if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)	// FIXME-3 check access to LMO
   1.333 -					num=QString ("%1").arg(num.toInt()-1);
   1.334 -				else	
   1.335 -					num=QString ("%1").arg(num.toInt()+1);
   1.336 -				s=typ+num;
   1.337 -			}	
   1.338 -
   1.339 -			if (select(s))
   1.340 -				// pad to oldDepth, select the last branch for each depth
   1.341 -				for (i=d;i<oldDepth;i++)
   1.342 -				{
   1.343 -					b=select (s);
   1.344 -					if (b)
   1.345 -						if ( getSelectedItem()->branchCount()>0)
   1.346 -							s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 );
   1.347 -						else	
   1.348 -							break;
   1.349 -					else
   1.350 -						break;
   1.351 -				}	
   1.352 -			
   1.353 -			// try to select the freshly built string
   1.354 -			found=select(s);
   1.355 -			d--;
   1.356 -		}
   1.357 -		return;
   1.358 -	}	
   1.359 -}
   1.360 -
   1.361 -void VymModel::selectUpperBranch()
   1.362 -{
   1.363 -	if (selection.isBlocked() ) return;
   1.364 -
   1.365 -	BranchItem *bi=getSelectedBranchItem();
   1.366 -	if (bi && bi->getType()==TreeItem::Branch)
   1.367 -	{
   1.368 -		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	//FIXME-3 check getBO
   1.369 -			selectPrevBranchInt();
   1.370 -		else
   1.371 -			if (bi->depth()==1)
   1.372 -				selectNextBranchInt();
   1.373 -			else
   1.374 -				selectPrevBranchInt();
   1.375  	}
   1.376  }
   1.377  
   1.378 +void VymModel::selectPrevBranchInt()
   1.379 +{
   1.380 +
   1.381 +	BranchItem *bi=getSelectedBranchItem();
   1.382 +	if (bi)
   1.383 +	{
   1.384 +		BranchItem *pi=(BranchItem*)bi->parent();
   1.385 +		if (bi!=rootItem)
   1.386 +		{
   1.387 +			int i=bi->num();
   1.388 +			if (i>0)
   1.389 +			{
   1.390 +				// select previous branch with same parent
   1.391 +				bi=pi->getBranchNum(i-1);
   1.392 +				select (bi);
   1.393 +				return;
   1.394 +			}
   1.395 +			bi=pi;
   1.396 +			while (bi->branchCount() >0)
   1.397 +				bi=bi->getLastBranch();
   1.398 +			select (bi);	
   1.399 +
   1.400 +			// Try to select last branch in parent pi2 previous to own parent pi
   1.401 +			/*
   1.402 +			TreeItem *pi2=pi->parent();
   1.403 +			if (pi2)
   1.404 +			{
   1.405 +				int j=pi->num();
   1.406 +				if (pi2->)
   1.407 +			}
   1.408 +			*/
   1.409 +		}
   1.410 +	}
   1.411 +}
   1.412 +
   1.413 +void VymModel::selectAboveBranchInt()
   1.414 +{
   1.415 +	BranchItem *bi=getSelectedBranchItem();
   1.416 +	if (bi)
   1.417 +	{
   1.418 +		BranchItem *newbi=NULL;
   1.419 +		BranchItem *pi=(BranchItem*)bi->parent();
   1.420 +		int i=bi->num();
   1.421 +		if (i>0)
   1.422 +		{
   1.423 +			// goto previous branch with same parent
   1.424 +			newbi=pi->getBranchNum(i-1);
   1.425 +			while (newbi->branchCount() >0 )
   1.426 +				newbi=newbi->getLastBranch();
   1.427 +		}
   1.428 +		else
   1.429 +			newbi=pi;
   1.430 +		if (newbi==rootItem) 
   1.431 + 			// already at top branch (resp. mapcenter)
   1.432 +			return;
   1.433 +		select (newbi);
   1.434 +	}
   1.435 +}
   1.436 +
   1.437 +void VymModel::selectBelowBranchInt()
   1.438 +{
   1.439 +	BranchItem *bi=getSelectedBranchItem();
   1.440 +	if (bi)
   1.441 +	{
   1.442 +		BranchItem *newbi=NULL;
   1.443 +
   1.444 +		if (bi->branchCount() >0)
   1.445 +			newbi=bi->getFirstBranch();
   1.446 +		else
   1.447 +		{
   1.448 +			BranchItem *pi;
   1.449 +			int i;
   1.450 +			while (!newbi)
   1.451 +			{
   1.452 +				pi=(BranchItem*)bi->parent();
   1.453 +				i=bi->num();
   1.454 +				if (pi->branchCount()-1 > i)
   1.455 +				{
   1.456 +					newbi=(BranchItem*)pi->getBranchNum(i+1);
   1.457 +					//done...
   1.458 +					break;
   1.459 +				}	
   1.460 +				else
   1.461 +					// look for siblings of myself 
   1.462 +					// or parent, or parent of parent...
   1.463 +					bi=pi;
   1.464 +				if (bi==rootItem)
   1.465 +					// already at end
   1.466 +					return;
   1.467 +			}	
   1.468 +		}
   1.469 +		select (newbi);
   1.470 +	}
   1.471 +}
   1.472 +
   1.473 +void VymModel::selectUpperBranch()
   1.474 +{
   1.475 +	if (selection.isBlocked() ) return;
   1.476 +
   1.477 +	BranchItem *bi=getSelectedBranchItem();
   1.478 +	if (bi && bi->isBranchLikeType())
   1.479 +		selectAboveBranchInt();
   1.480 +}
   1.481 +
   1.482  void VymModel::selectLowerBranch()
   1.483  {
   1.484  	if (selection.isBlocked() ) return;
   1.485  
   1.486  	BranchItem *bi=getSelectedBranchItem();
   1.487 -	if (bi && bi->getType()==TreeItem::Branch)
   1.488 -	{
   1.489 -		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	//FIXME-3 check getBO
   1.490 -			selectNextBranchInt();
   1.491 -		else
   1.492 -			if (bi->depth()==1)
   1.493 -				selectPrevBranchInt();
   1.494 -			else
   1.495 -				selectNextBranchInt();
   1.496 -	}			
   1.497 +	if (bi && bi->isBranchLikeType())
   1.498 +		selectBelowBranchInt();
   1.499  }
   1.500  
   1.501