vymmodel.cpp
changeset 795 6b0a5f4923d3
parent 794 d922fb6ea482
child 796 cf634bbf9e04
     1.1 --- a/vymmodel.cpp	Fri Sep 11 12:56:15 2009 +0000
     1.2 +++ b/vymmodel.cpp	Thu Sep 17 09:41:09 2009 +0000
     1.3 @@ -640,7 +640,7 @@
     1.4  	return err;
     1.5  }
     1.6  
     1.7 -void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)	// FIXME-1 test e.g. with undo color subtree
     1.8 +void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)	
     1.9  {
    1.10  	QString pathDir=path.left(path.findRev("/"));
    1.11  	QDir d(pathDir);
    1.12 @@ -1077,7 +1077,6 @@
    1.13  
    1.14  
    1.15  	parseAtom (redoCommand);
    1.16 -	reposition();
    1.17  
    1.18  	blockSaveState=blockSaveStateOrg;
    1.19  
    1.20 @@ -1156,7 +1155,6 @@
    1.21  		cout << "    ---------------------------"<<endl<<endl;
    1.22  	}	
    1.23  	parseAtom (undoCommand);
    1.24 -	reposition();
    1.25  
    1.26  	undosAvail--;
    1.27  	curStep--; 
    1.28 @@ -1180,7 +1178,7 @@
    1.29  
    1.30  	mainWindow->updateHistory (undoSet);
    1.31  	updateActions();
    1.32 -	emitSelectionChanged();
    1.33 +	//emitSelectionChanged();
    1.34  }
    1.35  
    1.36  bool VymModel::isUndoAvailable()
    1.37 @@ -1439,7 +1437,7 @@
    1.38  	return  ti;
    1.39  }
    1.40  
    1.41 -TreeItem* VymModel::findID (const QString &s)
    1.42 +TreeItem* VymModel::findID (const QString &s)	//FIXME-4 Search also other types...
    1.43  {
    1.44  	BranchItem *cur=NULL;
    1.45  	BranchItem *prev=NULL;
    1.46 @@ -1602,9 +1600,7 @@
    1.47  
    1.48  void VymModel::setScene (QGraphicsScene *s)
    1.49  {
    1.50 -	mapScene=s;	// FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
    1.51 -    //init();	// Here we have a mapScene set, 
    1.52 -			// which is (still) needed to create MapCenters
    1.53 +	mapScene=s;	
    1.54  }
    1.55  
    1.56  void VymModel::setURL(const QString &url) 
    1.57 @@ -1918,47 +1914,80 @@
    1.58  	}
    1.59  }
    1.60  
    1.61 -void VymModel::moveUp()	//FIXME-2 crashes if trying to move MCO
    1.62 +bool VymModel::moveUp(BranchItem *bi)	//FIXME-2 crashes if trying to move MCO
    1.63 +{
    1.64 +	if (bi && bi->canMoveUp()) 
    1.65 +		return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
    1.66 +	else	
    1.67 +		return false;
    1.68 +}
    1.69 +
    1.70 +void VymModel::moveUp()	
    1.71  {
    1.72  	BranchItem *selbi=getSelectedBranch();
    1.73  	if (selbi)
    1.74  	{
    1.75 -		if (!selbi->canMoveUp()) return;
    1.76  		QString oldsel=getSelectString();
    1.77 -		if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
    1.78 -
    1.79 -			saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
    1.80 +		if (moveUp (selbi))
    1.81 +			saveState (
    1.82 +				getSelectString(),"moveDown ()",
    1.83 +				oldsel,"moveUp ()",
    1.84 +				QString("Move up %1").arg(getObjectName(selbi)));
    1.85  	}
    1.86  }
    1.87  
    1.88 +bool VymModel::moveDown(BranchItem *bi)	
    1.89 +{
    1.90 +	if (bi && bi->canMoveDown())
    1.91 +		return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
    1.92 +	else
    1.93 +		return false;
    1.94 +}
    1.95 +
    1.96  void VymModel::moveDown()	
    1.97  {
    1.98  	BranchItem *selbi=getSelectedBranch();
    1.99  	if (selbi)
   1.100  	{
   1.101 -		if (!selbi->canMoveDown()) return;
   1.102  		QString oldsel=getSelectString();
   1.103 -		if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
   1.104 -
   1.105 -			saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
   1.106 +		if ( moveDown(selbi))
   1.107 +			saveState (
   1.108 +				getSelectString(),"moveUp ()",
   1.109 +				oldsel,"moveDown ()",
   1.110 +				QString("Move down %1").arg(getObjectName(selbi)));
   1.111  	}
   1.112  }
   1.113  
   1.114 -void VymModel::sortChildren()	// FIXME-2 not implemented yet
   1.115 -{
   1.116 -/*
   1.117 -	BranchObj* bo=getSelectedBranch();
   1.118 -	if (bo)
   1.119 +void VymModel::detach()	
   1.120 +{
   1.121 +	BranchItem *selbi=getSelectedBranch();
   1.122 +	if (selbi && selbi->depth()>0)
   1.123  	{
   1.124 -		if(treeItem->branchCount()>1)
   1.125 +		//QString oldsel=getSelectString();
   1.126 +		if ( relinkBranch (selbi,rootItem,-1) )
   1.127 +			saveState (
   1.128 +				selbi,QString("relink()"), //FIXME-1 add paramters
   1.129 +				selbi,"detach ()",
   1.130 +				QString("Detach %1").arg(getObjectName(selbi))
   1.131 +			);
   1.132 +	}
   1.133 +}
   1.134 +
   1.135 +void VymModel::sortChildren()
   1.136 +{
   1.137 +	BranchItem* selbi=getSelectedBranch();
   1.138 +	if (selbi)
   1.139 +	{
   1.140 +		if(selbi->branchCount()>1)
   1.141  		{
   1.142 -			saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
   1.143 -			bo->sortChildren();
   1.144 +			saveStateChangingPart(
   1.145 +				selbi,selbi, "sortChildren ()",
   1.146 +				QString("Sort children of %1").arg(getObjectName(selbi)));
   1.147 +			selbi->sortChildren();
   1.148  			reposition();
   1.149  			emitShowSelection();
   1.150  		}
   1.151  	}
   1.152 -*/
   1.153  }
   1.154  
   1.155  BranchItem* VymModel::createMapCenter()
   1.156 @@ -2437,7 +2466,6 @@
   1.157  
   1.158  TreeItem* VymModel::deleteItem (TreeItem *ti)
   1.159  {
   1.160 -	cout << "VM::deleteItem "<<ti<<"  "<<getSelectString(ti).toStdString()<<endl;
   1.161  	if (ti)
   1.162  	{
   1.163  		TreeItem *pi=ti->parent();
   1.164 @@ -2457,6 +2485,29 @@
   1.165  	return NULL;
   1.166  }
   1.167  
   1.168 +void VymModel::clearItem (TreeItem *ti)
   1.169 +{
   1.170 +	if (ti)
   1.171 +	{
   1.172 +		QModelIndex parentIndex=index(ti);
   1.173 +		if (!parentIndex.isValid()) return;
   1.174 +
   1.175 +		int n=ti->childCount();
   1.176 +		if (n==0) return;
   1.177 +
   1.178 +		emit (layoutAboutToBeChanged() );
   1.179 +
   1.180 +		beginRemoveRows (parentIndex,0,n-1);
   1.181 +		removeRows (0,n,parentIndex);
   1.182 +		endRemoveRows();
   1.183 +		reposition();
   1.184 +
   1.185 +		emit (layoutChanged() );
   1.186 +
   1.187 +	}	
   1.188 +	return ;
   1.189 +}
   1.190 +
   1.191  bool VymModel::scrollBranch(BranchItem *bi)
   1.192  {
   1.193  	if (bi)	
   1.194 @@ -2478,7 +2529,7 @@
   1.195  			);
   1.196  			emitDataHasChanged(bi);
   1.197  			emitSelectionChanged();
   1.198 -			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x //FIXME-3 force update via signal...
   1.199 +			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x 
   1.200  			return true;
   1.201  		}
   1.202  	}	
   1.203 @@ -2492,7 +2543,9 @@
   1.204  		if (!bi->isScrolled()) return false;
   1.205  		if (bi->branchCount()==0) return false;
   1.206  		if (bi->depth()==0) return false;
   1.207 -
   1.208 +		if (bi->toggleScroll())
   1.209 +		{
   1.210 +			reposition();
   1.211  		QString u,r;
   1.212  		u="scroll";
   1.213  		r="unscroll";
   1.214 @@ -2503,13 +2556,12 @@
   1.215  			QString ("%1 ()").arg(r),
   1.216  			QString ("%1 %2").arg(r).arg(getObjectName(bi))
   1.217  		);
   1.218 -		bi->toggleScroll();
   1.219  		emitDataHasChanged(bi);
   1.220  		emitSelectionChanged();
   1.221 -
   1.222 -		mapScene->update(); //Needed for _quick_ update,  even in 1.13.x //FIXME-3 force update via signal...
   1.223 +			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x 
   1.224  		return true;
   1.225  	}	
   1.226 +	}	
   1.227  	return false;
   1.228  }
   1.229  
   1.230 @@ -2523,24 +2575,34 @@
   1.231  		else
   1.232  			scrollBranch (bi);
   1.233  	}
   1.234 -	// saveState is called in above functions
   1.235 +	// saveState & reposition are called in above functions
   1.236  }
   1.237  
   1.238 -void VymModel::unscrollChildren() 	// FIXME-2	first, next moved to vymmodel
   1.239 -
   1.240 -{
   1.241 -/*
   1.242 -	BranchObj *bo=getSelectedBranch();
   1.243 -	if (bo)
   1.244 +void VymModel::unscrollChildren() 	//FIXME-2 does not update flag yet, possible segfault
   1.245 +{
   1.246 +	BranchItem *selbi=getSelectedBranch();
   1.247 +	BranchItem *prev=NULL;
   1.248 +	BranchItem *cur=selbi;
   1.249 +	if (selbi)
   1.250  	{
   1.251 -		bo->first();
   1.252 -		while (bo) 
   1.253 +		saveStateChangingPart(
   1.254 +			selbi,
   1.255 +			selbi,
   1.256 +			QString ("unscrollChildren ()"),
   1.257 +			QString ("unscroll all children of %1").arg(getObjectName(selbi))
   1.258 +		);	
   1.259 +		while (cur) 
   1.260  		{
   1.261 -			if (bo->isScrolled()) unscrollBranch (bo);
   1.262 -			bo=bo->next();
   1.263 +			if (cur->isScrolled())
   1.264 +			{
   1.265 +				cur->toggleScroll(); 
   1.266 +				emitDataHasChanged (cur);
   1.267  		}
   1.268 +			cur=next (cur,prev,selbi);
   1.269 +		}	
   1.270 +		updateActions();
   1.271 +		reposition();
   1.272  	}	
   1.273 -*/	
   1.274  }
   1.275  
   1.276  void VymModel::emitExpandAll()
   1.277 @@ -2606,6 +2668,7 @@
   1.278  			QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
   1.279  		);	
   1.280  		selbi->setHeadingColor(c); // color branch
   1.281 +		mapScene->update();
   1.282  	}
   1.283  }
   1.284  
   1.285 @@ -2627,7 +2690,7 @@
   1.286  			cur->setHeadingColor(c); // color links, color children
   1.287  			cur=next (cur,prev,selbi);
   1.288  		}	
   1.289 -
   1.290 +	mapScene->update();
   1.291  	}
   1.292  }
   1.293  
   1.294 @@ -4057,82 +4120,16 @@
   1.295  	*/
   1.296  }
   1.297  
   1.298 -void VymModel::reposition()	//FIXME-3 VM should have no need to reposition, this is done in views???
   1.299 +void VymModel::reposition()	//FIXME-4 VM should have no need to reposition, but the views...
   1.300  {
   1.301  	//cout << "VM::reposition blocked="<<blockReposition<<endl;
   1.302  	if (blockReposition) return;
   1.303  
   1.304  	for (int i=0;i<rootItem->branchCount(); i++)
   1.305  		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
   1.306 -	emitSelectionChanged();	
   1.307 +	//emitSelectionChanged();	
   1.308  }
   1.309  
   1.310 -/*
   1.311 -QPolygonF VymModel::shape(BranchObj *bo)	//FIXME-4
   1.312 -{
   1.313 -	return QPolygonF ();
   1.314 -	// Creating (arbitrary) shapes
   1.315 -
   1.316 -	QPolygonF p;
   1.317 -	QRectF rb=bo->getBBox();
   1.318 -	if (bo->getDepth()==0)
   1.319 -	{
   1.320 -		// Just take BBox of this mapCenter
   1.321 -		p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
   1.322 -		return p;
   1.323 -	}
   1.324 -
   1.325 -	// Take union of BBox and TotalBBox 
   1.326 -
   1.327 -	QRectF ra=bo->getTotalBBox();
   1.328 -	if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
   1.329 -		p   <<ra.bottomLeft()
   1.330 -			<<ra.topLeft()
   1.331 -			<<QPointF (rb.topLeft().x(), ra.topLeft().y() )
   1.332 -			<<rb.topRight()
   1.333 -			<<rb.bottomRight()
   1.334 -			<<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
   1.335 -	else		
   1.336 -		p   <<ra.bottomRight()
   1.337 -			<<ra.topRight()
   1.338 -			<<QPointF (rb.topRight().x(), ra.topRight().y() )
   1.339 -			<<rb.topLeft()
   1.340 -			<<rb.bottomLeft()
   1.341 -			<<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
   1.342 -	return p;		
   1.343 -}
   1.344 -*/
   1.345 -
   1.346 -/*
   1.347 -void VymModel::moveAway(LinkableMapObj *lmo)	//FIXME-5
   1.348 -{
   1.349 -	// Autolayout:
   1.350 -	//
   1.351 -	// Move all branches and MapCenters away from lmo 
   1.352 -	// to avoid collisions 
   1.353 -
   1.354 -	QPolygonF pA;
   1.355 -	QPolygonF pB;
   1.356 -
   1.357 -	BranchObj *boA=(BranchObj*)lmo;
   1.358 -	BranchObj *boB;
   1.359 -	for (int i=0; i<rootItem->branchCount(); i++)
   1.360 -	{
   1.361 -		boB=rootItem->getBranchNum(i);
   1.362 -		pA=shape (boA);
   1.363 -		pB=shape (boB);
   1.364 -		PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
   1.365 -		cout <<"------->"
   1.366 -			<<"="<<r.intersect
   1.367 -			<<"  ("<<qPrintable(boA->getHeading() )<<")"
   1.368 -			<<"  with ("<< qPrintable (boB->getHeading() )
   1.369 -			<<")  willIntersect"
   1.370 -			<<r.willIntersect 
   1.371 -			<<"  minT="<<r.minTranslation<<endl<<endl;
   1.372 -	}
   1.373 -}
   1.374 -*/
   1.375 -
   1.376  
   1.377  void VymModel::setMapLinkStyle (const QString & s)
   1.378  {
   1.379 @@ -4274,7 +4271,7 @@
   1.380  	}
   1.381  }	
   1.382  
   1.383 -void VymModel::setMapBackgroundImage (const QString &fn)	//FIXME-2 missing savestate, move to ME
   1.384 +void VymModel::setMapBackgroundImage (const QString &fn)	//FIXME-3 missing savestate, move to ME
   1.385  {
   1.386  	QColor oldcol=mapScene->backgroundBrush().color();
   1.387  	/*
   1.388 @@ -4753,24 +4750,6 @@
   1.389  }
   1.390  
   1.391  
   1.392 -//bool VymModel::selectInt (LinkableMapObj *lmo)	// FIXME-3 still needed?
   1.393 -/*
   1.394 -{
   1.395 -	if (selection.select(lmo))
   1.396 -	{
   1.397 -		//emitSelectionChanged();
   1.398 -	}
   1.399 -}
   1.400 -
   1.401 -bool VymModel::selectInt (TreeItem *ti)	
   1.402 -{
   1.403 -	if (selection.select(lmo))
   1.404 -	{
   1.405 -		//emitSelectionChanged();
   1.406 -	}
   1.407 -}
   1.408 -*/
   1.409 -
   1.410  bool VymModel::selectFirstBranch()
   1.411  {
   1.412  	TreeItem *ti=getSelectedBranch();