1 #include <QApplication>
6 #include "branchitem.h"
7 #include "mapcenteritem.h"
8 #include "editxlinkdialog.h"
10 #include "exportxhtmldialog.h"
12 #include "geometry.h" // for addBBox
13 #include "mainwindow.h"
14 #include "mapcenterobj.h"
17 #include "selection.h"
20 #include "warningdialog.h"
21 #include "xml-freemind.h"
27 extern Main *mainWindow;
28 extern Settings settings;
29 extern QString tmpVymDir;
31 extern TextEditor *textEditor;
33 extern QString clipboardDir;
34 extern QString clipboardFile;
35 extern bool clipboardEmpty;
37 extern ImageIO imageIO;
39 extern QString vymName;
40 extern QString vymVersion;
41 extern QDir vymBaseDir;
43 extern QDir lastImageDir;
44 extern QDir lastFileDir;
46 extern FlagRowObj *standardFlagsDefault;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 // cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 // cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 selModel->clearSelection();
75 while (!mapCenters.isEmpty()) // FIXME-2 VM needs to be in treemodel only...
76 delete mapCenters.takeFirst();
78 QModelIndex ri=index(rootItem);
79 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
82 void VymModel::init ()
84 // We should have at least one map center to start with
85 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
90 // Also no scene yet (should not be needed anyway) FIXME-3 VM
103 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
104 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
105 mainWindow->updateHistory (undoSet);
108 makeTmpDirectories();
113 fileName=tr("unnamed");
115 blockReposition=false;
116 blockSaveState=false;
118 autosaveTimer=new QTimer (this);
119 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
121 fileChangedTimer=new QTimer (this);
122 fileChangedTimer->start(3000);
123 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
135 animationUse=settings.readBoolEntry("/animation/use",false);
136 animationTicks=settings.readNumEntry("/animation/ticks",10);
137 animationInterval=settings.readNumEntry("/animation/interval",50);
139 animationTimer=new QTimer (this);
140 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
143 defLinkColor=QColor (0,0,255);
144 defXLinkColor=QColor (180,180,180);
145 linkcolorhint=LinkableMapObj::DefaultColor;
146 linkstyle=LinkableMapObj::PolyParabel;
148 defXLinkColor=QColor (230,230,230);
156 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
160 void VymModel::makeTmpDirectories()
162 // Create unique temporary directories
163 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
164 histPath = tmpMapDir+"/history";
170 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
175 bool VymModel::isRepositionBlocked()
177 return blockReposition;
180 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
182 cout << "VymModel::updateActions \n";
183 // Tell mainwindow to update states of actions
184 mainWindow->updateActions();
189 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
191 // tmpdir temporary directory to which data will be written
192 // prefix mapname, which will be appended to images etc.
193 // writeflags Only write flags for "real" save of map, not undo
194 // offset offset of bbox of whole map in scene.
195 // Needed for XML export
204 case LinkableMapObj::Line:
207 case LinkableMapObj::Parabel:
210 case LinkableMapObj::PolyLine:
214 ls="StylePolyParabel";
218 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
220 if (linkcolorhint==LinkableMapObj::HeadingColor)
221 colhint=xml.attribut("linkColorHint","HeadingColor");
223 QString mapAttr=xml.attribut("version",vymVersion);
225 mapAttr+= xml.attribut("author",author) +
226 xml.attribut("comment",comment) +
227 xml.attribut("date",getDate()) +
228 xml.attribut("branchCount", QString().number(branchCount())) +
229 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
230 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
231 xml.attribut("linkStyle", ls ) +
232 xml.attribut("linkColor", defLinkColor.name() ) +
233 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
234 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
236 s+=xml.beginElement("vymmap",mapAttr);
239 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
240 standardFlagsDefault->resetUsedCounter();
242 // Reset the counters before saving
243 // TODO constr. of FIO creates lots of objects, better do this in some other way...
244 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
246 // Build xml recursivly
247 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
248 // Save all mapcenters as complete map, if saveSel not set
249 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
252 if ( typeid(*saveSel) == typeid(BranchObj) )
254 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
255 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
257 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
260 // Save local settings
261 s+=settings.getDataXML (destPath);
264 if (!selection.isEmpty() && !saveSel )
265 s+=xml.valueElement("select",selection.getSelectString());
268 s+=xml.endElement("vymmap");
271 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
275 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
279 for (int i=0; i<mapCenters.count(); i++)
280 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
284 void VymModel::setFilePath(QString fpath, QString destname)
286 if (fpath.isEmpty() || fpath=="")
293 filePath=fpath; // becomes absolute path
294 fileName=fpath; // gets stripped of path
295 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
297 // If fpath is not an absolute path, complete it
298 filePath=QDir(fpath).absPath();
299 fileDir=filePath.left (1+filePath.findRev ("/"));
301 // Set short name, too. Search from behind:
302 int i=fileName.findRev("/");
303 if (i>=0) fileName=fileName.remove (0,i+1);
305 // Forget the .vym (or .xml) for name of map
306 mapName=fileName.left(fileName.findRev(".",-1,true) );
310 void VymModel::setFilePath(QString fpath)
312 setFilePath (fpath,fpath);
315 QString VymModel::getFilePath()
320 QString VymModel::getFileName()
325 QString VymModel::getMapName()
330 QString VymModel::getDestPath()
335 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
337 ErrorCode err=success;
339 parseBaseHandler *handler;
343 case VymMap: handler=new parseVYMHandler; break;
344 case FreemindMap : handler=new parseFreemindHandler; break;
346 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
347 "Unknown FileType in VymModel::load()");
351 bool zipped_org=zipped;
355 selModel->clearSelection();
356 // FIXME-2 VM not needed??? model->setMapEditor(this);
357 // (map state is set later at end of load...)
360 BranchObj *bo=getSelectedBranch();
361 if (!bo) return aborted;
362 if (lmode==ImportAdd)
363 saveStateChangingPart(
366 QString("addMapInsert (%1)").arg(fname),
367 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
369 saveStateChangingPart(
372 QString("addMapReplace(%1)").arg(fname),
373 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
377 // Create temporary directory for packing
379 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
382 QMessageBox::critical( 0, tr( "Critical Load Error" ),
383 tr("Couldn't create temporary directory before load\n"));
388 err=unzipDir (tmpZipDir,fname);
398 // Look for mapname.xml
399 xmlfile= fname.left(fname.findRev(".",-1,true));
400 xmlfile=xmlfile.section( '/', -1 );
401 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
402 if (!mfile.exists() )
404 // mapname.xml does not exist, well,
405 // maybe someone renamed the mapname.vym file...
406 // Try to find any .xml in the toplevel
407 // directory of the .vym file
408 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
409 if (flist.count()==1)
411 // Only one entry, take this one
412 xmlfile=tmpZipDir + "/"+flist.first();
415 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
416 *it=tmpZipDir + "/" + *it;
417 // TODO Multiple entries, load all (but only the first one into this ME)
418 //mainWindow->fileLoadFromTmp (flist);
419 //returnCode=1; // Silently forget this attempt to load
420 qWarning ("MainWindow::load (fn) multimap found...");
423 if (flist.isEmpty() )
425 QMessageBox::critical( 0, tr( "Critical Load Error" ),
426 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
429 } //file doesn't exist
431 xmlfile=mfile.name();
434 QFile file( xmlfile);
436 // I am paranoid: file should exist anyway
437 // according to check in mainwindow.
440 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
441 tr(QString("Couldn't open map %1").arg(file.name())));
445 bool blockSaveStateOrg=blockSaveState;
446 blockReposition=true;
448 QXmlInputSource source( file);
449 QXmlSimpleReader reader;
450 reader.setContentHandler( handler );
451 reader.setErrorHandler( handler );
452 handler->setModel ( this);
455 // We need to set the tmpDir in order to load files with rel. path
460 tmpdir=fname.left(fname.findRev("/",-1));
461 handler->setTmpDir (tmpdir);
462 handler->setInputFile (file.name());
463 handler->setLoadMode (lmode);
464 bool ok = reader.parse( source );
465 blockReposition=false;
466 blockSaveState=blockSaveStateOrg;
470 reposition(); // FIXME-2 VM reposition the view instead...
477 autosaveTimer->stop();
480 // Reset timestamp to check for later updates of file
481 fileChangedTime=QFileInfo (destPath).lastModified();
484 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
485 tr( handler->errorProtocol() ) );
487 // Still return "success": the map maybe at least
488 // partially read by the parser
493 removeDir (QDir(tmpZipDir));
495 // Restore original zip state
502 ErrorCode VymModel::save (const SaveMode &savemode)
506 QString safeFilePath;
508 ErrorCode err=success;
512 mapFileName=mapName+".xml";
514 // use name given by user, even if he chooses .doc
515 mapFileName=fileName;
517 // Look, if we should zip the data:
520 QMessageBox mb( vymName,
521 tr("The map %1\ndid not use the compressed "
522 "vym file format.\nWriting it uncompressed will also write images \n"
523 "and flags and thus may overwrite files in the "
524 "given directory\n\nDo you want to write the map").arg(filePath),
525 QMessageBox::Warning,
526 QMessageBox::Yes | QMessageBox::Default,
528 QMessageBox::Cancel | QMessageBox::Escape);
529 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
530 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
531 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
534 case QMessageBox::Yes:
535 // save compressed (default file format)
538 case QMessageBox::No:
542 case QMessageBox::Cancel:
549 // First backup existing file, we
550 // don't want to add to old zip archives
554 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
556 QString backupFileName(destPath + "~");
557 QFile backupFile(backupFileName);
558 if (backupFile.exists() && !backupFile.remove())
560 QMessageBox::warning(0, tr("Save Error"),
561 tr("%1\ncould not be removed before saving").arg(backupFileName));
563 else if (!f.rename(backupFileName))
565 QMessageBox::warning(0, tr("Save Error"),
566 tr("%1\ncould not be renamed before saving").arg(destPath));
573 // Create temporary directory for packing
575 tmpZipDir=makeTmpDir (ok,"vym-zip");
578 QMessageBox::critical( 0, tr( "Critical Load Error" ),
579 tr("Couldn't create temporary directory before save\n"));
583 safeFilePath=filePath;
584 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
587 // Create mapName and fileDir
588 makeSubDirs (fileDir);
591 if (savemode==CompleteMap || selection.isEmpty())
594 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
597 autosaveTimer->stop();
602 if (selectionType()==TreeItem::Image)
605 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
606 // TODO take care of multiselections
609 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
612 qWarning ("ME::saveStringToDisk failed!");
618 if (err==success) err=zipDir (tmpZipDir,destPath);
621 removeDir (QDir(tmpZipDir));
623 // Restore original filepath outside of tmp zip dir
624 setFilePath (safeFilePath);
628 fileChangedTime=QFileInfo (destPath).lastModified();
632 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
634 QString pathDir=path.left(path.findRev("/"));
640 // We need to parse saved XML data
641 parseVYMHandler handler;
642 QXmlInputSource source( file);
643 QXmlSimpleReader reader;
644 reader.setContentHandler( &handler );
645 reader.setErrorHandler( &handler );
646 handler.setModel ( this);
647 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
648 if (undoSel.isEmpty())
652 handler.setLoadMode (NewMap);
656 handler.setLoadMode (ImportReplace);
658 blockReposition=true;
659 bool ok = reader.parse( source );
660 blockReposition=false;
663 // This should never ever happen
664 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
665 handler.errorProtocol());
668 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
671 void VymModel::addMapInsertInt (const QString &path, int pos)
673 /* FIXME-2 addMapInsertInt not ported yet
674 BranchObj *sel=getSelectedBranch();
677 QString pathDir=path.left(path.findRev("/"));
683 // We need to parse saved XML data
684 parseVYMHandler handler;
685 QXmlInputSource source( file);
686 QXmlSimpleReader reader;
687 reader.setContentHandler( &handler );
688 reader.setErrorHandler( &handler );
689 handler.setModel (this);
690 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
691 handler.setLoadMode (ImportAdd);
692 blockReposition=true;
693 bool ok = reader.parse( source );
694 blockReposition=false;
697 // This should never ever happen
698 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
699 handler.errorProtocol());
701 if (sel->getDepth()>0)
702 sel->getLastBranch()->linkTo (sel,pos);
704 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
709 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
711 TreeItem *fi=createImage();
714 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
722 void VymModel::loadFloatImage ()
724 BranchObj *bo=getSelectedBranch();
728 Q3FileDialog *fd=new Q3FileDialog( NULL);
729 fd->setMode (Q3FileDialog::ExistingFiles);
730 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
731 ImagePreview *p =new ImagePreview (fd);
732 fd->setContentsPreviewEnabled( TRUE );
733 fd->setContentsPreview( p, p );
734 fd->setPreviewMode( Q3FileDialog::Contents );
735 fd->setCaption(vymName+" - " +tr("Load image"));
736 fd->setDir (lastImageDir);
739 if ( fd->exec() == QDialog::Accepted )
741 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
742 lastImageDir=QDir (fd->dirPath());
745 for (int j=0; j<fd->selectedFiles().count(); j++)
747 s=fd->selectedFiles().at(j);
748 fio=loadFloatImageInt (s);
751 (LinkableMapObj*)fio,
754 QString ("loadImage (%1)").arg(s ),
755 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
758 // TODO loadFIO error handling
759 qWarning ("Failed to load "+s);
767 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
772 void VymModel::saveFloatImage ()
774 FloatImageObj *fio=selection.getFloatImage();
777 QFileDialog *fd=new QFileDialog( NULL);
778 fd->setFilters (imageIO.getFilters());
779 fd->setCaption(vymName+" - " +tr("Save image"));
780 fd->setFileMode( QFileDialog::AnyFile );
781 fd->setDirectory (lastImageDir);
782 // fd->setSelection (fio->getOriginalFilename());
786 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
788 fn=fd->selectedFiles().at(0);
789 if (QFile (fn).exists() )
791 QMessageBox mb( vymName,
792 tr("The file %1 exists already.\n"
793 "Do you want to overwrite it?").arg(fn),
794 QMessageBox::Warning,
795 QMessageBox::Yes | QMessageBox::Default,
796 QMessageBox::Cancel | QMessageBox::Escape,
797 QMessageBox::NoButton );
799 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
800 mb.setButtonText( QMessageBox::No, tr("Cancel"));
803 case QMessageBox::Yes:
806 case QMessageBox::Cancel:
813 saveFloatImageInt (fio,fd->selectedFilter(),fn );
820 void VymModel::importDirInt(BranchObj *dst, QDir d)
822 /* FIXME-2 importDirInt not ported yet
823 BranchObj *bo=getSelectedBranch();
826 // Traverse directories
827 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
828 QFileInfoList list = d.entryInfoList();
831 for (int i = 0; i < list.size(); ++i)
834 if (fi.fileName() != "." && fi.fileName() != ".." )
837 bo=dst->getLastBranch();
838 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
839 bi->setHeading (fi.fileName() ); // FIXME-3 check this
840 bo->setColor (QColor("blue"));
842 if ( !d.cd(fi.fileName()) )
843 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
846 // Recursively add subdirs
853 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
854 list = d.entryInfoList();
856 for (int i = 0; i < list.size(); ++i)
860 bo=dst->getLastBranch();
861 bo->setHeading (fi.fileName() );
862 bo->setColor (QColor("black"));
863 if (fi.fileName().right(4) == ".vym" )
864 bo->setVymLink (fi.filePath());
870 void VymModel::importDirInt (const QString &s)
872 BranchObj *bo=getSelectedBranch();
875 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
882 void VymModel::importDir()
884 BranchObj *bo=getSelectedBranch();
888 filters <<"VYM map (*.vym)";
889 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
890 fd->setMode (QFileDialog::DirectoryOnly);
891 fd->setFilters (filters);
892 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
896 if ( fd->exec() == QDialog::Accepted )
898 importDirInt (fd->selectedFile() );
900 //FIXME-3 VM needed? scene()->update();
906 void VymModel::autosave()
911 cout << "VymModel::autosave rejected due to missing filePath\n";
914 QDateTime now=QDateTime().currentDateTime();
916 // Disable autosave, while we have gone back in history
917 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
918 if (redosAvail>0) return;
920 // Also disable autosave for new map without filename
921 if (filePath.isEmpty()) return;
924 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
926 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
927 mainWindow->fileSave (this);
930 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
935 void VymModel::fileChanged()
937 // Check if file on disk has changed meanwhile
938 if (!filePath.isEmpty())
940 QDateTime tmod=QFileInfo (filePath).lastModified();
941 if (tmod>fileChangedTime)
943 // FIXME-2 VM switch to current mapeditor and finish lineedits...
944 QMessageBox mb( vymName,
945 tr("The file of the map on disk has changed:\n\n"
946 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
947 QMessageBox::Question,
949 QMessageBox::Cancel | QMessageBox::Default,
950 QMessageBox::NoButton );
952 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
953 mb.setButtonText( QMessageBox::No, tr("Ignore"));
956 case QMessageBox::Yes:
958 load (filePath,NewMap,fileType);
959 case QMessageBox::Cancel:
960 fileChangedTime=tmod; // allow autosave to overwrite newer file!
966 bool VymModel::isDefault()
971 void VymModel::makeDefault()
977 bool VymModel::hasChanged()
982 void VymModel::setChanged()
984 cout << "VM::setChanged()\n";
987 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
988 cout <<" timer started with "<<settings.value("/mainwindow/autosave/ms/",300000).toInt()<<endl;
997 QString VymModel::getObjectName (const LinkableMapObj *lmo)
1000 if (!lmo) return QString("Error: NULL has no name!");
1002 if ((typeid(*lmo) == typeid(BranchObj) ||
1003 typeid(*lmo) == typeid(MapCenterObj)))
1006 s=(((BranchObj*)lmo)->getHeading());
1007 if (s=="") s="unnamed";
1008 return QString("branch (%1)").arg(s);
1010 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1011 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1012 return QString("Unknown type has no name!");
1015 void VymModel::redo()
1017 // Can we undo at all?
1018 if (redosAvail<1) return;
1020 bool blockSaveStateOrg=blockSaveState;
1021 blockSaveState=true;
1025 if (undosAvail<stepsTotal) undosAvail++;
1027 if (curStep>stepsTotal) curStep=1;
1028 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1029 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1030 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1031 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1032 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1033 QString version=undoSet.readEntry ("/history/version");
1035 /* TODO Maybe check for version, if we save the history
1036 if (!checkVersion(version))
1037 QMessageBox::warning(0,tr("Warning"),
1038 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1041 // Find out current undo directory
1042 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1046 cout << "VymModel::redo() begin\n";
1047 cout << " undosAvail="<<undosAvail<<endl;
1048 cout << " redosAvail="<<redosAvail<<endl;
1049 cout << " curStep="<<curStep<<endl;
1050 cout << " ---------------------------"<<endl;
1051 cout << " comment="<<comment.toStdString()<<endl;
1052 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1053 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1054 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1055 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1056 cout << " ---------------------------"<<endl<<endl;
1059 // select object before redo
1060 if (!redoSelection.isEmpty())
1061 select (redoSelection);
1064 parseAtom (redoCommand);
1067 blockSaveState=blockSaveStateOrg;
1069 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1070 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1071 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1072 undoSet.writeSettings(histPath);
1074 mainWindow->updateHistory (undoSet);
1077 /* TODO remove testing
1078 cout << "ME::redo() end\n";
1079 cout << " undosAvail="<<undosAvail<<endl;
1080 cout << " redosAvail="<<redosAvail<<endl;
1081 cout << " curStep="<<curStep<<endl;
1082 cout << " ---------------------------"<<endl<<endl;
1088 bool VymModel::isRedoAvailable()
1090 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1096 void VymModel::undo()
1098 // Can we undo at all?
1099 if (undosAvail<1) return;
1101 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1103 bool blockSaveStateOrg=blockSaveState;
1104 blockSaveState=true;
1106 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1107 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1108 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1109 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1110 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1111 QString version=undoSet.readEntry ("/history/version");
1113 /* TODO Maybe check for version, if we save the history
1114 if (!checkVersion(version))
1115 QMessageBox::warning(0,tr("Warning"),
1116 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1119 // Find out current undo directory
1120 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1122 // select object before undo
1123 if (!undoSelection.isEmpty())
1124 select (undoSelection);
1128 cout << "VymModel::undo() begin\n";
1129 cout << " undosAvail="<<undosAvail<<endl;
1130 cout << " redosAvail="<<redosAvail<<endl;
1131 cout << " curStep="<<curStep<<endl;
1132 cout << " ---------------------------"<<endl;
1133 cout << " comment="<<comment.toStdString()<<endl;
1134 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1135 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1136 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1137 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1138 cout << " ---------------------------"<<endl<<endl;
1140 parseAtom (undoCommand);
1145 if (curStep<1) curStep=stepsTotal;
1149 blockSaveState=blockSaveStateOrg;
1150 /* TODO remove testing
1151 cout << "VymModel::undo() end\n";
1152 cout << " undosAvail="<<undosAvail<<endl;
1153 cout << " redosAvail="<<redosAvail<<endl;
1154 cout << " curStep="<<curStep<<endl;
1155 cout << " ---------------------------"<<endl<<endl;
1158 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1159 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1160 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1161 undoSet.writeSettings(histPath);
1163 mainWindow->updateHistory (undoSet);
1166 ensureSelectionVisible();
1169 bool VymModel::isUndoAvailable()
1171 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1177 void VymModel::gotoHistoryStep (int i)
1179 // Restore variables
1180 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1181 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1183 if (i<0) i=undosAvail+redosAvail;
1185 // Clicking above current step makes us undo things
1188 for (int j=0; j<undosAvail-i; j++) undo();
1191 // Clicking below current step makes us redo things
1193 for (int j=undosAvail; j<i; j++)
1195 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1199 // And ignore clicking the current row ;-)
1203 QString VymModel::getHistoryPath()
1205 QString histName(QString("history-%1").arg(curStep));
1206 return (tmpMapDir+"/"+histName);
1209 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
1211 sendData(redoCom); //FIXME-3 testing
1216 if (blockSaveState) return;
1218 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1220 // Find out current undo directory
1221 if (undosAvail<stepsTotal) undosAvail++;
1223 if (curStep>stepsTotal) curStep=1;
1225 QString backupXML="";
1226 QString histDir=getHistoryPath();
1227 QString bakMapPath=histDir+"/map.xml";
1229 // Create histDir if not available
1232 makeSubDirs (histDir);
1234 // Save depending on how much needs to be saved
1236 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1238 QString undoCommand="";
1239 if (savemode==UndoCommand)
1241 undoCommand=undoCom;
1243 else if (savemode==PartOfMap )
1245 undoCommand=undoCom;
1246 undoCommand.replace ("PATH",bakMapPath);
1249 if (!backupXML.isEmpty())
1250 // Write XML Data to disk
1251 saveStringToDisk (bakMapPath,backupXML);
1253 // We would have to save all actions in a tree, to keep track of
1254 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1257 // Write the current state to disk
1258 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1259 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1260 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1261 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1262 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1263 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1264 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1265 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1266 undoSet.setEntry (QString("/history/version"),vymVersion);
1267 undoSet.writeSettings(histPath);
1271 // TODO remove after testing
1272 //cout << " into="<< histPath.toStdString()<<endl;
1273 cout << " stepsTotal="<<stepsTotal<<
1274 ", undosAvail="<<undosAvail<<
1275 ", redosAvail="<<redosAvail<<
1276 ", curStep="<<curStep<<endl;
1277 cout << " ---------------------------"<<endl;
1278 cout << " comment="<<comment.toStdString()<<endl;
1279 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1280 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1281 cout << " redoCom="<<redoCom.toStdString()<<endl;
1282 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1283 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1284 cout << " ---------------------------"<<endl;
1287 mainWindow->updateHistory (undoSet);
1293 void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
1295 // save the selected part of the map, Undo will replace part of map
1296 QString undoSelection="";
1298 undoSelection=getSelectString(undoSel);
1300 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1301 QString redoSelection="";
1303 redoSelection=getSelectString(undoSel);
1305 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1308 saveState (PartOfMap,
1309 undoSelection, "addMapReplace (\"PATH\")",
1315 void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
1319 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1322 QString undoSelection=getSelectString (redoSel->getParObj());
1323 QString redoSelection=getSelectString(redoSel);
1324 if (typeid(*redoSel) == typeid(BranchObj) )
1326 // save the selected branch of the map, Undo will insert part of map
1327 saveState (PartOfMap,
1328 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->getTreeItem()->num()),
1329 redoSelection, "delete ()",
1336 void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
1338 // "Normal" savestate: save commands, selections and comment
1339 // so just save commands for undo and redo
1340 // and use current selection
1342 QString redoSelection="";
1343 if (redoSel) redoSelection=getSelectString(redoSel);
1344 QString undoSelection="";
1345 if (undoSel) undoSelection=getSelectString(undoSel);
1347 saveState (UndoCommand,
1354 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1356 // "Normal" savestate: save commands, selections and comment
1357 // so just save commands for undo and redo
1358 // and use current selection
1359 saveState (UndoCommand,
1366 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1368 // "Normal" savestate applied to model (no selection needed):
1369 // save commands and comment
1370 saveState (UndoCommand,
1378 QGraphicsScene* VymModel::getScene ()
1383 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1385 LinkableMapObj *lmo;
1387 for (int i=0;i<mapCenters.count(); i++)
1389 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1390 if (lmo) return lmo;
1395 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1397 LinkableMapObj *lmo;
1403 part=s.section(",",0,0);
1405 num=part.right(part.length() - 3);
1406 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1407 return mapCenters.at(num.toInt() );
1410 for (int i=0; i<mapCenters.count(); i++)
1412 lmo=mapCenters.at(i)->findObjBySelect(s);
1413 if (lmo) return lmo;
1418 LinkableMapObj* VymModel::findID (const QString &s)
1420 LinkableMapObj *lmo;
1421 for (int i=0; i<mapCenters.count(); i++)
1423 lmo=mapCenters.at(i)->findID (s);
1424 if (lmo) return lmo;
1429 //////////////////////////////////////////////
1431 //////////////////////////////////////////////
1432 void VymModel::setVersion (const QString &s)
1437 void VymModel::setAuthor (const QString &s)
1440 QString ("setMapAuthor (\"%1\")").arg(author),
1441 QString ("setMapAuthor (\"%1\")").arg(s),
1442 QString ("Set author of map to \"%1\"").arg(s)
1448 QString VymModel::getAuthor()
1453 void VymModel::setComment (const QString &s)
1456 QString ("setMapComment (\"%1\")").arg(comment),
1457 QString ("setMapComment (\"%1\")").arg(s),
1458 QString ("Set comment of map")
1464 QString VymModel::getComment ()
1469 QString VymModel::getDate ()
1471 return QDate::currentDate().toString ("yyyy-MM-dd");
1474 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1477 BranchItem *cur=NULL;
1478 BranchItem *prev=NULL;
1490 void VymModel::setHeading(const QString &s)
1492 BranchObj *sel=getSelectedBranch();
1497 "setHeading (\""+sel->getHeading()+"\")",
1499 "setHeading (\""+s+"\")",
1500 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1501 sel->setHeading(s );
1502 /* FIXME-3 testing only
1504 TreeItem *ti=getSelectedItem();
1508 //FIXME-3 VM ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1509 //QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1510 //FIXME-3 VM testing only cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1511 QModelIndex ix2=index (ti);
1512 emit (dataChanged ( ix2,ix2));
1516 cout << "Warning: VM::setHeading ti==NULL\n";
1519 //cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1523 ensureSelectionVisible();
1527 BranchObj* VymModel::findText (QString s, bool cs)
1530 QTextDocument::FindFlags flags=0;
1531 if (cs) flags=QTextDocument::FindCaseSensitively;
1534 { // Nothing found or new find process
1536 // nothing found, start again
1540 next (findCurrent,findPrevious,d);
1542 bool searching=true;
1543 bool foundNote=false;
1544 while (searching && !EOFind)
1548 // Searching in Note
1549 if (findCurrent->getNote().contains(s,cs))
1551 select (findCurrent);
1553 if (getSelectedBranch()!=itFind)
1556 ensureSelectionVisible();
1559 if (textEditor->findText(s,flags))
1565 // Searching in Heading
1566 if (searching && findCurrent->getHeading().contains (s,cs) )
1568 select(findCurrent);
1574 if (!next(findCurrent,findPrevious,d) )
1577 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1580 return getSelectedBranch();
1585 void VymModel::findReset()
1586 { // Necessary if text to find changes during a find process
1594 void VymModel::setScene (QGraphicsScene *s)
1596 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1597 //init(); // Here we have a mapScene set,
1598 // which is (still) needed to create MapCenters
1601 void VymModel::setURL(const QString &url)
1603 BranchObj *bo=getSelectedBranch();
1606 QString oldurl=bo->getURL();
1610 QString ("setURL (\"%1\")").arg(oldurl),
1612 QString ("setURL (\"%1\")").arg(url),
1613 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1618 ensureSelectionVisible();
1622 QString VymModel::getURL()
1624 BranchObj *bo=getSelectedBranch();
1626 return bo->getURL();
1631 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1633 return QStringList();
1636 BranchObj *bo=getSelectedBranch();
1642 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1650 void VymModel::linkFloatImageTo(const QString &dstString)
1652 FloatImageObj *fio=selection.getFloatImage();
1655 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1656 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1657 typeid(*dst)==typeid (MapCenterObj)))
1659 LinkableMapObj *dstPar=dst->getParObj();
1660 QString parString=getSelectString(dstPar);
1661 QString fioPreSelectString=getSelectString(fio);
1662 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1663 ((BranchObj*)dst)->addFloatImage (fio);
1664 selection.unselect();
1665 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1666 fio=((BranchObj*)dst)->getLastFloatImage();
1669 selection.select(fio);
1671 getSelectString(fio),
1672 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1674 QString ("linkTo (\"%1\")").arg(dstString),
1675 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1681 void VymModel::setFrameType(const FrameObj::FrameType &t)
1683 BranchObj *bo=getSelectedBranch();
1686 QString s=bo->getFrameTypeName();
1687 bo->setFrameType (t);
1688 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1689 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1695 void VymModel::setFrameType(const QString &s)
1697 BranchObj *bo=getSelectedBranch();
1700 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1701 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1702 bo->setFrameType (s);
1708 void VymModel::setFramePenColor(const QColor &c)
1710 BranchObj *bo=getSelectedBranch();
1713 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1714 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1715 bo->setFramePenColor (c);
1719 void VymModel::setFrameBrushColor(const QColor &c)
1721 BranchObj *bo=getSelectedBranch();
1724 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1725 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1726 bo->setFrameBrushColor (c);
1730 void VymModel::setFramePadding (const int &i)
1732 BranchObj *bo=getSelectedBranch();
1735 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1736 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1737 bo->setFramePadding (i);
1743 void VymModel::setFrameBorderWidth(const int &i)
1745 BranchObj *bo=getSelectedBranch();
1748 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1749 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1750 bo->setFrameBorderWidth (i);
1756 void VymModel::setIncludeImagesVer(bool b)
1758 BranchObj *bo=getSelectedBranch();
1761 QString u= b ? "false" : "true";
1762 QString r=!b ? "false" : "true";
1766 QString("setIncludeImagesVertically (%1)").arg(u),
1768 QString("setIncludeImagesVertically (%1)").arg(r),
1769 QString("Include images vertically in %1").arg(getObjectName(bo))
1771 bo->setIncludeImagesVer(b);
1776 void VymModel::setIncludeImagesHor(bool b)
1778 BranchObj *bo=getSelectedBranch();
1781 QString u= b ? "false" : "true";
1782 QString r=!b ? "false" : "true";
1786 QString("setIncludeImagesHorizontally (%1)").arg(u),
1788 QString("setIncludeImagesHorizontally (%1)").arg(r),
1789 QString("Include images horizontally in %1").arg(getObjectName(bo))
1791 bo->setIncludeImagesHor(b);
1796 void VymModel::setHideLinkUnselected (bool b)
1798 LinkableMapObj *sel=getSelectedLMO();
1800 (selectionType() == TreeItem::Branch ||
1801 selectionType() == TreeItem::MapCenter ||
1802 selectionType() == TreeItem::Image ))
1804 QString u= b ? "false" : "true";
1805 QString r=!b ? "false" : "true";
1809 QString("setHideLinkUnselected (%1)").arg(u),
1811 QString("setHideLinkUnselected (%1)").arg(r),
1812 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1814 sel->setHideLinkUnselected(b);
1818 void VymModel::setHideExport(bool b)
1820 BranchObj *bo=getSelectedBranch();
1823 bo->setHideInExport (b);
1824 QString u= b ? "false" : "true";
1825 QString r=!b ? "false" : "true";
1829 QString ("setHideExport (%1)").arg(u),
1831 QString ("setHideExport (%1)").arg(r),
1832 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1837 // FIXME-3 VM needed? scene()->update();
1841 void VymModel::toggleHideExport()
1843 BranchObj *bo=getSelectedBranch();
1845 setHideExport ( !bo->hideInExport() );
1849 void VymModel::copy()
1851 LinkableMapObj *sel=getSelectedLMO();
1853 (selectionType() == TreeItem::Branch ||
1854 selectionType() == TreeItem::MapCenter ||
1855 selectionType() == TreeItem::Image ))
1857 if (redosAvail == 0)
1860 QString s=getSelectString(sel);
1861 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1862 curClipboard=curStep;
1865 // Copy also to global clipboard, because we are at last step in history
1866 QString bakMapName(QString("history-%1").arg(curStep));
1867 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1868 copyDir (bakMapDir,clipboardDir );
1870 clipboardEmpty=false;
1876 void VymModel::pasteNoSave(const int &n)
1878 bool old=blockSaveState;
1879 blockSaveState=true;
1880 bool zippedOrg=zipped;
1881 if (redosAvail > 0 || n!=0)
1883 // Use the "historical" buffer
1884 QString bakMapName(QString("history-%1").arg(n));
1885 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1886 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1888 // Use the global buffer
1889 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1894 void VymModel::paste()
1896 BranchObj *sel=getSelectedBranch();
1899 saveStateChangingPart(
1902 QString ("paste (%1)").arg(curClipboard),
1903 QString("Paste to %1").arg( getObjectName(sel))
1910 void VymModel::cut()
1912 LinkableMapObj *sel=getSelectedLMO();
1913 if ( sel && (selectionType() == TreeItem::Branch ||
1914 selectionType()==TreeItem::MapCenter ||
1915 selectionType()==TreeItem::Image))
1917 /* No savestate! savestate is called in cutNoSave
1918 saveStateChangingPart(
1922 QString("Cut %1").arg(getObjectName(sel ))
1931 void VymModel::moveBranchUp()
1933 BranchObj* bo=getSelectedBranch();
1937 if (!bo->canMoveBranchUp()) return;
1938 par=(BranchObj*)(bo->getParObj());
1939 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1940 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1942 //FIXME-3 VM needed? scene()->update();
1944 ensureSelectionVisible();
1948 void VymModel::moveBranchDown()
1950 BranchObj* bo=getSelectedBranch();
1954 if (!bo->canMoveBranchDown()) return;
1955 par=(BranchObj*)(bo->getParObj());
1956 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1957 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1959 //FIXME-3 VM needed? scene()->update();
1961 ensureSelectionVisible();
1965 void VymModel::sortChildren() // FIXME-1 not implemented yet
1968 BranchObj* bo=getSelectedBranch();
1971 if(treeItem->branchCount()>1)
1973 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1976 ensureSelectionVisible();
1982 void VymModel::createMapCenter()
1984 MapCenterObj *mco=addMapCenter (QPointF (0,0) );
1988 BranchItem* VymModel::createBranch() // FIXME-2 switcht addNewBrancInt to BranchItem...
1990 BranchObj* bo=addNewBranchInt (-2);
1991 return (BranchItem*)bo->getTreeItem();
1994 TreeItem* VymModel::createImage()
1996 BranchObj *bo=getSelectedBranch();
1999 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
2002 QList<QVariant> cData;
2003 cData << "VM:createImage" << "undef"<<"undef";
2004 TreeItem *parti=bo->getTreeItem();
2005 TreeItem *ti=new TreeItem (cData,parti);
2006 ti->setLMO (newfio);
2007 ti->setType (TreeItem::Image);
2008 parti->appendChild (ti);
2012 newfio->setTreeItem (ti);
2013 select (newfio); // FIXME-2 VM really needed here?
2020 MapCenterObj* VymModel::addMapCenter ()
2022 MapCenterObj *mco=addMapCenter (contextPos);
2023 //FIXME-3 selection.select (mco);
2025 ensureSelectionVisible();
2030 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2031 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2036 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
2040 QModelIndex parix=index(rootItem);
2042 int n=rootItem->branchCount();
2044 emit (layoutAboutToBeChanged() );
2045 beginInsertRows (parix,n,n+1);
2047 QList<QVariant> cData;
2048 cData << "VM:addMapCenter" << "undef"<<"undef";
2049 MapCenterItem *ti=new MapCenterItem (cData,rootItem);
2050 cout << "VM::addMapCenter ti="<<ti<<endl;
2051 ti->setType (TreeItem::MapCenter);
2052 rootItem->appendChild (ti);
2055 emit (newChildObject (parix));
2056 emit (layoutChanged() );
2059 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
2060 mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2061 mapCenter->setTreeItem (ti); // TreeItem needs to exist before setVisibility
2062 ti->setLMO (mapCenter);
2063 mapCenter->move (absPos);
2064 mapCenter->setVisibility (true);
2065 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2066 mapCenters.append(mapCenter);
2069 qWarning ("MW::insertRow a");
2070 if (!insertRow(0, parix))
2072 std::cout << " war nix...\n";
2074 qWarning ("MW::insertRow b");
2080 MapCenterObj* VymModel::removeMapCenter(MapCenterObj* mco)
2082 int i=mapCenters.indexOf (mco);
2085 mapCenters.removeAt (i);
2087 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2092 MapCenterObj* VymModel::getLastMapCenter()
2094 if (mapCenters.size()>0)
2095 return mapCenters.last();
2102 BranchObj* VymModel::addNewBranchInt(int num)
2104 // Depending on pos:
2105 // -3 insert in children of parent above selection
2106 // -2 add branch to selection
2107 // -1 insert in children of parent below selection
2108 // 0..n insert in children of parent at pos
2109 BranchObj *newbo=NULL;
2110 BranchObj *bo=getSelectedBranch();
2111 BranchItem *bi=getSelectedBranchItem();
2117 QList<QVariant> cData;
2118 cData << "new" << "undef"<<"undef";
2120 BranchItem *parbi=bi;
2121 QModelIndex parix=index(parbi);
2122 int n=parbi->branchCount();
2124 emit (layoutAboutToBeChanged() );
2125 beginInsertRows (parix,n,n+1);
2126 bi=new BranchItem (cData,parbi);
2127 bi->setType (TreeItem::Branch);
2129 parbi->appendChild (bi);
2131 emit (newChildObject (parix));
2132 emit (layoutChanged() );
2134 // save scroll state. If scrolled, automatically select
2135 // new branch in order to tmp unscroll parent...
2136 newbo=bo->addBranch();
2141 newbo->setTreeItem (bi);
2142 select (newbo); // FIXME-2 VM really needed here?
2148 bo=(BranchObj*)bo->getParObj();
2149 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2153 bo=(BranchObj*)bo->getParObj();
2154 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2160 BranchObj* VymModel::addNewBranch(int pos)
2162 // Different meaning than num in addNewBranchInt!
2166 BranchObj *bo = getSelectedBranch();
2167 BranchObj *newbo=NULL;
2171 // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2173 newbo=addNewBranchInt (pos-2);
2181 QString ("addBranch (%1)").arg(pos),
2182 QString ("Add new branch to %1").arg(getObjectName(bo)));
2185 // selection.update(); FIXME-3
2186 latestSelectionString=getSelectString(newbo);
2187 // In Network mode, the client needs to know where the new branch is,
2188 // so we have to pass on this information via saveState.
2189 // TODO: Get rid of this positioning workaround
2190 QString ps=qpointfToString (newbo->getAbsPos());
2191 sendData ("selectLatestAdded ()");
2192 sendData (QString("move %1").arg(ps));
2200 BranchObj* VymModel::addNewBranchBefore()
2202 BranchObj *newbo=NULL;
2203 BranchObj *bo = getSelectedBranch();
2204 if (bo && selectionType()==TreeItem::Branch)
2205 // We accept no MapCenterObj here, so we _have_ a parent
2207 QPointF p=bo->getRelPos();
2210 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2212 // add below selection
2213 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2217 newbo->move2RelPos (p);
2219 // Move selection to new branch
2220 bo->linkTo (newbo,-1);
2222 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2223 QString ("Add branch before %1").arg(getObjectName(bo)));
2226 // selection.update(); FIXME-3
2229 latestSelectionString=selection.getSelectString();
2233 void VymModel::deleteSelection()
2235 BranchObj *bo = getSelectedBranch(); // FIXME-2 VM should not be necessary
2238 QModelIndex ix=getSelectedIndex();
2239 if (!ix.isValid() ) return;
2241 QModelIndex parentIndex=parent(ix);
2243 if (!parentIndex.isValid())
2245 cout << "VM::delete no valid parent ix\n";
2249 TreeItem *ti=bo->getTreeItem();
2251 if (selectionType()==TreeItem::MapCenter)
2253 // BranchObj* par=(BranchObj*)(bo->getParObj());
2254 //selection.unselect();
2255 /* FIXME-1 VM Note: does saveStateRemovingPart work for MCO? (No parent!)
2256 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2258 emit (layoutAboutToBeChanged() );
2260 parentIndex=parent(index(ti));
2261 cout << "VM::delete ti="<<ti<<" row="<<ix.row()<<" parIndex.valid="<<parentIndex.isValid()<<endl;
2263 beginRemoveRows (parentIndex,n,n);
2264 removeRows (n,1,parentIndex);
2265 bo=removeMapCenter ((MapCenterObj*)bo);
2270 ensureSelectionVisible();
2271 ensureSelectionVisible();
2275 emit (layoutChanged() );
2277 if (selectionType()==TreeItem::Branch)
2280 BranchObj* par=(BranchObj*)bo->getParObj();
2282 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2284 emit (layoutAboutToBeChanged() );
2286 cout << "VM::delete ti="<<ti<<" row="<<ix.row()<<endl;
2287 parentIndex=parent(index(ti));
2289 beginRemoveRows (parentIndex,n,n);
2290 removeRows (n,1,parentIndex);
2292 par->removeBranch(bo); // remove from BranchObj lists...
2294 ensureSelectionVisible();
2297 emit (layoutChanged() );
2300 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2305 BranchObj* par=(BranchObj*)fio->getParObj();
2306 saveStateChangingPart(
2310 QString("Delete %1").arg(getObjectName(fio))
2313 par->removeFloatImage(fio);
2316 ensureSelectionVisible();
2322 void VymModel::deleteKeepChildren() //FIXME-1 VM still missing
2325 BranchObj *bo=getSelectedBranch();
2329 par=(BranchObj*)(bo->getParObj());
2331 // Don't use this on mapcenter
2334 // Check if we have childs at all to keep
2335 if (bo->getTreeItem()->branchCount()==0)
2341 QPointF p=bo->getRelPos();
2342 saveStateChangingPart(
2345 "deleteKeepChildren ()",
2346 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2349 QString sel=getSelectString(bo);
2351 par->removeBranchHere(bo);
2354 getSelectedBranch()->move2RelPos (p);
2359 void VymModel::deleteChildren() //FIXME-1 VM still missing
2362 BranchObj *bo=getSelectedBranch();
2365 saveStateChangingPart(
2368 "deleteChildren ()",
2369 QString( "Remove children of branch %1").arg(getObjectName(bo))
2371 bo->removeChildren();
2377 bool VymModel::scrollBranch(BranchItem *bi)
2381 if (bi->isScrolled()) return false;
2382 if (bi->branchCount()==0) return false;
2383 if (bi->depth()==0) return false;
2387 /* FIXME-1 no savestate yet
2390 QString ("%1 ()").arg(u),
2392 QString ("%1 ()").arg(r),
2393 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2397 //selection.update();
2398 // FIXME-3 VM needed? scene()->update();
2404 bool VymModel::unscrollBranch(BranchItem *bi)
2408 if (bi->isScrolled()) return false;
2409 if (bi->branchCount()==0) return false;
2410 if (bi->depth()==0) return false;
2415 /* FIXME-1 no savestate yet
2418 QString ("%1 ()").arg(u),
2420 QString ("%1 ()").arg(r),
2421 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2425 // selection.update();
2426 // FIXME-3 VM needed? scene()->update();
2432 void VymModel::toggleScroll()
2434 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2435 if (bi && bi->getType()==TreeItem::Branch )
2437 if (bi->isScrolled())
2438 unscrollBranch (bi);
2444 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2448 BranchObj *bo=getSelectedBranch();
2454 if (bo->isScrolled()) unscrollBranch (bo);
2461 void VymModel::addFloatImage (const QPixmap &img)
2463 BranchObj *bo=getSelectedBranch();
2466 FloatImageObj *fio=bo->addFloatImage();
2468 fio->setOriginalFilename("No original filename (image added by dropevent)");
2469 QString s=getSelectString(bo);
2470 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2471 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2473 // FIXME-3 VM needed? scene()->update();
2478 void VymModel::colorBranch (QColor c)
2480 BranchObj *bo=getSelectedBranch();
2485 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2487 QString ("colorBranch (\"%1\")").arg(c.name()),
2488 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2490 bo->setColor(c); // color branch
2494 void VymModel::colorSubtree (QColor c)
2496 BranchObj *bo=getSelectedBranch();
2499 saveStateChangingPart(
2502 QString ("colorSubtree (\"%1\")").arg(c.name()),
2503 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2505 bo->setColorSubtree (c); // color links, color children
2509 QColor VymModel::getCurrentHeadingColor()
2511 BranchObj *bo=getSelectedBranch();
2512 if (bo) return bo->getColor();
2514 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2520 void VymModel::editURL()
2522 BranchObj *bo=getSelectedBranch();
2526 QString text = QInputDialog::getText(
2527 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2528 bo->getURL(), &ok, NULL);
2530 // user entered something and pressed OK
2535 void VymModel::editLocalURL()
2537 BranchObj *bo=getSelectedBranch();
2540 QStringList filters;
2541 filters <<"All files (*)";
2542 filters << tr("Text","Filedialog") + " (*.txt)";
2543 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2544 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2545 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2546 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2547 fd->setFilters (filters);
2548 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2549 fd->setDirectory (lastFileDir);
2550 if (! bo->getVymLink().isEmpty() )
2551 fd->selectFile( bo->getURL() );
2554 if ( fd->exec() == QDialog::Accepted )
2556 lastFileDir=QDir (fd->directory().path());
2557 setURL (fd->selectedFile() );
2563 void VymModel::editHeading2URL()
2565 BranchObj *bo=getSelectedBranch();
2567 setURL (bo->getHeading());
2570 void VymModel::editBugzilla2URL()
2572 BranchObj *bo=getSelectedBranch();
2575 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2580 void VymModel::editFATE2URL()
2582 BranchObj *bo=getSelectedBranch();
2585 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2588 "setURL (\""+bo->getURL()+"\")",
2590 "setURL (\""+url+"\")",
2591 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2598 void VymModel::editVymLink()
2600 BranchObj *bo=getSelectedBranch();
2603 QStringList filters;
2604 filters <<"VYM map (*.vym)";
2605 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2606 fd->setFilters (filters);
2607 fd->setCaption(vymName+" - " +tr("Link to another map"));
2608 fd->setDirectory (lastFileDir);
2609 if (! bo->getVymLink().isEmpty() )
2610 fd->selectFile( bo->getVymLink() );
2614 if ( fd->exec() == QDialog::Accepted )
2616 lastFileDir=QDir (fd->directory().path());
2619 "setVymLink (\""+bo->getVymLink()+"\")",
2621 "setVymLink (\""+fd->selectedFile()+"\")",
2622 QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile())
2624 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2629 void VymModel::setVymLink (const QString &s)
2631 // Internal function, no saveState needed
2632 BranchObj *bo=getSelectedBranch();
2639 ensureSelectionVisible();
2643 void VymModel::deleteVymLink()
2645 BranchObj *bo=getSelectedBranch();
2650 "setVymLink (\""+bo->getVymLink()+"\")",
2652 "setVymLink (\"\")",
2653 QString("Unset vymlink of %1").arg(getObjectName(bo))
2655 bo->setVymLink ("" );
2658 // FIXME-3 VM needed? scene()->update();
2662 QString VymModel::getVymLink()
2664 BranchObj *bo=getSelectedBranch();
2666 return bo->getVymLink();
2672 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2674 return QStringList();
2677 BranchObj *bo=getSelectedBranch();
2683 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2692 void VymModel::followXLink(int i)
2694 BranchObj *bo=getSelectedBranch();
2697 bo=bo->XLinkTargetAt(i);
2700 selection.select(bo);
2701 ensureSelectionVisible();
2706 void VymModel::editXLink(int i) // FIXME-1 VM missing saveState
2708 BranchObj *bo=getSelectedBranch();
2711 XLinkObj *xlo=bo->XLinkAt(i);
2714 EditXLinkDialog dia;
2716 dia.setSelection(bo);
2717 if (dia.exec() == QDialog::Accepted)
2719 if (dia.useSettingsGlobal() )
2721 setMapDefXLinkColor (xlo->getColor() );
2722 setMapDefXLinkWidth (xlo->getWidth() );
2724 if (dia.deleteXLink())
2725 bo->deleteXLinkAt(i);
2735 //////////////////////////////////////////////
2737 //////////////////////////////////////////////
2739 void VymModel::parseAtom(const QString &atom)
2741 BranchObj *selb=getSelectedBranch();
2742 TreeItem* selti=getSelectedItem();
2743 BranchItem *selbi=getSelectedBranchItem();
2749 // Split string s into command and parameters
2750 parser.parseAtom (atom);
2751 QString com=parser.getCommand();
2753 // External commands
2754 /////////////////////////////////////////////////////////////////////
2755 if (com=="addBranch")
2759 parser.setError (Aborted,"Nothing selected");
2762 parser.setError (Aborted,"Type of selection is not a branch");
2767 if (parser.checkParCount(pl))
2769 if (parser.parCount()==0)
2773 n=parser.parInt (ok,0);
2774 if (ok ) addNewBranch (n);
2778 /////////////////////////////////////////////////////////////////////
2779 } else if (com=="addBranchBefore")
2783 parser.setError (Aborted,"Nothing selected");
2786 parser.setError (Aborted,"Type of selection is not a branch");
2789 if (parser.parCount()==0)
2791 addNewBranchBefore ();
2794 /////////////////////////////////////////////////////////////////////
2795 } else if (com==QString("addMapCenter"))
2797 if (parser.checkParCount(2))
2799 x=parser.parDouble (ok,0);
2802 y=parser.parDouble (ok,1);
2803 if (ok) addMapCenter (QPointF(x,y));
2806 /////////////////////////////////////////////////////////////////////
2807 } else if (com==QString("addMapReplace"))
2811 parser.setError (Aborted,"Nothing selected");
2814 parser.setError (Aborted,"Type of selection is not a branch");
2815 } else if (parser.checkParCount(1))
2817 //s=parser.parString (ok,0); // selection
2818 t=parser.parString (ok,0); // path to map
2819 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2820 addMapReplaceInt(getSelectString(selb),t);
2822 /////////////////////////////////////////////////////////////////////
2823 } else if (com==QString("addMapInsert"))
2827 parser.setError (Aborted,"Nothing selected");
2830 parser.setError (Aborted,"Type of selection is not a branch");
2833 if (parser.checkParCount(2))
2835 t=parser.parString (ok,0); // path to map
2836 n=parser.parInt(ok,1); // position
2837 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2838 addMapInsertInt(t,n);
2841 /////////////////////////////////////////////////////////////////////
2842 } else if (com=="clearFlags")
2846 parser.setError (Aborted,"Nothing selected");
2849 parser.setError (Aborted,"Type of selection is not a branch");
2850 } else if (parser.checkParCount(0))
2852 selb->clearStandardFlags();
2853 selb->updateFlagsToolbar();
2855 /////////////////////////////////////////////////////////////////////
2856 } else if (com=="colorBranch")
2860 parser.setError (Aborted,"Nothing selected");
2863 parser.setError (Aborted,"Type of selection is not a branch");
2864 } else if (parser.checkParCount(1))
2866 QColor c=parser.parColor (ok,0);
2867 if (ok) colorBranch (c);
2869 /////////////////////////////////////////////////////////////////////
2870 } else if (com=="colorSubtree")
2874 parser.setError (Aborted,"Nothing selected");
2877 parser.setError (Aborted,"Type of selection is not a branch");
2878 } else if (parser.checkParCount(1))
2880 QColor c=parser.parColor (ok,0);
2881 if (ok) colorSubtree (c);
2883 /////////////////////////////////////////////////////////////////////
2884 } else if (com=="copy")
2888 parser.setError (Aborted,"Nothing selected");
2891 parser.setError (Aborted,"Type of selection is not a branch");
2892 } else if (parser.checkParCount(0))
2894 //FIXME-1 missing action for copy
2896 /////////////////////////////////////////////////////////////////////
2897 } else if (com=="cut")
2901 parser.setError (Aborted,"Nothing selected");
2902 } else if ( selectionType()!=TreeItem::Branch &&
2903 selectionType()!=TreeItem::MapCenter &&
2904 selectionType()!=TreeItem::Image )
2906 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2907 } else if (parser.checkParCount(0))
2911 /////////////////////////////////////////////////////////////////////
2912 } else if (com=="delete")
2916 parser.setError (Aborted,"Nothing selected");
2918 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2920 parser.setError (Aborted,"Type of selection is wrong.");
2923 else if (parser.checkParCount(0))
2927 /////////////////////////////////////////////////////////////////////
2928 } else if (com=="deleteKeepChildren")
2932 parser.setError (Aborted,"Nothing selected");
2935 parser.setError (Aborted,"Type of selection is not a branch");
2936 } else if (parser.checkParCount(0))
2938 deleteKeepChildren();
2940 /////////////////////////////////////////////////////////////////////
2941 } else if (com=="deleteChildren")
2945 parser.setError (Aborted,"Nothing selected");
2948 parser.setError (Aborted,"Type of selection is not a branch");
2949 } else if (parser.checkParCount(0))
2953 /////////////////////////////////////////////////////////////////////
2954 } else if (com=="exportASCII")
2958 if (parser.parCount()>=1)
2959 // Hey, we even have a filename
2960 fname=parser.parString(ok,0);
2963 parser.setError (Aborted,"Could not read filename");
2966 exportASCII (fname,false);
2968 /////////////////////////////////////////////////////////////////////
2969 } else if (com=="exportImage")
2973 if (parser.parCount()>=2)
2974 // Hey, we even have a filename
2975 fname=parser.parString(ok,0);
2978 parser.setError (Aborted,"Could not read filename");
2981 QString format="PNG";
2982 if (parser.parCount()>=2)
2984 format=parser.parString(ok,1);
2986 exportImage (fname,false,format);
2988 /////////////////////////////////////////////////////////////////////
2989 } else if (com=="exportXHTML")
2993 if (parser.parCount()>=2)
2994 // Hey, we even have a filename
2995 fname=parser.parString(ok,1);
2998 parser.setError (Aborted,"Could not read filename");
3001 exportXHTML (fname,false);
3003 /////////////////////////////////////////////////////////////////////
3004 } else if (com=="exportXML")
3008 if (parser.parCount()>=2)
3009 // Hey, we even have a filename
3010 fname=parser.parString(ok,1);
3013 parser.setError (Aborted,"Could not read filename");
3016 exportXML (fname,false);
3018 /////////////////////////////////////////////////////////////////////
3019 } else if (com=="importDir")
3023 parser.setError (Aborted,"Nothing selected");
3026 parser.setError (Aborted,"Type of selection is not a branch");
3027 } else if (parser.checkParCount(1))
3029 s=parser.parString(ok,0);
3030 if (ok) importDirInt(s);
3032 /////////////////////////////////////////////////////////////////////
3033 } else if (com=="linkTo")
3037 parser.setError (Aborted,"Nothing selected");
3040 if (parser.checkParCount(4))
3042 // 0 selectstring of parent
3043 // 1 num in parent (for branches)
3044 // 2,3 x,y of mainbranch or mapcenter
3045 s=parser.parString(ok,0);
3046 LinkableMapObj *dst=findObjBySelect (s);
3049 if (typeid(*dst) == typeid(BranchObj) )
3051 // Get number in parent
3052 n=parser.parInt (ok,1);
3055 selb->linkTo ((BranchObj*)(dst),n);
3058 } else if (typeid(*dst) == typeid(MapCenterObj) )
3060 selb->linkTo ((BranchObj*)(dst),-1);
3061 // Get coordinates of mainbranch
3062 x=parser.parDouble(ok,2);
3065 y=parser.parDouble(ok,3);
3075 } else if ( selectionType() == TreeItem::Image)
3077 if (parser.checkParCount(1))
3079 // 0 selectstring of parent
3080 s=parser.parString(ok,0);
3081 LinkableMapObj *dst=findObjBySelect (s);
3084 if (typeid(*dst) == typeid(BranchObj) ||
3085 typeid(*dst) == typeid(MapCenterObj))
3086 linkFloatImageTo (getSelectString(dst));
3088 parser.setError (Aborted,"Destination is not a branch");
3091 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3092 /////////////////////////////////////////////////////////////////////
3093 } else if (com=="loadImage")
3097 parser.setError (Aborted,"Nothing selected");
3100 parser.setError (Aborted,"Type of selection is not a branch");
3101 } else if (parser.checkParCount(1))
3103 s=parser.parString(ok,0);
3104 if (ok) loadFloatImageInt (s);
3106 /////////////////////////////////////////////////////////////////////
3107 } else if (com=="moveBranchUp")
3111 parser.setError (Aborted,"Nothing selected");
3114 parser.setError (Aborted,"Type of selection is not a branch");
3115 } else if (parser.checkParCount(0))
3119 /////////////////////////////////////////////////////////////////////
3120 } else if (com=="moveBranchDown")
3124 parser.setError (Aborted,"Nothing selected");
3127 parser.setError (Aborted,"Type of selection is not a branch");
3128 } else if (parser.checkParCount(0))
3132 /////////////////////////////////////////////////////////////////////
3133 } else if (com=="move")
3137 parser.setError (Aborted,"Nothing selected");
3138 } else if ( selectionType()!=TreeItem::Branch &&
3139 selectionType()!=TreeItem::MapCenter &&
3140 selectionType()!=TreeItem::Image )
3142 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3143 } else if (parser.checkParCount(2))
3145 x=parser.parDouble (ok,0);
3148 y=parser.parDouble (ok,1);
3152 /////////////////////////////////////////////////////////////////////
3153 } else if (com=="moveRel")
3157 parser.setError (Aborted,"Nothing selected");
3158 } else if ( selectionType()!=TreeItem::Branch &&
3159 selectionType()!=TreeItem::MapCenter &&
3160 selectionType()!=TreeItem::Image )
3162 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3163 } else if (parser.checkParCount(2))
3165 x=parser.parDouble (ok,0);
3168 y=parser.parDouble (ok,1);
3169 if (ok) moveRel (x,y);
3172 /////////////////////////////////////////////////////////////////////
3173 } else if (com=="nop")
3175 /////////////////////////////////////////////////////////////////////
3176 } else if (com=="paste")
3180 parser.setError (Aborted,"Nothing selected");
3183 parser.setError (Aborted,"Type of selection is not a branch");
3184 } else if (parser.checkParCount(1))
3186 n=parser.parInt (ok,0);
3187 if (ok) pasteNoSave(n);
3189 /////////////////////////////////////////////////////////////////////
3190 } else if (com=="qa")
3194 parser.setError (Aborted,"Nothing selected");
3197 parser.setError (Aborted,"Type of selection is not a branch");
3198 } else if (parser.checkParCount(4))
3201 c=parser.parString (ok,0);
3204 parser.setError (Aborted,"No comment given");
3207 s=parser.parString (ok,1);
3210 parser.setError (Aborted,"First parameter is not a string");
3213 t=parser.parString (ok,2);
3216 parser.setError (Aborted,"Condition is not a string");
3219 u=parser.parString (ok,3);
3222 parser.setError (Aborted,"Third parameter is not a string");
3227 parser.setError (Aborted,"Unknown type: "+s);
3232 parser.setError (Aborted,"Unknown operator: "+t);
3237 parser.setError (Aborted,"Type of selection is not a branch");
3240 if (selb->getHeading() == u)
3242 cout << "PASSED: " << qPrintable (c) << endl;
3245 cout << "FAILED: " << qPrintable (c) << endl;
3255 /////////////////////////////////////////////////////////////////////
3256 } else if (com=="saveImage")
3258 FloatImageObj *fio=selection.getFloatImage();
3261 parser.setError (Aborted,"Type of selection is not an image");
3262 } else if (parser.checkParCount(2))
3264 s=parser.parString(ok,0);
3267 t=parser.parString(ok,1);
3268 if (ok) saveFloatImageInt (fio,t,s);
3271 /////////////////////////////////////////////////////////////////////
3272 } else if (com=="scroll")
3276 parser.setError (Aborted,"Nothing selected");
3277 } else if (! selbi )
3279 parser.setError (Aborted,"Type of selection is not a branch");
3280 } else if (parser.checkParCount(0))
3282 if (!scrollBranch (selbi))
3283 parser.setError (Aborted,"Could not scroll branch");
3285 /////////////////////////////////////////////////////////////////////
3286 } else if (com=="select")
3288 if (parser.checkParCount(1))
3290 s=parser.parString(ok,0);
3293 /////////////////////////////////////////////////////////////////////
3294 } else if (com=="selectLastBranch")
3298 parser.setError (Aborted,"Nothing selected");
3301 parser.setError (Aborted,"Type of selection is not a branch");
3302 } else if (parser.checkParCount(0))
3304 BranchItem *bi=selbi->getLastBranch();
3306 parser.setError (Aborted,"Could not select last branch");
3307 select (bi); // FIXME-3 was selectInt
3310 /////////////////////////////////////////////////////////////////////
3311 } else if (com=="selectLastImage")
3315 parser.setError (Aborted,"Nothing selected");
3318 parser.setError (Aborted,"Type of selection is not a branch");
3319 } else if (parser.checkParCount(0))
3321 FloatImageObj *fio=selb->getLastFloatImage();
3323 parser.setError (Aborted,"Could not select last image");
3324 select (fio); // FIXME-3 was selectInt
3327 /////////////////////////////////////////////////////////////////////
3328 } else if (com=="selectLatestAdded")
3330 if (latestSelectionString.isEmpty() )
3332 parser.setError (Aborted,"No latest added object");
3335 if (!select (latestSelectionString))
3336 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3338 /////////////////////////////////////////////////////////////////////
3339 } else if (com=="setFrameType")
3341 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3343 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3345 else if (parser.checkParCount(1))
3347 s=parser.parString(ok,0);
3348 if (ok) setFrameType (s);
3350 /////////////////////////////////////////////////////////////////////
3351 } else if (com=="setFramePenColor")
3353 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3355 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3357 else if (parser.checkParCount(1))
3359 QColor c=parser.parColor(ok,0);
3360 if (ok) setFramePenColor (c);
3362 /////////////////////////////////////////////////////////////////////
3363 } else if (com=="setFrameBrushColor")
3365 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3367 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3369 else if (parser.checkParCount(1))
3371 QColor c=parser.parColor(ok,0);
3372 if (ok) setFrameBrushColor (c);
3374 /////////////////////////////////////////////////////////////////////
3375 } else if (com=="setFramePadding")
3377 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3379 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3381 else if (parser.checkParCount(1))
3383 n=parser.parInt(ok,0);
3384 if (ok) setFramePadding(n);
3386 /////////////////////////////////////////////////////////////////////
3387 } else if (com=="setFrameBorderWidth")
3389 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3391 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3393 else if (parser.checkParCount(1))
3395 n=parser.parInt(ok,0);
3396 if (ok) setFrameBorderWidth (n);
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="setMapAuthor")
3401 if (parser.checkParCount(1))
3403 s=parser.parString(ok,0);
3404 if (ok) setAuthor (s);
3406 /////////////////////////////////////////////////////////////////////
3407 } else if (com=="setMapComment")
3409 if (parser.checkParCount(1))
3411 s=parser.parString(ok,0);
3412 if (ok) setComment(s);
3414 /////////////////////////////////////////////////////////////////////
3415 } else if (com=="setMapBackgroundColor")
3419 parser.setError (Aborted,"Nothing selected");
3420 } else if (! getSelectedBranch() )
3422 parser.setError (Aborted,"Type of selection is not a branch");
3423 } else if (parser.checkParCount(1))
3425 QColor c=parser.parColor (ok,0);
3426 if (ok) setMapBackgroundColor (c);
3428 /////////////////////////////////////////////////////////////////////
3429 } else if (com=="setMapDefLinkColor")
3433 parser.setError (Aborted,"Nothing selected");
3436 parser.setError (Aborted,"Type of selection is not a branch");
3437 } else if (parser.checkParCount(1))
3439 QColor c=parser.parColor (ok,0);
3440 if (ok) setMapDefLinkColor (c);
3442 /////////////////////////////////////////////////////////////////////
3443 } else if (com=="setMapLinkStyle")
3445 if (parser.checkParCount(1))
3447 s=parser.parString (ok,0);
3448 if (ok) setMapLinkStyle(s);
3450 /////////////////////////////////////////////////////////////////////
3451 } else if (com=="setHeading")
3455 parser.setError (Aborted,"Nothing selected");
3458 parser.setError (Aborted,"Type of selection is not a branch");
3459 } else if (parser.checkParCount(1))
3461 s=parser.parString (ok,0);
3465 /////////////////////////////////////////////////////////////////////
3466 } else if (com=="setHideExport")
3470 parser.setError (Aborted,"Nothing selected");
3471 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3473 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3474 } else if (parser.checkParCount(1))
3476 b=parser.parBool(ok,0);
3477 if (ok) setHideExport (b);
3479 /////////////////////////////////////////////////////////////////////
3480 } else if (com=="setIncludeImagesHorizontally")
3484 parser.setError (Aborted,"Nothing selected");
3487 parser.setError (Aborted,"Type of selection is not a branch");
3488 } else if (parser.checkParCount(1))
3490 b=parser.parBool(ok,0);
3491 if (ok) setIncludeImagesHor(b);
3493 /////////////////////////////////////////////////////////////////////
3494 } else if (com=="setIncludeImagesVertically")
3498 parser.setError (Aborted,"Nothing selected");
3501 parser.setError (Aborted,"Type of selection is not a branch");
3502 } else if (parser.checkParCount(1))
3504 b=parser.parBool(ok,0);
3505 if (ok) setIncludeImagesVer(b);
3507 /////////////////////////////////////////////////////////////////////
3508 } else if (com=="setHideLinkUnselected")
3512 parser.setError (Aborted,"Nothing selected");
3513 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3515 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3516 } else if (parser.checkParCount(1))
3518 b=parser.parBool(ok,0);
3519 if (ok) setHideLinkUnselected(b);
3521 /////////////////////////////////////////////////////////////////////
3522 } else if (com=="setSelectionColor")
3524 if (parser.checkParCount(1))
3526 QColor c=parser.parColor (ok,0);
3527 if (ok) setSelectionColorInt (c);
3529 /////////////////////////////////////////////////////////////////////
3530 } else if (com=="setURL")
3534 parser.setError (Aborted,"Nothing selected");
3537 parser.setError (Aborted,"Type of selection is not a branch");
3538 } else if (parser.checkParCount(1))
3540 s=parser.parString (ok,0);
3543 /////////////////////////////////////////////////////////////////////
3544 } else if (com=="setVymLink")
3548 parser.setError (Aborted,"Nothing selected");
3551 parser.setError (Aborted,"Type of selection is not a branch");
3552 } else if (parser.checkParCount(1))
3554 s=parser.parString (ok,0);
3555 if (ok) setVymLink(s);
3558 /////////////////////////////////////////////////////////////////////
3559 else if (com=="setFlag")
3563 parser.setError (Aborted,"Nothing selected");
3566 parser.setError (Aborted,"Type of selection is not a branch");
3567 } else if (parser.checkParCount(1))
3569 s=parser.parString(ok,0);
3572 selb->activateStandardFlag(s);
3573 selb->updateFlagsToolbar();
3576 /////////////////////////////////////////////////////////////////////
3577 } else if (com=="setFrameType")
3581 parser.setError (Aborted,"Nothing selected");
3584 parser.setError (Aborted,"Type of selection is not a branch");
3585 } else if (parser.checkParCount(1))
3587 s=parser.parString(ok,0);
3591 /////////////////////////////////////////////////////////////////////
3592 } else if (com=="sortChildren")
3596 parser.setError (Aborted,"Nothing selected");
3599 parser.setError (Aborted,"Type of selection is not a branch");
3600 } else if (parser.checkParCount(0))
3604 /////////////////////////////////////////////////////////////////////
3605 } else if (com=="toggleFlag")
3609 parser.setError (Aborted,"Nothing selected");
3612 parser.setError (Aborted,"Type of selection is not a branch");
3613 } else if (parser.checkParCount(1))
3615 s=parser.parString(ok,0);
3618 selb->toggleStandardFlag(s);
3619 selb->updateFlagsToolbar();
3622 /////////////////////////////////////////////////////////////////////
3623 } else if (com=="unscroll")
3627 parser.setError (Aborted,"Nothing selected");
3630 parser.setError (Aborted,"Type of selection is not a branch");
3631 } else if (parser.checkParCount(0))
3633 if (!unscrollBranch (selbi))
3634 parser.setError (Aborted,"Could not unscroll branch");
3636 /////////////////////////////////////////////////////////////////////
3637 } else if (com=="unscrollChildren")
3641 parser.setError (Aborted,"Nothing selected");
3644 parser.setError (Aborted,"Type of selection is not a branch");
3645 } else if (parser.checkParCount(0))
3647 unscrollChildren ();
3649 /////////////////////////////////////////////////////////////////////
3650 } else if (com=="unsetFlag")
3652 if (selection.isEmpty() )
3654 parser.setError (Aborted,"Nothing selected");
3657 parser.setError (Aborted,"Type of selection is not a branch");
3658 } else if (parser.checkParCount(1))
3660 s=parser.parString(ok,0);
3663 selb->deactivateStandardFlag(s);
3664 selb->updateFlagsToolbar();
3668 parser.setError (Aborted,"Unknown command");
3671 if (parser.errorLevel()==NoError)
3673 // setChanged(); FIXME-2 should not be called e.g. for export?!
3678 // TODO Error handling
3679 qWarning("VymModel::parseAtom: Error!");
3680 qWarning(parser.errorMessage());
3684 void VymModel::runScript (QString script)
3686 parser.setScript (script);
3688 while (parser.next() )
3689 parseAtom(parser.getAtom());
3692 void VymModel::setExportMode (bool b)
3694 // should be called before and after exports
3695 // depending on the settings
3696 if (b && settings.value("/export/useHideExport","true")=="true")
3697 setHideTmpMode (HideExport);
3699 setHideTmpMode (HideNone);
3702 void VymModel::exportImage(QString fname, bool askName, QString format)
3706 fname=getMapName()+".png";
3713 QFileDialog *fd=new QFileDialog (NULL);
3714 fd->setCaption (tr("Export map as image"));
3715 fd->setDirectory (lastImageDir);
3716 fd->setFileMode(QFileDialog::AnyFile);
3717 fd->setFilters (imageIO.getFilters() );
3720 fl=fd->selectedFiles();
3722 format=imageIO.getType(fd->selectedFilter());
3726 setExportMode (true);
3727 QPixmap pix (getPixmap());
3728 pix.save(fname, format);
3729 setExportMode (false);
3733 void VymModel::exportXML(QString dir, bool askForName)
3737 dir=browseDirectory(NULL,tr("Export XML to directory"));
3738 if (dir =="" && !reallyWriteDirectory(dir) )
3742 // Hide stuff during export, if settings want this
3743 setExportMode (true);
3745 // Create subdirectories
3748 // write to directory
3749 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3752 file.setName ( dir + "/"+mapName+".xml");
3753 if ( !file.open( QIODevice::WriteOnly ) )
3755 // This should neverever happen
3756 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3760 // Write it finally, and write in UTF8, no matter what
3761 QTextStream ts( &file );
3762 ts.setEncoding (QTextStream::UnicodeUTF8);
3766 // Now write image, too
3767 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3769 setExportMode (false);
3772 void VymModel::exportASCII(QString fname,bool askName)
3777 ex.setFile (mapName+".txt");
3783 //ex.addFilter ("TXT (*.txt)");
3784 ex.setDir(lastImageDir);
3785 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3790 setExportMode(true);
3792 setExportMode(false);
3796 void VymModel::exportXHTML (const QString &dir, bool askForName)
3798 ExportXHTMLDialog dia(NULL);
3799 dia.setFilePath (filePath );
3800 dia.setMapName (mapName );
3802 if (dir!="") dia.setDir (dir);
3808 if (dia.exec()!=QDialog::Accepted)
3812 QDir d (dia.getDir());
3813 // Check, if warnings should be used before overwriting
3814 // the output directory
3815 if (d.exists() && d.count()>0)
3818 warn.showCancelButton (true);
3819 warn.setText(QString(
3820 "The directory %1 is not empty.\n"
3821 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3822 warn.setCaption("Warning: Directory not empty");
3823 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3825 if (warn.exec()!=QDialog::Accepted) ok=false;
3832 exportXML (dia.getDir(),false );
3833 dia.doExport(mapName );
3834 //if (dia.hasChanged()) setChanged();
3838 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3843 if (ex.setConfigFile(cf))
3845 setExportMode (true);
3846 ex.exportPresentation();
3847 setExportMode (false);
3854 //////////////////////////////////////////////
3856 //////////////////////////////////////////////
3858 void VymModel::registerEditor(QWidget *me)
3860 mapEditor=(MapEditor*)me;
3861 for (int i=0; i<mapCenters.count(); i++)
3862 mapCenters.at(i)->setMapEditor(mapEditor);
3865 void VymModel::unregisterEditor(QWidget *)
3870 void VymModel::setContextPos(QPointF p)
3875 void VymModel::unsetContextPos()
3877 contextPos=QPointF();
3880 void VymModel::updateNoteFlag()
3883 cout << "VM::updateNoteFlag()\n";
3884 /* FIXME-1 modify note flag
3885 BranchObj *bo=getSelectedBranch();
3888 bo->updateNoteFlag();
3889 mainWindow->updateActions();
3894 void VymModel::updateRelPositions()
3896 for (int i=0; i<mapCenters.count(); i++)
3897 mapCenters.at(i)->updateRelPositions();
3900 void VymModel::reposition()
3902 for (int i=0;i<mapCenters.count(); i++)
3903 mapCenters.at(i)->reposition(); // for positioning heading
3906 QPolygonF VymModel::shape(BranchObj *bo)
3908 // Creating (arbitrary) shapes
3911 QRectF rb=bo->getBBox();
3912 if (bo->getDepth()==0)
3914 // Just take BBox of this mapCenter
3915 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3919 // Take union of BBox and TotalBBox
3921 QRectF ra=bo->getTotalBBox();
3922 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3925 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3928 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3930 p <<ra.bottomRight()
3932 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3935 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3940 void VymModel::moveAway(LinkableMapObj *lmo)
3944 // Move all branches and MapCenters away from lmo
3945 // to avoid collisions
3950 BranchObj *boA=(BranchObj*)lmo;
3952 for (int i=0; i<mapCenters.count(); i++)
3954 boB=mapCenters.at(i);
3957 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3960 <<" ("<<qPrintable(boA->getHeading() )<<")"
3961 <<" with ("<< qPrintable (boB->getHeading() )
3964 <<" minT="<<r.minTranslation<<endl<<endl;
3968 QPixmap VymModel::getPixmap()
3970 QRectF mapRect=getTotalBBox();
3971 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3974 pp.setRenderHints(mapEditor->renderHints());
3976 // Don't print the visualisation of selection
3977 selection.unselect();
3979 mapScene->render ( &pp,
3980 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3981 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3983 // Restore selection
3984 selection.reselect();
3990 void VymModel::setMapLinkStyle (const QString & s)
3995 case LinkableMapObj::Line :
3998 case LinkableMapObj::Parabel:
3999 snow="StyleParabel";
4001 case LinkableMapObj::PolyLine:
4002 snow="StylePolyLine";
4004 case LinkableMapObj::PolyParabel:
4005 snow="StylePolyParabel";
4008 snow="UndefinedStyle";
4013 QString("setMapLinkStyle (\"%1\")").arg(s),
4014 QString("setMapLinkStyle (\"%1\")").arg(snow),
4015 QString("Set map link style (\"%1\")").arg(s)
4019 linkstyle=LinkableMapObj::Line;
4020 else if (s=="StyleParabel")
4021 linkstyle=LinkableMapObj::Parabel;
4022 else if (s=="StylePolyLine")
4023 linkstyle=LinkableMapObj::PolyLine;
4024 else if (s=="StylePolyParabel")
4025 linkstyle=LinkableMapObj::PolyParabel;
4027 linkstyle=LinkableMapObj::UndefinedStyle;
4029 BranchItem *cur=NULL;
4030 BranchItem *prev=NULL;
4036 bo=(BranchObj*)(cur->getLMO() );
4037 bo->setLinkStyle(bo->getDefLinkStyle());
4038 cur=next(cur,prev,d);
4043 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4048 void VymModel::setMapDefLinkColor(QColor col)
4050 if ( !col.isValid() ) return;
4052 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4053 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4054 QString("Set map link color to %1").arg(col.name())
4058 BranchItem *cur=NULL;
4059 BranchItem *prev=NULL;
4062 cur=next(cur,prev,d);
4065 bo=(BranchObj*)(cur->getLMO() );
4072 void VymModel::setMapLinkColorHintInt()
4074 // called from setMapLinkColorHint(lch) or at end of parse
4075 BranchItem *cur=NULL;
4076 BranchItem *prev=NULL;
4079 cur=next(cur,prev,d);
4082 bo=(BranchObj*)(cur->getLMO() );
4084 cur=next(cur,prev,d);
4088 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4091 setMapLinkColorHintInt();
4094 void VymModel::toggleMapLinkColorHint()
4096 if (linkcolorhint==LinkableMapObj::HeadingColor)
4097 linkcolorhint=LinkableMapObj::DefaultColor;
4099 linkcolorhint=LinkableMapObj::HeadingColor;
4100 BranchItem *cur=NULL;
4101 BranchItem *prev=NULL;
4104 cur=next(cur,prev,d);
4107 bo=(BranchObj*)(cur->getLMO() );
4113 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4115 Q3FileDialog *fd=new Q3FileDialog( NULL);
4116 fd->setMode (Q3FileDialog::ExistingFile);
4117 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4118 ImagePreview *p =new ImagePreview (fd);
4119 fd->setContentsPreviewEnabled( TRUE );
4120 fd->setContentsPreview( p, p );
4121 fd->setPreviewMode( Q3FileDialog::Contents );
4122 fd->setCaption(vymName+" - " +tr("Load background image"));
4123 fd->setDir (lastImageDir);
4126 if ( fd->exec() == QDialog::Accepted )
4128 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4129 lastImageDir=QDir (fd->dirPath());
4130 setMapBackgroundImage (fd->selectedFile());
4134 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4136 QColor oldcol=mapScene->backgroundBrush().color();
4140 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4142 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4143 QString("Set background color of map to %1").arg(col.name()));
4146 brush.setTextureImage (QPixmap (fn));
4147 mapScene->setBackgroundBrush(brush);
4150 void VymModel::selectMapBackgroundColor() // FIXME-1 move to ME
4152 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4153 if ( !col.isValid() ) return;
4154 setMapBackgroundColor( col );
4158 void VymModel::setMapBackgroundColor(QColor col) // FIXME-1 move to ME
4160 QColor oldcol=mapScene->backgroundBrush().color();
4162 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4163 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4164 QString("Set background color of map to %1").arg(col.name()));
4165 mapScene->setBackgroundBrush(col);
4168 QColor VymModel::getMapBackgroundColor() // FIXME-1 move to ME
4170 return mapScene->backgroundBrush().color();
4174 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-1 move to ME
4176 return linkcolorhint;
4179 QColor VymModel::getMapDefLinkColor() // FIXME-1 move to ME
4181 return defLinkColor;
4184 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-1 move to ME
4189 QColor VymModel::getMapDefXLinkColor() // FIXME-1 move to ME
4191 return defXLinkColor;
4194 void VymModel::setMapDefXLinkWidth (int w) // FIXME-1 move to ME
4199 int VymModel::getMapDefXLinkWidth() // FIXME-1 move to ME
4201 return defXLinkWidth;
4204 void VymModel::move(const double &x, const double &y)
4206 BranchObj *bo = getSelectedBranch();
4208 (selectionType()==TreeItem::Branch ||
4209 selectionType()==TreeItem::MapCenter ||
4210 selectionType()==TreeItem::Image
4213 QPointF ap(bo->getAbsPos());
4217 QString ps=qpointfToString(ap);
4218 QString s=getSelectString();
4221 s, "move "+qpointfToString(to),
4222 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4230 void VymModel::moveRel (const double &x, const double &y)
4232 BranchObj *bo = getSelectedBranch();
4234 (selectionType()==TreeItem::Branch ||
4235 selectionType()==TreeItem::MapCenter ||
4236 selectionType()==TreeItem::Image
4240 QPointF rp(bo->getRelPos());
4244 QString ps=qpointfToString (bo->getRelPos());
4245 QString s=getSelectString(bo);
4248 s, "moveRel "+qpointfToString(to),
4249 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4250 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4259 void VymModel::animate()
4261 animationTimer->stop();
4264 while (i<animObjList.size() )
4266 bo=(BranchObj*)animObjList.at(i);
4271 animObjList.removeAt(i);
4278 QItemSelection sel=selModel->selection();
4279 emit (selectionChanged(sel,sel));
4282 if (!animObjList.isEmpty()) animationTimer->start();
4286 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4288 if (bo && bo->getDepth()>0)
4291 ap.setStart (start);
4293 ap.setTicks (animationTicks);
4294 ap.setAnimated (true);
4295 bo->setAnimation (ap);
4296 animObjList.append( bo );
4297 animationTimer->setSingleShot (true);
4298 animationTimer->start(animationInterval);
4302 void VymModel::stopAnimation (MapObj *mo)
4304 int i=animObjList.indexOf(mo);
4306 animObjList.removeAt (i);
4309 void VymModel::sendSelection()
4311 if (netstate!=Server) return;
4312 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4315 void VymModel::newServer()
4319 tcpServer = new QTcpServer(this);
4320 if (!tcpServer->listen(QHostAddress::Any,port)) {
4321 QMessageBox::critical(NULL, "vym server",
4322 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4323 //FIXME-3 needed? we are no widget any longer... close();
4326 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4328 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4331 void VymModel::connectToServer()
4334 server="salam.suse.de";
4336 clientSocket = new QTcpSocket (this);
4337 clientSocket->abort();
4338 clientSocket->connectToHost(server ,port);
4339 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4340 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4341 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4343 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4348 void VymModel::newClient()
4350 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4351 connect(newClient, SIGNAL(disconnected()),
4352 newClient, SLOT(deleteLater()));
4354 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4356 clientList.append (newClient);
4360 void VymModel::sendData(const QString &s)
4362 if (clientList.size()==0) return;
4364 // Create bytearray to send
4366 QDataStream out(&block, QIODevice::WriteOnly);
4367 out.setVersion(QDataStream::Qt_4_0);
4369 // Reserve some space for blocksize
4372 // Write sendCounter
4373 out << sendCounter++;
4378 // Go back and write blocksize so far
4379 out.device()->seek(0);
4380 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4384 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4386 for (int i=0; i<clientList.size(); ++i)
4388 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4389 clientList.at(i)->write (block);
4393 void VymModel::readData ()
4395 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4398 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4402 QDataStream in(clientSocket);
4403 in.setVersion(QDataStream::Qt_4_0);
4411 cout << " t="<<qPrintable (t)<<endl;
4417 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4419 switch (socketError) {
4420 case QAbstractSocket::RemoteHostClosedError:
4422 case QAbstractSocket::HostNotFoundError:
4423 QMessageBox::information(NULL, vymName +" Network client",
4424 "The host was not found. Please check the "
4425 "host name and port settings.");
4427 case QAbstractSocket::ConnectionRefusedError:
4428 QMessageBox::information(NULL, vymName + " Network client",
4429 "The connection was refused by the peer. "
4430 "Make sure the fortune server is running, "
4431 "and check that the host name and port "
4432 "settings are correct.");
4435 QMessageBox::information(NULL, vymName + " Network client",
4436 QString("The following error occurred: %1.")
4437 .arg(clientSocket->errorString()));
4444 void VymModel::selectMapSelectionColor()
4446 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4447 setSelectionColor (col);
4450 void VymModel::setSelectionColorInt (QColor col)
4452 if ( !col.isValid() ) return;
4454 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4455 QString("setSelectionColor (%1)").arg(col.name()),
4456 QString("Set color of selection box to %1").arg(col.name())
4459 mapEditor->setSelectionColor (col);
4463 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4465 cout << "VymModel::changeSelection (";
4466 if (!newsel.indexes().isEmpty() )
4467 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4469 if (!oldsel.indexes().isEmpty() )
4470 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4475 void VymModel::updateSelection(const QItemSelection &newsel)
4477 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4478 ensureSelectionVisible();
4482 void VymModel::updateSelection()
4484 QItemSelection newsel=selModel->selection();
4485 updateSelection (newsel);
4488 void VymModel::setSelectionColor(QColor col)
4490 if ( !col.isValid() ) return;
4492 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4493 QString("setSelectionColor (%1)").arg(col.name()),
4494 QString("Set color of selection box to %1").arg(col.name())
4496 setSelectionColorInt (col);
4499 QColor VymModel::getSelectionColor()
4501 return mapEditor->getSelectionColor();
4504 void VymModel::setHideTmpMode (HideTmpMode mode)
4507 for (int i=0;i<mapCenters.count(); i++)
4508 mapCenters.at(i)->setHideTmp (mode);
4510 // FIXME-3 needed? scene()->update();
4514 QRectF VymModel::getTotalBBox()
4517 for (int i=0;i<mapCenters.count(); i++)
4518 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4522 //////////////////////////////////////////////
4523 // Selection related
4524 //////////////////////////////////////////////
4526 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4531 QItemSelectionModel* VymModel::getSelectionModel()
4536 void VymModel::setSelectionBlocked (bool b)
4541 selection.unblock();
4544 bool VymModel::isSelectionBlocked()
4546 return selection.isBlocked();
4549 bool VymModel::select ()
4551 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4553 TreeItem *item = getItem (index);
4554 return select (item->getLMO() );
4557 bool VymModel::select (const QString &s)
4559 LinkableMapObj *lmo=findObjBySelect(s);
4561 // Finally select the found object
4571 bool VymModel::select (LinkableMapObj *lmo)
4573 QItemSelection oldsel=selModel->selection();
4576 return select (lmo->getTreeItem() );
4581 bool VymModel::select (TreeItem *ti)
4585 QModelIndex ix=index(ti);
4586 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4587 ti->setLastSelectedBranch();
4588 //updateSelection(oldsel); //FIXME-3 needed?
4594 void VymModel::unselect()
4596 selModel->clearSelection();
4599 void VymModel::reselect()
4601 selection.reselect();
4604 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4606 LinkableMapObj *lmo=getSelectedLMO();
4607 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4610 void VymModel::emitContentHasChanged (TreeItem *ti)
4612 QModelIndex ix=index(ti);
4613 emit (contentHasChanged (ix) );
4617 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4620 if (selection.select(lmo))
4622 //selection.update();
4623 sendSelection (); // FIXME-4 VM use signal
4627 void VymModel::selectInt (TreeItem *ti)
4629 if (selection.select(lmo))
4631 //selection.update();
4632 sendSelection (); // FIXME-4 VM use signal
4637 void VymModel::selectNextBranchInt()
4639 // Increase number of branch
4640 LinkableMapObj *sel=getSelectedBranch();
4643 QString s=getSelectString();
4649 part=s.section(",",-1);
4651 num=part.right(part.length() - 3);
4653 s=s.left (s.length() -num.length());
4656 num=QString ("%1").arg(num.toUInt()+1);
4660 // Try to select this one
4661 if (select (s)) return;
4663 // We have no direct successor,
4664 // try to increase the parental number in order to
4665 // find a successor with same depth
4667 int d=getSelectedLMO()->getDepth();
4672 while (!found && d>0)
4674 s=s.section (",",0,d-1);
4675 // replace substring of current depth in s with "1"
4676 part=s.section(",",-1);
4678 num=part.right(part.length() - 3);
4682 // increase number of parent
4683 num=QString ("%1").arg(num.toUInt()+1);
4684 s=s.section (",",0,d-2) + ","+ typ+num;
4687 // Special case, look at orientation
4688 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)
4689 num=QString ("%1").arg(num.toUInt()+1);
4691 num=QString ("%1").arg(num.toUInt()-1);
4696 // pad to oldDepth, select the first branch for each depth
4697 for (i=d;i<oldDepth;i++)
4702 if ( getSelectedItem()->branchCount()>0)
4710 // try to select the freshly built string
4718 void VymModel::selectPrevBranchInt()
4720 // Decrease number of branch
4721 if (selectionType()==TreeItem::Branch)
4723 QString s=getSelectString();
4729 part=s.section(",",-1);
4731 num=part.right(part.length() - 3);
4733 s=s.left (s.length() -num.length());
4735 int n=num.toInt()-1;
4738 num=QString ("%1").arg(n);
4741 // Try to select this one
4742 if (n>=0 && select (s)) return;
4744 // We have no direct precessor,
4745 // try to decrease the parental number in order to
4746 // find a precessor with same depth
4748 int d=getSelectedLMO()->getDepth();
4753 while (!found && d>0)
4755 s=s.section (",",0,d-1);
4756 // replace substring of current depth in s with "1"
4757 part=s.section(",",-1);
4759 num=part.right(part.length() - 3);
4763 // decrease number of parent
4764 num=QString ("%1").arg(num.toInt()-1);
4765 s=s.section (",",0,d-2) + ","+ typ+num;
4768 // Special case, look at orientation
4769 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)
4770 num=QString ("%1").arg(num.toInt()-1);
4772 num=QString ("%1").arg(num.toInt()+1);
4777 // pad to oldDepth, select the last branch for each depth
4778 for (i=d;i<oldDepth;i++)
4782 if ( getSelectedItem()->branchCount()>0)
4783 s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 );
4790 // try to select the freshly built string
4798 void VymModel::selectUpperBranch()
4800 if (selection.isBlocked() ) return;
4802 BranchObj *bo=getSelectedBranch();
4803 if (bo && selectionType()==TreeItem::Branch)
4805 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4806 selectPrevBranchInt();
4808 if (bo->getDepth()==1)
4809 selectNextBranchInt();
4811 selectPrevBranchInt();
4815 void VymModel::selectLowerBranch()
4817 if (selection.isBlocked() ) return;
4819 BranchObj *bo=getSelectedBranch();
4820 if (bo && selectionType()==TreeItem::Branch)
4822 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4823 selectNextBranchInt();
4825 if (bo->getDepth()==1)
4826 selectPrevBranchInt();
4828 selectNextBranchInt();
4833 void VymModel::selectLeftBranch()
4835 if (selection.isBlocked() ) return;
4837 QItemSelection oldsel=selModel->selection();
4840 LinkableMapObj *sel=getSelectedBranch();
4843 if (selectionType()== TreeItem::MapCenter)
4845 QModelIndex ix=getSelectedIndex();
4846 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4849 par=(BranchObj*)(sel->getParObj());
4850 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4853 if (selectionType() == TreeItem::Branch ||
4854 selectionType() == TreeItem::Image)
4856 QModelIndex ix=getSelectedIndex();
4858 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4863 if (selectionType() == TreeItem::Branch )
4865 selectLastSelectedBranch();
4870 updateSelection (oldsel);
4874 void VymModel::selectRightBranch()
4876 if (selection.isBlocked() ) return;
4878 QItemSelection oldsel=selModel->selection();
4881 LinkableMapObj *sel=getSelectedBranch();
4884 if (selectionType()== TreeItem::MapCenter)
4886 QModelIndex ix=getSelectedIndex();
4887 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4890 par=(BranchObj*)(sel->getParObj());
4891 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4894 if (selectionType() == TreeItem::Branch )
4896 selectLastSelectedBranch();
4902 if (selectionType() == TreeItem::Branch ||
4903 selectionType() == TreeItem::Image)
4905 QModelIndex ix=getSelectedIndex();
4907 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4911 updateSelection (oldsel);
4915 void VymModel::selectFirstBranch()
4917 TreeItem *ti=getSelectedBranchItem();
4920 TreeItem *par=ti->parent();
4922 TreeItem *ti2=par->getFirstBranch();
4926 ensureSelectionVisible();
4932 void VymModel::selectLastBranch()
4934 TreeItem *ti=getSelectedBranchItem();
4937 TreeItem *par=ti->parent();
4939 TreeItem *ti2=par->getLastBranch();
4943 ensureSelectionVisible();
4949 void VymModel::selectLastSelectedBranch()
4951 TreeItem *ti=getSelectedBranchItem();
4954 ti=ti->getLastSelectedBranch();
4955 if (ti) select (ti);
4959 void VymModel::selectParent()
4961 TreeItem *ti=getSelectedItem();
4969 ensureSelectionVisible();
4974 TreeItem::Type VymModel::selectionType()
4976 QModelIndexList list=selModel->selectedIndexes();
4977 if (list.isEmpty()) return TreeItem::Undefined;
4978 TreeItem *ti = getItem (list.first() );
4979 return ti->getType();
4983 LinkableMapObj* VymModel::getSelectedLMO()
4985 QModelIndexList list=selModel->selectedIndexes();
4986 if (!list.isEmpty() )
4988 TreeItem *ti = getItem (list.first() );
4989 TreeItem::Type type=ti->getType();
4990 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4992 return ti->getLMO();
4998 BranchObj* VymModel::getSelectedBranch()
5000 TreeItem *ti = getSelectedBranchItem();
5002 return (BranchObj*)ti->getLMO();
5007 BranchItem* VymModel::getSelectedBranchItem()
5009 QModelIndexList list=selModel->selectedIndexes();
5010 if (!list.isEmpty() )
5012 TreeItem *ti = getItem (list.first() );
5013 TreeItem::Type type=ti->getType();
5014 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5015 return (BranchItem*)ti;
5020 TreeItem* VymModel::getSelectedItem()
5022 QModelIndexList list=selModel->selectedIndexes();
5023 if (!list.isEmpty() )
5024 return getItem (list.first() );
5029 QModelIndex VymModel::getSelectedIndex()
5031 QModelIndexList list=selModel->selectedIndexes();
5032 if (list.isEmpty() )
5033 return QModelIndex();
5035 return list.first();
5038 FloatImageObj* VymModel::getSelectedFloatImage()
5040 return selection.getFloatImage();
5043 QString VymModel::getSelectString ()
5045 LinkableMapObj *lmo=getSelectedLMO();
5047 return getSelectString(lmo);
5052 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5054 if (!lmo) return QString();
5055 return getSelectString (lmo->getTreeItem() );
5058 QString VymModel::getSelectString (TreeItem *ti)
5062 if (ti->getType() == TreeItem::Branch ||
5063 ti->getType() == TreeItem::MapCenter)
5065 TreeItem *par=ti->parent();
5068 if (ti->depth() ==1)
5069 // Mainbranch, return
5070 s= "bo:" + QString("%1").arg(ti->num() );
5072 // Branch, call myself recursively
5073 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5077 int i=rootItem->num(ti);
5078 if (i>=0) s=QString("mc:%1").arg(i);