vymmodel.cpp
changeset 777 8acac4fade1b
parent 776 25e634a7e1dc
child 779 1fb50e79661c
     1.1 --- a/vymmodel.cpp	Mon Jun 08 11:36:56 2009 +0000
     1.2 +++ b/vymmodel.cpp	Mon Jun 29 10:27:42 2009 +0000
     1.3 @@ -1609,162 +1609,154 @@
     1.4  	return urls;
     1.5  }
     1.6  
     1.7 -void VymModel::linkFloatImageTo(const QString &dstString)	// FIXME-0
     1.8 -{
     1.9 -	//FIXME-0 FloatImageObj *fio=selection.getFloatImage();
    1.10 -	FloatImageObj *fio=NULL;
    1.11 -	if (fio)
    1.12 +
    1.13 +void VymModel::setFrameType(const FrameObj::FrameType &t)	//FIXME-4 not saved if there is no LMO
    1.14 +{
    1.15 +	BranchItem *bi=getSelectedBranchItem();
    1.16 +	if (bi)
    1.17  	{
    1.18 -		TreeItem *dst=findBySelectString (dstString);
    1.19 -		if (dst && dst->isBranchLikeType() )
    1.20 -		{			
    1.21 -			TreeItem *dstPar=dst->parent();
    1.22 -			QString parString=getSelectString(dstPar);
    1.23 -			QString fioPreSelectString=getSelectString(fio);
    1.24 -			QString fioPreParentSelectString=getSelectString (fio->getParObj());
    1.25 -			// FIXME-0 ((BranchObj*)dst)->addFloatImage (fio);
    1.26 -			unselect();
    1.27 -			// ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
    1.28 -			fio=((BranchObj*)dst)->getLastFloatImage();
    1.29 -			fio->setRelPos();
    1.30 -			fio->reposition();
    1.31 -			// select (fio);
    1.32 -			saveState(
    1.33 -				getSelectString(fio),
    1.34 -				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
    1.35 -				fioPreSelectString, 
    1.36 -				QString ("linkTo (\"%1\")").arg(dstString),
    1.37 -				QString ("Link floatimage to %1").arg(getObjectName(dst)));
    1.38 +		BranchObj *bo=(BranchObj*)(bi->getLMO());
    1.39 +		if (bo)
    1.40 +		{
    1.41 +			QString s=bo->getFrameTypeName();
    1.42 +			bo->setFrameType (t);
    1.43 +			saveState (bi, QString("setFrameType (\"%1\")").arg(s),
    1.44 +				bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
    1.45 +			reposition();
    1.46 +			bo->updateLink();
    1.47  		}
    1.48  	}
    1.49  }
    1.50  
    1.51 -
    1.52 -void VymModel::setFrameType(const FrameObj::FrameType &t)	//FIXME-2
    1.53 +void VymModel::setFrameType(const QString &s)	//FIXME-4 not saved if there is no LMO
    1.54 +{
    1.55 +	BranchItem *bi=getSelectedBranchItem();
    1.56 +	if (bi)
    1.57 +	{
    1.58 +		BranchObj *bo=(BranchObj*)(bi->getLMO());
    1.59 +		if (bo)
    1.60 +		{
    1.61 +			saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
    1.62 +				bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
    1.63 +			bo->setFrameType (s);
    1.64 +			reposition();
    1.65 +			bo->updateLink();
    1.66 +		}
    1.67 +	}
    1.68 +}
    1.69 +
    1.70 +void VymModel::setFramePenColor(const QColor &c)	//FIXME-4 not saved if there is no LMO
    1.71 +
    1.72 +{
    1.73 +	BranchItem *bi=getSelectedBranchItem();
    1.74 +	if (bi)
    1.75 +	{
    1.76 +		BranchObj *bo=(BranchObj*)(bi->getLMO());
    1.77 +		if (bo)
    1.78 +		{
    1.79 +			saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
    1.80 +				bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
    1.81 +			bo->setFramePenColor (c);
    1.82 +		}	
    1.83 +	}	
    1.84 +}
    1.85 +
    1.86 +void VymModel::setFrameBrushColor(const QColor &c)	//FIXME-4 not saved if there is no LMO
    1.87 +{
    1.88 +	BranchItem *bi=getSelectedBranchItem();
    1.89 +	if (bi)
    1.90 +	{
    1.91 +		BranchObj *bo=(BranchObj*)(bi->getLMO());
    1.92 +		if (bo)
    1.93 +		{
    1.94 +			saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
    1.95 +				bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
    1.96 +			bo->setFrameBrushColor (c);
    1.97 +		}	
    1.98 +	}	
    1.99 +}
   1.100 +
   1.101 +void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
   1.102 +{
   1.103 +	BranchItem *bi=getSelectedBranchItem();
   1.104 +	if (bi)
   1.105 +	{
   1.106 +		BranchObj *bo=(BranchObj*)(bi->getLMO());
   1.107 +		if (bo)
   1.108 +		{
   1.109 +			saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
   1.110 +				bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
   1.111 +			bo->setFramePadding (i);
   1.112 +			reposition();
   1.113 +			bo->updateLink();
   1.114 +		}	
   1.115 +	}	
   1.116 +}
   1.117 +
   1.118 +void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
   1.119 +{
   1.120 +	BranchItem *bi=getSelectedBranchItem();
   1.121 +	if (bi)
   1.122 +	{
   1.123 +		BranchObj *bo=(BranchObj*)(bi->getLMO());
   1.124 +		if (bo)
   1.125 +		{
   1.126 +			saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
   1.127 +				bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
   1.128 +			bo->setFrameBorderWidth (i);
   1.129 +			reposition();
   1.130 +			bo->updateLink();
   1.131 +		}	
   1.132 +	}	
   1.133 +}
   1.134 +
   1.135 +void VymModel::setIncludeImagesVer(bool b)	//FIXME-2
   1.136  {
   1.137  /*
   1.138 -	BranchObj *bo=getSelectedBranch();
   1.139 -	if (bo)
   1.140 +	BranchItem *bi=getSelectedBranchItem();
   1.141 +	if (ti)
   1.142  	{
   1.143 -		QString s=bo->getFrameTypeName();
   1.144 -		bo->setFrameType (t);
   1.145 -		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
   1.146 -			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
   1.147 -		reposition();
   1.148 -		bo->updateLink();
   1.149 -	}
   1.150 -*/	
   1.151 -}
   1.152 -
   1.153 -void VymModel::setFrameType(const QString &s)	//FIXME-2
   1.154 -{
   1.155 -/*
   1.156 -	BranchObj *bo=getSelectedBranch();
   1.157 -	if (bo)
   1.158 -	{
   1.159 -		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
   1.160 -			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
   1.161 -		bo->setFrameType (s);
   1.162 -		reposition();
   1.163 -		bo->updateLink();
   1.164 -	}
   1.165 -*/
   1.166 -}
   1.167 -
   1.168 -void VymModel::setFramePenColor(const QColor &c)	//FIXME-2
   1.169 -{
   1.170 -/*
   1.171 -	BranchObj *bo=getSelectedBranch();
   1.172 -	if (bo)
   1.173 -	{
   1.174 -		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
   1.175 -			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
   1.176 -		bo->setFramePenColor (c);
   1.177 -	}	
   1.178 -*/	
   1.179 -}
   1.180 -
   1.181 -void VymModel::setFrameBrushColor(const QColor &c)	//FIXME-2
   1.182 -{
   1.183 -/*
   1.184 -	BranchObj *bo=getSelectedBranch();
   1.185 -	if (bo)
   1.186 -	{
   1.187 -		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
   1.188 -			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
   1.189 -		bo->setFrameBrushColor (c);
   1.190 +		BranchObj *bo=bi->getLMO();
   1.191 +		if (bo)
   1.192 +		{
   1.193 +			QString u= b ? "false" : "true";
   1.194 +			QString r=!b ? "false" : "true";
   1.195 +			
   1.196 +			saveState(
   1.197 +				bo,
   1.198 +				QString("setIncludeImagesVertically (%1)").arg(u),
   1.199 +				bo, 
   1.200 +				QString("setIncludeImagesVertically (%1)").arg(r),
   1.201 +				QString("Include images vertically in %1").arg(getObjectName(bo))
   1.202 +			);	
   1.203 +			bo->setIncludeImagesVer(b);
   1.204 +			reposition();
   1.205 +		}	
   1.206  	}	
   1.207  */}
   1.208  
   1.209 -void VymModel::setFramePadding (const int &i) //FIXME-2
   1.210 +void VymModel::setIncludeImagesHor(bool b)	//FIXME-2
   1.211  {
   1.212  /*
   1.213 -	BranchObj *bo=getSelectedBranch();
   1.214 -	if (bo)
   1.215 +	TreeItem *bi=getSelectedBranchItem();
   1.216 +	if (ti)
   1.217  	{
   1.218 -		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
   1.219 -			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
   1.220 -		bo->setFramePadding (i);
   1.221 -		reposition();
   1.222 -		bo->updateLink();
   1.223 -	}	
   1.224 -	*/
   1.225 -}
   1.226 -
   1.227 -void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
   1.228 -{
   1.229 -/*
   1.230 -	BranchObj *bo=getSelectedBranch();
   1.231 -	if (bo)
   1.232 -	{
   1.233 -		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
   1.234 -			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
   1.235 -		bo->setFrameBorderWidth (i);
   1.236 -		reposition();
   1.237 -		bo->updateLink();
   1.238 -	}	
   1.239 -*/	
   1.240 -}
   1.241 -
   1.242 -void VymModel::setIncludeImagesVer(bool b)	//FIXME-2
   1.243 -{
   1.244 -/*
   1.245 -	BranchObj *bo=getSelectedBranch();
   1.246 -	if (bo)
   1.247 -	{
   1.248 -		QString u= b ? "false" : "true";
   1.249 -		QString r=!b ? "false" : "true";
   1.250 -		
   1.251 -		saveState(
   1.252 -			bo,
   1.253 -			QString("setIncludeImagesVertically (%1)").arg(u),
   1.254 -			bo, 
   1.255 -			QString("setIncludeImagesVertically (%1)").arg(r),
   1.256 -			QString("Include images vertically in %1").arg(getObjectName(bo))
   1.257 -		);	
   1.258 -		bo->setIncludeImagesVer(b);
   1.259 -		reposition();
   1.260 -	}	
   1.261 -*/}
   1.262 -
   1.263 -void VymModel::setIncludeImagesHor(bool b)	//FIXME-2
   1.264 -{
   1.265 -/*
   1.266 -	BranchObj *bo=getSelectedBranch();
   1.267 -	if (bo)
   1.268 -	{
   1.269 -		QString u= b ? "false" : "true";
   1.270 -		QString r=!b ? "false" : "true";
   1.271 -		
   1.272 -		saveState(
   1.273 -			bo,
   1.274 -			QString("setIncludeImagesHorizontally (%1)").arg(u),
   1.275 -			bo, 
   1.276 -			QString("setIncludeImagesHorizontally (%1)").arg(r),
   1.277 -			QString("Include images horizontally in %1").arg(getObjectName(bo))
   1.278 -		);	
   1.279 -		bo->setIncludeImagesHor(b);
   1.280 -		reposition();
   1.281 +		BranchObj *bo=bi->getLMO();
   1.282 +		if (bo)
   1.283 +		{
   1.284 +			QString u= b ? "false" : "true";
   1.285 +			QString r=!b ? "false" : "true";
   1.286 +			
   1.287 +			saveState(
   1.288 +				bo,
   1.289 +				QString("setIncludeImagesHorizontally (%1)").arg(u),
   1.290 +				bo, 
   1.291 +				QString("setIncludeImagesHorizontally (%1)").arg(r),
   1.292 +				QString("Include images horizontally in %1").arg(getObjectName(bo))
   1.293 +			);	
   1.294 +			bo->setIncludeImagesHor(b);
   1.295 +			reposition();
   1.296 +		}	
   1.297  	}	
   1.298  	*/
   1.299  }
   1.300 @@ -1795,22 +1787,22 @@
   1.301  
   1.302  void VymModel::setHideExport(bool b)
   1.303  {
   1.304 -	MapItem *mi=(MapItem*)getSelectedItem();
   1.305 -	if (mi && 
   1.306 -		(mi->getType()==TreeItem::Image ||mi->isBranchLikeType()))
   1.307 +	TreeItem *ti=getSelectedItem();
   1.308 +	if (ti && 
   1.309 +		(ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
   1.310  	{
   1.311 -		mi->setHideInExport (b);
   1.312 +		ti->setHideInExport (b);
   1.313  		QString u= b ? "false" : "true";
   1.314  		QString r=!b ? "false" : "true";
   1.315  		
   1.316  		saveState(
   1.317 -			mi,
   1.318 +			ti,
   1.319  			QString ("setHideExport (%1)").arg(u),
   1.320 -			mi,
   1.321 +			ti,
   1.322  			QString ("setHideExport (%1)").arg(r),
   1.323 -			QString ("Set HideExport flag of %1 to %2").arg(getObjectName(mi)).arg (r)
   1.324 +			QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
   1.325  		);	
   1.326 -			emitDataHasChanged(mi);
   1.327 +			emitDataHasChanged(ti);
   1.328  			emitSelectionChanged();
   1.329  		updateActions();
   1.330  		reposition();
   1.331 @@ -1962,11 +1954,12 @@
   1.332  	{
   1.333  		QModelIndex parix;
   1.334  		int n;
   1.335 +
   1.336  		QList<QVariant> cData;
   1.337 -		cData << "VM::createImage" << "undef"<<"undef";
   1.338 -
   1.339 -		ImageItem *newii=new ImageItem (cData);	
   1.340 -		newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
   1.341 +		cData << "new" << "undef"<<"undef";
   1.342 +
   1.343 +		ImageItem *newii=new ImageItem(cData) ;	
   1.344 +		//newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
   1.345  
   1.346  		emit (layoutAboutToBeChanged() );
   1.347  
   1.348 @@ -2187,6 +2180,43 @@
   1.349  	return false;
   1.350  }
   1.351  
   1.352 +bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
   1.353 +{
   1.354 +	if (image && dst)
   1.355 +	{
   1.356 +		emit (layoutAboutToBeChanged() );
   1.357 +
   1.358 +		BranchItem *pi=(BranchItem*)(image->parent());
   1.359 +		QString oldParString=getSelectString (pi);
   1.360 +		// Remove at current position
   1.361 +		int n=image->childNum();
   1.362 +		beginRemoveRows (index(pi),n,n);
   1.363 +		pi->removeChild (n);
   1.364 +		endRemoveRows();
   1.365 +
   1.366 +		// Add at dst
   1.367 +		QModelIndex dstix=index(dst);
   1.368 +		n=dst->getRowNumAppend (image);
   1.369 +		beginInsertRows (dstix,n,n+1);	
   1.370 +		dst->appendChild (image);	
   1.371 +		endInsertRows ();
   1.372 +
   1.373 +		// Set new parent also for lmo
   1.374 +		if (image->getLMO() && dst->getLMO() )
   1.375 +			image->getLMO()->setParObj (dst->getLMO() );
   1.376 +
   1.377 +		emit (layoutChanged() );
   1.378 +		saveState(
   1.379 +			image,
   1.380 +			QString("relinkTo (\"%1\")").arg(oldParString), 
   1.381 +			image,
   1.382 +			QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
   1.383 +			QString ("Relink floatimage to %1").arg(getObjectName(dst)));
   1.384 +		return true;	
   1.385 +	}
   1.386 +	return false;
   1.387 +}
   1.388 +
   1.389  void VymModel::deleteSelection()
   1.390  {
   1.391  	BranchItem *selbi=getSelectedBranchItem();
   1.392 @@ -2436,7 +2466,7 @@
   1.393  	}
   1.394  }
   1.395  
   1.396 -void VymModel::addFloatImage (const QPixmap &img) //FIXME-0
   1.397 +void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
   1.398  {
   1.399  /*
   1.400  	BranchObj *bo=getSelectedBranch();
   1.401 @@ -3067,10 +3097,8 @@
   1.402  				TreeItem *dst=findBySelectString (s);
   1.403  				if (dst)
   1.404  				{	
   1.405 -					/* FIXME-0 relink img
   1.406  					if (dst->isBranchLikeType())
   1.407 -						linkFloatImageTo (getSelectString(dst));
   1.408 -					*/	
   1.409 +						relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
   1.410  				} else	
   1.411  					parser.setError (Aborted,"Destination is not a branch");
   1.412  			}		
   1.413 @@ -3871,7 +3899,6 @@
   1.414  
   1.415  void VymModel::updateRelPositions()		//FIXME-3 VM should have no need to updateRelPos
   1.416  {
   1.417 -	cout << "VM::updateRelPos...\n";
   1.418  	/* FIXME-3 ???
   1.419  	for (int i=0; i<rootItem->branchCount(); i++)
   1.420  		((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
   1.421 @@ -4927,7 +4954,7 @@
   1.422  		TreeItem::Type type=ti->getType();
   1.423  		if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
   1.424  		{
   1.425 -			return ((MapItem*)ti)->getLMO();
   1.426 +			return ti->getLMO();
   1.427  		}	
   1.428  	}
   1.429  	return NULL;
   1.430 @@ -4937,7 +4964,7 @@
   1.431  {
   1.432  	TreeItem *ti = getSelectedBranchItem();
   1.433  	if (ti)
   1.434 -		return (BranchObj*)((MapItem*)ti)->getLMO();
   1.435 +		return (BranchObj*)(ti->getLMO());
   1.436  	else	
   1.437  		return NULL;
   1.438  }
   1.439 @@ -4996,28 +5023,22 @@
   1.440  	return getSelectString (lmo->getTreeItem() );
   1.441  }
   1.442  
   1.443 -QString VymModel::getSelectString (TreeItem *ti)
   1.444 +QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
   1.445  {
   1.446  	QString s;
   1.447  	if (!ti) return s;
   1.448 -	if (ti->isBranchLikeType())
   1.449 -	{	
   1.450 -		TreeItem *par=ti->parent();
   1.451 -		if (par)
   1.452 -		{
   1.453 -			if (ti->depth() ==1)
   1.454 -				// Mainbranch, return 
   1.455 -				s= "bo:" + QString("%1").arg(ti->num() );
   1.456 -			else	
   1.457 -				// Branch, call myself recursively
   1.458 -				s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
   1.459 -		} else
   1.460 -		{
   1.461 -			// MapCenter
   1.462 -			int i=rootItem->num(ti);
   1.463 -			if (i>=0) s=QString("mc:%1").arg(i);
   1.464 -		}	
   1.465 -	}	
   1.466 +	switch (ti->getType())
   1.467 +	{
   1.468 +		case TreeItem::MapCenter: s="mc:"; break;
   1.469 +		case TreeItem::Branch: s="bo:";break;
   1.470 +		case TreeItem::Image: s="fi:";break;
   1.471 +		default:break;
   1.472 +	}
   1.473 +	s=  s + QString("%1").arg(ti->num());
   1.474 +	if (ti->depth() >0)
   1.475 +		// call myself recursively
   1.476 +		s= getSelectString(ti->parent()) +","+s;
   1.477 +			
   1.478  	return s;
   1.479  }
   1.480