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 "xlinkitem.h"
20 #include "xml-freemind.h"
26 extern Main *mainWindow;
27 extern QDBusConnection dbusConnection;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
33 extern FlagRow *standardFlagsMaster;
35 extern QString clipboardDir;
36 extern QString clipboardFile;
37 extern bool clipboardEmpty;
39 extern ImageIO imageIO;
41 extern QString vymName;
42 extern QString vymVersion;
43 extern QDir vymBaseDir;
45 extern QDir lastImageDir;
46 extern QDir lastFileDir;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 //cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 //cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 selModel->clearSelection();
73 while (rootItem->childCount() >0)
74 deleteItem (rootItem->getChildNum(0) );
77 void VymModel::init ()
82 // Also no scene yet (should not be needed anyway) FIXME-3 VM
95 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
96 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
97 mainWindow->updateHistory (undoSet);
100 makeTmpDirectories();
105 fileName=tr("unnamed");
107 blockReposition=false;
108 blockSaveState=false;
110 autosaveTimer=new QTimer (this);
111 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
113 fileChangedTimer=new QTimer (this);
114 fileChangedTimer->start(3000);
115 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
120 selectionBlocked=false;
127 // animations // FIXME-3 switch to new animation system
128 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
129 animationTicks=settings.readNumEntry("/animation/ticks",10);
130 animationInterval=settings.readNumEntry("/animation/interval",50);
132 animationTimer=new QTimer (this);
133 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
136 defLinkColor=QColor (0,0,255);
137 defXLinkColor=QColor (180,180,180);
138 linkcolorhint=LinkableMapObj::DefaultColor;
139 linkstyle=LinkableMapObj::PolyParabel;
141 defXLinkColor=QColor (230,230,230);
143 hidemode=TreeItem::HideNone;
149 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
151 //Initialize DBUS object
152 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
153 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
154 qWarning ("VymModel: Couldn't register DBUS object!");
157 void VymModel::makeTmpDirectories()
159 // Create unique temporary directories
160 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
161 histPath = tmpMapDir+"/history";
167 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
172 bool VymModel::isRepositionBlocked()
174 return blockReposition;
177 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
179 //cout << "VM::updateActions \n";
180 // Tell mainwindow to update states of actions
181 mainWindow->updateActions();
186 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
188 // tmpdir temporary directory to which data will be written
189 // prefix mapname, which will be appended to images etc.
190 // writeflags Only write flags for "real" save of map, not undo
191 // offset offset of bbox of whole map in scene.
192 // Needed for XML export
201 case LinkableMapObj::Line:
204 case LinkableMapObj::Parabel:
207 case LinkableMapObj::PolyLine:
211 ls="StylePolyParabel";
215 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
217 if (linkcolorhint==LinkableMapObj::HeadingColor)
218 colhint=xml.attribut("linkColorHint","HeadingColor");
220 QString mapAttr=xml.attribut("version",vymVersion);
222 mapAttr+= xml.attribut("author",author) +
223 xml.attribut("comment",comment) +
224 xml.attribut("date",getDate()) +
225 xml.attribut("branchCount", QString().number(branchCount())) +
226 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
227 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
228 xml.attribut("linkStyle", ls ) +
229 xml.attribut("linkColor", defLinkColor.name() ) +
230 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
231 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
233 s+=xml.beginElement("vymmap",mapAttr);
236 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
237 standardFlagsMaster->resetUsedCounter();
239 // Build xml recursivly
241 // Save all mapcenters as complete map, if saveSel not set
242 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
245 switch (saveSel->getType())
247 case TreeItem::Branch:
249 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
251 case TreeItem::MapCenter:
253 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
255 case TreeItem::Image:
257 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
260 // other types shouldn't be safed directly...
265 // Save local settings
266 s+=settings.getDataXML (destPath);
269 if (getSelectedItem() && !saveSel )
270 s+=xml.valueElement("select",getSelectString());
273 s+=xml.endElement("vymmap");
275 //cout << s.toStdString() << endl;
277 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
281 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
285 for (int i=0; i<rootItem->branchCount(); i++)
286 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
290 void VymModel::setFilePath(QString fpath, QString destname)
292 if (fpath.isEmpty() || fpath=="")
299 filePath=fpath; // becomes absolute path
300 fileName=fpath; // gets stripped of path
301 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
303 // If fpath is not an absolute path, complete it
304 filePath=QDir(fpath).absPath();
305 fileDir=filePath.left (1+filePath.findRev ("/"));
307 // Set short name, too. Search from behind:
308 int i=fileName.findRev("/");
309 if (i>=0) fileName=fileName.remove (0,i+1);
311 // Forget the .vym (or .xml) for name of map
312 mapName=fileName.left(fileName.findRev(".",-1,true) );
316 void VymModel::setFilePath(QString fpath)
318 setFilePath (fpath,fpath);
321 QString VymModel::getFilePath()
326 QString VymModel::getFileName()
331 QString VymModel::getMapName()
336 QString VymModel::getDestPath()
341 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
343 ErrorCode err=success;
345 parseBaseHandler *handler;
349 case VymMap: handler=new parseVYMHandler; break;
350 case FreemindMap : handler=new parseFreemindHandler; break;
352 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
353 "Unknown FileType in VymModel::load()");
357 bool zipped_org=zipped;
361 selModel->clearSelection();
362 // FIXME-2 VM not needed??? model->setMapEditor(this);
363 // (map state is set later at end of load...)
366 BranchItem *bi=getSelectedBranch();
367 if (!bi) return aborted;
368 if (lmode==ImportAdd)
369 saveStateChangingPart(
372 QString("addMapInsert (%1)").arg(fname),
373 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
375 saveStateChangingPart(
378 QString("addMapReplace(%1)").arg(fname),
379 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
383 // Create temporary directory for packing
385 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
388 QMessageBox::critical( 0, tr( "Critical Load Error" ),
389 tr("Couldn't create temporary directory before load\n"));
394 err=unzipDir (tmpZipDir,fname);
404 // Look for mapname.xml
405 xmlfile= fname.left(fname.findRev(".",-1,true));
406 xmlfile=xmlfile.section( '/', -1 );
407 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
408 if (!mfile.exists() )
410 // mapname.xml does not exist, well,
411 // maybe someone renamed the mapname.vym file...
412 // Try to find any .xml in the toplevel
413 // directory of the .vym file
414 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
415 if (flist.count()==1)
417 // Only one entry, take this one
418 xmlfile=tmpZipDir + "/"+flist.first();
421 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
422 *it=tmpZipDir + "/" + *it;
423 // TODO Multiple entries, load all (but only the first one into this ME)
424 //mainWindow->fileLoadFromTmp (flist);
425 //returnCode=1; // Silently forget this attempt to load
426 qWarning ("MainWindow::load (fn) multimap found...");
429 if (flist.isEmpty() )
431 QMessageBox::critical( 0, tr( "Critical Load Error" ),
432 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
435 } //file doesn't exist
437 xmlfile=mfile.name();
440 QFile file( xmlfile);
442 // I am paranoid: file should exist anyway
443 // according to check in mainwindow.
446 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
447 tr(QString("Couldn't open map %1").arg(file.name())));
451 bool blockSaveStateOrg=blockSaveState;
452 blockReposition=true;
454 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
455 QXmlInputSource source( file);
456 QXmlSimpleReader reader;
457 reader.setContentHandler( handler );
458 reader.setErrorHandler( handler );
459 handler->setModel ( this);
462 // We need to set the tmpDir in order to load files with rel. path
467 tmpdir=fname.left(fname.findRev("/",-1));
468 handler->setTmpDir (tmpdir);
469 handler->setInputFile (file.name());
470 handler->setLoadMode (lmode);
471 bool ok = reader.parse( source );
472 blockReposition=false;
473 blockSaveState=blockSaveStateOrg;
474 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
478 reposition(); // FIXME-2 VM reposition the view instead...
479 emitSelectionChanged();
485 autosaveTimer->stop();
488 // Reset timestamp to check for later updates of file
489 fileChangedTime=QFileInfo (destPath).lastModified();
492 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
493 tr( handler->errorProtocol() ) );
495 // Still return "success": the map maybe at least
496 // partially read by the parser
501 removeDir (QDir(tmpZipDir));
503 // Restore original zip state
510 ErrorCode VymModel::save (const SaveMode &savemode)
514 QString safeFilePath;
516 ErrorCode err=success;
520 mapFileName=mapName+".xml";
522 // use name given by user, even if he chooses .doc
523 mapFileName=fileName;
525 // Look, if we should zip the data:
528 QMessageBox mb( vymName,
529 tr("The map %1\ndid not use the compressed "
530 "vym file format.\nWriting it uncompressed will also write images \n"
531 "and flags and thus may overwrite files in the "
532 "given directory\n\nDo you want to write the map").arg(filePath),
533 QMessageBox::Warning,
534 QMessageBox::Yes | QMessageBox::Default,
536 QMessageBox::Cancel | QMessageBox::Escape);
537 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
538 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
539 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
542 case QMessageBox::Yes:
543 // save compressed (default file format)
546 case QMessageBox::No:
550 case QMessageBox::Cancel:
557 // First backup existing file, we
558 // don't want to add to old zip archives
562 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
564 QString backupFileName(destPath + "~");
565 QFile backupFile(backupFileName);
566 if (backupFile.exists() && !backupFile.remove())
568 QMessageBox::warning(0, tr("Save Error"),
569 tr("%1\ncould not be removed before saving").arg(backupFileName));
571 else if (!f.rename(backupFileName))
573 QMessageBox::warning(0, tr("Save Error"),
574 tr("%1\ncould not be renamed before saving").arg(destPath));
581 // Create temporary directory for packing
583 tmpZipDir=makeTmpDir (ok,"vym-zip");
586 QMessageBox::critical( 0, tr( "Critical Load Error" ),
587 tr("Couldn't create temporary directory before save\n"));
591 safeFilePath=filePath;
592 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
595 // Create mapName and fileDir
596 makeSubDirs (fileDir);
599 if (savemode==CompleteMap || selModel->selection().isEmpty())
602 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
605 autosaveTimer->stop();
610 if (selectionType()==TreeItem::Image)
613 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
614 // TODO take care of multiselections
617 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
620 qWarning ("ME::saveStringToDisk failed!");
626 if (err==success) err=zipDir (tmpZipDir,destPath);
629 removeDir (QDir(tmpZipDir));
631 // Restore original filepath outside of tmp zip dir
632 setFilePath (safeFilePath);
636 fileChangedTime=QFileInfo (destPath).lastModified();
640 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
642 QString pathDir=path.left(path.findRev("/"));
648 // We need to parse saved XML data
649 parseVYMHandler handler;
650 QXmlInputSource source( file);
651 QXmlSimpleReader reader;
652 reader.setContentHandler( &handler );
653 reader.setErrorHandler( &handler );
654 handler.setModel ( this);
655 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
656 if (undoSel.isEmpty())
660 handler.setLoadMode (NewMap);
664 handler.setLoadMode (ImportReplace);
666 blockReposition=true;
667 bool ok = reader.parse( source );
668 blockReposition=false;
671 // This should never ever happen
672 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
673 handler.errorProtocol());
676 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
679 bool VymModel::addMapInsertInt (const QString &path)
681 QString pathDir=path.left(path.findRev("/"));
687 // We need to parse saved XML data
688 parseVYMHandler handler;
689 QXmlInputSource source( file);
690 QXmlSimpleReader reader;
691 reader.setContentHandler( &handler );
692 reader.setErrorHandler( &handler );
693 handler.setModel (this);
694 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
695 handler.setLoadMode (ImportAdd);
696 blockReposition=true;
697 bool ok = reader.parse( source );
698 blockReposition=false;
699 if ( ok ) return true;
701 // This should never ever happen
702 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
703 handler.errorProtocol());
706 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
710 bool VymModel::addMapInsertInt (const QString &path, int pos)
712 BranchItem *selbi=getSelectedBranch();
715 if (addMapInsertInt (path))
717 if (selbi->depth()>0)
718 relinkBranch (selbi->getLastBranch(), selbi,pos);
722 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
726 qWarning ("ME::addMapInsertInt nothing selected");
730 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
732 ImageItem *ii=createImage(dst);
742 void VymModel::loadFloatImage ()
744 BranchItem *selbi=getSelectedBranch();
748 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
749 fd->setMode (Q3FileDialog::ExistingFiles);
750 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
751 ImagePreview *p =new ImagePreview (fd);
752 fd->setContentsPreviewEnabled( TRUE );
753 fd->setContentsPreview( p, p );
754 fd->setPreviewMode( Q3FileDialog::Contents );
755 fd->setCaption(vymName+" - " +tr("Load image"));
756 fd->setDir (lastImageDir);
759 if ( fd->exec() == QDialog::Accepted )
761 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
762 lastImageDir=QDir (fd->dirPath());
765 for (int j=0; j<fd->selectedFiles().count(); j++)
767 s=fd->selectedFiles().at(j);
768 ii=loadFloatImageInt (selbi,s);
769 //FIXME-3 check savestate for loadImage
775 QString ("loadImage (%1)").arg(s ),
776 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
779 // TODO loadFIO error handling
780 qWarning ("Failed to load "+s);
788 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
793 void VymModel::saveFloatImage ()
795 ImageItem *ii=getSelectedImage();
798 QFileDialog *fd=new QFileDialog( NULL);
799 fd->setFilters (imageIO.getFilters());
800 fd->setCaption(vymName+" - " +tr("Save image"));
801 fd->setFileMode( QFileDialog::AnyFile );
802 fd->setDirectory (lastImageDir);
803 // fd->setSelection (fio->getOriginalFilename());
807 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
809 fn=fd->selectedFiles().at(0);
810 if (QFile (fn).exists() )
812 QMessageBox mb( vymName,
813 tr("The file %1 exists already.\n"
814 "Do you want to overwrite it?").arg(fn),
815 QMessageBox::Warning,
816 QMessageBox::Yes | QMessageBox::Default,
817 QMessageBox::Cancel | QMessageBox::Escape,
818 QMessageBox::NoButton );
820 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
821 mb.setButtonText( QMessageBox::No, tr("Cancel"));
824 case QMessageBox::Yes:
827 case QMessageBox::Cancel:
834 saveFloatImageInt (ii,fd->selectedFilter(),fn );
841 void VymModel::importDirInt(BranchItem *dst, QDir d)
843 BranchItem *selbi=getSelectedBranch();
847 // Traverse directories
848 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
849 QFileInfoList list = d.entryInfoList();
852 for (int i = 0; i < list.size(); ++i)
855 if (fi.fileName() != "." && fi.fileName() != ".." )
857 bi=addNewBranchInt(dst,-2);
858 bi->setHeading (fi.fileName() ); // FIXME-3 check this
859 bi->setHeadingColor (QColor("blue"));
861 if ( !d.cd(fi.fileName()) )
862 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
865 // Recursively add subdirs
872 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
873 list = d.entryInfoList();
875 for (int i = 0; i < list.size(); ++i)
878 bi=addNewBranchInt (dst,-2);
879 bi->setHeading (fi.fileName() );
880 bi->setHeadingColor (QColor("black"));
881 if (fi.fileName().right(4) == ".vym" )
882 bi->setVymLink (fi.filePath());
887 void VymModel::importDirInt (const QString &s)
889 BranchItem *selbi=getSelectedBranch();
892 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
895 importDirInt (selbi,d);
899 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
901 BranchItem *selbi=getSelectedBranch();
905 filters <<"VYM map (*.vym)";
906 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
907 fd->setMode (QFileDialog::DirectoryOnly);
908 fd->setFilters (filters);
909 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
913 if ( fd->exec() == QDialog::Accepted )
915 importDirInt (fd->selectedFile() );
917 //FIXME-3 VM needed? scene()->update();
923 void VymModel::autosave()
928 cout << "VymModel::autosave rejected due to missing filePath\n";
931 QDateTime now=QDateTime().currentDateTime();
933 // Disable autosave, while we have gone back in history
934 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
935 if (redosAvail>0) return;
937 // Also disable autosave for new map without filename
938 if (filePath.isEmpty()) return;
941 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
943 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
944 mainWindow->fileSave (this);
947 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
952 void VymModel::fileChanged()
954 // Check if file on disk has changed meanwhile
955 if (!filePath.isEmpty())
957 QDateTime tmod=QFileInfo (filePath).lastModified();
958 if (tmod>fileChangedTime)
960 // FIXME-2 VM switch to current mapeditor and finish lineedits...
961 QMessageBox mb( vymName,
962 tr("The file of the map on disk has changed:\n\n"
963 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
964 QMessageBox::Question,
966 QMessageBox::Cancel | QMessageBox::Default,
967 QMessageBox::NoButton );
969 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
970 mb.setButtonText( QMessageBox::No, tr("Ignore"));
973 case QMessageBox::Yes:
975 load (filePath,NewMap,fileType);
976 case QMessageBox::Cancel:
977 fileChangedTime=tmod; // allow autosave to overwrite newer file!
983 bool VymModel::isDefault()
988 void VymModel::makeDefault()
994 bool VymModel::hasChanged()
999 void VymModel::setChanged()
1002 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1006 latestAddedItem=NULL;
1010 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1012 if (!lmo || !lmo->getTreeItem() ) return QString();
1013 return getObjectName (lmo->getTreeItem() );
1017 QString VymModel::getObjectName (TreeItem *ti)
1020 if (!ti) return QString("Error: NULL has no name!");
1022 if (s=="") s="unnamed";
1024 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1027 void VymModel::redo()
1029 // Can we undo at all?
1030 if (redosAvail<1) return;
1032 bool blockSaveStateOrg=blockSaveState;
1033 blockSaveState=true;
1037 if (undosAvail<stepsTotal) undosAvail++;
1039 if (curStep>stepsTotal) curStep=1;
1040 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1041 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1042 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1043 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1044 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1045 QString version=undoSet.readEntry ("/history/version");
1047 /* TODO Maybe check for version, if we save the history
1048 if (!checkVersion(version))
1049 QMessageBox::warning(0,tr("Warning"),
1050 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1053 // Find out current undo directory
1054 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1058 cout << "VymModel::redo() begin\n";
1059 cout << " undosAvail="<<undosAvail<<endl;
1060 cout << " redosAvail="<<redosAvail<<endl;
1061 cout << " curStep="<<curStep<<endl;
1062 cout << " ---------------------------"<<endl;
1063 cout << " comment="<<comment.toStdString()<<endl;
1064 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1065 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1066 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1067 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1068 cout << " ---------------------------"<<endl<<endl;
1071 // select object before redo
1072 if (!redoSelection.isEmpty())
1073 select (redoSelection);
1078 parseAtom (redoCommand,noErr,errMsg);
1080 blockSaveState=blockSaveStateOrg;
1082 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1083 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1084 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1085 undoSet.writeSettings(histPath);
1087 mainWindow->updateHistory (undoSet);
1090 /* TODO remove testing
1091 cout << "ME::redo() end\n";
1092 cout << " undosAvail="<<undosAvail<<endl;
1093 cout << " redosAvail="<<redosAvail<<endl;
1094 cout << " curStep="<<curStep<<endl;
1095 cout << " ---------------------------"<<endl<<endl;
1101 bool VymModel::isRedoAvailable()
1103 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1109 void VymModel::undo()
1111 // Can we undo at all?
1112 if (undosAvail<1) return;
1114 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1116 bool blockSaveStateOrg=blockSaveState;
1117 blockSaveState=true;
1119 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1120 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1121 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1122 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1123 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1124 QString version=undoSet.readEntry ("/history/version");
1126 /* TODO Maybe check for version, if we save the history
1127 if (!checkVersion(version))
1128 QMessageBox::warning(0,tr("Warning"),
1129 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1132 // Find out current undo directory
1133 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1135 // select object before undo
1136 if (!select (undoSelection))
1138 qWarning ("VymModel::undo() Could not select object for undo");
1144 cout << "VymModel::undo() begin\n";
1145 cout << " undosAvail="<<undosAvail<<endl;
1146 cout << " redosAvail="<<redosAvail<<endl;
1147 cout << " curStep="<<curStep<<endl;
1148 cout << " ---------------------------"<<endl;
1149 cout << " comment="<<comment.toStdString()<<endl;
1150 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1151 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1152 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1153 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1154 cout << " ---------------------------"<<endl<<endl;
1159 parseAtom (redoCommand,noErr,errMsg);
1163 if (curStep<1) curStep=stepsTotal;
1167 blockSaveState=blockSaveStateOrg;
1169 cout << "VymModel::undo() end\n";
1170 cout << " undosAvail="<<undosAvail<<endl;
1171 cout << " redosAvail="<<redosAvail<<endl;
1172 cout << " curStep="<<curStep<<endl;
1173 cout << " ---------------------------"<<endl<<endl;
1176 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1177 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1178 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1179 undoSet.writeSettings(histPath);
1181 mainWindow->updateHistory (undoSet);
1183 //emitSelectionChanged();
1186 bool VymModel::isUndoAvailable()
1188 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1194 void VymModel::gotoHistoryStep (int i)
1196 // Restore variables
1197 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1198 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1200 if (i<0) i=undosAvail+redosAvail;
1202 // Clicking above current step makes us undo things
1205 for (int j=0; j<undosAvail-i; j++) undo();
1208 // Clicking below current step makes us redo things
1210 for (int j=undosAvail; j<i; j++)
1212 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1216 // And ignore clicking the current row ;-)
1220 QString VymModel::getHistoryPath()
1222 QString histName(QString("history-%1").arg(curStep));
1223 return (tmpMapDir+"/"+histName);
1226 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1228 sendData(redoCom); //FIXME-3 testing
1233 if (blockSaveState) return;
1235 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1237 // Find out current undo directory
1238 if (undosAvail<stepsTotal) undosAvail++;
1240 if (curStep>stepsTotal) curStep=1;
1242 QString backupXML="";
1243 QString histDir=getHistoryPath();
1244 QString bakMapPath=histDir+"/map.xml";
1246 // Create histDir if not available
1249 makeSubDirs (histDir);
1251 // Save depending on how much needs to be saved
1253 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1255 QString undoCommand="";
1256 if (savemode==UndoCommand)
1258 undoCommand=undoCom;
1260 else if (savemode==PartOfMap )
1262 undoCommand=undoCom;
1263 undoCommand.replace ("PATH",bakMapPath);
1267 if (!backupXML.isEmpty())
1268 // Write XML Data to disk
1269 saveStringToDisk (bakMapPath,backupXML);
1271 // We would have to save all actions in a tree, to keep track of
1272 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1275 // Write the current state to disk
1276 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1277 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1278 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1279 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1280 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1282 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1283 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1284 undoSet.setEntry (QString("/history/version"),vymVersion);
1285 undoSet.writeSettings(histPath);
1289 // TODO remove after testing
1290 //cout << " into="<< histPath.toStdString()<<endl;
1291 cout << " stepsTotal="<<stepsTotal<<
1292 ", undosAvail="<<undosAvail<<
1293 ", redosAvail="<<redosAvail<<
1294 ", curStep="<<curStep<<endl;
1295 cout << " ---------------------------"<<endl;
1296 cout << " comment="<<comment.toStdString()<<endl;
1297 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1298 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1299 cout << " redoCom="<<redoCom.toStdString()<<endl;
1300 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1301 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1302 cout << " ---------------------------"<<endl;
1305 mainWindow->updateHistory (undoSet);
1311 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1313 // save the selected part of the map, Undo will replace part of map
1314 QString undoSelection="";
1316 undoSelection=getSelectString(undoSel);
1318 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1319 QString redoSelection="";
1321 redoSelection=getSelectString(undoSel);
1323 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1326 saveState (PartOfMap,
1327 undoSelection, "addMapReplace (\"PATH\")",
1333 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1337 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1340 QString undoSelection;
1341 QString redoSelection=getSelectString(redoSel);
1342 if (redoSel->getType()==TreeItem::Branch)
1344 undoSelection=getSelectString (redoSel->parent());
1345 // save the selected branch of the map, Undo will insert part of map
1346 saveState (PartOfMap,
1347 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1348 redoSelection, "delete ()",
1352 if (redoSel->getType()==TreeItem::MapCenter)
1354 // save the selected branch of the map, Undo will insert part of map
1355 saveState (PartOfMap,
1356 undoSelection, QString("addMapInsert (\"PATH\")"),
1357 redoSelection, "delete ()",
1364 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1366 // "Normal" savestate: save commands, selections and comment
1367 // so just save commands for undo and redo
1368 // and use current selection
1370 QString redoSelection="";
1371 if (redoSel) redoSelection=getSelectString(redoSel);
1372 QString undoSelection="";
1373 if (undoSel) undoSelection=getSelectString(undoSel);
1375 saveState (UndoCommand,
1382 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1384 // "Normal" savestate: save commands, selections and comment
1385 // so just save commands for undo and redo
1386 // and use current selection
1387 saveState (UndoCommand,
1394 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1396 // "Normal" savestate applied to model (no selection needed):
1397 // save commands and comment
1398 saveState (UndoCommand,
1406 QGraphicsScene* VymModel::getScene ()
1411 TreeItem* VymModel::findBySelectString(QString s)
1413 if (s.isEmpty() ) return NULL;
1415 // Old maps don't have multiple mapcenters and don't save full path
1416 if (s.left(2) !="mc")
1419 QStringList parts=s.split (",");
1422 TreeItem *ti=rootItem;
1424 while (!parts.isEmpty() )
1426 typ=parts.first().left(2);
1427 n=parts.first().right(parts.first().length() - 3).toInt();
1428 parts.removeFirst();
1429 if (typ=="mc" || typ=="bo")
1430 ti=ti->getBranchNum (n);
1432 ti=ti->getImageNum (n);
1434 ti=ti->getAttributeNum (n);
1436 ti=ti->getXLinkNum (n);
1437 if(!ti) return NULL;
1442 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1444 BranchItem *cur=NULL;
1445 BranchItem *prev=NULL;
1446 nextBranch(cur,prev);
1449 if (s==cur->getID() ) return cur;
1450 nextBranch(cur,prev);
1455 //////////////////////////////////////////////
1457 //////////////////////////////////////////////
1458 void VymModel::setVersion (const QString &s)
1463 void VymModel::setAuthor (const QString &s)
1466 QString ("setMapAuthor (\"%1\")").arg(author),
1467 QString ("setMapAuthor (\"%1\")").arg(s),
1468 QString ("Set author of map to \"%1\"").arg(s)
1473 QString VymModel::getAuthor()
1478 void VymModel::setComment (const QString &s)
1481 QString ("setMapComment (\"%1\")").arg(comment),
1482 QString ("setMapComment (\"%1\")").arg(s),
1483 QString ("Set comment of map")
1488 QString VymModel::getComment ()
1493 QString VymModel::getDate ()
1495 return QDate::currentDate().toString ("yyyy-MM-dd");
1498 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1501 BranchItem *cur=NULL;
1502 BranchItem *prev=NULL;
1503 nextBranch(cur,prev);
1507 nextBranch(cur,prev);
1512 void VymModel::setSortFilter (const QString &s)
1515 emit (sortFilterChanged (sortFilter));
1518 QString VymModel::getSortFilter ()
1523 void VymModel::setHeading(const QString &s)
1525 BranchItem *selbi=getSelectedBranch();
1530 "setHeading (\""+selbi->getHeading()+"\")",
1532 "setHeading (\""+s+"\")",
1533 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1534 selbi->setHeading(s );
1535 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1537 emitSelectionChanged();
1541 QString VymModel::getHeading()
1543 TreeItem *selti=getSelectedItem();
1545 return selti->getHeading();
1550 void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here)
1552 TreeItem *selti=getSelectedItem();
1556 emitNoteHasChanged(selti);
1560 QString VymModel::getNote()
1562 TreeItem *selti=getSelectedItem();
1564 return selti->getNote();
1569 BranchItem* VymModel::findText (QString s, bool cs)
1571 QTextDocument::FindFlags flags=0;
1572 if (cs) flags=QTextDocument::FindCaseSensitively;
1575 { // Nothing found or new find process
1577 // nothing found, start again
1581 nextBranch (findCurrent,findPrevious);
1583 bool searching=true;
1584 bool foundNote=false;
1585 while (searching && !EOFind)
1589 // Searching in Note
1590 if (findCurrent->getNote().contains(s,cs))
1592 select (findCurrent);
1594 if (getSelectedBranch()!=itFind)
1597 emitShowSelection();
1600 if (textEditor->findText(s,flags))
1606 // Searching in Heading
1607 if (searching && findCurrent->getHeading().contains (s,cs) )
1609 select(findCurrent);
1615 if (!nextBranch(findCurrent,findPrevious) )
1618 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1621 return getSelectedBranch();
1626 void VymModel::findReset()
1627 { // Necessary if text to find changes during a find process
1633 void VymModel::setScene (QGraphicsScene *s)
1638 void VymModel::setURL(const QString &url)
1640 TreeItem *selti=getSelectedItem();
1643 QString oldurl=selti->getURL();
1644 selti->setURL (url);
1647 QString ("setURL (\"%1\")").arg(oldurl),
1649 QString ("setURL (\"%1\")").arg(url),
1650 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1653 emitDataHasChanged (selti);
1654 emitShowSelection();
1658 QString VymModel::getURL()
1660 TreeItem *selti=getSelectedItem();
1662 return selti->getURL();
1667 QStringList VymModel::getURLs()
1670 BranchItem *selbi=getSelectedBranch();
1671 BranchItem *cur=selbi;
1672 BranchItem *prev=NULL;
1675 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1676 cur=nextBranch (cur,prev,true,selbi);
1682 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1684 BranchItem *bi=getSelectedBranch();
1687 BranchObj *bo=(BranchObj*)(bi->getLMO());
1690 QString s=bo->getFrameTypeName();
1691 bo->setFrameType (t);
1692 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1693 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1695 bo->updateLinkGeometry();
1700 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1702 BranchItem *bi=getSelectedBranch();
1705 BranchObj *bo=(BranchObj*)(bi->getLMO());
1708 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1709 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1710 bo->setFrameType (s);
1712 bo->updateLinkGeometry();
1717 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1720 BranchItem *bi=getSelectedBranch();
1723 BranchObj *bo=(BranchObj*)(bi->getLMO());
1726 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1727 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1728 bo->setFramePenColor (c);
1733 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1735 BranchItem *bi=getSelectedBranch();
1738 BranchObj *bo=(BranchObj*)(bi->getLMO());
1741 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1742 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1743 bo->setFrameBrushColor (c);
1748 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1750 BranchItem *bi=getSelectedBranch();
1753 BranchObj *bo=(BranchObj*)(bi->getLMO());
1756 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1757 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1758 bo->setFramePadding (i);
1760 bo->updateLinkGeometry();
1765 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1767 BranchItem *bi=getSelectedBranch();
1770 BranchObj *bo=(BranchObj*)(bi->getLMO());
1773 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1774 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1775 bo->setFrameBorderWidth (i);
1777 bo->updateLinkGeometry();
1782 void VymModel::setIncludeImagesVer(bool b)
1784 BranchItem *bi=getSelectedBranch();
1787 QString u= b ? "false" : "true";
1788 QString r=!b ? "false" : "true";
1792 QString("setIncludeImagesVertically (%1)").arg(u),
1794 QString("setIncludeImagesVertically (%1)").arg(r),
1795 QString("Include images vertically in %1").arg(getObjectName(bi))
1797 bi->setIncludeImagesVer(b);
1798 emitDataHasChanged ( bi);
1803 void VymModel::setIncludeImagesHor(bool b)
1805 BranchItem *bi=getSelectedBranch();
1808 QString u= b ? "false" : "true";
1809 QString r=!b ? "false" : "true";
1813 QString("setIncludeImagesHorizontally (%1)").arg(u),
1815 QString("setIncludeImagesHorizontally (%1)").arg(r),
1816 QString("Include images horizontally in %1").arg(getObjectName(bi))
1818 bi->setIncludeImagesHor(b);
1819 emitDataHasChanged ( bi);
1824 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1826 TreeItem *ti=getSelectedItem();
1827 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1829 QString u= b ? "false" : "true";
1830 QString r=!b ? "false" : "true";
1834 QString("setHideLinkUnselected (%1)").arg(u),
1836 QString("setHideLinkUnselected (%1)").arg(r),
1837 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1839 ((MapItem*)ti)->setHideLinkUnselected(b);
1843 void VymModel::setHideExport(bool b)
1845 TreeItem *ti=getSelectedItem();
1847 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1849 ti->setHideInExport (b);
1850 QString u= b ? "false" : "true";
1851 QString r=!b ? "false" : "true";
1855 QString ("setHideExport (%1)").arg(u),
1857 QString ("setHideExport (%1)").arg(r),
1858 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1860 emitDataHasChanged(ti);
1861 emitSelectionChanged();
1864 // emitSelectionChanged();
1865 // FIXME-3 VM needed? scene()->update();
1869 void VymModel::toggleHideExport()
1871 TreeItem *selti=getSelectedItem();
1873 setHideExport ( !selti->hideInExport() );
1876 void VymModel::addTimestamp() //FIXME-3 new function, localize
1878 BranchItem *selbi=addNewBranch();
1881 QDate today=QDate::currentDate();
1883 selbi->setHeading (QString ("%1-%2-%3")
1884 .arg(today.year(),4,10,c)
1885 .arg(today.month(),2,10,c)
1886 .arg(today.day(),2,10,c));
1887 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1894 void VymModel::copy()
1896 TreeItem *selti=getSelectedItem();
1898 (selti->getType() == TreeItem::Branch ||
1899 selti->getType() == TreeItem::MapCenter ||
1900 selti->getType() == TreeItem::Image ))
1902 if (redosAvail == 0)
1905 QString s=getSelectString(selti);
1906 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1907 curClipboard=curStep;
1910 // Copy also to global clipboard, because we are at last step in history
1911 QString bakMapName(QString("history-%1").arg(curStep));
1912 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1913 copyDir (bakMapDir,clipboardDir );
1915 clipboardEmpty=false;
1921 void VymModel::pasteNoSave(const int &n)
1923 bool old=blockSaveState;
1924 blockSaveState=true;
1925 bool zippedOrg=zipped;
1926 if (redosAvail > 0 || n!=0)
1928 // Use the "historical" buffer
1929 QString bakMapName(QString("history-%1").arg(n));
1930 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1931 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1933 // Use the global buffer
1934 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1939 void VymModel::paste()
1941 BranchItem *selbi=getSelectedBranch();
1944 saveStateChangingPart(
1947 QString ("paste (%1)").arg(curClipboard),
1948 QString("Paste to %1").arg( getObjectName(selbi))
1955 void VymModel::cut()
1957 TreeItem *selti=getSelectedItem();
1958 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1966 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1968 if (bi && bi->canMoveUp())
1969 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1974 void VymModel::moveUp()
1976 BranchItem *selbi=getSelectedBranch();
1979 QString oldsel=getSelectString();
1982 getSelectString(),"moveDown ()",
1984 QString("Move up %1").arg(getObjectName(selbi)));
1988 bool VymModel::moveDown(BranchItem *bi)
1990 if (bi && bi->canMoveDown())
1991 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
1996 void VymModel::moveDown()
1998 BranchItem *selbi=getSelectedBranch();
2001 QString oldsel=getSelectString();
2002 if ( moveDown(selbi))
2004 getSelectString(),"moveUp ()",
2005 oldsel,"moveDown ()",
2006 QString("Move down %1").arg(getObjectName(selbi)));
2010 void VymModel::detach()
2012 BranchItem *selbi=getSelectedBranch();
2013 if (selbi && selbi->depth()>0)
2015 // if no relPos have been set before, try to use current rel positions
2016 if (selbi->getLMO())
2017 for (int i=0; i<selbi->branchCount();++i)
2018 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2020 //QString oldsel=getSelectString();
2021 if ( relinkBranch (selbi,rootItem,-1) )
2023 selbi,QString("relink()"), //FIXME-1 add paramters when detaching
2025 QString("Detach %1").arg(getObjectName(selbi))
2030 void VymModel::sortChildren()
2032 BranchItem* selbi=getSelectedBranch();
2035 if(selbi->branchCount()>1)
2037 saveStateChangingPart(
2038 selbi,selbi, "sortChildren ()",
2039 QString("Sort children of %1").arg(getObjectName(selbi)));
2040 selbi->sortChildren();
2042 emitShowSelection();
2047 BranchItem* VymModel::createMapCenter()
2049 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2053 BranchItem* VymModel::createBranch(BranchItem *dst)
2056 return addNewBranchInt (dst,-2);
2061 ImageItem* VymModel::createImage(BranchItem *dst)
2068 QList<QVariant> cData;
2069 cData << "new" << "undef";
2071 ImageItem *newii=new ImageItem(cData) ;
2072 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2074 emit (layoutAboutToBeChanged() );
2077 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2078 n=dst->getRowNumAppend(newii);
2079 beginInsertRows (parix,n,n);
2080 dst->appendChild (newii);
2083 emit (layoutChanged() );
2085 // save scroll state. If scrolled, automatically select
2086 // new branch in order to tmp unscroll parent...
2087 newii->createMapObj(mapScene);
2094 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2101 QList<QVariant> cData;
2102 cData << "new xLink"<<"undef";
2104 XLinkItem *newxli=new XLinkItem(cData) ;
2105 newxli->setBegin (bi);
2107 emit (layoutAboutToBeChanged() );
2110 n=bi->getRowNumAppend(newxli);
2111 beginInsertRows (parix,n,n);
2112 bi->appendChild (newxli);
2115 emit (layoutChanged() );
2117 // save scroll state. If scrolled, automatically select
2118 // new branch in order to tmp unscroll parent...
2121 newxli->createMapObj(mapScene);
2129 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2131 BranchItem *selbi=getSelectedBranch();
2134 QList<QVariant> cData;
2135 cData << "new attribute" << "undef";
2136 AttributeItem *a=new AttributeItem (cData);
2138 emit (layoutAboutToBeChanged() );
2140 QModelIndex parix=index(selbi);
2141 int n=selbi->getRowNumAppend (a);
2142 beginInsertRows (parix,n,n);
2143 selbi->appendChild (a);
2146 emit (layoutChanged() );
2154 BranchItem* VymModel::addMapCenter ()
2156 BranchItem *bi=addMapCenter (contextPos);
2158 emitShowSelection();
2163 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2164 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2169 BranchItem* VymModel::addMapCenter(QPointF absPos)
2170 // createMapCenter could then probably be merged with createBranch
2174 QModelIndex parix=index(rootItem);
2176 QList<QVariant> cData;
2177 cData << "VM:addMapCenter" << "undef";
2178 BranchItem *newbi=new BranchItem (cData,rootItem);
2179 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2180 int n=rootItem->getRowNumAppend (newbi);
2182 emit (layoutAboutToBeChanged() );
2183 beginInsertRows (parix,n,n);
2185 rootItem->appendChild (newbi);
2188 emit (layoutChanged() );
2191 newbi->setPositionMode (MapItem::Absolute);
2192 BranchObj *bo=newbi->createMapObj(mapScene);
2193 if (bo) bo->move (absPos);
2198 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2200 // Depending on pos:
2201 // -3 insert in children of parent above selection
2202 // -2 add branch to selection
2203 // -1 insert in children of parent below selection
2204 // 0..n insert in children of parent at pos
2207 QList<QVariant> cData;
2208 cData << "" << "undef";
2213 BranchItem *newbi=new BranchItem (cData);
2214 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2216 emit (layoutAboutToBeChanged() );
2222 n=parbi->getRowNumAppend (newbi);
2223 beginInsertRows (parix,n,n);
2224 parbi->appendChild (newbi);
2226 }else if (num==-1 || num==-3)
2228 // insert below selection
2229 parbi=(BranchItem*)dst->parent();
2232 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2233 beginInsertRows (parix,n,n);
2234 parbi->insertBranch(n,newbi);
2237 emit (layoutChanged() );
2239 // Set color of heading to that of parent
2240 newbi->setHeadingColor (parbi->getHeadingColor());
2242 // save scroll state. If scrolled, automatically select
2243 // new branch in order to tmp unscroll parent...
2244 newbi->createMapObj(mapScene);
2249 BranchItem* VymModel::addNewBranch(int pos)
2251 // Different meaning than num in addNewBranchInt!
2255 BranchItem *newbi=NULL;
2256 BranchItem *selbi=getSelectedBranch();
2260 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2262 newbi=addNewBranchInt (selbi,pos-2);
2270 QString ("addBranch (%1)").arg(pos),
2271 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2274 // emitSelectionChanged(); FIXME-3
2275 latestAddedItem=newbi;
2276 // In Network mode, the client needs to know where the new branch is,
2277 // so we have to pass on this information via saveState.
2278 // TODO: Get rid of this positioning workaround
2279 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2280 sendData ("selectLatestAdded ()");
2281 sendData (QString("move %1").arg(ps));
2290 BranchItem* VymModel::addNewBranchBefore()
2292 BranchItem *newbi=NULL;
2293 BranchItem *selbi=getSelectedBranch();
2294 if (selbi && selbi->getType()==TreeItem::Branch)
2295 // We accept no MapCenter here, so we _have_ a parent
2297 //QPointF p=bo->getRelPos();
2300 // add below selection
2301 newbi=addNewBranchInt (selbi,-1);
2305 //newbi->move2RelPos (p);
2307 // Move selection to new branch
2308 relinkBranch (selbi,newbi,0);
2310 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2311 QString ("Add branch before %1").arg(getObjectName(selbi)));
2313 // FIXME-3 needed? reposition();
2314 // emitSelectionChanged(); FIXME-3
2320 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2326 emit (layoutAboutToBeChanged() );
2327 BranchItem *branchpi=(BranchItem*)branch->parent();
2328 // Remove at current position
2329 int n=branch->childNum();
2330 beginRemoveRows (index(branchpi),n,n);
2331 branchpi->removeChild (n);
2334 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2336 // Append as last branch to dst
2337 if (dst->branchCount()==0)
2340 n=dst->getFirstBranch()->childNumber();
2341 beginInsertRows (index(dst),n+pos,n+pos);
2342 dst->insertBranch (pos,branch);
2345 // Correct type if necessesary
2346 if (branch->getType()==TreeItem::MapCenter)
2347 branch->setType(TreeItem::Branch);
2349 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2350 branch->updateStyles();
2352 emit (layoutChanged() );
2353 reposition(); // both for moveUp/Down and relinking
2354 if (dst->isScrolled() )
2357 branch->updateVisibility();
2366 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2370 emit (layoutAboutToBeChanged() );
2372 BranchItem *pi=(BranchItem*)(image->parent());
2373 QString oldParString=getSelectString (pi);
2374 // Remove at current position
2375 int n=image->childNum();
2376 beginRemoveRows (index(pi),n,n);
2377 pi->removeChild (n);
2381 QModelIndex dstix=index(dst);
2382 n=dst->getRowNumAppend (image);
2383 beginInsertRows (dstix,n,n+1);
2384 dst->appendChild (image);
2387 // Set new parent also for lmo
2388 if (image->getLMO() && dst->getLMO() )
2389 image->getLMO()->setParObj (dst->getLMO() );
2391 emit (layoutChanged() );
2394 QString("relinkTo (\"%1\")").arg(oldParString),
2396 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2397 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2403 void VymModel::deleteSelection()
2405 BranchItem *selbi=getSelectedBranch();
2410 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2412 TreeItem *pi=deleteItem (selbi);
2416 emitShowSelection();
2420 TreeItem *ti=getSelectedItem();
2422 { // Delete other item
2423 TreeItem *pi=ti->parent();
2425 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2427 saveStateChangingPart(
2431 QString("Delete %1").arg(getObjectName(ti))
2435 emitDataHasChanged (pi);
2438 emitShowSelection();
2439 } else if (ti->getType()==TreeItem::XLink)
2441 //FIXME-2 savestate missing
2444 qWarning ("VymmModel::deleteSelection() unknown type?!");
2448 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2451 BranchItem *selbi=getSelectedBranch();
2455 // Don't use this on mapcenter
2456 if (selbi->depth()<2) return;
2458 pi=(BranchItem*)(selbi->parent());
2459 // Check if we have childs at all to keep
2460 if (selbi->branchCount()==0)
2467 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2468 saveStateChangingPart(
2471 "deleteKeepChildren ()",
2472 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2475 QString sel=getSelectString(selbi);
2477 int pos=selbi->num();
2478 BranchItem *bi=selbi->getFirstBranch();
2481 relinkBranch (bi,pi,pos);
2482 bi=selbi->getFirstBranch();
2488 BranchObj *bo=getSelectedBranchObj();
2491 bo->move2RelPos (p);
2497 void VymModel::deleteChildren()
2500 BranchItem *selbi=getSelectedBranch();
2503 saveStateChangingPart(
2506 "deleteChildren ()",
2507 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2509 emit (layoutAboutToBeChanged() );
2511 QModelIndex ix=index (selbi);
2512 int n=selbi->branchCount()-1;
2513 beginRemoveRows (ix,0,n);
2514 removeRows (0,n+1,ix);
2516 if (selbi->isScrolled()) selbi->unScroll();
2517 emit (layoutChanged() );
2522 TreeItem* VymModel::deleteItem (TreeItem *ti)
2526 TreeItem *pi=ti->parent();
2527 QModelIndex parentIndex=index(pi);
2529 emit (layoutAboutToBeChanged() );
2531 int n=ti->childNum();
2532 beginRemoveRows (parentIndex,n,n);
2533 removeRows (n,1,parentIndex);
2537 emit (layoutChanged() );
2538 if (pi->depth()>=0) return pi;
2543 void VymModel::clearItem (TreeItem *ti)
2547 QModelIndex parentIndex=index(ti);
2548 if (!parentIndex.isValid()) return;
2550 int n=ti->childCount();
2553 emit (layoutAboutToBeChanged() );
2555 beginRemoveRows (parentIndex,0,n-1);
2556 removeRows (0,n,parentIndex);
2560 emit (layoutChanged() );
2566 bool VymModel::scrollBranch(BranchItem *bi)
2570 if (bi->isScrolled()) return false;
2571 if (bi->branchCount()==0) return false;
2572 if (bi->depth()==0) return false;
2573 if (bi->toggleScroll())
2581 QString ("%1 ()").arg(u),
2583 QString ("%1 ()").arg(r),
2584 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2586 emitDataHasChanged(bi);
2587 emitSelectionChanged();
2588 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2595 bool VymModel::unscrollBranch(BranchItem *bi)
2599 if (!bi->isScrolled()) return false;
2600 if (bi->branchCount()==0) return false;
2601 if (bi->depth()==0) return false;
2602 if (bi->toggleScroll())
2610 QString ("%1 ()").arg(u),
2612 QString ("%1 ()").arg(r),
2613 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2615 emitDataHasChanged(bi);
2616 emitSelectionChanged();
2617 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2624 void VymModel::toggleScroll()
2626 BranchItem *bi=(BranchItem*)getSelectedBranch();
2627 if (bi && bi->isBranchLikeType() )
2629 if (bi->isScrolled())
2630 unscrollBranch (bi);
2634 // saveState & reposition are called in above functions
2637 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2639 BranchItem *selbi=getSelectedBranch();
2640 BranchItem *prev=NULL;
2641 BranchItem *cur=selbi;
2644 saveStateChangingPart(
2647 QString ("unscrollChildren ()"),
2648 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2652 if (cur->isScrolled())
2654 cur->toggleScroll();
2655 emitDataHasChanged (cur);
2657 cur=nextBranch (cur,prev,true,selbi);
2664 void VymModel::emitExpandAll()
2666 emit (expandAll() );
2669 void VymModel::emitExpandOneLevel()
2671 emit (expandOneLevel () );
2674 void VymModel::emitCollapseOneLevel()
2676 emit (collapseOneLevel () );
2679 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2681 BranchItem *bi=getSelectedBranch();
2685 if (bi->isActiveStandardFlag(name))
2697 QString("%1 (\"%2\")").arg(u).arg(name),
2699 QString("%1 (\"%2\")").arg(r).arg(name),
2700 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2701 bi->toggleStandardFlag (name, master);
2703 emitSelectionChanged();
2707 void VymModel::addFloatImage (const QPixmap &img)
2709 BranchItem *selbi=getSelectedBranch();
2712 ImageItem *ii=createImage (selbi);
2714 ii->setOriginalFilename("No original filename (image added by dropevent)");
2715 QString s=getSelectString(selbi);
2716 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2717 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2719 // FIXME-3 VM needed? scene()->update();
2724 void VymModel::colorBranch (QColor c)
2726 BranchItem *selbi=getSelectedBranch();
2731 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2733 QString ("colorBranch (\"%1\")").arg(c.name()),
2734 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2736 selbi->setHeadingColor(c); // color branch
2741 void VymModel::colorSubtree (QColor c)
2743 BranchItem *selbi=getSelectedBranch();
2746 saveStateChangingPart(
2749 QString ("colorSubtree (\"%1\")").arg(c.name()),
2750 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2752 BranchItem *prev=NULL;
2753 BranchItem *cur=selbi;
2756 cur->setHeadingColor(c); // color links, color children
2757 cur=nextBranch (cur,prev,true,selbi);
2763 QColor VymModel::getCurrentHeadingColor()
2765 BranchItem *selbi=getSelectedBranch();
2766 if (selbi) return selbi->getHeadingColor();
2768 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2774 void VymModel::editURL()
2776 TreeItem *selti=getSelectedItem();
2780 QString text = QInputDialog::getText(
2781 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2782 selti->getURL(), &ok, NULL);
2784 // user entered something and pressed OK
2789 void VymModel::editLocalURL()
2791 TreeItem *selti=getSelectedItem();
2794 QStringList filters;
2795 filters <<"All files (*)";
2796 filters << tr("Text","Filedialog") + " (*.txt)";
2797 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2798 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2799 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2800 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2801 fd->setFilters (filters);
2802 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2803 fd->setDirectory (lastFileDir);
2804 if (! selti->getVymLink().isEmpty() )
2805 fd->selectFile( selti->getURL() );
2808 if ( fd->exec() == QDialog::Accepted )
2810 lastFileDir=QDir (fd->directory().path());
2811 setURL (fd->selectedFile() );
2817 void VymModel::editHeading2URL()
2819 TreeItem *selti=getSelectedItem();
2821 setURL (selti->getHeading());
2824 void VymModel::editBugzilla2URL()
2826 TreeItem *selti=getSelectedItem();
2829 QString h=selti->getHeading();
2830 QRegExp rx("^(\\d+)");
2831 if (rx.indexIn(h) !=-1)
2832 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2836 void VymModel::editFATE2URL()
2838 TreeItem *selti=getSelectedItem();
2841 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2844 "setURL (\""+selti->getURL()+"\")",
2846 "setURL (\""+url+"\")",
2847 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2849 selti->setURL (url);
2850 // FIXME-4 updateActions();
2854 void VymModel::editVymLink()
2856 BranchItem *bi=getSelectedBranch();
2859 QStringList filters;
2860 filters <<"VYM map (*.vym)";
2861 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2862 fd->setFilters (filters);
2863 fd->setCaption(vymName+" - " +tr("Link to another map"));
2864 fd->setDirectory (lastFileDir);
2865 if (! bi->getVymLink().isEmpty() )
2866 fd->selectFile( bi->getVymLink() );
2870 if ( fd->exec() == QDialog::Accepted )
2872 lastFileDir=QDir (fd->directory().path());
2875 "setVymLink (\""+bi->getVymLink()+"\")",
2877 "setVymLink (\""+fd->selectedFile()+"\")",
2878 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2880 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2885 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2887 // Internal function, no saveState needed
2888 TreeItem *selti=getSelectedItem();
2891 selti->setVymLink(s);
2893 emitDataHasChanged (selti);
2894 emitShowSelection();
2898 void VymModel::deleteVymLink()
2900 BranchItem *bi=getSelectedBranch();
2905 "setVymLink (\""+bi->getVymLink()+"\")",
2907 "setVymLink (\"\")",
2908 QString("Unset vymlink of %1").arg(getObjectName(bi))
2910 bi->setVymLink ("" );
2916 QString VymModel::getVymLink()
2918 BranchItem *bi=getSelectedBranch();
2920 return bi->getVymLink();
2926 QStringList VymModel::getVymLinks()
2929 BranchItem *selbi=getSelectedBranch();
2930 BranchItem *cur=selbi;
2931 BranchItem *prev=NULL;
2934 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2935 cur=nextBranch (cur,prev,true,selbi);
2941 void VymModel::followXLink(int i)
2944 BranchItem *selbi=getSelectedBranch();
2947 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2948 if (selbi) select (selbi);
2952 void VymModel::editXLink(int i)
2955 BranchItem *selbi=getSelectedBranch();
2958 XLinkItem *xli=selbi->getXLinkNum(i);
2961 EditXLinkDialog dia;
2963 dia.setSelection(selbi);
2964 if (dia.exec() == QDialog::Accepted)
2966 if (dia.useSettingsGlobal() )
2968 setMapDefXLinkColor (xli->getColor() );
2969 setMapDefXLinkWidth (xli->getWidth() );
2971 if (dia.deleteXLink()) deleteItem (xli);
2981 //////////////////////////////////////////////
2983 //////////////////////////////////////////////
2985 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
2987 TreeItem* selti=getSelectedItem();
2988 BranchItem *selbi=getSelectedBranch();
2993 QVariant returnValue;
2995 // Split string s into command and parameters
2996 parser.parseAtom (atom);
2997 QString com=parser.getCommand();
2999 // External commands
3000 /////////////////////////////////////////////////////////////////////
3001 if (com=="addBranch")
3005 parser.setError (Aborted,"Nothing selected");
3006 } else if (! selbi )
3008 parser.setError (Aborted,"Type of selection is not a branch");
3013 if (parser.checkParCount(pl))
3015 if (parser.parCount()==0)
3019 n=parser.parInt (ok,0);
3020 if (ok ) addNewBranch (n);
3024 /////////////////////////////////////////////////////////////////////
3025 } else if (com=="addBranchBefore")
3029 parser.setError (Aborted,"Nothing selected");
3030 } else if (! selbi )
3032 parser.setError (Aborted,"Type of selection is not a branch");
3035 if (parser.parCount()==0)
3037 addNewBranchBefore ();
3040 /////////////////////////////////////////////////////////////////////
3041 } else if (com==QString("addMapCenter"))
3043 if (parser.checkParCount(2))
3045 x=parser.parDouble (ok,0);
3048 y=parser.parDouble (ok,1);
3049 if (ok) addMapCenter (QPointF(x,y));
3052 /////////////////////////////////////////////////////////////////////
3053 } else if (com==QString("addMapReplace"))
3057 parser.setError (Aborted,"Nothing selected");
3058 } else if (! selbi )
3060 parser.setError (Aborted,"Type of selection is not a branch");
3061 } else if (parser.checkParCount(1))
3063 //s=parser.parString (ok,0); // selection
3064 t=parser.parString (ok,0); // path to map
3065 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3066 addMapReplaceInt(getSelectString(selbi),t);
3068 /////////////////////////////////////////////////////////////////////
3069 } else if (com==QString("addMapInsert"))
3071 if (parser.parCount()==2)
3076 parser.setError (Aborted,"Nothing selected");
3077 } else if (! selbi )
3079 parser.setError (Aborted,"Type of selection is not a branch");
3082 t=parser.parString (ok,0); // path to map
3083 n=parser.parInt(ok,1); // position
3084 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3085 addMapInsertInt(t,n);
3087 } else if (parser.parCount()==1)
3089 t=parser.parString (ok,0); // path to map
3090 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3093 parser.setError (Aborted,"Wrong number of parameters");
3094 /////////////////////////////////////////////////////////////////////
3095 } else if (com==QString("addXLink"))
3097 if (parser.parCount()>1)
3099 s=parser.parString (ok,0); // begin
3100 t=parser.parString (ok,1); // end
3101 BranchItem *begin=(BranchItem*)findBySelectString(s);
3102 BranchItem *end=(BranchItem*)findBySelectString(t);
3105 if (begin->isBranchLikeType() && end->isBranchLikeType())
3107 XLinkItem *xl=createXLink (begin,true);
3113 parser.setError (Aborted,"Failed to create xLink");
3116 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3119 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3121 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3122 /////////////////////////////////////////////////////////////////////
3123 } else if (com=="clearFlags")
3127 parser.setError (Aborted,"Nothing selected");
3128 } else if (! selbi )
3130 parser.setError (Aborted,"Type of selection is not a branch");
3131 } else if (parser.checkParCount(0))
3133 selbi->deactivateAllStandardFlags();
3135 /////////////////////////////////////////////////////////////////////
3136 } else if (com=="colorBranch")
3140 parser.setError (Aborted,"Nothing selected");
3141 } else if (! selbi )
3143 parser.setError (Aborted,"Type of selection is not a branch");
3144 } else if (parser.checkParCount(1))
3146 QColor c=parser.parColor (ok,0);
3147 if (ok) colorBranch (c);
3149 /////////////////////////////////////////////////////////////////////
3150 } else if (com=="colorSubtree")
3154 parser.setError (Aborted,"Nothing selected");
3155 } else if (! selbi )
3157 parser.setError (Aborted,"Type of selection is not a branch");
3158 } else if (parser.checkParCount(1))
3160 QColor c=parser.parColor (ok,0);
3161 if (ok) colorSubtree (c);
3163 /////////////////////////////////////////////////////////////////////
3164 } else if (com=="copy")
3168 parser.setError (Aborted,"Nothing selected");
3169 } else if ( selectionType()!=TreeItem::Branch &&
3170 selectionType()!=TreeItem::MapCenter &&
3171 selectionType()!=TreeItem::Image )
3173 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3174 } else if (parser.checkParCount(0))
3178 /////////////////////////////////////////////////////////////////////
3179 } else if (com=="cut")
3183 parser.setError (Aborted,"Nothing selected");
3184 } else if ( selectionType()!=TreeItem::Branch &&
3185 selectionType()!=TreeItem::MapCenter &&
3186 selectionType()!=TreeItem::Image )
3188 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3189 } else if (parser.checkParCount(0))
3193 /////////////////////////////////////////////////////////////////////
3194 } else if (com=="delete")
3198 parser.setError (Aborted,"Nothing selected");
3200 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3202 parser.setError (Aborted,"Type of selection is wrong.");
3205 else if (parser.checkParCount(0))
3209 /////////////////////////////////////////////////////////////////////
3210 } else if (com=="deleteKeepChildren")
3214 parser.setError (Aborted,"Nothing selected");
3215 } else if (! selbi )
3217 parser.setError (Aborted,"Type of selection is not a branch");
3218 } else if (parser.checkParCount(0))
3220 deleteKeepChildren();
3222 /////////////////////////////////////////////////////////////////////
3223 } else if (com=="deleteChildren")
3227 parser.setError (Aborted,"Nothing selected");
3230 parser.setError (Aborted,"Type of selection is not a branch");
3231 } else if (parser.checkParCount(0))
3235 /////////////////////////////////////////////////////////////////////
3236 } else if (com=="exportAO")
3240 if (parser.parCount()>=1)
3241 // Hey, we even have a filename
3242 fname=parser.parString(ok,0);
3245 parser.setError (Aborted,"Could not read filename");
3248 exportAO (fname,false);
3250 /////////////////////////////////////////////////////////////////////
3251 } else if (com=="exportASCII")
3255 if (parser.parCount()>=1)
3256 // Hey, we even have a filename
3257 fname=parser.parString(ok,0);
3260 parser.setError (Aborted,"Could not read filename");
3263 exportASCII (fname,false);
3265 /////////////////////////////////////////////////////////////////////
3266 } else if (com=="exportImage")
3270 if (parser.parCount()>=2)
3271 // Hey, we even have a filename
3272 fname=parser.parString(ok,0);
3275 parser.setError (Aborted,"Could not read filename");
3278 QString format="PNG";
3279 if (parser.parCount()>=2)
3281 format=parser.parString(ok,1);
3283 exportImage (fname,false,format);
3285 /////////////////////////////////////////////////////////////////////
3286 } else if (com=="exportXHTML")
3290 if (parser.parCount()>=2)
3291 // Hey, we even have a filename
3292 fname=parser.parString(ok,1);
3295 parser.setError (Aborted,"Could not read filename");
3298 exportXHTML (fname,false);
3300 /////////////////////////////////////////////////////////////////////
3301 } else if (com=="exportXML")
3305 if (parser.parCount()>=2)
3306 // Hey, we even have a filename
3307 fname=parser.parString(ok,1);
3310 parser.setError (Aborted,"Could not read filename");
3313 exportXML (fname,false);
3315 /////////////////////////////////////////////////////////////////////
3316 } else if (com=="getHeading")
3320 parser.setError (Aborted,"Nothing selected");
3321 } else if (parser.checkParCount(0))
3322 returnValue=selti->getHeading();
3323 /////////////////////////////////////////////////////////////////////
3324 } else if (com=="importDir")
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(1))
3334 s=parser.parString(ok,0);
3335 if (ok) importDirInt(s);
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="relinkTo")
3342 parser.setError (Aborted,"Nothing selected");
3345 if (parser.checkParCount(4))
3347 // 0 selectstring of parent
3348 // 1 num in parent (for branches)
3349 // 2,3 x,y of mainbranch or mapcenter
3350 s=parser.parString(ok,0);
3351 TreeItem *dst=findBySelectString (s);
3354 if (dst->getType()==TreeItem::Branch)
3356 // Get number in parent
3357 n=parser.parInt (ok,1);
3360 relinkBranch (selbi,(BranchItem*)dst,n);
3361 emitSelectionChanged();
3363 } else if (dst->getType()==TreeItem::MapCenter)
3365 relinkBranch (selbi,(BranchItem*)dst);
3366 // Get coordinates of mainbranch
3367 x=parser.parDouble(ok,2);
3370 y=parser.parDouble(ok,3);
3373 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3374 emitSelectionChanged();
3380 } else if ( selti->getType() == TreeItem::Image)
3382 if (parser.checkParCount(1))
3384 // 0 selectstring of parent
3385 s=parser.parString(ok,0);
3386 TreeItem *dst=findBySelectString (s);
3389 if (dst->isBranchLikeType())
3390 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3392 parser.setError (Aborted,"Destination is not a branch");
3395 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3396 /////////////////////////////////////////////////////////////////////
3397 } else if (com=="loadImage")
3401 parser.setError (Aborted,"Nothing selected");
3402 } else if (! selbi )
3404 parser.setError (Aborted,"Type of selection is not a branch");
3405 } else if (parser.checkParCount(1))
3407 s=parser.parString(ok,0);
3408 if (ok) loadFloatImageInt (selbi,s);
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="moveUp")
3415 parser.setError (Aborted,"Nothing selected");
3416 } else if (! selbi )
3418 parser.setError (Aborted,"Type of selection is not a branch");
3419 } else if (parser.checkParCount(0))
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="moveDown")
3428 parser.setError (Aborted,"Nothing selected");
3429 } else if (! selbi )
3431 parser.setError (Aborted,"Type of selection is not a branch");
3432 } else if (parser.checkParCount(0))
3436 /////////////////////////////////////////////////////////////////////
3437 } else if (com=="move")
3441 parser.setError (Aborted,"Nothing selected");
3442 } else if ( selectionType()!=TreeItem::Branch &&
3443 selectionType()!=TreeItem::MapCenter &&
3444 selectionType()!=TreeItem::Image )
3446 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3447 } else if (parser.checkParCount(2))
3449 x=parser.parDouble (ok,0);
3452 y=parser.parDouble (ok,1);
3456 /////////////////////////////////////////////////////////////////////
3457 } else if (com=="moveRel")
3461 parser.setError (Aborted,"Nothing selected");
3462 } else if ( selectionType()!=TreeItem::Branch &&
3463 selectionType()!=TreeItem::MapCenter &&
3464 selectionType()!=TreeItem::Image )
3466 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3467 } else if (parser.checkParCount(2))
3469 x=parser.parDouble (ok,0);
3472 y=parser.parDouble (ok,1);
3473 if (ok) moveRel (x,y);
3476 /////////////////////////////////////////////////////////////////////
3477 } else if (com=="nop")
3479 /////////////////////////////////////////////////////////////////////
3480 } else if (com=="paste")
3484 parser.setError (Aborted,"Nothing selected");
3485 } else if (! selbi )
3487 parser.setError (Aborted,"Type of selection is not a branch");
3488 } else if (parser.checkParCount(1))
3490 n=parser.parInt (ok,0);
3491 if (ok) pasteNoSave(n);
3493 /////////////////////////////////////////////////////////////////////
3494 } else if (com=="qa")
3498 parser.setError (Aborted,"Nothing selected");
3499 } else if (! selbi )
3501 parser.setError (Aborted,"Type of selection is not a branch");
3502 } else if (parser.checkParCount(4))
3505 c=parser.parString (ok,0);
3508 parser.setError (Aborted,"No comment given");
3511 s=parser.parString (ok,1);
3514 parser.setError (Aborted,"First parameter is not a string");
3517 t=parser.parString (ok,2);
3520 parser.setError (Aborted,"Condition is not a string");
3523 u=parser.parString (ok,3);
3526 parser.setError (Aborted,"Third parameter is not a string");
3531 parser.setError (Aborted,"Unknown type: "+s);
3536 parser.setError (Aborted,"Unknown operator: "+t);
3541 parser.setError (Aborted,"Type of selection is not a branch");
3544 if (selbi->getHeading() == u)
3546 cout << "PASSED: " << qPrintable (c) << endl;
3549 cout << "FAILED: " << qPrintable (c) << endl;
3559 /////////////////////////////////////////////////////////////////////
3560 } else if (com=="saveImage")
3562 ImageItem *ii=getSelectedImage();
3565 parser.setError (Aborted,"No image selected");
3566 } else if (parser.checkParCount(2))
3568 s=parser.parString(ok,0);
3571 t=parser.parString(ok,1);
3572 if (ok) saveFloatImageInt (ii,t,s);
3575 /////////////////////////////////////////////////////////////////////
3576 } else if (com=="scroll")
3580 parser.setError (Aborted,"Nothing selected");
3581 } else if (! selbi )
3583 parser.setError (Aborted,"Type of selection is not a branch");
3584 } else if (parser.checkParCount(0))
3586 if (!scrollBranch (selbi))
3587 parser.setError (Aborted,"Could not scroll branch");
3589 /////////////////////////////////////////////////////////////////////
3590 } else if (com=="select")
3592 if (parser.checkParCount(1))
3594 s=parser.parString(ok,0);
3597 /////////////////////////////////////////////////////////////////////
3598 } else if (com=="selectLastBranch")
3602 parser.setError (Aborted,"Nothing selected");
3603 } else if (! selbi )
3605 parser.setError (Aborted,"Type of selection is not a branch");
3606 } else if (parser.checkParCount(0))
3608 BranchItem *bi=selbi->getLastBranch();
3610 parser.setError (Aborted,"Could not select last branch");
3611 select (bi); // FIXME-3 was selectInt
3614 /////////////////////////////////////////////////////////////////////
3615 } else /* FIXME-2 if (com=="selectLastImage")
3619 parser.setError (Aborted,"Nothing selected");
3620 } else if (! selbi )
3622 parser.setError (Aborted,"Type of selection is not a branch");
3623 } else if (parser.checkParCount(0))
3625 FloatImageObj *fio=selb->getLastFloatImage();
3627 parser.setError (Aborted,"Could not select last image");
3628 select (fio); // FIXME-3 was selectInt
3631 /////////////////////////////////////////////////////////////////////
3632 } else */ if (com=="selectLatestAdded")
3634 if (!latestAddedItem)
3636 parser.setError (Aborted,"No latest added object");
3639 if (!select (latestAddedItem))
3640 parser.setError (Aborted,"Could not select latest added object ");
3642 /////////////////////////////////////////////////////////////////////
3643 } else if (com=="setFlag")
3647 parser.setError (Aborted,"Nothing selected");
3648 } else if (! selbi )
3650 parser.setError (Aborted,"Type of selection is not a branch");
3651 } else if (parser.checkParCount(1))
3653 s=parser.parString(ok,0);
3655 selbi->activateStandardFlag(s);
3657 /////////////////////////////////////////////////////////////////////
3658 } else if (com=="setFrameType")
3660 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3662 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3664 else if (parser.checkParCount(1))
3666 s=parser.parString(ok,0);
3667 if (ok) setFrameType (s);
3669 /////////////////////////////////////////////////////////////////////
3670 } else if (com=="setFramePenColor")
3672 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3674 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3676 else if (parser.checkParCount(1))
3678 QColor c=parser.parColor(ok,0);
3679 if (ok) setFramePenColor (c);
3681 /////////////////////////////////////////////////////////////////////
3682 } else if (com=="setFrameBrushColor")
3684 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3686 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3688 else if (parser.checkParCount(1))
3690 QColor c=parser.parColor(ok,0);
3691 if (ok) setFrameBrushColor (c);
3693 /////////////////////////////////////////////////////////////////////
3694 } else if (com=="setFramePadding")
3696 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3698 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3700 else if (parser.checkParCount(1))
3702 n=parser.parInt(ok,0);
3703 if (ok) setFramePadding(n);
3705 /////////////////////////////////////////////////////////////////////
3706 } else if (com=="setFrameBorderWidth")
3708 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3710 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3712 else if (parser.checkParCount(1))
3714 n=parser.parInt(ok,0);
3715 if (ok) setFrameBorderWidth (n);
3717 /////////////////////////////////////////////////////////////////////
3718 /* FIXME-2 else if (com=="setFrameType")
3722 parser.setError (Aborted,"Nothing selected");
3725 parser.setError (Aborted,"Type of selection is not a branch");
3726 } else if (parser.checkParCount(1))
3728 s=parser.parString(ok,0);
3732 /////////////////////////////////////////////////////////////////////
3734 /////////////////////////////////////////////////////////////////////
3735 } else if (com=="setHeading")
3739 parser.setError (Aborted,"Nothing selected");
3740 } else if (! selbi )
3742 parser.setError (Aborted,"Type of selection is not a branch");
3743 } else if (parser.checkParCount(1))
3745 s=parser.parString (ok,0);
3749 /////////////////////////////////////////////////////////////////////
3750 } else if (com=="setHideExport")
3754 parser.setError (Aborted,"Nothing selected");
3755 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3757 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3758 } else if (parser.checkParCount(1))
3760 b=parser.parBool(ok,0);
3761 if (ok) setHideExport (b);
3763 /////////////////////////////////////////////////////////////////////
3764 } else if (com=="setIncludeImagesHorizontally")
3768 parser.setError (Aborted,"Nothing selected");
3771 parser.setError (Aborted,"Type of selection is not a branch");
3772 } else if (parser.checkParCount(1))
3774 b=parser.parBool(ok,0);
3775 if (ok) setIncludeImagesHor(b);
3777 /////////////////////////////////////////////////////////////////////
3778 } else if (com=="setIncludeImagesVertically")
3782 parser.setError (Aborted,"Nothing selected");
3785 parser.setError (Aborted,"Type of selection is not a branch");
3786 } else if (parser.checkParCount(1))
3788 b=parser.parBool(ok,0);
3789 if (ok) setIncludeImagesVer(b);
3791 /////////////////////////////////////////////////////////////////////
3792 } else if (com=="setHideLinkUnselected")
3796 parser.setError (Aborted,"Nothing selected");
3797 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3799 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3800 } else if (parser.checkParCount(1))
3802 b=parser.parBool(ok,0);
3803 if (ok) setHideLinkUnselected(b);
3805 /////////////////////////////////////////////////////////////////////
3806 } else if (com=="setMapAuthor")
3808 if (parser.checkParCount(1))
3810 s=parser.parString(ok,0);
3811 if (ok) setAuthor (s);
3813 /////////////////////////////////////////////////////////////////////
3814 } else if (com=="setMapComment")
3816 if (parser.checkParCount(1))
3818 s=parser.parString(ok,0);
3819 if (ok) setComment(s);
3821 /////////////////////////////////////////////////////////////////////
3822 } else if (com=="setMapBackgroundColor")
3826 parser.setError (Aborted,"Nothing selected");
3827 } else if (! selbi )
3829 parser.setError (Aborted,"Type of selection is not a branch");
3830 } else if (parser.checkParCount(1))
3832 QColor c=parser.parColor (ok,0);
3833 if (ok) setMapBackgroundColor (c);
3835 /////////////////////////////////////////////////////////////////////
3836 } else if (com=="setMapDefLinkColor")
3840 parser.setError (Aborted,"Nothing selected");
3841 } else if (! selbi )
3843 parser.setError (Aborted,"Type of selection is not a branch");
3844 } else if (parser.checkParCount(1))
3846 QColor c=parser.parColor (ok,0);
3847 if (ok) setMapDefLinkColor (c);
3849 /////////////////////////////////////////////////////////////////////
3850 } else if (com=="setMapLinkStyle")
3852 if (parser.checkParCount(1))
3854 s=parser.parString (ok,0);
3855 if (ok) setMapLinkStyle(s);
3857 /////////////////////////////////////////////////////////////////////
3858 } else if (com=="setNote")
3862 parser.setError (Aborted,"Nothing selected");
3863 } else if (! selbi )
3865 parser.setError (Aborted,"Type of selection is not a branch");
3866 } else if (parser.checkParCount(1))
3868 s=parser.parString (ok,0);
3872 /////////////////////////////////////////////////////////////////////
3873 } else if (com=="setSelectionColor")
3875 if (parser.checkParCount(1))
3877 QColor c=parser.parColor (ok,0);
3878 if (ok) setSelectionColorInt (c);
3880 /////////////////////////////////////////////////////////////////////
3881 } else if (com=="setURL")
3885 parser.setError (Aborted,"Nothing selected");
3886 } else if (! selbi )
3888 parser.setError (Aborted,"Type of selection is not a branch");
3889 } else if (parser.checkParCount(1))
3891 s=parser.parString (ok,0);
3894 /////////////////////////////////////////////////////////////////////
3895 } else if (com=="setVymLink")
3899 parser.setError (Aborted,"Nothing selected");
3900 } else if (! selbi )
3902 parser.setError (Aborted,"Type of selection is not a branch");
3903 } else if (parser.checkParCount(1))
3905 s=parser.parString (ok,0);
3906 if (ok) setVymLink(s);
3908 } else if (com=="sortChildren")
3912 parser.setError (Aborted,"Nothing selected");
3913 } else if (! selbi )
3915 parser.setError (Aborted,"Type of selection is not a branch");
3916 } else if (parser.checkParCount(0))
3920 /////////////////////////////////////////////////////////////////////
3921 } else if (com=="toggleFlag")
3925 parser.setError (Aborted,"Nothing selected");
3926 } else if (! selbi )
3928 parser.setError (Aborted,"Type of selection is not a branch");
3929 } else if (parser.checkParCount(1))
3931 s=parser.parString(ok,0);
3933 selbi->toggleStandardFlag(s);
3935 /////////////////////////////////////////////////////////////////////
3936 } else if (com=="unscroll")
3940 parser.setError (Aborted,"Nothing selected");
3941 } else if (! selbi )
3943 parser.setError (Aborted,"Type of selection is not a branch");
3944 } else if (parser.checkParCount(0))
3946 if (!unscrollBranch (selbi))
3947 parser.setError (Aborted,"Could not unscroll branch");
3949 /////////////////////////////////////////////////////////////////////
3950 } else if (com=="unscrollChildren")
3954 parser.setError (Aborted,"Nothing selected");
3955 } else if (! selbi )
3957 parser.setError (Aborted,"Type of selection is not a branch");
3958 } else if (parser.checkParCount(0))
3960 unscrollChildren ();
3962 /////////////////////////////////////////////////////////////////////
3963 } else if (com=="unsetFlag")
3967 parser.setError (Aborted,"Nothing selected");
3968 } else if (! selbi )
3970 parser.setError (Aborted,"Type of selection is not a branch");
3971 } else if (parser.checkParCount(1))
3973 s=parser.parString(ok,0);
3975 selbi->deactivateStandardFlag(s);
3978 parser.setError (Aborted,"Unknown command");
3981 if (parser.errorLevel()==NoError)
3983 // setChanged(); FIXME-2 should not be called e.g. for export?!
3990 // TODO Error handling
3991 qWarning("VymModel::parseAtom: Error!");
3993 qWarning(parser.errorMessage());
3995 errorMsg=parser.errorMessage();
4000 QVariant VymModel::runScript (const QString &script)
4002 parser.setScript (script);
4007 while (parser.next() && noErr)
4009 r=parseAtom(parser.getAtom(),noErr,errMsg);
4010 if (!noErr) //FIXME-3 need dialog box here
4011 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4016 void VymModel::setExportMode (bool b)
4018 // should be called before and after exports
4019 // depending on the settings
4020 if (b && settings.value("/export/useHideExport","true")=="true")
4021 setHideTmpMode (TreeItem::HideExport);
4023 setHideTmpMode (TreeItem::HideNone);
4026 void VymModel::exportImage(QString fname, bool askName, QString format)
4030 fname=getMapName()+".png";
4037 QFileDialog *fd=new QFileDialog (NULL);
4038 fd->setCaption (tr("Export map as image"));
4039 fd->setDirectory (lastImageDir);
4040 fd->setFileMode(QFileDialog::AnyFile);
4041 fd->setFilters (imageIO.getFilters() );
4044 fl=fd->selectedFiles();
4046 format=imageIO.getType(fd->selectedFilter());
4050 setExportMode (true);
4051 QPixmap pix (mapEditor->getPixmap());
4052 pix.save(fname, format);
4053 setExportMode (false);
4057 void VymModel::exportXML(QString dir, bool askForName)
4061 dir=browseDirectory(NULL,tr("Export XML to directory"));
4062 if (dir =="" && !reallyWriteDirectory(dir) )
4066 // Hide stuff during export, if settings want this
4067 setExportMode (true);
4069 // Create subdirectories
4072 // write to directory //FIXME-4 check totalBBox here...
4073 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4076 file.setName ( dir + "/"+mapName+".xml");
4077 if ( !file.open( QIODevice::WriteOnly ) )
4079 // This should neverever happen
4080 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4084 // Write it finally, and write in UTF8, no matter what
4085 QTextStream ts( &file );
4086 ts.setEncoding (QTextStream::UnicodeUTF8);
4090 // Now write image, too
4091 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4093 setExportMode (false);
4096 void VymModel::exportAO (QString fname,bool askName)
4101 ex.setFile (mapName+".txt");
4107 //ex.addFilter ("TXT (*.txt)");
4108 ex.setDir(lastImageDir);
4109 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4114 setExportMode(true);
4116 setExportMode(false);
4120 void VymModel::exportASCII(QString fname,bool askName)
4125 ex.setFile (mapName+".txt");
4131 //ex.addFilter ("TXT (*.txt)");
4132 ex.setDir(lastImageDir);
4133 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4138 setExportMode(true);
4140 setExportMode(false);
4144 void VymModel::exportXHTML (const QString &dir, bool askForName)
4146 ExportXHTMLDialog dia(NULL);
4147 dia.setFilePath (filePath );
4148 dia.setMapName (mapName );
4150 if (dir!="") dia.setDir (dir);
4156 if (dia.exec()!=QDialog::Accepted)
4160 QDir d (dia.getDir());
4161 // Check, if warnings should be used before overwriting
4162 // the output directory
4163 if (d.exists() && d.count()>0)
4166 warn.showCancelButton (true);
4167 warn.setText(QString(
4168 "The directory %1 is not empty.\n"
4169 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4170 warn.setCaption("Warning: Directory not empty");
4171 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4173 if (warn.exec()!=QDialog::Accepted) ok=false;
4180 exportXML (dia.getDir(),false );
4181 dia.doExport(mapName );
4182 //if (dia.hasChanged()) setChanged();
4186 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4191 if (ex.setConfigFile(cf))
4193 setExportMode (true);
4194 ex.exportPresentation();
4195 setExportMode (false);
4202 //////////////////////////////////////////////
4204 //////////////////////////////////////////////
4206 void VymModel::registerEditor(QWidget *me)
4208 mapEditor=(MapEditor*)me;
4211 void VymModel::unregisterEditor(QWidget *)
4216 void VymModel::setContextPos(QPointF p)
4221 void VymModel::unsetContextPos()
4223 contextPos=QPointF();
4226 void VymModel::updateNoteFlag()
4229 TreeItem *selti=getSelectedItem();
4232 if (textEditor->isEmpty())
4235 selti->setNote (textEditor->getText());
4236 emitDataHasChanged(selti);
4237 emitSelectionChanged();
4242 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4244 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4245 if (blockReposition) return;
4247 for (int i=0;i<rootItem->branchCount(); i++)
4248 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4249 //emitSelectionChanged();
4253 void VymModel::setMapLinkStyle (const QString & s)
4258 case LinkableMapObj::Line :
4261 case LinkableMapObj::Parabel:
4262 snow="StyleParabel";
4264 case LinkableMapObj::PolyLine:
4265 snow="StylePolyLine";
4267 case LinkableMapObj::PolyParabel:
4268 snow="StylePolyParabel";
4271 snow="UndefinedStyle";
4276 QString("setMapLinkStyle (\"%1\")").arg(s),
4277 QString("setMapLinkStyle (\"%1\")").arg(snow),
4278 QString("Set map link style (\"%1\")").arg(s)
4282 linkstyle=LinkableMapObj::Line;
4283 else if (s=="StyleParabel")
4284 linkstyle=LinkableMapObj::Parabel;
4285 else if (s=="StylePolyLine")
4286 linkstyle=LinkableMapObj::PolyLine;
4287 else if (s=="StylePolyParabel")
4288 linkstyle=LinkableMapObj::PolyParabel;
4290 linkstyle=LinkableMapObj::UndefinedStyle;
4292 BranchItem *cur=NULL;
4293 BranchItem *prev=NULL;
4295 nextBranch (cur,prev);
4298 bo=(BranchObj*)(cur->getLMO() );
4299 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4300 cur=nextBranch(cur,prev);
4305 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4310 void VymModel::setMapDefLinkColor(QColor col)
4312 if ( !col.isValid() ) return;
4314 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4315 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4316 QString("Set map link color to %1").arg(col.name())
4320 BranchItem *cur=NULL;
4321 BranchItem *prev=NULL;
4323 cur=nextBranch(cur,prev);
4326 bo=(BranchObj*)(cur->getLMO() );
4328 nextBranch(cur,prev);
4333 void VymModel::setMapLinkColorHintInt()
4335 // called from setMapLinkColorHint(lch) or at end of parse
4336 BranchItem *cur=NULL;
4337 BranchItem *prev=NULL;
4339 cur=nextBranch(cur,prev);
4342 bo=(BranchObj*)(cur->getLMO() );
4344 cur=nextBranch(cur,prev);
4348 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4351 setMapLinkColorHintInt();
4354 void VymModel::toggleMapLinkColorHint()
4356 if (linkcolorhint==LinkableMapObj::HeadingColor)
4357 linkcolorhint=LinkableMapObj::DefaultColor;
4359 linkcolorhint=LinkableMapObj::HeadingColor;
4360 BranchItem *cur=NULL;
4361 BranchItem *prev=NULL;
4363 cur=nextBranch(cur,prev);
4366 bo=(BranchObj*)(cur->getLMO() );
4368 nextBranch(cur,prev);
4372 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4373 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4375 Q3FileDialog *fd=new Q3FileDialog( NULL);
4376 fd->setMode (Q3FileDialog::ExistingFile);
4377 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4378 ImagePreview *p =new ImagePreview (fd);
4379 fd->setContentsPreviewEnabled( TRUE );
4380 fd->setContentsPreview( p, p );
4381 fd->setPreviewMode( Q3FileDialog::Contents );
4382 fd->setCaption(vymName+" - " +tr("Load background image"));
4383 fd->setDir (lastImageDir);
4386 if ( fd->exec() == QDialog::Accepted )
4388 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4389 lastImageDir=QDir (fd->dirPath());
4390 setMapBackgroundImage (fd->selectedFile());
4394 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4396 QColor oldcol=mapScene->backgroundBrush().color();
4400 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4402 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4403 QString("Set background color of map to %1").arg(col.name()));
4406 brush.setTextureImage (QPixmap (fn));
4407 mapScene->setBackgroundBrush(brush);
4410 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4412 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4413 if ( !col.isValid() ) return;
4414 setMapBackgroundColor( col );
4418 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4420 QColor oldcol=mapScene->backgroundBrush().color();
4422 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4423 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4424 QString("Set background color of map to %1").arg(col.name()));
4425 mapScene->setBackgroundBrush(col);
4428 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4430 return mapScene->backgroundBrush().color();
4434 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4436 return linkcolorhint;
4439 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4441 return defLinkColor;
4444 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4449 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4451 return defXLinkColor;
4454 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4459 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4461 return defXLinkWidth;
4464 void VymModel::move(const double &x, const double &y)
4467 MapItem *seli = (MapItem*)getSelectedItem();
4468 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4470 LinkableMapObj *lmo=seli->getLMO();
4473 QPointF ap(lmo->getAbsPos());
4477 QString ps=qpointFToString(ap);
4478 QString s=getSelectString(seli);
4481 s, "move "+qpointFToString(to),
4482 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4485 emitSelectionChanged();
4491 void VymModel::moveRel (const double &x, const double &y)
4494 MapItem *seli = (MapItem*)getSelectedItem();
4495 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4497 LinkableMapObj *lmo=seli->getLMO();
4500 QPointF rp(lmo->getRelPos());
4504 QString ps=qpointFToString (lmo->getRelPos());
4505 QString s=getSelectString(seli);
4508 s, "moveRel "+qpointFToString(to),
4509 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4510 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4512 lmo->updateLinkGeometry();
4513 emitSelectionChanged();
4520 void VymModel::animate()
4522 animationTimer->stop();
4525 while (i<animObjList.size() )
4527 bo=(BranchObj*)animObjList.at(i);
4532 animObjList.removeAt(i);
4539 QItemSelection sel=selModel->selection();
4540 emit (selectionChanged(sel,sel));
4543 if (!animObjList.isEmpty()) animationTimer->start();
4547 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4549 if (start==dest) return;
4550 if (bo && bo->getTreeItem()->depth()>0)
4553 ap.setStart (start);
4555 ap.setTicks (animationTicks);
4556 ap.setAnimated (true);
4557 bo->setAnimation (ap);
4558 animObjList.append( bo );
4559 animationTimer->setSingleShot (true);
4560 animationTimer->start(animationInterval);
4564 void VymModel::stopAnimation (MapObj *mo)
4566 int i=animObjList.indexOf(mo);
4568 animObjList.removeAt (i);
4571 void VymModel::sendSelection()
4573 if (netstate!=Server) return;
4574 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4577 void VymModel::newServer()
4581 tcpServer = new QTcpServer(this);
4582 if (!tcpServer->listen(QHostAddress::Any,port)) {
4583 QMessageBox::critical(NULL, "vym server",
4584 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4585 //FIXME-3 needed? we are no widget any longer... close();
4588 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4590 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4593 void VymModel::connectToServer()
4596 server="salam.suse.de";
4598 clientSocket = new QTcpSocket (this);
4599 clientSocket->abort();
4600 clientSocket->connectToHost(server ,port);
4601 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4602 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4603 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4605 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4610 void VymModel::newClient()
4612 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4613 connect(newClient, SIGNAL(disconnected()),
4614 newClient, SLOT(deleteLater()));
4616 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4618 clientList.append (newClient);
4622 void VymModel::sendData(const QString &s)
4624 if (clientList.size()==0) return;
4626 // Create bytearray to send
4628 QDataStream out(&block, QIODevice::WriteOnly);
4629 out.setVersion(QDataStream::Qt_4_0);
4631 // Reserve some space for blocksize
4634 // Write sendCounter
4635 out << sendCounter++;
4640 // Go back and write blocksize so far
4641 out.device()->seek(0);
4642 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4646 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4648 for (int i=0; i<clientList.size(); ++i)
4650 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4651 clientList.at(i)->write (block);
4655 void VymModel::readData ()
4657 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4660 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4664 QDataStream in(clientSocket);
4665 in.setVersion(QDataStream::Qt_4_0);
4673 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4676 parseAtom (t,noErr,errMsg);
4682 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4684 switch (socketError) {
4685 case QAbstractSocket::RemoteHostClosedError:
4687 case QAbstractSocket::HostNotFoundError:
4688 QMessageBox::information(NULL, vymName +" Network client",
4689 "The host was not found. Please check the "
4690 "host name and port settings.");
4692 case QAbstractSocket::ConnectionRefusedError:
4693 QMessageBox::information(NULL, vymName + " Network client",
4694 "The connection was refused by the peer. "
4695 "Make sure the fortune server is running, "
4696 "and check that the host name and port "
4697 "settings are correct.");
4700 QMessageBox::information(NULL, vymName + " Network client",
4701 QString("The following error occurred: %1.")
4702 .arg(clientSocket->errorString()));
4706 /* FIXME-3 Playing with DBUS...
4707 QDBusVariant VymModel::query (const QString &query)
4709 TreeItem *selti=getSelectedItem();
4711 return QDBusVariant (selti->getHeading());
4713 return QDBusVariant ("Nothing selected.");
4717 void VymModel::testslot() //FIXME-3 Playing with DBUS
4719 cout << "VM::testslot called\n";
4722 void VymModel::selectMapSelectionColor()
4724 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4725 setSelectionColor (col);
4728 void VymModel::setSelectionColorInt (QColor col)
4730 if ( !col.isValid() ) return;
4732 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4733 QString("setSelectionColor (%1)").arg(col.name()),
4734 QString("Set color of selection box to %1").arg(col.name())
4737 mapEditor->setSelectionColor (col);
4740 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4742 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4743 //FIXME-3 emitShowSelection();
4747 void VymModel::emitSelectionChanged()
4749 QItemSelection newsel=selModel->selection();
4750 emitSelectionChanged (newsel);
4753 void VymModel::setSelectionColor(QColor col)
4755 if ( !col.isValid() ) return;
4757 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4758 QString("setSelectionColor (%1)").arg(col.name()),
4759 QString("Set color of selection box to %1").arg(col.name())
4761 setSelectionColorInt (col);
4764 QColor VymModel::getSelectionColor()
4766 return mapEditor->getSelectionColor();
4769 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4772 for (int i=0;i<rootItem->childCount();i++)
4773 rootItem->child(i)->setHideTmp (mode);
4775 // FIXME-3 needed? scene()->update();
4778 //////////////////////////////////////////////
4779 // Selection related
4780 //////////////////////////////////////////////
4782 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4787 QItemSelectionModel* VymModel::getSelectionModel()
4792 void VymModel::setSelectionBlocked (bool b)
4797 bool VymModel::isSelectionBlocked()
4799 return selectionBlocked;
4802 bool VymModel::select ()
4804 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4807 bool VymModel::select (const QString &s)
4814 TreeItem *ti=findBySelectString(s);
4815 if (ti) return select (index(ti));
4819 bool VymModel::select (LinkableMapObj *lmo)
4821 QItemSelection oldsel=selModel->selection();
4824 return select (index (lmo->getTreeItem()) );
4829 bool VymModel::select (TreeItem *ti)
4831 if (ti) return select (index(ti));
4835 bool VymModel::select (const QModelIndex &index)
4837 if (index.isValid() )
4839 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4840 BranchItem *bi=getSelectedBranch();
4841 if (bi) bi->setLastSelectedBranch();
4847 void VymModel::unselect()
4849 if (!selModel->selectedIndexes().isEmpty())
4851 lastSelectString=getSelectString();
4852 selModel->clearSelection();
4856 bool VymModel::reselect()
4858 return select (lastSelectString);
4861 void VymModel::emitShowSelection()
4863 if (!blockReposition)
4864 emit (showSelection() );
4867 void VymModel::emitNoteHasChanged (TreeItem *ti)
4869 QModelIndex ix=index(ti);
4870 emit (noteHasChanged (ix) );
4873 void VymModel::emitDataHasChanged (TreeItem *ti)
4875 QModelIndex ix=index(ti);
4876 emit (dataChanged (ix,ix) );
4880 bool VymModel::selectFirstBranch()
4882 TreeItem *ti=getSelectedBranch();
4885 TreeItem *par=ti->parent();
4888 TreeItem *ti2=par->getFirstBranch();
4889 if (ti2) return select(ti2);
4895 bool VymModel::selectLastBranch()
4897 TreeItem *ti=getSelectedBranch();
4900 TreeItem *par=ti->parent();
4903 TreeItem *ti2=par->getLastBranch();
4904 if (ti2) return select(ti2);
4910 bool VymModel::selectLastSelectedBranch()
4912 BranchItem *bi=getSelectedBranch();
4915 bi=bi->getLastSelectedBranch();
4916 if (bi) return select (bi);
4921 bool VymModel::selectParent()
4923 TreeItem *ti=getSelectedItem();
4934 TreeItem::Type VymModel::selectionType()
4936 QModelIndexList list=selModel->selectedIndexes();
4937 if (list.isEmpty()) return TreeItem::Undefined;
4938 TreeItem *ti = getItem (list.first() );
4939 return ti->getType();
4943 LinkableMapObj* VymModel::getSelectedLMO()
4945 QModelIndexList list=selModel->selectedIndexes();
4946 if (!list.isEmpty() )
4948 TreeItem *ti = getItem (list.first() );
4949 TreeItem::Type type=ti->getType();
4950 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4951 return ((MapItem*)ti)->getLMO();
4956 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4958 TreeItem *ti = getSelectedBranch();
4960 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4965 BranchItem* VymModel::getSelectedBranch()
4967 QModelIndexList list=selModel->selectedIndexes();
4968 if (!list.isEmpty() )
4970 TreeItem *ti = getItem (list.first() );
4971 TreeItem::Type type=ti->getType();
4972 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4973 return (BranchItem*)ti;
4978 ImageItem* VymModel::getSelectedImage()
4980 QModelIndexList list=selModel->selectedIndexes();
4981 if (!list.isEmpty())
4983 TreeItem *ti=getItem (list.first());
4984 if (ti && ti->getType()==TreeItem::Image)
4985 return (ImageItem*)ti;
4990 AttributeItem* VymModel::getSelectedAttribute()
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::Attribute)
4998 return (AttributeItem*)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 QString VymModel::getSelectString ()
5023 return getSelectString (getSelectedItem());
5026 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5028 if (!lmo) return QString();
5029 return getSelectString (lmo->getTreeItem() );
5032 QString VymModel::getSelectString (TreeItem *ti)
5036 switch (ti->getType())
5038 case TreeItem::MapCenter: s="mc:"; break;
5039 case TreeItem::Branch: s="bo:";break;
5040 case TreeItem::Image: s="fi:";break;
5041 case TreeItem::Attribute: s="ai:";break;
5042 case TreeItem::XLink: s="xl:";break;
5044 s="unknown type in VymModel::getSelectString()";
5047 s= s + QString("%1").arg(ti->num());
5049 // call myself recursively
5050 s= getSelectString(ti->parent()) +","+s;