Fixed problem with images included in branches. Added missing adaptormodel.* files
1 #include <QApplication>
7 #include "branchitem.h"
8 #include "editxlinkdialog.h"
10 #include "exportxhtmldialog.h"
12 #include "geometry.h" // for addBBox
13 #include "mainwindow.h"
17 #include "warningdialog.h"
18 #include "xml-freemind.h"
24 extern Main *mainWindow;
25 extern QDBusConnection dbusConnection;
27 extern Settings settings;
28 extern QString tmpVymDir;
30 extern TextEditor *textEditor;
31 extern FlagRow *standardFlagsMaster;
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 Settings settings;
50 int VymModel::mapNum=0; // make instance
54 // cout << "Const VymModel\n";
56 rootItem->setModel (this);
62 cout << "Destr VymModel\n";
63 autosaveTimer->stop();
64 fileChangedTimer->stop();
68 void VymModel::clear()
70 selModel->clearSelection();
72 //QModelIndex ri=index(rootItem);
73 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
76 void VymModel::init ()
78 // We should have at least one map center to start with
79 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
84 // Also no scene yet (should not be needed anyway) FIXME-3 VM
97 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
98 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
99 mainWindow->updateHistory (undoSet);
102 makeTmpDirectories();
107 fileName=tr("unnamed");
109 blockReposition=false;
110 blockSaveState=false;
112 autosaveTimer=new QTimer (this);
113 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
115 fileChangedTimer=new QTimer (this);
116 fileChangedTimer->start(3000);
117 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
122 selectionBlocked=false;
130 animationUse=settings.readBoolEntry("/animation/use",false);
131 animationTicks=settings.readNumEntry("/animation/ticks",10);
132 animationInterval=settings.readNumEntry("/animation/interval",50);
134 animationTimer=new QTimer (this);
135 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
138 defLinkColor=QColor (0,0,255);
139 defXLinkColor=QColor (180,180,180);
140 linkcolorhint=LinkableMapObj::DefaultColor;
141 linkstyle=LinkableMapObj::PolyParabel;
143 defXLinkColor=QColor (230,230,230);
145 hidemode=TreeItem::HideNone;
151 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
154 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
155 //adaptor->setModel (this);
156 //connection.registerObject("/Car", car);
157 dbusConnection.registerService("org.insilmaril.VymModel");
158 dbusConnection.sessionBus().registerObject ("/Object1",this);
161 void VymModel::makeTmpDirectories()
163 // Create unique temporary directories
164 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
165 histPath = tmpMapDir+"/history";
171 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
176 bool VymModel::isRepositionBlocked()
178 return blockReposition;
181 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
183 //cout << "VM::updateActions \n";
184 // Tell mainwindow to update states of actions
185 mainWindow->updateActions();
190 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
192 // tmpdir temporary directory to which data will be written
193 // prefix mapname, which will be appended to images etc.
194 // writeflags Only write flags for "real" save of map, not undo
195 // offset offset of bbox of whole map in scene.
196 // Needed for XML export
205 case LinkableMapObj::Line:
208 case LinkableMapObj::Parabel:
211 case LinkableMapObj::PolyLine:
215 ls="StylePolyParabel";
219 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
221 if (linkcolorhint==LinkableMapObj::HeadingColor)
222 colhint=xml.attribut("linkColorHint","HeadingColor");
224 QString mapAttr=xml.attribut("version",vymVersion);
226 mapAttr+= xml.attribut("author",author) +
227 xml.attribut("comment",comment) +
228 xml.attribut("date",getDate()) +
229 xml.attribut("branchCount", QString().number(branchCount())) +
230 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
231 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
232 xml.attribut("linkStyle", ls ) +
233 xml.attribut("linkColor", defLinkColor.name() ) +
234 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
235 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
237 s+=xml.beginElement("vymmap",mapAttr);
240 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
241 standardFlagsMaster->resetUsedCounter();
243 // Reset the counters before saving
244 // TODO constr. of FIO creates lots of objects, better do this in some other way...
245 ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
247 // Build xml recursivly
248 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
249 // Save all mapcenters as complete map, if saveSel not set
250 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
253 if (saveSel->isBranchLikeType())
255 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
256 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
258 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
261 // Save local settings
262 s+=settings.getDataXML (destPath);
265 if (getSelectedItem() && !saveSel )
266 s+=xml.valueElement("select",getSelectString());
269 s+=xml.endElement("vymmap");
271 //cout << s.toStdString() << endl;
273 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
277 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
281 for (int i=0; i<rootItem->branchCount(); i++)
282 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
286 void VymModel::setFilePath(QString fpath, QString destname)
288 if (fpath.isEmpty() || fpath=="")
295 filePath=fpath; // becomes absolute path
296 fileName=fpath; // gets stripped of path
297 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
299 // If fpath is not an absolute path, complete it
300 filePath=QDir(fpath).absPath();
301 fileDir=filePath.left (1+filePath.findRev ("/"));
303 // Set short name, too. Search from behind:
304 int i=fileName.findRev("/");
305 if (i>=0) fileName=fileName.remove (0,i+1);
307 // Forget the .vym (or .xml) for name of map
308 mapName=fileName.left(fileName.findRev(".",-1,true) );
312 void VymModel::setFilePath(QString fpath)
314 setFilePath (fpath,fpath);
317 QString VymModel::getFilePath()
322 QString VymModel::getFileName()
327 QString VymModel::getMapName()
332 QString VymModel::getDestPath()
337 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
339 ErrorCode err=success;
341 parseBaseHandler *handler;
345 case VymMap: handler=new parseVYMHandler; break;
346 case FreemindMap : handler=new parseFreemindHandler; break;
348 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
349 "Unknown FileType in VymModel::load()");
353 bool zipped_org=zipped;
357 selModel->clearSelection();
358 // FIXME-2 VM not needed??? model->setMapEditor(this);
359 // (map state is set later at end of load...)
362 BranchItem *bi=getSelectedBranchItem();
363 if (!bi) return aborted;
364 if (lmode==ImportAdd)
365 saveStateChangingPart(
368 QString("addMapInsert (%1)").arg(fname),
369 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
371 saveStateChangingPart(
374 QString("addMapReplace(%1)").arg(fname),
375 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
379 // Create temporary directory for packing
381 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
384 QMessageBox::critical( 0, tr( "Critical Load Error" ),
385 tr("Couldn't create temporary directory before load\n"));
390 err=unzipDir (tmpZipDir,fname);
400 // Look for mapname.xml
401 xmlfile= fname.left(fname.findRev(".",-1,true));
402 xmlfile=xmlfile.section( '/', -1 );
403 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
404 if (!mfile.exists() )
406 // mapname.xml does not exist, well,
407 // maybe someone renamed the mapname.vym file...
408 // Try to find any .xml in the toplevel
409 // directory of the .vym file
410 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
411 if (flist.count()==1)
413 // Only one entry, take this one
414 xmlfile=tmpZipDir + "/"+flist.first();
417 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
418 *it=tmpZipDir + "/" + *it;
419 // TODO Multiple entries, load all (but only the first one into this ME)
420 //mainWindow->fileLoadFromTmp (flist);
421 //returnCode=1; // Silently forget this attempt to load
422 qWarning ("MainWindow::load (fn) multimap found...");
425 if (flist.isEmpty() )
427 QMessageBox::critical( 0, tr( "Critical Load Error" ),
428 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
431 } //file doesn't exist
433 xmlfile=mfile.name();
436 QFile file( xmlfile);
438 // I am paranoid: file should exist anyway
439 // according to check in mainwindow.
442 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
443 tr(QString("Couldn't open map %1").arg(file.name())));
447 bool blockSaveStateOrg=blockSaveState;
448 blockReposition=true;
450 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
451 QXmlInputSource source( file);
452 QXmlSimpleReader reader;
453 reader.setContentHandler( handler );
454 reader.setErrorHandler( handler );
455 handler->setModel ( this);
458 // We need to set the tmpDir in order to load files with rel. path
463 tmpdir=fname.left(fname.findRev("/",-1));
464 handler->setTmpDir (tmpdir);
465 handler->setInputFile (file.name());
466 handler->setLoadMode (lmode);
467 bool ok = reader.parse( source );
468 blockReposition=false;
469 blockSaveState=blockSaveStateOrg;
470 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
474 reposition(); // FIXME-2 VM reposition the view instead...
475 emitSelectionChanged();
481 autosaveTimer->stop();
484 // Reset timestamp to check for later updates of file
485 fileChangedTime=QFileInfo (destPath).lastModified();
488 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
489 tr( handler->errorProtocol() ) );
491 // Still return "success": the map maybe at least
492 // partially read by the parser
497 removeDir (QDir(tmpZipDir));
499 // Restore original zip state
506 ErrorCode VymModel::save (const SaveMode &savemode)
510 QString safeFilePath;
512 ErrorCode err=success;
516 mapFileName=mapName+".xml";
518 // use name given by user, even if he chooses .doc
519 mapFileName=fileName;
521 // Look, if we should zip the data:
524 QMessageBox mb( vymName,
525 tr("The map %1\ndid not use the compressed "
526 "vym file format.\nWriting it uncompressed will also write images \n"
527 "and flags and thus may overwrite files in the "
528 "given directory\n\nDo you want to write the map").arg(filePath),
529 QMessageBox::Warning,
530 QMessageBox::Yes | QMessageBox::Default,
532 QMessageBox::Cancel | QMessageBox::Escape);
533 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
534 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
535 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
538 case QMessageBox::Yes:
539 // save compressed (default file format)
542 case QMessageBox::No:
546 case QMessageBox::Cancel:
553 // First backup existing file, we
554 // don't want to add to old zip archives
558 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
560 QString backupFileName(destPath + "~");
561 QFile backupFile(backupFileName);
562 if (backupFile.exists() && !backupFile.remove())
564 QMessageBox::warning(0, tr("Save Error"),
565 tr("%1\ncould not be removed before saving").arg(backupFileName));
567 else if (!f.rename(backupFileName))
569 QMessageBox::warning(0, tr("Save Error"),
570 tr("%1\ncould not be renamed before saving").arg(destPath));
577 // Create temporary directory for packing
579 tmpZipDir=makeTmpDir (ok,"vym-zip");
582 QMessageBox::critical( 0, tr( "Critical Load Error" ),
583 tr("Couldn't create temporary directory before save\n"));
587 safeFilePath=filePath;
588 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
591 // Create mapName and fileDir
592 makeSubDirs (fileDir);
595 if (savemode==CompleteMap || selModel->selection().isEmpty())
598 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
601 autosaveTimer->stop();
606 if (selectionType()==TreeItem::Image)
609 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
610 // TODO take care of multiselections
613 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
616 qWarning ("ME::saveStringToDisk failed!");
622 if (err==success) err=zipDir (tmpZipDir,destPath);
625 removeDir (QDir(tmpZipDir));
627 // Restore original filepath outside of tmp zip dir
628 setFilePath (safeFilePath);
632 fileChangedTime=QFileInfo (destPath).lastModified();
636 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree
638 QString pathDir=path.left(path.findRev("/"));
644 // We need to parse saved XML data
645 parseVYMHandler handler;
646 QXmlInputSource source( file);
647 QXmlSimpleReader reader;
648 reader.setContentHandler( &handler );
649 reader.setErrorHandler( &handler );
650 handler.setModel ( this);
651 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
652 if (undoSel.isEmpty())
656 handler.setLoadMode (NewMap);
660 handler.setLoadMode (ImportReplace);
662 blockReposition=true;
663 bool ok = reader.parse( source );
664 blockReposition=false;
667 // This should never ever happen
668 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
669 handler.errorProtocol());
672 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
675 void VymModel::addMapInsertInt (const QString &path, int pos)
677 /* FIXME-2 addMapInsertInt not ported yet
678 BranchObj *sel=getSelectedBranch();
681 QString pathDir=path.left(path.findRev("/"));
687 // We need to parse saved XML data
688 parseVYMHandler handler;
689 QXmlInputSource source( file);
690 QXmlSimpleReader reader;
691 reader.setContentHandler( &handler );
692 reader.setErrorHandler( &handler );
693 handler.setModel (this);
694 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
695 handler.setLoadMode (ImportAdd);
696 blockReposition=true;
697 bool ok = reader.parse( source );
698 blockReposition=false;
701 // This should never ever happen
702 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
703 handler.errorProtocol());
705 if (sel->getDepth()>0)
706 sel->getLastBranch()->linkTo (sel,pos);
708 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
713 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
715 ImageItem *ii=createImage(dst);
725 void VymModel::loadFloatImage ()
727 BranchItem *selbi=getSelectedBranchItem();
731 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
732 fd->setMode (Q3FileDialog::ExistingFiles);
733 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
734 ImagePreview *p =new ImagePreview (fd);
735 fd->setContentsPreviewEnabled( TRUE );
736 fd->setContentsPreview( p, p );
737 fd->setPreviewMode( Q3FileDialog::Contents );
738 fd->setCaption(vymName+" - " +tr("Load image"));
739 fd->setDir (lastImageDir);
742 if ( fd->exec() == QDialog::Accepted )
744 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
745 lastImageDir=QDir (fd->dirPath());
748 for (int j=0; j<fd->selectedFiles().count(); j++)
750 s=fd->selectedFiles().at(j);
751 ii=loadFloatImageInt (selbi,s);
752 //FIXME-3 check savestate for loadImage
758 QString ("loadImage (%1)").arg(s ),
759 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
762 // TODO loadFIO error handling
763 qWarning ("Failed to load "+s);
771 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
776 void VymModel::saveFloatImage ()
778 ImageItem *ii=getSelectedImageItem();
781 QFileDialog *fd=new QFileDialog( NULL);
782 fd->setFilters (imageIO.getFilters());
783 fd->setCaption(vymName+" - " +tr("Save image"));
784 fd->setFileMode( QFileDialog::AnyFile );
785 fd->setDirectory (lastImageDir);
786 // fd->setSelection (fio->getOriginalFilename());
790 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
792 fn=fd->selectedFiles().at(0);
793 if (QFile (fn).exists() )
795 QMessageBox mb( vymName,
796 tr("The file %1 exists already.\n"
797 "Do you want to overwrite it?").arg(fn),
798 QMessageBox::Warning,
799 QMessageBox::Yes | QMessageBox::Default,
800 QMessageBox::Cancel | QMessageBox::Escape,
801 QMessageBox::NoButton );
803 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
804 mb.setButtonText( QMessageBox::No, tr("Cancel"));
807 case QMessageBox::Yes:
810 case QMessageBox::Cancel:
817 saveFloatImageInt (ii,fd->selectedFilter(),fn );
824 void VymModel::importDirInt(BranchObj *dst, QDir d)
826 /* FIXME-2 importDirInt not ported yet
827 BranchObj *bo=getSelectedBranch();
830 // Traverse directories
831 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
832 QFileInfoList list = d.entryInfoList();
835 for (int i = 0; i < list.size(); ++i)
838 if (fi.fileName() != "." && fi.fileName() != ".." )
841 bo=dst->getLastBranch();
842 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
843 bi->setHeading (fi.fileName() ); // FIXME-3 check this
844 bo->setColor (QColor("blue"));
846 if ( !d.cd(fi.fileName()) )
847 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
850 // Recursively add subdirs
857 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
858 list = d.entryInfoList();
860 for (int i = 0; i < list.size(); ++i)
864 bo=dst->getLastBranch();
865 bo->setHeading (fi.fileName() );
866 bo->setColor (QColor("black"));
867 if (fi.fileName().right(4) == ".vym" )
868 bo->setVymLink (fi.filePath());
874 void VymModel::importDirInt (const QString &s) // FIXME-2
877 BranchObj *bo=getSelectedBranch();
880 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
888 void VymModel::importDir() //FIXME-2
891 BranchObj *bo=getSelectedBranch();
895 filters <<"VYM map (*.vym)";
896 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
897 fd->setMode (QFileDialog::DirectoryOnly);
898 fd->setFilters (filters);
899 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
903 if ( fd->exec() == QDialog::Accepted )
905 importDirInt (fd->selectedFile() );
907 //FIXME-3 VM needed? scene()->update();
914 void VymModel::autosave()
919 cout << "VymModel::autosave rejected due to missing filePath\n";
922 QDateTime now=QDateTime().currentDateTime();
924 // Disable autosave, while we have gone back in history
925 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
926 if (redosAvail>0) return;
928 // Also disable autosave for new map without filename
929 if (filePath.isEmpty()) return;
932 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
934 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
935 mainWindow->fileSave (this);
938 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
943 void VymModel::fileChanged()
945 // Check if file on disk has changed meanwhile
946 if (!filePath.isEmpty())
948 QDateTime tmod=QFileInfo (filePath).lastModified();
949 if (tmod>fileChangedTime)
951 // FIXME-2 VM switch to current mapeditor and finish lineedits...
952 QMessageBox mb( vymName,
953 tr("The file of the map on disk has changed:\n\n"
954 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
955 QMessageBox::Question,
957 QMessageBox::Cancel | QMessageBox::Default,
958 QMessageBox::NoButton );
960 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
961 mb.setButtonText( QMessageBox::No, tr("Ignore"));
964 case QMessageBox::Yes:
966 load (filePath,NewMap,fileType);
967 case QMessageBox::Cancel:
968 fileChangedTime=tmod; // allow autosave to overwrite newer file!
974 bool VymModel::isDefault()
979 void VymModel::makeDefault()
985 bool VymModel::hasChanged()
990 void VymModel::setChanged()
993 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
997 latestAddedItem=NULL;
1001 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1003 if (!lmo || !lmo->getTreeItem() ) return QString();
1004 return getObjectName (lmo->getTreeItem() );
1008 QString VymModel::getObjectName (TreeItem *ti)
1011 if (!ti) return QString("Error: NULL has no name!");
1013 if (s=="") s="unnamed";
1015 if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter??
1016 return QString("branch (%1)").arg(s);
1017 if (ti->getType()==TreeItem::Image)
1018 return QString ("image (%1)").arg(ti->getHeading());
1019 return QString("Unknown type has no name!");
1022 void VymModel::redo()
1024 // Can we undo at all?
1025 if (redosAvail<1) return;
1027 bool blockSaveStateOrg=blockSaveState;
1028 blockSaveState=true;
1032 if (undosAvail<stepsTotal) undosAvail++;
1034 if (curStep>stepsTotal) curStep=1;
1035 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1036 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1037 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1038 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1039 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1040 QString version=undoSet.readEntry ("/history/version");
1042 /* TODO Maybe check for version, if we save the history
1043 if (!checkVersion(version))
1044 QMessageBox::warning(0,tr("Warning"),
1045 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1048 // Find out current undo directory
1049 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1053 cout << "VymModel::redo() begin\n";
1054 cout << " undosAvail="<<undosAvail<<endl;
1055 cout << " redosAvail="<<redosAvail<<endl;
1056 cout << " curStep="<<curStep<<endl;
1057 cout << " ---------------------------"<<endl;
1058 cout << " comment="<<comment.toStdString()<<endl;
1059 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1060 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1061 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1062 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1063 cout << " ---------------------------"<<endl<<endl;
1066 // select object before redo
1067 if (!redoSelection.isEmpty())
1068 select (redoSelection);
1071 parseAtom (redoCommand);
1074 blockSaveState=blockSaveStateOrg;
1076 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1077 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1078 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1079 undoSet.writeSettings(histPath);
1081 mainWindow->updateHistory (undoSet);
1084 /* TODO remove testing
1085 cout << "ME::redo() end\n";
1086 cout << " undosAvail="<<undosAvail<<endl;
1087 cout << " redosAvail="<<redosAvail<<endl;
1088 cout << " curStep="<<curStep<<endl;
1089 cout << " ---------------------------"<<endl<<endl;
1095 bool VymModel::isRedoAvailable()
1097 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1103 void VymModel::undo()
1105 // Can we undo at all?
1106 if (undosAvail<1) return;
1108 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1110 bool blockSaveStateOrg=blockSaveState;
1111 blockSaveState=true;
1113 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1114 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1115 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1116 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1117 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1118 QString version=undoSet.readEntry ("/history/version");
1120 /* TODO Maybe check for version, if we save the history
1121 if (!checkVersion(version))
1122 QMessageBox::warning(0,tr("Warning"),
1123 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1126 // Find out current undo directory
1127 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1129 // select object before undo
1130 if (!undoSelection.isEmpty())
1131 select (undoSelection);
1135 cout << "VymModel::undo() begin\n";
1136 cout << " undosAvail="<<undosAvail<<endl;
1137 cout << " redosAvail="<<redosAvail<<endl;
1138 cout << " curStep="<<curStep<<endl;
1139 cout << " ---------------------------"<<endl;
1140 cout << " comment="<<comment.toStdString()<<endl;
1141 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1142 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1143 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1144 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1145 cout << " ---------------------------"<<endl<<endl;
1147 parseAtom (undoCommand);
1152 if (curStep<1) curStep=stepsTotal;
1156 blockSaveState=blockSaveStateOrg;
1157 /* TODO remove testing
1158 cout << "VymModel::undo() end\n";
1159 cout << " undosAvail="<<undosAvail<<endl;
1160 cout << " redosAvail="<<redosAvail<<endl;
1161 cout << " curStep="<<curStep<<endl;
1162 cout << " ---------------------------"<<endl<<endl;
1165 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1166 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1167 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1168 undoSet.writeSettings(histPath);
1170 mainWindow->updateHistory (undoSet);
1172 emitSelectionChanged();
1175 bool VymModel::isUndoAvailable()
1177 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1183 void VymModel::gotoHistoryStep (int i)
1185 // Restore variables
1186 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1187 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1189 if (i<0) i=undosAvail+redosAvail;
1191 // Clicking above current step makes us undo things
1194 for (int j=0; j<undosAvail-i; j++) undo();
1197 // Clicking below current step makes us redo things
1199 for (int j=undosAvail; j<i; j++)
1201 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1205 // And ignore clicking the current row ;-)
1209 QString VymModel::getHistoryPath()
1211 QString histName(QString("history-%1").arg(curStep));
1212 return (tmpMapDir+"/"+histName);
1215 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1217 sendData(redoCom); //FIXME-3 testing
1222 if (blockSaveState) return;
1224 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1226 // Find out current undo directory
1227 if (undosAvail<stepsTotal) undosAvail++;
1229 if (curStep>stepsTotal) curStep=1;
1231 QString backupXML="";
1232 QString histDir=getHistoryPath();
1233 QString bakMapPath=histDir+"/map.xml";
1235 // Create histDir if not available
1238 makeSubDirs (histDir);
1240 // Save depending on how much needs to be saved
1242 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1244 QString undoCommand="";
1245 if (savemode==UndoCommand)
1247 undoCommand=undoCom;
1249 else if (savemode==PartOfMap )
1251 undoCommand=undoCom;
1252 undoCommand.replace ("PATH",bakMapPath);
1256 if (!backupXML.isEmpty())
1257 // Write XML Data to disk
1258 saveStringToDisk (bakMapPath,backupXML);
1260 // We would have to save all actions in a tree, to keep track of
1261 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1264 // Write the current state to disk
1265 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1266 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1267 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1268 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1269 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1270 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1271 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1272 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1273 undoSet.setEntry (QString("/history/version"),vymVersion);
1274 undoSet.writeSettings(histPath);
1278 // TODO remove after testing
1279 //cout << " into="<< histPath.toStdString()<<endl;
1280 cout << " stepsTotal="<<stepsTotal<<
1281 ", undosAvail="<<undosAvail<<
1282 ", redosAvail="<<redosAvail<<
1283 ", curStep="<<curStep<<endl;
1284 cout << " ---------------------------"<<endl;
1285 cout << " comment="<<comment.toStdString()<<endl;
1286 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1287 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1288 cout << " redoCom="<<redoCom.toStdString()<<endl;
1289 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1290 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1291 cout << " ---------------------------"<<endl;
1294 mainWindow->updateHistory (undoSet);
1300 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1302 // save the selected part of the map, Undo will replace part of map
1303 QString undoSelection="";
1305 undoSelection=getSelectString(undoSel);
1307 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1308 QString redoSelection="";
1310 redoSelection=getSelectString(undoSel);
1312 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1315 saveState (PartOfMap,
1316 undoSelection, "addMapReplace (\"PATH\")",
1322 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1326 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1329 QString undoSelection=getSelectString (redoSel->parent() );
1330 QString redoSelection=getSelectString(redoSel);
1331 if (redoSel->getType()==TreeItem::Branch)
1333 // save the selected branch of the map, Undo will insert part of map
1334 saveState (PartOfMap,
1335 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1336 redoSelection, "delete ()",
1343 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1345 // "Normal" savestate: save commands, selections and comment
1346 // so just save commands for undo and redo
1347 // and use current selection
1349 QString redoSelection="";
1350 if (redoSel) redoSelection=getSelectString(redoSel);
1351 QString undoSelection="";
1352 if (undoSel) undoSelection=getSelectString(undoSel);
1354 saveState (UndoCommand,
1361 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1363 // "Normal" savestate: save commands, selections and comment
1364 // so just save commands for undo and redo
1365 // and use current selection
1366 saveState (UndoCommand,
1373 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1375 // "Normal" savestate applied to model (no selection needed):
1376 // save commands and comment
1377 saveState (UndoCommand,
1385 QGraphicsScene* VymModel::getScene ()
1390 TreeItem* VymModel::findBySelectString(QString s)
1392 if (s.isEmpty() ) return NULL;
1394 // Old maps don't have multiple mapcenters and don't save full path
1395 if (s.left(2) !="mc")
1398 QStringList parts=s.split (",");
1401 TreeItem *ti=rootItem;
1403 while (!parts.isEmpty() )
1405 typ=parts.first().left(2);
1406 n=parts.first().right(parts.first().length() - 3).toInt();
1407 parts.removeFirst();
1408 if (typ=="mc" || typ=="bo")
1409 ti=ti->getBranchNum (n);
1413 ti=ti->getImageNum (n);
1419 TreeItem* VymModel::findID (const QString &s)
1422 for (int i=0; i<rootItem->branchCount(); i++)
1424 ti=rootItem->getBranchNum(i)->findID (s);
1430 //////////////////////////////////////////////
1432 //////////////////////////////////////////////
1433 void VymModel::setVersion (const QString &s)
1438 void VymModel::setAuthor (const QString &s)
1441 QString ("setMapAuthor (\"%1\")").arg(author),
1442 QString ("setMapAuthor (\"%1\")").arg(s),
1443 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")
1463 QString VymModel::getComment ()
1468 QString VymModel::getDate ()
1470 return QDate::currentDate().toString ("yyyy-MM-dd");
1473 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1476 BranchItem *cur=NULL;
1477 BranchItem *prev=NULL;
1487 void VymModel::setHeading(const QString &s)
1489 BranchItem *selbi=getSelectedBranchItem();
1494 "setHeading (\""+selbi->getHeading()+"\")",
1496 "setHeading (\""+s+"\")",
1497 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1498 selbi->setHeading(s );
1499 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1501 emitSelectionChanged();
1505 QString VymModel::getHeading()
1507 TreeItem *selti=getSelectedItem();
1509 return selti->getHeading();
1514 BranchItem* VymModel::findText (QString s, bool cs)
1516 QTextDocument::FindFlags flags=0;
1517 if (cs) flags=QTextDocument::FindCaseSensitively;
1520 { // Nothing found or new find process
1522 // nothing found, start again
1526 next (findCurrent,findPrevious);
1528 bool searching=true;
1529 bool foundNote=false;
1530 while (searching && !EOFind)
1534 // Searching in Note
1535 if (findCurrent->getNote().contains(s,cs))
1537 select (findCurrent);
1539 if (getSelectedBranch()!=itFind)
1542 emitShowSelection();
1545 if (textEditor->findText(s,flags))
1551 // Searching in Heading
1552 if (searching && findCurrent->getHeading().contains (s,cs) )
1554 select(findCurrent);
1560 if (!next(findCurrent,findPrevious) )
1563 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1566 return getSelectedBranchItem();
1571 void VymModel::findReset()
1572 { // Necessary if text to find changes during a find process
1578 void VymModel::setScene (QGraphicsScene *s)
1580 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1581 //init(); // Here we have a mapScene set,
1582 // which is (still) needed to create MapCenters
1585 void VymModel::setURL(const QString &url)
1587 TreeItem *selti=getSelectedItem();
1590 QString oldurl=selti->getURL();
1591 selti->setURL (url);
1594 QString ("setURL (\"%1\")").arg(oldurl),
1596 QString ("setURL (\"%1\")").arg(url),
1597 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1600 emitDataHasChanged (selti);
1601 emitShowSelection();
1605 QString VymModel::getURL()
1607 TreeItem *selti=getSelectedItem();
1609 return selti->getURL();
1614 QStringList VymModel::getURLs()
1617 BranchItem *selbi=getSelectedBranchItem();
1618 BranchItem *cur=selbi;
1619 BranchItem *prev=NULL;
1622 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1623 cur=next (cur,prev,selbi);
1629 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1631 BranchItem *bi=getSelectedBranchItem();
1634 BranchObj *bo=(BranchObj*)(bi->getLMO());
1637 QString s=bo->getFrameTypeName();
1638 bo->setFrameType (t);
1639 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1640 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1642 bo->updateLinkGeometry();
1647 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1649 BranchItem *bi=getSelectedBranchItem();
1652 BranchObj *bo=(BranchObj*)(bi->getLMO());
1655 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1656 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1657 bo->setFrameType (s);
1659 bo->updateLinkGeometry();
1664 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1667 BranchItem *bi=getSelectedBranchItem();
1670 BranchObj *bo=(BranchObj*)(bi->getLMO());
1673 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1674 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1675 bo->setFramePenColor (c);
1680 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1682 BranchItem *bi=getSelectedBranchItem();
1685 BranchObj *bo=(BranchObj*)(bi->getLMO());
1688 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1689 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1690 bo->setFrameBrushColor (c);
1695 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1697 BranchItem *bi=getSelectedBranchItem();
1700 BranchObj *bo=(BranchObj*)(bi->getLMO());
1703 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1704 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1705 bo->setFramePadding (i);
1707 bo->updateLinkGeometry();
1712 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1714 BranchItem *bi=getSelectedBranchItem();
1717 BranchObj *bo=(BranchObj*)(bi->getLMO());
1720 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1721 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1722 bo->setFrameBorderWidth (i);
1724 bo->updateLinkGeometry();
1729 void VymModel::setIncludeImagesVer(bool b)
1731 BranchItem *bi=getSelectedBranchItem();
1734 QString u= b ? "false" : "true";
1735 QString r=!b ? "false" : "true";
1739 QString("setIncludeImagesVertically (%1)").arg(u),
1741 QString("setIncludeImagesVertically (%1)").arg(r),
1742 QString("Include images vertically in %1").arg(getObjectName(bi))
1744 bi->setIncludeImagesVer(b);
1745 emitDataHasChanged ( bi);
1750 void VymModel::setIncludeImagesHor(bool b)
1752 BranchItem *bi=getSelectedBranchItem();
1755 QString u= b ? "false" : "true";
1756 QString r=!b ? "false" : "true";
1760 QString("setIncludeImagesHorizontally (%1)").arg(u),
1762 QString("setIncludeImagesHorizontally (%1)").arg(r),
1763 QString("Include images horizontally in %1").arg(getObjectName(bi))
1765 bi->setIncludeImagesHor(b);
1766 emitDataHasChanged ( bi);
1771 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1773 TreeItem *ti=getSelectedItem();
1774 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1776 QString u= b ? "false" : "true";
1777 QString r=!b ? "false" : "true";
1781 QString("setHideLinkUnselected (%1)").arg(u),
1783 QString("setHideLinkUnselected (%1)").arg(r),
1784 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1786 ((MapItem*)ti)->setHideLinkUnselected(b);
1790 void VymModel::setHideExport(bool b)
1792 TreeItem *ti=getSelectedItem();
1794 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1796 ti->setHideInExport (b);
1797 QString u= b ? "false" : "true";
1798 QString r=!b ? "false" : "true";
1802 QString ("setHideExport (%1)").arg(u),
1804 QString ("setHideExport (%1)").arg(r),
1805 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1807 emitDataHasChanged(ti);
1808 emitSelectionChanged();
1811 // emitSelectionChanged();
1812 // FIXME-3 VM needed? scene()->update();
1816 void VymModel::toggleHideExport()
1818 TreeItem *selti=getSelectedItem();
1820 setHideExport ( !selti->hideInExport() );
1824 void VymModel::copy()
1826 TreeItem *selti=getSelectedItem();
1828 (selti->getType() == TreeItem::Branch ||
1829 selti->getType() == TreeItem::MapCenter ||
1830 selti->getType() == TreeItem::Image ))
1832 if (redosAvail == 0)
1835 QString s=getSelectString(selti);
1836 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1837 curClipboard=curStep;
1840 // Copy also to global clipboard, because we are at last step in history
1841 QString bakMapName(QString("history-%1").arg(curStep));
1842 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1843 copyDir (bakMapDir,clipboardDir );
1845 clipboardEmpty=false;
1851 void VymModel::pasteNoSave(const int &n)
1853 bool old=blockSaveState;
1854 blockSaveState=true;
1855 bool zippedOrg=zipped;
1856 if (redosAvail > 0 || n!=0)
1858 // Use the "historical" buffer
1859 QString bakMapName(QString("history-%1").arg(n));
1860 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1861 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1863 // Use the global buffer
1864 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1869 void VymModel::paste()
1871 BranchItem *selbi=getSelectedBranchItem();
1874 saveStateChangingPart(
1877 QString ("paste (%1)").arg(curClipboard),
1878 QString("Paste to %1").arg( getObjectName(selbi))
1885 void VymModel::cut()
1887 TreeItem *selti=getSelectedItem();
1888 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1896 void VymModel::moveUp()
1898 BranchItem *selbi=getSelectedBranchItem();
1901 if (!selbi->canMoveUp()) return;
1902 QString oldsel=getSelectString();
1903 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1905 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1909 void VymModel::moveDown()
1911 BranchItem *selbi=getSelectedBranchItem();
1914 if (!selbi->canMoveDown()) return;
1915 QString oldsel=getSelectString();
1916 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1918 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1922 void VymModel::sortChildren() // FIXME-2 not implemented yet
1925 BranchObj* bo=getSelectedBranch();
1928 if(treeItem->branchCount()>1)
1930 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1933 emitShowSelection();
1939 BranchItem* VymModel::createMapCenter()
1941 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1945 BranchItem* VymModel::createBranch(BranchItem *dst)
1948 return addNewBranchInt (dst,-2);
1953 ImageItem* VymModel::createImage(BranchItem *dst)
1960 QList<QVariant> cData;
1961 cData << "new" << "undef"<<"undef";
1963 ImageItem *newii=new ImageItem(cData) ;
1964 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1966 emit (layoutAboutToBeChanged() );
1969 n=dst->getRowNumAppend(newii);
1970 beginInsertRows (parix,n,n+1);
1971 dst->appendChild (newii);
1974 emit (layoutChanged() );
1976 // save scroll state. If scrolled, automatically select
1977 // new branch in order to tmp unscroll parent...
1978 newii->createMapObj(mapScene);
1985 BranchItem* VymModel::addMapCenter ()
1987 BranchItem *bi=addMapCenter (contextPos);
1989 emitShowSelection();
1994 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
1995 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2000 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2001 // createMapCenter could then probably be merged with createBranch
2005 QModelIndex parix=index(rootItem);
2007 int n=rootItem->branchCount();
2009 emit (layoutAboutToBeChanged() );
2010 beginInsertRows (parix,n,n+1);
2012 QList<QVariant> cData;
2013 cData << "VM:addMapCenter" << "undef"<<"undef";
2014 BranchItem *newbi=new BranchItem (cData);
2015 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2016 rootItem->appendChild (newbi);
2019 emit (layoutChanged() );
2022 newbi->setPositionMode (MapItem::Absolute);
2023 newbi->createMapObj(mapScene);
2028 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2030 // Depending on pos:
2031 // -3 insert in children of parent above selection
2032 // -2 add branch to selection
2033 // -1 insert in children of parent below selection
2034 // 0..n insert in children of parent at pos
2037 QList<QVariant> cData;
2038 cData << "new" << "undef"<<"undef";
2043 BranchItem *newbi=new BranchItem (cData);
2044 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2046 emit (layoutAboutToBeChanged() );
2052 n=parbi->getRowNumAppend (newbi);
2053 beginInsertRows (parix,n,n+1);
2054 parbi->appendChild (newbi);
2056 }else if (num==-1 || num==-3)
2058 // insert below selection
2059 parbi=(BranchItem*)dst->parent();
2062 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2063 beginInsertRows (parix,n,n);
2064 parbi->insertBranch(n,newbi);
2067 emit (layoutChanged() );
2069 // save scroll state. If scrolled, automatically select
2070 // new branch in order to tmp unscroll parent...
2071 newbi->createMapObj(mapScene);
2076 BranchItem* VymModel::addNewBranch(int pos)
2078 // Different meaning than num in addNewBranchInt!
2082 BranchItem *newbi=NULL;
2083 BranchItem *selbi=getSelectedBranchItem();
2087 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2089 newbi=addNewBranchInt (selbi,pos-2);
2097 QString ("addBranch (%1)").arg(pos),
2098 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2101 // emitSelectionChanged(); FIXME-3
2102 latestAddedItem=newbi;
2103 // In Network mode, the client needs to know where the new branch is,
2104 // so we have to pass on this information via saveState.
2105 // TODO: Get rid of this positioning workaround
2106 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2107 sendData ("selectLatestAdded ()");
2108 sendData (QString("move %1").arg(ps));
2117 BranchItem* VymModel::addNewBranchBefore()
2119 BranchItem *newbi=NULL;
2120 BranchItem *selbi=getSelectedBranchItem();
2121 if (selbi && selbi->getType()==TreeItem::Branch)
2122 // We accept no MapCenter here, so we _have_ a parent
2124 //QPointF p=bo->getRelPos();
2127 // add below selection
2128 newbi=addNewBranchInt (selbi,-1);
2132 //newbi->move2RelPos (p);
2134 // Move selection to new branch
2135 relinkBranch (selbi,newbi,0);
2137 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2138 QString ("Add branch before %1").arg(getObjectName(selbi)));
2140 // FIXME-3 needed? reposition();
2141 // emitSelectionChanged(); FIXME-3
2147 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2151 if (branch->depth()==0)
2153 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2155 emit (layoutAboutToBeChanged() );
2156 BranchItem *branchpi=(BranchItem*)branch->parent();
2157 // Remove at current position
2158 int n=branch->childNum();
2159 beginRemoveRows (index(branchpi),n,n);
2160 branchpi->removeChild (n);
2163 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2165 // Append as last branch to dst
2166 if (dst->branchCount()==0)
2169 n=dst->getFirstBranch()->childNumber();
2170 beginInsertRows (index(dst),n+pos,n+pos);
2171 dst->insertBranch (pos,branch);
2174 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2175 branch->updateStyles();
2177 emit (layoutChanged() );
2178 reposition(); // both for moveUp/Down and relinking
2179 if (dst->isScrolled() )
2182 branch->updateVisibility();
2191 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2195 emit (layoutAboutToBeChanged() );
2197 BranchItem *pi=(BranchItem*)(image->parent());
2198 QString oldParString=getSelectString (pi);
2199 // Remove at current position
2200 int n=image->childNum();
2201 beginRemoveRows (index(pi),n,n);
2202 pi->removeChild (n);
2206 QModelIndex dstix=index(dst);
2207 n=dst->getRowNumAppend (image);
2208 beginInsertRows (dstix,n,n+1);
2209 dst->appendChild (image);
2212 // Set new parent also for lmo
2213 if (image->getLMO() && dst->getLMO() )
2214 image->getLMO()->setParObj (dst->getLMO() );
2216 emit (layoutChanged() );
2219 QString("relinkTo (\"%1\")").arg(oldParString),
2221 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2222 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2228 void VymModel::deleteSelection() // FIXME-2 include fix for deleted mapcenters from 1.12.4
2230 BranchItem *selbi=getSelectedBranchItem();
2232 if (selbi && selbi->isBranchLikeType() )
2235 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2237 TreeItem *pi=deleteItem (selbi);
2241 emitShowSelection();
2245 ImageItem *ii=getSelectedImageItem();
2248 BranchItem *pi=(BranchItem*)(ii->parent());
2249 saveStateChangingPart(
2253 QString("Delete %1").arg(getObjectName(ii))
2259 emitShowSelection();
2264 void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters
2267 BranchItem *selbi=getSelectedBranchItem();
2271 // Don't use this on mapcenter
2272 if (selbi->depth()<2) return;
2274 pi=(BranchItem*)(selbi->parent());
2275 // Check if we have childs at all to keep
2276 if (selbi->branchCount()==0)
2283 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2284 saveStateChangingPart(
2287 "deleteKeepChildren ()",
2288 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2291 QString sel=getSelectString(selbi);
2293 int pos=selbi->num();
2294 BranchItem *bi=selbi->getFirstBranch();
2297 relinkBranch (bi,pi,pos);
2298 bi=selbi->getFirstBranch();
2304 BranchObj *bo=getSelectedBranchObj();
2307 bo->move2RelPos (p);
2313 void VymModel::deleteChildren()
2316 BranchItem *selbi=getSelectedBranchItem();
2319 saveStateChangingPart(
2322 "deleteChildren ()",
2323 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2325 emit (layoutAboutToBeChanged() );
2327 QModelIndex ix=index (selbi);
2328 int n=selbi->branchCount()-1;
2329 beginRemoveRows (ix,0,n);
2330 removeRows (0,n+1,ix);
2332 if (selbi->isScrolled()) selbi->unScroll();
2333 emit (layoutChanged() );
2338 TreeItem* VymModel::deleteItem (TreeItem *ti)
2342 TreeItem *pi=ti->parent();
2343 QModelIndex parentIndex=index(pi);
2345 emit (layoutAboutToBeChanged() );
2347 int n=ti->childNum();
2348 beginRemoveRows (parentIndex,n,n);
2349 removeRows (n,1,parentIndex);
2353 emit (layoutChanged() );
2354 if (pi->depth()>0) return pi;
2359 bool VymModel::scrollBranch(BranchItem *bi)
2363 if (bi->isScrolled()) return false;
2364 if (bi->branchCount()==0) return false;
2365 if (bi->depth()==0) return false;
2366 if (bi->toggleScroll())
2373 QString ("%1 ()").arg(u),
2375 QString ("%1 ()").arg(r),
2376 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2378 emitDataHasChanged(bi);
2379 emitSelectionChanged();
2380 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2387 bool VymModel::unscrollBranch(BranchItem *bi)
2391 if (!bi->isScrolled()) return false;
2392 if (bi->branchCount()==0) return false;
2393 if (bi->depth()==0) return false;
2400 QString ("%1 ()").arg(u),
2402 QString ("%1 ()").arg(r),
2403 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2406 emitDataHasChanged(bi);
2407 emitSelectionChanged();
2409 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2415 void VymModel::toggleScroll()
2417 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2418 if (bi && bi->isBranchLikeType() )
2420 if (bi->isScrolled())
2421 unscrollBranch (bi);
2425 // saveState is called in above functions
2428 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2432 BranchObj *bo=getSelectedBranch();
2438 if (bo->isScrolled()) unscrollBranch (bo);
2445 void VymModel::emitExpandAll()
2447 emit (expandAll() );
2450 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2452 BranchItem *bi=getSelectedBranchItem();
2456 if (bi->isActiveStandardFlag(name))
2468 QString("%1 (\"%2\")").arg(u).arg(name),
2470 QString("%1 (\"%2\")").arg(r).arg(name),
2471 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2472 bi->toggleStandardFlag (name, master);
2474 emitSelectionChanged();
2478 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2481 BranchObj *bo=getSelectedBranch();
2484 FloatImageObj *fio=bo->addFloatImage();
2486 fio->setOriginalFilename("No original filename (image added by dropevent)");
2487 QString s=getSelectString(bo);
2488 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2489 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2491 // FIXME-3 VM needed? scene()->update();
2497 void VymModel::colorBranch (QColor c)
2499 BranchItem *selbi=getSelectedBranchItem();
2504 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2506 QString ("colorBranch (\"%1\")").arg(c.name()),
2507 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2509 selbi->setHeadingColor(c); // color branch
2513 void VymModel::colorSubtree (QColor c)
2515 BranchItem *selbi=getSelectedBranchItem();
2518 saveStateChangingPart(
2521 QString ("colorSubtree (\"%1\")").arg(c.name()),
2522 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2524 BranchItem *prev=NULL;
2525 BranchItem *cur=selbi;
2528 cur->setHeadingColor(c); // color links, color children
2529 cur=next (cur,prev,selbi);
2535 QColor VymModel::getCurrentHeadingColor()
2537 BranchItem *selbi=getSelectedBranchItem();
2538 if (selbi) return selbi->getHeadingColor();
2540 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2546 void VymModel::editURL()
2548 TreeItem *selti=getSelectedItem();
2552 QString text = QInputDialog::getText(
2553 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2554 selti->getURL(), &ok, NULL);
2556 // user entered something and pressed OK
2561 void VymModel::editLocalURL()
2563 TreeItem *selti=getSelectedItem();
2566 QStringList filters;
2567 filters <<"All files (*)";
2568 filters << tr("Text","Filedialog") + " (*.txt)";
2569 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2570 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2571 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2572 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2573 fd->setFilters (filters);
2574 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2575 fd->setDirectory (lastFileDir);
2576 if (! selti->getVymLink().isEmpty() )
2577 fd->selectFile( selti->getURL() );
2580 if ( fd->exec() == QDialog::Accepted )
2582 lastFileDir=QDir (fd->directory().path());
2583 setURL (fd->selectedFile() );
2589 void VymModel::editHeading2URL()
2591 TreeItem *selti=getSelectedItem();
2593 setURL (selti->getHeading());
2596 void VymModel::editBugzilla2URL()
2598 TreeItem *selti=getSelectedItem();
2601 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2606 void VymModel::editFATE2URL()
2608 TreeItem *selti=getSelectedItem();
2611 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2614 "setURL (\""+selti->getURL()+"\")",
2616 "setURL (\""+url+"\")",
2617 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2619 selti->setURL (url);
2620 // FIXME-4 updateActions();
2624 void VymModel::editVymLink()
2626 BranchItem *bi=getSelectedBranchItem();
2629 QStringList filters;
2630 filters <<"VYM map (*.vym)";
2631 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2632 fd->setFilters (filters);
2633 fd->setCaption(vymName+" - " +tr("Link to another map"));
2634 fd->setDirectory (lastFileDir);
2635 if (! bi->getVymLink().isEmpty() )
2636 fd->selectFile( bi->getVymLink() );
2640 if ( fd->exec() == QDialog::Accepted )
2642 lastFileDir=QDir (fd->directory().path());
2645 "setVymLink (\""+bi->getVymLink()+"\")",
2647 "setVymLink (\""+fd->selectedFile()+"\")",
2648 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2650 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2655 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2657 // Internal function, no saveState needed
2658 TreeItem *selti=getSelectedItem();
2661 selti->setVymLink(s);
2663 emitDataHasChanged (selti);
2664 emitShowSelection();
2668 void VymModel::deleteVymLink()
2670 BranchItem *bi=getSelectedBranchItem();
2675 "setVymLink (\""+bi->getVymLink()+"\")",
2677 "setVymLink (\"\")",
2678 QString("Unset vymlink of %1").arg(getObjectName(bi))
2680 bi->setVymLink ("" );
2686 QString VymModel::getVymLink()
2688 BranchItem *bi=getSelectedBranchItem();
2690 return bi->getVymLink();
2696 QStringList VymModel::getVymLinks()
2699 BranchItem *selbi=getSelectedBranchItem();
2700 BranchItem *cur=selbi;
2701 BranchItem *prev=NULL;
2704 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2705 cur=next (cur,prev,selbi);
2711 void VymModel::followXLink(int i) // FIXME-2
2715 BranchObj *bo=getSelectedBranch();
2718 bo=bo->XLinkTargetAt(i);
2721 selection.select(bo);
2722 emitShowSelection();
2728 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2732 BranchObj *bo=getSelectedBranch();
2735 XLinkObj *xlo=bo->XLinkAt(i);
2738 EditXLinkDialog dia;
2740 dia.setSelection(bo);
2741 if (dia.exec() == QDialog::Accepted)
2743 if (dia.useSettingsGlobal() )
2745 setMapDefXLinkColor (xlo->getColor() );
2746 setMapDefXLinkWidth (xlo->getWidth() );
2748 if (dia.deleteXLink())
2749 bo->deleteXLinkAt(i);
2760 //////////////////////////////////////////////
2762 //////////////////////////////////////////////
2764 void VymModel::parseAtom(const QString &atom)
2766 TreeItem* selti=getSelectedItem();
2767 BranchItem *selbi=getSelectedBranchItem();
2773 // Split string s into command and parameters
2774 parser.parseAtom (atom);
2775 QString com=parser.getCommand();
2777 // External commands
2778 /////////////////////////////////////////////////////////////////////
2779 if (com=="addBranch")
2783 parser.setError (Aborted,"Nothing selected");
2784 } else if (! selbi )
2786 parser.setError (Aborted,"Type of selection is not a branch");
2791 if (parser.checkParCount(pl))
2793 if (parser.parCount()==0)
2797 n=parser.parInt (ok,0);
2798 if (ok ) addNewBranch (n);
2802 /////////////////////////////////////////////////////////////////////
2803 } else if (com=="addBranchBefore")
2807 parser.setError (Aborted,"Nothing selected");
2808 } else if (! selbi )
2810 parser.setError (Aborted,"Type of selection is not a branch");
2813 if (parser.parCount()==0)
2815 addNewBranchBefore ();
2818 /////////////////////////////////////////////////////////////////////
2819 } else if (com==QString("addMapCenter"))
2821 if (parser.checkParCount(2))
2823 x=parser.parDouble (ok,0);
2826 y=parser.parDouble (ok,1);
2827 if (ok) addMapCenter (QPointF(x,y));
2830 /////////////////////////////////////////////////////////////////////
2831 } else if (com==QString("addMapReplace"))
2835 parser.setError (Aborted,"Nothing selected");
2836 } else if (! selbi )
2838 parser.setError (Aborted,"Type of selection is not a branch");
2839 } else if (parser.checkParCount(1))
2841 //s=parser.parString (ok,0); // selection
2842 t=parser.parString (ok,0); // path to map
2843 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2844 addMapReplaceInt(getSelectString(selbi),t);
2846 /////////////////////////////////////////////////////////////////////
2847 } else if (com==QString("addMapInsert"))
2851 parser.setError (Aborted,"Nothing selected");
2852 } else if (! selbi )
2854 parser.setError (Aborted,"Type of selection is not a branch");
2857 if (parser.checkParCount(2))
2859 t=parser.parString (ok,0); // path to map
2860 n=parser.parInt(ok,1); // position
2861 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2862 addMapInsertInt(t,n);
2865 /////////////////////////////////////////////////////////////////////
2866 } else if (com=="clearFlags")
2870 parser.setError (Aborted,"Nothing selected");
2871 } else if (! selbi )
2873 parser.setError (Aborted,"Type of selection is not a branch");
2874 } else if (parser.checkParCount(0))
2876 selbi->deactivateAllStandardFlags();
2878 /////////////////////////////////////////////////////////////////////
2879 } else if (com=="colorBranch")
2883 parser.setError (Aborted,"Nothing selected");
2884 } else if (! selbi )
2886 parser.setError (Aborted,"Type of selection is not a branch");
2887 } else if (parser.checkParCount(1))
2889 QColor c=parser.parColor (ok,0);
2890 if (ok) colorBranch (c);
2892 /////////////////////////////////////////////////////////////////////
2893 } else if (com=="colorSubtree")
2897 parser.setError (Aborted,"Nothing selected");
2898 } else if (! selbi )
2900 parser.setError (Aborted,"Type of selection is not a branch");
2901 } else if (parser.checkParCount(1))
2903 QColor c=parser.parColor (ok,0);
2904 if (ok) colorSubtree (c);
2906 /////////////////////////////////////////////////////////////////////
2907 } else if (com=="copy")
2911 parser.setError (Aborted,"Nothing selected");
2912 } else if ( selectionType()!=TreeItem::Branch &&
2913 selectionType()!=TreeItem::MapCenter &&
2914 selectionType()!=TreeItem::Image )
2916 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2917 } else if (parser.checkParCount(0))
2921 /////////////////////////////////////////////////////////////////////
2922 } else if (com=="cut")
2926 parser.setError (Aborted,"Nothing selected");
2927 } else if ( selectionType()!=TreeItem::Branch &&
2928 selectionType()!=TreeItem::MapCenter &&
2929 selectionType()!=TreeItem::Image )
2931 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2932 } else if (parser.checkParCount(0))
2936 /////////////////////////////////////////////////////////////////////
2937 } else if (com=="delete")
2941 parser.setError (Aborted,"Nothing selected");
2943 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2945 parser.setError (Aborted,"Type of selection is wrong.");
2948 else if (parser.checkParCount(0))
2952 /////////////////////////////////////////////////////////////////////
2953 } else if (com=="deleteKeepChildren")
2957 parser.setError (Aborted,"Nothing selected");
2958 } else if (! selbi )
2960 parser.setError (Aborted,"Type of selection is not a branch");
2961 } else if (parser.checkParCount(0))
2963 deleteKeepChildren();
2965 /////////////////////////////////////////////////////////////////////
2966 } else if (com=="deleteChildren")
2970 parser.setError (Aborted,"Nothing selected");
2973 parser.setError (Aborted,"Type of selection is not a branch");
2974 } else if (parser.checkParCount(0))
2978 /////////////////////////////////////////////////////////////////////
2979 } else if (com=="exportASCII")
2983 if (parser.parCount()>=1)
2984 // Hey, we even have a filename
2985 fname=parser.parString(ok,0);
2988 parser.setError (Aborted,"Could not read filename");
2991 exportASCII (fname,false);
2993 /////////////////////////////////////////////////////////////////////
2994 } else if (com=="exportImage")
2998 if (parser.parCount()>=2)
2999 // Hey, we even have a filename
3000 fname=parser.parString(ok,0);
3003 parser.setError (Aborted,"Could not read filename");
3006 QString format="PNG";
3007 if (parser.parCount()>=2)
3009 format=parser.parString(ok,1);
3011 exportImage (fname,false,format);
3013 /////////////////////////////////////////////////////////////////////
3014 } else if (com=="exportXHTML")
3018 if (parser.parCount()>=2)
3019 // Hey, we even have a filename
3020 fname=parser.parString(ok,1);
3023 parser.setError (Aborted,"Could not read filename");
3026 exportXHTML (fname,false);
3028 /////////////////////////////////////////////////////////////////////
3029 } else if (com=="exportXML")
3033 if (parser.parCount()>=2)
3034 // Hey, we even have a filename
3035 fname=parser.parString(ok,1);
3038 parser.setError (Aborted,"Could not read filename");
3041 exportXML (fname,false);
3043 /////////////////////////////////////////////////////////////////////
3044 } else if (com=="importDir")
3048 parser.setError (Aborted,"Nothing selected");
3049 } else if (! selbi )
3051 parser.setError (Aborted,"Type of selection is not a branch");
3052 } else if (parser.checkParCount(1))
3054 s=parser.parString(ok,0);
3055 if (ok) importDirInt(s);
3057 /////////////////////////////////////////////////////////////////////
3058 } else if (com=="relinkTo")
3062 parser.setError (Aborted,"Nothing selected");
3065 if (parser.checkParCount(4))
3067 // 0 selectstring of parent
3068 // 1 num in parent (for branches)
3069 // 2,3 x,y of mainbranch or mapcenter
3070 s=parser.parString(ok,0);
3071 TreeItem *dst=findBySelectString (s);
3074 if (dst->getType()==TreeItem::Branch)
3076 // Get number in parent
3077 n=parser.parInt (ok,1);
3080 relinkBranch (selbi,(BranchItem*)dst,n);
3081 emitSelectionChanged();
3083 } else if (dst->getType()==TreeItem::MapCenter)
3085 relinkBranch (selbi,(BranchItem*)dst);
3086 // Get coordinates of mainbranch
3087 x=parser.parDouble(ok,2);
3090 y=parser.parDouble(ok,3);
3093 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3094 emitSelectionChanged();
3100 } else if ( selti->getType() == TreeItem::Image)
3102 if (parser.checkParCount(1))
3104 // 0 selectstring of parent
3105 s=parser.parString(ok,0);
3106 TreeItem *dst=findBySelectString (s);
3109 if (dst->isBranchLikeType())
3110 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3112 parser.setError (Aborted,"Destination is not a branch");
3115 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3116 /////////////////////////////////////////////////////////////////////
3117 } else if (com=="loadImage")
3121 parser.setError (Aborted,"Nothing selected");
3122 } else if (! selbi )
3124 parser.setError (Aborted,"Type of selection is not a branch");
3125 } else if (parser.checkParCount(1))
3127 s=parser.parString(ok,0);
3128 if (ok) loadFloatImageInt (selbi,s);
3130 /////////////////////////////////////////////////////////////////////
3131 } else if (com=="moveUp")
3135 parser.setError (Aborted,"Nothing selected");
3136 } else if (! selbi )
3138 parser.setError (Aborted,"Type of selection is not a branch");
3139 } else if (parser.checkParCount(0))
3143 /////////////////////////////////////////////////////////////////////
3144 } else if (com=="moveDown")
3148 parser.setError (Aborted,"Nothing selected");
3149 } else if (! selbi )
3151 parser.setError (Aborted,"Type of selection is not a branch");
3152 } else if (parser.checkParCount(0))
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="move")
3161 parser.setError (Aborted,"Nothing selected");
3162 } else if ( selectionType()!=TreeItem::Branch &&
3163 selectionType()!=TreeItem::MapCenter &&
3164 selectionType()!=TreeItem::Image )
3166 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3167 } else if (parser.checkParCount(2))
3169 x=parser.parDouble (ok,0);
3172 y=parser.parDouble (ok,1);
3176 /////////////////////////////////////////////////////////////////////
3177 } else if (com=="moveRel")
3181 parser.setError (Aborted,"Nothing selected");
3182 } else if ( selectionType()!=TreeItem::Branch &&
3183 selectionType()!=TreeItem::MapCenter &&
3184 selectionType()!=TreeItem::Image )
3186 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3187 } else if (parser.checkParCount(2))
3189 x=parser.parDouble (ok,0);
3192 y=parser.parDouble (ok,1);
3193 if (ok) moveRel (x,y);
3196 /////////////////////////////////////////////////////////////////////
3197 } else if (com=="nop")
3199 /////////////////////////////////////////////////////////////////////
3200 } else if (com=="paste")
3204 parser.setError (Aborted,"Nothing selected");
3205 } else if (! selbi )
3207 parser.setError (Aborted,"Type of selection is not a branch");
3208 } else if (parser.checkParCount(1))
3210 n=parser.parInt (ok,0);
3211 if (ok) pasteNoSave(n);
3213 /////////////////////////////////////////////////////////////////////
3214 } else if (com=="qa")
3218 parser.setError (Aborted,"Nothing selected");
3219 } else if (! selbi )
3221 parser.setError (Aborted,"Type of selection is not a branch");
3222 } else if (parser.checkParCount(4))
3225 c=parser.parString (ok,0);
3228 parser.setError (Aborted,"No comment given");
3231 s=parser.parString (ok,1);
3234 parser.setError (Aborted,"First parameter is not a string");
3237 t=parser.parString (ok,2);
3240 parser.setError (Aborted,"Condition is not a string");
3243 u=parser.parString (ok,3);
3246 parser.setError (Aborted,"Third parameter is not a string");
3251 parser.setError (Aborted,"Unknown type: "+s);
3256 parser.setError (Aborted,"Unknown operator: "+t);
3261 parser.setError (Aborted,"Type of selection is not a branch");
3264 if (selbi->getHeading() == u)
3266 cout << "PASSED: " << qPrintable (c) << endl;
3269 cout << "FAILED: " << qPrintable (c) << endl;
3279 /////////////////////////////////////////////////////////////////////
3280 } else if (com=="saveImage")
3282 ImageItem *ii=getSelectedImageItem();
3285 parser.setError (Aborted,"No image selected");
3286 } else if (parser.checkParCount(2))
3288 s=parser.parString(ok,0);
3291 t=parser.parString(ok,1);
3292 if (ok) saveFloatImageInt (ii,t,s);
3295 /////////////////////////////////////////////////////////////////////
3296 } else if (com=="scroll")
3300 parser.setError (Aborted,"Nothing selected");
3301 } else if (! selbi )
3303 parser.setError (Aborted,"Type of selection is not a branch");
3304 } else if (parser.checkParCount(0))
3306 if (!scrollBranch (selbi))
3307 parser.setError (Aborted,"Could not scroll branch");
3309 /////////////////////////////////////////////////////////////////////
3310 } else if (com=="select")
3312 if (parser.checkParCount(1))
3314 s=parser.parString(ok,0);
3317 /////////////////////////////////////////////////////////////////////
3318 } else if (com=="selectLastBranch")
3322 parser.setError (Aborted,"Nothing selected");
3323 } else if (! selbi )
3325 parser.setError (Aborted,"Type of selection is not a branch");
3326 } else if (parser.checkParCount(0))
3328 BranchItem *bi=selbi->getLastBranch();
3330 parser.setError (Aborted,"Could not select last branch");
3331 select (bi); // FIXME-3 was selectInt
3334 /////////////////////////////////////////////////////////////////////
3335 } else /* FIXME-2 if (com=="selectLastImage")
3339 parser.setError (Aborted,"Nothing selected");
3340 } else if (! selbi )
3342 parser.setError (Aborted,"Type of selection is not a branch");
3343 } else if (parser.checkParCount(0))
3345 FloatImageObj *fio=selb->getLastFloatImage();
3347 parser.setError (Aborted,"Could not select last image");
3348 select (fio); // FIXME-3 was selectInt
3351 /////////////////////////////////////////////////////////////////////
3352 } else */ if (com=="selectLatestAdded")
3354 if (!latestAddedItem)
3356 parser.setError (Aborted,"No latest added object");
3359 if (!select (latestAddedItem))
3360 parser.setError (Aborted,"Could not select latest added object ");
3362 /////////////////////////////////////////////////////////////////////
3363 } else if (com=="setFrameType")
3365 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3367 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3369 else if (parser.checkParCount(1))
3371 s=parser.parString(ok,0);
3372 if (ok) setFrameType (s);
3374 /////////////////////////////////////////////////////////////////////
3375 } else if (com=="setFramePenColor")
3377 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3379 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3381 else if (parser.checkParCount(1))
3383 QColor c=parser.parColor(ok,0);
3384 if (ok) setFramePenColor (c);
3386 /////////////////////////////////////////////////////////////////////
3387 } else if (com=="setFrameBrushColor")
3389 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3391 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3393 else if (parser.checkParCount(1))
3395 QColor c=parser.parColor(ok,0);
3396 if (ok) setFrameBrushColor (c);
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="setFramePadding")
3401 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3403 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3405 else if (parser.checkParCount(1))
3407 n=parser.parInt(ok,0);
3408 if (ok) setFramePadding(n);
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="setFrameBorderWidth")
3413 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3415 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3417 else if (parser.checkParCount(1))
3419 n=parser.parInt(ok,0);
3420 if (ok) setFrameBorderWidth (n);
3422 /////////////////////////////////////////////////////////////////////
3423 } else if (com=="setMapAuthor")
3425 if (parser.checkParCount(1))
3427 s=parser.parString(ok,0);
3428 if (ok) setAuthor (s);
3430 /////////////////////////////////////////////////////////////////////
3431 } else if (com=="setMapComment")
3433 if (parser.checkParCount(1))
3435 s=parser.parString(ok,0);
3436 if (ok) setComment(s);
3438 /////////////////////////////////////////////////////////////////////
3439 } else if (com=="setMapBackgroundColor")
3443 parser.setError (Aborted,"Nothing selected");
3444 } else if (! selbi )
3446 parser.setError (Aborted,"Type of selection is not a branch");
3447 } else if (parser.checkParCount(1))
3449 QColor c=parser.parColor (ok,0);
3450 if (ok) setMapBackgroundColor (c);
3452 /////////////////////////////////////////////////////////////////////
3453 } else if (com=="setMapDefLinkColor")
3457 parser.setError (Aborted,"Nothing selected");
3458 } else if (! selbi )
3460 parser.setError (Aborted,"Type of selection is not a branch");
3461 } else if (parser.checkParCount(1))
3463 QColor c=parser.parColor (ok,0);
3464 if (ok) setMapDefLinkColor (c);
3466 /////////////////////////////////////////////////////////////////////
3467 } else if (com=="setMapLinkStyle")
3469 if (parser.checkParCount(1))
3471 s=parser.parString (ok,0);
3472 if (ok) setMapLinkStyle(s);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="setHeading")
3479 parser.setError (Aborted,"Nothing selected");
3480 } else if (! selbi )
3482 parser.setError (Aborted,"Type of selection is not a branch");
3483 } else if (parser.checkParCount(1))
3485 s=parser.parString (ok,0);
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="setHideExport")
3494 parser.setError (Aborted,"Nothing selected");
3495 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3497 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3498 } else if (parser.checkParCount(1))
3500 b=parser.parBool(ok,0);
3501 if (ok) setHideExport (b);
3503 /////////////////////////////////////////////////////////////////////
3504 } else if (com=="setIncludeImagesHorizontally")
3508 parser.setError (Aborted,"Nothing selected");
3511 parser.setError (Aborted,"Type of selection is not a branch");
3512 } else if (parser.checkParCount(1))
3514 b=parser.parBool(ok,0);
3515 if (ok) setIncludeImagesHor(b);
3517 /////////////////////////////////////////////////////////////////////
3518 } else if (com=="setIncludeImagesVertically")
3522 parser.setError (Aborted,"Nothing selected");
3525 parser.setError (Aborted,"Type of selection is not a branch");
3526 } else if (parser.checkParCount(1))
3528 b=parser.parBool(ok,0);
3529 if (ok) setIncludeImagesVer(b);
3531 /////////////////////////////////////////////////////////////////////
3532 } else if (com=="setHideLinkUnselected")
3536 parser.setError (Aborted,"Nothing selected");
3537 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3539 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3540 } else if (parser.checkParCount(1))
3542 b=parser.parBool(ok,0);
3543 if (ok) setHideLinkUnselected(b);
3545 /////////////////////////////////////////////////////////////////////
3546 } else if (com=="setSelectionColor")
3548 if (parser.checkParCount(1))
3550 QColor c=parser.parColor (ok,0);
3551 if (ok) setSelectionColorInt (c);
3553 /////////////////////////////////////////////////////////////////////
3554 } else if (com=="setURL")
3558 parser.setError (Aborted,"Nothing selected");
3559 } else if (! selbi )
3561 parser.setError (Aborted,"Type of selection is not a branch");
3562 } else if (parser.checkParCount(1))
3564 s=parser.parString (ok,0);
3567 /////////////////////////////////////////////////////////////////////
3568 } else if (com=="setVymLink")
3572 parser.setError (Aborted,"Nothing selected");
3573 } else if (! selbi )
3575 parser.setError (Aborted,"Type of selection is not a branch");
3576 } else if (parser.checkParCount(1))
3578 s=parser.parString (ok,0);
3579 if (ok) setVymLink(s);
3582 /////////////////////////////////////////////////////////////////////
3583 else if (com=="setFlag")
3587 parser.setError (Aborted,"Nothing selected");
3588 } else if (! selbi )
3590 parser.setError (Aborted,"Type of selection is not a branch");
3591 } else if (parser.checkParCount(1))
3593 s=parser.parString(ok,0);
3595 selbi->activateStandardFlag(s);
3597 /////////////////////////////////////////////////////////////////////
3598 } else /* FIXME-2 if (com=="setFrameType")
3602 parser.setError (Aborted,"Nothing selected");
3605 parser.setError (Aborted,"Type of selection is not a branch");
3606 } else if (parser.checkParCount(1))
3608 s=parser.parString(ok,0);
3612 /////////////////////////////////////////////////////////////////////
3613 } else*/ if (com=="sortChildren")
3617 parser.setError (Aborted,"Nothing selected");
3618 } else if (! selbi )
3620 parser.setError (Aborted,"Type of selection is not a branch");
3621 } else if (parser.checkParCount(0))
3625 /////////////////////////////////////////////////////////////////////
3626 } else if (com=="toggleFlag")
3630 parser.setError (Aborted,"Nothing selected");
3631 } else if (! selbi )
3633 parser.setError (Aborted,"Type of selection is not a branch");
3634 } else if (parser.checkParCount(1))
3636 s=parser.parString(ok,0);
3638 selbi->toggleStandardFlag(s);
3640 /////////////////////////////////////////////////////////////////////
3641 } else if (com=="unscroll")
3645 parser.setError (Aborted,"Nothing selected");
3646 } else if (! selbi )
3648 parser.setError (Aborted,"Type of selection is not a branch");
3649 } else if (parser.checkParCount(0))
3651 if (!unscrollBranch (selbi))
3652 parser.setError (Aborted,"Could not unscroll branch");
3654 /////////////////////////////////////////////////////////////////////
3655 } else if (com=="unscrollChildren")
3659 parser.setError (Aborted,"Nothing selected");
3660 } else if (! selbi )
3662 parser.setError (Aborted,"Type of selection is not a branch");
3663 } else if (parser.checkParCount(0))
3665 unscrollChildren ();
3667 /////////////////////////////////////////////////////////////////////
3668 } else if (com=="unsetFlag")
3672 parser.setError (Aborted,"Nothing selected");
3673 } else if (! selbi )
3675 parser.setError (Aborted,"Type of selection is not a branch");
3676 } else if (parser.checkParCount(1))
3678 s=parser.parString(ok,0);
3680 selbi->deactivateStandardFlag(s);
3683 parser.setError (Aborted,"Unknown command");
3686 if (parser.errorLevel()==NoError)
3688 // setChanged(); FIXME-2 should not be called e.g. for export?!
3693 // TODO Error handling
3694 qWarning("VymModel::parseAtom: Error!");
3695 qWarning(parser.errorMessage());
3699 void VymModel::runScript (QString script)
3701 parser.setScript (script);
3703 while (parser.next() )
3704 parseAtom(parser.getAtom());
3707 void VymModel::setExportMode (bool b)
3709 // should be called before and after exports
3710 // depending on the settings
3711 if (b && settings.value("/export/useHideExport","true")=="true")
3712 setHideTmpMode (TreeItem::HideExport);
3714 setHideTmpMode (TreeItem::HideNone);
3717 void VymModel::exportImage(QString fname, bool askName, QString format)
3719 /* FIXME-2 export as image, but directly from mapEditor?!
3722 fname=getMapName()+".png";
3729 QFileDialog *fd=new QFileDialog (NULL);
3730 fd->setCaption (tr("Export map as image"));
3731 fd->setDirectory (lastImageDir);
3732 fd->setFileMode(QFileDialog::AnyFile);
3733 fd->setFilters (imageIO.getFilters() );
3736 fl=fd->selectedFiles();
3738 format=imageIO.getType(fd->selectedFilter());
3742 setExportMode (true);
3743 QPixmap pix (mapEditor->getPixmap());
3744 pix.save(fname, format);
3745 setExportMode (false);
3750 void VymModel::exportXML(QString dir, bool askForName)
3754 dir=browseDirectory(NULL,tr("Export XML to directory"));
3755 if (dir =="" && !reallyWriteDirectory(dir) )
3759 // Hide stuff during export, if settings want this
3760 setExportMode (true);
3762 // Create subdirectories
3765 // write to directory //FIXME-4 check totalBBox here...
3766 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3769 file.setName ( dir + "/"+mapName+".xml");
3770 if ( !file.open( QIODevice::WriteOnly ) )
3772 // This should neverever happen
3773 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3777 // Write it finally, and write in UTF8, no matter what
3778 QTextStream ts( &file );
3779 ts.setEncoding (QTextStream::UnicodeUTF8);
3783 // Now write image, too
3784 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3786 setExportMode (false);
3789 void VymModel::exportASCII(QString fname,bool askName)
3794 ex.setFile (mapName+".txt");
3800 //ex.addFilter ("TXT (*.txt)");
3801 ex.setDir(lastImageDir);
3802 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3807 setExportMode(true);
3809 setExportMode(false);
3813 void VymModel::exportXHTML (const QString &dir, bool askForName)
3815 ExportXHTMLDialog dia(NULL);
3816 dia.setFilePath (filePath );
3817 dia.setMapName (mapName );
3819 if (dir!="") dia.setDir (dir);
3825 if (dia.exec()!=QDialog::Accepted)
3829 QDir d (dia.getDir());
3830 // Check, if warnings should be used before overwriting
3831 // the output directory
3832 if (d.exists() && d.count()>0)
3835 warn.showCancelButton (true);
3836 warn.setText(QString(
3837 "The directory %1 is not empty.\n"
3838 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3839 warn.setCaption("Warning: Directory not empty");
3840 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3842 if (warn.exec()!=QDialog::Accepted) ok=false;
3849 exportXML (dia.getDir(),false );
3850 dia.doExport(mapName );
3851 //if (dia.hasChanged()) setChanged();
3855 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3860 if (ex.setConfigFile(cf))
3862 setExportMode (true);
3863 ex.exportPresentation();
3864 setExportMode (false);
3871 //////////////////////////////////////////////
3873 //////////////////////////////////////////////
3875 void VymModel::registerEditor(QWidget *me)
3877 mapEditor=(MapEditor*)me;
3880 void VymModel::unregisterEditor(QWidget *)
3885 void VymModel::setContextPos(QPointF p)
3890 void VymModel::unsetContextPos()
3892 contextPos=QPointF();
3895 void VymModel::updateNoteFlag()
3898 TreeItem *selti=getSelectedItem();
3901 if (textEditor->isEmpty())
3904 selti->setNote (textEditor->getText());
3905 emitDataHasChanged(selti);
3906 emitSelectionChanged();
3911 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3914 for (int i=0; i<rootItem->branchCount(); i++)
3915 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3918 void MapCenterObj::updateRelPositions()
3920 if (repositionRequest) unsetAllRepositionRequests();
3922 // update relative Positions of branches and floats
3923 for (int i=0; i<treeItem->branchCount(); ++i)
3925 treeItem->getBranchObjNum(i)->setRelPos();
3926 treeItem->getBranchObjNum(i)->setOrientation();
3929 for (int i=0; i<floatimage.size(); ++i)
3930 floatimage.at(i)->setRelPos();
3932 if (repositionRequest) reposition();
3937 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3939 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3940 if (blockReposition) return;
3942 for (int i=0;i<rootItem->branchCount(); i++)
3943 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3947 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3949 return QPolygonF ();
3950 // Creating (arbitrary) shapes
3953 QRectF rb=bo->getBBox();
3954 if (bo->getDepth()==0)
3956 // Just take BBox of this mapCenter
3957 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3961 // Take union of BBox and TotalBBox
3963 QRectF ra=bo->getTotalBBox();
3964 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3967 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3970 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3972 p <<ra.bottomRight()
3974 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3977 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3983 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3987 // Move all branches and MapCenters away from lmo
3988 // to avoid collisions
3993 BranchObj *boA=(BranchObj*)lmo;
3995 for (int i=0; i<rootItem->branchCount(); i++)
3997 boB=rootItem->getBranchNum(i);
4000 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4003 <<" ("<<qPrintable(boA->getHeading() )<<")"
4004 <<" with ("<< qPrintable (boB->getHeading() )
4007 <<" minT="<<r.minTranslation<<endl<<endl;
4013 void VymModel::setMapLinkStyle (const QString & s)
4018 case LinkableMapObj::Line :
4021 case LinkableMapObj::Parabel:
4022 snow="StyleParabel";
4024 case LinkableMapObj::PolyLine:
4025 snow="StylePolyLine";
4027 case LinkableMapObj::PolyParabel:
4028 snow="StylePolyParabel";
4031 snow="UndefinedStyle";
4036 QString("setMapLinkStyle (\"%1\")").arg(s),
4037 QString("setMapLinkStyle (\"%1\")").arg(snow),
4038 QString("Set map link style (\"%1\")").arg(s)
4042 linkstyle=LinkableMapObj::Line;
4043 else if (s=="StyleParabel")
4044 linkstyle=LinkableMapObj::Parabel;
4045 else if (s=="StylePolyLine")
4046 linkstyle=LinkableMapObj::PolyLine;
4047 else if (s=="StylePolyParabel")
4048 linkstyle=LinkableMapObj::PolyParabel;
4050 linkstyle=LinkableMapObj::UndefinedStyle;
4052 BranchItem *cur=NULL;
4053 BranchItem *prev=NULL;
4058 bo=(BranchObj*)(cur->getLMO() );
4059 bo->setLinkStyle(bo->getDefLinkStyle());
4065 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4070 void VymModel::setMapDefLinkColor(QColor col)
4072 if ( !col.isValid() ) return;
4074 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4075 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4076 QString("Set map link color to %1").arg(col.name())
4080 BranchItem *cur=NULL;
4081 BranchItem *prev=NULL;
4086 bo=(BranchObj*)(cur->getLMO() );
4093 void VymModel::setMapLinkColorHintInt()
4095 // called from setMapLinkColorHint(lch) or at end of parse
4096 BranchItem *cur=NULL;
4097 BranchItem *prev=NULL;
4102 bo=(BranchObj*)(cur->getLMO() );
4108 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4111 setMapLinkColorHintInt();
4114 void VymModel::toggleMapLinkColorHint()
4116 if (linkcolorhint==LinkableMapObj::HeadingColor)
4117 linkcolorhint=LinkableMapObj::DefaultColor;
4119 linkcolorhint=LinkableMapObj::HeadingColor;
4120 BranchItem *cur=NULL;
4121 BranchItem *prev=NULL;
4126 bo=(BranchObj*)(cur->getLMO() );
4132 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4134 Q3FileDialog *fd=new Q3FileDialog( NULL);
4135 fd->setMode (Q3FileDialog::ExistingFile);
4136 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4137 ImagePreview *p =new ImagePreview (fd);
4138 fd->setContentsPreviewEnabled( TRUE );
4139 fd->setContentsPreview( p, p );
4140 fd->setPreviewMode( Q3FileDialog::Contents );
4141 fd->setCaption(vymName+" - " +tr("Load background image"));
4142 fd->setDir (lastImageDir);
4145 if ( fd->exec() == QDialog::Accepted )
4147 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4148 lastImageDir=QDir (fd->dirPath());
4149 setMapBackgroundImage (fd->selectedFile());
4153 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate, move to ME
4155 QColor oldcol=mapScene->backgroundBrush().color();
4159 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4161 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4162 QString("Set background color of map to %1").arg(col.name()));
4165 brush.setTextureImage (QPixmap (fn));
4166 mapScene->setBackgroundBrush(brush);
4169 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4171 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4172 if ( !col.isValid() ) return;
4173 setMapBackgroundColor( col );
4177 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4179 QColor oldcol=mapScene->backgroundBrush().color();
4181 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4182 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4183 QString("Set background color of map to %1").arg(col.name()));
4184 mapScene->setBackgroundBrush(col);
4187 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4189 return mapScene->backgroundBrush().color();
4193 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4195 return linkcolorhint;
4198 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4200 return defLinkColor;
4203 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4208 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4210 return defXLinkColor;
4213 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4218 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4220 return defXLinkWidth;
4223 void VymModel::move(const double &x, const double &y) // FIXME-3
4227 BranchObj *bo = getSelectedBranch();
4229 (selectionType()==TreeItem::Branch ||
4230 selectionType()==TreeItem::MapCenter ||
4231 selectionType()==TreeItem::Image
4234 QPointF ap(bo->getAbsPos());
4238 QString ps=qpointfToString(ap);
4239 QString s=getSelectString();
4242 s, "move "+qpointfToString(to),
4243 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4246 emitSelectionChanged();
4252 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4256 BranchObj *bo = getSelectedBranch();
4258 (selectionType()==TreeItem::Branch ||
4259 selectionType()==TreeItem::MapCenter ||
4260 selectionType()==TreeItem::Image
4264 QPointF rp(bo->getRelPos());
4268 QString ps=qpointfToString (bo->getRelPos());
4269 QString s=getSelectString(bo);
4272 s, "moveRel "+qpointfToString(to),
4273 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4274 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4276 bo->updateLinkGeometry();
4277 emitSelectionChanged();
4284 void VymModel::animate()
4286 animationTimer->stop();
4289 while (i<animObjList.size() )
4291 bo=(BranchObj*)animObjList.at(i);
4296 animObjList.removeAt(i);
4303 QItemSelection sel=selModel->selection();
4304 emit (selectionChanged(sel,sel));
4307 if (!animObjList.isEmpty()) animationTimer->start();
4311 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4313 if (bo && bo->getTreeItem()->depth()>0)
4316 ap.setStart (start);
4318 ap.setTicks (animationTicks);
4319 ap.setAnimated (true);
4320 bo->setAnimation (ap);
4321 animObjList.append( bo );
4322 animationTimer->setSingleShot (true);
4323 animationTimer->start(animationInterval);
4327 void VymModel::stopAnimation (MapObj *mo)
4329 int i=animObjList.indexOf(mo);
4331 animObjList.removeAt (i);
4334 void VymModel::sendSelection()
4336 if (netstate!=Server) return;
4337 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4340 void VymModel::newServer()
4344 tcpServer = new QTcpServer(this);
4345 if (!tcpServer->listen(QHostAddress::Any,port)) {
4346 QMessageBox::critical(NULL, "vym server",
4347 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4348 //FIXME-3 needed? we are no widget any longer... close();
4351 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4353 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4356 void VymModel::connectToServer()
4359 server="salam.suse.de";
4361 clientSocket = new QTcpSocket (this);
4362 clientSocket->abort();
4363 clientSocket->connectToHost(server ,port);
4364 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4365 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4366 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4368 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4373 void VymModel::newClient()
4375 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4376 connect(newClient, SIGNAL(disconnected()),
4377 newClient, SLOT(deleteLater()));
4379 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4381 clientList.append (newClient);
4385 void VymModel::sendData(const QString &s)
4387 if (clientList.size()==0) return;
4389 // Create bytearray to send
4391 QDataStream out(&block, QIODevice::WriteOnly);
4392 out.setVersion(QDataStream::Qt_4_0);
4394 // Reserve some space for blocksize
4397 // Write sendCounter
4398 out << sendCounter++;
4403 // Go back and write blocksize so far
4404 out.device()->seek(0);
4405 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4409 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4411 for (int i=0; i<clientList.size(); ++i)
4413 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4414 clientList.at(i)->write (block);
4418 void VymModel::readData ()
4420 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4423 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4427 QDataStream in(clientSocket);
4428 in.setVersion(QDataStream::Qt_4_0);
4436 cout << " t="<<qPrintable (t)<<endl;
4442 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4444 switch (socketError) {
4445 case QAbstractSocket::RemoteHostClosedError:
4447 case QAbstractSocket::HostNotFoundError:
4448 QMessageBox::information(NULL, vymName +" Network client",
4449 "The host was not found. Please check the "
4450 "host name and port settings.");
4452 case QAbstractSocket::ConnectionRefusedError:
4453 QMessageBox::information(NULL, vymName + " Network client",
4454 "The connection was refused by the peer. "
4455 "Make sure the fortune server is running, "
4456 "and check that the host name and port "
4457 "settings are correct.");
4460 QMessageBox::information(NULL, vymName + " Network client",
4461 QString("The following error occurred: %1.")
4462 .arg(clientSocket->errorString()));
4466 /* FIXME-3 Playing with DBUS...
4467 QDBusVariant VymModel::query (const QString &query)
4469 TreeItem *selti=getSelectedItem();
4471 return QDBusVariant (selti->getHeading());
4473 return QDBusVariant ("Nothing selected.");
4477 void VymModel::testslot() //FIXME-3
4479 cout << "VM::testslot called\n";
4482 void VymModel::selectMapSelectionColor()
4484 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4485 setSelectionColor (col);
4488 void VymModel::setSelectionColorInt (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())
4497 mapEditor->setSelectionColor (col);
4501 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4503 cout << "VymModel::changeSelection (";
4504 if (!newsel.indexes().isEmpty() )
4505 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4507 if (!oldsel.indexes().isEmpty() )
4508 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4513 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4517 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4519 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4520 emitShowSelection();
4524 void VymModel::emitSelectionChanged()
4526 QItemSelection newsel=selModel->selection();
4527 emitSelectionChanged (newsel);
4530 void VymModel::setSelectionColor(QColor col)
4532 if ( !col.isValid() ) return;
4534 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4535 QString("setSelectionColor (%1)").arg(col.name()),
4536 QString("Set color of selection box to %1").arg(col.name())
4538 setSelectionColorInt (col);
4541 QColor VymModel::getSelectionColor()
4543 return mapEditor->getSelectionColor();
4546 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4549 for (int i=0;i<rootItem->childCount();i++)
4550 rootItem->child(i)->setHideTmp (mode);
4552 // FIXME-3 needed? scene()->update();
4555 //////////////////////////////////////////////
4556 // Selection related
4557 //////////////////////////////////////////////
4559 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4564 QItemSelectionModel* VymModel::getSelectionModel()
4569 void VymModel::setSelectionBlocked (bool b)
4574 bool VymModel::isSelectionBlocked()
4576 return selectionBlocked;
4579 bool VymModel::select ()
4581 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4584 bool VymModel::select (const QString &s)
4586 TreeItem *ti=findBySelectString(s);
4596 bool VymModel::select (LinkableMapObj *lmo)
4598 QItemSelection oldsel=selModel->selection();
4601 return select (lmo->getTreeItem() );
4606 bool VymModel::select (TreeItem *ti)
4608 if (ti) return select (index(ti));
4612 bool VymModel::select (const QModelIndex &index)
4614 if (index.isValid() )
4616 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4617 getSelectedItem()->setLastSelectedBranch();
4623 void VymModel::unselect()
4625 lastSelectString=getSelectString();
4626 selModel->clearSelection();
4629 void VymModel::reselect()
4631 select (lastSelectString);
4634 void VymModel::emitShowSelection()
4636 if (!blockReposition)
4637 emit (showSelection() );
4640 void VymModel::emitNoteHasChanged (TreeItem *ti)
4642 QModelIndex ix=index(ti);
4643 emit (noteHasChanged (ix) );
4646 void VymModel::emitDataHasChanged (TreeItem *ti)
4648 QModelIndex ix=index(ti);
4649 emit (dataChanged (ix,ix) );
4653 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4656 if (selection.select(lmo))
4658 //emitSelectionChanged();
4662 void VymModel::selectInt (TreeItem *ti)
4664 if (selection.select(lmo))
4666 //emitSelectionChanged();
4671 void VymModel::selectNextBranchInt()
4673 BranchItem *bi=getSelectedBranchItem();
4676 TreeItem *pi=bi->parent();
4680 if (i<pi->branchCount() )
4682 // select previous branch with same parent
4684 select (pi->getBranchNum(i));
4692 void VymModel::selectPrevBranchInt()
4695 BranchItem *bi=getSelectedBranchItem();
4698 BranchItem *pi=(BranchItem*)bi->parent();
4704 // select previous branch with same parent
4705 bi=pi->getBranchNum(i-1);
4710 while (bi->branchCount() >0)
4711 bi=bi->getLastBranch();
4714 // Try to select last branch in parent pi2 previous to own parent pi
4716 TreeItem *pi2=pi->parent();
4727 void VymModel::selectAboveBranchInt()
4729 BranchItem *bi=getSelectedBranchItem();
4732 BranchItem *newbi=NULL;
4733 BranchItem *pi=(BranchItem*)bi->parent();
4737 // goto previous branch with same parent
4738 newbi=pi->getBranchNum(i-1);
4739 while (newbi->branchCount() >0 )
4740 newbi=newbi->getLastBranch();
4744 if (newbi==rootItem)
4745 // already at top branch (resp. mapcenter)
4751 void VymModel::selectBelowBranchInt()
4753 BranchItem *bi=getSelectedBranchItem();
4756 BranchItem *newbi=NULL;
4758 if (bi->branchCount() >0)
4759 newbi=bi->getFirstBranch();
4766 pi=(BranchItem*)bi->parent();
4768 if (pi->branchCount()-1 > i)
4770 newbi=(BranchItem*)pi->getBranchNum(i+1);
4775 // look for siblings of myself
4776 // or parent, or parent of parent...
4787 void VymModel::selectUpperBranch()
4789 BranchItem *bi=getSelectedBranchItem();
4790 if (bi && bi->isBranchLikeType())
4791 selectAboveBranchInt();
4794 void VymModel::selectLowerBranch()
4796 BranchItem *bi=getSelectedBranchItem();
4797 if (bi && bi->isBranchLikeType())
4798 selectBelowBranchInt();
4802 void VymModel::selectLeftBranch()
4804 QItemSelection oldsel=selModel->selection();
4807 BranchItem *selbi=getSelectedBranchItem();
4808 TreeItem::Type type=selbi->getType();
4811 if (type == TreeItem::MapCenter)
4813 QModelIndex ix=index(selbi);
4814 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4817 par=(BranchItem*)selbi->parent();
4818 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4821 if (type == TreeItem::Branch ||
4822 type == TreeItem::Image)
4824 QModelIndex ix=index (selbi->parent());
4825 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4830 if (type == TreeItem::Branch )
4832 selectLastSelectedBranch();
4840 void VymModel::selectRightBranch()
4842 QItemSelection oldsel=selModel->selection();
4845 BranchItem *selbi=getSelectedBranchItem();
4846 TreeItem::Type type=selbi->getType();
4849 if (type==TreeItem::MapCenter)
4851 QModelIndex ix=index(selbi);
4852 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4855 par=(BranchItem*)selbi->parent();
4856 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4859 if ( type== TreeItem::Branch )
4861 selectLastSelectedBranch();
4867 if (type == TreeItem::Branch ||
4868 type == TreeItem::Image)
4870 QModelIndex ix=index(selbi->parent());
4871 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4878 void VymModel::selectFirstBranch()
4880 TreeItem *ti=getSelectedBranchItem();
4883 TreeItem *par=ti->parent();
4885 TreeItem *ti2=par->getFirstBranch();
4888 emitSelectionChanged();
4893 void VymModel::selectLastBranch()
4895 TreeItem *ti=getSelectedBranchItem();
4898 TreeItem *par=ti->parent();
4900 TreeItem *ti2=par->getLastBranch();
4903 emitSelectionChanged();
4908 void VymModel::selectLastSelectedBranch()
4910 TreeItem *ti=getSelectedBranchItem();
4913 ti=ti->getLastSelectedBranch();
4914 if (ti) select (ti);
4918 void VymModel::selectParent()
4920 TreeItem *ti=getSelectedItem();
4927 emitSelectionChanged();
4931 TreeItem::Type VymModel::selectionType()
4933 QModelIndexList list=selModel->selectedIndexes();
4934 if (list.isEmpty()) return TreeItem::Undefined;
4935 TreeItem *ti = getItem (list.first() );
4936 return ti->getType();
4940 LinkableMapObj* VymModel::getSelectedLMO()
4942 QModelIndexList list=selModel->selectedIndexes();
4943 if (!list.isEmpty() )
4945 TreeItem *ti = getItem (list.first() );
4946 TreeItem::Type type=ti->getType();
4947 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4948 return ((MapItem*)ti)->getLMO();
4953 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4955 TreeItem *ti = getSelectedBranchItem();
4957 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4962 BranchItem* VymModel::getSelectedBranchItem()
4964 QModelIndexList list=selModel->selectedIndexes();
4965 if (!list.isEmpty() )
4967 TreeItem *ti = getItem (list.first() );
4968 TreeItem::Type type=ti->getType();
4969 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4970 return (BranchItem*)ti;
4975 TreeItem* VymModel::getSelectedItem()
4977 QModelIndexList list=selModel->selectedIndexes();
4978 if (!list.isEmpty() )
4979 return getItem (list.first() );
4984 QModelIndex VymModel::getSelectedIndex()
4986 QModelIndexList list=selModel->selectedIndexes();
4987 if (list.isEmpty() )
4988 return QModelIndex();
4990 return list.first();
4993 ImageItem* VymModel::getSelectedImageItem()
4995 QModelIndexList list=selModel->selectedIndexes();
4996 if (!list.isEmpty())
4998 TreeItem *ti=getItem (list.first());
4999 if (ti && ti->getType()==TreeItem::Image)
5000 return (ImageItem*)ti;
5005 QString VymModel::getSelectString ()
5007 return getSelectString (getSelectedItem());
5010 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5012 if (!lmo) return QString();
5013 return getSelectString (lmo->getTreeItem() );
5016 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
5020 switch (ti->getType())
5022 case TreeItem::MapCenter: s="mc:"; break;
5023 case TreeItem::Branch: s="bo:";break;
5024 case TreeItem::Image: s="fi:";break;
5027 s= s + QString("%1").arg(ti->num());
5029 // call myself recursively
5030 s= getSelectString(ti->parent()) +","+s;