vymmodel.cpp
changeset 775 6e4b586aa88a
parent 773 340bc29da9a0
child 776 25e634a7e1dc
     1.1 --- a/vymmodel.cpp	Tue May 26 11:24:51 2009 +0000
     1.2 +++ b/vymmodel.cpp	Wed Jun 03 20:37:17 2009 +0000
     1.3 @@ -11,7 +11,6 @@
     1.4  #include "file.h"
     1.5  #include "geometry.h"		// for addBBox
     1.6  #include "mainwindow.h"
     1.7 -#include "mapcenterobj.h"
     1.8  #include "misc.h"
     1.9  #include "parser.h"
    1.10  
    1.11 @@ -463,7 +462,7 @@
    1.12  		if ( ok ) 
    1.13  		{
    1.14  			reposition();	// FIXME-2 VM reposition the view instead...
    1.15 -			updateSelection();
    1.16 +			emitSelectionChanged();
    1.17  			if (lmode==NewMap)
    1.18  			{
    1.19  				mapDefault=false;
    1.20 @@ -701,9 +700,9 @@
    1.21  */
    1.22  }
    1.23  
    1.24 -FloatImageObj* VymModel::loadFloatImageInt (QString fn)
    1.25 -{
    1.26 -	TreeItem *fi=createImage();
    1.27 +FloatImageObj* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
    1.28 +{
    1.29 +	TreeItem *fi=createImage(dst);
    1.30  	if (fi)
    1.31  	{
    1.32  		FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
    1.33 @@ -714,14 +713,13 @@
    1.34  	return NULL;
    1.35  }	
    1.36  
    1.37 -void VymModel::loadFloatImage ()	// FIXME-2
    1.38 -{
    1.39 -/*
    1.40 -	BranchObj *bo=getSelectedBranch();
    1.41 -	if (bo)
    1.42 +void VymModel::loadFloatImage ()
    1.43 +{
    1.44 +	BranchItem *selbi=getSelectedBranchItem();
    1.45 +	if (selbi)
    1.46  	{
    1.47  
    1.48 -		Q3FileDialog *fd=new Q3FileDialog( NULL);
    1.49 +		Q3FileDialog *fd=new Q3FileDialog( NULL);	// FIXME-4 get rid of Q3FileDialog
    1.50  		fd->setMode (Q3FileDialog::ExistingFiles);
    1.51  		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
    1.52  		ImagePreview *p =new ImagePreview (fd);
    1.53 @@ -741,24 +739,26 @@
    1.54  			for (int j=0; j<fd->selectedFiles().count(); j++)
    1.55  			{
    1.56  				s=fd->selectedFiles().at(j);
    1.57 -				fio=loadFloatImageInt (s);
    1.58 +				fio=loadFloatImageInt (selbi,s);
    1.59 +				//FIXME-1 savestate for loadImage missing
    1.60 +				/*
    1.61  				if (fio)
    1.62  					saveState(
    1.63  						(LinkableMapObj*)fio,
    1.64  						"delete ()",
    1.65 -						bo, 
    1.66 +						selbi, 
    1.67  						QString ("loadImage (%1)").arg(s ),
    1.68 -						QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
    1.69 +						QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
    1.70  					);
    1.71  				else
    1.72  					// TODO loadFIO error handling
    1.73  					qWarning ("Failed to load "+s);
    1.74 +					*/
    1.75  			}
    1.76  		}
    1.77  		delete (p);
    1.78  		delete (fd);
    1.79  	}
    1.80 -*/	
    1.81  }
    1.82  
    1.83  void VymModel::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
    1.84 @@ -1179,7 +1179,7 @@
    1.85  
    1.86  	mainWindow->updateHistory (undoSet);
    1.87  	updateActions();
    1.88 -	updateSelection();
    1.89 +	emitSelectionChanged();
    1.90  }
    1.91  
    1.92  bool VymModel::isUndoAvailable()
    1.93 @@ -1509,7 +1509,7 @@
    1.94  		emitDataHasChanged ( selbi);	//FIXME-3 maybe emit signal from TreeItem? 
    1.95  
    1.96  		reposition();
    1.97 -		updateSelection();
    1.98 +		emitSelectionChanged();
    1.99  	}
   1.100  }
   1.101  
   1.102 @@ -1829,7 +1829,7 @@
   1.103  		);	
   1.104  		updateActions();
   1.105  		reposition();
   1.106 -		// updateSelection();
   1.107 +		// emitSelectionChanged();
   1.108  		// FIXME-3 VM needed? scene()->update();
   1.109  	}
   1.110  }
   1.111 @@ -1960,25 +1960,22 @@
   1.112  BranchItem* VymModel::createMapCenter()
   1.113  {
   1.114  	BranchItem *newbi=addMapCenter (QPointF (0,0) );
   1.115 -	select (newbi);
   1.116  	return newbi;
   1.117  }
   1.118  
   1.119 -BranchItem* VymModel::createBranch()	
   1.120 -{
   1.121 -	BranchItem *selbi=getSelectedBranchItem();
   1.122 -	if (selbi)
   1.123 -		return addNewBranchInt (selbi,-2);
   1.124 +BranchItem* VymModel::createBranch(BranchItem *dst)	
   1.125 +{
   1.126 +	if (dst)
   1.127 +		return addNewBranchInt (dst,-2);
   1.128  	else
   1.129  		return NULL;
   1.130  }
   1.131  
   1.132 -TreeItem* VymModel::createImage()	//FIXME-1
   1.133 +TreeItem* VymModel::createImage(BranchItem *dst)	//FIXME-1
   1.134  {
   1.135  	return NULL;
   1.136  /*
   1.137 -	BranchObj *bo=getSelectedBranch();
   1.138 -	if (bo)
   1.139 +	if (dst)
   1.140  	{
   1.141  		FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
   1.142  
   1.143 @@ -2017,6 +2014,7 @@
   1.144  }
   1.145  
   1.146  BranchItem* VymModel::addMapCenter(QPointF absPos)	//FIXME-2 absPos not used in context menu?!
   1.147 +// createMapCenter could then probably be merged with createBranch
   1.148  {
   1.149  
   1.150  	// Create TreeItem
   1.151 @@ -2037,12 +2035,13 @@
   1.152  	emit (layoutChanged() );
   1.153  
   1.154  	// Create MapObj
   1.155 +	newbi->setPositionMode (MapItem::Absolute);
   1.156  	newbi->createMapObj(mapScene);
   1.157  		
   1.158  	return newbi;
   1.159  }
   1.160  
   1.161 -BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)	//FIXME-4 simplify...
   1.162 +BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)	
   1.163  {
   1.164  	// Depending on pos:
   1.165  	// -3		insert in children of parent  above selection 
   1.166 @@ -2086,7 +2085,6 @@
   1.167  	// new branch in order to tmp unscroll parent...
   1.168  	newbi->createMapObj(mapScene);
   1.169  	reposition();
   1.170 -	select (newbi);
   1.171  	return newbi;
   1.172  }	
   1.173  
   1.174 @@ -2103,7 +2101,6 @@
   1.175  	{
   1.176  		// FIXME-3 setCursor (Qt::ArrowCursor);  //Still needed?
   1.177  
   1.178 -
   1.179  		newbi=addNewBranchInt (selbi,pos-2);
   1.180  
   1.181  		if (newbi)
   1.182 @@ -2116,7 +2113,7 @@
   1.183  				QString ("Add new branch to %1").arg(getObjectName(selbi)));	
   1.184  
   1.185  			reposition();
   1.186 -			// updateSelection(); FIXME-3
   1.187 +			// emitSelectionChanged(); FIXME-3
   1.188  			latestAddedItem=newbi;
   1.189  			// In Network mode, the client needs to know where the new branch is,
   1.190  			// so we have to pass on this information via saveState.
   1.191 @@ -2156,10 +2153,9 @@
   1.192  				QString ("Add branch before %1").arg(getObjectName(selbi)));
   1.193  
   1.194  			// FIXME-3 needed? reposition();
   1.195 -			// updateSelection(); FIXME-3 
   1.196 +			// emitSelectionChanged(); FIXME-3 
   1.197  		}
   1.198  	}	
   1.199 -	//FIXME-3 needed? latestSelectionString=selection.getSelectString();
   1.200  	return newbi;
   1.201  }
   1.202  
   1.203 @@ -2250,43 +2246,46 @@
   1.204  	*/
   1.205  }
   1.206  
   1.207 -void VymModel::deleteKeepChildren()		//FIXME-2 VM still missing
   1.208 -
   1.209 -{
   1.210 -/*
   1.211 -	BranchObj *bo=getSelectedBranch();
   1.212 -	BranchObj *par;
   1.213 -	if (bo)
   1.214 +void VymModel::deleteKeepChildren()	
   1.215 +
   1.216 +{
   1.217 +	BranchItem *selbi=getSelectedBranchItem();
   1.218 +	BranchItem *pi;
   1.219 +	if (selbi)
   1.220  	{
   1.221 -		par=(BranchObj*)(bo->getParObj());
   1.222 -
   1.223  		// Don't use this on mapcenter
   1.224 -		if (!par) return;
   1.225 -
   1.226 +		if (selbi->depth()<2) return;
   1.227 +
   1.228 +		pi=(BranchItem*)(selbi->parent());
   1.229  		// Check if we have childs at all to keep
   1.230 -		if (bo->getTreeItem()->branchCount()==0) 
   1.231 +		if (selbi->branchCount()==0) 
   1.232  		{
   1.233  			deleteSelection();
   1.234  			return;
   1.235  		}
   1.236  
   1.237 -		QPointF p=bo->getRelPos();
   1.238 +		QPointF p;
   1.239 +		if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
   1.240  		saveStateChangingPart(
   1.241 -			bo->getParObj(),
   1.242 -			bo,
   1.243 +			pi,
   1.244 +			selbi,
   1.245  			"deleteKeepChildren ()",
   1.246 -			QString("Remove %1 and keep its children").arg(getObjectName(bo))
   1.247 +			QString("Remove %1 and keep its children").arg(getObjectName(selbi))
   1.248  		);
   1.249  
   1.250 -		QString sel=getSelectString(bo);
   1.251 +		QString sel=getSelectString(selbi);
   1.252  		unselect();
   1.253 -		par->removeBranchHere(bo);
   1.254 +		//FIXME-0 missing in VM pi->removeBranchHere(selbi);
   1.255  		reposition();
   1.256  		select (sel);
   1.257 -		getSelectedBranch()->move2RelPos (p);
   1.258 -		reposition();
   1.259 +		BranchObj *bo=getSelectedBranchObj();
   1.260 +		if (bo) 
   1.261 +		{
   1.262 +			bo->move2RelPos (p);
   1.263 +			reposition();
   1.264 +		}
   1.265  	}	
   1.266 -*/}
   1.267 +}
   1.268  
   1.269  void VymModel::deleteChildren()		
   1.270  
   1.271 @@ -2332,7 +2331,7 @@
   1.272  				QString ("%1 %2").arg(r).arg(getObjectName(bi))
   1.273  			);
   1.274  			emitDataHasChanged(bi);
   1.275 -			updateSelection();
   1.276 +			emitSelectionChanged();
   1.277  			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x //FIXME-3 force update via signal...
   1.278  			return true;
   1.279  		}
   1.280 @@ -2360,7 +2359,7 @@
   1.281  		);
   1.282  		bi->toggleScroll();
   1.283  		emitDataHasChanged(bi);
   1.284 -		updateSelection();
   1.285 +		emitSelectionChanged();
   1.286  
   1.287  		mapScene->update(); //Needed for _quick_ update,  even in 1.13.x //FIXME-3 force update via signal...
   1.288  		return true;
   1.289 @@ -2427,7 +2426,7 @@
   1.290  			QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
   1.291  			bi->toggleStandardFlag (name, master);
   1.292  		reposition();
   1.293 -		updateSelection();	
   1.294 +		emitSelectionChanged();	
   1.295  	}
   1.296  }
   1.297  
   1.298 @@ -2617,7 +2616,7 @@
   1.299  		bi->setVymLink(s);
   1.300  		reposition();
   1.301  		updateActions();
   1.302 -		//updateSelection();
   1.303 +		//emitSelectionChanged();
   1.304  	}
   1.305  }
   1.306  
   1.307 @@ -3034,7 +3033,7 @@
   1.308  						if (ok)
   1.309  						{
   1.310  							selb->linkTo ((BranchObj*)(dst),n);
   1.311 -							updateSelection();
   1.312 +							emitSelectionChanged();
   1.313  						}	
   1.314  					} else if (typid(*dst) == typid(MapCenterObj) ) 
   1.315  					{
   1.316 @@ -3047,7 +3046,7 @@
   1.317  							if (ok) 
   1.318  							{
   1.319  								selbi->move (x,y);
   1.320 -								updateSelection();
   1.321 +								emitSelectionChanged();
   1.322  							}
   1.323  						}
   1.324  					}	
   1.325 @@ -3082,7 +3081,7 @@
   1.326  		} else if (parser.checkParCount(1))
   1.327  		{
   1.328  			s=parser.parString(ok,0);
   1.329 -			if (ok) loadFloatImageInt (s);
   1.330 +			if (ok) loadFloatImageInt (selbi,s);
   1.331  		}	
   1.332  	/////////////////////////////////////////////////////////////////////
   1.333  	} else if (com=="moveUp")
   1.334 @@ -3859,16 +3858,36 @@
   1.335  		else
   1.336  			selti->setNote (textEditor->getText());
   1.337  		emitDataHasChanged(selti);		
   1.338 -		updateSelection();
   1.339 +		emitSelectionChanged();
   1.340  
   1.341  	}
   1.342  }
   1.343  
   1.344  void VymModel::updateRelPositions()		//FIXME-3 VM should have no need to updateRelPos
   1.345  {
   1.346 -	//cout << "VM::updateRelPos...\n";
   1.347 +	cout << "VM::updateRelPos...\n";
   1.348 +	/* FIXME-3 ???
   1.349  	for (int i=0; i<rootItem->branchCount(); i++)
   1.350  		((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
   1.351 +		*/
   1.352 +		/*
   1.353 +	void MapCenterObj::updateRelPositions()
   1.354 +	{
   1.355 +		if (repositionRequest) unsetAllRepositionRequests();
   1.356 +
   1.357 +		// update relative Positions of branches and floats
   1.358 +		for (int i=0; i<treeItem->branchCount(); ++i)
   1.359 +		{
   1.360 +			treeItem->getBranchObjNum(i)->setRelPos();
   1.361 +			treeItem->getBranchObjNum(i)->setOrientation();
   1.362 +		}
   1.363 +		
   1.364 +		for (int i=0; i<floatimage.size(); ++i)
   1.365 +			floatimage.at(i)->setRelPos();
   1.366 +
   1.367 +		if (repositionRequest) reposition();
   1.368 +	}
   1.369 +	*/
   1.370  }
   1.371  
   1.372  void VymModel::reposition()	//FIXME-3 VM should have no need to reposition, this is done in views???
   1.373 @@ -4201,7 +4220,7 @@
   1.374                  QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
   1.375              bo->move(x,y);
   1.376              reposition();
   1.377 -            updateSelection();
   1.378 +            emitSelectionChanged();
   1.379          }
   1.380  	}
   1.381  */	
   1.382 @@ -4232,7 +4251,7 @@
   1.383              ((OrnamentedObj*)bo)->move2RelPos (x,y);
   1.384              reposition();
   1.385              bo->updateLink();
   1.386 -            updateSelection();
   1.387 +            emitSelectionChanged();
   1.388          }
   1.389  	}
   1.390  */	
   1.391 @@ -4455,17 +4474,21 @@
   1.392  }
   1.393  */
   1.394  
   1.395 -void VymModel::updateSelection(const QItemSelection &newsel)
   1.396 +void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel)	//FIXME-4 connected but not used so far
   1.397 +{
   1.398 +}
   1.399 +
   1.400 +void VymModel::emitSelectionChanged(const QItemSelection &newsel)
   1.401  {
   1.402  	emit (selectionChanged(newsel,newsel));	// needed e.g. to update geometry in editor
   1.403  	emitShowSelection();
   1.404  	sendSelection();
   1.405  }
   1.406  
   1.407 -void VymModel::updateSelection()
   1.408 +void VymModel::emitSelectionChanged()
   1.409  {
   1.410  	QItemSelection newsel=selModel->selection();
   1.411 -	updateSelection (newsel);
   1.412 +	emitSelectionChanged (newsel);
   1.413  }
   1.414  
   1.415  void VymModel::setSelectionColor(QColor col)
   1.416 @@ -4610,7 +4633,7 @@
   1.417  {
   1.418  	if (selection.select(lmo))
   1.419  	{
   1.420 -		//updateSelection();
   1.421 +		//emitSelectionChanged();
   1.422  	}
   1.423  }
   1.424  
   1.425 @@ -4618,7 +4641,7 @@
   1.426  {
   1.427  	if (selection.select(lmo))
   1.428  	{
   1.429 -		//updateSelection();
   1.430 +		//emitSelectionChanged();
   1.431  	}
   1.432  }
   1.433  */
   1.434 @@ -4840,7 +4863,7 @@
   1.435  		TreeItem *ti2=par->getFirstBranch();
   1.436  		if (ti2) {
   1.437  			select(ti2);
   1.438 -			updateSelection();
   1.439 +			emitSelectionChanged();
   1.440  		}
   1.441  	}		
   1.442  }
   1.443 @@ -4855,7 +4878,7 @@
   1.444  		TreeItem *ti2=par->getLastBranch();
   1.445  		if (ti2) {
   1.446  			select(ti2);
   1.447 -			updateSelection();
   1.448 +			emitSelectionChanged();
   1.449  		}
   1.450  	}		
   1.451  }
   1.452 @@ -4879,7 +4902,7 @@
   1.453  		par=ti->parent();
   1.454  		if (!par) return;
   1.455  		select(par);
   1.456 -		updateSelection();
   1.457 +		emitSelectionChanged();
   1.458  	}		
   1.459  }
   1.460  
   1.461 @@ -4955,11 +4978,7 @@
   1.462  
   1.463  QString VymModel::getSelectString ()
   1.464  {
   1.465 -	LinkableMapObj *lmo=getSelectedLMO();
   1.466 -	if (lmo) 
   1.467 -		return getSelectString(lmo);
   1.468 -	else
   1.469 -		return QString();
   1.470 +	return getSelectString (getSelectedItem());
   1.471  }
   1.472  
   1.473  QString VymModel::getSelectString (LinkableMapObj *lmo)	// FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...