vymmodel.cpp
changeset 738 716a777c1c98
parent 737 53e51e8d47e7
child 739 3d43b46a8564
     1.1 --- a/vymmodel.cpp	Thu Jan 22 15:40:08 2009 +0000
     1.2 +++ b/vymmodel.cpp	Fri Jan 30 09:14:12 2009 +0000
     1.3 @@ -1500,7 +1500,7 @@
     1.4  		sel->setHeading(s );
     1.5  		/* FIXME testing only
     1.6  		*/
     1.7 -		TreeItem *ti=getSelectedTreeItem();
     1.8 +		TreeItem *ti=getSelectedItem();
     1.9  		if (ti)
    1.10  		{
    1.11  			ti->setHeading (s);
    1.12 @@ -3975,7 +3975,7 @@
    1.13  	}
    1.14  }
    1.15  
    1.16 -void VymModel::selectMapBackgroundImage ()
    1.17 +void VymModel::selectMapBackgroundImage ()	// FIXME move to ME
    1.18  {
    1.19  	Q3FileDialog *fd=new Q3FileDialog( NULL);
    1.20  	fd->setMode (Q3FileDialog::ExistingFile);
    1.21 @@ -4012,7 +4012,7 @@
    1.22  	mapScene->setBackgroundBrush(brush);
    1.23  }
    1.24  
    1.25 -void VymModel::selectMapBackgroundColor()
    1.26 +void VymModel::selectMapBackgroundColor()	// FIXME move to ME
    1.27  {
    1.28  	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
    1.29  	if ( !col.isValid() ) return;
    1.30 @@ -4020,7 +4020,7 @@
    1.31  }
    1.32  
    1.33  
    1.34 -void VymModel::setMapBackgroundColor(QColor col)
    1.35 +void VymModel::setMapBackgroundColor(QColor col)	// FIXME move to ME
    1.36  {
    1.37  	QColor oldcol=mapScene->backgroundBrush().color();
    1.38  	saveState(
    1.39 @@ -4030,38 +4030,38 @@
    1.40  	mapScene->setBackgroundBrush(col);
    1.41  }
    1.42  
    1.43 -QColor VymModel::getMapBackgroundColor()
    1.44 +QColor VymModel::getMapBackgroundColor()	// FIXME move to ME
    1.45  {
    1.46      return mapScene->backgroundBrush().color();
    1.47  }
    1.48  
    1.49  
    1.50 -LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()
    1.51 +LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()	// FIXME move to ME
    1.52  {
    1.53  	return linkcolorhint;
    1.54  }
    1.55  
    1.56 -QColor VymModel::getMapDefLinkColor()
    1.57 +QColor VymModel::getMapDefLinkColor()	// FIXME move to ME
    1.58  {
    1.59  	return defLinkColor;
    1.60  }
    1.61  
    1.62 -void VymModel::setMapDefXLinkColor(QColor col)
    1.63 +void VymModel::setMapDefXLinkColor(QColor col)	// FIXME move to ME
    1.64  {
    1.65  	defXLinkColor=col;
    1.66  }
    1.67  
    1.68 -QColor VymModel::getMapDefXLinkColor()
    1.69 +QColor VymModel::getMapDefXLinkColor()	// FIXME move to ME
    1.70  {
    1.71  	return defXLinkColor;
    1.72  }
    1.73  
    1.74 -void VymModel::setMapDefXLinkWidth (int w)
    1.75 +void VymModel::setMapDefXLinkWidth (int w)	// FIXME move to ME
    1.76  {
    1.77  	defXLinkWidth=w;
    1.78  }
    1.79  
    1.80 -int VymModel::getMapDefXLinkWidth()
    1.81 +int VymModel::getMapDefXLinkWidth()	// FIXME move to ME
    1.82  {
    1.83  	return defXLinkWidth;
    1.84  }
    1.85 @@ -4326,7 +4326,6 @@
    1.86  
    1.87  void VymModel::updateSelection()
    1.88  {
    1.89 -	cout << "VM::updateSelection ()\n";
    1.90  	QItemSelection newsel=selModel->selection();
    1.91  	updateSelection (newsel);
    1.92  }
    1.93 @@ -4334,6 +4333,7 @@
    1.94  void VymModel::updateSelection(const QItemSelection &oldsel)
    1.95  {
    1.96  	QItemSelection newsel=selModel->selection();
    1.97 +	/*
    1.98  	cout << "VM::updateSelection   new=";
    1.99  	if (!newsel.indexes().isEmpty() )
   1.100  		cout << newsel.indexes().first().row()<<"," << newsel.indexes().first().column();
   1.101 @@ -4341,7 +4341,8 @@
   1.102  	if (!oldsel.indexes().isEmpty() )
   1.103  		cout << oldsel.indexes().first().row()<<"," << oldsel.indexes().first().column();
   1.104  	cout <<endl;
   1.105 -	//emit (selectionChanged(newsel,oldsel));
   1.106 +	*/
   1.107 +	//emit (selectionChanged(newsel,oldsel));	// FIXME needed?
   1.108  	ensureSelectionVisible();
   1.109  	sendSelection();
   1.110  }
   1.111 @@ -4435,10 +4436,18 @@
   1.112  	QItemSelection oldsel=selModel->selection();
   1.113  
   1.114  	if (lmo)
   1.115 +		return select (lmo->getTreeItem() );
   1.116 +	else	
   1.117 +		return false;
   1.118 +}
   1.119 +
   1.120 +bool VymModel::select (TreeItem *ti)
   1.121 +{
   1.122 +	if (ti)
   1.123  	{
   1.124 -		TreeItem *ti=lmo->getTreeItem();
   1.125  		QModelIndex ix=index(ti);
   1.126  		selModel->select (ix,QItemSelectionModel::ClearAndSelect  );
   1.127 +		ti->setLastSelectedBranch();
   1.128  		//updateSelection(oldsel);	//FIXME needed?
   1.129  		return true;
   1.130  	}
   1.131 @@ -4556,10 +4565,9 @@
   1.132  void VymModel::selectPrevBranchInt()
   1.133  {
   1.134  	// Decrease number of branch
   1.135 -	BranchObj *bo=getSelectedBranch();
   1.136 -	if (bo)
   1.137 +	if (selectionType()==TreeItem::Branch)
   1.138  	{
   1.139 -		QString s=selection.getSelectString();
   1.140 +		QString s=getSelectString();
   1.141  		QString part;
   1.142  		QString typ;
   1.143  		QString num;
   1.144 @@ -4577,6 +4585,9 @@
   1.145  		num=QString ("%1").arg(n);
   1.146  		s=s+num;
   1.147  		
   1.148 +		cout <<"SP::  s0="<<s.toStdString()<<endl;
   1.149 +
   1.150 +
   1.151  		// Try to select this one
   1.152  		if (n>=0 && select (s)) return;
   1.153  
   1.154 @@ -4612,6 +4623,7 @@
   1.155  				s=typ+num;
   1.156  			}	
   1.157  
   1.158 +		cout <<"SP::  si="<<s.toStdString()<<endl;
   1.159  			if (select(s))
   1.160  				// pad to oldDepth, select the last branch for each depth
   1.161  				for (i=d;i<oldDepth;i++)
   1.162 @@ -4753,16 +4765,14 @@
   1.163  
   1.164  void VymModel::selectFirstBranch()
   1.165  {
   1.166 -	BranchObj *bo1=getSelectedBranch();
   1.167 -	BranchObj *bo2;
   1.168 -	BranchObj* par;
   1.169 -	if (bo1)
   1.170 +	TreeItem *ti=getSelectedBranchItem();
   1.171 +	if (ti)
   1.172  	{
   1.173 -		par=(BranchObj*)(bo1->getParObj());
   1.174 +		TreeItem *par=ti->parent();
   1.175  		if (!par) return;
   1.176 -		bo2=par->getFirstBranch();
   1.177 -		if (bo2) {
   1.178 -			selection.select(bo2);
   1.179 +		TreeItem *ti2=par->getFirstBranch();
   1.180 +		if (ti2) {
   1.181 +			select(ti2);
   1.182  			selection.update();
   1.183  			ensureSelectionVisible();
   1.184  			sendSelection();
   1.185 @@ -4772,17 +4782,14 @@
   1.186  
   1.187  void VymModel::selectLastBranch()
   1.188  {
   1.189 -	BranchObj *bo1=getSelectedBranch();
   1.190 -	BranchObj *bo2;
   1.191 -	BranchObj* par;
   1.192 -	if (bo1)
   1.193 +	TreeItem *ti=getSelectedBranchItem();
   1.194 +	if (ti)
   1.195  	{
   1.196 -		par=(BranchObj*)(bo1->getParObj());
   1.197 +		TreeItem *par=ti->parent();
   1.198  		if (!par) return;
   1.199 -		bo2=par->getLastBranch();
   1.200 -		if (bo2) 
   1.201 -		{
   1.202 -			selection.select(bo2);
   1.203 +		TreeItem *ti2=par->getLastBranch();
   1.204 +		if (ti2) {
   1.205 +			select(ti2);
   1.206  			selection.update();
   1.207  			ensureSelectionVisible();
   1.208  			sendSelection();
   1.209 @@ -4792,29 +4799,23 @@
   1.210  
   1.211  void VymModel::selectLastSelectedBranch()
   1.212  {
   1.213 -	QItemSelection oldsel=selModel->selection();
   1.214 -
   1.215 +	TreeItem *ti=getSelectedBranchItem();
   1.216  	BranchObj *bo1=getSelectedBranch();
   1.217 -	BranchObj *bo2;
   1.218 -	if (bo1)
   1.219 +	if (ti)
   1.220  	{
   1.221 -		cout << "bo1="<<bo1->getHeading().toStdString()<<endl;
   1.222 -		bo2=bo1->getLastSelectedBranch();
   1.223 -		if (bo2) 
   1.224 -		{
   1.225 -			cout << "bo2="<<bo2->getHeading().toStdString()<<endl;
   1.226 -			select(bo2);
   1.227 -		}
   1.228 +		ti=ti->getLastSelectedBranch();
   1.229 +		if (ti) select (ti);
   1.230  	}		
   1.231  }
   1.232  
   1.233  void VymModel::selectParent()
   1.234  {
   1.235 +	TreeItem *ti=getSelectedItem();
   1.236  	LinkableMapObj *lmo=getSelectedLMO();
   1.237 -	BranchObj* par;
   1.238 -	if (lmo)
   1.239 +	TreeItem *par;
   1.240 +	if (ti)
   1.241  	{
   1.242 -		par=(BranchObj*)(lmo->getParObj());
   1.243 +		par=ti->parent();
   1.244  		if (!par) return;
   1.245  		select(par);
   1.246  		selection.update();
   1.247 @@ -4849,21 +4850,27 @@
   1.248  
   1.249  BranchObj* VymModel::getSelectedBranch()
   1.250  {
   1.251 +	TreeItem *ti = getSelectedBranchItem();
   1.252 +	if (ti)
   1.253 +		return (BranchObj*)ti->getLMO();
   1.254 +	else	
   1.255 +		return NULL;
   1.256 +}
   1.257 +
   1.258 +TreeItem* VymModel::getSelectedBranchItem()
   1.259 +{
   1.260  	QModelIndexList list=selModel->selectedIndexes();
   1.261  	if (!list.isEmpty() )
   1.262  	{
   1.263  		TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
   1.264  		TreeItem::Type type=ti->getType();
   1.265  		if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
   1.266 -		{
   1.267 -			return (BranchObj*)ti->getLMO();
   1.268 -		}	
   1.269 +			return ti;
   1.270  	}
   1.271  	return NULL;
   1.272 -
   1.273  }
   1.274  
   1.275 -TreeItem* VymModel::getSelectedTreeItem()
   1.276 +TreeItem* VymModel::getSelectedItem()
   1.277  {
   1.278  	// FIXME this may not only be branch, but also float etc...
   1.279  	BranchObj* bo=getSelectedBranch();
   1.280 @@ -4887,7 +4894,11 @@
   1.281  
   1.282  QString VymModel::getSelectString ()
   1.283  {
   1.284 -	return selection.getSelectString();
   1.285 +	LinkableMapObj *lmo=getSelectedLMO();
   1.286 +	if (lmo) 
   1.287 +		return getSelectString(lmo);
   1.288 +	else
   1.289 +		return QString();
   1.290  }
   1.291  
   1.292  QString VymModel::getSelectString (LinkableMapObj *lmo)	// FIXME VM needs to use TreeModel