mapeditor.cpp
branchqt4-port
changeset 17 557239819c45
parent 16 41c3d7f9f532
child 18 70c41284cb48
     1.1 --- a/mapeditor.cpp	Tue Aug 29 08:31:42 2006 +0000
     1.2 +++ b/mapeditor.cpp	Wed Aug 30 12:16:25 2006 +0000
     1.3 @@ -129,8 +129,9 @@
     1.4  extern QMenu* branchContextMenu;
     1.5  extern QMenu* branchAddContextMenu;
     1.6  extern QMenu* branchRemoveContextMenu;
     1.7 -extern QMenu* branchLinksContextMenuEdit;
     1.8 -extern QMenu* branchLinksContextMenuFollow;
     1.9 +extern QMenu* branchLinksContextMenu;
    1.10 +extern QMenu* branchXLinksContextMenuEdit;
    1.11 +extern QMenu* branchXLinksContextMenuFollow;
    1.12  extern QMenu* floatimageContextMenu;
    1.13  extern QMenu* saveImageFormatMenu;
    1.14  extern QMenu* canvasContextMenu;
    1.15 @@ -376,7 +377,7 @@
    1.16  	d.mkdir (tmpMapDir,true);
    1.17  }
    1.18  
    1.19 -QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
    1.20 +QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
    1.21  {
    1.22  	// tmpdir		temporary directory to which data will be written
    1.23  	// prefix		mapname, which will be appended to images etc.
    1.24 @@ -408,7 +409,7 @@
    1.25  		colhint=attribut("linkColorHint","HeadingColor");
    1.26  
    1.27  	QString mapAttr=attribut("version",__VYM_VERSION);
    1.28 -	if (!saveSelection)
    1.29 +	if (!saveSel)
    1.30  		mapAttr+= attribut("author",mapCenter->getAuthor()) +
    1.31  				  attribut("comment",mapCenter->getComment()) +
    1.32  			      attribut("date",mapCenter->getDate()) +
    1.33 @@ -428,25 +429,28 @@
    1.34  	FloatImageObj (mapCanvas).resetSaveCounter();
    1.35  
    1.36  	// Build xml recursivly
    1.37 -	if (!saveSelection)
    1.38 +	if (!saveSel)
    1.39 +		// Save complete map, if saveSel not set
    1.40  		s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
    1.41  	else
    1.42  	{
    1.43 -		if ( typeid(*saveSelection) == typeid(BranchObj) )
    1.44 -			s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
    1.45 -		else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
    1.46 -			s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
    1.47 +		if ( typeid(*saveSel) == typeid(BranchObj) )
    1.48 +			// Save Subtree
    1.49 +			s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
    1.50 +		else if ( typeid(*saveSel) == typeid(FloatImageObj) )
    1.51 +			// Save image
    1.52 +			s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
    1.53  			
    1.54  		else if (selection && typeid(*selection)==typeid(BranchObj))
    1.55 -				// This is used if selected branch is saved from mainwindow
    1.56 -				s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
    1.57 +			// Save selected branch is saved from mainwindow		//FIXME maybe use "subtree" above?
    1.58 +			s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
    1.59  	}
    1.60  
    1.61  	// Save local settings
    1.62  	s+=settings.getXMLData (destPath);
    1.63  
    1.64  	// Save selection
    1.65 -	if (selection && !saveSelection ) 
    1.66 +	if (selection && !saveSel ) 
    1.67  		s+=valueElement("select",selection->getSelectString());
    1.68  
    1.69  	decIndent();
    1.70 @@ -459,14 +463,22 @@
    1.71  
    1.72  void MapEditor::saveStateComplete(const QString &comment)
    1.73  {
    1.74 -	// Save complete map
    1.75 -	saveState (CompleteMap,"",NULL,"",NULL, comment);
    1.76 +	// Save complete map, Undo will replace whole map
    1.77 +	saveState (CompleteMap,
    1.78 +		NULL, "",
    1.79 +		NULL, "", 
    1.80 +		comment, 
    1.81 +		mapCenter);
    1.82  }
    1.83  
    1.84  void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
    1.85  {
    1.86 -	// save the selected part of the map 
    1.87 -	saveState (PartOfMap,"",undoSel,"",NULL, comment);
    1.88 +	// save the selected part of the map, Undo will replace part of map 
    1.89 +	saveState (PartOfMap,
    1.90 +		undoSel, "",
    1.91 +		NULL, "", 
    1.92 +		comment, 
    1.93 +		undoSel);
    1.94  }
    1.95  
    1.96  void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
    1.97 @@ -474,16 +486,33 @@
    1.98  	// selection does not change during action,
    1.99  	// so just save commands for undo and redo
   1.100  	// and use current selection
   1.101 -	saveState (UndoCommand,uc,selection,rc,selection, comment);
   1.102 +	saveState (UndoCommand,
   1.103 +		selection, uc,
   1.104 +		selection, rc, 
   1.105 +		comment, 
   1.106 +		NULL);
   1.107  }
   1.108  
   1.109 -void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uncom, const QString &comment) 
   1.110 +void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uc, const QString &comment) 
   1.111  {
   1.112 -	// 
   1.113 -	saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
   1.114 +	// TODO Is this still needed?
   1.115 +	saveState (UndoCommand,
   1.116 +		unsel, uc,
   1.117 +		NULL, "FIXME-redoCom",	//FIXME
   1.118 +		comment, 
   1.119 +		NULL);
   1.120  }
   1.121  
   1.122 -void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
   1.123 +void MapEditor::saveStateComData(LinkableMapObj *unSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) 
   1.124 +{
   1.125 +	saveState (UndoCommand,
   1.126 +		unSel, uc,
   1.127 +		NULL, "FIXME-redoCom",	//FIXME
   1.128 +		comment, 
   1.129 +		saveSel);
   1.130 +}
   1.131 +
   1.132 +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, LinkableMapObj *redoSel, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
   1.133  {
   1.134  	// Main saveState
   1.135  
   1.136 @@ -491,10 +520,7 @@
   1.137  
   1.138  	/* TODO remove after testing
   1.139  	*/
   1.140 -	cout << "ME::saveState()  begin\n"<<endl;
   1.141 -	cout << "    undosTotal="<<undosTotal<<endl;
   1.142 -	cout << "    ---------------------------"<<endl;
   1.143 -
   1.144 +	cout << "ME::saveState()  begin"<<endl;
   1.145  	historyWindow->append (comment);
   1.146  	
   1.147  	setChanged();
   1.148 @@ -526,21 +552,22 @@
   1.149  		undoSelection=undoSel->getSelectString();
   1.150  		
   1.151  	// Save depending on how much needs to be saved	
   1.152 +	if (!saveSel)
   1.153 +		backupXML="";
   1.154 +	else 
   1.155 +		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
   1.156 +		
   1.157  	QString undoCommand="";
   1.158  	if (savemode==UndoCommand)
   1.159  	{
   1.160  		undoCommand=undoCom;
   1.161 -		backupXML="";
   1.162  	}	
   1.163  	else if (savemode==PartOfMap && undoSel)
   1.164  	{
   1.165  		undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
   1.166 -		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
   1.167  	} else
   1.168  	{
   1.169  		undoCommand="undoMap (\""+bakMapPath+"\")";
   1.170 -		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
   1.171 -		undoSelection="";
   1.172  	}
   1.173  	if (!backupXML.isEmpty())
   1.174  		// Write XML Data to disk
   1.175 @@ -557,16 +584,17 @@
   1.176  
   1.177  	/* TODO remove after testing
   1.178  	*/
   1.179 -	cout << "          into="<< histPath.toStdString()<<endl;
   1.180 -	cout << "    undosAvail="<<undosAvail<<endl;
   1.181 -	cout << "       curStep="<<curStep<<endl;
   1.182 +	//cout << "          into="<< histPath.toStdString()<<endl;
   1.183 +	cout << "    undosTotal="<<undosTotal<<
   1.184 +	", undosAvail="<<undosAvail<<
   1.185 +	", curStep="<<curStep<<endl;
   1.186  	cout << "    ---------------------------"<<endl;
   1.187  	cout << "    comment="<<comment.toStdString()<<endl;
   1.188  	cout << "    undoCom="<<undoCommand.toStdString()<<endl;
   1.189  	cout << "    undoSel="<<undoSelection.toStdString()<<endl;
   1.190  	cout << "    redoCom="<<redoCom.toStdString()<<endl;
   1.191  	cout << "    redoSel="<<redoSelection.toStdString()<<endl;
   1.192 -	cout << "    ---------------------------"<<endl<<endl;
   1.193 +	cout << "    ---------------------------"<<endl;
   1.194  }
   1.195  
   1.196  void MapEditor::parseAtom(const QString &atom)
   1.197 @@ -692,8 +720,8 @@
   1.198  	{
   1.199  		if (api.checkParamCount(2))
   1.200  		{
   1.201 -			s=api.parString (ok,0);
   1.202 -			t=api.parString (ok,1);
   1.203 +			s=api.parString (ok,0);	// undo selection
   1.204 +			t=api.parString (ok,1);	// backup dir
   1.205  			undoXML(s,t);	
   1.206  		}
   1.207  	} else if (com=="select")
   1.208 @@ -711,6 +739,7 @@
   1.209  	// Any errors?
   1.210  	if (api.error())
   1.211  	{
   1.212 +		// TODO Error handling
   1.213  		qWarning("MapEditor::parseAtom: Error!");
   1.214  		qWarning(api.errorDesc());
   1.215  	}	
   1.216 @@ -1467,43 +1496,6 @@
   1.217  	}	
   1.218  }
   1.219  
   1.220 -void MapEditor::editHeading()
   1.221 -{
   1.222 -/* FIXME not needed any longer
   1.223 -	if (selection  &&  
   1.224 -		 (typeid(*selection) == typeid(BranchObj) || 
   1.225 -		  typeid(*selection) == typeid(MapCenterObj) ) ) 
   1.226 -	{
   1.227 -		editingBO=(BranchObj*)selection;
   1.228 -		ensureSelectionVisible();
   1.229 -		QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
   1.230 -
   1.231 -		QDialog *d =new QDialog(NULL);
   1.232 -		QLineEdit *le=new QLineEdit (d);
   1.233 -		d->setWindowFlags (Qt::FramelessWindowHint);
   1.234 -		QPoint q=mapToGlobal (QPoint(0,0));
   1.235 -		d->setGeometry(p.x()+q.x(),p.y()+q.y(),200,25);
   1.236 -		le->resize (d->size());
   1.237 -		le->setText (editingBO->getHeading());
   1.238 -		le->selectAll();
   1.239 -		connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
   1.240 -		d->activateWindow();
   1.241 -		d->exec();
   1.242 -
   1.243 -		saveStateConstSelection(
   1.244 -			"setHeading (\""+editingBO->getHeading()+"\")", 
   1.245 -			"setHeading (\""+le->text()+"\")", 
   1.246 -			QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(le->text()) );
   1.247 -		editingBO->setHeading(le->text() );
   1.248 -		editingBO=NULL;
   1.249 -		mapCenter->reposition();
   1.250 -		adjustCanvasSize();
   1.251 -		ensureSelectionVisible();
   1.252 -		activateWindow();
   1.253 -	}	
   1.254 -*/	
   1.255 -}
   1.256 -
   1.257  QString MapEditor::getHeading(bool &ok, QPoint &p)
   1.258  {
   1.259  	if (selection  &&  
   1.260 @@ -1513,8 +1505,8 @@
   1.261  		ok=true;
   1.262  		ensureSelectionVisible();
   1.263  		p = ((BranchObj*)selection)->getAbsPos();
   1.264 -		p.setY(p.y()+((BranchObj*)selection)->height()/2);
   1.265 -//		p = mapTo(mainWindow,worldMatrix().map( p));
   1.266 +		p.setX (p.x() - contentsX());
   1.267 +		p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
   1.268  		return ((BranchObj*)selection)->getHeading();
   1.269  	}
   1.270  	ok=false;
   1.271 @@ -1523,7 +1515,6 @@
   1.272  
   1.273  void MapEditor::setHeading(const QString &s)
   1.274  {
   1.275 -	// Internal function, no saveState needed
   1.276  	if (selection  &&  
   1.277  		 (typeid(*selection) == typeid(BranchObj) || 
   1.278  		  typeid(*selection) == typeid(MapCenterObj) ) ) 
   1.279 @@ -1682,7 +1673,7 @@
   1.280  				bo2->setHeading("");
   1.281  			}	
   1.282  			if (actionSettingsAutoedit->isOn() )
   1.283 -				editHeading();
   1.284 +				mainWindow->editHeading();
   1.285  			if (!actionSettingsAutoselectHeading->isOn()
   1.286  				&& !wasScrolled)
   1.287  			{
   1.288 @@ -1698,12 +1689,13 @@
   1.289  {
   1.290  	if (selection  && typeid(*selection) ==typeid(BranchObj) ) 
   1.291  	{
   1.292 -		BranchObj* bo=dynamic_cast <BranchObj*> (selection);
   1.293 +		BranchObj* bo=(BranchObj*)selection;
   1.294  		BranchObj* par=(BranchObj*)(bo->getParObj());
   1.295  		bo->unselect();
   1.296  		if (selection->getDepth()>1)
   1.297  			// Normal branch, save parent with childs
   1.298  			saveStatePart(par,QString("Delete %1").arg(getName(bo)));
   1.299 +		//	naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
   1.300  		else
   1.301  			// Mainbranch, save whole map
   1.302  			// TODO Better would be to insert mainbranch again at pos
   1.303 @@ -1719,7 +1711,7 @@
   1.304  	}
   1.305  	if (selection  && typeid(*selection) ==typeid(FloatImageObj) ) 
   1.306  	{
   1.307 -		FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
   1.308 +		FloatImageObj* fio=(FloatImageObj*)selection;
   1.309  		BranchObj* par=(BranchObj*)(fio->getParObj());
   1.310  		saveStatePart(par, QString("Delete %1").arg(getName(fio)));
   1.311  		fio->unselect();
   1.312 @@ -1775,6 +1767,12 @@
   1.313  	return false;
   1.314  }
   1.315  
   1.316 +QString MapEditor::getSelectString()
   1.317 +{
   1.318 +	if (selection) return selection->getSelectString();
   1.319 +	return QString();
   1.320 +}
   1.321 +
   1.322  void MapEditor::selectInt (LinkableMapObj *lmo)
   1.323  {
   1.324  	if (lmo && selection != lmo)
   1.325 @@ -2244,7 +2242,7 @@
   1.326  BranchObj* MapEditor::findText (QString s, bool cs)
   1.327  {
   1.328  	QTextDocument::FindFlags flags=0;
   1.329 -	if (cs) flags=QTextDocument::QTextDocument::FindCaseSensitively;
   1.330 +	if (cs) flags=QTextDocument::FindCaseSensitively;
   1.331  
   1.332  	if (!itFind) 
   1.333  	{	// Nothing found or new find process
   1.334 @@ -2336,6 +2334,24 @@
   1.335  		return "";
   1.336  }
   1.337  
   1.338 +QStringList MapEditor::getURLs()
   1.339 +{
   1.340 +	QStringList urls;
   1.341 +	if (selection && (typeid(*selection) == typeid(BranchObj) ||
   1.342 +			typeid(*selection) == typeid(MapCenterObj)) )
   1.343 +	{		
   1.344 +		BranchObj *bo=(BranchObj*)selection;
   1.345 +		bo=bo->first();	
   1.346 +		while (bo) 
   1.347 +		{
   1.348 +			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
   1.349 +			bo=bo->next();
   1.350 +		}	
   1.351 +	}	
   1.352 +	return urls;
   1.353 +}
   1.354 +
   1.355 +
   1.356  void MapEditor::editHeading2URL()
   1.357  {
   1.358  	if (selection && (typeid(*selection) == typeid(BranchObj) ||
   1.359 @@ -2454,6 +2470,24 @@
   1.360  	
   1.361  }
   1.362  
   1.363 +QStringList MapEditor::getVymLinks()
   1.364 +{
   1.365 +	QStringList links;
   1.366 +	if (selection && (typeid(*selection) == typeid(BranchObj) ||
   1.367 +			typeid(*selection) == typeid(MapCenterObj)) )
   1.368 +	{		
   1.369 +		BranchObj *bo=(BranchObj*)selection;
   1.370 +		bo=bo->first();	
   1.371 +		while (bo) 
   1.372 +		{
   1.373 +			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
   1.374 +			bo=bo->next();
   1.375 +		}	
   1.376 +	}	
   1.377 +	return links;
   1.378 +}
   1.379 +
   1.380 +
   1.381  void MapEditor::removeBranchKeepChilds()
   1.382  {
   1.383  	if (selection && (typeid(*selection) == typeid(BranchObj) ))
   1.384 @@ -2579,14 +2613,14 @@
   1.385  			// Take care of links
   1.386  			if (bo->countXLinks()==0)
   1.387  			{
   1.388 -				branchLinksContextMenuEdit->clear();
   1.389 -				branchLinksContextMenuFollow->clear();
   1.390 +				branchXLinksContextMenuEdit->clear();
   1.391 +				branchXLinksContextMenuFollow->clear();
   1.392  			} else
   1.393  			{
   1.394  				BranchObj *bot;
   1.395  				QString s;
   1.396 -				branchLinksContextMenuEdit->clear();
   1.397 -				branchLinksContextMenuFollow->clear();
   1.398 +				branchXLinksContextMenuEdit->clear();
   1.399 +				branchXLinksContextMenuFollow->clear();
   1.400  				for (int i=0; i<=bo->countXLinks();i++)
   1.401  				{
   1.402  					bot=bo->XLinkTargetAt(i);
   1.403 @@ -2595,8 +2629,8 @@
   1.404  						s=bot->getHeading();
   1.405  						if (s.length()>25)
   1.406  							s=s.left(25)+"...";
   1.407 -						branchLinksContextMenuFollow->addAction (s);
   1.408 -						branchLinksContextMenuEdit->addAction (s);
   1.409 +						branchXLinksContextMenuFollow->addAction (s);
   1.410 +						branchXLinksContextMenuEdit->addAction (s);
   1.411  					}	
   1.412  				}
   1.413  			}
   1.414 @@ -3631,7 +3665,7 @@
   1.415  			if (selection) selection->unselect();
   1.416  			selection=lmo;
   1.417  			selection->select();
   1.418 -			editHeading();
   1.419 +			mainWindow->editHeading();
   1.420  		}
   1.421  	}
   1.422  }