Empty branches are always unscrolled after import, relinking to scrolled branch doesn't open branch, starting DBUS implementation
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 //new CarAdaptor(car);
155 //connection.registerObject("/Car", car);
156 dbusConnection.registerService("org.insilmaril.vym");
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-2 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?
1502 emitSelectionChanged();
1506 BranchItem* VymModel::findText (QString s, bool cs)
1508 QTextDocument::FindFlags flags=0;
1509 if (cs) flags=QTextDocument::FindCaseSensitively;
1512 { // Nothing found or new find process
1514 // nothing found, start again
1518 next (findCurrent,findPrevious);
1520 bool searching=true;
1521 bool foundNote=false;
1522 while (searching && !EOFind)
1526 // Searching in Note
1527 if (findCurrent->getNote().contains(s,cs))
1529 select (findCurrent);
1531 if (getSelectedBranch()!=itFind)
1534 emitShowSelection();
1537 if (textEditor->findText(s,flags))
1543 // Searching in Heading
1544 if (searching && findCurrent->getHeading().contains (s,cs) )
1546 select(findCurrent);
1552 if (!next(findCurrent,findPrevious) )
1555 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1558 return getSelectedBranchItem();
1563 void VymModel::findReset()
1564 { // Necessary if text to find changes during a find process
1570 void VymModel::setScene (QGraphicsScene *s)
1572 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1573 //init(); // Here we have a mapScene set,
1574 // which is (still) needed to create MapCenters
1577 void VymModel::setURL(const QString &url)
1579 TreeItem *selti=getSelectedItem();
1582 QString oldurl=selti->getURL();
1583 selti->setURL (url);
1586 QString ("setURL (\"%1\")").arg(oldurl),
1588 QString ("setURL (\"%1\")").arg(url),
1589 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1592 emitDataHasChanged (selti);
1593 emitShowSelection();
1597 QString VymModel::getURL()
1599 TreeItem *selti=getSelectedItem();
1601 return selti->getURL();
1606 QStringList VymModel::getURLs()
1609 BranchItem *selbi=getSelectedBranchItem();
1610 BranchItem *cur=selbi;
1611 BranchItem *prev=NULL;
1614 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1615 cur=next (cur,prev,selbi);
1621 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1623 BranchItem *bi=getSelectedBranchItem();
1626 BranchObj *bo=(BranchObj*)(bi->getLMO());
1629 QString s=bo->getFrameTypeName();
1630 bo->setFrameType (t);
1631 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1632 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1634 bo->updateLinkGeometry();
1639 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1641 BranchItem *bi=getSelectedBranchItem();
1644 BranchObj *bo=(BranchObj*)(bi->getLMO());
1647 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1648 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1649 bo->setFrameType (s);
1651 bo->updateLinkGeometry();
1656 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1659 BranchItem *bi=getSelectedBranchItem();
1662 BranchObj *bo=(BranchObj*)(bi->getLMO());
1665 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1666 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1667 bo->setFramePenColor (c);
1672 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1674 BranchItem *bi=getSelectedBranchItem();
1677 BranchObj *bo=(BranchObj*)(bi->getLMO());
1680 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1681 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1682 bo->setFrameBrushColor (c);
1687 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1689 BranchItem *bi=getSelectedBranchItem();
1692 BranchObj *bo=(BranchObj*)(bi->getLMO());
1695 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1696 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1697 bo->setFramePadding (i);
1699 bo->updateLinkGeometry();
1704 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1706 BranchItem *bi=getSelectedBranchItem();
1709 BranchObj *bo=(BranchObj*)(bi->getLMO());
1712 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1713 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1714 bo->setFrameBorderWidth (i);
1716 bo->updateLinkGeometry();
1721 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1724 BranchItem *bi=getSelectedBranchItem();
1727 BranchObj *bo=bi->getLMO();
1730 QString u= b ? "false" : "true";
1731 QString r=!b ? "false" : "true";
1735 QString("setIncludeImagesVertically (%1)").arg(u),
1737 QString("setIncludeImagesVertically (%1)").arg(r),
1738 QString("Include images vertically in %1").arg(getObjectName(bo))
1740 bo->setIncludeImagesVer(b);
1746 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1749 TreeItem *bi=getSelectedBranchItem();
1752 BranchObj *bo=bi->getLMO();
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(bo))
1765 bo->setIncludeImagesHor(b);
1772 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1774 TreeItem *ti=getSelectedItem();
1775 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1777 QString u= b ? "false" : "true";
1778 QString r=!b ? "false" : "true";
1782 QString("setHideLinkUnselected (%1)").arg(u),
1784 QString("setHideLinkUnselected (%1)").arg(r),
1785 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1787 ((MapItem*)ti)->setHideLinkUnselected(b);
1791 void VymModel::setHideExport(bool b)
1793 TreeItem *ti=getSelectedItem();
1795 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1797 ti->setHideInExport (b);
1798 QString u= b ? "false" : "true";
1799 QString r=!b ? "false" : "true";
1803 QString ("setHideExport (%1)").arg(u),
1805 QString ("setHideExport (%1)").arg(r),
1806 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1808 emitDataHasChanged(ti);
1809 emitSelectionChanged();
1812 // emitSelectionChanged();
1813 // FIXME-3 VM needed? scene()->update();
1817 void VymModel::toggleHideExport()
1819 TreeItem *selti=getSelectedItem();
1821 setHideExport ( !selti->hideInExport() );
1825 void VymModel::copy()
1827 TreeItem *selti=getSelectedItem();
1829 (selti->getType() == TreeItem::Branch ||
1830 selti->getType() == TreeItem::MapCenter ||
1831 selti->getType() == TreeItem::Image ))
1833 if (redosAvail == 0)
1836 QString s=getSelectString(selti);
1837 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1838 curClipboard=curStep;
1841 // Copy also to global clipboard, because we are at last step in history
1842 QString bakMapName(QString("history-%1").arg(curStep));
1843 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1844 copyDir (bakMapDir,clipboardDir );
1846 clipboardEmpty=false;
1852 void VymModel::pasteNoSave(const int &n)
1854 bool old=blockSaveState;
1855 blockSaveState=true;
1856 bool zippedOrg=zipped;
1857 if (redosAvail > 0 || n!=0)
1859 // Use the "historical" buffer
1860 QString bakMapName(QString("history-%1").arg(n));
1861 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1862 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1864 // Use the global buffer
1865 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1870 void VymModel::paste()
1872 BranchItem *selbi=getSelectedBranchItem();
1875 saveStateChangingPart(
1878 QString ("paste (%1)").arg(curClipboard),
1879 QString("Paste to %1").arg( getObjectName(selbi))
1886 void VymModel::cut()
1888 TreeItem *selti=getSelectedItem();
1889 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1897 void VymModel::moveUp()
1899 BranchItem *selbi=getSelectedBranchItem();
1902 if (!selbi->canMoveUp()) return;
1903 QString oldsel=getSelectString();
1904 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1906 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1910 void VymModel::moveDown()
1912 BranchItem *selbi=getSelectedBranchItem();
1915 if (!selbi->canMoveDown()) return;
1916 QString oldsel=getSelectString();
1917 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1919 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1923 void VymModel::sortChildren() // FIXME-2 not implemented yet
1926 BranchObj* bo=getSelectedBranch();
1929 if(treeItem->branchCount()>1)
1931 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1934 emitShowSelection();
1940 BranchItem* VymModel::createMapCenter()
1942 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1946 BranchItem* VymModel::createBranch(BranchItem *dst)
1949 return addNewBranchInt (dst,-2);
1954 ImageItem* VymModel::createImage(BranchItem *dst)
1961 QList<QVariant> cData;
1962 cData << "new" << "undef"<<"undef";
1964 ImageItem *newii=new ImageItem(cData) ;
1965 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1967 emit (layoutAboutToBeChanged() );
1970 n=dst->getRowNumAppend(newii);
1971 beginInsertRows (parix,n,n+1);
1972 dst->appendChild (newii);
1975 emit (layoutChanged() );
1977 // save scroll state. If scrolled, automatically select
1978 // new branch in order to tmp unscroll parent...
1979 newii->createMapObj(mapScene);
1986 BranchItem* VymModel::addMapCenter ()
1988 BranchItem *bi=addMapCenter (contextPos);
1990 emitShowSelection();
1995 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
1996 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2001 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2002 // createMapCenter could then probably be merged with createBranch
2006 QModelIndex parix=index(rootItem);
2008 int n=rootItem->branchCount();
2010 emit (layoutAboutToBeChanged() );
2011 beginInsertRows (parix,n,n+1);
2013 QList<QVariant> cData;
2014 cData << "VM:addMapCenter" << "undef"<<"undef";
2015 BranchItem *newbi=new BranchItem (cData);
2016 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2017 rootItem->appendChild (newbi);
2020 emit (layoutChanged() );
2023 newbi->setPositionMode (MapItem::Absolute);
2024 newbi->createMapObj(mapScene);
2029 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2031 // Depending on pos:
2032 // -3 insert in children of parent above selection
2033 // -2 add branch to selection
2034 // -1 insert in children of parent below selection
2035 // 0..n insert in children of parent at pos
2038 QList<QVariant> cData;
2039 cData << "new" << "undef"<<"undef";
2044 BranchItem *newbi=new BranchItem (cData);
2045 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2047 emit (layoutAboutToBeChanged() );
2053 n=parbi->getRowNumAppend (newbi);
2054 beginInsertRows (parix,n,n+1);
2055 parbi->appendChild (newbi);
2057 }else if (num==-1 || num==-3)
2059 // insert below selection
2060 parbi=(BranchItem*)dst->parent();
2063 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2064 beginInsertRows (parix,n,n);
2065 parbi->insertBranch(n,newbi);
2068 emit (layoutChanged() );
2070 // save scroll state. If scrolled, automatically select
2071 // new branch in order to tmp unscroll parent...
2072 newbi->createMapObj(mapScene);
2077 BranchItem* VymModel::addNewBranch(int pos)
2079 // Different meaning than num in addNewBranchInt!
2083 BranchItem *newbi=NULL;
2084 BranchItem *selbi=getSelectedBranchItem();
2088 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2090 newbi=addNewBranchInt (selbi,pos-2);
2098 QString ("addBranch (%1)").arg(pos),
2099 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2102 // emitSelectionChanged(); FIXME-3
2103 latestAddedItem=newbi;
2104 // In Network mode, the client needs to know where the new branch is,
2105 // so we have to pass on this information via saveState.
2106 // TODO: Get rid of this positioning workaround
2107 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2108 sendData ("selectLatestAdded ()");
2109 sendData (QString("move %1").arg(ps));
2118 BranchItem* VymModel::addNewBranchBefore()
2120 BranchItem *newbi=NULL;
2121 BranchItem *selbi=getSelectedBranchItem();
2122 if (selbi && selbi->getType()==TreeItem::Branch)
2123 // We accept no MapCenter here, so we _have_ a parent
2125 //QPointF p=bo->getRelPos();
2128 // add below selection
2129 newbi=addNewBranchInt (selbi,-1);
2133 //newbi->move2RelPos (p);
2135 // Move selection to new branch
2136 relinkBranch (selbi,newbi,0);
2138 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2139 QString ("Add branch before %1").arg(getObjectName(selbi)));
2141 // FIXME-3 needed? reposition();
2142 // emitSelectionChanged(); FIXME-3
2148 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2152 if (branch->depth()==0)
2154 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2156 emit (layoutAboutToBeChanged() );
2157 BranchItem *branchpi=(BranchItem*)branch->parent();
2158 // Remove at current position
2159 int n=branch->childNum();
2160 beginRemoveRows (index(branchpi),n,n);
2161 branchpi->removeChild (n);
2164 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2166 // Append as last branch to dst
2167 if (dst->branchCount()==0)
2170 n=dst->getFirstBranch()->childNumber();
2171 beginInsertRows (index(dst),n+pos,n+pos);
2172 dst->insertBranch (pos,branch);
2175 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2176 branch->updateStyles();
2178 emit (layoutChanged() );
2179 reposition(); // both for moveUp/Down and relinking
2180 if (dst->isScrolled() )
2183 branch->updateVisibility();
2192 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2196 emit (layoutAboutToBeChanged() );
2198 BranchItem *pi=(BranchItem*)(image->parent());
2199 QString oldParString=getSelectString (pi);
2200 // Remove at current position
2201 int n=image->childNum();
2202 beginRemoveRows (index(pi),n,n);
2203 pi->removeChild (n);
2207 QModelIndex dstix=index(dst);
2208 n=dst->getRowNumAppend (image);
2209 beginInsertRows (dstix,n,n+1);
2210 dst->appendChild (image);
2213 // Set new parent also for lmo
2214 if (image->getLMO() && dst->getLMO() )
2215 image->getLMO()->setParObj (dst->getLMO() );
2217 emit (layoutChanged() );
2220 QString("relinkTo (\"%1\")").arg(oldParString),
2222 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2223 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2229 void VymModel::deleteSelection()
2231 BranchItem *selbi=getSelectedBranchItem();
2233 if (selbi && selbi->isBranchLikeType() )
2236 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2238 TreeItem *pi=deleteItem (selbi);
2242 emitShowSelection();
2246 ImageItem *ii=getSelectedImageItem();
2249 BranchItem *pi=(BranchItem*)(ii->parent());
2250 saveStateChangingPart(
2254 QString("Delete %1").arg(getObjectName(ii))
2260 emitShowSelection();
2265 void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters
2268 BranchItem *selbi=getSelectedBranchItem();
2272 // Don't use this on mapcenter
2273 if (selbi->depth()<2) return;
2275 pi=(BranchItem*)(selbi->parent());
2276 // Check if we have childs at all to keep
2277 if (selbi->branchCount()==0)
2284 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2285 saveStateChangingPart(
2288 "deleteKeepChildren ()",
2289 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2292 QString sel=getSelectString(selbi);
2294 int pos=selbi->num();
2295 BranchItem *bi=selbi->getFirstBranch();
2298 relinkBranch (bi,pi,pos);
2299 bi=selbi->getFirstBranch();
2305 BranchObj *bo=getSelectedBranchObj();
2308 bo->move2RelPos (p);
2314 void VymModel::deleteChildren()
2317 BranchItem *selbi=getSelectedBranchItem();
2320 saveStateChangingPart(
2323 "deleteChildren ()",
2324 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2326 emit (layoutAboutToBeChanged() );
2328 QModelIndex ix=index (selbi);
2329 int n=selbi->branchCount()-1;
2330 beginRemoveRows (ix,0,n);
2331 removeRows (0,n+1,ix);
2333 if (selbi->isScrolled()) selbi->unScroll();
2334 emit (layoutChanged() );
2339 TreeItem* VymModel::deleteItem (TreeItem *ti)
2343 TreeItem *pi=ti->parent();
2344 QModelIndex parentIndex=index(pi);
2346 emit (layoutAboutToBeChanged() );
2348 int n=ti->childNum();
2349 beginRemoveRows (parentIndex,n,n);
2350 removeRows (n,1,parentIndex);
2354 emit (layoutChanged() );
2355 if (pi->depth()>0) return pi;
2360 bool VymModel::scrollBranch(BranchItem *bi)
2364 if (bi->isScrolled()) return false;
2365 if (bi->branchCount()==0) return false;
2366 if (bi->depth()==0) return false;
2367 if (bi->toggleScroll())
2374 QString ("%1 ()").arg(u),
2376 QString ("%1 ()").arg(r),
2377 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2379 emitDataHasChanged(bi);
2380 emitSelectionChanged();
2381 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2388 bool VymModel::unscrollBranch(BranchItem *bi)
2392 if (!bi->isScrolled()) return false;
2393 if (bi->branchCount()==0) return false;
2394 if (bi->depth()==0) return false;
2401 QString ("%1 ()").arg(u),
2403 QString ("%1 ()").arg(r),
2404 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2407 emitDataHasChanged(bi);
2408 emitSelectionChanged();
2410 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2416 void VymModel::toggleScroll()
2418 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2419 if (bi && bi->isBranchLikeType() )
2421 if (bi->isScrolled())
2422 unscrollBranch (bi);
2426 // saveState is called in above functions
2429 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2433 BranchObj *bo=getSelectedBranch();
2439 if (bo->isScrolled()) unscrollBranch (bo);
2446 void VymModel::emitExpandAll()
2448 emit (expandAll() );
2451 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2453 BranchItem *bi=getSelectedBranchItem();
2457 if (bi->isActiveStandardFlag(name))
2469 QString("%1 (\"%2\")").arg(u).arg(name),
2471 QString("%1 (\"%2\")").arg(r).arg(name),
2472 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2473 bi->toggleStandardFlag (name, master);
2475 emitSelectionChanged();
2479 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2482 BranchObj *bo=getSelectedBranch();
2485 FloatImageObj *fio=bo->addFloatImage();
2487 fio->setOriginalFilename("No original filename (image added by dropevent)");
2488 QString s=getSelectString(bo);
2489 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2490 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2492 // FIXME-3 VM needed? scene()->update();
2498 void VymModel::colorBranch (QColor c)
2500 BranchItem *selbi=getSelectedBranchItem();
2505 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2507 QString ("colorBranch (\"%1\")").arg(c.name()),
2508 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2510 selbi->setHeadingColor(c); // color branch
2514 void VymModel::colorSubtree (QColor c)
2516 BranchItem *selbi=getSelectedBranchItem();
2519 saveStateChangingPart(
2522 QString ("colorSubtree (\"%1\")").arg(c.name()),
2523 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2525 BranchItem *prev=NULL;
2526 BranchItem *cur=selbi;
2529 cur->setHeadingColor(c); // color links, color children
2530 cur=next (cur,prev,selbi);
2536 QColor VymModel::getCurrentHeadingColor()
2538 BranchItem *selbi=getSelectedBranchItem();
2539 if (selbi) return selbi->getHeadingColor();
2541 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2547 void VymModel::editURL()
2549 TreeItem *selti=getSelectedItem();
2553 QString text = QInputDialog::getText(
2554 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2555 selti->getURL(), &ok, NULL);
2557 // user entered something and pressed OK
2562 void VymModel::editLocalURL()
2564 TreeItem *selti=getSelectedItem();
2567 QStringList filters;
2568 filters <<"All files (*)";
2569 filters << tr("Text","Filedialog") + " (*.txt)";
2570 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2571 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2572 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2573 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2574 fd->setFilters (filters);
2575 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2576 fd->setDirectory (lastFileDir);
2577 if (! selti->getVymLink().isEmpty() )
2578 fd->selectFile( selti->getURL() );
2581 if ( fd->exec() == QDialog::Accepted )
2583 lastFileDir=QDir (fd->directory().path());
2584 setURL (fd->selectedFile() );
2590 void VymModel::editHeading2URL()
2592 TreeItem *selti=getSelectedItem();
2594 setURL (selti->getHeading());
2597 void VymModel::editBugzilla2URL()
2599 TreeItem *selti=getSelectedItem();
2602 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2607 void VymModel::editFATE2URL()
2609 TreeItem *selti=getSelectedItem();
2612 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2615 "setURL (\""+selti->getURL()+"\")",
2617 "setURL (\""+url+"\")",
2618 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2620 selti->setURL (url);
2621 // FIXME-4 updateActions();
2625 void VymModel::editVymLink()
2627 BranchItem *bi=getSelectedBranchItem();
2630 QStringList filters;
2631 filters <<"VYM map (*.vym)";
2632 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2633 fd->setFilters (filters);
2634 fd->setCaption(vymName+" - " +tr("Link to another map"));
2635 fd->setDirectory (lastFileDir);
2636 if (! bi->getVymLink().isEmpty() )
2637 fd->selectFile( bi->getVymLink() );
2641 if ( fd->exec() == QDialog::Accepted )
2643 lastFileDir=QDir (fd->directory().path());
2646 "setVymLink (\""+bi->getVymLink()+"\")",
2648 "setVymLink (\""+fd->selectedFile()+"\")",
2649 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2651 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2656 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2658 // Internal function, no saveState needed
2659 TreeItem *selti=getSelectedItem();
2662 selti->setVymLink(s);
2664 emitDataHasChanged (selti);
2665 emitShowSelection();
2669 void VymModel::deleteVymLink()
2671 BranchItem *bi=getSelectedBranchItem();
2676 "setVymLink (\""+bi->getVymLink()+"\")",
2678 "setVymLink (\"\")",
2679 QString("Unset vymlink of %1").arg(getObjectName(bi))
2681 bi->setVymLink ("" );
2687 QString VymModel::getVymLink()
2689 BranchItem *bi=getSelectedBranchItem();
2691 return bi->getVymLink();
2697 QStringList VymModel::getVymLinks()
2700 BranchItem *selbi=getSelectedBranchItem();
2701 BranchItem *cur=selbi;
2702 BranchItem *prev=NULL;
2705 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2706 cur=next (cur,prev,selbi);
2712 void VymModel::followXLink(int i) // FIXME-2
2716 BranchObj *bo=getSelectedBranch();
2719 bo=bo->XLinkTargetAt(i);
2722 selection.select(bo);
2723 emitShowSelection();
2729 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2733 BranchObj *bo=getSelectedBranch();
2736 XLinkObj *xlo=bo->XLinkAt(i);
2739 EditXLinkDialog dia;
2741 dia.setSelection(bo);
2742 if (dia.exec() == QDialog::Accepted)
2744 if (dia.useSettingsGlobal() )
2746 setMapDefXLinkColor (xlo->getColor() );
2747 setMapDefXLinkWidth (xlo->getWidth() );
2749 if (dia.deleteXLink())
2750 bo->deleteXLinkAt(i);
2761 //////////////////////////////////////////////
2763 //////////////////////////////////////////////
2765 void VymModel::parseAtom(const QString &atom)
2767 TreeItem* selti=getSelectedItem();
2768 BranchItem *selbi=getSelectedBranchItem();
2774 // Split string s into command and parameters
2775 parser.parseAtom (atom);
2776 QString com=parser.getCommand();
2778 // External commands
2779 /////////////////////////////////////////////////////////////////////
2780 if (com=="addBranch")
2784 parser.setError (Aborted,"Nothing selected");
2785 } else if (! selbi )
2787 parser.setError (Aborted,"Type of selection is not a branch");
2792 if (parser.checkParCount(pl))
2794 if (parser.parCount()==0)
2798 n=parser.parInt (ok,0);
2799 if (ok ) addNewBranch (n);
2803 /////////////////////////////////////////////////////////////////////
2804 } else if (com=="addBranchBefore")
2808 parser.setError (Aborted,"Nothing selected");
2809 } else if (! selbi )
2811 parser.setError (Aborted,"Type of selection is not a branch");
2814 if (parser.parCount()==0)
2816 addNewBranchBefore ();
2819 /////////////////////////////////////////////////////////////////////
2820 } else if (com==QString("addMapCenter"))
2822 if (parser.checkParCount(2))
2824 x=parser.parDouble (ok,0);
2827 y=parser.parDouble (ok,1);
2828 if (ok) addMapCenter (QPointF(x,y));
2831 /////////////////////////////////////////////////////////////////////
2832 } else if (com==QString("addMapReplace"))
2836 parser.setError (Aborted,"Nothing selected");
2837 } else if (! selbi )
2839 parser.setError (Aborted,"Type of selection is not a branch");
2840 } else if (parser.checkParCount(1))
2842 //s=parser.parString (ok,0); // selection
2843 t=parser.parString (ok,0); // path to map
2844 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2845 addMapReplaceInt(getSelectString(selbi),t);
2847 /////////////////////////////////////////////////////////////////////
2848 } else if (com==QString("addMapInsert"))
2852 parser.setError (Aborted,"Nothing selected");
2853 } else if (! selbi )
2855 parser.setError (Aborted,"Type of selection is not a branch");
2858 if (parser.checkParCount(2))
2860 t=parser.parString (ok,0); // path to map
2861 n=parser.parInt(ok,1); // position
2862 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2863 addMapInsertInt(t,n);
2866 /////////////////////////////////////////////////////////////////////
2867 } else if (com=="clearFlags")
2871 parser.setError (Aborted,"Nothing selected");
2872 } else if (! selbi )
2874 parser.setError (Aborted,"Type of selection is not a branch");
2875 } else if (parser.checkParCount(0))
2877 selbi->deactivateAllStandardFlags();
2879 /////////////////////////////////////////////////////////////////////
2880 } else if (com=="colorBranch")
2884 parser.setError (Aborted,"Nothing selected");
2885 } else if (! selbi )
2887 parser.setError (Aborted,"Type of selection is not a branch");
2888 } else if (parser.checkParCount(1))
2890 QColor c=parser.parColor (ok,0);
2891 if (ok) colorBranch (c);
2893 /////////////////////////////////////////////////////////////////////
2894 } else if (com=="colorSubtree")
2898 parser.setError (Aborted,"Nothing selected");
2899 } else if (! selbi )
2901 parser.setError (Aborted,"Type of selection is not a branch");
2902 } else if (parser.checkParCount(1))
2904 QColor c=parser.parColor (ok,0);
2905 if (ok) colorSubtree (c);
2907 /////////////////////////////////////////////////////////////////////
2908 } else if (com=="copy")
2912 parser.setError (Aborted,"Nothing selected");
2913 } else if ( selectionType()!=TreeItem::Branch &&
2914 selectionType()!=TreeItem::MapCenter &&
2915 selectionType()!=TreeItem::Image )
2917 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2918 } else if (parser.checkParCount(0))
2922 /////////////////////////////////////////////////////////////////////
2923 } else if (com=="cut")
2927 parser.setError (Aborted,"Nothing selected");
2928 } else if ( selectionType()!=TreeItem::Branch &&
2929 selectionType()!=TreeItem::MapCenter &&
2930 selectionType()!=TreeItem::Image )
2932 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2933 } else if (parser.checkParCount(0))
2937 /////////////////////////////////////////////////////////////////////
2938 } else if (com=="delete")
2942 parser.setError (Aborted,"Nothing selected");
2944 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2946 parser.setError (Aborted,"Type of selection is wrong.");
2949 else if (parser.checkParCount(0))
2953 /////////////////////////////////////////////////////////////////////
2954 } else if (com=="deleteKeepChildren")
2958 parser.setError (Aborted,"Nothing selected");
2959 } else if (! selbi )
2961 parser.setError (Aborted,"Type of selection is not a branch");
2962 } else if (parser.checkParCount(0))
2964 deleteKeepChildren();
2966 /////////////////////////////////////////////////////////////////////
2967 } else if (com=="deleteChildren")
2971 parser.setError (Aborted,"Nothing selected");
2974 parser.setError (Aborted,"Type of selection is not a branch");
2975 } else if (parser.checkParCount(0))
2979 /////////////////////////////////////////////////////////////////////
2980 } else if (com=="exportASCII")
2984 if (parser.parCount()>=1)
2985 // Hey, we even have a filename
2986 fname=parser.parString(ok,0);
2989 parser.setError (Aborted,"Could not read filename");
2992 exportASCII (fname,false);
2994 /////////////////////////////////////////////////////////////////////
2995 } else if (com=="exportImage")
2999 if (parser.parCount()>=2)
3000 // Hey, we even have a filename
3001 fname=parser.parString(ok,0);
3004 parser.setError (Aborted,"Could not read filename");
3007 QString format="PNG";
3008 if (parser.parCount()>=2)
3010 format=parser.parString(ok,1);
3012 exportImage (fname,false,format);
3014 /////////////////////////////////////////////////////////////////////
3015 } else if (com=="exportXHTML")
3019 if (parser.parCount()>=2)
3020 // Hey, we even have a filename
3021 fname=parser.parString(ok,1);
3024 parser.setError (Aborted,"Could not read filename");
3027 exportXHTML (fname,false);
3029 /////////////////////////////////////////////////////////////////////
3030 } else if (com=="exportXML")
3034 if (parser.parCount()>=2)
3035 // Hey, we even have a filename
3036 fname=parser.parString(ok,1);
3039 parser.setError (Aborted,"Could not read filename");
3042 exportXML (fname,false);
3044 /////////////////////////////////////////////////////////////////////
3045 } else if (com=="importDir")
3049 parser.setError (Aborted,"Nothing selected");
3050 } else if (! selbi )
3052 parser.setError (Aborted,"Type of selection is not a branch");
3053 } else if (parser.checkParCount(1))
3055 s=parser.parString(ok,0);
3056 if (ok) importDirInt(s);
3058 /////////////////////////////////////////////////////////////////////
3059 } else if (com=="relinkTo")
3063 parser.setError (Aborted,"Nothing selected");
3066 if (parser.checkParCount(4))
3068 // 0 selectstring of parent
3069 // 1 num in parent (for branches)
3070 // 2,3 x,y of mainbranch or mapcenter
3071 s=parser.parString(ok,0);
3072 TreeItem *dst=findBySelectString (s);
3075 if (dst->getType()==TreeItem::Branch)
3077 // Get number in parent
3078 n=parser.parInt (ok,1);
3081 relinkBranch (selbi,(BranchItem*)dst,n);
3082 emitSelectionChanged();
3084 } else if (dst->getType()==TreeItem::MapCenter)
3086 relinkBranch (selbi,(BranchItem*)dst);
3087 // Get coordinates of mainbranch
3088 x=parser.parDouble(ok,2);
3091 y=parser.parDouble(ok,3);
3094 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3095 emitSelectionChanged();
3101 } else if ( selti->getType() == TreeItem::Image)
3103 if (parser.checkParCount(1))
3105 // 0 selectstring of parent
3106 s=parser.parString(ok,0);
3107 TreeItem *dst=findBySelectString (s);
3110 if (dst->isBranchLikeType())
3111 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3113 parser.setError (Aborted,"Destination is not a branch");
3116 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3117 /////////////////////////////////////////////////////////////////////
3118 } else if (com=="loadImage")
3122 parser.setError (Aborted,"Nothing selected");
3123 } else if (! selbi )
3125 parser.setError (Aborted,"Type of selection is not a branch");
3126 } else if (parser.checkParCount(1))
3128 s=parser.parString(ok,0);
3129 if (ok) loadFloatImageInt (selbi,s);
3131 /////////////////////////////////////////////////////////////////////
3132 } else if (com=="moveUp")
3136 parser.setError (Aborted,"Nothing selected");
3137 } else if (! selbi )
3139 parser.setError (Aborted,"Type of selection is not a branch");
3140 } else if (parser.checkParCount(0))
3144 /////////////////////////////////////////////////////////////////////
3145 } else if (com=="moveDown")
3149 parser.setError (Aborted,"Nothing selected");
3150 } else if (! selbi )
3152 parser.setError (Aborted,"Type of selection is not a branch");
3153 } else if (parser.checkParCount(0))
3157 /////////////////////////////////////////////////////////////////////
3158 } else if (com=="move")
3162 parser.setError (Aborted,"Nothing selected");
3163 } else if ( selectionType()!=TreeItem::Branch &&
3164 selectionType()!=TreeItem::MapCenter &&
3165 selectionType()!=TreeItem::Image )
3167 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3168 } else if (parser.checkParCount(2))
3170 x=parser.parDouble (ok,0);
3173 y=parser.parDouble (ok,1);
3177 /////////////////////////////////////////////////////////////////////
3178 } else if (com=="moveRel")
3182 parser.setError (Aborted,"Nothing selected");
3183 } else if ( selectionType()!=TreeItem::Branch &&
3184 selectionType()!=TreeItem::MapCenter &&
3185 selectionType()!=TreeItem::Image )
3187 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3188 } else if (parser.checkParCount(2))
3190 x=parser.parDouble (ok,0);
3193 y=parser.parDouble (ok,1);
3194 if (ok) moveRel (x,y);
3197 /////////////////////////////////////////////////////////////////////
3198 } else if (com=="nop")
3200 /////////////////////////////////////////////////////////////////////
3201 } else if (com=="paste")
3205 parser.setError (Aborted,"Nothing selected");
3206 } else if (! selbi )
3208 parser.setError (Aborted,"Type of selection is not a branch");
3209 } else if (parser.checkParCount(1))
3211 n=parser.parInt (ok,0);
3212 if (ok) pasteNoSave(n);
3214 /////////////////////////////////////////////////////////////////////
3215 } else if (com=="qa")
3219 parser.setError (Aborted,"Nothing selected");
3220 } else if (! selbi )
3222 parser.setError (Aborted,"Type of selection is not a branch");
3223 } else if (parser.checkParCount(4))
3226 c=parser.parString (ok,0);
3229 parser.setError (Aborted,"No comment given");
3232 s=parser.parString (ok,1);
3235 parser.setError (Aborted,"First parameter is not a string");
3238 t=parser.parString (ok,2);
3241 parser.setError (Aborted,"Condition is not a string");
3244 u=parser.parString (ok,3);
3247 parser.setError (Aborted,"Third parameter is not a string");
3252 parser.setError (Aborted,"Unknown type: "+s);
3257 parser.setError (Aborted,"Unknown operator: "+t);
3262 parser.setError (Aborted,"Type of selection is not a branch");
3265 if (selbi->getHeading() == u)
3267 cout << "PASSED: " << qPrintable (c) << endl;
3270 cout << "FAILED: " << qPrintable (c) << endl;
3280 /////////////////////////////////////////////////////////////////////
3281 } else if (com=="saveImage")
3283 ImageItem *ii=getSelectedImageItem();
3286 parser.setError (Aborted,"No image selected");
3287 } else if (parser.checkParCount(2))
3289 s=parser.parString(ok,0);
3292 t=parser.parString(ok,1);
3293 if (ok) saveFloatImageInt (ii,t,s);
3296 /////////////////////////////////////////////////////////////////////
3297 } else if (com=="scroll")
3301 parser.setError (Aborted,"Nothing selected");
3302 } else if (! selbi )
3304 parser.setError (Aborted,"Type of selection is not a branch");
3305 } else if (parser.checkParCount(0))
3307 if (!scrollBranch (selbi))
3308 parser.setError (Aborted,"Could not scroll branch");
3310 /////////////////////////////////////////////////////////////////////
3311 } else if (com=="select")
3313 if (parser.checkParCount(1))
3315 s=parser.parString(ok,0);
3318 /////////////////////////////////////////////////////////////////////
3319 } else if (com=="selectLastBranch")
3323 parser.setError (Aborted,"Nothing selected");
3324 } else if (! selbi )
3326 parser.setError (Aborted,"Type of selection is not a branch");
3327 } else if (parser.checkParCount(0))
3329 BranchItem *bi=selbi->getLastBranch();
3331 parser.setError (Aborted,"Could not select last branch");
3332 select (bi); // FIXME-3 was selectInt
3335 /////////////////////////////////////////////////////////////////////
3336 } else /* FIXME-2 if (com=="selectLastImage")
3340 parser.setError (Aborted,"Nothing selected");
3341 } else if (! selbi )
3343 parser.setError (Aborted,"Type of selection is not a branch");
3344 } else if (parser.checkParCount(0))
3346 FloatImageObj *fio=selb->getLastFloatImage();
3348 parser.setError (Aborted,"Could not select last image");
3349 select (fio); // FIXME-3 was selectInt
3352 /////////////////////////////////////////////////////////////////////
3353 } else */ if (com=="selectLatestAdded")
3355 if (!latestAddedItem)
3357 parser.setError (Aborted,"No latest added object");
3360 if (!select (latestAddedItem))
3361 parser.setError (Aborted,"Could not select latest added object ");
3363 /////////////////////////////////////////////////////////////////////
3364 } else if (com=="setFrameType")
3366 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3368 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3370 else if (parser.checkParCount(1))
3372 s=parser.parString(ok,0);
3373 if (ok) setFrameType (s);
3375 /////////////////////////////////////////////////////////////////////
3376 } else if (com=="setFramePenColor")
3378 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3380 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3382 else if (parser.checkParCount(1))
3384 QColor c=parser.parColor(ok,0);
3385 if (ok) setFramePenColor (c);
3387 /////////////////////////////////////////////////////////////////////
3388 } else if (com=="setFrameBrushColor")
3390 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3392 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3394 else if (parser.checkParCount(1))
3396 QColor c=parser.parColor(ok,0);
3397 if (ok) setFrameBrushColor (c);
3399 /////////////////////////////////////////////////////////////////////
3400 } else if (com=="setFramePadding")
3402 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3404 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3406 else if (parser.checkParCount(1))
3408 n=parser.parInt(ok,0);
3409 if (ok) setFramePadding(n);
3411 /////////////////////////////////////////////////////////////////////
3412 } else if (com=="setFrameBorderWidth")
3414 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3416 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3418 else if (parser.checkParCount(1))
3420 n=parser.parInt(ok,0);
3421 if (ok) setFrameBorderWidth (n);
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="setMapAuthor")
3426 if (parser.checkParCount(1))
3428 s=parser.parString(ok,0);
3429 if (ok) setAuthor (s);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="setMapComment")
3434 if (parser.checkParCount(1))
3436 s=parser.parString(ok,0);
3437 if (ok) setComment(s);
3439 /////////////////////////////////////////////////////////////////////
3440 } else if (com=="setMapBackgroundColor")
3444 parser.setError (Aborted,"Nothing selected");
3445 } else if (! selbi )
3447 parser.setError (Aborted,"Type of selection is not a branch");
3448 } else if (parser.checkParCount(1))
3450 QColor c=parser.parColor (ok,0);
3451 if (ok) setMapBackgroundColor (c);
3453 /////////////////////////////////////////////////////////////////////
3454 } else if (com=="setMapDefLinkColor")
3458 parser.setError (Aborted,"Nothing selected");
3459 } else if (! selbi )
3461 parser.setError (Aborted,"Type of selection is not a branch");
3462 } else if (parser.checkParCount(1))
3464 QColor c=parser.parColor (ok,0);
3465 if (ok) setMapDefLinkColor (c);
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="setMapLinkStyle")
3470 if (parser.checkParCount(1))
3472 s=parser.parString (ok,0);
3473 if (ok) setMapLinkStyle(s);
3475 /////////////////////////////////////////////////////////////////////
3476 } else if (com=="setHeading")
3480 parser.setError (Aborted,"Nothing selected");
3481 } else if (! selbi )
3483 parser.setError (Aborted,"Type of selection is not a branch");
3484 } else if (parser.checkParCount(1))
3486 s=parser.parString (ok,0);
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="setHideExport")
3495 parser.setError (Aborted,"Nothing selected");
3496 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3498 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3499 } else if (parser.checkParCount(1))
3501 b=parser.parBool(ok,0);
3502 if (ok) setHideExport (b);
3504 /////////////////////////////////////////////////////////////////////
3505 } else if (com=="setIncludeImagesHorizontally")
3509 parser.setError (Aborted,"Nothing selected");
3512 parser.setError (Aborted,"Type of selection is not a branch");
3513 } else if (parser.checkParCount(1))
3515 b=parser.parBool(ok,0);
3516 if (ok) setIncludeImagesHor(b);
3518 /////////////////////////////////////////////////////////////////////
3519 } else if (com=="setIncludeImagesVertically")
3523 parser.setError (Aborted,"Nothing selected");
3526 parser.setError (Aborted,"Type of selection is not a branch");
3527 } else if (parser.checkParCount(1))
3529 b=parser.parBool(ok,0);
3530 if (ok) setIncludeImagesVer(b);
3532 /////////////////////////////////////////////////////////////////////
3533 } else if (com=="setHideLinkUnselected")
3537 parser.setError (Aborted,"Nothing selected");
3538 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3540 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3541 } else if (parser.checkParCount(1))
3543 b=parser.parBool(ok,0);
3544 if (ok) setHideLinkUnselected(b);
3546 /////////////////////////////////////////////////////////////////////
3547 } else if (com=="setSelectionColor")
3549 if (parser.checkParCount(1))
3551 QColor c=parser.parColor (ok,0);
3552 if (ok) setSelectionColorInt (c);
3554 /////////////////////////////////////////////////////////////////////
3555 } else if (com=="setURL")
3559 parser.setError (Aborted,"Nothing selected");
3560 } else if (! selbi )
3562 parser.setError (Aborted,"Type of selection is not a branch");
3563 } else if (parser.checkParCount(1))
3565 s=parser.parString (ok,0);
3568 /////////////////////////////////////////////////////////////////////
3569 } else if (com=="setVymLink")
3573 parser.setError (Aborted,"Nothing selected");
3574 } else if (! selbi )
3576 parser.setError (Aborted,"Type of selection is not a branch");
3577 } else if (parser.checkParCount(1))
3579 s=parser.parString (ok,0);
3580 if (ok) setVymLink(s);
3583 /////////////////////////////////////////////////////////////////////
3584 else if (com=="setFlag")
3588 parser.setError (Aborted,"Nothing selected");
3589 } else if (! selbi )
3591 parser.setError (Aborted,"Type of selection is not a branch");
3592 } else if (parser.checkParCount(1))
3594 s=parser.parString(ok,0);
3596 selbi->activateStandardFlag(s);
3598 /////////////////////////////////////////////////////////////////////
3599 } else /* FIXME-2 if (com=="setFrameType")
3603 parser.setError (Aborted,"Nothing selected");
3606 parser.setError (Aborted,"Type of selection is not a branch");
3607 } else if (parser.checkParCount(1))
3609 s=parser.parString(ok,0);
3613 /////////////////////////////////////////////////////////////////////
3614 } else*/ if (com=="sortChildren")
3618 parser.setError (Aborted,"Nothing selected");
3619 } else if (! selbi )
3621 parser.setError (Aborted,"Type of selection is not a branch");
3622 } else if (parser.checkParCount(0))
3626 /////////////////////////////////////////////////////////////////////
3627 } else if (com=="toggleFlag")
3631 parser.setError (Aborted,"Nothing selected");
3632 } else if (! selbi )
3634 parser.setError (Aborted,"Type of selection is not a branch");
3635 } else if (parser.checkParCount(1))
3637 s=parser.parString(ok,0);
3639 selbi->toggleStandardFlag(s);
3641 /////////////////////////////////////////////////////////////////////
3642 } else if (com=="unscroll")
3646 parser.setError (Aborted,"Nothing selected");
3647 } else if (! selbi )
3649 parser.setError (Aborted,"Type of selection is not a branch");
3650 } else if (parser.checkParCount(0))
3652 if (!unscrollBranch (selbi))
3653 parser.setError (Aborted,"Could not unscroll branch");
3655 /////////////////////////////////////////////////////////////////////
3656 } else if (com=="unscrollChildren")
3660 parser.setError (Aborted,"Nothing selected");
3661 } else if (! selbi )
3663 parser.setError (Aborted,"Type of selection is not a branch");
3664 } else if (parser.checkParCount(0))
3666 unscrollChildren ();
3668 /////////////////////////////////////////////////////////////////////
3669 } else if (com=="unsetFlag")
3673 parser.setError (Aborted,"Nothing selected");
3674 } else if (! selbi )
3676 parser.setError (Aborted,"Type of selection is not a branch");
3677 } else if (parser.checkParCount(1))
3679 s=parser.parString(ok,0);
3681 selbi->deactivateStandardFlag(s);
3684 parser.setError (Aborted,"Unknown command");
3687 if (parser.errorLevel()==NoError)
3689 // setChanged(); FIXME-2 should not be called e.g. for export?!
3694 // TODO Error handling
3695 qWarning("VymModel::parseAtom: Error!");
3696 qWarning(parser.errorMessage());
3700 void VymModel::runScript (QString script)
3702 parser.setScript (script);
3704 while (parser.next() )
3705 parseAtom(parser.getAtom());
3708 void VymModel::setExportMode (bool b)
3710 // should be called before and after exports
3711 // depending on the settings
3712 if (b && settings.value("/export/useHideExport","true")=="true")
3713 setHideTmpMode (TreeItem::HideExport);
3715 setHideTmpMode (TreeItem::HideNone);
3718 void VymModel::exportImage(QString fname, bool askName, QString format)
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 (getPixmap());
3744 pix.save(fname, format);
3745 setExportMode (false);
3749 void VymModel::exportXML(QString dir, bool askForName)
3753 dir=browseDirectory(NULL,tr("Export XML to directory"));
3754 if (dir =="" && !reallyWriteDirectory(dir) )
3758 // Hide stuff during export, if settings want this
3759 setExportMode (true);
3761 // Create subdirectories
3764 // write to directory
3765 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3768 file.setName ( dir + "/"+mapName+".xml");
3769 if ( !file.open( QIODevice::WriteOnly ) )
3771 // This should neverever happen
3772 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3776 // Write it finally, and write in UTF8, no matter what
3777 QTextStream ts( &file );
3778 ts.setEncoding (QTextStream::UnicodeUTF8);
3782 // Now write image, too
3783 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3785 setExportMode (false);
3788 void VymModel::exportASCII(QString fname,bool askName)
3793 ex.setFile (mapName+".txt");
3799 //ex.addFilter ("TXT (*.txt)");
3800 ex.setDir(lastImageDir);
3801 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3806 setExportMode(true);
3808 setExportMode(false);
3812 void VymModel::exportXHTML (const QString &dir, bool askForName)
3814 ExportXHTMLDialog dia(NULL);
3815 dia.setFilePath (filePath );
3816 dia.setMapName (mapName );
3818 if (dir!="") dia.setDir (dir);
3824 if (dia.exec()!=QDialog::Accepted)
3828 QDir d (dia.getDir());
3829 // Check, if warnings should be used before overwriting
3830 // the output directory
3831 if (d.exists() && d.count()>0)
3834 warn.showCancelButton (true);
3835 warn.setText(QString(
3836 "The directory %1 is not empty.\n"
3837 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3838 warn.setCaption("Warning: Directory not empty");
3839 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3841 if (warn.exec()!=QDialog::Accepted) ok=false;
3848 exportXML (dia.getDir(),false );
3849 dia.doExport(mapName );
3850 //if (dia.hasChanged()) setChanged();
3854 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3859 if (ex.setConfigFile(cf))
3861 setExportMode (true);
3862 ex.exportPresentation();
3863 setExportMode (false);
3870 //////////////////////////////////////////////
3872 //////////////////////////////////////////////
3874 void VymModel::registerEditor(QWidget *me)
3876 mapEditor=(MapEditor*)me;
3879 void VymModel::unregisterEditor(QWidget *)
3884 void VymModel::setContextPos(QPointF p)
3889 void VymModel::unsetContextPos()
3891 contextPos=QPointF();
3894 void VymModel::updateNoteFlag()
3897 TreeItem *selti=getSelectedItem();
3900 if (textEditor->isEmpty())
3903 selti->setNote (textEditor->getText());
3904 emitDataHasChanged(selti);
3905 emitSelectionChanged();
3910 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3913 for (int i=0; i<rootItem->branchCount(); i++)
3914 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3917 void MapCenterObj::updateRelPositions()
3919 if (repositionRequest) unsetAllRepositionRequests();
3921 // update relative Positions of branches and floats
3922 for (int i=0; i<treeItem->branchCount(); ++i)
3924 treeItem->getBranchObjNum(i)->setRelPos();
3925 treeItem->getBranchObjNum(i)->setOrientation();
3928 for (int i=0; i<floatimage.size(); ++i)
3929 floatimage.at(i)->setRelPos();
3931 if (repositionRequest) reposition();
3936 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3938 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3939 if (blockReposition) return;
3941 for (int i=0;i<rootItem->branchCount(); i++)
3942 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3946 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3948 return QPolygonF ();
3949 // Creating (arbitrary) shapes
3952 QRectF rb=bo->getBBox();
3953 if (bo->getDepth()==0)
3955 // Just take BBox of this mapCenter
3956 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3960 // Take union of BBox and TotalBBox
3962 QRectF ra=bo->getTotalBBox();
3963 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3966 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3969 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3971 p <<ra.bottomRight()
3973 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3976 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3982 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3986 // Move all branches and MapCenters away from lmo
3987 // to avoid collisions
3992 BranchObj *boA=(BranchObj*)lmo;
3994 for (int i=0; i<rootItem->branchCount(); i++)
3996 boB=rootItem->getBranchNum(i);
3999 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4002 <<" ("<<qPrintable(boA->getHeading() )<<")"
4003 <<" with ("<< qPrintable (boB->getHeading() )
4006 <<" minT="<<r.minTranslation<<endl<<endl;
4011 QPixmap VymModel::getPixmap()
4013 QRectF mapRect=getTotalBBox();
4014 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4017 pp.setRenderHints(mapEditor->renderHints());
4019 // Don't print the visualisation of selection
4022 mapScene->render ( &pp,
4023 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4024 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4026 // Restore selection
4033 void VymModel::setMapLinkStyle (const QString & s)
4038 case LinkableMapObj::Line :
4041 case LinkableMapObj::Parabel:
4042 snow="StyleParabel";
4044 case LinkableMapObj::PolyLine:
4045 snow="StylePolyLine";
4047 case LinkableMapObj::PolyParabel:
4048 snow="StylePolyParabel";
4051 snow="UndefinedStyle";
4056 QString("setMapLinkStyle (\"%1\")").arg(s),
4057 QString("setMapLinkStyle (\"%1\")").arg(snow),
4058 QString("Set map link style (\"%1\")").arg(s)
4062 linkstyle=LinkableMapObj::Line;
4063 else if (s=="StyleParabel")
4064 linkstyle=LinkableMapObj::Parabel;
4065 else if (s=="StylePolyLine")
4066 linkstyle=LinkableMapObj::PolyLine;
4067 else if (s=="StylePolyParabel")
4068 linkstyle=LinkableMapObj::PolyParabel;
4070 linkstyle=LinkableMapObj::UndefinedStyle;
4072 BranchItem *cur=NULL;
4073 BranchItem *prev=NULL;
4078 bo=(BranchObj*)(cur->getLMO() );
4079 bo->setLinkStyle(bo->getDefLinkStyle());
4085 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4090 void VymModel::setMapDefLinkColor(QColor col)
4092 if ( !col.isValid() ) return;
4094 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4095 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4096 QString("Set map link color to %1").arg(col.name())
4100 BranchItem *cur=NULL;
4101 BranchItem *prev=NULL;
4106 bo=(BranchObj*)(cur->getLMO() );
4113 void VymModel::setMapLinkColorHintInt()
4115 // called from setMapLinkColorHint(lch) or at end of parse
4116 BranchItem *cur=NULL;
4117 BranchItem *prev=NULL;
4122 bo=(BranchObj*)(cur->getLMO() );
4128 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4131 setMapLinkColorHintInt();
4134 void VymModel::toggleMapLinkColorHint()
4136 if (linkcolorhint==LinkableMapObj::HeadingColor)
4137 linkcolorhint=LinkableMapObj::DefaultColor;
4139 linkcolorhint=LinkableMapObj::HeadingColor;
4140 BranchItem *cur=NULL;
4141 BranchItem *prev=NULL;
4146 bo=(BranchObj*)(cur->getLMO() );
4152 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4154 Q3FileDialog *fd=new Q3FileDialog( NULL);
4155 fd->setMode (Q3FileDialog::ExistingFile);
4156 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4157 ImagePreview *p =new ImagePreview (fd);
4158 fd->setContentsPreviewEnabled( TRUE );
4159 fd->setContentsPreview( p, p );
4160 fd->setPreviewMode( Q3FileDialog::Contents );
4161 fd->setCaption(vymName+" - " +tr("Load background image"));
4162 fd->setDir (lastImageDir);
4165 if ( fd->exec() == QDialog::Accepted )
4167 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4168 lastImageDir=QDir (fd->dirPath());
4169 setMapBackgroundImage (fd->selectedFile());
4173 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4175 QColor oldcol=mapScene->backgroundBrush().color();
4179 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4181 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4182 QString("Set background color of map to %1").arg(col.name()));
4185 brush.setTextureImage (QPixmap (fn));
4186 mapScene->setBackgroundBrush(brush);
4189 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4191 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4192 if ( !col.isValid() ) return;
4193 setMapBackgroundColor( col );
4197 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4199 QColor oldcol=mapScene->backgroundBrush().color();
4201 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4202 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4203 QString("Set background color of map to %1").arg(col.name()));
4204 mapScene->setBackgroundBrush(col);
4207 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4209 return mapScene->backgroundBrush().color();
4213 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4215 return linkcolorhint;
4218 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4220 return defLinkColor;
4223 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4228 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4230 return defXLinkColor;
4233 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4238 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4240 return defXLinkWidth;
4243 void VymModel::move(const double &x, const double &y) // FIXME-3
4247 BranchObj *bo = getSelectedBranch();
4249 (selectionType()==TreeItem::Branch ||
4250 selectionType()==TreeItem::MapCenter ||
4251 selectionType()==TreeItem::Image
4254 QPointF ap(bo->getAbsPos());
4258 QString ps=qpointfToString(ap);
4259 QString s=getSelectString();
4262 s, "move "+qpointfToString(to),
4263 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4266 emitSelectionChanged();
4272 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4276 BranchObj *bo = getSelectedBranch();
4278 (selectionType()==TreeItem::Branch ||
4279 selectionType()==TreeItem::MapCenter ||
4280 selectionType()==TreeItem::Image
4284 QPointF rp(bo->getRelPos());
4288 QString ps=qpointfToString (bo->getRelPos());
4289 QString s=getSelectString(bo);
4292 s, "moveRel "+qpointfToString(to),
4293 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4294 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4296 bo->updateLinkGeometry();
4297 emitSelectionChanged();
4304 void VymModel::animate()
4306 animationTimer->stop();
4309 while (i<animObjList.size() )
4311 bo=(BranchObj*)animObjList.at(i);
4316 animObjList.removeAt(i);
4323 QItemSelection sel=selModel->selection();
4324 emit (selectionChanged(sel,sel));
4327 if (!animObjList.isEmpty()) animationTimer->start();
4331 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4333 if (bo && bo->getTreeItem()->depth()>0)
4336 ap.setStart (start);
4338 ap.setTicks (animationTicks);
4339 ap.setAnimated (true);
4340 bo->setAnimation (ap);
4341 animObjList.append( bo );
4342 animationTimer->setSingleShot (true);
4343 animationTimer->start(animationInterval);
4347 void VymModel::stopAnimation (MapObj *mo)
4349 int i=animObjList.indexOf(mo);
4351 animObjList.removeAt (i);
4354 void VymModel::sendSelection()
4356 if (netstate!=Server) return;
4357 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4360 void VymModel::newServer()
4364 tcpServer = new QTcpServer(this);
4365 if (!tcpServer->listen(QHostAddress::Any,port)) {
4366 QMessageBox::critical(NULL, "vym server",
4367 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4368 //FIXME-3 needed? we are no widget any longer... close();
4371 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4373 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4376 void VymModel::connectToServer()
4379 server="salam.suse.de";
4381 clientSocket = new QTcpSocket (this);
4382 clientSocket->abort();
4383 clientSocket->connectToHost(server ,port);
4384 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4385 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4386 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4388 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4393 void VymModel::newClient()
4395 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4396 connect(newClient, SIGNAL(disconnected()),
4397 newClient, SLOT(deleteLater()));
4399 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4401 clientList.append (newClient);
4405 void VymModel::sendData(const QString &s)
4407 if (clientList.size()==0) return;
4409 // Create bytearray to send
4411 QDataStream out(&block, QIODevice::WriteOnly);
4412 out.setVersion(QDataStream::Qt_4_0);
4414 // Reserve some space for blocksize
4417 // Write sendCounter
4418 out << sendCounter++;
4423 // Go back and write blocksize so far
4424 out.device()->seek(0);
4425 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4429 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4431 for (int i=0; i<clientList.size(); ++i)
4433 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4434 clientList.at(i)->write (block);
4438 void VymModel::readData ()
4440 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4443 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4447 QDataStream in(clientSocket);
4448 in.setVersion(QDataStream::Qt_4_0);
4456 cout << " t="<<qPrintable (t)<<endl;
4462 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4464 switch (socketError) {
4465 case QAbstractSocket::RemoteHostClosedError:
4467 case QAbstractSocket::HostNotFoundError:
4468 QMessageBox::information(NULL, vymName +" Network client",
4469 "The host was not found. Please check the "
4470 "host name and port settings.");
4472 case QAbstractSocket::ConnectionRefusedError:
4473 QMessageBox::information(NULL, vymName + " Network client",
4474 "The connection was refused by the peer. "
4475 "Make sure the fortune server is running, "
4476 "and check that the host name and port "
4477 "settings are correct.");
4480 QMessageBox::information(NULL, vymName + " Network client",
4481 QString("The following error occurred: %1.")
4482 .arg(clientSocket->errorString()));
4489 void VymModel::selectMapSelectionColor()
4491 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4492 setSelectionColor (col);
4495 void VymModel::setSelectionColorInt (QColor col)
4497 if ( !col.isValid() ) return;
4499 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4500 QString("setSelectionColor (%1)").arg(col.name()),
4501 QString("Set color of selection box to %1").arg(col.name())
4504 mapEditor->setSelectionColor (col);
4508 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4510 cout << "VymModel::changeSelection (";
4511 if (!newsel.indexes().isEmpty() )
4512 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4514 if (!oldsel.indexes().isEmpty() )
4515 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4520 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4524 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4526 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4527 emitShowSelection();
4531 void VymModel::emitSelectionChanged()
4533 QItemSelection newsel=selModel->selection();
4534 emitSelectionChanged (newsel);
4537 void VymModel::setSelectionColor(QColor col)
4539 if ( !col.isValid() ) return;
4541 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4542 QString("setSelectionColor (%1)").arg(col.name()),
4543 QString("Set color of selection box to %1").arg(col.name())
4545 setSelectionColorInt (col);
4548 QColor VymModel::getSelectionColor()
4550 return mapEditor->getSelectionColor();
4553 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4556 for (int i=0;i<rootItem->childCount();i++)
4557 rootItem->child(i)->setHideTmp (mode);
4559 // FIXME-3 needed? scene()->update();
4563 QRectF VymModel::getTotalBBox() //FIXME-2
4567 for (int i=0;i<rootItem->branchCount(); i++)
4568 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4573 //////////////////////////////////////////////
4574 // Selection related
4575 //////////////////////////////////////////////
4577 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4582 QItemSelectionModel* VymModel::getSelectionModel()
4587 void VymModel::setSelectionBlocked (bool b)
4592 bool VymModel::isSelectionBlocked()
4594 return selectionBlocked;
4597 bool VymModel::select ()
4599 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4602 bool VymModel::select (const QString &s)
4604 TreeItem *ti=findBySelectString(s);
4614 bool VymModel::select (LinkableMapObj *lmo)
4616 QItemSelection oldsel=selModel->selection();
4619 return select (lmo->getTreeItem() );
4624 bool VymModel::select (TreeItem *ti)
4626 if (ti) return select (index(ti));
4630 bool VymModel::select (const QModelIndex &index)
4632 if (index.isValid() )
4634 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4635 getSelectedItem()->setLastSelectedBranch();
4641 void VymModel::unselect()
4643 lastSelectString=getSelectString();
4644 selModel->clearSelection();
4647 void VymModel::reselect()
4649 select (lastSelectString);
4652 void VymModel::emitShowSelection()
4654 if (!blockReposition)
4655 emit (showSelection() );
4658 void VymModel::emitNoteHasChanged (TreeItem *ti)
4660 QModelIndex ix=index(ti);
4661 emit (noteHasChanged (ix) );
4664 void VymModel::emitDataHasChanged (TreeItem *ti)
4666 QModelIndex ix=index(ti);
4667 emit (dataChanged (ix,ix) );
4671 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4674 if (selection.select(lmo))
4676 //emitSelectionChanged();
4680 void VymModel::selectInt (TreeItem *ti)
4682 if (selection.select(lmo))
4684 //emitSelectionChanged();
4689 void VymModel::selectNextBranchInt()
4691 BranchItem *bi=getSelectedBranchItem();
4694 TreeItem *pi=bi->parent();
4698 if (i<pi->branchCount() )
4700 // select previous branch with same parent
4702 select (pi->getBranchNum(i));
4710 void VymModel::selectPrevBranchInt()
4713 BranchItem *bi=getSelectedBranchItem();
4716 BranchItem *pi=(BranchItem*)bi->parent();
4722 // select previous branch with same parent
4723 bi=pi->getBranchNum(i-1);
4728 while (bi->branchCount() >0)
4729 bi=bi->getLastBranch();
4732 // Try to select last branch in parent pi2 previous to own parent pi
4734 TreeItem *pi2=pi->parent();
4745 void VymModel::selectAboveBranchInt()
4747 BranchItem *bi=getSelectedBranchItem();
4750 BranchItem *newbi=NULL;
4751 BranchItem *pi=(BranchItem*)bi->parent();
4755 // goto previous branch with same parent
4756 newbi=pi->getBranchNum(i-1);
4757 while (newbi->branchCount() >0 )
4758 newbi=newbi->getLastBranch();
4762 if (newbi==rootItem)
4763 // already at top branch (resp. mapcenter)
4769 void VymModel::selectBelowBranchInt()
4771 BranchItem *bi=getSelectedBranchItem();
4774 BranchItem *newbi=NULL;
4776 if (bi->branchCount() >0)
4777 newbi=bi->getFirstBranch();
4784 pi=(BranchItem*)bi->parent();
4786 if (pi->branchCount()-1 > i)
4788 newbi=(BranchItem*)pi->getBranchNum(i+1);
4793 // look for siblings of myself
4794 // or parent, or parent of parent...
4805 void VymModel::selectUpperBranch()
4807 BranchItem *bi=getSelectedBranchItem();
4808 if (bi && bi->isBranchLikeType())
4809 selectAboveBranchInt();
4812 void VymModel::selectLowerBranch()
4814 BranchItem *bi=getSelectedBranchItem();
4815 if (bi && bi->isBranchLikeType())
4816 selectBelowBranchInt();
4820 void VymModel::selectLeftBranch()
4822 QItemSelection oldsel=selModel->selection();
4825 BranchItem *selbi=getSelectedBranchItem();
4826 TreeItem::Type type=selbi->getType();
4829 if (type == TreeItem::MapCenter)
4831 QModelIndex ix=index(selbi);
4832 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4835 par=(BranchItem*)selbi->parent();
4836 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4839 if (type == TreeItem::Branch ||
4840 type == TreeItem::Image)
4842 QModelIndex ix=index (selbi->parent());
4843 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4848 if (type == TreeItem::Branch )
4850 selectLastSelectedBranch();
4858 void VymModel::selectRightBranch()
4860 QItemSelection oldsel=selModel->selection();
4863 BranchItem *selbi=getSelectedBranchItem();
4864 TreeItem::Type type=selbi->getType();
4867 if (type==TreeItem::MapCenter)
4869 QModelIndex ix=index(selbi);
4870 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4873 par=(BranchItem*)selbi->parent();
4874 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4877 if ( type== TreeItem::Branch )
4879 selectLastSelectedBranch();
4885 if (type == TreeItem::Branch ||
4886 type == TreeItem::Image)
4888 QModelIndex ix=index(selbi->parent());
4889 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4896 void VymModel::selectFirstBranch()
4898 TreeItem *ti=getSelectedBranchItem();
4901 TreeItem *par=ti->parent();
4903 TreeItem *ti2=par->getFirstBranch();
4906 emitSelectionChanged();
4911 void VymModel::selectLastBranch()
4913 TreeItem *ti=getSelectedBranchItem();
4916 TreeItem *par=ti->parent();
4918 TreeItem *ti2=par->getLastBranch();
4921 emitSelectionChanged();
4926 void VymModel::selectLastSelectedBranch()
4928 TreeItem *ti=getSelectedBranchItem();
4931 ti=ti->getLastSelectedBranch();
4932 if (ti) select (ti);
4936 void VymModel::selectParent()
4938 TreeItem *ti=getSelectedItem();
4945 emitSelectionChanged();
4949 TreeItem::Type VymModel::selectionType()
4951 QModelIndexList list=selModel->selectedIndexes();
4952 if (list.isEmpty()) return TreeItem::Undefined;
4953 TreeItem *ti = getItem (list.first() );
4954 return ti->getType();
4958 LinkableMapObj* VymModel::getSelectedLMO()
4960 QModelIndexList list=selModel->selectedIndexes();
4961 if (!list.isEmpty() )
4963 TreeItem *ti = getItem (list.first() );
4964 TreeItem::Type type=ti->getType();
4965 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4966 return ((MapItem*)ti)->getLMO();
4971 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4973 TreeItem *ti = getSelectedBranchItem();
4975 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4980 BranchItem* VymModel::getSelectedBranchItem()
4982 QModelIndexList list=selModel->selectedIndexes();
4983 if (!list.isEmpty() )
4985 TreeItem *ti = getItem (list.first() );
4986 TreeItem::Type type=ti->getType();
4987 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4988 return (BranchItem*)ti;
4993 TreeItem* VymModel::getSelectedItem()
4995 QModelIndexList list=selModel->selectedIndexes();
4996 if (!list.isEmpty() )
4997 return getItem (list.first() );
5002 QModelIndex VymModel::getSelectedIndex()
5004 QModelIndexList list=selModel->selectedIndexes();
5005 if (list.isEmpty() )
5006 return QModelIndex();
5008 return list.first();
5011 ImageItem* VymModel::getSelectedImageItem()
5013 QModelIndexList list=selModel->selectedIndexes();
5014 if (!list.isEmpty())
5016 TreeItem *ti=getItem (list.first());
5017 if (ti && ti->getType()==TreeItem::Image)
5018 return (ImageItem*)ti;
5023 QString VymModel::getSelectString ()
5025 return getSelectString (getSelectedItem());
5028 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5030 if (!lmo) return QString();
5031 return getSelectString (lmo->getTreeItem() );
5034 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
5038 switch (ti->getType())
5040 case TreeItem::MapCenter: s="mc:"; break;
5041 case TreeItem::Branch: s="bo:";break;
5042 case TreeItem::Image: s="fi:";break;
5045 s= s + QString("%1").arg(ti->num());
5047 // call myself recursively
5048 s= getSelectString(ti->parent()) +","+s;