vymmodel.cpp
changeset 659 b582bba9e312
parent 650 65c5a0c28d20
child 660 d0e047b8d412
     1.1 --- a/vymmodel.cpp	Tue Jan 15 10:54:41 2008 +0000
     1.2 +++ b/vymmodel.cpp	Wed Jan 16 15:45:19 2008 +0000
     1.3 @@ -101,89 +101,6 @@
     1.4  	return NULL;
     1.5  }
     1.6  
     1.7 -// Only as long as we dont have Model/View yet
     1.8 -LinkableMapObj* VymModel::getSelection()
     1.9 -{
    1.10 -	return mapEditor->getSelection();
    1.11 -}
    1.12 -BranchObj* VymModel::getSelectedBranch()
    1.13 -{
    1.14 -	return mapEditor->getSelectedBranch();
    1.15 -}
    1.16 -
    1.17 -bool VymModel::select (const QString &s)
    1.18 -{
    1.19 -	LinkableMapObj *lmo=model->findObjBySelect(s);
    1.20 -
    1.21 -/*
    1.22 -	// Finally select the found object
    1.23 -	if (lmo)
    1.24 -	{
    1.25 -		xelection.unselect();
    1.26 -		xelection.select(lmo);
    1.27 -		xelection.update();
    1.28 -		ensureSelectionVisible();
    1.29 -		sendSelection ();
    1.30 -		return true;
    1.31 -	} 
    1.32 -	return false;
    1.33 -*/
    1.34 -}
    1.35 -
    1.36 -QString VymModel::getSelectString (LinkableMapObj *lmo)
    1.37 -{
    1.38 -	QString s;
    1.39 -	if (!lmo) return s;
    1.40 -	if (typeid(*lmo)==typeid(BranchObj) ||
    1.41 -		typeid(*lmo)==typeid(MapCenterObj) )
    1.42 -	{	
    1.43 -		LinkableMapObj *par=lmo->getParObj();
    1.44 -		if (par)
    1.45 -		{
    1.46 -			if (lmo->getDepth() ==1)
    1.47 -				// Mainbranch, return 
    1.48 -				s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
    1.49 -			else	
    1.50 -				// Branch, call myself recursively
    1.51 -				s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
    1.52 -		} else
    1.53 -		{
    1.54 -			// MapCenter
    1.55 -			int i=mapCenters.indexOf ((MapCenterObj*)lmo);
    1.56 -			if (i>=0) s=QString("mc:%1").arg(i);
    1.57 -		}	
    1.58 -	}	
    1.59 -	return s;
    1.60 -
    1.61 -}
    1.62 -
    1.63 -/* FIXME copied from MCO, still needed?
    1.64 -void VymModel::move (double x, double y)
    1.65 -{
    1.66 -	BranchObj::move(x,y);
    1.67 -}
    1.68 -
    1.69 -void VymModel::moveBy (double x, double y)
    1.70 -{
    1.71 -	BranchObj::moveBy(x,y);
    1.72 -}
    1.73 -
    1.74 -void VymModel::moveAll (double x, double y)
    1.75 -{
    1.76 -	// Get rel. position
    1.77 -	double dx=x-absPos.x();
    1.78 -	double dy=y-absPos.y();
    1.79 -
    1.80 -	// Move myself and branches
    1.81 -	moveAllBy (dx,dy);
    1.82 -}
    1.83 -
    1.84 -void VymModel::moveAllBy (double dx, double dy)
    1.85 -{
    1.86 -	// Move myself and childs
    1.87 -	BranchObj::moveBy(dx,dy);
    1.88 -}
    1.89 -*/
    1.90  BranchObj* VymModel::first()
    1.91  {
    1.92  	if (mapCenters.count()>0) 
    1.93 @@ -212,45 +129,6 @@
    1.94  			return mapCenters.at(i);
    1.95  	} 
    1.96  	return NULL;
    1.97 -
    1.98 -}
    1.99 -	
   1.100 -	/* FIXME copied from MCO, still needed?
   1.101 -void VymModel::updateLink()
   1.102 -{
   1.103 -	// set childPos to middle of MapCenterObj
   1.104 -	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
   1.105 -	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
   1.106 -	parPos=childPos;		
   1.107 -	for (int i=0; i<branch.size(); ++i)
   1.108 -		branch.at(i)->updateLink();
   1.109 -}
   1.110 -
   1.111 -*/
   1.112 -void VymModel::updateRelPositions()
   1.113 -{
   1.114 -	for (int i=0; i<mapCenters.count(); i++)
   1.115 -		mapCenters.at(i)->updateRelPositions();
   1.116 -}
   1.117 -
   1.118 -void VymModel::reposition()
   1.119 -{
   1.120 -	for (int i=0;i<mapCenters.count(); i++)
   1.121 -		mapCenters.at(i)->reposition();	//	for positioning heading
   1.122 -}
   1.123 -
   1.124 -void VymModel::setHideTmp (HideTmpMode mode)
   1.125 -{
   1.126 -	for (int i=0;i<mapCenters.count(); i++)
   1.127 -		mapCenters.at(i)->setHideTmp (mode);	
   1.128 -}
   1.129 -
   1.130 -QRectF VymModel::getTotalBBox()
   1.131 -{
   1.132 -	QRectF r;
   1.133 -	for (int i=0;i<mapCenters.count(); i++)
   1.134 -		r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
   1.135 -	return r;	
   1.136  }
   1.137  
   1.138  LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
   1.139 @@ -274,7 +152,7 @@
   1.140  		QString typ;
   1.141  		QString num;
   1.142  		part=s.section(",",0,0);
   1.143 -		typ=part.left (3);
   1.144 +		typ=part.left (2);
   1.145  		num=part.right(part.length() - 3);
   1.146  		if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
   1.147  			return mapCenters.at(num.toInt() );
   1.148 @@ -309,3 +187,96 @@
   1.149  }
   1.150  
   1.151  
   1.152 +//////////////////////////////////////////////
   1.153 +// View related
   1.154 +//////////////////////////////////////////////
   1.155 +
   1.156 +	/* FIXME copied from MCO, still needed?
   1.157 +void VymModel::updateLink()
   1.158 +{
   1.159 +	// set childPos to middle of MapCenterObj
   1.160 +	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
   1.161 +	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
   1.162 +	parPos=childPos;		
   1.163 +	for (int i=0; i<branch.size(); ++i)
   1.164 +		branch.at(i)->updateLink();
   1.165 +}
   1.166 +
   1.167 +*/
   1.168 +void VymModel::updateRelPositions()
   1.169 +{
   1.170 +	for (int i=0; i<mapCenters.count(); i++)
   1.171 +		mapCenters.at(i)->updateRelPositions();
   1.172 +}
   1.173 +
   1.174 +void VymModel::reposition()
   1.175 +{
   1.176 +	for (int i=0;i<mapCenters.count(); i++)
   1.177 +		mapCenters.at(i)->reposition();	//	for positioning heading
   1.178 +}
   1.179 +
   1.180 +
   1.181 +
   1.182 +//////////////////////////////////////////////
   1.183 +// Selection related
   1.184 +//////////////////////////////////////////////
   1.185 +
   1.186 +
   1.187 +// Only as long as we dont have Model/View yet
   1.188 +LinkableMapObj* VymModel::getSelection()
   1.189 +{
   1.190 +	return mapEditor->getSelection();
   1.191 +}
   1.192 +BranchObj* VymModel::getSelectedBranch()
   1.193 +{
   1.194 +	return mapEditor->getSelectedBranch();
   1.195 +}
   1.196 +
   1.197 +
   1.198 +bool VymModel::select (const QString &s)
   1.199 +{
   1.200 +	return mapEditor->select (s);
   1.201 +}
   1.202 +
   1.203 +QString VymModel::getSelectString (LinkableMapObj *lmo)
   1.204 +{
   1.205 +	QString s;
   1.206 +	if (!lmo) return s;
   1.207 +	if (typeid(*lmo)==typeid(BranchObj) ||
   1.208 +		typeid(*lmo)==typeid(MapCenterObj) )
   1.209 +	{	
   1.210 +		LinkableMapObj *par=lmo->getParObj();
   1.211 +		if (par)
   1.212 +		{
   1.213 +			if (lmo->getDepth() ==1)
   1.214 +				// Mainbranch, return 
   1.215 +				s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
   1.216 +			else	
   1.217 +				// Branch, call myself recursively
   1.218 +				s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
   1.219 +		} else
   1.220 +		{
   1.221 +			// MapCenter
   1.222 +			int i=mapCenters.indexOf ((MapCenterObj*)lmo);
   1.223 +			if (i>=0) s=QString("mc:%1").arg(i);
   1.224 +		}	
   1.225 +	}	
   1.226 +	return s;
   1.227 +
   1.228 +}
   1.229 +
   1.230 +	
   1.231 +void VymModel::setHideTmp (HideTmpMode mode)
   1.232 +{
   1.233 +	for (int i=0;i<mapCenters.count(); i++)
   1.234 +		mapCenters.at(i)->setHideTmp (mode);	
   1.235 +}
   1.236 +
   1.237 +QRectF VymModel::getTotalBBox()
   1.238 +{
   1.239 +	QRectF r;
   1.240 +	for (int i=0;i<mapCenters.count(); i++)
   1.241 +		r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
   1.242 +	return r;	
   1.243 +}
   1.244 +