1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
18 #include "warningdialog.h"
19 #include "xml-freemind.h"
25 extern Main *mainWindow;
26 extern QDBusConnection dbusConnection;
28 extern Settings settings;
29 extern QString tmpVymDir;
31 extern TextEditor *textEditor;
32 extern FlagRow *standardFlagsMaster;
34 extern QString clipboardDir;
35 extern QString clipboardFile;
36 extern bool clipboardEmpty;
38 extern ImageIO imageIO;
40 extern QString vymName;
41 extern QString vymVersion;
42 extern QDir vymBaseDir;
44 extern QDir lastImageDir;
45 extern QDir lastFileDir;
47 extern Settings settings;
51 int VymModel::mapNum=0; // make instance
55 // cout << "Const VymModel\n";
57 rootItem->setModel (this);
63 cout << "Destr VymModel\n";
64 autosaveTimer->stop();
65 fileChangedTimer->stop();
69 void VymModel::clear()
71 selModel->clearSelection();
73 //QModelIndex ri=index(rootItem);
74 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
77 void VymModel::init ()
79 // We should have at least one map center to start with
80 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
85 // Also no scene yet (should not be needed anyway) FIXME-3 VM
98 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
99 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
100 mainWindow->updateHistory (undoSet);
103 makeTmpDirectories();
108 fileName=tr("unnamed");
110 blockReposition=false;
111 blockSaveState=false;
113 autosaveTimer=new QTimer (this);
114 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
116 fileChangedTimer=new QTimer (this);
117 fileChangedTimer->start(3000);
118 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
123 selectionBlocked=false;
130 // animations // FIXME-3 switch to new animation system
131 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
132 animationTicks=settings.readNumEntry("/animation/ticks",10);
133 animationInterval=settings.readNumEntry("/animation/interval",50);
135 animationTimer=new QTimer (this);
136 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
139 defLinkColor=QColor (0,0,255);
140 defXLinkColor=QColor (180,180,180);
141 linkcolorhint=LinkableMapObj::DefaultColor;
142 linkstyle=LinkableMapObj::PolyParabel;
144 defXLinkColor=QColor (230,230,230);
146 hidemode=TreeItem::HideNone;
152 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
155 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
156 //adaptor->setModel (this);
157 //connection.registerObject("/Car", car);
158 dbusConnection.registerService("org.insilmaril.VymModel");
159 dbusConnection.sessionBus().registerObject ("/Object1",this);
162 void VymModel::makeTmpDirectories()
164 // Create unique temporary directories
165 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
166 histPath = tmpMapDir+"/history";
172 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
177 bool VymModel::isRepositionBlocked()
179 return blockReposition;
182 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
184 //cout << "VM::updateActions \n";
185 // Tell mainwindow to update states of actions
186 mainWindow->updateActions();
191 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
193 // tmpdir temporary directory to which data will be written
194 // prefix mapname, which will be appended to images etc.
195 // writeflags Only write flags for "real" save of map, not undo
196 // offset offset of bbox of whole map in scene.
197 // Needed for XML export
206 case LinkableMapObj::Line:
209 case LinkableMapObj::Parabel:
212 case LinkableMapObj::PolyLine:
216 ls="StylePolyParabel";
220 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
222 if (linkcolorhint==LinkableMapObj::HeadingColor)
223 colhint=xml.attribut("linkColorHint","HeadingColor");
225 QString mapAttr=xml.attribut("version",vymVersion);
227 mapAttr+= xml.attribut("author",author) +
228 xml.attribut("comment",comment) +
229 xml.attribut("date",getDate()) +
230 xml.attribut("branchCount", QString().number(branchCount())) +
231 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
232 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
233 xml.attribut("linkStyle", ls ) +
234 xml.attribut("linkColor", defLinkColor.name() ) +
235 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
236 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
238 s+=xml.beginElement("vymmap",mapAttr);
241 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
242 standardFlagsMaster->resetUsedCounter();
244 // Reset the counters before saving
245 // TODO constr. of FIO creates lots of objects, better do this in some other way...
246 ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
248 // Build xml recursivly
249 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
250 // Save all mapcenters as complete map, if saveSel not set
251 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
254 if (saveSel->isBranchLikeType())
256 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
257 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
259 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
262 // Save local settings
263 s+=settings.getDataXML (destPath);
266 if (getSelectedItem() && !saveSel )
267 s+=xml.valueElement("select",getSelectString());
270 s+=xml.endElement("vymmap");
272 //cout << s.toStdString() << endl;
274 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
278 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
282 for (int i=0; i<rootItem->branchCount(); i++)
283 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
287 void VymModel::setFilePath(QString fpath, QString destname)
289 if (fpath.isEmpty() || fpath=="")
296 filePath=fpath; // becomes absolute path
297 fileName=fpath; // gets stripped of path
298 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
300 // If fpath is not an absolute path, complete it
301 filePath=QDir(fpath).absPath();
302 fileDir=filePath.left (1+filePath.findRev ("/"));
304 // Set short name, too. Search from behind:
305 int i=fileName.findRev("/");
306 if (i>=0) fileName=fileName.remove (0,i+1);
308 // Forget the .vym (or .xml) for name of map
309 mapName=fileName.left(fileName.findRev(".",-1,true) );
313 void VymModel::setFilePath(QString fpath)
315 setFilePath (fpath,fpath);
318 QString VymModel::getFilePath()
323 QString VymModel::getFileName()
328 QString VymModel::getMapName()
333 QString VymModel::getDestPath()
338 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
340 ErrorCode err=success;
342 parseBaseHandler *handler;
346 case VymMap: handler=new parseVYMHandler; break;
347 case FreemindMap : handler=new parseFreemindHandler; break;
349 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
350 "Unknown FileType in VymModel::load()");
354 bool zipped_org=zipped;
358 selModel->clearSelection();
359 // FIXME-2 VM not needed??? model->setMapEditor(this);
360 // (map state is set later at end of load...)
363 BranchItem *bi=getSelectedBranchItem();
364 if (!bi) return aborted;
365 if (lmode==ImportAdd)
366 saveStateChangingPart(
369 QString("addMapInsert (%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 saveStateChangingPart(
375 QString("addMapReplace(%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
380 // Create temporary directory for packing
382 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
385 QMessageBox::critical( 0, tr( "Critical Load Error" ),
386 tr("Couldn't create temporary directory before load\n"));
391 err=unzipDir (tmpZipDir,fname);
401 // Look for mapname.xml
402 xmlfile= fname.left(fname.findRev(".",-1,true));
403 xmlfile=xmlfile.section( '/', -1 );
404 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
405 if (!mfile.exists() )
407 // mapname.xml does not exist, well,
408 // maybe someone renamed the mapname.vym file...
409 // Try to find any .xml in the toplevel
410 // directory of the .vym file
411 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
412 if (flist.count()==1)
414 // Only one entry, take this one
415 xmlfile=tmpZipDir + "/"+flist.first();
418 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
419 *it=tmpZipDir + "/" + *it;
420 // TODO Multiple entries, load all (but only the first one into this ME)
421 //mainWindow->fileLoadFromTmp (flist);
422 //returnCode=1; // Silently forget this attempt to load
423 qWarning ("MainWindow::load (fn) multimap found...");
426 if (flist.isEmpty() )
428 QMessageBox::critical( 0, tr( "Critical Load Error" ),
429 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
432 } //file doesn't exist
434 xmlfile=mfile.name();
437 QFile file( xmlfile);
439 // I am paranoid: file should exist anyway
440 // according to check in mainwindow.
443 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
444 tr(QString("Couldn't open map %1").arg(file.name())));
448 bool blockSaveStateOrg=blockSaveState;
449 blockReposition=true;
451 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
452 QXmlInputSource source( file);
453 QXmlSimpleReader reader;
454 reader.setContentHandler( handler );
455 reader.setErrorHandler( handler );
456 handler->setModel ( this);
459 // We need to set the tmpDir in order to load files with rel. path
464 tmpdir=fname.left(fname.findRev("/",-1));
465 handler->setTmpDir (tmpdir);
466 handler->setInputFile (file.name());
467 handler->setLoadMode (lmode);
468 bool ok = reader.parse( source );
469 blockReposition=false;
470 blockSaveState=blockSaveStateOrg;
471 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
475 reposition(); // FIXME-2 VM reposition the view instead...
476 emitSelectionChanged();
482 autosaveTimer->stop();
485 // Reset timestamp to check for later updates of file
486 fileChangedTime=QFileInfo (destPath).lastModified();
489 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
490 tr( handler->errorProtocol() ) );
492 // Still return "success": the map maybe at least
493 // partially read by the parser
498 removeDir (QDir(tmpZipDir));
500 // Restore original zip state
507 ErrorCode VymModel::save (const SaveMode &savemode)
511 QString safeFilePath;
513 ErrorCode err=success;
517 mapFileName=mapName+".xml";
519 // use name given by user, even if he chooses .doc
520 mapFileName=fileName;
522 // Look, if we should zip the data:
525 QMessageBox mb( vymName,
526 tr("The map %1\ndid not use the compressed "
527 "vym file format.\nWriting it uncompressed will also write images \n"
528 "and flags and thus may overwrite files in the "
529 "given directory\n\nDo you want to write the map").arg(filePath),
530 QMessageBox::Warning,
531 QMessageBox::Yes | QMessageBox::Default,
533 QMessageBox::Cancel | QMessageBox::Escape);
534 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
535 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
536 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
539 case QMessageBox::Yes:
540 // save compressed (default file format)
543 case QMessageBox::No:
547 case QMessageBox::Cancel:
554 // First backup existing file, we
555 // don't want to add to old zip archives
559 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
561 QString backupFileName(destPath + "~");
562 QFile backupFile(backupFileName);
563 if (backupFile.exists() && !backupFile.remove())
565 QMessageBox::warning(0, tr("Save Error"),
566 tr("%1\ncould not be removed before saving").arg(backupFileName));
568 else if (!f.rename(backupFileName))
570 QMessageBox::warning(0, tr("Save Error"),
571 tr("%1\ncould not be renamed before saving").arg(destPath));
578 // Create temporary directory for packing
580 tmpZipDir=makeTmpDir (ok,"vym-zip");
583 QMessageBox::critical( 0, tr( "Critical Load Error" ),
584 tr("Couldn't create temporary directory before save\n"));
588 safeFilePath=filePath;
589 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
592 // Create mapName and fileDir
593 makeSubDirs (fileDir);
596 if (savemode==CompleteMap || selModel->selection().isEmpty())
599 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
602 autosaveTimer->stop();
607 if (selectionType()==TreeItem::Image)
610 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
611 // TODO take care of multiselections
614 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
617 qWarning ("ME::saveStringToDisk failed!");
623 if (err==success) err=zipDir (tmpZipDir,destPath);
626 removeDir (QDir(tmpZipDir));
628 // Restore original filepath outside of tmp zip dir
629 setFilePath (safeFilePath);
633 fileChangedTime=QFileInfo (destPath).lastModified();
637 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree
639 QString pathDir=path.left(path.findRev("/"));
645 // We need to parse saved XML data
646 parseVYMHandler handler;
647 QXmlInputSource source( file);
648 QXmlSimpleReader reader;
649 reader.setContentHandler( &handler );
650 reader.setErrorHandler( &handler );
651 handler.setModel ( this);
652 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
653 if (undoSel.isEmpty())
657 handler.setLoadMode (NewMap);
661 handler.setLoadMode (ImportReplace);
663 blockReposition=true;
664 bool ok = reader.parse( source );
665 blockReposition=false;
668 // This should never ever happen
669 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
670 handler.errorProtocol());
673 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
676 void VymModel::addMapInsertInt (const QString &path, int pos)
678 /* FIXME-2 addMapInsertInt not ported yet
679 BranchObj *sel=getSelectedBranch();
682 QString pathDir=path.left(path.findRev("/"));
688 // We need to parse saved XML data
689 parseVYMHandler handler;
690 QXmlInputSource source( file);
691 QXmlSimpleReader reader;
692 reader.setContentHandler( &handler );
693 reader.setErrorHandler( &handler );
694 handler.setModel (this);
695 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
696 handler.setLoadMode (ImportAdd);
697 blockReposition=true;
698 bool ok = reader.parse( source );
699 blockReposition=false;
702 // This should never ever happen
703 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
704 handler.errorProtocol());
706 if (sel->getDepth()>0)
707 sel->getLastBranch()->linkTo (sel,pos);
709 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
714 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
716 ImageItem *ii=createImage(dst);
726 void VymModel::loadFloatImage ()
728 BranchItem *selbi=getSelectedBranchItem();
732 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
733 fd->setMode (Q3FileDialog::ExistingFiles);
734 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
735 ImagePreview *p =new ImagePreview (fd);
736 fd->setContentsPreviewEnabled( TRUE );
737 fd->setContentsPreview( p, p );
738 fd->setPreviewMode( Q3FileDialog::Contents );
739 fd->setCaption(vymName+" - " +tr("Load image"));
740 fd->setDir (lastImageDir);
743 if ( fd->exec() == QDialog::Accepted )
745 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
746 lastImageDir=QDir (fd->dirPath());
749 for (int j=0; j<fd->selectedFiles().count(); j++)
751 s=fd->selectedFiles().at(j);
752 ii=loadFloatImageInt (selbi,s);
753 //FIXME-3 check savestate for loadImage
759 QString ("loadImage (%1)").arg(s ),
760 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
763 // TODO loadFIO error handling
764 qWarning ("Failed to load "+s);
772 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
777 void VymModel::saveFloatImage ()
779 ImageItem *ii=getSelectedImageItem();
782 QFileDialog *fd=new QFileDialog( NULL);
783 fd->setFilters (imageIO.getFilters());
784 fd->setCaption(vymName+" - " +tr("Save image"));
785 fd->setFileMode( QFileDialog::AnyFile );
786 fd->setDirectory (lastImageDir);
787 // fd->setSelection (fio->getOriginalFilename());
791 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
793 fn=fd->selectedFiles().at(0);
794 if (QFile (fn).exists() )
796 QMessageBox mb( vymName,
797 tr("The file %1 exists already.\n"
798 "Do you want to overwrite it?").arg(fn),
799 QMessageBox::Warning,
800 QMessageBox::Yes | QMessageBox::Default,
801 QMessageBox::Cancel | QMessageBox::Escape,
802 QMessageBox::NoButton );
804 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
805 mb.setButtonText( QMessageBox::No, tr("Cancel"));
808 case QMessageBox::Yes:
811 case QMessageBox::Cancel:
818 saveFloatImageInt (ii,fd->selectedFilter(),fn );
825 void VymModel::importDirInt(BranchObj *dst, QDir d)
827 /* FIXME-2 importDirInt not ported yet
828 BranchObj *bo=getSelectedBranch();
831 // Traverse directories
832 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
833 QFileInfoList list = d.entryInfoList();
836 for (int i = 0; i < list.size(); ++i)
839 if (fi.fileName() != "." && fi.fileName() != ".." )
842 bo=dst->getLastBranch();
843 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
844 bi->setHeading (fi.fileName() ); // FIXME-3 check this
845 bo->setColor (QColor("blue"));
847 if ( !d.cd(fi.fileName()) )
848 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
851 // Recursively add subdirs
858 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
859 list = d.entryInfoList();
861 for (int i = 0; i < list.size(); ++i)
865 bo=dst->getLastBranch();
866 bo->setHeading (fi.fileName() );
867 bo->setColor (QColor("black"));
868 if (fi.fileName().right(4) == ".vym" )
869 bo->setVymLink (fi.filePath());
875 void VymModel::importDirInt (const QString &s) // FIXME-2
878 BranchObj *bo=getSelectedBranch();
881 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
889 void VymModel::importDir() //FIXME-2
892 BranchObj *bo=getSelectedBranch();
896 filters <<"VYM map (*.vym)";
897 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
898 fd->setMode (QFileDialog::DirectoryOnly);
899 fd->setFilters (filters);
900 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
904 if ( fd->exec() == QDialog::Accepted )
906 importDirInt (fd->selectedFile() );
908 //FIXME-3 VM needed? scene()->update();
915 void VymModel::autosave()
920 cout << "VymModel::autosave rejected due to missing filePath\n";
923 QDateTime now=QDateTime().currentDateTime();
925 // Disable autosave, while we have gone back in history
926 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
927 if (redosAvail>0) return;
929 // Also disable autosave for new map without filename
930 if (filePath.isEmpty()) return;
933 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
935 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
936 mainWindow->fileSave (this);
939 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
944 void VymModel::fileChanged()
946 // Check if file on disk has changed meanwhile
947 if (!filePath.isEmpty())
949 QDateTime tmod=QFileInfo (filePath).lastModified();
950 if (tmod>fileChangedTime)
952 // FIXME-2 VM switch to current mapeditor and finish lineedits...
953 QMessageBox mb( vymName,
954 tr("The file of the map on disk has changed:\n\n"
955 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
956 QMessageBox::Question,
958 QMessageBox::Cancel | QMessageBox::Default,
959 QMessageBox::NoButton );
961 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
962 mb.setButtonText( QMessageBox::No, tr("Ignore"));
965 case QMessageBox::Yes:
967 load (filePath,NewMap,fileType);
968 case QMessageBox::Cancel:
969 fileChangedTime=tmod; // allow autosave to overwrite newer file!
975 bool VymModel::isDefault()
980 void VymModel::makeDefault()
986 bool VymModel::hasChanged()
991 void VymModel::setChanged()
994 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
998 latestAddedItem=NULL;
1002 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1004 if (!lmo || !lmo->getTreeItem() ) return QString();
1005 return getObjectName (lmo->getTreeItem() );
1009 QString VymModel::getObjectName (TreeItem *ti)
1012 if (!ti) return QString("Error: NULL has no name!");
1014 if (s=="") s="unnamed";
1016 if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter??
1017 return QString("branch (%1)").arg(s);
1018 if (ti->getType()==TreeItem::Image)
1019 return QString ("image (%1)").arg(ti->getHeading());
1020 return QString("Unknown type has no name!");
1023 void VymModel::redo()
1025 // Can we undo at all?
1026 if (redosAvail<1) return;
1028 bool blockSaveStateOrg=blockSaveState;
1029 blockSaveState=true;
1033 if (undosAvail<stepsTotal) undosAvail++;
1035 if (curStep>stepsTotal) curStep=1;
1036 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1037 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1038 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1039 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1040 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1041 QString version=undoSet.readEntry ("/history/version");
1043 /* TODO Maybe check for version, if we save the history
1044 if (!checkVersion(version))
1045 QMessageBox::warning(0,tr("Warning"),
1046 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1049 // Find out current undo directory
1050 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1054 cout << "VymModel::redo() begin\n";
1055 cout << " undosAvail="<<undosAvail<<endl;
1056 cout << " redosAvail="<<redosAvail<<endl;
1057 cout << " curStep="<<curStep<<endl;
1058 cout << " ---------------------------"<<endl;
1059 cout << " comment="<<comment.toStdString()<<endl;
1060 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1061 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1062 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1063 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1064 cout << " ---------------------------"<<endl<<endl;
1067 // select object before redo
1068 if (!redoSelection.isEmpty())
1069 select (redoSelection);
1072 parseAtom (redoCommand);
1075 blockSaveState=blockSaveStateOrg;
1077 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1078 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1079 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1080 undoSet.writeSettings(histPath);
1082 mainWindow->updateHistory (undoSet);
1085 /* TODO remove testing
1086 cout << "ME::redo() end\n";
1087 cout << " undosAvail="<<undosAvail<<endl;
1088 cout << " redosAvail="<<redosAvail<<endl;
1089 cout << " curStep="<<curStep<<endl;
1090 cout << " ---------------------------"<<endl<<endl;
1096 bool VymModel::isRedoAvailable()
1098 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1104 void VymModel::undo()
1106 // Can we undo at all?
1107 if (undosAvail<1) return;
1109 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1111 bool blockSaveStateOrg=blockSaveState;
1112 blockSaveState=true;
1114 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1115 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1116 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1117 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1118 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1119 QString version=undoSet.readEntry ("/history/version");
1121 /* TODO Maybe check for version, if we save the history
1122 if (!checkVersion(version))
1123 QMessageBox::warning(0,tr("Warning"),
1124 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1127 // Find out current undo directory
1128 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1130 // select object before undo
1131 if (!undoSelection.isEmpty())
1132 select (undoSelection);
1136 cout << "VymModel::undo() begin\n";
1137 cout << " undosAvail="<<undosAvail<<endl;
1138 cout << " redosAvail="<<redosAvail<<endl;
1139 cout << " curStep="<<curStep<<endl;
1140 cout << " ---------------------------"<<endl;
1141 cout << " comment="<<comment.toStdString()<<endl;
1142 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1143 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1144 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1145 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1146 cout << " ---------------------------"<<endl<<endl;
1148 parseAtom (undoCommand);
1153 if (curStep<1) curStep=stepsTotal;
1157 blockSaveState=blockSaveStateOrg;
1158 /* TODO remove testing
1159 cout << "VymModel::undo() end\n";
1160 cout << " undosAvail="<<undosAvail<<endl;
1161 cout << " redosAvail="<<redosAvail<<endl;
1162 cout << " curStep="<<curStep<<endl;
1163 cout << " ---------------------------"<<endl<<endl;
1166 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1167 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1168 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1169 undoSet.writeSettings(histPath);
1171 mainWindow->updateHistory (undoSet);
1173 emitSelectionChanged();
1176 bool VymModel::isUndoAvailable()
1178 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1184 void VymModel::gotoHistoryStep (int i)
1186 // Restore variables
1187 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1188 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1190 if (i<0) i=undosAvail+redosAvail;
1192 // Clicking above current step makes us undo things
1195 for (int j=0; j<undosAvail-i; j++) undo();
1198 // Clicking below current step makes us redo things
1200 for (int j=undosAvail; j<i; j++)
1202 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1206 // And ignore clicking the current row ;-)
1210 QString VymModel::getHistoryPath()
1212 QString histName(QString("history-%1").arg(curStep));
1213 return (tmpMapDir+"/"+histName);
1216 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1218 sendData(redoCom); //FIXME-3 testing
1223 if (blockSaveState) return;
1225 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1227 // Find out current undo directory
1228 if (undosAvail<stepsTotal) undosAvail++;
1230 if (curStep>stepsTotal) curStep=1;
1232 QString backupXML="";
1233 QString histDir=getHistoryPath();
1234 QString bakMapPath=histDir+"/map.xml";
1236 // Create histDir if not available
1239 makeSubDirs (histDir);
1241 // Save depending on how much needs to be saved
1243 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1245 QString undoCommand="";
1246 if (savemode==UndoCommand)
1248 undoCommand=undoCom;
1250 else if (savemode==PartOfMap )
1252 undoCommand=undoCom;
1253 undoCommand.replace ("PATH",bakMapPath);
1257 if (!backupXML.isEmpty())
1258 // Write XML Data to disk
1259 saveStringToDisk (bakMapPath,backupXML);
1261 // We would have to save all actions in a tree, to keep track of
1262 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1265 // Write the current state to disk
1266 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1267 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1268 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1269 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1270 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1271 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1272 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1273 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1274 undoSet.setEntry (QString("/history/version"),vymVersion);
1275 undoSet.writeSettings(histPath);
1279 // TODO remove after testing
1280 //cout << " into="<< histPath.toStdString()<<endl;
1281 cout << " stepsTotal="<<stepsTotal<<
1282 ", undosAvail="<<undosAvail<<
1283 ", redosAvail="<<redosAvail<<
1284 ", curStep="<<curStep<<endl;
1285 cout << " ---------------------------"<<endl;
1286 cout << " comment="<<comment.toStdString()<<endl;
1287 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1288 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1289 cout << " redoCom="<<redoCom.toStdString()<<endl;
1290 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1291 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1292 cout << " ---------------------------"<<endl;
1295 mainWindow->updateHistory (undoSet);
1301 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1303 // save the selected part of the map, Undo will replace part of map
1304 QString undoSelection="";
1306 undoSelection=getSelectString(undoSel);
1308 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1309 QString redoSelection="";
1311 redoSelection=getSelectString(undoSel);
1313 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1316 saveState (PartOfMap,
1317 undoSelection, "addMapReplace (\"PATH\")",
1323 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1327 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1330 QString undoSelection=getSelectString (redoSel->parent() );
1331 QString redoSelection=getSelectString(redoSel);
1332 if (redoSel->getType()==TreeItem::Branch)
1334 // save the selected branch of the map, Undo will insert part of map
1335 saveState (PartOfMap,
1336 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1337 redoSelection, "delete ()",
1344 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1346 // "Normal" savestate: save commands, selections and comment
1347 // so just save commands for undo and redo
1348 // and use current selection
1350 QString redoSelection="";
1351 if (redoSel) redoSelection=getSelectString(redoSel);
1352 QString undoSelection="";
1353 if (undoSel) undoSelection=getSelectString(undoSel);
1355 saveState (UndoCommand,
1362 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1364 // "Normal" savestate: save commands, selections and comment
1365 // so just save commands for undo and redo
1366 // and use current selection
1367 saveState (UndoCommand,
1374 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1376 // "Normal" savestate applied to model (no selection needed):
1377 // save commands and comment
1378 saveState (UndoCommand,
1386 QGraphicsScene* VymModel::getScene ()
1391 TreeItem* VymModel::findBySelectString(QString s)
1393 if (s.isEmpty() ) return NULL;
1395 // Old maps don't have multiple mapcenters and don't save full path
1396 if (s.left(2) !="mc")
1399 QStringList parts=s.split (",");
1402 TreeItem *ti=rootItem;
1404 while (!parts.isEmpty() )
1406 typ=parts.first().left(2);
1407 n=parts.first().right(parts.first().length() - 3).toInt();
1408 parts.removeFirst();
1409 if (typ=="mc" || typ=="bo")
1410 ti=ti->getBranchNum (n);
1414 ti=ti->getImageNum (n);
1420 TreeItem* VymModel::findID (const QString &s)
1423 for (int i=0; i<rootItem->branchCount(); i++)
1425 ti=rootItem->getBranchNum(i)->findID (s);
1431 //////////////////////////////////////////////
1433 //////////////////////////////////////////////
1434 void VymModel::setVersion (const QString &s)
1439 void VymModel::setAuthor (const QString &s)
1442 QString ("setMapAuthor (\"%1\")").arg(author),
1443 QString ("setMapAuthor (\"%1\")").arg(s),
1444 QString ("Set author of map to \"%1\"").arg(s)
1449 QString VymModel::getAuthor()
1454 void VymModel::setComment (const QString &s)
1457 QString ("setMapComment (\"%1\")").arg(comment),
1458 QString ("setMapComment (\"%1\")").arg(s),
1459 QString ("Set comment of map")
1464 QString VymModel::getComment ()
1469 QString VymModel::getDate ()
1471 return QDate::currentDate().toString ("yyyy-MM-dd");
1474 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1477 BranchItem *cur=NULL;
1478 BranchItem *prev=NULL;
1488 void VymModel::setHeading(const QString &s)
1490 BranchItem *selbi=getSelectedBranchItem();
1495 "setHeading (\""+selbi->getHeading()+"\")",
1497 "setHeading (\""+s+"\")",
1498 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1499 selbi->setHeading(s );
1500 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1502 emitSelectionChanged();
1506 QString VymModel::getHeading()
1508 TreeItem *selti=getSelectedItem();
1510 return selti->getHeading();
1515 BranchItem* VymModel::findText (QString s, bool cs)
1517 QTextDocument::FindFlags flags=0;
1518 if (cs) flags=QTextDocument::FindCaseSensitively;
1521 { // Nothing found or new find process
1523 // nothing found, start again
1527 next (findCurrent,findPrevious);
1529 bool searching=true;
1530 bool foundNote=false;
1531 while (searching && !EOFind)
1535 // Searching in Note
1536 if (findCurrent->getNote().contains(s,cs))
1538 select (findCurrent);
1540 if (getSelectedBranch()!=itFind)
1543 emitShowSelection();
1546 if (textEditor->findText(s,flags))
1552 // Searching in Heading
1553 if (searching && findCurrent->getHeading().contains (s,cs) )
1555 select(findCurrent);
1561 if (!next(findCurrent,findPrevious) )
1564 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1567 return getSelectedBranchItem();
1572 void VymModel::findReset()
1573 { // Necessary if text to find changes during a find process
1579 void VymModel::setScene (QGraphicsScene *s)
1581 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1582 //init(); // Here we have a mapScene set,
1583 // which is (still) needed to create MapCenters
1586 void VymModel::setURL(const QString &url)
1588 TreeItem *selti=getSelectedItem();
1591 QString oldurl=selti->getURL();
1592 selti->setURL (url);
1595 QString ("setURL (\"%1\")").arg(oldurl),
1597 QString ("setURL (\"%1\")").arg(url),
1598 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1601 emitDataHasChanged (selti);
1602 emitShowSelection();
1606 QString VymModel::getURL()
1608 TreeItem *selti=getSelectedItem();
1610 return selti->getURL();
1615 QStringList VymModel::getURLs()
1618 BranchItem *selbi=getSelectedBranchItem();
1619 BranchItem *cur=selbi;
1620 BranchItem *prev=NULL;
1623 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1624 cur=next (cur,prev,selbi);
1630 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1632 BranchItem *bi=getSelectedBranchItem();
1635 BranchObj *bo=(BranchObj*)(bi->getLMO());
1638 QString s=bo->getFrameTypeName();
1639 bo->setFrameType (t);
1640 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1641 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1643 bo->updateLinkGeometry();
1648 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1650 BranchItem *bi=getSelectedBranchItem();
1653 BranchObj *bo=(BranchObj*)(bi->getLMO());
1656 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1657 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1658 bo->setFrameType (s);
1660 bo->updateLinkGeometry();
1665 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1668 BranchItem *bi=getSelectedBranchItem();
1671 BranchObj *bo=(BranchObj*)(bi->getLMO());
1674 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1675 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1676 bo->setFramePenColor (c);
1681 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1683 BranchItem *bi=getSelectedBranchItem();
1686 BranchObj *bo=(BranchObj*)(bi->getLMO());
1689 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1690 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1691 bo->setFrameBrushColor (c);
1696 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1698 BranchItem *bi=getSelectedBranchItem();
1701 BranchObj *bo=(BranchObj*)(bi->getLMO());
1704 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1705 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1706 bo->setFramePadding (i);
1708 bo->updateLinkGeometry();
1713 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1715 BranchItem *bi=getSelectedBranchItem();
1718 BranchObj *bo=(BranchObj*)(bi->getLMO());
1721 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1722 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1723 bo->setFrameBorderWidth (i);
1725 bo->updateLinkGeometry();
1730 void VymModel::setIncludeImagesVer(bool b)
1732 BranchItem *bi=getSelectedBranchItem();
1735 QString u= b ? "false" : "true";
1736 QString r=!b ? "false" : "true";
1740 QString("setIncludeImagesVertically (%1)").arg(u),
1742 QString("setIncludeImagesVertically (%1)").arg(r),
1743 QString("Include images vertically in %1").arg(getObjectName(bi))
1745 bi->setIncludeImagesVer(b);
1746 emitDataHasChanged ( bi);
1751 void VymModel::setIncludeImagesHor(bool b)
1753 BranchItem *bi=getSelectedBranchItem();
1756 QString u= b ? "false" : "true";
1757 QString r=!b ? "false" : "true";
1761 QString("setIncludeImagesHorizontally (%1)").arg(u),
1763 QString("setIncludeImagesHorizontally (%1)").arg(r),
1764 QString("Include images horizontally in %1").arg(getObjectName(bi))
1766 bi->setIncludeImagesHor(b);
1767 emitDataHasChanged ( bi);
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 AttributeItem* VymModel::addAttribute()
1988 cout << "VM::addAttribute\n";
1990 TreeItem *selti=getSelectedItem();
1993 QList<QVariant> cData;
1994 cData << "new attribute" << "undef"<<"undef";
1995 AttributeItem *a=new AttributeItem (cData);
1997 emit (layoutAboutToBeChanged() );
1999 QModelIndex parix=index(selti);
2000 int n=selti->getRowNumAppend (a);
2001 beginInsertRows (parix,n,n+1);
2002 selti->appendChild (a);
2005 emit (layoutChanged() );
2013 BranchItem* VymModel::addMapCenter ()
2015 BranchItem *bi=addMapCenter (contextPos);
2017 emitShowSelection();
2022 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2023 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2028 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2029 // createMapCenter could then probably be merged with createBranch
2033 QModelIndex parix=index(rootItem);
2035 int n=rootItem->branchCount();
2037 emit (layoutAboutToBeChanged() );
2038 beginInsertRows (parix,n,n+1);
2040 QList<QVariant> cData;
2041 cData << "VM:addMapCenter" << "undef"<<"undef";
2042 BranchItem *newbi=new BranchItem (cData);
2043 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2044 rootItem->appendChild (newbi);
2047 emit (layoutChanged() );
2050 newbi->setPositionMode (MapItem::Absolute);
2051 newbi->createMapObj(mapScene);
2056 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2058 // Depending on pos:
2059 // -3 insert in children of parent above selection
2060 // -2 add branch to selection
2061 // -1 insert in children of parent below selection
2062 // 0..n insert in children of parent at pos
2065 QList<QVariant> cData;
2066 cData << "new" << "undef"<<"undef";
2071 BranchItem *newbi=new BranchItem (cData);
2072 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2074 emit (layoutAboutToBeChanged() );
2080 n=parbi->getRowNumAppend (newbi);
2081 beginInsertRows (parix,n,n+1);
2082 parbi->appendChild (newbi);
2084 }else if (num==-1 || num==-3)
2086 // insert below selection
2087 parbi=(BranchItem*)dst->parent();
2090 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2091 beginInsertRows (parix,n,n);
2092 parbi->insertBranch(n,newbi);
2095 emit (layoutChanged() );
2097 // save scroll state. If scrolled, automatically select
2098 // new branch in order to tmp unscroll parent...
2099 newbi->createMapObj(mapScene);
2104 BranchItem* VymModel::addNewBranch(int pos)
2106 // Different meaning than num in addNewBranchInt!
2110 BranchItem *newbi=NULL;
2111 BranchItem *selbi=getSelectedBranchItem();
2115 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2117 newbi=addNewBranchInt (selbi,pos-2);
2125 QString ("addBranch (%1)").arg(pos),
2126 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2129 // emitSelectionChanged(); FIXME-3
2130 latestAddedItem=newbi;
2131 // In Network mode, the client needs to know where the new branch is,
2132 // so we have to pass on this information via saveState.
2133 // TODO: Get rid of this positioning workaround
2134 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2135 sendData ("selectLatestAdded ()");
2136 sendData (QString("move %1").arg(ps));
2145 BranchItem* VymModel::addNewBranchBefore()
2147 BranchItem *newbi=NULL;
2148 BranchItem *selbi=getSelectedBranchItem();
2149 if (selbi && selbi->getType()==TreeItem::Branch)
2150 // We accept no MapCenter here, so we _have_ a parent
2152 //QPointF p=bo->getRelPos();
2155 // add below selection
2156 newbi=addNewBranchInt (selbi,-1);
2160 //newbi->move2RelPos (p);
2162 // Move selection to new branch
2163 relinkBranch (selbi,newbi,0);
2165 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2166 QString ("Add branch before %1").arg(getObjectName(selbi)));
2168 // FIXME-3 needed? reposition();
2169 // emitSelectionChanged(); FIXME-3
2175 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2179 if (branch->depth()==0)
2181 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2183 emit (layoutAboutToBeChanged() );
2184 BranchItem *branchpi=(BranchItem*)branch->parent();
2185 // Remove at current position
2186 int n=branch->childNum();
2187 beginRemoveRows (index(branchpi),n,n);
2188 branchpi->removeChild (n);
2191 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2193 // Append as last branch to dst
2194 if (dst->branchCount()==0)
2197 n=dst->getFirstBranch()->childNumber();
2198 beginInsertRows (index(dst),n+pos,n+pos);
2199 dst->insertBranch (pos,branch);
2202 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2203 branch->updateStyles();
2205 emit (layoutChanged() );
2206 reposition(); // both for moveUp/Down and relinking
2207 if (dst->isScrolled() )
2210 branch->updateVisibility();
2219 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2223 emit (layoutAboutToBeChanged() );
2225 BranchItem *pi=(BranchItem*)(image->parent());
2226 QString oldParString=getSelectString (pi);
2227 // Remove at current position
2228 int n=image->childNum();
2229 beginRemoveRows (index(pi),n,n);
2230 pi->removeChild (n);
2234 QModelIndex dstix=index(dst);
2235 n=dst->getRowNumAppend (image);
2236 beginInsertRows (dstix,n,n+1);
2237 dst->appendChild (image);
2240 // Set new parent also for lmo
2241 if (image->getLMO() && dst->getLMO() )
2242 image->getLMO()->setParObj (dst->getLMO() );
2244 emit (layoutChanged() );
2247 QString("relinkTo (\"%1\")").arg(oldParString),
2249 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2250 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2256 void VymModel::deleteSelection() // FIXME-2 include fix for deleted mapcenters from 1.12.4
2258 BranchItem *selbi=getSelectedBranchItem();
2260 if (selbi && selbi->isBranchLikeType() )
2263 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2265 TreeItem *pi=deleteItem (selbi);
2269 emitShowSelection();
2273 ImageItem *ii=getSelectedImageItem();
2276 BranchItem *pi=(BranchItem*)(ii->parent());
2277 saveStateChangingPart(
2281 QString("Delete %1").arg(getObjectName(ii))
2287 emitShowSelection();
2292 void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters
2295 BranchItem *selbi=getSelectedBranchItem();
2299 // Don't use this on mapcenter
2300 if (selbi->depth()<2) return;
2302 pi=(BranchItem*)(selbi->parent());
2303 // Check if we have childs at all to keep
2304 if (selbi->branchCount()==0)
2311 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2312 saveStateChangingPart(
2315 "deleteKeepChildren ()",
2316 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2319 QString sel=getSelectString(selbi);
2321 int pos=selbi->num();
2322 BranchItem *bi=selbi->getFirstBranch();
2325 relinkBranch (bi,pi,pos);
2326 bi=selbi->getFirstBranch();
2332 BranchObj *bo=getSelectedBranchObj();
2335 bo->move2RelPos (p);
2341 void VymModel::deleteChildren()
2344 BranchItem *selbi=getSelectedBranchItem();
2347 saveStateChangingPart(
2350 "deleteChildren ()",
2351 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2353 emit (layoutAboutToBeChanged() );
2355 QModelIndex ix=index (selbi);
2356 int n=selbi->branchCount()-1;
2357 beginRemoveRows (ix,0,n);
2358 removeRows (0,n+1,ix);
2360 if (selbi->isScrolled()) selbi->unScroll();
2361 emit (layoutChanged() );
2366 TreeItem* VymModel::deleteItem (TreeItem *ti)
2370 TreeItem *pi=ti->parent();
2371 QModelIndex parentIndex=index(pi);
2373 emit (layoutAboutToBeChanged() );
2375 int n=ti->childNum();
2376 beginRemoveRows (parentIndex,n,n);
2377 removeRows (n,1,parentIndex);
2381 emit (layoutChanged() );
2382 if (pi->depth()>0) return pi;
2387 bool VymModel::scrollBranch(BranchItem *bi)
2391 if (bi->isScrolled()) return false;
2392 if (bi->branchCount()==0) return false;
2393 if (bi->depth()==0) return false;
2394 if (bi->toggleScroll())
2401 QString ("%1 ()").arg(u),
2403 QString ("%1 ()").arg(r),
2404 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2406 emitDataHasChanged(bi);
2407 emitSelectionChanged();
2408 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2415 bool VymModel::unscrollBranch(BranchItem *bi)
2419 if (!bi->isScrolled()) return false;
2420 if (bi->branchCount()==0) return false;
2421 if (bi->depth()==0) return false;
2428 QString ("%1 ()").arg(u),
2430 QString ("%1 ()").arg(r),
2431 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2434 emitDataHasChanged(bi);
2435 emitSelectionChanged();
2437 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2443 void VymModel::toggleScroll()
2445 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2446 if (bi && bi->isBranchLikeType() )
2448 if (bi->isScrolled())
2449 unscrollBranch (bi);
2453 // saveState is called in above functions
2456 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2460 BranchObj *bo=getSelectedBranch();
2466 if (bo->isScrolled()) unscrollBranch (bo);
2473 void VymModel::emitExpandAll()
2475 emit (expandAll() );
2478 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2480 BranchItem *bi=getSelectedBranchItem();
2484 if (bi->isActiveStandardFlag(name))
2496 QString("%1 (\"%2\")").arg(u).arg(name),
2498 QString("%1 (\"%2\")").arg(r).arg(name),
2499 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2500 bi->toggleStandardFlag (name, master);
2502 emitSelectionChanged();
2506 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2509 BranchObj *bo=getSelectedBranch();
2512 FloatImageObj *fio=bo->addFloatImage();
2514 fio->setOriginalFilename("No original filename (image added by dropevent)");
2515 QString s=getSelectString(bo);
2516 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2517 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2519 // FIXME-3 VM needed? scene()->update();
2525 void VymModel::colorBranch (QColor c)
2527 BranchItem *selbi=getSelectedBranchItem();
2532 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2534 QString ("colorBranch (\"%1\")").arg(c.name()),
2535 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2537 selbi->setHeadingColor(c); // color branch
2541 void VymModel::colorSubtree (QColor c)
2543 BranchItem *selbi=getSelectedBranchItem();
2546 saveStateChangingPart(
2549 QString ("colorSubtree (\"%1\")").arg(c.name()),
2550 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2552 BranchItem *prev=NULL;
2553 BranchItem *cur=selbi;
2556 cur->setHeadingColor(c); // color links, color children
2557 cur=next (cur,prev,selbi);
2563 QColor VymModel::getCurrentHeadingColor()
2565 BranchItem *selbi=getSelectedBranchItem();
2566 if (selbi) return selbi->getHeadingColor();
2568 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2574 void VymModel::editURL()
2576 TreeItem *selti=getSelectedItem();
2580 QString text = QInputDialog::getText(
2581 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2582 selti->getURL(), &ok, NULL);
2584 // user entered something and pressed OK
2589 void VymModel::editLocalURL()
2591 TreeItem *selti=getSelectedItem();
2594 QStringList filters;
2595 filters <<"All files (*)";
2596 filters << tr("Text","Filedialog") + " (*.txt)";
2597 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2598 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2599 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2600 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2601 fd->setFilters (filters);
2602 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2603 fd->setDirectory (lastFileDir);
2604 if (! selti->getVymLink().isEmpty() )
2605 fd->selectFile( selti->getURL() );
2608 if ( fd->exec() == QDialog::Accepted )
2610 lastFileDir=QDir (fd->directory().path());
2611 setURL (fd->selectedFile() );
2617 void VymModel::editHeading2URL()
2619 TreeItem *selti=getSelectedItem();
2621 setURL (selti->getHeading());
2624 void VymModel::editBugzilla2URL()
2626 TreeItem *selti=getSelectedItem();
2629 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2634 void VymModel::editFATE2URL()
2636 TreeItem *selti=getSelectedItem();
2639 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2642 "setURL (\""+selti->getURL()+"\")",
2644 "setURL (\""+url+"\")",
2645 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2647 selti->setURL (url);
2648 // FIXME-4 updateActions();
2652 void VymModel::editVymLink()
2654 BranchItem *bi=getSelectedBranchItem();
2657 QStringList filters;
2658 filters <<"VYM map (*.vym)";
2659 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2660 fd->setFilters (filters);
2661 fd->setCaption(vymName+" - " +tr("Link to another map"));
2662 fd->setDirectory (lastFileDir);
2663 if (! bi->getVymLink().isEmpty() )
2664 fd->selectFile( bi->getVymLink() );
2668 if ( fd->exec() == QDialog::Accepted )
2670 lastFileDir=QDir (fd->directory().path());
2673 "setVymLink (\""+bi->getVymLink()+"\")",
2675 "setVymLink (\""+fd->selectedFile()+"\")",
2676 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2678 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2683 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2685 // Internal function, no saveState needed
2686 TreeItem *selti=getSelectedItem();
2689 selti->setVymLink(s);
2691 emitDataHasChanged (selti);
2692 emitShowSelection();
2696 void VymModel::deleteVymLink()
2698 BranchItem *bi=getSelectedBranchItem();
2703 "setVymLink (\""+bi->getVymLink()+"\")",
2705 "setVymLink (\"\")",
2706 QString("Unset vymlink of %1").arg(getObjectName(bi))
2708 bi->setVymLink ("" );
2714 QString VymModel::getVymLink()
2716 BranchItem *bi=getSelectedBranchItem();
2718 return bi->getVymLink();
2724 QStringList VymModel::getVymLinks()
2727 BranchItem *selbi=getSelectedBranchItem();
2728 BranchItem *cur=selbi;
2729 BranchItem *prev=NULL;
2732 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2733 cur=next (cur,prev,selbi);
2739 void VymModel::followXLink(int i) // FIXME-2
2743 BranchObj *bo=getSelectedBranch();
2746 bo=bo->XLinkTargetAt(i);
2749 selection.select(bo);
2750 emitShowSelection();
2756 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2760 BranchObj *bo=getSelectedBranch();
2763 XLinkObj *xlo=bo->XLinkAt(i);
2766 EditXLinkDialog dia;
2768 dia.setSelection(bo);
2769 if (dia.exec() == QDialog::Accepted)
2771 if (dia.useSettingsGlobal() )
2773 setMapDefXLinkColor (xlo->getColor() );
2774 setMapDefXLinkWidth (xlo->getWidth() );
2776 if (dia.deleteXLink())
2777 bo->deleteXLinkAt(i);
2788 //////////////////////////////////////////////
2790 //////////////////////////////////////////////
2792 void VymModel::parseAtom(const QString &atom)
2794 TreeItem* selti=getSelectedItem();
2795 BranchItem *selbi=getSelectedBranchItem();
2801 // Split string s into command and parameters
2802 parser.parseAtom (atom);
2803 QString com=parser.getCommand();
2805 // External commands
2806 /////////////////////////////////////////////////////////////////////
2807 if (com=="addBranch")
2811 parser.setError (Aborted,"Nothing selected");
2812 } else if (! selbi )
2814 parser.setError (Aborted,"Type of selection is not a branch");
2819 if (parser.checkParCount(pl))
2821 if (parser.parCount()==0)
2825 n=parser.parInt (ok,0);
2826 if (ok ) addNewBranch (n);
2830 /////////////////////////////////////////////////////////////////////
2831 } else if (com=="addBranchBefore")
2835 parser.setError (Aborted,"Nothing selected");
2836 } else if (! selbi )
2838 parser.setError (Aborted,"Type of selection is not a branch");
2841 if (parser.parCount()==0)
2843 addNewBranchBefore ();
2846 /////////////////////////////////////////////////////////////////////
2847 } else if (com==QString("addMapCenter"))
2849 if (parser.checkParCount(2))
2851 x=parser.parDouble (ok,0);
2854 y=parser.parDouble (ok,1);
2855 if (ok) addMapCenter (QPointF(x,y));
2858 /////////////////////////////////////////////////////////////////////
2859 } else if (com==QString("addMapReplace"))
2863 parser.setError (Aborted,"Nothing selected");
2864 } else if (! selbi )
2866 parser.setError (Aborted,"Type of selection is not a branch");
2867 } else if (parser.checkParCount(1))
2869 //s=parser.parString (ok,0); // selection
2870 t=parser.parString (ok,0); // path to map
2871 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2872 addMapReplaceInt(getSelectString(selbi),t);
2874 /////////////////////////////////////////////////////////////////////
2875 } else if (com==QString("addMapInsert"))
2879 parser.setError (Aborted,"Nothing selected");
2880 } else if (! selbi )
2882 parser.setError (Aborted,"Type of selection is not a branch");
2885 if (parser.checkParCount(2))
2887 t=parser.parString (ok,0); // path to map
2888 n=parser.parInt(ok,1); // position
2889 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2890 addMapInsertInt(t,n);
2893 /////////////////////////////////////////////////////////////////////
2894 } else if (com=="clearFlags")
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(0))
2904 selbi->deactivateAllStandardFlags();
2906 /////////////////////////////////////////////////////////////////////
2907 } else if (com=="colorBranch")
2911 parser.setError (Aborted,"Nothing selected");
2912 } else if (! selbi )
2914 parser.setError (Aborted,"Type of selection is not a branch");
2915 } else if (parser.checkParCount(1))
2917 QColor c=parser.parColor (ok,0);
2918 if (ok) colorBranch (c);
2920 /////////////////////////////////////////////////////////////////////
2921 } else if (com=="colorSubtree")
2925 parser.setError (Aborted,"Nothing selected");
2926 } else if (! selbi )
2928 parser.setError (Aborted,"Type of selection is not a branch");
2929 } else if (parser.checkParCount(1))
2931 QColor c=parser.parColor (ok,0);
2932 if (ok) colorSubtree (c);
2934 /////////////////////////////////////////////////////////////////////
2935 } else if (com=="copy")
2939 parser.setError (Aborted,"Nothing selected");
2940 } else if ( selectionType()!=TreeItem::Branch &&
2941 selectionType()!=TreeItem::MapCenter &&
2942 selectionType()!=TreeItem::Image )
2944 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2945 } else if (parser.checkParCount(0))
2949 /////////////////////////////////////////////////////////////////////
2950 } else if (com=="cut")
2954 parser.setError (Aborted,"Nothing selected");
2955 } else if ( selectionType()!=TreeItem::Branch &&
2956 selectionType()!=TreeItem::MapCenter &&
2957 selectionType()!=TreeItem::Image )
2959 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2960 } else if (parser.checkParCount(0))
2964 /////////////////////////////////////////////////////////////////////
2965 } else if (com=="delete")
2969 parser.setError (Aborted,"Nothing selected");
2971 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2973 parser.setError (Aborted,"Type of selection is wrong.");
2976 else if (parser.checkParCount(0))
2980 /////////////////////////////////////////////////////////////////////
2981 } else if (com=="deleteKeepChildren")
2985 parser.setError (Aborted,"Nothing selected");
2986 } else if (! selbi )
2988 parser.setError (Aborted,"Type of selection is not a branch");
2989 } else if (parser.checkParCount(0))
2991 deleteKeepChildren();
2993 /////////////////////////////////////////////////////////////////////
2994 } else if (com=="deleteChildren")
2998 parser.setError (Aborted,"Nothing selected");
3001 parser.setError (Aborted,"Type of selection is not a branch");
3002 } else if (parser.checkParCount(0))
3006 /////////////////////////////////////////////////////////////////////
3007 } else if (com=="exportASCII")
3011 if (parser.parCount()>=1)
3012 // Hey, we even have a filename
3013 fname=parser.parString(ok,0);
3016 parser.setError (Aborted,"Could not read filename");
3019 exportASCII (fname,false);
3021 /////////////////////////////////////////////////////////////////////
3022 } else if (com=="exportImage")
3026 if (parser.parCount()>=2)
3027 // Hey, we even have a filename
3028 fname=parser.parString(ok,0);
3031 parser.setError (Aborted,"Could not read filename");
3034 QString format="PNG";
3035 if (parser.parCount()>=2)
3037 format=parser.parString(ok,1);
3039 exportImage (fname,false,format);
3041 /////////////////////////////////////////////////////////////////////
3042 } else if (com=="exportXHTML")
3046 if (parser.parCount()>=2)
3047 // Hey, we even have a filename
3048 fname=parser.parString(ok,1);
3051 parser.setError (Aborted,"Could not read filename");
3054 exportXHTML (fname,false);
3056 /////////////////////////////////////////////////////////////////////
3057 } else if (com=="exportXML")
3061 if (parser.parCount()>=2)
3062 // Hey, we even have a filename
3063 fname=parser.parString(ok,1);
3066 parser.setError (Aborted,"Could not read filename");
3069 exportXML (fname,false);
3071 /////////////////////////////////////////////////////////////////////
3072 } else if (com=="importDir")
3076 parser.setError (Aborted,"Nothing selected");
3077 } else if (! selbi )
3079 parser.setError (Aborted,"Type of selection is not a branch");
3080 } else if (parser.checkParCount(1))
3082 s=parser.parString(ok,0);
3083 if (ok) importDirInt(s);
3085 /////////////////////////////////////////////////////////////////////
3086 } else if (com=="relinkTo")
3090 parser.setError (Aborted,"Nothing selected");
3093 if (parser.checkParCount(4))
3095 // 0 selectstring of parent
3096 // 1 num in parent (for branches)
3097 // 2,3 x,y of mainbranch or mapcenter
3098 s=parser.parString(ok,0);
3099 TreeItem *dst=findBySelectString (s);
3102 if (dst->getType()==TreeItem::Branch)
3104 // Get number in parent
3105 n=parser.parInt (ok,1);
3108 relinkBranch (selbi,(BranchItem*)dst,n);
3109 emitSelectionChanged();
3111 } else if (dst->getType()==TreeItem::MapCenter)
3113 relinkBranch (selbi,(BranchItem*)dst);
3114 // Get coordinates of mainbranch
3115 x=parser.parDouble(ok,2);
3118 y=parser.parDouble(ok,3);
3121 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3122 emitSelectionChanged();
3128 } else if ( selti->getType() == TreeItem::Image)
3130 if (parser.checkParCount(1))
3132 // 0 selectstring of parent
3133 s=parser.parString(ok,0);
3134 TreeItem *dst=findBySelectString (s);
3137 if (dst->isBranchLikeType())
3138 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3140 parser.setError (Aborted,"Destination is not a branch");
3143 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3144 /////////////////////////////////////////////////////////////////////
3145 } else if (com=="loadImage")
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(1))
3155 s=parser.parString(ok,0);
3156 if (ok) loadFloatImageInt (selbi,s);
3158 /////////////////////////////////////////////////////////////////////
3159 } else if (com=="moveUp")
3163 parser.setError (Aborted,"Nothing selected");
3164 } else if (! selbi )
3166 parser.setError (Aborted,"Type of selection is not a branch");
3167 } else if (parser.checkParCount(0))
3171 /////////////////////////////////////////////////////////////////////
3172 } else if (com=="moveDown")
3176 parser.setError (Aborted,"Nothing selected");
3177 } else if (! selbi )
3179 parser.setError (Aborted,"Type of selection is not a branch");
3180 } else if (parser.checkParCount(0))
3184 /////////////////////////////////////////////////////////////////////
3185 } else if (com=="move")
3189 parser.setError (Aborted,"Nothing selected");
3190 } else if ( selectionType()!=TreeItem::Branch &&
3191 selectionType()!=TreeItem::MapCenter &&
3192 selectionType()!=TreeItem::Image )
3194 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3195 } else if (parser.checkParCount(2))
3197 x=parser.parDouble (ok,0);
3200 y=parser.parDouble (ok,1);
3204 /////////////////////////////////////////////////////////////////////
3205 } else if (com=="moveRel")
3209 parser.setError (Aborted,"Nothing selected");
3210 } else if ( selectionType()!=TreeItem::Branch &&
3211 selectionType()!=TreeItem::MapCenter &&
3212 selectionType()!=TreeItem::Image )
3214 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3215 } else if (parser.checkParCount(2))
3217 x=parser.parDouble (ok,0);
3220 y=parser.parDouble (ok,1);
3221 if (ok) moveRel (x,y);
3224 /////////////////////////////////////////////////////////////////////
3225 } else if (com=="nop")
3227 /////////////////////////////////////////////////////////////////////
3228 } else if (com=="paste")
3232 parser.setError (Aborted,"Nothing selected");
3233 } else if (! selbi )
3235 parser.setError (Aborted,"Type of selection is not a branch");
3236 } else if (parser.checkParCount(1))
3238 n=parser.parInt (ok,0);
3239 if (ok) pasteNoSave(n);
3241 /////////////////////////////////////////////////////////////////////
3242 } else if (com=="qa")
3246 parser.setError (Aborted,"Nothing selected");
3247 } else if (! selbi )
3249 parser.setError (Aborted,"Type of selection is not a branch");
3250 } else if (parser.checkParCount(4))
3253 c=parser.parString (ok,0);
3256 parser.setError (Aborted,"No comment given");
3259 s=parser.parString (ok,1);
3262 parser.setError (Aborted,"First parameter is not a string");
3265 t=parser.parString (ok,2);
3268 parser.setError (Aborted,"Condition is not a string");
3271 u=parser.parString (ok,3);
3274 parser.setError (Aborted,"Third parameter is not a string");
3279 parser.setError (Aborted,"Unknown type: "+s);
3284 parser.setError (Aborted,"Unknown operator: "+t);
3289 parser.setError (Aborted,"Type of selection is not a branch");
3292 if (selbi->getHeading() == u)
3294 cout << "PASSED: " << qPrintable (c) << endl;
3297 cout << "FAILED: " << qPrintable (c) << endl;
3307 /////////////////////////////////////////////////////////////////////
3308 } else if (com=="saveImage")
3310 ImageItem *ii=getSelectedImageItem();
3313 parser.setError (Aborted,"No image selected");
3314 } else if (parser.checkParCount(2))
3316 s=parser.parString(ok,0);
3319 t=parser.parString(ok,1);
3320 if (ok) saveFloatImageInt (ii,t,s);
3323 /////////////////////////////////////////////////////////////////////
3324 } else if (com=="scroll")
3328 parser.setError (Aborted,"Nothing selected");
3329 } else if (! selbi )
3331 parser.setError (Aborted,"Type of selection is not a branch");
3332 } else if (parser.checkParCount(0))
3334 if (!scrollBranch (selbi))
3335 parser.setError (Aborted,"Could not scroll branch");
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="select")
3340 if (parser.checkParCount(1))
3342 s=parser.parString(ok,0);
3345 /////////////////////////////////////////////////////////////////////
3346 } else if (com=="selectLastBranch")
3350 parser.setError (Aborted,"Nothing selected");
3351 } else if (! selbi )
3353 parser.setError (Aborted,"Type of selection is not a branch");
3354 } else if (parser.checkParCount(0))
3356 BranchItem *bi=selbi->getLastBranch();
3358 parser.setError (Aborted,"Could not select last branch");
3359 select (bi); // FIXME-3 was selectInt
3362 /////////////////////////////////////////////////////////////////////
3363 } else /* FIXME-2 if (com=="selectLastImage")
3367 parser.setError (Aborted,"Nothing selected");
3368 } else if (! selbi )
3370 parser.setError (Aborted,"Type of selection is not a branch");
3371 } else if (parser.checkParCount(0))
3373 FloatImageObj *fio=selb->getLastFloatImage();
3375 parser.setError (Aborted,"Could not select last image");
3376 select (fio); // FIXME-3 was selectInt
3379 /////////////////////////////////////////////////////////////////////
3380 } else */ if (com=="selectLatestAdded")
3382 if (!latestAddedItem)
3384 parser.setError (Aborted,"No latest added object");
3387 if (!select (latestAddedItem))
3388 parser.setError (Aborted,"Could not select latest added object ");
3390 /////////////////////////////////////////////////////////////////////
3391 } else if (com=="setFrameType")
3393 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3395 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3397 else if (parser.checkParCount(1))
3399 s=parser.parString(ok,0);
3400 if (ok) setFrameType (s);
3402 /////////////////////////////////////////////////////////////////////
3403 } else if (com=="setFramePenColor")
3405 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3407 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3409 else if (parser.checkParCount(1))
3411 QColor c=parser.parColor(ok,0);
3412 if (ok) setFramePenColor (c);
3414 /////////////////////////////////////////////////////////////////////
3415 } else if (com=="setFrameBrushColor")
3417 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3419 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3421 else if (parser.checkParCount(1))
3423 QColor c=parser.parColor(ok,0);
3424 if (ok) setFrameBrushColor (c);
3426 /////////////////////////////////////////////////////////////////////
3427 } else if (com=="setFramePadding")
3429 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3431 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3433 else if (parser.checkParCount(1))
3435 n=parser.parInt(ok,0);
3436 if (ok) setFramePadding(n);
3438 /////////////////////////////////////////////////////////////////////
3439 } else if (com=="setFrameBorderWidth")
3441 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3443 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3445 else if (parser.checkParCount(1))
3447 n=parser.parInt(ok,0);
3448 if (ok) setFrameBorderWidth (n);
3450 /////////////////////////////////////////////////////////////////////
3451 } else if (com=="setMapAuthor")
3453 if (parser.checkParCount(1))
3455 s=parser.parString(ok,0);
3456 if (ok) setAuthor (s);
3458 /////////////////////////////////////////////////////////////////////
3459 } else if (com=="setMapComment")
3461 if (parser.checkParCount(1))
3463 s=parser.parString(ok,0);
3464 if (ok) setComment(s);
3466 /////////////////////////////////////////////////////////////////////
3467 } else if (com=="setMapBackgroundColor")
3471 parser.setError (Aborted,"Nothing selected");
3472 } else if (! selbi )
3474 parser.setError (Aborted,"Type of selection is not a branch");
3475 } else if (parser.checkParCount(1))
3477 QColor c=parser.parColor (ok,0);
3478 if (ok) setMapBackgroundColor (c);
3480 /////////////////////////////////////////////////////////////////////
3481 } else if (com=="setMapDefLinkColor")
3485 parser.setError (Aborted,"Nothing selected");
3486 } else if (! selbi )
3488 parser.setError (Aborted,"Type of selection is not a branch");
3489 } else if (parser.checkParCount(1))
3491 QColor c=parser.parColor (ok,0);
3492 if (ok) setMapDefLinkColor (c);
3494 /////////////////////////////////////////////////////////////////////
3495 } else if (com=="setMapLinkStyle")
3497 if (parser.checkParCount(1))
3499 s=parser.parString (ok,0);
3500 if (ok) setMapLinkStyle(s);
3502 /////////////////////////////////////////////////////////////////////
3503 } else if (com=="setHeading")
3507 parser.setError (Aborted,"Nothing selected");
3508 } else if (! selbi )
3510 parser.setError (Aborted,"Type of selection is not a branch");
3511 } else if (parser.checkParCount(1))
3513 s=parser.parString (ok,0);
3517 /////////////////////////////////////////////////////////////////////
3518 } else if (com=="setHideExport")
3522 parser.setError (Aborted,"Nothing selected");
3523 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3525 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3526 } else if (parser.checkParCount(1))
3528 b=parser.parBool(ok,0);
3529 if (ok) setHideExport (b);
3531 /////////////////////////////////////////////////////////////////////
3532 } else if (com=="setIncludeImagesHorizontally")
3536 parser.setError (Aborted,"Nothing selected");
3539 parser.setError (Aborted,"Type of selection is not a branch");
3540 } else if (parser.checkParCount(1))
3542 b=parser.parBool(ok,0);
3543 if (ok) setIncludeImagesHor(b);
3545 /////////////////////////////////////////////////////////////////////
3546 } else if (com=="setIncludeImagesVertically")
3550 parser.setError (Aborted,"Nothing selected");
3553 parser.setError (Aborted,"Type of selection is not a branch");
3554 } else if (parser.checkParCount(1))
3556 b=parser.parBool(ok,0);
3557 if (ok) setIncludeImagesVer(b);
3559 /////////////////////////////////////////////////////////////////////
3560 } else if (com=="setHideLinkUnselected")
3564 parser.setError (Aborted,"Nothing selected");
3565 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3567 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3568 } else if (parser.checkParCount(1))
3570 b=parser.parBool(ok,0);
3571 if (ok) setHideLinkUnselected(b);
3573 /////////////////////////////////////////////////////////////////////
3574 } else if (com=="setSelectionColor")
3576 if (parser.checkParCount(1))
3578 QColor c=parser.parColor (ok,0);
3579 if (ok) setSelectionColorInt (c);
3581 /////////////////////////////////////////////////////////////////////
3582 } else if (com=="setURL")
3586 parser.setError (Aborted,"Nothing selected");
3587 } else if (! selbi )
3589 parser.setError (Aborted,"Type of selection is not a branch");
3590 } else if (parser.checkParCount(1))
3592 s=parser.parString (ok,0);
3595 /////////////////////////////////////////////////////////////////////
3596 } else if (com=="setVymLink")
3600 parser.setError (Aborted,"Nothing selected");
3601 } else if (! selbi )
3603 parser.setError (Aborted,"Type of selection is not a branch");
3604 } else if (parser.checkParCount(1))
3606 s=parser.parString (ok,0);
3607 if (ok) setVymLink(s);
3610 /////////////////////////////////////////////////////////////////////
3611 else if (com=="setFlag")
3615 parser.setError (Aborted,"Nothing selected");
3616 } else if (! selbi )
3618 parser.setError (Aborted,"Type of selection is not a branch");
3619 } else if (parser.checkParCount(1))
3621 s=parser.parString(ok,0);
3623 selbi->activateStandardFlag(s);
3625 /////////////////////////////////////////////////////////////////////
3626 } else /* FIXME-2 if (com=="setFrameType")
3630 parser.setError (Aborted,"Nothing selected");
3633 parser.setError (Aborted,"Type of selection is not a branch");
3634 } else if (parser.checkParCount(1))
3636 s=parser.parString(ok,0);
3640 /////////////////////////////////////////////////////////////////////
3641 } else*/ if (com=="sortChildren")
3645 parser.setError (Aborted,"Nothing selected");
3646 } else if (! selbi )
3648 parser.setError (Aborted,"Type of selection is not a branch");
3649 } else if (parser.checkParCount(0))
3653 /////////////////////////////////////////////////////////////////////
3654 } else if (com=="toggleFlag")
3658 parser.setError (Aborted,"Nothing selected");
3659 } else if (! selbi )
3661 parser.setError (Aborted,"Type of selection is not a branch");
3662 } else if (parser.checkParCount(1))
3664 s=parser.parString(ok,0);
3666 selbi->toggleStandardFlag(s);
3668 /////////////////////////////////////////////////////////////////////
3669 } else if (com=="unscroll")
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(0))
3679 if (!unscrollBranch (selbi))
3680 parser.setError (Aborted,"Could not unscroll branch");
3682 /////////////////////////////////////////////////////////////////////
3683 } else if (com=="unscrollChildren")
3687 parser.setError (Aborted,"Nothing selected");
3688 } else if (! selbi )
3690 parser.setError (Aborted,"Type of selection is not a branch");
3691 } else if (parser.checkParCount(0))
3693 unscrollChildren ();
3695 /////////////////////////////////////////////////////////////////////
3696 } else if (com=="unsetFlag")
3700 parser.setError (Aborted,"Nothing selected");
3701 } else if (! selbi )
3703 parser.setError (Aborted,"Type of selection is not a branch");
3704 } else if (parser.checkParCount(1))
3706 s=parser.parString(ok,0);
3708 selbi->deactivateStandardFlag(s);
3711 parser.setError (Aborted,"Unknown command");
3714 if (parser.errorLevel()==NoError)
3716 // setChanged(); FIXME-2 should not be called e.g. for export?!
3721 // TODO Error handling
3722 qWarning("VymModel::parseAtom: Error!");
3723 qWarning(parser.errorMessage());
3727 void VymModel::runScript (QString script)
3729 parser.setScript (script);
3731 while (parser.next() )
3732 parseAtom(parser.getAtom());
3735 void VymModel::setExportMode (bool b)
3737 // should be called before and after exports
3738 // depending on the settings
3739 if (b && settings.value("/export/useHideExport","true")=="true")
3740 setHideTmpMode (TreeItem::HideExport);
3742 setHideTmpMode (TreeItem::HideNone);
3745 void VymModel::exportImage(QString fname, bool askName, QString format)
3747 /* FIXME-2 export as image, but directly from mapEditor?!
3750 fname=getMapName()+".png";
3757 QFileDialog *fd=new QFileDialog (NULL);
3758 fd->setCaption (tr("Export map as image"));
3759 fd->setDirectory (lastImageDir);
3760 fd->setFileMode(QFileDialog::AnyFile);
3761 fd->setFilters (imageIO.getFilters() );
3764 fl=fd->selectedFiles();
3766 format=imageIO.getType(fd->selectedFilter());
3770 setExportMode (true);
3771 QPixmap pix (mapEditor->getPixmap());
3772 pix.save(fname, format);
3773 setExportMode (false);
3778 void VymModel::exportXML(QString dir, bool askForName)
3782 dir=browseDirectory(NULL,tr("Export XML to directory"));
3783 if (dir =="" && !reallyWriteDirectory(dir) )
3787 // Hide stuff during export, if settings want this
3788 setExportMode (true);
3790 // Create subdirectories
3793 // write to directory //FIXME-4 check totalBBox here...
3794 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3797 file.setName ( dir + "/"+mapName+".xml");
3798 if ( !file.open( QIODevice::WriteOnly ) )
3800 // This should neverever happen
3801 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3805 // Write it finally, and write in UTF8, no matter what
3806 QTextStream ts( &file );
3807 ts.setEncoding (QTextStream::UnicodeUTF8);
3811 // Now write image, too
3812 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3814 setExportMode (false);
3817 void VymModel::exportASCII(QString fname,bool askName)
3822 ex.setFile (mapName+".txt");
3828 //ex.addFilter ("TXT (*.txt)");
3829 ex.setDir(lastImageDir);
3830 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3835 setExportMode(true);
3837 setExportMode(false);
3841 void VymModel::exportXHTML (const QString &dir, bool askForName)
3843 ExportXHTMLDialog dia(NULL);
3844 dia.setFilePath (filePath );
3845 dia.setMapName (mapName );
3847 if (dir!="") dia.setDir (dir);
3853 if (dia.exec()!=QDialog::Accepted)
3857 QDir d (dia.getDir());
3858 // Check, if warnings should be used before overwriting
3859 // the output directory
3860 if (d.exists() && d.count()>0)
3863 warn.showCancelButton (true);
3864 warn.setText(QString(
3865 "The directory %1 is not empty.\n"
3866 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3867 warn.setCaption("Warning: Directory not empty");
3868 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3870 if (warn.exec()!=QDialog::Accepted) ok=false;
3877 exportXML (dia.getDir(),false );
3878 dia.doExport(mapName );
3879 //if (dia.hasChanged()) setChanged();
3883 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3888 if (ex.setConfigFile(cf))
3890 setExportMode (true);
3891 ex.exportPresentation();
3892 setExportMode (false);
3899 //////////////////////////////////////////////
3901 //////////////////////////////////////////////
3903 void VymModel::registerEditor(QWidget *me)
3905 mapEditor=(MapEditor*)me;
3908 void VymModel::unregisterEditor(QWidget *)
3913 void VymModel::setContextPos(QPointF p)
3918 void VymModel::unsetContextPos()
3920 contextPos=QPointF();
3923 void VymModel::updateNoteFlag()
3926 TreeItem *selti=getSelectedItem();
3929 if (textEditor->isEmpty())
3932 selti->setNote (textEditor->getText());
3933 emitDataHasChanged(selti);
3934 emitSelectionChanged();
3939 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3942 for (int i=0; i<rootItem->branchCount(); i++)
3943 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3946 void MapCenterObj::updateRelPositions()
3948 if (repositionRequest) unsetAllRepositionRequests();
3950 // update relative Positions of branches and floats
3951 for (int i=0; i<treeItem->branchCount(); ++i)
3953 treeItem->getBranchObjNum(i)->setRelPos();
3954 treeItem->getBranchObjNum(i)->setOrientation();
3957 for (int i=0; i<floatimage.size(); ++i)
3958 floatimage.at(i)->setRelPos();
3960 if (repositionRequest) reposition();
3965 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3967 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3968 if (blockReposition) return;
3970 for (int i=0;i<rootItem->branchCount(); i++)
3971 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3975 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3977 return QPolygonF ();
3978 // Creating (arbitrary) shapes
3981 QRectF rb=bo->getBBox();
3982 if (bo->getDepth()==0)
3984 // Just take BBox of this mapCenter
3985 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3989 // Take union of BBox and TotalBBox
3991 QRectF ra=bo->getTotalBBox();
3992 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3995 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3998 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
4000 p <<ra.bottomRight()
4002 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4005 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4011 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4015 // Move all branches and MapCenters away from lmo
4016 // to avoid collisions
4021 BranchObj *boA=(BranchObj*)lmo;
4023 for (int i=0; i<rootItem->branchCount(); i++)
4025 boB=rootItem->getBranchNum(i);
4028 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4031 <<" ("<<qPrintable(boA->getHeading() )<<")"
4032 <<" with ("<< qPrintable (boB->getHeading() )
4035 <<" minT="<<r.minTranslation<<endl<<endl;
4041 void VymModel::setMapLinkStyle (const QString & s)
4046 case LinkableMapObj::Line :
4049 case LinkableMapObj::Parabel:
4050 snow="StyleParabel";
4052 case LinkableMapObj::PolyLine:
4053 snow="StylePolyLine";
4055 case LinkableMapObj::PolyParabel:
4056 snow="StylePolyParabel";
4059 snow="UndefinedStyle";
4064 QString("setMapLinkStyle (\"%1\")").arg(s),
4065 QString("setMapLinkStyle (\"%1\")").arg(snow),
4066 QString("Set map link style (\"%1\")").arg(s)
4070 linkstyle=LinkableMapObj::Line;
4071 else if (s=="StyleParabel")
4072 linkstyle=LinkableMapObj::Parabel;
4073 else if (s=="StylePolyLine")
4074 linkstyle=LinkableMapObj::PolyLine;
4075 else if (s=="StylePolyParabel")
4076 linkstyle=LinkableMapObj::PolyParabel;
4078 linkstyle=LinkableMapObj::UndefinedStyle;
4080 BranchItem *cur=NULL;
4081 BranchItem *prev=NULL;
4086 bo=(BranchObj*)(cur->getLMO() );
4087 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4093 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4098 void VymModel::setMapDefLinkColor(QColor col)
4100 if ( !col.isValid() ) return;
4102 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4103 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4104 QString("Set map link color to %1").arg(col.name())
4108 BranchItem *cur=NULL;
4109 BranchItem *prev=NULL;
4114 bo=(BranchObj*)(cur->getLMO() );
4121 void VymModel::setMapLinkColorHintInt()
4123 // called from setMapLinkColorHint(lch) or at end of parse
4124 BranchItem *cur=NULL;
4125 BranchItem *prev=NULL;
4130 bo=(BranchObj*)(cur->getLMO() );
4136 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4139 setMapLinkColorHintInt();
4142 void VymModel::toggleMapLinkColorHint()
4144 if (linkcolorhint==LinkableMapObj::HeadingColor)
4145 linkcolorhint=LinkableMapObj::DefaultColor;
4147 linkcolorhint=LinkableMapObj::HeadingColor;
4148 BranchItem *cur=NULL;
4149 BranchItem *prev=NULL;
4154 bo=(BranchObj*)(cur->getLMO() );
4160 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4162 Q3FileDialog *fd=new Q3FileDialog( NULL);
4163 fd->setMode (Q3FileDialog::ExistingFile);
4164 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4165 ImagePreview *p =new ImagePreview (fd);
4166 fd->setContentsPreviewEnabled( TRUE );
4167 fd->setContentsPreview( p, p );
4168 fd->setPreviewMode( Q3FileDialog::Contents );
4169 fd->setCaption(vymName+" - " +tr("Load background image"));
4170 fd->setDir (lastImageDir);
4173 if ( fd->exec() == QDialog::Accepted )
4175 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4176 lastImageDir=QDir (fd->dirPath());
4177 setMapBackgroundImage (fd->selectedFile());
4181 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate, move to ME
4183 QColor oldcol=mapScene->backgroundBrush().color();
4187 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4189 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4190 QString("Set background color of map to %1").arg(col.name()));
4193 brush.setTextureImage (QPixmap (fn));
4194 mapScene->setBackgroundBrush(brush);
4197 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4199 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4200 if ( !col.isValid() ) return;
4201 setMapBackgroundColor( col );
4205 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4207 QColor oldcol=mapScene->backgroundBrush().color();
4209 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4210 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4211 QString("Set background color of map to %1").arg(col.name()));
4212 mapScene->setBackgroundBrush(col);
4215 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4217 return mapScene->backgroundBrush().color();
4221 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4223 return linkcolorhint;
4226 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4228 return defLinkColor;
4231 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4236 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4238 return defXLinkColor;
4241 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4246 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4248 return defXLinkWidth;
4251 void VymModel::move(const double &x, const double &y) // FIXME-3
4255 BranchObj *bo = getSelectedBranch();
4257 (selectionType()==TreeItem::Branch ||
4258 selectionType()==TreeItem::MapCenter ||
4259 selectionType()==TreeItem::Image
4262 QPointF ap(bo->getAbsPos());
4266 QString ps=qpointfToString(ap);
4267 QString s=getSelectString();
4270 s, "move "+qpointfToString(to),
4271 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4274 emitSelectionChanged();
4280 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4284 BranchObj *bo = getSelectedBranch();
4286 (selectionType()==TreeItem::Branch ||
4287 selectionType()==TreeItem::MapCenter ||
4288 selectionType()==TreeItem::Image
4292 QPointF rp(bo->getRelPos());
4296 QString ps=qpointfToString (bo->getRelPos());
4297 QString s=getSelectString(bo);
4300 s, "moveRel "+qpointfToString(to),
4301 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4302 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4304 bo->updateLinkGeometry();
4305 emitSelectionChanged();
4312 void VymModel::animate()
4314 animationTimer->stop();
4317 while (i<animObjList.size() )
4319 bo=(BranchObj*)animObjList.at(i);
4324 animObjList.removeAt(i);
4331 QItemSelection sel=selModel->selection();
4332 emit (selectionChanged(sel,sel));
4335 if (!animObjList.isEmpty()) animationTimer->start();
4339 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4341 if (bo && bo->getTreeItem()->depth()>0)
4344 ap.setStart (start);
4346 ap.setTicks (animationTicks);
4347 ap.setAnimated (true);
4348 bo->setAnimation (ap);
4349 animObjList.append( bo );
4350 animationTimer->setSingleShot (true);
4351 animationTimer->start(animationInterval);
4355 void VymModel::stopAnimation (MapObj *mo)
4357 int i=animObjList.indexOf(mo);
4359 animObjList.removeAt (i);
4362 void VymModel::sendSelection()
4364 if (netstate!=Server) return;
4365 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4368 void VymModel::newServer()
4372 tcpServer = new QTcpServer(this);
4373 if (!tcpServer->listen(QHostAddress::Any,port)) {
4374 QMessageBox::critical(NULL, "vym server",
4375 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4376 //FIXME-3 needed? we are no widget any longer... close();
4379 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4381 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4384 void VymModel::connectToServer()
4387 server="salam.suse.de";
4389 clientSocket = new QTcpSocket (this);
4390 clientSocket->abort();
4391 clientSocket->connectToHost(server ,port);
4392 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4393 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4394 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4396 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4401 void VymModel::newClient()
4403 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4404 connect(newClient, SIGNAL(disconnected()),
4405 newClient, SLOT(deleteLater()));
4407 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4409 clientList.append (newClient);
4413 void VymModel::sendData(const QString &s)
4415 if (clientList.size()==0) return;
4417 // Create bytearray to send
4419 QDataStream out(&block, QIODevice::WriteOnly);
4420 out.setVersion(QDataStream::Qt_4_0);
4422 // Reserve some space for blocksize
4425 // Write sendCounter
4426 out << sendCounter++;
4431 // Go back and write blocksize so far
4432 out.device()->seek(0);
4433 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4437 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4439 for (int i=0; i<clientList.size(); ++i)
4441 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4442 clientList.at(i)->write (block);
4446 void VymModel::readData ()
4448 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4451 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4455 QDataStream in(clientSocket);
4456 in.setVersion(QDataStream::Qt_4_0);
4464 cout << " t="<<qPrintable (t)<<endl;
4470 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4472 switch (socketError) {
4473 case QAbstractSocket::RemoteHostClosedError:
4475 case QAbstractSocket::HostNotFoundError:
4476 QMessageBox::information(NULL, vymName +" Network client",
4477 "The host was not found. Please check the "
4478 "host name and port settings.");
4480 case QAbstractSocket::ConnectionRefusedError:
4481 QMessageBox::information(NULL, vymName + " Network client",
4482 "The connection was refused by the peer. "
4483 "Make sure the fortune server is running, "
4484 "and check that the host name and port "
4485 "settings are correct.");
4488 QMessageBox::information(NULL, vymName + " Network client",
4489 QString("The following error occurred: %1.")
4490 .arg(clientSocket->errorString()));
4494 /* FIXME-3 Playing with DBUS...
4495 QDBusVariant VymModel::query (const QString &query)
4497 TreeItem *selti=getSelectedItem();
4499 return QDBusVariant (selti->getHeading());
4501 return QDBusVariant ("Nothing selected.");
4505 void VymModel::testslot() //FIXME-3
4507 cout << "VM::testslot called\n";
4510 void VymModel::selectMapSelectionColor()
4512 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4513 setSelectionColor (col);
4516 void VymModel::setSelectionColorInt (QColor col)
4518 if ( !col.isValid() ) return;
4520 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4521 QString("setSelectionColor (%1)").arg(col.name()),
4522 QString("Set color of selection box to %1").arg(col.name())
4525 mapEditor->setSelectionColor (col);
4529 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4531 cout << "VymModel::changeSelection (";
4532 if (!newsel.indexes().isEmpty() )
4533 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4535 if (!oldsel.indexes().isEmpty() )
4536 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4541 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4545 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4547 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4548 emitShowSelection();
4552 void VymModel::emitSelectionChanged()
4554 QItemSelection newsel=selModel->selection();
4555 emitSelectionChanged (newsel);
4558 void VymModel::setSelectionColor(QColor col)
4560 if ( !col.isValid() ) return;
4562 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4563 QString("setSelectionColor (%1)").arg(col.name()),
4564 QString("Set color of selection box to %1").arg(col.name())
4566 setSelectionColorInt (col);
4569 QColor VymModel::getSelectionColor()
4571 return mapEditor->getSelectionColor();
4574 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4577 for (int i=0;i<rootItem->childCount();i++)
4578 rootItem->child(i)->setHideTmp (mode);
4580 // FIXME-3 needed? scene()->update();
4583 //////////////////////////////////////////////
4584 // Selection related
4585 //////////////////////////////////////////////
4587 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4592 QItemSelectionModel* VymModel::getSelectionModel()
4597 void VymModel::setSelectionBlocked (bool b)
4602 bool VymModel::isSelectionBlocked()
4604 return selectionBlocked;
4607 bool VymModel::select ()
4609 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4612 bool VymModel::select (const QString &s)
4614 TreeItem *ti=findBySelectString(s);
4624 bool VymModel::select (LinkableMapObj *lmo)
4626 QItemSelection oldsel=selModel->selection();
4629 return select (lmo->getTreeItem() );
4634 bool VymModel::select (TreeItem *ti)
4636 if (ti) return select (index(ti));
4640 bool VymModel::select (const QModelIndex &index)
4642 if (index.isValid() )
4644 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4645 getSelectedItem()->setLastSelectedBranch();
4651 void VymModel::unselect()
4653 lastSelectString=getSelectString();
4654 selModel->clearSelection();
4657 void VymModel::reselect()
4659 select (lastSelectString);
4662 void VymModel::emitShowSelection()
4664 if (!blockReposition)
4665 emit (showSelection() );
4668 void VymModel::emitNoteHasChanged (TreeItem *ti)
4670 QModelIndex ix=index(ti);
4671 emit (noteHasChanged (ix) );
4674 void VymModel::emitDataHasChanged (TreeItem *ti)
4676 QModelIndex ix=index(ti);
4677 emit (dataChanged (ix,ix) );
4681 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4684 if (selection.select(lmo))
4686 //emitSelectionChanged();
4690 void VymModel::selectInt (TreeItem *ti)
4692 if (selection.select(lmo))
4694 //emitSelectionChanged();
4699 void VymModel::selectNextBranchInt()
4701 BranchItem *bi=getSelectedBranchItem();
4704 TreeItem *pi=bi->parent();
4708 if (i<pi->branchCount() )
4710 // select previous branch with same parent
4712 select (pi->getBranchNum(i));
4720 void VymModel::selectPrevBranchInt()
4723 BranchItem *bi=getSelectedBranchItem();
4726 BranchItem *pi=(BranchItem*)bi->parent();
4732 // select previous branch with same parent
4733 bi=pi->getBranchNum(i-1);
4738 while (bi->branchCount() >0)
4739 bi=bi->getLastBranch();
4742 // Try to select last branch in parent pi2 previous to own parent pi
4744 TreeItem *pi2=pi->parent();
4755 void VymModel::selectAboveBranchInt()
4757 BranchItem *bi=getSelectedBranchItem();
4760 BranchItem *newbi=NULL;
4761 BranchItem *pi=(BranchItem*)bi->parent();
4765 // goto previous branch with same parent
4766 newbi=pi->getBranchNum(i-1);
4767 while (newbi->branchCount() >0 )
4768 newbi=newbi->getLastBranch();
4772 if (newbi==rootItem)
4773 // already at top branch (resp. mapcenter)
4779 void VymModel::selectBelowBranchInt()
4781 BranchItem *bi=getSelectedBranchItem();
4784 BranchItem *newbi=NULL;
4786 if (bi->branchCount() >0)
4787 newbi=bi->getFirstBranch();
4794 pi=(BranchItem*)bi->parent();
4796 if (pi->branchCount()-1 > i)
4798 newbi=(BranchItem*)pi->getBranchNum(i+1);
4803 // look for siblings of myself
4804 // or parent, or parent of parent...
4815 void VymModel::selectUpperBranch()
4817 BranchItem *bi=getSelectedBranchItem();
4818 if (bi && bi->isBranchLikeType())
4819 selectAboveBranchInt();
4822 void VymModel::selectLowerBranch()
4824 BranchItem *bi=getSelectedBranchItem();
4825 if (bi && bi->isBranchLikeType())
4826 selectBelowBranchInt();
4830 void VymModel::selectLeftBranch()
4832 QItemSelection oldsel=selModel->selection();
4835 BranchItem *selbi=getSelectedBranchItem();
4836 TreeItem::Type type=selbi->getType();
4839 if (type == TreeItem::MapCenter)
4841 QModelIndex ix=index(selbi);
4842 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4845 par=(BranchItem*)selbi->parent();
4846 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4849 if (type == TreeItem::Branch ||
4850 type == TreeItem::Image)
4852 QModelIndex ix=index (selbi->parent());
4853 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4858 if (type == TreeItem::Branch )
4860 selectLastSelectedBranch();
4868 void VymModel::selectRightBranch()
4870 QItemSelection oldsel=selModel->selection();
4873 BranchItem *selbi=getSelectedBranchItem();
4874 TreeItem::Type type=selbi->getType();
4877 if (type==TreeItem::MapCenter)
4879 QModelIndex ix=index(selbi);
4880 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4883 par=(BranchItem*)selbi->parent();
4884 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4887 if ( type== TreeItem::Branch )
4889 selectLastSelectedBranch();
4895 if (type == TreeItem::Branch ||
4896 type == TreeItem::Image)
4898 QModelIndex ix=index(selbi->parent());
4899 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4906 void VymModel::selectFirstBranch()
4908 TreeItem *ti=getSelectedBranchItem();
4911 TreeItem *par=ti->parent();
4913 TreeItem *ti2=par->getFirstBranch();
4916 emitSelectionChanged();
4921 void VymModel::selectLastBranch()
4923 TreeItem *ti=getSelectedBranchItem();
4926 TreeItem *par=ti->parent();
4928 TreeItem *ti2=par->getLastBranch();
4931 emitSelectionChanged();
4936 void VymModel::selectLastSelectedBranch()
4938 TreeItem *ti=getSelectedBranchItem();
4941 ti=ti->getLastSelectedBranch();
4942 if (ti) select (ti);
4946 void VymModel::selectParent()
4948 TreeItem *ti=getSelectedItem();
4955 emitSelectionChanged();
4959 TreeItem::Type VymModel::selectionType()
4961 QModelIndexList list=selModel->selectedIndexes();
4962 if (list.isEmpty()) return TreeItem::Undefined;
4963 TreeItem *ti = getItem (list.first() );
4964 return ti->getType();
4968 LinkableMapObj* VymModel::getSelectedLMO()
4970 QModelIndexList list=selModel->selectedIndexes();
4971 if (!list.isEmpty() )
4973 TreeItem *ti = getItem (list.first() );
4974 TreeItem::Type type=ti->getType();
4975 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4976 return ((MapItem*)ti)->getLMO();
4981 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4983 TreeItem *ti = getSelectedBranchItem();
4985 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4990 BranchItem* VymModel::getSelectedBranchItem()
4992 QModelIndexList list=selModel->selectedIndexes();
4993 if (!list.isEmpty() )
4995 TreeItem *ti = getItem (list.first() );
4996 TreeItem::Type type=ti->getType();
4997 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4998 return (BranchItem*)ti;
5003 TreeItem* VymModel::getSelectedItem()
5005 QModelIndexList list=selModel->selectedIndexes();
5006 if (!list.isEmpty() )
5007 return getItem (list.first() );
5012 QModelIndex VymModel::getSelectedIndex()
5014 QModelIndexList list=selModel->selectedIndexes();
5015 if (list.isEmpty() )
5016 return QModelIndex();
5018 return list.first();
5021 ImageItem* VymModel::getSelectedImageItem()
5023 QModelIndexList list=selModel->selectedIndexes();
5024 if (!list.isEmpty())
5026 TreeItem *ti=getItem (list.first());
5027 if (ti && ti->getType()==TreeItem::Image)
5028 return (ImageItem*)ti;
5033 QString VymModel::getSelectString ()
5035 return getSelectString (getSelectedItem());
5038 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5040 if (!lmo) return QString();
5041 return getSelectString (lmo->getTreeItem() );
5044 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
5048 switch (ti->getType())
5050 case TreeItem::MapCenter: s="mc:"; break;
5051 case TreeItem::Branch: s="bo:";break;
5052 case TreeItem::Image: s="fi:";break;
5055 s= s + QString("%1").arg(ti->num());
5057 // call myself recursively
5058 s= getSelectString(ti->parent()) +","+s;