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 while (rootItem->childCount() >0)
73 deleteItem (rootItem->getChildNum(0) );
76 void VymModel::init ()
81 // Also no scene yet (should not be needed anyway) FIXME-3 VM
94 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
95 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
96 mainWindow->updateHistory (undoSet);
104 fileName=tr("unnamed");
106 blockReposition=false;
107 blockSaveState=false;
109 autosaveTimer=new QTimer (this);
110 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
112 fileChangedTimer=new QTimer (this);
113 fileChangedTimer->start(3000);
114 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
119 selectionBlocked=false;
124 // animations // FIXME-3 switch to new animation system
125 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
126 animationTicks=settings.readNumEntry("/animation/ticks",10);
127 animationInterval=settings.readNumEntry("/animation/interval",50);
129 animationTimer=new QTimer (this);
130 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
133 defLinkColor=QColor (0,0,255);
134 defXLinkColor=QColor (180,180,180);
135 linkcolorhint=LinkableMapObj::DefaultColor;
136 linkstyle=LinkableMapObj::PolyParabel;
138 defXLinkColor=QColor (230,230,230);
140 hidemode=TreeItem::HideNone;
146 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
148 //Initialize DBUS object
149 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
150 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
151 qWarning ("VymModel: Couldn't register DBUS object!");
154 void VymModel::makeTmpDirectories()
156 // Create unique temporary directories
157 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
158 histPath = tmpMapDir+"/history";
164 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
169 bool VymModel::isRepositionBlocked()
171 return blockReposition;
174 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
176 //cout << "VM::updateActions \n";
177 // Tell mainwindow to update states of actions
178 mainWindow->updateActions();
183 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
185 // tmpdir temporary directory to which data will be written
186 // prefix mapname, which will be appended to images etc.
187 // writeflags Only write flags for "real" save of map, not undo
188 // offset offset of bbox of whole map in scene.
189 // Needed for XML export
198 case LinkableMapObj::Line:
201 case LinkableMapObj::Parabel:
204 case LinkableMapObj::PolyLine:
208 ls="StylePolyParabel";
212 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
214 if (linkcolorhint==LinkableMapObj::HeadingColor)
215 colhint=xml.attribut("linkColorHint","HeadingColor");
217 QString mapAttr=xml.attribut("version",vymVersion);
219 mapAttr+= xml.attribut("author",author) +
220 xml.attribut("comment",comment) +
221 xml.attribut("date",getDate()) +
222 xml.attribut("branchCount", QString().number(branchCount())) +
223 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
224 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
225 xml.attribut("linkStyle", ls ) +
226 xml.attribut("linkColor", defLinkColor.name() ) +
227 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
228 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
230 s+=xml.beginElement("vymmap",mapAttr);
233 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
234 standardFlagsMaster->resetUsedCounter();
236 // Build xml recursivly
238 // Save all mapcenters as complete map, if saveSel not set
239 s+=saveTreeToDir(tmpdir,prefix,offset);
242 switch (saveSel->getType())
244 case TreeItem::Branch:
246 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
248 case TreeItem::MapCenter:
250 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
252 case TreeItem::Image:
254 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
257 // other types shouldn't be safed directly...
262 // Save local settings
263 s+=settings.getDataXML (destPath);
266 if (getSelectedItem() && !saveSel )
267 s+=xml.valueElement("select",getSelectString());
270 s+=xml.endElement("vymmap");
272 //cout << s.toStdString() << endl;
274 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
278 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
282 for (int i=0; i<rootItem->branchCount(); i++)
283 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
287 void VymModel::setFilePath(QString fpath, QString destname)
289 if (fpath.isEmpty() || fpath=="")
296 filePath=fpath; // becomes absolute path
297 fileName=fpath; // gets stripped of path
298 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
300 // If fpath is not an absolute path, complete it
301 filePath=QDir(fpath).absPath();
302 fileDir=filePath.left (1+filePath.findRev ("/"));
304 // Set short name, too. Search from behind:
305 int i=fileName.findRev("/");
306 if (i>=0) fileName=fileName.remove (0,i+1);
308 // Forget the .vym (or .xml) for name of map
309 mapName=fileName.left(fileName.findRev(".",-1,true) );
313 void VymModel::setFilePath(QString fpath)
315 setFilePath (fpath,fpath);
318 QString VymModel::getFilePath()
323 QString VymModel::getFileName()
328 QString VymModel::getMapName()
333 QString VymModel::getDestPath()
338 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
340 ErrorCode err=success;
342 parseBaseHandler *handler;
346 case VymMap: handler=new parseVYMHandler; break;
347 case FreemindMap : handler=new parseFreemindHandler; break;
349 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
350 "Unknown FileType in VymModel::load()");
354 bool zipped_org=zipped;
358 selModel->clearSelection();
359 // FIXME-2 VM not needed??? model->setMapEditor(this);
360 // (map state is set later at end of load...)
363 BranchItem *bi=getSelectedBranch();
364 if (!bi) return aborted;
365 if (lmode==ImportAdd)
366 saveStateChangingPart(
369 QString("addMapInsert (%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 saveStateChangingPart(
375 QString("addMapReplace(%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
380 // Create temporary directory for packing
382 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
385 QMessageBox::critical( 0, tr( "Critical Load Error" ),
386 tr("Couldn't create temporary directory before load\n"));
391 err=unzipDir (tmpZipDir,fname);
401 // Look for mapname.xml
402 xmlfile= fname.left(fname.findRev(".",-1,true));
403 xmlfile=xmlfile.section( '/', -1 );
404 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
405 if (!mfile.exists() )
407 // mapname.xml does not exist, well,
408 // maybe someone renamed the mapname.vym file...
409 // Try to find any .xml in the toplevel
410 // directory of the .vym file
411 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
412 if (flist.count()==1)
414 // Only one entry, take this one
415 xmlfile=tmpZipDir + "/"+flist.first();
418 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
419 *it=tmpZipDir + "/" + *it;
420 // TODO Multiple entries, load all (but only the first one into this ME)
421 //mainWindow->fileLoadFromTmp (flist);
422 //returnCode=1; // Silently forget this attempt to load
423 qWarning ("MainWindow::load (fn) multimap found...");
426 if (flist.isEmpty() )
428 QMessageBox::critical( 0, tr( "Critical Load Error" ),
429 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
432 } //file doesn't exist
434 xmlfile=mfile.name();
437 QFile file( xmlfile);
439 // I am paranoid: file should exist anyway
440 // according to check in mainwindow.
443 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
444 tr(QString("Couldn't open map %1").arg(file.name())));
448 bool blockSaveStateOrg=blockSaveState;
449 blockReposition=true;
451 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
452 QXmlInputSource source( file);
453 QXmlSimpleReader reader;
454 reader.setContentHandler( handler );
455 reader.setErrorHandler( handler );
456 handler->setModel ( this);
459 // We need to set the tmpDir in order to load files with rel. path
464 tmpdir=fname.left(fname.findRev("/",-1));
465 handler->setTmpDir (tmpdir);
466 handler->setInputFile (file.name());
467 handler->setLoadMode (lmode);
468 bool ok = reader.parse( source );
469 blockReposition=false;
470 blockSaveState=blockSaveStateOrg;
471 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
475 reposition(); // FIXME-2 VM reposition the view instead...
476 emitSelectionChanged();
482 autosaveTimer->stop();
485 // Reset timestamp to check for later updates of file
486 fileChangedTime=QFileInfo (destPath).lastModified();
489 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
490 tr( handler->errorProtocol() ) );
492 // Still return "success": the map maybe at least
493 // partially read by the parser
498 removeDir (QDir(tmpZipDir));
500 // Restore original zip state
507 ErrorCode VymModel::save (const SaveMode &savemode)
511 QString safeFilePath;
513 ErrorCode err=success;
517 mapFileName=mapName+".xml";
519 // use name given by user, even if he chooses .doc
520 mapFileName=fileName;
522 // Look, if we should zip the data:
525 QMessageBox mb( vymName,
526 tr("The map %1\ndid not use the compressed "
527 "vym file format.\nWriting it uncompressed will also write images \n"
528 "and flags and thus may overwrite files in the "
529 "given directory\n\nDo you want to write the map").arg(filePath),
530 QMessageBox::Warning,
531 QMessageBox::Yes | QMessageBox::Default,
533 QMessageBox::Cancel | QMessageBox::Escape);
534 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
535 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
536 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
539 case QMessageBox::Yes:
540 // save compressed (default file format)
543 case QMessageBox::No:
547 case QMessageBox::Cancel:
554 // First backup existing file, we
555 // don't want to add to old zip archives
559 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
561 QString backupFileName(destPath + "~");
562 QFile backupFile(backupFileName);
563 if (backupFile.exists() && !backupFile.remove())
565 QMessageBox::warning(0, tr("Save Error"),
566 tr("%1\ncould not be removed before saving").arg(backupFileName));
568 else if (!f.rename(backupFileName))
570 QMessageBox::warning(0, tr("Save Error"),
571 tr("%1\ncould not be renamed before saving").arg(destPath));
578 // Create temporary directory for packing
580 tmpZipDir=makeTmpDir (ok,"vym-zip");
583 QMessageBox::critical( 0, tr( "Critical Load Error" ),
584 tr("Couldn't create temporary directory before save\n"));
588 safeFilePath=filePath;
589 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
592 // Create mapName and fileDir
593 makeSubDirs (fileDir);
596 if (savemode==CompleteMap || selModel->selection().isEmpty())
599 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
602 autosaveTimer->stop();
607 if (selectionType()==TreeItem::Image)
610 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
611 // TODO take care of multiselections
614 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
617 qWarning ("ME::saveStringToDisk failed!");
623 if (err==success) err=zipDir (tmpZipDir,destPath);
626 removeDir (QDir(tmpZipDir));
628 // Restore original filepath outside of tmp zip dir
629 setFilePath (safeFilePath);
633 fileChangedTime=QFileInfo (destPath).lastModified();
637 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
639 QString pathDir=path.left(path.findRev("/"));
645 // We need to parse saved XML data
646 parseVYMHandler handler;
647 QXmlInputSource source( file);
648 QXmlSimpleReader reader;
649 reader.setContentHandler( &handler );
650 reader.setErrorHandler( &handler );
651 handler.setModel ( this);
652 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
653 if (undoSel.isEmpty())
657 handler.setLoadMode (NewMap);
661 handler.setLoadMode (ImportReplace);
663 blockReposition=true;
664 bool ok = reader.parse( source );
665 blockReposition=false;
668 // This should never ever happen
669 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
670 handler.errorProtocol());
673 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
676 bool VymModel::addMapInsertInt (const QString &path)
678 QString pathDir=path.left(path.findRev("/"));
684 // We need to parse saved XML data
685 parseVYMHandler handler;
686 QXmlInputSource source( file);
687 QXmlSimpleReader reader;
688 reader.setContentHandler( &handler );
689 reader.setErrorHandler( &handler );
690 handler.setModel (this);
691 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
692 handler.setLoadMode (ImportAdd);
693 blockReposition=true;
694 bool ok = reader.parse( source );
695 blockReposition=false;
696 if ( ok ) return true;
698 // This should never ever happen
699 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
700 handler.errorProtocol());
703 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
707 bool VymModel::addMapInsertInt (const QString &path, int pos)
709 BranchItem *selbi=getSelectedBranch();
712 if (addMapInsertInt (path))
714 if (selbi->depth()>0)
715 relinkBranch (selbi->getLastBranch(), selbi,pos);
719 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
723 qWarning ("ME::addMapInsertInt nothing selected");
727 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
729 ImageItem *ii=createImage(dst);
739 void VymModel::loadFloatImage ()
741 BranchItem *selbi=getSelectedBranch();
745 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
746 fd->setMode (Q3FileDialog::ExistingFiles);
747 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
748 ImagePreview *p =new ImagePreview (fd);
749 fd->setContentsPreviewEnabled( TRUE );
750 fd->setContentsPreview( p, p );
751 fd->setPreviewMode( Q3FileDialog::Contents );
752 fd->setCaption(vymName+" - " +tr("Load image"));
753 fd->setDir (lastImageDir);
756 if ( fd->exec() == QDialog::Accepted )
758 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
759 lastImageDir=QDir (fd->dirPath());
762 for (int j=0; j<fd->selectedFiles().count(); j++)
764 s=fd->selectedFiles().at(j);
765 ii=loadFloatImageInt (selbi,s);
766 //FIXME-3 check savestate for loadImage
772 QString ("loadImage (%1)").arg(s ),
773 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
776 // TODO loadFIO error handling
777 qWarning ("Failed to load "+s);
785 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
790 void VymModel::saveFloatImage ()
792 ImageItem *ii=getSelectedImage();
795 QFileDialog *fd=new QFileDialog( NULL);
796 fd->setFilters (imageIO.getFilters());
797 fd->setCaption(vymName+" - " +tr("Save image"));
798 fd->setFileMode( QFileDialog::AnyFile );
799 fd->setDirectory (lastImageDir);
800 // fd->setSelection (fio->getOriginalFilename());
804 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
806 fn=fd->selectedFiles().at(0);
807 if (QFile (fn).exists() )
809 QMessageBox mb( vymName,
810 tr("The file %1 exists already.\n"
811 "Do you want to overwrite it?").arg(fn),
812 QMessageBox::Warning,
813 QMessageBox::Yes | QMessageBox::Default,
814 QMessageBox::Cancel | QMessageBox::Escape,
815 QMessageBox::NoButton );
817 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
818 mb.setButtonText( QMessageBox::No, tr("Cancel"));
821 case QMessageBox::Yes:
824 case QMessageBox::Cancel:
831 saveFloatImageInt (ii,fd->selectedFilter(),fn );
838 void VymModel::importDirInt(BranchItem *dst, QDir d)
840 BranchItem *selbi=getSelectedBranch();
844 // Traverse directories
845 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
846 QFileInfoList list = d.entryInfoList();
849 for (int i = 0; i < list.size(); ++i)
852 if (fi.fileName() != "." && fi.fileName() != ".." )
854 bi=addNewBranchInt(dst,-2);
855 bi->setHeading (fi.fileName() ); // FIXME-3 check this
856 bi->setHeadingColor (QColor("blue"));
858 if ( !d.cd(fi.fileName()) )
859 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
862 // Recursively add subdirs
869 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
870 list = d.entryInfoList();
872 for (int i = 0; i < list.size(); ++i)
875 bi=addNewBranchInt (dst,-2);
876 bi->setHeading (fi.fileName() );
877 bi->setHeadingColor (QColor("black"));
878 if (fi.fileName().right(4) == ".vym" )
879 bi->setVymLink (fi.filePath());
884 void VymModel::importDirInt (const QString &s)
886 BranchItem *selbi=getSelectedBranch();
889 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
892 importDirInt (selbi,d);
896 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
898 BranchItem *selbi=getSelectedBranch();
902 filters <<"VYM map (*.vym)";
903 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
904 fd->setMode (QFileDialog::DirectoryOnly);
905 fd->setFilters (filters);
906 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
910 if ( fd->exec() == QDialog::Accepted )
912 importDirInt (fd->selectedFile() );
914 //FIXME-3 VM needed? scene()->update();
920 void VymModel::autosave()
925 cout << "VymModel::autosave rejected due to missing filePath\n";
928 QDateTime now=QDateTime().currentDateTime();
930 // Disable autosave, while we have gone back in history
931 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
932 if (redosAvail>0) return;
934 // Also disable autosave for new map without filename
935 if (filePath.isEmpty()) return;
938 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
940 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
941 mainWindow->fileSave (this);
944 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
949 void VymModel::fileChanged()
951 // Check if file on disk has changed meanwhile
952 if (!filePath.isEmpty())
954 QDateTime tmod=QFileInfo (filePath).lastModified();
955 if (tmod>fileChangedTime)
957 // FIXME-2 VM switch to current mapeditor and finish lineedits...
958 QMessageBox mb( vymName,
959 tr("The file of the map on disk has changed:\n\n"
960 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
961 QMessageBox::Question,
963 QMessageBox::Cancel | QMessageBox::Default,
964 QMessageBox::NoButton );
966 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
967 mb.setButtonText( QMessageBox::No, tr("Ignore"));
970 case QMessageBox::Yes:
972 load (filePath,NewMap,fileType);
973 case QMessageBox::Cancel:
974 fileChangedTime=tmod; // allow autosave to overwrite newer file!
980 bool VymModel::isDefault()
985 void VymModel::makeDefault()
991 bool VymModel::hasChanged()
996 void VymModel::setChanged()
999 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1003 latestAddedItem=NULL;
1007 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1009 if (!lmo || !lmo->getTreeItem() ) return QString();
1010 return getObjectName (lmo->getTreeItem() );
1014 QString VymModel::getObjectName (TreeItem *ti)
1017 if (!ti) return QString("Error: NULL has no name!");
1019 if (s=="") s="unnamed";
1021 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1024 void VymModel::redo()
1026 // Can we undo at all?
1027 if (redosAvail<1) return;
1029 bool blockSaveStateOrg=blockSaveState;
1030 blockSaveState=true;
1034 if (undosAvail<stepsTotal) undosAvail++;
1036 if (curStep>stepsTotal) curStep=1;
1037 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1038 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1039 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1040 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1041 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1042 QString version=undoSet.readEntry ("/history/version");
1044 /* TODO Maybe check for version, if we save the history
1045 if (!checkVersion(version))
1046 QMessageBox::warning(0,tr("Warning"),
1047 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1050 // Find out current undo directory
1051 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1055 cout << "VymModel::redo() begin\n";
1056 cout << " undosAvail="<<undosAvail<<endl;
1057 cout << " redosAvail="<<redosAvail<<endl;
1058 cout << " curStep="<<curStep<<endl;
1059 cout << " ---------------------------"<<endl;
1060 cout << " comment="<<comment.toStdString()<<endl;
1061 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1062 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1063 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1064 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1065 cout << " ---------------------------"<<endl<<endl;
1068 // select object before redo
1069 if (!redoSelection.isEmpty())
1070 select (redoSelection);
1075 parseAtom (redoCommand,noErr,errMsg);
1077 blockSaveState=blockSaveStateOrg;
1079 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1080 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1081 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1082 undoSet.writeSettings(histPath);
1084 mainWindow->updateHistory (undoSet);
1087 /* TODO remove testing
1088 cout << "ME::redo() end\n";
1089 cout << " undosAvail="<<undosAvail<<endl;
1090 cout << " redosAvail="<<redosAvail<<endl;
1091 cout << " curStep="<<curStep<<endl;
1092 cout << " ---------------------------"<<endl<<endl;
1098 bool VymModel::isRedoAvailable()
1100 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1106 void VymModel::undo()
1108 // Can we undo at all?
1109 if (undosAvail<1) return;
1111 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1113 bool blockSaveStateOrg=blockSaveState;
1114 blockSaveState=true;
1116 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1117 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1118 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1119 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1120 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1121 QString version=undoSet.readEntry ("/history/version");
1123 /* TODO Maybe check for version, if we save the history
1124 if (!checkVersion(version))
1125 QMessageBox::warning(0,tr("Warning"),
1126 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1129 // Find out current undo directory
1130 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1132 // select object before undo
1133 if (!select (undoSelection))
1135 qWarning ("VymModel::undo() Could not select object for undo");
1142 cout << "VymModel::undo() begin\n";
1143 cout << " undosAvail="<<undosAvail<<endl;
1144 cout << " redosAvail="<<redosAvail<<endl;
1145 cout << " curStep="<<curStep<<endl;
1146 cout << " ---------------------------"<<endl;
1147 cout << " comment="<<comment.toStdString()<<endl;
1148 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1149 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1150 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1151 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1152 cout << " ---------------------------"<<endl<<endl;
1157 parseAtom (undoCommand,noErr,errMsg);
1161 if (curStep<1) curStep=stepsTotal;
1165 blockSaveState=blockSaveStateOrg;
1167 cout << "VymModel::undo() end\n";
1168 cout << " undosAvail="<<undosAvail<<endl;
1169 cout << " redosAvail="<<redosAvail<<endl;
1170 cout << " curStep="<<curStep<<endl;
1171 cout << " ---------------------------"<<endl<<endl;
1174 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1175 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1176 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1177 undoSet.writeSettings(histPath);
1179 mainWindow->updateHistory (undoSet);
1181 //emitSelectionChanged();
1184 bool VymModel::isUndoAvailable()
1186 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1192 void VymModel::gotoHistoryStep (int i)
1194 // Restore variables
1195 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1196 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1198 if (i<0) i=undosAvail+redosAvail;
1200 // Clicking above current step makes us undo things
1203 for (int j=0; j<undosAvail-i; j++) undo();
1206 // Clicking below current step makes us redo things
1208 for (int j=undosAvail; j<i; j++)
1210 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1214 // And ignore clicking the current row ;-)
1218 QString VymModel::getHistoryPath()
1220 QString histName(QString("history-%1").arg(curStep));
1221 return (tmpMapDir+"/"+histName);
1224 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1226 sendData(redoCom); //FIXME-3 testing
1231 if (blockSaveState) return;
1233 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1235 // Find out current undo directory
1236 if (undosAvail<stepsTotal) undosAvail++;
1238 if (curStep>stepsTotal) curStep=1;
1240 QString backupXML="";
1241 QString histDir=getHistoryPath();
1242 QString bakMapPath=histDir+"/map.xml";
1244 // Create histDir if not available
1247 makeSubDirs (histDir);
1249 // Save depending on how much needs to be saved
1251 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1253 QString undoCommand="";
1254 if (savemode==UndoCommand)
1256 undoCommand=undoCom;
1258 else if (savemode==PartOfMap )
1260 undoCommand=undoCom;
1261 undoCommand.replace ("PATH",bakMapPath);
1265 if (!backupXML.isEmpty())
1266 // Write XML Data to disk
1267 saveStringToDisk (bakMapPath,backupXML);
1269 // We would have to save all actions in a tree, to keep track of
1270 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1273 // Write the current state to disk
1274 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1275 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1276 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1277 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1278 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1280 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1282 undoSet.setEntry (QString("/history/version"),vymVersion);
1283 undoSet.writeSettings(histPath);
1287 // TODO remove after testing
1288 //cout << " into="<< histPath.toStdString()<<endl;
1289 cout << " stepsTotal="<<stepsTotal<<
1290 ", undosAvail="<<undosAvail<<
1291 ", redosAvail="<<redosAvail<<
1292 ", curStep="<<curStep<<endl;
1293 cout << " ---------------------------"<<endl;
1294 cout << " comment="<<comment.toStdString()<<endl;
1295 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1296 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1297 cout << " redoCom="<<redoCom.toStdString()<<endl;
1298 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1299 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1300 cout << " ---------------------------"<<endl;
1303 mainWindow->updateHistory (undoSet);
1309 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1311 // save the selected part of the map, Undo will replace part of map
1312 QString undoSelection="";
1314 undoSelection=getSelectString(undoSel);
1316 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1317 QString redoSelection="";
1319 redoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1324 saveState (PartOfMap,
1325 undoSelection, "addMapReplace (\"PATH\")",
1331 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1335 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1338 QString undoSelection;
1339 QString redoSelection=getSelectString(redoSel);
1340 if (redoSel->getType()==TreeItem::Branch)
1342 undoSelection=getSelectString (redoSel->parent());
1343 // save the selected branch of the map, Undo will insert part of map
1344 saveState (PartOfMap,
1345 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1346 redoSelection, "delete ()",
1350 if (redoSel->getType()==TreeItem::MapCenter)
1352 // save the selected branch of the map, Undo will insert part of map
1353 saveState (PartOfMap,
1354 undoSelection, QString("addMapInsert (\"PATH\")"),
1355 redoSelection, "delete ()",
1362 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1364 // "Normal" savestate: save commands, selections and comment
1365 // so just save commands for undo and redo
1366 // and use current selection
1368 QString redoSelection="";
1369 if (redoSel) redoSelection=getSelectString(redoSel);
1370 QString undoSelection="";
1371 if (undoSel) undoSelection=getSelectString(undoSel);
1373 saveState (UndoCommand,
1380 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1382 // "Normal" savestate: save commands, selections and comment
1383 // so just save commands for undo and redo
1384 // and use current selection
1385 saveState (UndoCommand,
1392 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1394 // "Normal" savestate applied to model (no selection needed):
1395 // save commands and comment
1396 saveState (UndoCommand,
1404 QGraphicsScene* VymModel::getScene ()
1409 TreeItem* VymModel::findBySelectString(QString s)
1411 if (s.isEmpty() ) return NULL;
1413 // Old maps don't have multiple mapcenters and don't save full path
1414 if (s.left(2) !="mc")
1417 QStringList parts=s.split (",");
1420 TreeItem *ti=rootItem;
1422 while (!parts.isEmpty() )
1424 typ=parts.first().left(2);
1425 n=parts.first().right(parts.first().length() - 3).toInt();
1426 parts.removeFirst();
1427 if (typ=="mc" || typ=="bo")
1428 ti=ti->getBranchNum (n);
1430 ti=ti->getImageNum (n);
1432 ti=ti->getAttributeNum (n);
1434 ti=ti->getXLinkNum (n);
1435 if(!ti) return NULL;
1440 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1442 BranchItem *cur=NULL;
1443 BranchItem *prev=NULL;
1444 nextBranch(cur,prev);
1447 if (s==cur->getID() ) return cur;
1448 nextBranch(cur,prev);
1453 //////////////////////////////////////////////
1455 //////////////////////////////////////////////
1456 void VymModel::setVersion (const QString &s)
1461 void VymModel::setAuthor (const QString &s)
1464 QString ("setMapAuthor (\"%1\")").arg(author),
1465 QString ("setMapAuthor (\"%1\")").arg(s),
1466 QString ("Set author of map to \"%1\"").arg(s)
1471 QString VymModel::getAuthor()
1476 void VymModel::setComment (const QString &s)
1479 QString ("setMapComment (\"%1\")").arg(comment),
1480 QString ("setMapComment (\"%1\")").arg(s),
1481 QString ("Set comment of map")
1486 QString VymModel::getComment ()
1491 QString VymModel::getDate ()
1493 return QDate::currentDate().toString ("yyyy-MM-dd");
1496 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1499 BranchItem *cur=NULL;
1500 BranchItem *prev=NULL;
1501 nextBranch(cur,prev);
1505 nextBranch(cur,prev);
1510 void VymModel::setSortFilter (const QString &s)
1513 emit (sortFilterChanged (sortFilter));
1516 QString VymModel::getSortFilter ()
1521 void VymModel::setHeading(const QString &s)
1523 BranchItem *selbi=getSelectedBranch();
1528 "setHeading (\""+selbi->getHeading()+"\")",
1530 "setHeading (\""+s+"\")",
1531 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1532 selbi->setHeading(s );
1533 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1535 emitSelectionChanged();
1539 QString VymModel::getHeading()
1541 TreeItem *selti=getSelectedItem();
1543 return selti->getHeading();
1548 void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here)
1550 TreeItem *selti=getSelectedItem();
1554 emitNoteHasChanged(selti);
1558 QString VymModel::getNote()
1560 TreeItem *selti=getSelectedItem();
1562 return selti->getNote();
1567 BranchItem* VymModel::findText (QString s, bool cs)
1569 if (!s.isEmpty() && s!=findString)
1575 QTextDocument::FindFlags flags=0;
1576 if (cs) flags=QTextDocument::FindCaseSensitively;
1579 { // Nothing found or new find process
1581 // nothing found, start again
1585 nextBranch (findCurrent,findPrevious);
1587 bool searching=true;
1588 bool foundNote=false;
1589 while (searching && !EOFind)
1593 // Searching in Note
1594 if (findCurrent->getNote().contains(findString,cs))
1596 select (findCurrent);
1598 if (getSelectedBranch()!=itFind)
1601 emitShowSelection();
1604 if (textEditor->findText(findString,flags))
1610 // Searching in Heading
1611 if (searching && findCurrent->getHeading().contains (findString,cs) )
1613 select(findCurrent);
1619 if (!nextBranch(findCurrent,findPrevious) )
1622 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1625 return getSelectedBranch();
1630 void VymModel::findReset()
1631 { // Necessary if text to find changes during a find process
1638 void VymModel::emitShowFindWidget()
1640 emit (showFindWidget());
1643 void VymModel::setScene (QGraphicsScene *s)
1648 void VymModel::setURL(const QString &url)
1650 TreeItem *selti=getSelectedItem();
1653 QString oldurl=selti->getURL();
1654 selti->setURL (url);
1657 QString ("setURL (\"%1\")").arg(oldurl),
1659 QString ("setURL (\"%1\")").arg(url),
1660 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1663 emitDataHasChanged (selti);
1664 emitShowSelection();
1668 QString VymModel::getURL()
1670 TreeItem *selti=getSelectedItem();
1672 return selti->getURL();
1677 QStringList VymModel::getURLs()
1680 BranchItem *selbi=getSelectedBranch();
1681 BranchItem *cur=selbi;
1682 BranchItem *prev=NULL;
1685 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1686 cur=nextBranch (cur,prev,true,selbi);
1692 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1694 BranchItem *bi=getSelectedBranch();
1697 BranchObj *bo=(BranchObj*)(bi->getLMO());
1700 QString s=bo->getFrameTypeName();
1701 bo->setFrameType (t);
1702 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1703 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1705 bo->updateLinkGeometry();
1710 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1712 BranchItem *bi=getSelectedBranch();
1715 BranchObj *bo=(BranchObj*)(bi->getLMO());
1718 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1719 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1720 bo->setFrameType (s);
1722 bo->updateLinkGeometry();
1727 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1730 BranchItem *bi=getSelectedBranch();
1733 BranchObj *bo=(BranchObj*)(bi->getLMO());
1736 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1737 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1738 bo->setFramePenColor (c);
1743 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1745 BranchItem *bi=getSelectedBranch();
1748 BranchObj *bo=(BranchObj*)(bi->getLMO());
1751 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1752 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1753 bo->setFrameBrushColor (c);
1758 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1760 BranchItem *bi=getSelectedBranch();
1763 BranchObj *bo=(BranchObj*)(bi->getLMO());
1766 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1767 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1768 bo->setFramePadding (i);
1770 bo->updateLinkGeometry();
1775 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1777 BranchItem *bi=getSelectedBranch();
1780 BranchObj *bo=(BranchObj*)(bi->getLMO());
1783 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1784 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1785 bo->setFrameBorderWidth (i);
1787 bo->updateLinkGeometry();
1792 void VymModel::setIncludeImagesVer(bool b)
1794 BranchItem *bi=getSelectedBranch();
1797 QString u= b ? "false" : "true";
1798 QString r=!b ? "false" : "true";
1802 QString("setIncludeImagesVertically (%1)").arg(u),
1804 QString("setIncludeImagesVertically (%1)").arg(r),
1805 QString("Include images vertically in %1").arg(getObjectName(bi))
1807 bi->setIncludeImagesVer(b);
1808 emitDataHasChanged ( bi);
1813 void VymModel::setIncludeImagesHor(bool b)
1815 BranchItem *bi=getSelectedBranch();
1818 QString u= b ? "false" : "true";
1819 QString r=!b ? "false" : "true";
1823 QString("setIncludeImagesHorizontally (%1)").arg(u),
1825 QString("setIncludeImagesHorizontally (%1)").arg(r),
1826 QString("Include images horizontally in %1").arg(getObjectName(bi))
1828 bi->setIncludeImagesHor(b);
1829 emitDataHasChanged ( bi);
1834 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1836 TreeItem *ti=getSelectedItem();
1837 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1839 QString u= b ? "false" : "true";
1840 QString r=!b ? "false" : "true";
1844 QString("setHideLinkUnselected (%1)").arg(u),
1846 QString("setHideLinkUnselected (%1)").arg(r),
1847 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1849 ((MapItem*)ti)->setHideLinkUnselected(b);
1853 void VymModel::setHideExport(bool b)
1855 TreeItem *ti=getSelectedItem();
1857 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1859 ti->setHideInExport (b);
1860 QString u= b ? "false" : "true";
1861 QString r=!b ? "false" : "true";
1865 QString ("setHideExport (%1)").arg(u),
1867 QString ("setHideExport (%1)").arg(r),
1868 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1870 emitDataHasChanged(ti);
1871 emitSelectionChanged();
1874 // emitSelectionChanged();
1875 // FIXME-3 VM needed? scene()->update();
1879 void VymModel::toggleHideExport()
1881 TreeItem *selti=getSelectedItem();
1883 setHideExport ( !selti->hideInExport() );
1886 void VymModel::addTimestamp() //FIXME-3 new function, localize
1888 BranchItem *selbi=addNewBranch();
1891 QDate today=QDate::currentDate();
1893 selbi->setHeading (QString ("%1-%2-%3")
1894 .arg(today.year(),4,10,c)
1895 .arg(today.month(),2,10,c)
1896 .arg(today.day(),2,10,c));
1897 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1904 void VymModel::copy()
1906 TreeItem *selti=getSelectedItem();
1908 (selti->getType() == TreeItem::Branch ||
1909 selti->getType() == TreeItem::MapCenter ||
1910 selti->getType() == TreeItem::Image ))
1912 if (redosAvail == 0)
1915 QString s=getSelectString(selti);
1916 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1917 curClipboard=curStep;
1920 // Copy also to global clipboard, because we are at last step in history
1921 QString bakMapName(QString("history-%1").arg(curStep));
1922 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1923 copyDir (bakMapDir,clipboardDir );
1925 clipboardEmpty=false;
1931 void VymModel::pasteNoSave(const int &n)
1933 bool old=blockSaveState;
1934 blockSaveState=true;
1935 bool zippedOrg=zipped;
1936 if (redosAvail > 0 || n!=0)
1938 // Use the "historical" buffer
1939 QString bakMapName(QString("history-%1").arg(n));
1940 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1941 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1943 // Use the global buffer
1944 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1949 void VymModel::paste()
1951 BranchItem *selbi=getSelectedBranch();
1954 saveStateChangingPart(
1957 QString ("paste (%1)").arg(curClipboard),
1958 QString("Paste to %1").arg( getObjectName(selbi))
1965 void VymModel::cut()
1967 TreeItem *selti=getSelectedItem();
1968 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1976 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1978 if (bi && bi->canMoveUp())
1979 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1984 void VymModel::moveUp()
1986 BranchItem *selbi=getSelectedBranch();
1989 QString oldsel=getSelectString();
1992 getSelectString(),"moveDown ()",
1994 QString("Move up %1").arg(getObjectName(selbi)));
1998 bool VymModel::moveDown(BranchItem *bi)
2000 if (bi && bi->canMoveDown())
2001 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2006 void VymModel::moveDown()
2008 BranchItem *selbi=getSelectedBranch();
2011 QString oldsel=getSelectString();
2012 if ( moveDown(selbi))
2014 getSelectString(),"moveUp ()",
2015 oldsel,"moveDown ()",
2016 QString("Move down %1").arg(getObjectName(selbi)));
2020 void VymModel::detach()
2022 BranchItem *selbi=getSelectedBranch();
2023 if (selbi && selbi->depth()>0)
2025 // if no relPos have been set before, try to use current rel positions
2026 if (selbi->getLMO())
2027 for (int i=0; i<selbi->branchCount();++i)
2028 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2030 QString oldsel=getSelectString();
2033 BranchObj *bo=selbi->getBranchObj();
2034 if (bo) p=bo->getAbsPos();
2035 QString parsel=getSelectString(selbi->parent());
2036 if ( relinkBranch (selbi,rootItem,-1) )
2038 getSelectString (selbi),
2039 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2042 QString("Detach %1").arg(getObjectName(selbi))
2047 void VymModel::sortChildren()
2049 BranchItem* selbi=getSelectedBranch();
2052 if(selbi->branchCount()>1)
2054 saveStateChangingPart(
2055 selbi,selbi, "sortChildren ()",
2056 QString("Sort children of %1").arg(getObjectName(selbi)));
2057 selbi->sortChildren();
2059 emitShowSelection();
2064 BranchItem* VymModel::createMapCenter()
2066 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2070 BranchItem* VymModel::createBranch(BranchItem *dst)
2073 return addNewBranchInt (dst,-2);
2078 ImageItem* VymModel::createImage(BranchItem *dst)
2085 QList<QVariant> cData;
2086 cData << "new" << "undef";
2088 ImageItem *newii=new ImageItem(cData) ;
2089 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2091 emit (layoutAboutToBeChanged() );
2094 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2095 n=dst->getRowNumAppend(newii);
2096 beginInsertRows (parix,n,n);
2097 dst->appendChild (newii);
2100 emit (layoutChanged() );
2102 // save scroll state. If scrolled, automatically select
2103 // new branch in order to tmp unscroll parent...
2104 newii->createMapObj(mapScene);
2111 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2118 QList<QVariant> cData;
2119 cData << "new xLink"<<"undef";
2121 XLinkItem *newxli=new XLinkItem(cData) ;
2122 newxli->setBegin (bi);
2124 emit (layoutAboutToBeChanged() );
2127 n=bi->getRowNumAppend(newxli);
2128 beginInsertRows (parix,n,n);
2129 bi->appendChild (newxli);
2132 emit (layoutChanged() );
2134 // save scroll state. If scrolled, automatically select
2135 // new branch in order to tmp unscroll parent...
2138 newxli->createMapObj(mapScene);
2146 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2148 BranchItem *selbi=getSelectedBranch();
2151 QList<QVariant> cData;
2152 cData << "new attribute" << "undef";
2153 AttributeItem *a=new AttributeItem (cData);
2155 emit (layoutAboutToBeChanged() );
2157 QModelIndex parix=index(selbi);
2158 int n=selbi->getRowNumAppend (a);
2159 beginInsertRows (parix,n,n);
2160 selbi->appendChild (a);
2163 emit (layoutChanged() );
2171 BranchItem* VymModel::addMapCenter ()
2173 BranchItem *bi=addMapCenter (contextPos);
2175 emitShowSelection();
2180 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2181 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2186 BranchItem* VymModel::addMapCenter(QPointF absPos)
2187 // createMapCenter could then probably be merged with createBranch
2191 QModelIndex parix=index(rootItem);
2193 QList<QVariant> cData;
2194 cData << "VM:addMapCenter" << "undef";
2195 BranchItem *newbi=new BranchItem (cData,rootItem);
2196 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2197 int n=rootItem->getRowNumAppend (newbi);
2199 emit (layoutAboutToBeChanged() );
2200 beginInsertRows (parix,n,n);
2202 rootItem->appendChild (newbi);
2205 emit (layoutChanged() );
2208 newbi->setPositionMode (MapItem::Absolute);
2209 BranchObj *bo=newbi->createMapObj(mapScene);
2210 if (bo) bo->move (absPos);
2215 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2217 // Depending on pos:
2218 // -3 insert in children of parent above selection
2219 // -2 add branch to selection
2220 // -1 insert in children of parent below selection
2221 // 0..n insert in children of parent at pos
2224 QList<QVariant> cData;
2225 cData << "" << "undef";
2230 BranchItem *newbi=new BranchItem (cData);
2231 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2233 emit (layoutAboutToBeChanged() );
2239 n=parbi->getRowNumAppend (newbi);
2240 beginInsertRows (parix,n,n);
2241 parbi->appendChild (newbi);
2243 }else if (num==-1 || num==-3)
2245 // insert below selection
2246 parbi=(BranchItem*)dst->parent();
2249 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2250 beginInsertRows (parix,n,n);
2251 parbi->insertBranch(n,newbi);
2254 emit (layoutChanged() );
2256 // Set color of heading to that of parent
2257 newbi->setHeadingColor (parbi->getHeadingColor());
2259 // save scroll state. If scrolled, automatically select
2260 // new branch in order to tmp unscroll parent...
2261 newbi->createMapObj(mapScene);
2266 BranchItem* VymModel::addNewBranch(int pos)
2268 // Different meaning than num in addNewBranchInt!
2272 BranchItem *newbi=NULL;
2273 BranchItem *selbi=getSelectedBranch();
2277 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2279 newbi=addNewBranchInt (selbi,pos-2);
2287 QString ("addBranch (%1)").arg(pos),
2288 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2291 // emitSelectionChanged(); FIXME-3
2292 latestAddedItem=newbi;
2293 // In Network mode, the client needs to know where the new branch is,
2294 // so we have to pass on this information via saveState.
2295 // TODO: Get rid of this positioning workaround
2296 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2297 sendData ("selectLatestAdded ()");
2298 sendData (QString("move %1").arg(ps));
2307 BranchItem* VymModel::addNewBranchBefore()
2309 BranchItem *newbi=NULL;
2310 BranchItem *selbi=getSelectedBranch();
2311 if (selbi && selbi->getType()==TreeItem::Branch)
2312 // We accept no MapCenter here, so we _have_ a parent
2314 //QPointF p=bo->getRelPos();
2317 // add below selection
2318 newbi=addNewBranchInt (selbi,-1);
2322 //newbi->move2RelPos (p);
2324 // Move selection to new branch
2325 relinkBranch (selbi,newbi,0);
2327 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2328 QString ("Add branch before %1").arg(getObjectName(selbi)));
2330 // FIXME-3 needed? reposition();
2331 // emitSelectionChanged(); FIXME-3
2337 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2343 emit (layoutAboutToBeChanged() );
2344 BranchItem *branchpi=(BranchItem*)branch->parent();
2345 // Remove at current position
2346 int n=branch->childNum();
2347 beginRemoveRows (index(branchpi),n,n);
2348 branchpi->removeChild (n);
2351 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2353 // Append as last branch to dst
2354 if (dst->branchCount()==0)
2357 n=dst->getFirstBranch()->childNumber();
2358 beginInsertRows (index(dst),n+pos,n+pos);
2359 dst->insertBranch (pos,branch);
2362 // Correct type if necessesary
2363 if (branch->getType()==TreeItem::MapCenter)
2364 branch->setType(TreeItem::Branch);
2366 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2367 branch->updateStyles();
2369 emit (layoutChanged() );
2370 reposition(); // both for moveUp/Down and relinking
2371 if (dst->isScrolled() )
2374 branch->updateVisibility();
2383 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2387 emit (layoutAboutToBeChanged() );
2389 BranchItem *pi=(BranchItem*)(image->parent());
2390 QString oldParString=getSelectString (pi);
2391 // Remove at current position
2392 int n=image->childNum();
2393 beginRemoveRows (index(pi),n,n);
2394 pi->removeChild (n);
2398 QModelIndex dstix=index(dst);
2399 n=dst->getRowNumAppend (image);
2400 beginInsertRows (dstix,n,n+1);
2401 dst->appendChild (image);
2404 // Set new parent also for lmo
2405 if (image->getLMO() && dst->getLMO() )
2406 image->getLMO()->setParObj (dst->getLMO() );
2408 emit (layoutChanged() );
2411 QString("relinkTo (\"%1\")").arg(oldParString),
2413 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2414 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2420 void VymModel::deleteSelection()
2422 BranchItem *selbi=getSelectedBranch();
2427 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2429 TreeItem *pi=deleteItem (selbi);
2433 emitShowSelection();
2437 TreeItem *ti=getSelectedItem();
2439 { // Delete other item
2440 TreeItem *pi=ti->parent();
2442 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2444 saveStateChangingPart(
2448 QString("Delete %1").arg(getObjectName(ti))
2452 emitDataHasChanged (pi);
2455 emitShowSelection();
2456 } else if (ti->getType()==TreeItem::XLink)
2458 //FIXME-2 savestate missing
2461 qWarning ("VymmModel::deleteSelection() unknown type?!");
2465 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2468 BranchItem *selbi=getSelectedBranch();
2472 // Don't use this on mapcenter
2473 if (selbi->depth()<2) return;
2475 pi=(BranchItem*)(selbi->parent());
2476 // Check if we have childs at all to keep
2477 if (selbi->branchCount()==0)
2484 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2485 saveStateChangingPart(
2488 "deleteKeepChildren ()",
2489 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2492 QString sel=getSelectString(selbi);
2494 int pos=selbi->num();
2495 BranchItem *bi=selbi->getFirstBranch();
2498 relinkBranch (bi,pi,pos);
2499 bi=selbi->getFirstBranch();
2505 BranchObj *bo=getSelectedBranchObj();
2508 bo->move2RelPos (p);
2514 void VymModel::deleteChildren()
2517 BranchItem *selbi=getSelectedBranch();
2520 saveStateChangingPart(
2523 "deleteChildren ()",
2524 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2526 emit (layoutAboutToBeChanged() );
2528 QModelIndex ix=index (selbi);
2529 int n=selbi->branchCount()-1;
2530 beginRemoveRows (ix,0,n);
2531 removeRows (0,n+1,ix);
2533 if (selbi->isScrolled()) selbi->unScroll();
2534 emit (layoutChanged() );
2539 TreeItem* VymModel::deleteItem (TreeItem *ti)
2543 TreeItem *pi=ti->parent();
2544 QModelIndex parentIndex=index(pi);
2546 emit (layoutAboutToBeChanged() );
2548 int n=ti->childNum();
2549 beginRemoveRows (parentIndex,n,n);
2550 removeRows (n,1,parentIndex);
2554 emit (layoutChanged() );
2555 if (pi->depth()>=0) return pi;
2560 void VymModel::clearItem (TreeItem *ti)
2564 QModelIndex parentIndex=index(ti);
2565 if (!parentIndex.isValid()) return;
2567 int n=ti->childCount();
2570 emit (layoutAboutToBeChanged() );
2572 beginRemoveRows (parentIndex,0,n-1);
2573 removeRows (0,n,parentIndex);
2577 emit (layoutChanged() );
2583 bool VymModel::scrollBranch(BranchItem *bi)
2587 if (bi->isScrolled()) return false;
2588 if (bi->branchCount()==0) return false;
2589 if (bi->depth()==0) return false;
2590 if (bi->toggleScroll())
2598 QString ("%1 ()").arg(u),
2600 QString ("%1 ()").arg(r),
2601 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2603 emitDataHasChanged(bi);
2604 emitSelectionChanged();
2605 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2612 bool VymModel::unscrollBranch(BranchItem *bi)
2616 if (!bi->isScrolled()) return false;
2617 if (bi->branchCount()==0) return false;
2618 if (bi->depth()==0) return false;
2619 if (bi->toggleScroll())
2627 QString ("%1 ()").arg(u),
2629 QString ("%1 ()").arg(r),
2630 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2632 emitDataHasChanged(bi);
2633 emitSelectionChanged();
2634 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2641 void VymModel::toggleScroll()
2643 BranchItem *bi=(BranchItem*)getSelectedBranch();
2644 if (bi && bi->isBranchLikeType() )
2646 if (bi->isScrolled())
2647 unscrollBranch (bi);
2651 // saveState & reposition are called in above functions
2654 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2656 BranchItem *selbi=getSelectedBranch();
2657 BranchItem *prev=NULL;
2658 BranchItem *cur=selbi;
2661 saveStateChangingPart(
2664 QString ("unscrollChildren ()"),
2665 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2669 if (cur->isScrolled())
2671 cur->toggleScroll();
2672 emitDataHasChanged (cur);
2674 cur=nextBranch (cur,prev,true,selbi);
2681 void VymModel::emitExpandAll()
2683 emit (expandAll() );
2686 void VymModel::emitExpandOneLevel()
2688 emit (expandOneLevel () );
2691 void VymModel::emitCollapseOneLevel()
2693 emit (collapseOneLevel () );
2696 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2698 BranchItem *bi=getSelectedBranch();
2702 if (bi->isActiveStandardFlag(name))
2714 QString("%1 (\"%2\")").arg(u).arg(name),
2716 QString("%1 (\"%2\")").arg(r).arg(name),
2717 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2718 bi->toggleStandardFlag (name, master);
2720 emitSelectionChanged();
2724 void VymModel::addFloatImage (const QPixmap &img)
2726 BranchItem *selbi=getSelectedBranch();
2729 ImageItem *ii=createImage (selbi);
2731 ii->setOriginalFilename("No original filename (image added by dropevent)");
2732 QString s=getSelectString(selbi);
2733 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2734 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2736 // FIXME-3 VM needed? scene()->update();
2741 void VymModel::colorBranch (QColor c)
2743 BranchItem *selbi=getSelectedBranch();
2748 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2750 QString ("colorBranch (\"%1\")").arg(c.name()),
2751 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2753 selbi->setHeadingColor(c); // color branch
2758 void VymModel::colorSubtree (QColor c)
2760 BranchItem *selbi=getSelectedBranch();
2763 saveStateChangingPart(
2766 QString ("colorSubtree (\"%1\")").arg(c.name()),
2767 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2769 BranchItem *prev=NULL;
2770 BranchItem *cur=selbi;
2773 cur->setHeadingColor(c); // color links, color children
2774 cur=nextBranch (cur,prev,true,selbi);
2780 QColor VymModel::getCurrentHeadingColor()
2782 BranchItem *selbi=getSelectedBranch();
2783 if (selbi) return selbi->getHeadingColor();
2785 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2791 void VymModel::editURL()
2793 TreeItem *selti=getSelectedItem();
2797 QString text = QInputDialog::getText(
2798 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2799 selti->getURL(), &ok, NULL);
2801 // user entered something and pressed OK
2806 void VymModel::editLocalURL()
2808 TreeItem *selti=getSelectedItem();
2811 QStringList filters;
2812 filters <<"All files (*)";
2813 filters << tr("Text","Filedialog") + " (*.txt)";
2814 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2815 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2816 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2817 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2818 fd->setFilters (filters);
2819 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2820 fd->setDirectory (lastFileDir);
2821 if (! selti->getVymLink().isEmpty() )
2822 fd->selectFile( selti->getURL() );
2825 if ( fd->exec() == QDialog::Accepted )
2827 lastFileDir=QDir (fd->directory().path());
2828 setURL (fd->selectedFile() );
2834 void VymModel::editHeading2URL()
2836 TreeItem *selti=getSelectedItem();
2838 setURL (selti->getHeading());
2841 void VymModel::editBugzilla2URL()
2843 TreeItem *selti=getSelectedItem();
2846 QString h=selti->getHeading();
2847 QRegExp rx("^(\\d+)");
2848 if (rx.indexIn(h) !=-1)
2849 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2853 void VymModel::editFATE2URL()
2855 TreeItem *selti=getSelectedItem();
2858 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2861 "setURL (\""+selti->getURL()+"\")",
2863 "setURL (\""+url+"\")",
2864 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2866 selti->setURL (url);
2867 // FIXME-4 updateActions();
2871 void VymModel::editVymLink()
2873 BranchItem *bi=getSelectedBranch();
2876 QStringList filters;
2877 filters <<"VYM map (*.vym)";
2878 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2879 fd->setFilters (filters);
2880 fd->setCaption(vymName+" - " +tr("Link to another map"));
2881 fd->setDirectory (lastFileDir);
2882 if (! bi->getVymLink().isEmpty() )
2883 fd->selectFile( bi->getVymLink() );
2887 if ( fd->exec() == QDialog::Accepted )
2889 lastFileDir=QDir (fd->directory().path());
2892 "setVymLink (\""+bi->getVymLink()+"\")",
2894 "setVymLink (\""+fd->selectedFile()+"\")",
2895 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2897 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2902 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2904 // Internal function, no saveState needed
2905 TreeItem *selti=getSelectedItem();
2908 selti->setVymLink(s);
2910 emitDataHasChanged (selti);
2911 emitShowSelection();
2915 void VymModel::deleteVymLink()
2917 BranchItem *bi=getSelectedBranch();
2922 "setVymLink (\""+bi->getVymLink()+"\")",
2924 "setVymLink (\"\")",
2925 QString("Unset vymlink of %1").arg(getObjectName(bi))
2927 bi->setVymLink ("" );
2933 QString VymModel::getVymLink()
2935 BranchItem *bi=getSelectedBranch();
2937 return bi->getVymLink();
2943 QStringList VymModel::getVymLinks()
2946 BranchItem *selbi=getSelectedBranch();
2947 BranchItem *cur=selbi;
2948 BranchItem *prev=NULL;
2951 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2952 cur=nextBranch (cur,prev,true,selbi);
2958 void VymModel::followXLink(int i)
2961 BranchItem *selbi=getSelectedBranch();
2964 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2965 if (selbi) select (selbi);
2969 void VymModel::editXLink(int i)
2972 BranchItem *selbi=getSelectedBranch();
2975 XLinkItem *xli=selbi->getXLinkNum(i);
2978 EditXLinkDialog dia;
2980 dia.setSelection(selbi);
2981 if (dia.exec() == QDialog::Accepted)
2983 if (dia.useSettingsGlobal() )
2985 setMapDefXLinkColor (xli->getColor() );
2986 setMapDefXLinkWidth (xli->getWidth() );
2988 if (dia.deleteXLink()) deleteItem (xli);
2998 //////////////////////////////////////////////
3000 //////////////////////////////////////////////
3002 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3004 TreeItem* selti=getSelectedItem();
3005 BranchItem *selbi=getSelectedBranch();
3010 QVariant returnValue;
3012 // Split string s into command and parameters
3013 parser.parseAtom (atom);
3014 QString com=parser.getCommand();
3016 // External commands
3017 /////////////////////////////////////////////////////////////////////
3018 if (com=="addBranch")
3022 parser.setError (Aborted,"Nothing selected");
3023 } else if (! selbi )
3025 parser.setError (Aborted,"Type of selection is not a branch");
3030 if (parser.checkParCount(pl))
3032 if (parser.parCount()==0)
3036 n=parser.parInt (ok,0);
3037 if (ok ) addNewBranch (n);
3041 /////////////////////////////////////////////////////////////////////
3042 } else if (com=="addBranchBefore")
3046 parser.setError (Aborted,"Nothing selected");
3047 } else if (! selbi )
3049 parser.setError (Aborted,"Type of selection is not a branch");
3052 if (parser.parCount()==0)
3054 addNewBranchBefore ();
3057 /////////////////////////////////////////////////////////////////////
3058 } else if (com==QString("addMapCenter"))
3060 if (parser.checkParCount(2))
3062 x=parser.parDouble (ok,0);
3065 y=parser.parDouble (ok,1);
3066 if (ok) addMapCenter (QPointF(x,y));
3069 /////////////////////////////////////////////////////////////////////
3070 } else if (com==QString("addMapReplace"))
3074 parser.setError (Aborted,"Nothing selected");
3075 } else if (! selbi )
3077 parser.setError (Aborted,"Type of selection is not a branch");
3078 } else if (parser.checkParCount(1))
3080 //s=parser.parString (ok,0); // selection
3081 t=parser.parString (ok,0); // path to map
3082 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3083 addMapReplaceInt(getSelectString(selbi),t);
3085 /////////////////////////////////////////////////////////////////////
3086 } else if (com==QString("addMapInsert"))
3088 if (parser.parCount()==2)
3093 parser.setError (Aborted,"Nothing selected");
3094 } else if (! selbi )
3096 parser.setError (Aborted,"Type of selection is not a branch");
3099 t=parser.parString (ok,0); // path to map
3100 n=parser.parInt(ok,1); // position
3101 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3102 addMapInsertInt(t,n);
3104 } else if (parser.parCount()==1)
3106 t=parser.parString (ok,0); // path to map
3107 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3110 parser.setError (Aborted,"Wrong number of parameters");
3111 /////////////////////////////////////////////////////////////////////
3112 } else if (com==QString("addXLink"))
3114 if (parser.parCount()>1)
3116 s=parser.parString (ok,0); // begin
3117 t=parser.parString (ok,1); // end
3118 BranchItem *begin=(BranchItem*)findBySelectString(s);
3119 BranchItem *end=(BranchItem*)findBySelectString(t);
3122 if (begin->isBranchLikeType() && end->isBranchLikeType())
3124 XLinkItem *xl=createXLink (begin,true);
3130 parser.setError (Aborted,"Failed to create xLink");
3133 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3136 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3138 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3139 /////////////////////////////////////////////////////////////////////
3140 } else if (com=="clearFlags")
3144 parser.setError (Aborted,"Nothing selected");
3145 } else if (! selbi )
3147 parser.setError (Aborted,"Type of selection is not a branch");
3148 } else if (parser.checkParCount(0))
3150 selbi->deactivateAllStandardFlags();
3152 /////////////////////////////////////////////////////////////////////
3153 } else if (com=="colorBranch")
3157 parser.setError (Aborted,"Nothing selected");
3158 } else if (! selbi )
3160 parser.setError (Aborted,"Type of selection is not a branch");
3161 } else if (parser.checkParCount(1))
3163 QColor c=parser.parColor (ok,0);
3164 if (ok) colorBranch (c);
3166 /////////////////////////////////////////////////////////////////////
3167 } else if (com=="colorSubtree")
3171 parser.setError (Aborted,"Nothing selected");
3172 } else if (! selbi )
3174 parser.setError (Aborted,"Type of selection is not a branch");
3175 } else if (parser.checkParCount(1))
3177 QColor c=parser.parColor (ok,0);
3178 if (ok) colorSubtree (c);
3180 /////////////////////////////////////////////////////////////////////
3181 } else if (com=="copy")
3185 parser.setError (Aborted,"Nothing selected");
3186 } else if ( selectionType()!=TreeItem::Branch &&
3187 selectionType()!=TreeItem::MapCenter &&
3188 selectionType()!=TreeItem::Image )
3190 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3191 } else if (parser.checkParCount(0))
3195 /////////////////////////////////////////////////////////////////////
3196 } else if (com=="cut")
3200 parser.setError (Aborted,"Nothing selected");
3201 } else if ( selectionType()!=TreeItem::Branch &&
3202 selectionType()!=TreeItem::MapCenter &&
3203 selectionType()!=TreeItem::Image )
3205 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3206 } else if (parser.checkParCount(0))
3210 /////////////////////////////////////////////////////////////////////
3211 } else if (com=="delete")
3215 parser.setError (Aborted,"Nothing selected");
3217 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3219 parser.setError (Aborted,"Type of selection is wrong.");
3222 else if (parser.checkParCount(0))
3226 /////////////////////////////////////////////////////////////////////
3227 } else if (com=="deleteKeepChildren")
3231 parser.setError (Aborted,"Nothing selected");
3232 } else if (! selbi )
3234 parser.setError (Aborted,"Type of selection is not a branch");
3235 } else if (parser.checkParCount(0))
3237 deleteKeepChildren();
3239 /////////////////////////////////////////////////////////////////////
3240 } else if (com=="deleteChildren")
3244 parser.setError (Aborted,"Nothing selected");
3247 parser.setError (Aborted,"Type of selection is not a branch");
3248 } else if (parser.checkParCount(0))
3252 /////////////////////////////////////////////////////////////////////
3253 } else if (com=="exportAO")
3257 if (parser.parCount()>=1)
3258 // Hey, we even have a filename
3259 fname=parser.parString(ok,0);
3262 parser.setError (Aborted,"Could not read filename");
3265 exportAO (fname,false);
3267 /////////////////////////////////////////////////////////////////////
3268 } else if (com=="exportASCII")
3272 if (parser.parCount()>=1)
3273 // Hey, we even have a filename
3274 fname=parser.parString(ok,0);
3277 parser.setError (Aborted,"Could not read filename");
3280 exportASCII (fname,false);
3282 /////////////////////////////////////////////////////////////////////
3283 } else if (com=="exportImage")
3287 if (parser.parCount()>=2)
3288 // Hey, we even have a filename
3289 fname=parser.parString(ok,0);
3292 parser.setError (Aborted,"Could not read filename");
3295 QString format="PNG";
3296 if (parser.parCount()>=2)
3298 format=parser.parString(ok,1);
3300 exportImage (fname,false,format);
3302 /////////////////////////////////////////////////////////////////////
3303 } else if (com=="exportXHTML")
3307 if (parser.parCount()>=2)
3308 // Hey, we even have a filename
3309 fname=parser.parString(ok,1);
3312 parser.setError (Aborted,"Could not read filename");
3315 exportXHTML (fname,false);
3317 /////////////////////////////////////////////////////////////////////
3318 } else if (com=="exportXML")
3322 if (parser.parCount()>=2)
3323 // Hey, we even have a filename
3324 fname=parser.parString(ok,1);
3327 parser.setError (Aborted,"Could not read filename");
3330 exportXML (fname,false);
3332 /////////////////////////////////////////////////////////////////////
3333 } else if (com=="getHeading")
3337 parser.setError (Aborted,"Nothing selected");
3338 } else if (parser.checkParCount(0))
3339 returnValue=selti->getHeading();
3340 /////////////////////////////////////////////////////////////////////
3341 } else if (com=="importDir")
3345 parser.setError (Aborted,"Nothing selected");
3346 } else if (! selbi )
3348 parser.setError (Aborted,"Type of selection is not a branch");
3349 } else if (parser.checkParCount(1))
3351 s=parser.parString(ok,0);
3352 if (ok) importDirInt(s);
3354 /////////////////////////////////////////////////////////////////////
3355 } else if (com=="relinkTo")
3359 parser.setError (Aborted,"Nothing selected");
3362 if (parser.checkParCount(4))
3364 // 0 selectstring of parent
3365 // 1 num in parent (for branches)
3366 // 2,3 x,y of mainbranch or mapcenter
3367 s=parser.parString(ok,0);
3368 TreeItem *dst=findBySelectString (s);
3371 if (dst->getType()==TreeItem::Branch)
3373 // Get number in parent
3374 n=parser.parInt (ok,1);
3377 relinkBranch (selbi,(BranchItem*)dst,n);
3378 emitSelectionChanged();
3380 } else if (dst->getType()==TreeItem::MapCenter)
3382 relinkBranch (selbi,(BranchItem*)dst);
3383 // Get coordinates of mainbranch
3384 x=parser.parDouble(ok,2);
3387 y=parser.parDouble(ok,3);
3390 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3391 emitSelectionChanged();
3397 } else if ( selti->getType() == TreeItem::Image)
3399 if (parser.checkParCount(1))
3401 // 0 selectstring of parent
3402 s=parser.parString(ok,0);
3403 TreeItem *dst=findBySelectString (s);
3406 if (dst->isBranchLikeType())
3407 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3409 parser.setError (Aborted,"Destination is not a branch");
3412 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3413 /////////////////////////////////////////////////////////////////////
3414 } else if (com=="loadImage")
3418 parser.setError (Aborted,"Nothing selected");
3419 } else if (! selbi )
3421 parser.setError (Aborted,"Type of selection is not a branch");
3422 } else if (parser.checkParCount(1))
3424 s=parser.parString(ok,0);
3425 if (ok) loadFloatImageInt (selbi,s);
3427 /////////////////////////////////////////////////////////////////////
3428 } else if (com=="moveUp")
3432 parser.setError (Aborted,"Nothing selected");
3433 } else if (! selbi )
3435 parser.setError (Aborted,"Type of selection is not a branch");
3436 } else if (parser.checkParCount(0))
3440 /////////////////////////////////////////////////////////////////////
3441 } else if (com=="moveDown")
3445 parser.setError (Aborted,"Nothing selected");
3446 } else if (! selbi )
3448 parser.setError (Aborted,"Type of selection is not a branch");
3449 } else if (parser.checkParCount(0))
3453 /////////////////////////////////////////////////////////////////////
3454 } else if (com=="move")
3458 parser.setError (Aborted,"Nothing selected");
3459 } else if ( selectionType()!=TreeItem::Branch &&
3460 selectionType()!=TreeItem::MapCenter &&
3461 selectionType()!=TreeItem::Image )
3463 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3464 } else if (parser.checkParCount(2))
3466 x=parser.parDouble (ok,0);
3469 y=parser.parDouble (ok,1);
3473 /////////////////////////////////////////////////////////////////////
3474 } else if (com=="moveRel")
3478 parser.setError (Aborted,"Nothing selected");
3479 } else if ( selectionType()!=TreeItem::Branch &&
3480 selectionType()!=TreeItem::MapCenter &&
3481 selectionType()!=TreeItem::Image )
3483 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3484 } else if (parser.checkParCount(2))
3486 x=parser.parDouble (ok,0);
3489 y=parser.parDouble (ok,1);
3490 if (ok) moveRel (x,y);
3493 /////////////////////////////////////////////////////////////////////
3494 } else if (com=="nop")
3496 /////////////////////////////////////////////////////////////////////
3497 } else if (com=="paste")
3501 parser.setError (Aborted,"Nothing selected");
3502 } else if (! selbi )
3504 parser.setError (Aborted,"Type of selection is not a branch");
3505 } else if (parser.checkParCount(1))
3507 n=parser.parInt (ok,0);
3508 if (ok) pasteNoSave(n);
3510 /////////////////////////////////////////////////////////////////////
3511 } else if (com=="qa")
3515 parser.setError (Aborted,"Nothing selected");
3516 } else if (! selbi )
3518 parser.setError (Aborted,"Type of selection is not a branch");
3519 } else if (parser.checkParCount(4))
3522 c=parser.parString (ok,0);
3525 parser.setError (Aborted,"No comment given");
3528 s=parser.parString (ok,1);
3531 parser.setError (Aborted,"First parameter is not a string");
3534 t=parser.parString (ok,2);
3537 parser.setError (Aborted,"Condition is not a string");
3540 u=parser.parString (ok,3);
3543 parser.setError (Aborted,"Third parameter is not a string");
3548 parser.setError (Aborted,"Unknown type: "+s);
3553 parser.setError (Aborted,"Unknown operator: "+t);
3558 parser.setError (Aborted,"Type of selection is not a branch");
3561 if (selbi->getHeading() == u)
3563 cout << "PASSED: " << qPrintable (c) << endl;
3566 cout << "FAILED: " << qPrintable (c) << endl;
3576 /////////////////////////////////////////////////////////////////////
3577 } else if (com=="saveImage")
3579 ImageItem *ii=getSelectedImage();
3582 parser.setError (Aborted,"No image selected");
3583 } else if (parser.checkParCount(2))
3585 s=parser.parString(ok,0);
3588 t=parser.parString(ok,1);
3589 if (ok) saveFloatImageInt (ii,t,s);
3592 /////////////////////////////////////////////////////////////////////
3593 } else if (com=="scroll")
3597 parser.setError (Aborted,"Nothing selected");
3598 } else if (! selbi )
3600 parser.setError (Aborted,"Type of selection is not a branch");
3601 } else if (parser.checkParCount(0))
3603 if (!scrollBranch (selbi))
3604 parser.setError (Aborted,"Could not scroll branch");
3606 /////////////////////////////////////////////////////////////////////
3607 } else if (com=="select")
3609 if (parser.checkParCount(1))
3611 s=parser.parString(ok,0);
3614 /////////////////////////////////////////////////////////////////////
3615 } else if (com=="selectLastBranch")
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 BranchItem *bi=selbi->getLastBranch();
3627 parser.setError (Aborted,"Could not select last branch");
3628 select (bi); // FIXME-3 was selectInt
3631 /////////////////////////////////////////////////////////////////////
3632 } else /* FIXME-2 if (com=="selectLastImage")
3636 parser.setError (Aborted,"Nothing selected");
3637 } else if (! selbi )
3639 parser.setError (Aborted,"Type of selection is not a branch");
3640 } else if (parser.checkParCount(0))
3642 FloatImageObj *fio=selb->getLastFloatImage();
3644 parser.setError (Aborted,"Could not select last image");
3645 select (fio); // FIXME-3 was selectInt
3648 /////////////////////////////////////////////////////////////////////
3649 } else */ if (com=="selectLatestAdded")
3651 if (!latestAddedItem)
3653 parser.setError (Aborted,"No latest added object");
3656 if (!select (latestAddedItem))
3657 parser.setError (Aborted,"Could not select latest added object ");
3659 /////////////////////////////////////////////////////////////////////
3660 } else if (com=="setFlag")
3664 parser.setError (Aborted,"Nothing selected");
3665 } else if (! selbi )
3667 parser.setError (Aborted,"Type of selection is not a branch");
3668 } else if (parser.checkParCount(1))
3670 s=parser.parString(ok,0);
3672 selbi->activateStandardFlag(s);
3674 /////////////////////////////////////////////////////////////////////
3675 } else if (com=="setFrameType")
3677 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3679 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3681 else if (parser.checkParCount(1))
3683 s=parser.parString(ok,0);
3684 if (ok) setFrameType (s);
3686 /////////////////////////////////////////////////////////////////////
3687 } else if (com=="setFramePenColor")
3689 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3691 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3693 else if (parser.checkParCount(1))
3695 QColor c=parser.parColor(ok,0);
3696 if (ok) setFramePenColor (c);
3698 /////////////////////////////////////////////////////////////////////
3699 } else if (com=="setFrameBrushColor")
3701 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3703 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3705 else if (parser.checkParCount(1))
3707 QColor c=parser.parColor(ok,0);
3708 if (ok) setFrameBrushColor (c);
3710 /////////////////////////////////////////////////////////////////////
3711 } else if (com=="setFramePadding")
3713 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3715 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3717 else if (parser.checkParCount(1))
3719 n=parser.parInt(ok,0);
3720 if (ok) setFramePadding(n);
3722 /////////////////////////////////////////////////////////////////////
3723 } else if (com=="setFrameBorderWidth")
3725 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3727 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3729 else if (parser.checkParCount(1))
3731 n=parser.parInt(ok,0);
3732 if (ok) setFrameBorderWidth (n);
3734 /////////////////////////////////////////////////////////////////////
3735 /* FIXME-2 else if (com=="setFrameType")
3739 parser.setError (Aborted,"Nothing selected");
3742 parser.setError (Aborted,"Type of selection is not a branch");
3743 } else if (parser.checkParCount(1))
3745 s=parser.parString(ok,0);
3749 /////////////////////////////////////////////////////////////////////
3751 /////////////////////////////////////////////////////////////////////
3752 } else if (com=="setHeading")
3756 parser.setError (Aborted,"Nothing selected");
3757 } else if (! selbi )
3759 parser.setError (Aborted,"Type of selection is not a branch");
3760 } else if (parser.checkParCount(1))
3762 s=parser.parString (ok,0);
3766 /////////////////////////////////////////////////////////////////////
3767 } else if (com=="setHideExport")
3771 parser.setError (Aborted,"Nothing selected");
3772 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3774 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3775 } else if (parser.checkParCount(1))
3777 b=parser.parBool(ok,0);
3778 if (ok) setHideExport (b);
3780 /////////////////////////////////////////////////////////////////////
3781 } else if (com=="setIncludeImagesHorizontally")
3785 parser.setError (Aborted,"Nothing selected");
3788 parser.setError (Aborted,"Type of selection is not a branch");
3789 } else if (parser.checkParCount(1))
3791 b=parser.parBool(ok,0);
3792 if (ok) setIncludeImagesHor(b);
3794 /////////////////////////////////////////////////////////////////////
3795 } else if (com=="setIncludeImagesVertically")
3799 parser.setError (Aborted,"Nothing selected");
3802 parser.setError (Aborted,"Type of selection is not a branch");
3803 } else if (parser.checkParCount(1))
3805 b=parser.parBool(ok,0);
3806 if (ok) setIncludeImagesVer(b);
3808 /////////////////////////////////////////////////////////////////////
3809 } else if (com=="setHideLinkUnselected")
3813 parser.setError (Aborted,"Nothing selected");
3814 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3816 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3817 } else if (parser.checkParCount(1))
3819 b=parser.parBool(ok,0);
3820 if (ok) setHideLinkUnselected(b);
3822 /////////////////////////////////////////////////////////////////////
3823 } else if (com=="setMapAuthor")
3825 if (parser.checkParCount(1))
3827 s=parser.parString(ok,0);
3828 if (ok) setAuthor (s);
3830 /////////////////////////////////////////////////////////////////////
3831 } else if (com=="setMapComment")
3833 if (parser.checkParCount(1))
3835 s=parser.parString(ok,0);
3836 if (ok) setComment(s);
3838 /////////////////////////////////////////////////////////////////////
3839 } else if (com=="setMapBackgroundColor")
3843 parser.setError (Aborted,"Nothing selected");
3844 } else if (! selbi )
3846 parser.setError (Aborted,"Type of selection is not a branch");
3847 } else if (parser.checkParCount(1))
3849 QColor c=parser.parColor (ok,0);
3850 if (ok) setMapBackgroundColor (c);
3852 /////////////////////////////////////////////////////////////////////
3853 } else if (com=="setMapDefLinkColor")
3857 parser.setError (Aborted,"Nothing selected");
3858 } else if (! selbi )
3860 parser.setError (Aborted,"Type of selection is not a branch");
3861 } else if (parser.checkParCount(1))
3863 QColor c=parser.parColor (ok,0);
3864 if (ok) setMapDefLinkColor (c);
3866 /////////////////////////////////////////////////////////////////////
3867 } else if (com=="setMapLinkStyle")
3869 if (parser.checkParCount(1))
3871 s=parser.parString (ok,0);
3872 if (ok) setMapLinkStyle(s);
3874 /////////////////////////////////////////////////////////////////////
3875 } else if (com=="setNote")
3879 parser.setError (Aborted,"Nothing selected");
3880 } else if (! selbi )
3882 parser.setError (Aborted,"Type of selection is not a branch");
3883 } else if (parser.checkParCount(1))
3885 s=parser.parString (ok,0);
3889 /////////////////////////////////////////////////////////////////////
3890 } else if (com=="setSelectionColor")
3892 if (parser.checkParCount(1))
3894 QColor c=parser.parColor (ok,0);
3895 if (ok) setSelectionColorInt (c);
3897 /////////////////////////////////////////////////////////////////////
3898 } else if (com=="setURL")
3902 parser.setError (Aborted,"Nothing selected");
3903 } else if (! selbi )
3905 parser.setError (Aborted,"Type of selection is not a branch");
3906 } else if (parser.checkParCount(1))
3908 s=parser.parString (ok,0);
3911 /////////////////////////////////////////////////////////////////////
3912 } else if (com=="setVymLink")
3916 parser.setError (Aborted,"Nothing selected");
3917 } else if (! selbi )
3919 parser.setError (Aborted,"Type of selection is not a branch");
3920 } else if (parser.checkParCount(1))
3922 s=parser.parString (ok,0);
3923 if (ok) setVymLink(s);
3925 } else if (com=="sortChildren")
3929 parser.setError (Aborted,"Nothing selected");
3930 } else if (! selbi )
3932 parser.setError (Aborted,"Type of selection is not a branch");
3933 } else if (parser.checkParCount(0))
3937 /////////////////////////////////////////////////////////////////////
3938 } else if (com=="toggleFlag")
3942 parser.setError (Aborted,"Nothing selected");
3943 } else if (! selbi )
3945 parser.setError (Aborted,"Type of selection is not a branch");
3946 } else if (parser.checkParCount(1))
3948 s=parser.parString(ok,0);
3950 selbi->toggleStandardFlag(s);
3952 /////////////////////////////////////////////////////////////////////
3953 } else if (com=="unscroll")
3957 parser.setError (Aborted,"Nothing selected");
3958 } else if (! selbi )
3960 parser.setError (Aborted,"Type of selection is not a branch");
3961 } else if (parser.checkParCount(0))
3963 if (!unscrollBranch (selbi))
3964 parser.setError (Aborted,"Could not unscroll branch");
3966 /////////////////////////////////////////////////////////////////////
3967 } else if (com=="unscrollChildren")
3971 parser.setError (Aborted,"Nothing selected");
3972 } else if (! selbi )
3974 parser.setError (Aborted,"Type of selection is not a branch");
3975 } else if (parser.checkParCount(0))
3977 unscrollChildren ();
3979 /////////////////////////////////////////////////////////////////////
3980 } else if (com=="unsetFlag")
3984 parser.setError (Aborted,"Nothing selected");
3985 } else if (! selbi )
3987 parser.setError (Aborted,"Type of selection is not a branch");
3988 } else if (parser.checkParCount(1))
3990 s=parser.parString(ok,0);
3992 selbi->deactivateStandardFlag(s);
3995 parser.setError (Aborted,"Unknown command");
3998 if (parser.errorLevel()==NoError)
4000 // setChanged(); FIXME-2 should not be called e.g. for export?!
4007 // TODO Error handling
4008 qWarning("VymModel::parseAtom: Error!");
4010 qWarning(parser.errorMessage());
4012 errorMsg=parser.errorMessage();
4017 QVariant VymModel::runScript (const QString &script)
4019 parser.setScript (script);
4024 while (parser.next() && noErr)
4026 r=parseAtom(parser.getAtom(),noErr,errMsg);
4027 if (!noErr) //FIXME-3 need dialog box here
4028 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4033 void VymModel::setExportMode (bool b)
4035 // should be called before and after exports
4036 // depending on the settings
4037 if (b && settings.value("/export/useHideExport","true")=="true")
4038 setHideTmpMode (TreeItem::HideExport);
4040 setHideTmpMode (TreeItem::HideNone);
4043 void VymModel::exportImage(QString fname, bool askName, QString format)
4047 fname=getMapName()+".png";
4054 QFileDialog *fd=new QFileDialog (NULL);
4055 fd->setCaption (tr("Export map as image"));
4056 fd->setDirectory (lastImageDir);
4057 fd->setFileMode(QFileDialog::AnyFile);
4058 fd->setFilters (imageIO.getFilters() );
4061 fl=fd->selectedFiles();
4063 format=imageIO.getType(fd->selectedFilter());
4067 setExportMode (true);
4068 QPixmap pix (mapEditor->getPixmap());
4069 pix.save(fname, format);
4070 setExportMode (false);
4074 void VymModel::exportXML(QString dir, bool askForName)
4078 dir=browseDirectory(NULL,tr("Export XML to directory"));
4079 if (dir =="" && !reallyWriteDirectory(dir) )
4083 // Hide stuff during export, if settings want this
4084 setExportMode (true);
4086 // Create subdirectories
4089 // write to directory //FIXME-4 check totalBBox here...
4090 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4093 file.setName ( dir + "/"+mapName+".xml");
4094 if ( !file.open( QIODevice::WriteOnly ) )
4096 // This should neverever happen
4097 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4101 // Write it finally, and write in UTF8, no matter what
4102 QTextStream ts( &file );
4103 ts.setEncoding (QTextStream::UnicodeUTF8);
4107 // Now write image, too
4108 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4110 setExportMode (false);
4113 void VymModel::exportAO (QString fname,bool askName)
4118 ex.setFile (mapName+".txt");
4124 //ex.addFilter ("TXT (*.txt)");
4125 ex.setDir(lastImageDir);
4126 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4131 setExportMode(true);
4133 setExportMode(false);
4137 void VymModel::exportASCII(QString fname,bool askName)
4142 ex.setFile (mapName+".txt");
4148 //ex.addFilter ("TXT (*.txt)");
4149 ex.setDir(lastImageDir);
4150 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4155 setExportMode(true);
4157 setExportMode(false);
4161 void VymModel::exportXHTML (const QString &dir, bool askForName)
4163 ExportXHTMLDialog dia(NULL);
4164 dia.setFilePath (filePath );
4165 dia.setMapName (mapName );
4167 if (dir!="") dia.setDir (dir);
4173 if (dia.exec()!=QDialog::Accepted)
4177 QDir d (dia.getDir());
4178 // Check, if warnings should be used before overwriting
4179 // the output directory
4180 if (d.exists() && d.count()>0)
4183 warn.showCancelButton (true);
4184 warn.setText(QString(
4185 "The directory %1 is not empty.\n"
4186 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4187 warn.setCaption("Warning: Directory not empty");
4188 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4190 if (warn.exec()!=QDialog::Accepted) ok=false;
4197 exportXML (dia.getDir(),false );
4198 dia.doExport(mapName );
4199 //if (dia.hasChanged()) setChanged();
4203 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4208 if (ex.setConfigFile(cf))
4210 setExportMode (true);
4211 ex.exportPresentation();
4212 setExportMode (false);
4219 //////////////////////////////////////////////
4221 //////////////////////////////////////////////
4223 void VymModel::registerEditor(QWidget *me)
4225 mapEditor=(MapEditor*)me;
4228 void VymModel::unregisterEditor(QWidget *)
4233 void VymModel::setContextPos(QPointF p)
4238 void VymModel::unsetContextPos()
4240 contextPos=QPointF();
4243 void VymModel::updateNoteFlag()
4246 TreeItem *selti=getSelectedItem();
4249 if (textEditor->isEmpty())
4252 selti->setNote (textEditor->getText());
4253 emitDataHasChanged(selti);
4254 emitSelectionChanged();
4259 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4261 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4262 if (blockReposition) return;
4264 for (int i=0;i<rootItem->branchCount(); i++)
4265 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4266 //emitSelectionChanged();
4270 void VymModel::setMapLinkStyle (const QString & s)
4275 case LinkableMapObj::Line :
4278 case LinkableMapObj::Parabel:
4279 snow="StyleParabel";
4281 case LinkableMapObj::PolyLine:
4282 snow="StylePolyLine";
4284 case LinkableMapObj::PolyParabel:
4285 snow="StylePolyParabel";
4288 snow="UndefinedStyle";
4293 QString("setMapLinkStyle (\"%1\")").arg(s),
4294 QString("setMapLinkStyle (\"%1\")").arg(snow),
4295 QString("Set map link style (\"%1\")").arg(s)
4299 linkstyle=LinkableMapObj::Line;
4300 else if (s=="StyleParabel")
4301 linkstyle=LinkableMapObj::Parabel;
4302 else if (s=="StylePolyLine")
4303 linkstyle=LinkableMapObj::PolyLine;
4304 else if (s=="StylePolyParabel")
4305 linkstyle=LinkableMapObj::PolyParabel;
4307 linkstyle=LinkableMapObj::UndefinedStyle;
4309 BranchItem *cur=NULL;
4310 BranchItem *prev=NULL;
4312 nextBranch (cur,prev);
4315 bo=(BranchObj*)(cur->getLMO() );
4316 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4317 cur=nextBranch(cur,prev);
4322 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4327 void VymModel::setMapDefLinkColor(QColor col)
4329 if ( !col.isValid() ) return;
4331 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4332 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4333 QString("Set map link color to %1").arg(col.name())
4337 BranchItem *cur=NULL;
4338 BranchItem *prev=NULL;
4340 cur=nextBranch(cur,prev);
4343 bo=(BranchObj*)(cur->getLMO() );
4345 nextBranch(cur,prev);
4350 void VymModel::setMapLinkColorHintInt()
4352 // called from setMapLinkColorHint(lch) or at end of parse
4353 BranchItem *cur=NULL;
4354 BranchItem *prev=NULL;
4356 cur=nextBranch(cur,prev);
4359 bo=(BranchObj*)(cur->getLMO() );
4361 cur=nextBranch(cur,prev);
4365 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4368 setMapLinkColorHintInt();
4371 void VymModel::toggleMapLinkColorHint()
4373 if (linkcolorhint==LinkableMapObj::HeadingColor)
4374 linkcolorhint=LinkableMapObj::DefaultColor;
4376 linkcolorhint=LinkableMapObj::HeadingColor;
4377 BranchItem *cur=NULL;
4378 BranchItem *prev=NULL;
4380 cur=nextBranch(cur,prev);
4383 bo=(BranchObj*)(cur->getLMO() );
4385 nextBranch(cur,prev);
4389 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4390 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4392 Q3FileDialog *fd=new Q3FileDialog( NULL);
4393 fd->setMode (Q3FileDialog::ExistingFile);
4394 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4395 ImagePreview *p =new ImagePreview (fd);
4396 fd->setContentsPreviewEnabled( TRUE );
4397 fd->setContentsPreview( p, p );
4398 fd->setPreviewMode( Q3FileDialog::Contents );
4399 fd->setCaption(vymName+" - " +tr("Load background image"));
4400 fd->setDir (lastImageDir);
4403 if ( fd->exec() == QDialog::Accepted )
4405 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4406 lastImageDir=QDir (fd->dirPath());
4407 setMapBackgroundImage (fd->selectedFile());
4411 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4413 QColor oldcol=mapScene->backgroundBrush().color();
4417 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4419 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4420 QString("Set background color of map to %1").arg(col.name()));
4423 brush.setTextureImage (QPixmap (fn));
4424 mapScene->setBackgroundBrush(brush);
4427 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4429 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4430 if ( !col.isValid() ) return;
4431 setMapBackgroundColor( col );
4435 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4437 QColor oldcol=mapScene->backgroundBrush().color();
4439 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4440 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4441 QString("Set background color of map to %1").arg(col.name()));
4442 mapScene->setBackgroundBrush(col);
4445 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4447 return mapScene->backgroundBrush().color();
4451 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4453 return linkcolorhint;
4456 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4458 return defLinkColor;
4461 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4466 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4468 return defXLinkColor;
4471 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4476 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4478 return defXLinkWidth;
4481 void VymModel::move(const double &x, const double &y)
4484 MapItem *seli = (MapItem*)getSelectedItem();
4485 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4487 LinkableMapObj *lmo=seli->getLMO();
4490 QPointF ap(lmo->getAbsPos());
4494 QString ps=qpointFToString(ap);
4495 QString s=getSelectString(seli);
4498 s, "move "+qpointFToString(to),
4499 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4502 emitSelectionChanged();
4508 void VymModel::moveRel (const double &x, const double &y)
4511 MapItem *seli = (MapItem*)getSelectedItem();
4512 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4514 LinkableMapObj *lmo=seli->getLMO();
4517 QPointF rp(lmo->getRelPos());
4521 QString ps=qpointFToString (lmo->getRelPos());
4522 QString s=getSelectString(seli);
4525 s, "moveRel "+qpointFToString(to),
4526 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4527 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4529 lmo->updateLinkGeometry();
4530 emitSelectionChanged();
4537 void VymModel::animate()
4539 animationTimer->stop();
4542 while (i<animObjList.size() )
4544 bo=(BranchObj*)animObjList.at(i);
4549 animObjList.removeAt(i);
4556 QItemSelection sel=selModel->selection();
4557 emit (selectionChanged(sel,sel));
4560 if (!animObjList.isEmpty()) animationTimer->start();
4564 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4566 if (start==dest) return;
4567 if (bo && bo->getTreeItem()->depth()>0)
4570 ap.setStart (start);
4572 ap.setTicks (animationTicks);
4573 ap.setAnimated (true);
4574 bo->setAnimation (ap);
4575 animObjList.append( bo );
4576 animationTimer->setSingleShot (true);
4577 animationTimer->start(animationInterval);
4581 void VymModel::stopAnimation (MapObj *mo)
4583 int i=animObjList.indexOf(mo);
4585 animObjList.removeAt (i);
4588 void VymModel::sendSelection()
4590 if (netstate!=Server) return;
4591 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4594 void VymModel::newServer()
4598 tcpServer = new QTcpServer(this);
4599 if (!tcpServer->listen(QHostAddress::Any,port)) {
4600 QMessageBox::critical(NULL, "vym server",
4601 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4602 //FIXME-3 needed? we are no widget any longer... close();
4605 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4607 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4610 void VymModel::connectToServer()
4613 server="salam.suse.de";
4615 clientSocket = new QTcpSocket (this);
4616 clientSocket->abort();
4617 clientSocket->connectToHost(server ,port);
4618 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4619 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4620 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4622 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4627 void VymModel::newClient()
4629 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4630 connect(newClient, SIGNAL(disconnected()),
4631 newClient, SLOT(deleteLater()));
4633 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4635 clientList.append (newClient);
4639 void VymModel::sendData(const QString &s)
4641 if (clientList.size()==0) return;
4643 // Create bytearray to send
4645 QDataStream out(&block, QIODevice::WriteOnly);
4646 out.setVersion(QDataStream::Qt_4_0);
4648 // Reserve some space for blocksize
4651 // Write sendCounter
4652 out << sendCounter++;
4657 // Go back and write blocksize so far
4658 out.device()->seek(0);
4659 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4663 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4665 for (int i=0; i<clientList.size(); ++i)
4667 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4668 clientList.at(i)->write (block);
4672 void VymModel::readData ()
4674 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4677 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4681 QDataStream in(clientSocket);
4682 in.setVersion(QDataStream::Qt_4_0);
4690 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4693 parseAtom (t,noErr,errMsg);
4699 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4701 switch (socketError) {
4702 case QAbstractSocket::RemoteHostClosedError:
4704 case QAbstractSocket::HostNotFoundError:
4705 QMessageBox::information(NULL, vymName +" Network client",
4706 "The host was not found. Please check the "
4707 "host name and port settings.");
4709 case QAbstractSocket::ConnectionRefusedError:
4710 QMessageBox::information(NULL, vymName + " Network client",
4711 "The connection was refused by the peer. "
4712 "Make sure the fortune server is running, "
4713 "and check that the host name and port "
4714 "settings are correct.");
4717 QMessageBox::information(NULL, vymName + " Network client",
4718 QString("The following error occurred: %1.")
4719 .arg(clientSocket->errorString()));
4723 /* FIXME-3 Playing with DBUS...
4724 QDBusVariant VymModel::query (const QString &query)
4726 TreeItem *selti=getSelectedItem();
4728 return QDBusVariant (selti->getHeading());
4730 return QDBusVariant ("Nothing selected.");
4734 void VymModel::testslot() //FIXME-3 Playing with DBUS
4736 cout << "VM::testslot called\n";
4739 void VymModel::selectMapSelectionColor()
4741 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4742 setSelectionColor (col);
4745 void VymModel::setSelectionColorInt (QColor col)
4747 if ( !col.isValid() ) return;
4749 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4750 QString("setSelectionColor (%1)").arg(col.name()),
4751 QString("Set color of selection box to %1").arg(col.name())
4754 mapEditor->setSelectionColor (col);
4757 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4759 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4760 //FIXME-3 emitShowSelection();
4764 void VymModel::emitSelectionChanged()
4766 QItemSelection newsel=selModel->selection();
4767 emitSelectionChanged (newsel);
4770 void VymModel::setSelectionColor(QColor col)
4772 if ( !col.isValid() ) return;
4774 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4775 QString("setSelectionColor (%1)").arg(col.name()),
4776 QString("Set color of selection box to %1").arg(col.name())
4778 setSelectionColorInt (col);
4781 QColor VymModel::getSelectionColor()
4783 return mapEditor->getSelectionColor();
4786 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4789 for (int i=0;i<rootItem->childCount();i++)
4790 rootItem->child(i)->setHideTmp (mode);
4792 // FIXME-3 needed? scene()->update();
4795 //////////////////////////////////////////////
4796 // Selection related
4797 //////////////////////////////////////////////
4799 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4804 QItemSelectionModel* VymModel::getSelectionModel()
4809 void VymModel::setSelectionBlocked (bool b)
4814 bool VymModel::isSelectionBlocked()
4816 return selectionBlocked;
4819 bool VymModel::select ()
4821 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4824 bool VymModel::select (const QString &s)
4831 TreeItem *ti=findBySelectString(s);
4832 if (ti) return select (index(ti));
4836 bool VymModel::select (LinkableMapObj *lmo)
4838 QItemSelection oldsel=selModel->selection();
4841 return select (index (lmo->getTreeItem()) );
4846 bool VymModel::select (TreeItem *ti)
4848 if (ti) return select (index(ti));
4852 bool VymModel::select (const QModelIndex &index)
4854 if (index.isValid() )
4856 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4857 BranchItem *bi=getSelectedBranch();
4858 if (bi) bi->setLastSelectedBranch();
4864 void VymModel::unselect()
4866 if (!selModel->selectedIndexes().isEmpty())
4868 lastSelectString=getSelectString();
4869 selModel->clearSelection();
4873 bool VymModel::reselect()
4875 return select (lastSelectString);
4878 void VymModel::emitShowSelection()
4880 if (!blockReposition)
4881 emit (showSelection() );
4884 void VymModel::emitNoteHasChanged (TreeItem *ti)
4886 QModelIndex ix=index(ti);
4887 emit (noteHasChanged (ix) );
4890 void VymModel::emitDataHasChanged (TreeItem *ti)
4892 QModelIndex ix=index(ti);
4893 emit (dataChanged (ix,ix) );
4897 bool VymModel::selectFirstBranch()
4899 TreeItem *ti=getSelectedBranch();
4902 TreeItem *par=ti->parent();
4905 TreeItem *ti2=par->getFirstBranch();
4906 if (ti2) return select(ti2);
4912 bool VymModel::selectLastBranch()
4914 TreeItem *ti=getSelectedBranch();
4917 TreeItem *par=ti->parent();
4920 TreeItem *ti2=par->getLastBranch();
4921 if (ti2) return select(ti2);
4927 bool VymModel::selectLastSelectedBranch()
4929 BranchItem *bi=getSelectedBranch();
4932 bi=bi->getLastSelectedBranch();
4933 if (bi) return select (bi);
4938 bool VymModel::selectParent()
4940 TreeItem *ti=getSelectedItem();
4951 TreeItem::Type VymModel::selectionType()
4953 QModelIndexList list=selModel->selectedIndexes();
4954 if (list.isEmpty()) return TreeItem::Undefined;
4955 TreeItem *ti = getItem (list.first() );
4956 return ti->getType();
4960 LinkableMapObj* VymModel::getSelectedLMO()
4962 QModelIndexList list=selModel->selectedIndexes();
4963 if (!list.isEmpty() )
4965 TreeItem *ti = getItem (list.first() );
4966 TreeItem::Type type=ti->getType();
4967 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4968 return ((MapItem*)ti)->getLMO();
4973 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4975 TreeItem *ti = getSelectedBranch();
4977 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4982 BranchItem* VymModel::getSelectedBranch()
4984 QModelIndexList list=selModel->selectedIndexes();
4985 if (!list.isEmpty() )
4987 TreeItem *ti = getItem (list.first() );
4988 TreeItem::Type type=ti->getType();
4989 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4990 return (BranchItem*)ti;
4995 ImageItem* VymModel::getSelectedImage()
4997 QModelIndexList list=selModel->selectedIndexes();
4998 if (!list.isEmpty())
5000 TreeItem *ti=getItem (list.first());
5001 if (ti && ti->getType()==TreeItem::Image)
5002 return (ImageItem*)ti;
5007 AttributeItem* VymModel::getSelectedAttribute()
5009 QModelIndexList list=selModel->selectedIndexes();
5010 if (!list.isEmpty() )
5012 TreeItem *ti = getItem (list.first() );
5013 TreeItem::Type type=ti->getType();
5014 if (type ==TreeItem::Attribute)
5015 return (AttributeItem*)ti;
5020 TreeItem* VymModel::getSelectedItem()
5022 QModelIndexList list=selModel->selectedIndexes();
5023 if (!list.isEmpty() )
5024 return getItem (list.first() );
5029 QModelIndex VymModel::getSelectedIndex()
5031 QModelIndexList list=selModel->selectedIndexes();
5032 if (list.isEmpty() )
5033 return QModelIndex();
5035 return list.first();
5038 QString VymModel::getSelectString ()
5040 return getSelectString (getSelectedItem());
5043 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5045 if (!lmo) return QString();
5046 return getSelectString (lmo->getTreeItem() );
5049 QString VymModel::getSelectString (TreeItem *ti)
5053 switch (ti->getType())
5055 case TreeItem::MapCenter: s="mc:"; break;
5056 case TreeItem::Branch: s="bo:";break;
5057 case TreeItem::Image: s="fi:";break;
5058 case TreeItem::Attribute: s="ai:";break;
5059 case TreeItem::XLink: s="xl:";break;
5061 s="unknown type in VymModel::getSelectString()";
5064 s= s + QString("%1").arg(ti->num());
5066 // call myself recursively
5067 s= getSelectString(ti->parent()) +","+s;