vymmodel.cpp
changeset 771 01f2f6d6789d
parent 769 a6931cd6309a
child 772 e3f722759c7e
     1.1 --- a/vymmodel.cpp	Mon May 18 09:41:31 2009 +0000
     1.2 +++ b/vymmodel.cpp	Mon May 18 11:22:41 2009 +0000
     1.3 @@ -252,11 +252,9 @@
     1.4  			//s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
     1.5  	}
     1.6  
     1.7 -	cout << "VM::saveToDir 1 \n";
     1.8  	// Save local settings
     1.9  	s+=settings.getDataXML (destPath);
    1.10  
    1.11 -	cout << "VM::saveToDir 2 \n";
    1.12  	// Save selection
    1.13  	if (getSelectedItem() && !saveSel ) 
    1.14  		s+=xml.valueElement("select",getSelectString());
    1.15 @@ -1619,23 +1617,19 @@
    1.16  		return QString();
    1.17  }
    1.18  
    1.19 -QStringList VymModel::getURLs()	// FIXME-1	first, next moved to vymmodel
    1.20 -{
    1.21 -	return QStringList();
    1.22 -	/*
    1.23 +QStringList VymModel::getURLs()	
    1.24 +{
    1.25  	QStringList urls;
    1.26 -	BranchObj *bo=getSelectedBranch();
    1.27 -	if (bo)
    1.28 -	{		
    1.29 -		bo=bo->first();	
    1.30 -		while (bo) 
    1.31 -		{
    1.32 -			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
    1.33 -			bo=bo->next();
    1.34 -		}	
    1.35 +	BranchItem *cur=getSelectedBranchItem();
    1.36 +	BranchItem *prev=NULL;
    1.37 +	int d=0;
    1.38 +	next (cur,prev,d);
    1.39 +	while (cur) 
    1.40 +	{
    1.41 +		if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
    1.42 +		cur=next (cur,prev,d);
    1.43  	}	
    1.44  	return urls;
    1.45 -	*/
    1.46  }
    1.47  
    1.48  void VymModel::linkFloatImageTo(const QString &dstString)	// FIXME-2
    1.49 @@ -1976,7 +1970,11 @@
    1.50  
    1.51  BranchItem* VymModel::createBranch()	
    1.52  {
    1.53 -	return addNewBranchInt (-2);
    1.54 +	BranchItem *selbi=getSelectedBranchItem();
    1.55 +	if (selbi)
    1.56 +		return addNewBranchInt (selbi,-2);
    1.57 +	else
    1.58 +		return NULL;
    1.59  }
    1.60  
    1.61  TreeItem* VymModel::createImage()	//FIXME-2
    1.62 @@ -2069,64 +2067,60 @@
    1.63  	return mci;
    1.64  }
    1.65  
    1.66 -BranchItem* VymModel::addNewBranchInt(int num)
    1.67 +BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)	//FIXME-4 simplify...
    1.68  {
    1.69  	// Depending on pos:
    1.70  	// -3		insert in children of parent  above selection 
    1.71  	// -2		add branch to selection 
    1.72  	// -1		insert in children of parent below selection 
    1.73  	// 0..n		insert in children of parent at pos
    1.74 -	BranchItem *selbi=getSelectedBranchItem();
    1.75 -	if (selbi)
    1.76 +
    1.77 +	// Create TreeItem
    1.78 +	QList<QVariant> cData;
    1.79 +	cData << "new" << "undef"<<"undef";
    1.80 +
    1.81 +	BranchItem *parbi;
    1.82 +	QModelIndex parix;
    1.83 +	int n;
    1.84 +	BranchItem *newbi=new BranchItem (cData);	
    1.85 +	newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
    1.86 +
    1.87 +	emit (layoutAboutToBeChanged() );
    1.88 +
    1.89 +	if (num==-2)
    1.90  	{
    1.91 -		// Create TreeItem
    1.92 -		QList<QVariant> cData;
    1.93 -		cData << "new" << "undef"<<"undef";
    1.94 -
    1.95 -		BranchItem *parbi;
    1.96 -		QModelIndex parix;
    1.97 -		int n;
    1.98 -		BranchItem *newbi=new BranchItem (cData);	
    1.99 -		newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
   1.100 -
   1.101 -		emit (layoutAboutToBeChanged() );
   1.102 -
   1.103 -		if (num==-2)
   1.104 -		{
   1.105 -			parbi=selbi;
   1.106 -			parix=index(parbi);
   1.107 -			n=parbi->childCount();
   1.108 -			beginInsertRows (parix,n,n+1);	
   1.109 -			parbi->appendChild (newbi);	
   1.110 -			endInsertRows ();
   1.111 -		}else if (num==-1)
   1.112 -		{
   1.113 -			// insert below selection
   1.114 -			parbi=(BranchItem*)selbi->parent();
   1.115 -			parix=index(parbi);
   1.116 -			n=selbi->childNumber()+1;
   1.117 -			beginInsertRows (parix,n,n);	
   1.118 -			parbi->insertBranch(n,newbi);	
   1.119 -			endInsertRows ();
   1.120 -		}else if (num==-3)
   1.121 -		{
   1.122 -			// insert above selection
   1.123 -			parbi=(BranchItem*)selbi->parent();
   1.124 -			parix=index(parbi);
   1.125 -			n=selbi->childNumber();
   1.126 -			beginInsertRows (parix,n,n);	
   1.127 -			parbi->insertBranch(n,newbi);	
   1.128 -			endInsertRows ();
   1.129 -		}
   1.130 -		emit (layoutChanged() );
   1.131 -
   1.132 -		// save scroll state. If scrolled, automatically select
   1.133 -		// new branch in order to tmp unscroll parent...
   1.134 -		newbi->createMapObj(mapScene);
   1.135 -		select (newbi);
   1.136 -		return newbi;
   1.137 -	}	
   1.138 -	return NULL;
   1.139 +		parbi=dst;
   1.140 +		parix=index(parbi);
   1.141 +		n=parbi->childCount();
   1.142 +		beginInsertRows (parix,n,n+1);	
   1.143 +		parbi->appendChild (newbi);	
   1.144 +		endInsertRows ();
   1.145 +	}else if (num==-1)
   1.146 +	{
   1.147 +		// insert below selection
   1.148 +		parbi=(BranchItem*)dst->parent();
   1.149 +		parix=index(parbi);
   1.150 +		n=dst->childNumber()+1;
   1.151 +		beginInsertRows (parix,n,n);	
   1.152 +		parbi->insertBranch(n,newbi);	
   1.153 +		endInsertRows ();
   1.154 +	}else if (num==-3)
   1.155 +	{
   1.156 +		// insert above selection
   1.157 +		parbi=(BranchItem*)dst->parent();
   1.158 +		parix=index(parbi);
   1.159 +		n=dst->childNumber();
   1.160 +		beginInsertRows (parix,n,n);	
   1.161 +		parbi->insertBranch(n,newbi);	
   1.162 +		endInsertRows ();
   1.163 +	} 
   1.164 +	emit (layoutChanged() );
   1.165 +
   1.166 +	// save scroll state. If scrolled, automatically select
   1.167 +	// new branch in order to tmp unscroll parent...
   1.168 +	newbi->createMapObj(mapScene);
   1.169 +	select (newbi);
   1.170 +	return newbi;
   1.171  }	
   1.172  
   1.173  BranchItem* VymModel::addNewBranch(int pos)
   1.174 @@ -2140,9 +2134,10 @@
   1.175  
   1.176  	if (selbi)
   1.177  	{
   1.178 -		// FIXME-3 VM  do we still need this in model? setCursor (Qt::ArrowCursor);
   1.179 -
   1.180 -		newbi=addNewBranchInt (pos-2);
   1.181 +		// FIXME-3 setCursor (Qt::ArrowCursor);  //Still needed?
   1.182 +
   1.183 +
   1.184 +		newbi=addNewBranchInt (selbi,pos-2);
   1.185  
   1.186  		if (newbi)
   1.187  		{
   1.188 @@ -2170,40 +2165,35 @@
   1.189  }
   1.190  
   1.191  
   1.192 -BranchItem* VymModel::addNewBranchBefore()	//FIXME-2
   1.193 -{
   1.194 -/*
   1.195 -	BranchObj *newbo=NULL;
   1.196 -	BranchObj *bo = getSelectedBranch();
   1.197 -	if (bo && selectionType()==TreeItem::Branch)
   1.198 -		 // We accept no MapCenterObj here, so we _have_ a parent
   1.199 +BranchItem* VymModel::addNewBranchBefore()	//FIXME-0
   1.200 +{
   1.201 +	BranchItem *newbi=NULL;
   1.202 +	BranchItem *selbi=getSelectedBranchItem();
   1.203 +	if (selbi && selbi->getType()==TreeItem::Branch)
   1.204 +		 // We accept no MapCenter here, so we _have_ a parent
   1.205  	{
   1.206 -		QPointF p=bo->getRelPos();
   1.207 -
   1.208 -
   1.209 -		BranchObj *parbo=(BranchObj*)(bo->getParObj());
   1.210 +		//QPointF p=bo->getRelPos();
   1.211 +
   1.212  
   1.213  		// add below selection
   1.214 -		newbo=parbo->insertBranch(bo->getTreeItem()->num()+1);		//FIXME-1 VM still missing
   1.215 -
   1.216 -		if (newbo)
   1.217 +		newbi=addNewBranchInt (selbi,-1);
   1.218 +
   1.219 +		if (newbi)
   1.220  		{
   1.221 -			newbo->move2RelPos (p);
   1.222 +			//newbi->move2RelPos (p);
   1.223  
   1.224  			// Move selection to new branch
   1.225 -			bo->linkTo (newbo,-1);
   1.226 -
   1.227 -			saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()", 
   1.228 -				QString ("Add branch before %1").arg(getObjectName(bo)));
   1.229 -
   1.230 -			reposition();
   1.231 +			relinkBranch (selbi,newbi,0);
   1.232 +
   1.233 +			saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()", 
   1.234 +				QString ("Add branch before %1").arg(getObjectName(selbi)));
   1.235 +
   1.236 +			// FIXME-3 needed? reposition();
   1.237  			// selection.update(); FIXME-3 
   1.238  		}
   1.239  	}	
   1.240 -	latestSelectionString=selection.getSelectString();
   1.241 -	return newbo;
   1.242 -	*/
   1.243 -	return NULL;
   1.244 +	//FIXME-3 needed? latestSelectionString=selection.getSelectString();
   1.245 +	return newbi;
   1.246  }
   1.247  
   1.248  bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
   1.249 @@ -2681,23 +2671,19 @@
   1.250  	
   1.251  }
   1.252  
   1.253 -QStringList VymModel::getVymLinks()	// FIXME-1	first, next moved to vymmodel
   1.254 -{
   1.255 -	return QStringList();
   1.256 -/*
   1.257 +QStringList VymModel::getVymLinks()	
   1.258 +{
   1.259  	QStringList links;
   1.260 -	BranchObj *bo=getSelectedBranch();
   1.261 -	if (bo)
   1.262 -	{		
   1.263 -		bo=bo->first();	
   1.264 -		while (bo) 
   1.265 -		{
   1.266 -			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
   1.267 -			bo=bo->next();
   1.268 -		}	
   1.269 +	BranchItem *cur=getSelectedBranchItem();
   1.270 +	BranchItem *prev=NULL;
   1.271 +	int d=0;
   1.272 +	next (cur,prev,d);
   1.273 +	while (cur) 
   1.274 +	{
   1.275 +		if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
   1.276 +		cur=next (cur,prev,d);
   1.277  	}	
   1.278  	return links;
   1.279 -*/	
   1.280  }
   1.281  
   1.282  
   1.283 @@ -2756,7 +2742,6 @@
   1.284  
   1.285  void VymModel::parseAtom(const QString &atom)
   1.286  {
   1.287 -	//BranchObj *selb=getSelectedBranch();	// FIXME-4
   1.288  	TreeItem* selti=getSelectedItem();
   1.289  	BranchItem *selbi=getSelectedBranchItem();
   1.290  	QString s,t;
   1.291 @@ -2903,12 +2888,14 @@
   1.292  		if (!selti)
   1.293  		{
   1.294  			parser.setError (Aborted,"Nothing selected");
   1.295 -		} else if (! selbi )
   1.296 +		} else if ( selectionType()!=TreeItem::Branch  && 
   1.297 +					selectionType()!=TreeItem::MapCenter  &&
   1.298 +					selectionType()!=TreeItem::Image )
   1.299  		{				  
   1.300 -			parser.setError (Aborted,"Type of selection is not a branch");
   1.301 +			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
   1.302  		} else if (parser.checkParCount(0))
   1.303  		{	
   1.304 -			//FIXME-1 missing action for copy
   1.305 +			copy();
   1.306  		}	
   1.307  	/////////////////////////////////////////////////////////////////////
   1.308  	} else if (com=="cut")