vymmodel.cpp
changeset 754 db0ec4bcf416
parent 753 25a77484ec72
child 755 ed5b407975b3
     1.1 --- a/vymmodel.cpp	Tue Apr 07 16:15:53 2009 +0000
     1.2 +++ b/vymmodel.cpp	Mon Apr 20 10:42:05 2009 +0000
     1.3 @@ -72,11 +72,7 @@
     1.4  {
     1.5  	selModel->clearSelection();
     1.6  
     1.7 -	// Remove stuff    
     1.8 -	while (!mapCenters.isEmpty())			// FIXME-2 VM needs to be in treemodel only...
     1.9 -		delete mapCenters.takeFirst();
    1.10 -
    1.11 -	QModelIndex ri=index(rootItem);
    1.12 +	//QModelIndex ri=index(rootItem);
    1.13  	//removeRows (0, rowCount(ri),ri);		// FIXME-2 here should be at least a beginRemoveRows...
    1.14  }
    1.15  
    1.16 @@ -273,12 +269,12 @@
    1.17  	return s;
    1.18  }
    1.19  
    1.20 -QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
    1.21 +QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)	// FIXME-4 verbose not needed (used to write icons)
    1.22  {
    1.23      QString s;
    1.24  
    1.25 -	for (int i=0; i<mapCenters.count(); i++)
    1.26 -		s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
    1.27 +	for (int i=0; i<rootItem->branchCount(); i++)	// FIXME-0 remove mapCenters
    1.28 +		s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
    1.29      return s;
    1.30  }
    1.31  
    1.32 @@ -1405,21 +1401,8 @@
    1.33  	return mapScene;
    1.34  }
    1.35  
    1.36 -LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
    1.37 -{
    1.38 -	LinkableMapObj *lmo;
    1.39 -
    1.40 -	for (int i=0;i<mapCenters.count(); i++)
    1.41 -	{
    1.42 -		lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
    1.43 -		if (lmo) return lmo;
    1.44 -	}
    1.45 -	return NULL;
    1.46 -}
    1.47 -
    1.48 -LinkableMapObj* VymModel::findObjBySelect(const QString &s)
    1.49 -{
    1.50 -	LinkableMapObj *lmo;
    1.51 +TreeItem* VymModel::findBySelectString(const QString &s)
    1.52 +{
    1.53  	if (!s.isEmpty() )
    1.54  	{
    1.55  		QString part;
    1.56 @@ -1428,25 +1411,26 @@
    1.57  		part=s.section(",",0,0);
    1.58  		typ=part.left (2);
    1.59  		num=part.right(part.length() - 3);
    1.60 -		if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
    1.61 -			return mapCenters.at(num.toInt() );
    1.62 +		if (typ=="mc" && num.toInt()>=0 && num.toInt() <rootItem->branchCount() )
    1.63 +			return rootItem->getBranchNum (num.toInt() );
    1.64  	}		
    1.65  
    1.66 -	for (int i=0; i<mapCenters.count(); i++)
    1.67 +	TreeItem *ti;
    1.68 +	for (int i=0; i<rootItem->branchCount(); i++)
    1.69  	{
    1.70 -		lmo=mapCenters.at(i)->findObjBySelect(s);
    1.71 -		if (lmo) return lmo;
    1.72 +		ti=rootItem->getBranchNum(i)->findBySelectString(s);
    1.73 +		if (ti) return ti;
    1.74  	}	
    1.75  	return NULL;
    1.76  }
    1.77  
    1.78 -LinkableMapObj* VymModel::findID (const QString &s)
    1.79 -{
    1.80 -	LinkableMapObj *lmo;
    1.81 -	for (int i=0; i<mapCenters.count(); i++)
    1.82 +TreeItem* VymModel::findID (const QString &s)
    1.83 +{
    1.84 +	TreeItem *ti;
    1.85 +	for (int i=0; i<rootItem->branchCount(); i++)
    1.86  	{
    1.87 -		lmo=mapCenters.at(i)->findID (s);
    1.88 -		if (lmo) return lmo;
    1.89 +		ti=rootItem->getBranchNum(i)->findID (s);
    1.90 +		if (ti) return ti;
    1.91  	}	
    1.92  	return NULL;
    1.93  }
    1.94 @@ -1466,7 +1450,6 @@
    1.95  		QString ("setMapAuthor (\"%1\")").arg(s),
    1.96  		QString ("Set author of map to \"%1\"").arg(s)
    1.97  	);
    1.98 -
    1.99  	author=s;
   1.100  }
   1.101  
   1.102 @@ -1482,7 +1465,6 @@
   1.103  		QString ("setMapComment (\"%1\")").arg(s),
   1.104  		QString ("Set comment of map")
   1.105  	);
   1.106 -
   1.107  	comment=s;
   1.108  }
   1.109  
   1.110 @@ -1509,7 +1491,6 @@
   1.111  		next(cur,prev,d);
   1.112  	}
   1.113  	return c;
   1.114 -
   1.115  }
   1.116  
   1.117  void VymModel::setHeading(const QString &s)
   1.118 @@ -1600,8 +1581,6 @@
   1.119  	EOFind=false;
   1.120  }
   1.121  
   1.122 -
   1.123 -
   1.124  void VymModel::setScene (QGraphicsScene *s)
   1.125  {
   1.126  	mapScene=s;	// FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
   1.127 @@ -1662,26 +1641,25 @@
   1.128  	*/
   1.129  }
   1.130  
   1.131 -void VymModel::linkFloatImageTo(const QString &dstString)	
   1.132 +void VymModel::linkFloatImageTo(const QString &dstString)	// FIXME-2
   1.133  {
   1.134  	FloatImageObj *fio=selection.getFloatImage();
   1.135  	if (fio)
   1.136  	{
   1.137 -		BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
   1.138 -		if (dst && (typeid(*dst)==typeid (BranchObj) || 
   1.139 -					typeid(*dst)==typeid (MapCenterObj)))
   1.140 +		TreeItem *dst=findBySelectString (dstString);
   1.141 +		if (dst && dst->isBranchLikeType() )
   1.142  		{			
   1.143 -			LinkableMapObj *dstPar=dst->getParObj();
   1.144 +			TreeItem *dstPar=dst->parent();
   1.145  			QString parString=getSelectString(dstPar);
   1.146  			QString fioPreSelectString=getSelectString(fio);
   1.147  			QString fioPreParentSelectString=getSelectString (fio->getParObj());
   1.148 -			((BranchObj*)dst)->addFloatImage (fio);
   1.149 -			selection.unselect();
   1.150 -			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
   1.151 +			// FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
   1.152 +			unselect();
   1.153 +			// ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
   1.154  			fio=((BranchObj*)dst)->getLastFloatImage();
   1.155  			fio->setRelPos();
   1.156  			fio->reposition();
   1.157 -			selection.select(fio);
   1.158 +			// select (fio);
   1.159  			saveState(
   1.160  				getSelectString(fio),
   1.161  				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
   1.162 @@ -2105,14 +2083,13 @@
   1.163  
   1.164  	// Create MapObj
   1.165  	MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
   1.166 -	mapCenter->setMapEditor(mapEditor);		//FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
   1.167 +	//mapCenter->setMapEditor(mapEditor);		//FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
   1.168  	mapCenter->setTreeItem (mci);	// TreeItem needs to exist before setVisibility
   1.169  	mci->setLMO (mapCenter);
   1.170  	mapCenter->updateHeading();
   1.171  	mapCenter->move (absPos);
   1.172      mapCenter->setVisibility (true);
   1.173  	//mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
   1.174 -	mapCenters.append(mapCenter);	//FIXME-1 get rid of mapCenters...
   1.175  	// Testing
   1.176  /*
   1.177  	qWarning ("MW::insertRow a");
   1.178 @@ -2134,19 +2111,15 @@
   1.179  	{
   1.180  		mapCenters.removeAt (i);
   1.181  		delete (mco);
   1.182 -		if (i>0) return mapCenters.at(i-1);	// Return previous MCO
   1.183 +		if (i>0) return rootItem->getBranchNum(i-1);	// Return previous MCO
   1.184  	}
   1.185  */	
   1.186  	return NULL;
   1.187  }
   1.188  
   1.189 -MapCenterObj* VymModel::getLastMapCenter()
   1.190 -{
   1.191 -	if (mapCenters.size()>0)
   1.192 -		return mapCenters.last();
   1.193 -	else
   1.194 -		return NULL;
   1.195 -
   1.196 +MapCenterObj* VymModel::getLastMapCenter()		// FIXME-3 still needed?
   1.197 +{
   1.198 +	return (MapCenterObj*)rootItem->getLastBranch();
   1.199  }
   1.200  
   1.201  
   1.202 @@ -3942,8 +3915,10 @@
   1.203  void VymModel::registerEditor(QWidget *me)
   1.204  {
   1.205  	mapEditor=(MapEditor*)me;
   1.206 -	for (int i=0; i<mapCenters.count(); i++)
   1.207 -		mapCenters.at(i)->setMapEditor(mapEditor);
   1.208 +	/* FIXME-3
   1.209 +	for (int i=0; i<rootItem->branchCount(); i++)
   1.210 +		rootItem->getBranchNum(i)->setMapEditor(mapEditor);
   1.211 +	*/
   1.212  }
   1.213  
   1.214  void VymModel::unregisterEditor(QWidget *)
   1.215 @@ -3975,16 +3950,18 @@
   1.216  	*/
   1.217  }
   1.218  
   1.219 -void VymModel::updateRelPositions()
   1.220 -{
   1.221 -	for (int i=0; i<mapCenters.count(); i++)
   1.222 -		mapCenters.at(i)->updateRelPositions();
   1.223 +void VymModel::updateRelPositions()		//FIXME-2 VM should have no need to updateRelPos
   1.224 +{
   1.225 +	cout << "VM::updateRelPos...\n";
   1.226 +	for (int i=0; i<rootItem->branchCount(); i++)
   1.227 +		((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
   1.228  }
   1.229  
   1.230 -void VymModel::reposition()	//FIXME-2 get rid of mapCenters...
   1.231 -{
   1.232 -	for (int i=0;i<mapCenters.count(); i++)
   1.233 -		mapCenters.at(i)->reposition();	//	for positioning heading
   1.234 +void VymModel::reposition()	//FIXME-2 VM should have no need to reposition, this is done in views???
   1.235 +{
   1.236 +	cout << "VM::reposition ...\n";
   1.237 +	for (int i=0;i<rootItem->branchCount(); i++)
   1.238 +		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
   1.239  }
   1.240  
   1.241  QPolygonF VymModel::shape(BranchObj *bo)
   1.242 @@ -4028,18 +4005,18 @@
   1.243  	// Move all branches and MapCenters away from lmo 
   1.244  	// to avoid collisions 
   1.245  
   1.246 +		/*
   1.247  	QPolygonF pA;
   1.248  	QPolygonF pB;
   1.249  
   1.250  	BranchObj *boA=(BranchObj*)lmo;
   1.251  	BranchObj *boB;
   1.252 -	for (int i=0; i<mapCenters.count(); i++)
   1.253 +	for (int i=0; i<rootItem->branchCount(); i++)
   1.254  	{
   1.255 -		boB=mapCenters.at(i);
   1.256 +		boB=rootItem->getBranchNum(i);
   1.257  		pA=shape (boA);
   1.258  		pB=shape (boB);
   1.259  		PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
   1.260 -		/*
   1.261  		cout <<"------->"
   1.262  			<<"="<<r.intersect
   1.263  			<<"  ("<<qPrintable(boA->getHeading() )<<")"
   1.264 @@ -4047,8 +4024,8 @@
   1.265  			<<")  willIntersect"
   1.266  			<<r.willIntersect 
   1.267  			<<"  minT="<<r.minTranslation<<endl<<endl;
   1.268 +	}
   1.269  			*/
   1.270 -	}
   1.271  }
   1.272  
   1.273  QPixmap VymModel::getPixmap()
   1.274 @@ -4603,11 +4580,13 @@
   1.275  }
   1.276  
   1.277  
   1.278 -QRectF VymModel::getTotalBBox()
   1.279 +QRectF VymModel::getTotalBBox()	//FIXME-2
   1.280  {
   1.281  	QRectF r;
   1.282 -	for (int i=0;i<mapCenters.count(); i++)
   1.283 -		r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
   1.284 +/*
   1.285 +	for (int i=0;i<rootItem->branchCount(); i++)
   1.286 +		r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
   1.287 +*/ 
   1.288  	return r;	
   1.289  }
   1.290  
   1.291 @@ -4648,13 +4627,11 @@
   1.292  
   1.293  bool VymModel::select (const QString &s)
   1.294  {
   1.295 -	LinkableMapObj *lmo=findObjBySelect(s);
   1.296 -
   1.297 -	// Finally select the found object
   1.298 -	if (lmo)
   1.299 +	TreeItem *ti=findBySelectString(s);
   1.300 +	if (ti)
   1.301  	{
   1.302  		unselect();
   1.303 -		select (lmo);
   1.304 +		select (ti);
   1.305  		return true;
   1.306  	} 
   1.307  	return false;
   1.308 @@ -4677,7 +4654,6 @@
   1.309  		QModelIndex ix=index(ti);
   1.310  		selModel->select (ix,QItemSelectionModel::ClearAndSelect  );
   1.311  		ti->setLastSelectedBranch();
   1.312 -		//updateSelection(oldsel);	//FIXME-3 needed?
   1.313  		return true;
   1.314  	}
   1.315  	return false;
   1.316 @@ -4960,12 +4936,12 @@
   1.317  				// left of center
   1.318  				if (type == TreeItem::Branch )
   1.319  				{
   1.320 +					cout << "VM::selLeft\n";
   1.321  					selectLastSelectedBranch();
   1.322  					return;
   1.323  				}
   1.324  			}
   1.325  		}	
   1.326 -		updateSelection (oldsel);
   1.327  	}
   1.328  }
   1.329  
   1.330 @@ -5001,12 +4977,12 @@
   1.331  				if (type == TreeItem::Branch ||
   1.332  					type == TreeItem::Image)
   1.333  				{
   1.334 +					cout << "VM::selRight\n";
   1.335  					QModelIndex ix=index(selbi->parent());
   1.336  					selModel->select (ix,QItemSelectionModel::ClearAndSelect  );
   1.337  				}
   1.338  			}
   1.339  		}	
   1.340 -		updateSelection (oldsel);
   1.341  	}
   1.342  }
   1.343