1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
18 #include "warningdialog.h"
19 #include "xlinkitem.h"
20 #include "xml-freemind.h"
26 extern Main *mainWindow;
27 extern QDBusConnection dbusConnection;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
33 extern FlagRow *standardFlagsMaster;
35 extern QString clipboardDir;
36 extern QString clipboardFile;
37 extern bool clipboardEmpty;
39 extern ImageIO imageIO;
41 extern QString vymName;
42 extern QString vymVersion;
43 extern QDir vymBaseDir;
45 extern QDir lastImageDir;
46 extern QDir lastFileDir;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 //cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 //cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 selModel->clearSelection();
73 while (rootItem->childCount() >0)
74 deleteItem (rootItem->getChildNum(0) );
77 void VymModel::init ()
82 // Also no scene yet (should not be needed anyway) FIXME-3 VM
95 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
96 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
97 mainWindow->updateHistory (undoSet);
100 makeTmpDirectories();
105 fileName=tr("unnamed");
107 blockReposition=false;
108 blockSaveState=false;
110 autosaveTimer=new QTimer (this);
111 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
113 fileChangedTimer=new QTimer (this);
114 fileChangedTimer->start(3000);
115 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
120 selectionBlocked=false;
125 // animations // FIXME-3 switch to new animation system
126 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
127 animationTicks=settings.readNumEntry("/animation/ticks",10);
128 animationInterval=settings.readNumEntry("/animation/interval",50);
130 animationTimer=new QTimer (this);
131 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
134 defLinkColor=QColor (0,0,255);
135 defXLinkColor=QColor (180,180,180);
136 linkcolorhint=LinkableMapObj::DefaultColor;
137 linkstyle=LinkableMapObj::PolyParabel;
139 defXLinkColor=QColor (230,230,230);
141 hidemode=TreeItem::HideNone;
147 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
149 //Initialize DBUS object
150 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
151 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
152 qWarning ("VymModel: Couldn't register DBUS object!");
155 void VymModel::makeTmpDirectories()
157 // Create unique temporary directories
158 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
159 histPath = tmpMapDir+"/history";
165 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
170 bool VymModel::isRepositionBlocked()
172 return blockReposition;
175 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
177 //cout << "VM::updateActions \n";
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
199 case LinkableMapObj::Line:
202 case LinkableMapObj::Parabel:
205 case LinkableMapObj::PolyLine:
209 ls="StylePolyParabel";
213 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
215 if (linkcolorhint==LinkableMapObj::HeadingColor)
216 colhint=xml.attribut("linkColorHint","HeadingColor");
218 QString mapAttr=xml.attribut("version",vymVersion);
220 mapAttr+= xml.attribut("author",author) +
221 xml.attribut("comment",comment) +
222 xml.attribut("date",getDate()) +
223 xml.attribut("branchCount", QString().number(branchCount())) +
224 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
226 xml.attribut("linkStyle", ls ) +
227 xml.attribut("linkColor", defLinkColor.name() ) +
228 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
229 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
231 s+=xml.beginElement("vymmap",mapAttr);
234 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
235 standardFlagsMaster->resetUsedCounter();
237 // Build xml recursivly
239 // Save all mapcenters as complete map, if saveSel not set
240 s+=saveTreeToDir(tmpdir,prefix,offset);
243 switch (saveSel->getType())
245 case TreeItem::Branch:
247 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
249 case TreeItem::MapCenter:
251 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
253 case TreeItem::Image:
255 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
258 // other types shouldn't be safed directly...
263 // Save local settings
264 s+=settings.getDataXML (destPath);
267 if (getSelectedItem() && !saveSel )
268 s+=xml.valueElement("select",getSelectString());
271 s+=xml.endElement("vymmap");
273 //cout << s.toStdString() << endl;
275 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
279 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
283 for (int i=0; i<rootItem->branchCount(); i++)
284 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
288 void VymModel::setFilePath(QString fpath, QString destname)
290 if (fpath.isEmpty() || fpath=="")
297 filePath=fpath; // becomes absolute path
298 fileName=fpath; // gets stripped of path
299 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
301 // If fpath is not an absolute path, complete it
302 filePath=QDir(fpath).absPath();
303 fileDir=filePath.left (1+filePath.findRev ("/"));
305 // Set short name, too. Search from behind:
306 int i=fileName.findRev("/");
307 if (i>=0) fileName=fileName.remove (0,i+1);
309 // Forget the .vym (or .xml) for name of map
310 mapName=fileName.left(fileName.findRev(".",-1,true) );
314 void VymModel::setFilePath(QString fpath)
316 setFilePath (fpath,fpath);
319 QString VymModel::getFilePath()
324 QString VymModel::getFileName()
329 QString VymModel::getMapName()
334 QString VymModel::getDestPath()
339 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
341 ErrorCode err=success;
343 parseBaseHandler *handler;
347 case VymMap: handler=new parseVYMHandler; break;
348 case FreemindMap : handler=new parseFreemindHandler; break;
350 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
351 "Unknown FileType in VymModel::load()");
355 bool zipped_org=zipped;
359 selModel->clearSelection();
360 // FIXME-2 VM not needed??? model->setMapEditor(this);
361 // (map state is set later at end of load...)
364 BranchItem *bi=getSelectedBranch();
365 if (!bi) return aborted;
366 if (lmode==ImportAdd)
367 saveStateChangingPart(
370 QString("addMapInsert (%1)").arg(fname),
371 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
373 saveStateChangingPart(
376 QString("addMapReplace(%1)").arg(fname),
377 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
381 // Create temporary directory for packing
383 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
386 QMessageBox::critical( 0, tr( "Critical Load Error" ),
387 tr("Couldn't create temporary directory before load\n"));
392 err=unzipDir (tmpZipDir,fname);
402 // Look for mapname.xml
403 xmlfile= fname.left(fname.findRev(".",-1,true));
404 xmlfile=xmlfile.section( '/', -1 );
405 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
406 if (!mfile.exists() )
408 // mapname.xml does not exist, well,
409 // maybe someone renamed the mapname.vym file...
410 // Try to find any .xml in the toplevel
411 // directory of the .vym file
412 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
413 if (flist.count()==1)
415 // Only one entry, take this one
416 xmlfile=tmpZipDir + "/"+flist.first();
419 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
420 *it=tmpZipDir + "/" + *it;
421 // TODO Multiple entries, load all (but only the first one into this ME)
422 //mainWindow->fileLoadFromTmp (flist);
423 //returnCode=1; // Silently forget this attempt to load
424 qWarning ("MainWindow::load (fn) multimap found...");
427 if (flist.isEmpty() )
429 QMessageBox::critical( 0, tr( "Critical Load Error" ),
430 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
433 } //file doesn't exist
435 xmlfile=mfile.name();
438 QFile file( xmlfile);
440 // I am paranoid: file should exist anyway
441 // according to check in mainwindow.
444 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
445 tr(QString("Couldn't open map %1").arg(file.name())));
449 bool blockSaveStateOrg=blockSaveState;
450 blockReposition=true;
452 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
453 QXmlInputSource source( file);
454 QXmlSimpleReader reader;
455 reader.setContentHandler( handler );
456 reader.setErrorHandler( handler );
457 handler->setModel ( this);
460 // We need to set the tmpDir in order to load files with rel. path
465 tmpdir=fname.left(fname.findRev("/",-1));
466 handler->setTmpDir (tmpdir);
467 handler->setInputFile (file.name());
468 handler->setLoadMode (lmode);
469 bool ok = reader.parse( source );
470 blockReposition=false;
471 blockSaveState=blockSaveStateOrg;
472 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
476 reposition(); // FIXME-2 VM reposition the view instead...
477 emitSelectionChanged();
483 autosaveTimer->stop();
486 // Reset timestamp to check for later updates of file
487 fileChangedTime=QFileInfo (destPath).lastModified();
490 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
491 tr( handler->errorProtocol() ) );
493 // Still return "success": the map maybe at least
494 // partially read by the parser
499 removeDir (QDir(tmpZipDir));
501 // Restore original zip state
508 ErrorCode VymModel::save (const SaveMode &savemode)
512 QString safeFilePath;
514 ErrorCode err=success;
518 mapFileName=mapName+".xml";
520 // use name given by user, even if he chooses .doc
521 mapFileName=fileName;
523 // Look, if we should zip the data:
526 QMessageBox mb( vymName,
527 tr("The map %1\ndid not use the compressed "
528 "vym file format.\nWriting it uncompressed will also write images \n"
529 "and flags and thus may overwrite files in the "
530 "given directory\n\nDo you want to write the map").arg(filePath),
531 QMessageBox::Warning,
532 QMessageBox::Yes | QMessageBox::Default,
534 QMessageBox::Cancel | QMessageBox::Escape);
535 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
536 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
537 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
540 case QMessageBox::Yes:
541 // save compressed (default file format)
544 case QMessageBox::No:
548 case QMessageBox::Cancel:
555 // First backup existing file, we
556 // don't want to add to old zip archives
560 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
562 QString backupFileName(destPath + "~");
563 QFile backupFile(backupFileName);
564 if (backupFile.exists() && !backupFile.remove())
566 QMessageBox::warning(0, tr("Save Error"),
567 tr("%1\ncould not be removed before saving").arg(backupFileName));
569 else if (!f.rename(backupFileName))
571 QMessageBox::warning(0, tr("Save Error"),
572 tr("%1\ncould not be renamed before saving").arg(destPath));
579 // Create temporary directory for packing
581 tmpZipDir=makeTmpDir (ok,"vym-zip");
584 QMessageBox::critical( 0, tr( "Critical Load Error" ),
585 tr("Couldn't create temporary directory before save\n"));
589 safeFilePath=filePath;
590 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
593 // Create mapName and fileDir
594 makeSubDirs (fileDir);
597 if (savemode==CompleteMap || selModel->selection().isEmpty())
600 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
603 autosaveTimer->stop();
608 if (selectionType()==TreeItem::Image)
611 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
612 // TODO take care of multiselections
615 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
618 qWarning ("ME::saveStringToDisk failed!");
624 if (err==success) err=zipDir (tmpZipDir,destPath);
627 removeDir (QDir(tmpZipDir));
629 // Restore original filepath outside of tmp zip dir
630 setFilePath (safeFilePath);
634 fileChangedTime=QFileInfo (destPath).lastModified();
638 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
640 QString pathDir=path.left(path.findRev("/"));
646 // We need to parse saved XML data
647 parseVYMHandler handler;
648 QXmlInputSource source( file);
649 QXmlSimpleReader reader;
650 reader.setContentHandler( &handler );
651 reader.setErrorHandler( &handler );
652 handler.setModel ( this);
653 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
654 if (undoSel.isEmpty())
658 handler.setLoadMode (NewMap);
662 handler.setLoadMode (ImportReplace);
664 blockReposition=true;
665 bool ok = reader.parse( source );
666 blockReposition=false;
669 // This should never ever happen
670 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
671 handler.errorProtocol());
674 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
677 bool VymModel::addMapInsertInt (const QString &path)
679 QString pathDir=path.left(path.findRev("/"));
685 // We need to parse saved XML data
686 parseVYMHandler handler;
687 QXmlInputSource source( file);
688 QXmlSimpleReader reader;
689 reader.setContentHandler( &handler );
690 reader.setErrorHandler( &handler );
691 handler.setModel (this);
692 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
693 handler.setLoadMode (ImportAdd);
694 blockReposition=true;
695 bool ok = reader.parse( source );
696 blockReposition=false;
697 if ( ok ) return true;
699 // This should never ever happen
700 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
701 handler.errorProtocol());
704 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
708 bool VymModel::addMapInsertInt (const QString &path, int pos)
710 BranchItem *selbi=getSelectedBranch();
713 if (addMapInsertInt (path))
715 if (selbi->depth()>0)
716 relinkBranch (selbi->getLastBranch(), selbi,pos);
720 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
724 qWarning ("ME::addMapInsertInt nothing selected");
728 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
730 ImageItem *ii=createImage(dst);
740 void VymModel::loadFloatImage ()
742 BranchItem *selbi=getSelectedBranch();
746 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
747 fd->setMode (Q3FileDialog::ExistingFiles);
748 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
749 ImagePreview *p =new ImagePreview (fd);
750 fd->setContentsPreviewEnabled( TRUE );
751 fd->setContentsPreview( p, p );
752 fd->setPreviewMode( Q3FileDialog::Contents );
753 fd->setCaption(vymName+" - " +tr("Load image"));
754 fd->setDir (lastImageDir);
757 if ( fd->exec() == QDialog::Accepted )
759 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
760 lastImageDir=QDir (fd->dirPath());
763 for (int j=0; j<fd->selectedFiles().count(); j++)
765 s=fd->selectedFiles().at(j);
766 ii=loadFloatImageInt (selbi,s);
767 //FIXME-3 check savestate for loadImage
773 QString ("loadImage (%1)").arg(s ),
774 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
777 // TODO loadFIO error handling
778 qWarning ("Failed to load "+s);
786 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
791 void VymModel::saveFloatImage ()
793 ImageItem *ii=getSelectedImage();
796 QFileDialog *fd=new QFileDialog( NULL);
797 fd->setFilters (imageIO.getFilters());
798 fd->setCaption(vymName+" - " +tr("Save image"));
799 fd->setFileMode( QFileDialog::AnyFile );
800 fd->setDirectory (lastImageDir);
801 // fd->setSelection (fio->getOriginalFilename());
805 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
807 fn=fd->selectedFiles().at(0);
808 if (QFile (fn).exists() )
810 QMessageBox mb( vymName,
811 tr("The file %1 exists already.\n"
812 "Do you want to overwrite it?").arg(fn),
813 QMessageBox::Warning,
814 QMessageBox::Yes | QMessageBox::Default,
815 QMessageBox::Cancel | QMessageBox::Escape,
816 QMessageBox::NoButton );
818 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
819 mb.setButtonText( QMessageBox::No, tr("Cancel"));
822 case QMessageBox::Yes:
825 case QMessageBox::Cancel:
832 saveFloatImageInt (ii,fd->selectedFilter(),fn );
839 void VymModel::importDirInt(BranchItem *dst, QDir d)
841 BranchItem *selbi=getSelectedBranch();
845 // Traverse directories
846 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
847 QFileInfoList list = d.entryInfoList();
850 for (int i = 0; i < list.size(); ++i)
853 if (fi.fileName() != "." && fi.fileName() != ".." )
855 bi=addNewBranchInt(dst,-2);
856 bi->setHeading (fi.fileName() ); // FIXME-3 check this
857 bi->setHeadingColor (QColor("blue"));
859 if ( !d.cd(fi.fileName()) )
860 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
863 // Recursively add subdirs
870 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
871 list = d.entryInfoList();
873 for (int i = 0; i < list.size(); ++i)
876 bi=addNewBranchInt (dst,-2);
877 bi->setHeading (fi.fileName() );
878 bi->setHeadingColor (QColor("black"));
879 if (fi.fileName().right(4) == ".vym" )
880 bi->setVymLink (fi.filePath());
885 void VymModel::importDirInt (const QString &s)
887 BranchItem *selbi=getSelectedBranch();
890 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
893 importDirInt (selbi,d);
897 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
899 BranchItem *selbi=getSelectedBranch();
903 filters <<"VYM map (*.vym)";
904 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
905 fd->setMode (QFileDialog::DirectoryOnly);
906 fd->setFilters (filters);
907 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
911 if ( fd->exec() == QDialog::Accepted )
913 importDirInt (fd->selectedFile() );
915 //FIXME-3 VM needed? scene()->update();
921 void VymModel::autosave()
926 cout << "VymModel::autosave rejected due to missing filePath\n";
929 QDateTime now=QDateTime().currentDateTime();
931 // Disable autosave, while we have gone back in history
932 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
933 if (redosAvail>0) return;
935 // Also disable autosave for new map without filename
936 if (filePath.isEmpty()) return;
939 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
941 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
942 mainWindow->fileSave (this);
945 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
950 void VymModel::fileChanged()
952 // Check if file on disk has changed meanwhile
953 if (!filePath.isEmpty())
955 QDateTime tmod=QFileInfo (filePath).lastModified();
956 if (tmod>fileChangedTime)
958 // FIXME-2 VM switch to current mapeditor and finish lineedits...
959 QMessageBox mb( vymName,
960 tr("The file of the map on disk has changed:\n\n"
961 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
962 QMessageBox::Question,
964 QMessageBox::Cancel | QMessageBox::Default,
965 QMessageBox::NoButton );
967 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
968 mb.setButtonText( QMessageBox::No, tr("Ignore"));
971 case QMessageBox::Yes:
973 load (filePath,NewMap,fileType);
974 case QMessageBox::Cancel:
975 fileChangedTime=tmod; // allow autosave to overwrite newer file!
981 bool VymModel::isDefault()
986 void VymModel::makeDefault()
992 bool VymModel::hasChanged()
997 void VymModel::setChanged()
1000 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1004 latestAddedItem=NULL;
1008 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1010 if (!lmo || !lmo->getTreeItem() ) return QString();
1011 return getObjectName (lmo->getTreeItem() );
1015 QString VymModel::getObjectName (TreeItem *ti)
1018 if (!ti) return QString("Error: NULL has no name!");
1020 if (s=="") s="unnamed";
1022 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1025 void VymModel::redo()
1027 // Can we undo at all?
1028 if (redosAvail<1) return;
1030 bool blockSaveStateOrg=blockSaveState;
1031 blockSaveState=true;
1035 if (undosAvail<stepsTotal) undosAvail++;
1037 if (curStep>stepsTotal) curStep=1;
1038 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1039 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1040 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1041 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1042 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1043 QString version=undoSet.readEntry ("/history/version");
1045 /* TODO Maybe check for version, if we save the history
1046 if (!checkVersion(version))
1047 QMessageBox::warning(0,tr("Warning"),
1048 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1051 // Find out current undo directory
1052 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1056 cout << "VymModel::redo() begin\n";
1057 cout << " undosAvail="<<undosAvail<<endl;
1058 cout << " redosAvail="<<redosAvail<<endl;
1059 cout << " curStep="<<curStep<<endl;
1060 cout << " ---------------------------"<<endl;
1061 cout << " comment="<<comment.toStdString()<<endl;
1062 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1063 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1064 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1065 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1066 cout << " ---------------------------"<<endl<<endl;
1069 // select object before redo
1070 if (!redoSelection.isEmpty())
1071 select (redoSelection);
1076 parseAtom (redoCommand,noErr,errMsg);
1078 blockSaveState=blockSaveStateOrg;
1080 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1081 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1082 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1083 undoSet.writeSettings(histPath);
1085 mainWindow->updateHistory (undoSet);
1088 /* TODO remove testing
1089 cout << "ME::redo() end\n";
1090 cout << " undosAvail="<<undosAvail<<endl;
1091 cout << " redosAvail="<<redosAvail<<endl;
1092 cout << " curStep="<<curStep<<endl;
1093 cout << " ---------------------------"<<endl<<endl;
1099 bool VymModel::isRedoAvailable()
1101 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1107 void VymModel::undo()
1109 // Can we undo at all?
1110 if (undosAvail<1) return;
1112 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1114 bool blockSaveStateOrg=blockSaveState;
1115 blockSaveState=true;
1117 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1118 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1119 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1120 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1121 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1122 QString version=undoSet.readEntry ("/history/version");
1124 /* TODO Maybe check for version, if we save the history
1125 if (!checkVersion(version))
1126 QMessageBox::warning(0,tr("Warning"),
1127 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1130 // Find out current undo directory
1131 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1133 // select object before undo
1134 if (!select (undoSelection))
1136 qWarning ("VymModel::undo() Could not select object for undo");
1143 cout << "VymModel::undo() begin\n";
1144 cout << " undosAvail="<<undosAvail<<endl;
1145 cout << " redosAvail="<<redosAvail<<endl;
1146 cout << " curStep="<<curStep<<endl;
1147 cout << " ---------------------------"<<endl;
1148 cout << " comment="<<comment.toStdString()<<endl;
1149 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1150 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1151 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1152 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1153 cout << " ---------------------------"<<endl<<endl;
1158 parseAtom (undoCommand,noErr,errMsg);
1162 if (curStep<1) curStep=stepsTotal;
1166 blockSaveState=blockSaveStateOrg;
1168 cout << "VymModel::undo() end\n";
1169 cout << " undosAvail="<<undosAvail<<endl;
1170 cout << " redosAvail="<<redosAvail<<endl;
1171 cout << " curStep="<<curStep<<endl;
1172 cout << " ---------------------------"<<endl<<endl;
1175 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1176 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1177 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1178 undoSet.writeSettings(histPath);
1180 mainWindow->updateHistory (undoSet);
1182 //emitSelectionChanged();
1185 bool VymModel::isUndoAvailable()
1187 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1193 void VymModel::gotoHistoryStep (int i)
1195 // Restore variables
1196 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1197 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1199 if (i<0) i=undosAvail+redosAvail;
1201 // Clicking above current step makes us undo things
1204 for (int j=0; j<undosAvail-i; j++) undo();
1207 // Clicking below current step makes us redo things
1209 for (int j=undosAvail; j<i; j++)
1211 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1215 // And ignore clicking the current row ;-)
1219 QString VymModel::getHistoryPath()
1221 QString histName(QString("history-%1").arg(curStep));
1222 return (tmpMapDir+"/"+histName);
1225 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1227 sendData(redoCom); //FIXME-3 testing
1232 if (blockSaveState) return;
1234 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1236 // Find out current undo directory
1237 if (undosAvail<stepsTotal) undosAvail++;
1239 if (curStep>stepsTotal) curStep=1;
1241 QString backupXML="";
1242 QString histDir=getHistoryPath();
1243 QString bakMapPath=histDir+"/map.xml";
1245 // Create histDir if not available
1248 makeSubDirs (histDir);
1250 // Save depending on how much needs to be saved
1252 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1254 QString undoCommand="";
1255 if (savemode==UndoCommand)
1257 undoCommand=undoCom;
1259 else if (savemode==PartOfMap )
1261 undoCommand=undoCom;
1262 undoCommand.replace ("PATH",bakMapPath);
1266 if (!backupXML.isEmpty())
1267 // Write XML Data to disk
1268 saveStringToDisk (bakMapPath,backupXML);
1270 // We would have to save all actions in a tree, to keep track of
1271 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1274 // Write the current state to disk
1275 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1276 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1277 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1278 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1279 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1280 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1281 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1282 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1283 undoSet.setEntry (QString("/history/version"),vymVersion);
1284 undoSet.writeSettings(histPath);
1288 // TODO remove after testing
1289 //cout << " into="<< histPath.toStdString()<<endl;
1290 cout << " stepsTotal="<<stepsTotal<<
1291 ", undosAvail="<<undosAvail<<
1292 ", redosAvail="<<redosAvail<<
1293 ", curStep="<<curStep<<endl;
1294 cout << " ---------------------------"<<endl;
1295 cout << " comment="<<comment.toStdString()<<endl;
1296 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1297 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1298 cout << " redoCom="<<redoCom.toStdString()<<endl;
1299 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1300 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1301 cout << " ---------------------------"<<endl;
1304 mainWindow->updateHistory (undoSet);
1310 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1312 // save the selected part of the map, Undo will replace part of map
1313 QString undoSelection="";
1315 undoSelection=getSelectString(undoSel);
1317 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1318 QString redoSelection="";
1320 redoSelection=getSelectString(undoSel);
1322 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1325 saveState (PartOfMap,
1326 undoSelection, "addMapReplace (\"PATH\")",
1332 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1336 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1339 QString undoSelection;
1340 QString redoSelection=getSelectString(redoSel);
1341 if (redoSel->getType()==TreeItem::Branch)
1343 undoSelection=getSelectString (redoSel->parent());
1344 // save the selected branch of the map, Undo will insert part of map
1345 saveState (PartOfMap,
1346 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1347 redoSelection, "delete ()",
1351 if (redoSel->getType()==TreeItem::MapCenter)
1353 // save the selected branch of the map, Undo will insert part of map
1354 saveState (PartOfMap,
1355 undoSelection, QString("addMapInsert (\"PATH\")"),
1356 redoSelection, "delete ()",
1363 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1365 // "Normal" savestate: save commands, selections and comment
1366 // so just save commands for undo and redo
1367 // and use current selection
1369 QString redoSelection="";
1370 if (redoSel) redoSelection=getSelectString(redoSel);
1371 QString undoSelection="";
1372 if (undoSel) undoSelection=getSelectString(undoSel);
1374 saveState (UndoCommand,
1381 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1383 // "Normal" savestate: save commands, selections and comment
1384 // so just save commands for undo and redo
1385 // and use current selection
1386 saveState (UndoCommand,
1393 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1395 // "Normal" savestate applied to model (no selection needed):
1396 // save commands and comment
1397 saveState (UndoCommand,
1405 QGraphicsScene* VymModel::getScene ()
1410 TreeItem* VymModel::findBySelectString(QString s)
1412 if (s.isEmpty() ) return NULL;
1414 // Old maps don't have multiple mapcenters and don't save full path
1415 if (s.left(2) !="mc")
1418 QStringList parts=s.split (",");
1421 TreeItem *ti=rootItem;
1423 while (!parts.isEmpty() )
1425 typ=parts.first().left(2);
1426 n=parts.first().right(parts.first().length() - 3).toInt();
1427 parts.removeFirst();
1428 if (typ=="mc" || typ=="bo")
1429 ti=ti->getBranchNum (n);
1431 ti=ti->getImageNum (n);
1433 ti=ti->getAttributeNum (n);
1435 ti=ti->getXLinkNum (n);
1436 if(!ti) return NULL;
1441 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1443 BranchItem *cur=NULL;
1444 BranchItem *prev=NULL;
1445 nextBranch(cur,prev);
1448 if (s==cur->getID() ) return cur;
1449 nextBranch(cur,prev);
1454 //////////////////////////////////////////////
1456 //////////////////////////////////////////////
1457 void VymModel::setVersion (const QString &s)
1462 void VymModel::setAuthor (const QString &s)
1465 QString ("setMapAuthor (\"%1\")").arg(author),
1466 QString ("setMapAuthor (\"%1\")").arg(s),
1467 QString ("Set author of map to \"%1\"").arg(s)
1472 QString VymModel::getAuthor()
1477 void VymModel::setComment (const QString &s)
1480 QString ("setMapComment (\"%1\")").arg(comment),
1481 QString ("setMapComment (\"%1\")").arg(s),
1482 QString ("Set comment of map")
1487 QString VymModel::getComment ()
1492 QString VymModel::getDate ()
1494 return QDate::currentDate().toString ("yyyy-MM-dd");
1497 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1500 BranchItem *cur=NULL;
1501 BranchItem *prev=NULL;
1502 nextBranch(cur,prev);
1506 nextBranch(cur,prev);
1511 void VymModel::setSortFilter (const QString &s)
1514 emit (sortFilterChanged (sortFilter));
1517 QString VymModel::getSortFilter ()
1522 void VymModel::setHeading(const QString &s)
1524 BranchItem *selbi=getSelectedBranch();
1529 "setHeading (\""+selbi->getHeading()+"\")",
1531 "setHeading (\""+s+"\")",
1532 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1533 selbi->setHeading(s );
1534 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1536 emitSelectionChanged();
1540 QString VymModel::getHeading()
1542 TreeItem *selti=getSelectedItem();
1544 return selti->getHeading();
1549 void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here)
1551 TreeItem *selti=getSelectedItem();
1555 emitNoteHasChanged(selti);
1559 QString VymModel::getNote()
1561 TreeItem *selti=getSelectedItem();
1563 return selti->getNote();
1568 BranchItem* VymModel::findText (QString s, bool cs)
1570 if (!s.isEmpty() && s!=findString)
1576 QTextDocument::FindFlags flags=0;
1577 if (cs) flags=QTextDocument::FindCaseSensitively;
1580 { // Nothing found or new find process
1582 // nothing found, start again
1586 nextBranch (findCurrent,findPrevious);
1588 bool searching=true;
1589 bool foundNote=false;
1590 while (searching && !EOFind)
1594 // Searching in Note
1595 if (findCurrent->getNote().contains(findString,cs))
1597 select (findCurrent);
1599 if (getSelectedBranch()!=itFind)
1602 emitShowSelection();
1605 if (textEditor->findText(findString,flags))
1611 // Searching in Heading
1612 if (searching && findCurrent->getHeading().contains (findString,cs) )
1614 select(findCurrent);
1620 if (!nextBranch(findCurrent,findPrevious) )
1623 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1626 return getSelectedBranch();
1631 void VymModel::findReset()
1632 { // Necessary if text to find changes during a find process
1639 void VymModel::emitShowFindWidget()
1641 emit (showFindWidget());
1644 void VymModel::setScene (QGraphicsScene *s)
1649 void VymModel::setURL(const QString &url)
1651 TreeItem *selti=getSelectedItem();
1654 QString oldurl=selti->getURL();
1655 selti->setURL (url);
1658 QString ("setURL (\"%1\")").arg(oldurl),
1660 QString ("setURL (\"%1\")").arg(url),
1661 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1664 emitDataHasChanged (selti);
1665 emitShowSelection();
1669 QString VymModel::getURL()
1671 TreeItem *selti=getSelectedItem();
1673 return selti->getURL();
1678 QStringList VymModel::getURLs()
1681 BranchItem *selbi=getSelectedBranch();
1682 BranchItem *cur=selbi;
1683 BranchItem *prev=NULL;
1686 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1687 cur=nextBranch (cur,prev,true,selbi);
1693 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1695 BranchItem *bi=getSelectedBranch();
1698 BranchObj *bo=(BranchObj*)(bi->getLMO());
1701 QString s=bo->getFrameTypeName();
1702 bo->setFrameType (t);
1703 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1704 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1706 bo->updateLinkGeometry();
1711 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1713 BranchItem *bi=getSelectedBranch();
1716 BranchObj *bo=(BranchObj*)(bi->getLMO());
1719 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1720 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1721 bo->setFrameType (s);
1723 bo->updateLinkGeometry();
1728 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1731 BranchItem *bi=getSelectedBranch();
1734 BranchObj *bo=(BranchObj*)(bi->getLMO());
1737 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1738 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1739 bo->setFramePenColor (c);
1744 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1746 BranchItem *bi=getSelectedBranch();
1749 BranchObj *bo=(BranchObj*)(bi->getLMO());
1752 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1753 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1754 bo->setFrameBrushColor (c);
1759 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1761 BranchItem *bi=getSelectedBranch();
1764 BranchObj *bo=(BranchObj*)(bi->getLMO());
1767 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1768 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1769 bo->setFramePadding (i);
1771 bo->updateLinkGeometry();
1776 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1778 BranchItem *bi=getSelectedBranch();
1781 BranchObj *bo=(BranchObj*)(bi->getLMO());
1784 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1785 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1786 bo->setFrameBorderWidth (i);
1788 bo->updateLinkGeometry();
1793 void VymModel::setIncludeImagesVer(bool b)
1795 BranchItem *bi=getSelectedBranch();
1798 QString u= b ? "false" : "true";
1799 QString r=!b ? "false" : "true";
1803 QString("setIncludeImagesVertically (%1)").arg(u),
1805 QString("setIncludeImagesVertically (%1)").arg(r),
1806 QString("Include images vertically in %1").arg(getObjectName(bi))
1808 bi->setIncludeImagesVer(b);
1809 emitDataHasChanged ( bi);
1814 void VymModel::setIncludeImagesHor(bool b)
1816 BranchItem *bi=getSelectedBranch();
1819 QString u= b ? "false" : "true";
1820 QString r=!b ? "false" : "true";
1824 QString("setIncludeImagesHorizontally (%1)").arg(u),
1826 QString("setIncludeImagesHorizontally (%1)").arg(r),
1827 QString("Include images horizontally in %1").arg(getObjectName(bi))
1829 bi->setIncludeImagesHor(b);
1830 emitDataHasChanged ( bi);
1835 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1837 TreeItem *ti=getSelectedItem();
1838 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1840 QString u= b ? "false" : "true";
1841 QString r=!b ? "false" : "true";
1845 QString("setHideLinkUnselected (%1)").arg(u),
1847 QString("setHideLinkUnselected (%1)").arg(r),
1848 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1850 ((MapItem*)ti)->setHideLinkUnselected(b);
1854 void VymModel::setHideExport(bool b)
1856 TreeItem *ti=getSelectedItem();
1858 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1860 ti->setHideInExport (b);
1861 QString u= b ? "false" : "true";
1862 QString r=!b ? "false" : "true";
1866 QString ("setHideExport (%1)").arg(u),
1868 QString ("setHideExport (%1)").arg(r),
1869 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1871 emitDataHasChanged(ti);
1872 emitSelectionChanged();
1875 // emitSelectionChanged();
1876 // FIXME-3 VM needed? scene()->update();
1880 void VymModel::toggleHideExport()
1882 TreeItem *selti=getSelectedItem();
1884 setHideExport ( !selti->hideInExport() );
1887 void VymModel::addTimestamp() //FIXME-3 new function, localize
1889 BranchItem *selbi=addNewBranch();
1892 QDate today=QDate::currentDate();
1894 selbi->setHeading (QString ("%1-%2-%3")
1895 .arg(today.year(),4,10,c)
1896 .arg(today.month(),2,10,c)
1897 .arg(today.day(),2,10,c));
1898 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1905 void VymModel::copy()
1907 TreeItem *selti=getSelectedItem();
1909 (selti->getType() == TreeItem::Branch ||
1910 selti->getType() == TreeItem::MapCenter ||
1911 selti->getType() == TreeItem::Image ))
1913 if (redosAvail == 0)
1916 QString s=getSelectString(selti);
1917 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1918 curClipboard=curStep;
1921 // Copy also to global clipboard, because we are at last step in history
1922 QString bakMapName(QString("history-%1").arg(curStep));
1923 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1924 copyDir (bakMapDir,clipboardDir );
1926 clipboardEmpty=false;
1932 void VymModel::pasteNoSave(const int &n)
1934 bool old=blockSaveState;
1935 blockSaveState=true;
1936 bool zippedOrg=zipped;
1937 if (redosAvail > 0 || n!=0)
1939 // Use the "historical" buffer
1940 QString bakMapName(QString("history-%1").arg(n));
1941 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1942 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1944 // Use the global buffer
1945 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1950 void VymModel::paste()
1952 BranchItem *selbi=getSelectedBranch();
1955 saveStateChangingPart(
1958 QString ("paste (%1)").arg(curClipboard),
1959 QString("Paste to %1").arg( getObjectName(selbi))
1966 void VymModel::cut()
1968 TreeItem *selti=getSelectedItem();
1969 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1977 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1979 if (bi && bi->canMoveUp())
1980 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1985 void VymModel::moveUp()
1987 BranchItem *selbi=getSelectedBranch();
1990 QString oldsel=getSelectString();
1993 getSelectString(),"moveDown ()",
1995 QString("Move up %1").arg(getObjectName(selbi)));
1999 bool VymModel::moveDown(BranchItem *bi)
2001 if (bi && bi->canMoveDown())
2002 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2007 void VymModel::moveDown()
2009 BranchItem *selbi=getSelectedBranch();
2012 QString oldsel=getSelectString();
2013 if ( moveDown(selbi))
2015 getSelectString(),"moveUp ()",
2016 oldsel,"moveDown ()",
2017 QString("Move down %1").arg(getObjectName(selbi)));
2021 void VymModel::detach()
2023 BranchItem *selbi=getSelectedBranch();
2024 if (selbi && selbi->depth()>0)
2026 // if no relPos have been set before, try to use current rel positions
2027 if (selbi->getLMO())
2028 for (int i=0; i<selbi->branchCount();++i)
2029 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2031 QString oldsel=getSelectString();
2034 BranchObj *bo=selbi->getBranchObj();
2035 if (bo) p=bo->getAbsPos();
2036 QString parsel=getSelectString(selbi->parent());
2037 if ( relinkBranch (selbi,rootItem,-1) )
2039 getSelectString (selbi),
2040 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2043 QString("Detach %1").arg(getObjectName(selbi))
2048 void VymModel::sortChildren()
2050 BranchItem* selbi=getSelectedBranch();
2053 if(selbi->branchCount()>1)
2055 saveStateChangingPart(
2056 selbi,selbi, "sortChildren ()",
2057 QString("Sort children of %1").arg(getObjectName(selbi)));
2058 selbi->sortChildren();
2060 emitShowSelection();
2065 BranchItem* VymModel::createMapCenter()
2067 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2071 BranchItem* VymModel::createBranch(BranchItem *dst)
2074 return addNewBranchInt (dst,-2);
2079 ImageItem* VymModel::createImage(BranchItem *dst)
2086 QList<QVariant> cData;
2087 cData << "new" << "undef";
2089 ImageItem *newii=new ImageItem(cData) ;
2090 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2092 emit (layoutAboutToBeChanged() );
2095 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2096 n=dst->getRowNumAppend(newii);
2097 beginInsertRows (parix,n,n);
2098 dst->appendChild (newii);
2101 emit (layoutChanged() );
2103 // save scroll state. If scrolled, automatically select
2104 // new branch in order to tmp unscroll parent...
2105 newii->createMapObj(mapScene);
2112 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2119 QList<QVariant> cData;
2120 cData << "new xLink"<<"undef";
2122 XLinkItem *newxli=new XLinkItem(cData) ;
2123 newxli->setBegin (bi);
2125 emit (layoutAboutToBeChanged() );
2128 n=bi->getRowNumAppend(newxli);
2129 beginInsertRows (parix,n,n);
2130 bi->appendChild (newxli);
2133 emit (layoutChanged() );
2135 // save scroll state. If scrolled, automatically select
2136 // new branch in order to tmp unscroll parent...
2139 newxli->createMapObj(mapScene);
2147 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2149 BranchItem *selbi=getSelectedBranch();
2152 QList<QVariant> cData;
2153 cData << "new attribute" << "undef";
2154 AttributeItem *a=new AttributeItem (cData);
2156 emit (layoutAboutToBeChanged() );
2158 QModelIndex parix=index(selbi);
2159 int n=selbi->getRowNumAppend (a);
2160 beginInsertRows (parix,n,n);
2161 selbi->appendChild (a);
2164 emit (layoutChanged() );
2172 BranchItem* VymModel::addMapCenter ()
2174 BranchItem *bi=addMapCenter (contextPos);
2176 emitShowSelection();
2181 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2182 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2187 BranchItem* VymModel::addMapCenter(QPointF absPos)
2188 // createMapCenter could then probably be merged with createBranch
2192 QModelIndex parix=index(rootItem);
2194 QList<QVariant> cData;
2195 cData << "VM:addMapCenter" << "undef";
2196 BranchItem *newbi=new BranchItem (cData,rootItem);
2197 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2198 int n=rootItem->getRowNumAppend (newbi);
2200 emit (layoutAboutToBeChanged() );
2201 beginInsertRows (parix,n,n);
2203 rootItem->appendChild (newbi);
2206 emit (layoutChanged() );
2209 newbi->setPositionMode (MapItem::Absolute);
2210 BranchObj *bo=newbi->createMapObj(mapScene);
2211 if (bo) bo->move (absPos);
2216 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2218 // Depending on pos:
2219 // -3 insert in children of parent above selection
2220 // -2 add branch to selection
2221 // -1 insert in children of parent below selection
2222 // 0..n insert in children of parent at pos
2225 QList<QVariant> cData;
2226 cData << "" << "undef";
2231 BranchItem *newbi=new BranchItem (cData);
2232 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2234 emit (layoutAboutToBeChanged() );
2240 n=parbi->getRowNumAppend (newbi);
2241 beginInsertRows (parix,n,n);
2242 parbi->appendChild (newbi);
2244 }else if (num==-1 || num==-3)
2246 // insert below selection
2247 parbi=(BranchItem*)dst->parent();
2250 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2251 beginInsertRows (parix,n,n);
2252 parbi->insertBranch(n,newbi);
2255 emit (layoutChanged() );
2257 // Set color of heading to that of parent
2258 newbi->setHeadingColor (parbi->getHeadingColor());
2260 // save scroll state. If scrolled, automatically select
2261 // new branch in order to tmp unscroll parent...
2262 newbi->createMapObj(mapScene);
2267 BranchItem* VymModel::addNewBranch(int pos)
2269 // Different meaning than num in addNewBranchInt!
2273 BranchItem *newbi=NULL;
2274 BranchItem *selbi=getSelectedBranch();
2278 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2280 newbi=addNewBranchInt (selbi,pos-2);
2288 QString ("addBranch (%1)").arg(pos),
2289 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2292 // emitSelectionChanged(); FIXME-3
2293 latestAddedItem=newbi;
2294 // In Network mode, the client needs to know where the new branch is,
2295 // so we have to pass on this information via saveState.
2296 // TODO: Get rid of this positioning workaround
2297 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2298 sendData ("selectLatestAdded ()");
2299 sendData (QString("move %1").arg(ps));
2308 BranchItem* VymModel::addNewBranchBefore()
2310 BranchItem *newbi=NULL;
2311 BranchItem *selbi=getSelectedBranch();
2312 if (selbi && selbi->getType()==TreeItem::Branch)
2313 // We accept no MapCenter here, so we _have_ a parent
2315 //QPointF p=bo->getRelPos();
2318 // add below selection
2319 newbi=addNewBranchInt (selbi,-1);
2323 //newbi->move2RelPos (p);
2325 // Move selection to new branch
2326 relinkBranch (selbi,newbi,0);
2328 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2329 QString ("Add branch before %1").arg(getObjectName(selbi)));
2331 // FIXME-3 needed? reposition();
2332 // emitSelectionChanged(); FIXME-3
2338 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2344 emit (layoutAboutToBeChanged() );
2345 BranchItem *branchpi=(BranchItem*)branch->parent();
2346 // Remove at current position
2347 int n=branch->childNum();
2348 beginRemoveRows (index(branchpi),n,n);
2349 branchpi->removeChild (n);
2352 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2354 // Append as last branch to dst
2355 if (dst->branchCount()==0)
2358 n=dst->getFirstBranch()->childNumber();
2359 beginInsertRows (index(dst),n+pos,n+pos);
2360 dst->insertBranch (pos,branch);
2363 // Correct type if necessesary
2364 if (branch->getType()==TreeItem::MapCenter)
2365 branch->setType(TreeItem::Branch);
2367 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2368 branch->updateStyles();
2370 emit (layoutChanged() );
2371 reposition(); // both for moveUp/Down and relinking
2372 if (dst->isScrolled() )
2375 branch->updateVisibility();
2384 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2388 emit (layoutAboutToBeChanged() );
2390 BranchItem *pi=(BranchItem*)(image->parent());
2391 QString oldParString=getSelectString (pi);
2392 // Remove at current position
2393 int n=image->childNum();
2394 beginRemoveRows (index(pi),n,n);
2395 pi->removeChild (n);
2399 QModelIndex dstix=index(dst);
2400 n=dst->getRowNumAppend (image);
2401 beginInsertRows (dstix,n,n+1);
2402 dst->appendChild (image);
2405 // Set new parent also for lmo
2406 if (image->getLMO() && dst->getLMO() )
2407 image->getLMO()->setParObj (dst->getLMO() );
2409 emit (layoutChanged() );
2412 QString("relinkTo (\"%1\")").arg(oldParString),
2414 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2415 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2421 void VymModel::deleteSelection()
2423 BranchItem *selbi=getSelectedBranch();
2428 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2430 TreeItem *pi=deleteItem (selbi);
2434 emitShowSelection();
2438 TreeItem *ti=getSelectedItem();
2440 { // Delete other item
2441 TreeItem *pi=ti->parent();
2443 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2445 saveStateChangingPart(
2449 QString("Delete %1").arg(getObjectName(ti))
2453 emitDataHasChanged (pi);
2456 emitShowSelection();
2457 } else if (ti->getType()==TreeItem::XLink)
2459 //FIXME-2 savestate missing
2462 qWarning ("VymmModel::deleteSelection() unknown type?!");
2466 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2469 BranchItem *selbi=getSelectedBranch();
2473 // Don't use this on mapcenter
2474 if (selbi->depth()<2) return;
2476 pi=(BranchItem*)(selbi->parent());
2477 // Check if we have childs at all to keep
2478 if (selbi->branchCount()==0)
2485 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2486 saveStateChangingPart(
2489 "deleteKeepChildren ()",
2490 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2493 QString sel=getSelectString(selbi);
2495 int pos=selbi->num();
2496 BranchItem *bi=selbi->getFirstBranch();
2499 relinkBranch (bi,pi,pos);
2500 bi=selbi->getFirstBranch();
2506 BranchObj *bo=getSelectedBranchObj();
2509 bo->move2RelPos (p);
2515 void VymModel::deleteChildren()
2518 BranchItem *selbi=getSelectedBranch();
2521 saveStateChangingPart(
2524 "deleteChildren ()",
2525 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2527 emit (layoutAboutToBeChanged() );
2529 QModelIndex ix=index (selbi);
2530 int n=selbi->branchCount()-1;
2531 beginRemoveRows (ix,0,n);
2532 removeRows (0,n+1,ix);
2534 if (selbi->isScrolled()) selbi->unScroll();
2535 emit (layoutChanged() );
2540 TreeItem* VymModel::deleteItem (TreeItem *ti)
2544 TreeItem *pi=ti->parent();
2545 QModelIndex parentIndex=index(pi);
2547 emit (layoutAboutToBeChanged() );
2549 int n=ti->childNum();
2550 beginRemoveRows (parentIndex,n,n);
2551 removeRows (n,1,parentIndex);
2555 emit (layoutChanged() );
2556 if (pi->depth()>=0) return pi;
2561 void VymModel::clearItem (TreeItem *ti)
2565 QModelIndex parentIndex=index(ti);
2566 if (!parentIndex.isValid()) return;
2568 int n=ti->childCount();
2571 emit (layoutAboutToBeChanged() );
2573 beginRemoveRows (parentIndex,0,n-1);
2574 removeRows (0,n,parentIndex);
2578 emit (layoutChanged() );
2584 bool VymModel::scrollBranch(BranchItem *bi)
2588 if (bi->isScrolled()) return false;
2589 if (bi->branchCount()==0) return false;
2590 if (bi->depth()==0) return false;
2591 if (bi->toggleScroll())
2599 QString ("%1 ()").arg(u),
2601 QString ("%1 ()").arg(r),
2602 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2604 emitDataHasChanged(bi);
2605 emitSelectionChanged();
2606 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2613 bool VymModel::unscrollBranch(BranchItem *bi)
2617 if (!bi->isScrolled()) return false;
2618 if (bi->branchCount()==0) return false;
2619 if (bi->depth()==0) return false;
2620 if (bi->toggleScroll())
2628 QString ("%1 ()").arg(u),
2630 QString ("%1 ()").arg(r),
2631 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2633 emitDataHasChanged(bi);
2634 emitSelectionChanged();
2635 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2642 void VymModel::toggleScroll()
2644 BranchItem *bi=(BranchItem*)getSelectedBranch();
2645 if (bi && bi->isBranchLikeType() )
2647 if (bi->isScrolled())
2648 unscrollBranch (bi);
2652 // saveState & reposition are called in above functions
2655 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2657 BranchItem *selbi=getSelectedBranch();
2658 BranchItem *prev=NULL;
2659 BranchItem *cur=selbi;
2662 saveStateChangingPart(
2665 QString ("unscrollChildren ()"),
2666 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2670 if (cur->isScrolled())
2672 cur->toggleScroll();
2673 emitDataHasChanged (cur);
2675 cur=nextBranch (cur,prev,true,selbi);
2682 void VymModel::emitExpandAll()
2684 emit (expandAll() );
2687 void VymModel::emitExpandOneLevel()
2689 emit (expandOneLevel () );
2692 void VymModel::emitCollapseOneLevel()
2694 emit (collapseOneLevel () );
2697 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2699 BranchItem *bi=getSelectedBranch();
2703 if (bi->isActiveStandardFlag(name))
2715 QString("%1 (\"%2\")").arg(u).arg(name),
2717 QString("%1 (\"%2\")").arg(r).arg(name),
2718 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2719 bi->toggleStandardFlag (name, master);
2721 emitSelectionChanged();
2725 void VymModel::addFloatImage (const QPixmap &img)
2727 BranchItem *selbi=getSelectedBranch();
2730 ImageItem *ii=createImage (selbi);
2732 ii->setOriginalFilename("No original filename (image added by dropevent)");
2733 QString s=getSelectString(selbi);
2734 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2735 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2737 // FIXME-3 VM needed? scene()->update();
2742 void VymModel::colorBranch (QColor c)
2744 BranchItem *selbi=getSelectedBranch();
2749 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2751 QString ("colorBranch (\"%1\")").arg(c.name()),
2752 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2754 selbi->setHeadingColor(c); // color branch
2759 void VymModel::colorSubtree (QColor c)
2761 BranchItem *selbi=getSelectedBranch();
2764 saveStateChangingPart(
2767 QString ("colorSubtree (\"%1\")").arg(c.name()),
2768 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2770 BranchItem *prev=NULL;
2771 BranchItem *cur=selbi;
2774 cur->setHeadingColor(c); // color links, color children
2775 cur=nextBranch (cur,prev,true,selbi);
2781 QColor VymModel::getCurrentHeadingColor()
2783 BranchItem *selbi=getSelectedBranch();
2784 if (selbi) return selbi->getHeadingColor();
2786 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2792 void VymModel::editURL()
2794 TreeItem *selti=getSelectedItem();
2798 QString text = QInputDialog::getText(
2799 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2800 selti->getURL(), &ok, NULL);
2802 // user entered something and pressed OK
2807 void VymModel::editLocalURL()
2809 TreeItem *selti=getSelectedItem();
2812 QStringList filters;
2813 filters <<"All files (*)";
2814 filters << tr("Text","Filedialog") + " (*.txt)";
2815 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2816 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2817 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2818 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2819 fd->setFilters (filters);
2820 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2821 fd->setDirectory (lastFileDir);
2822 if (! selti->getVymLink().isEmpty() )
2823 fd->selectFile( selti->getURL() );
2826 if ( fd->exec() == QDialog::Accepted )
2828 lastFileDir=QDir (fd->directory().path());
2829 setURL (fd->selectedFile() );
2835 void VymModel::editHeading2URL()
2837 TreeItem *selti=getSelectedItem();
2839 setURL (selti->getHeading());
2842 void VymModel::editBugzilla2URL()
2844 TreeItem *selti=getSelectedItem();
2847 QString h=selti->getHeading();
2848 QRegExp rx("^(\\d+)");
2849 if (rx.indexIn(h) !=-1)
2850 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2854 void VymModel::editFATE2URL()
2856 TreeItem *selti=getSelectedItem();
2859 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2862 "setURL (\""+selti->getURL()+"\")",
2864 "setURL (\""+url+"\")",
2865 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2867 selti->setURL (url);
2868 // FIXME-4 updateActions();
2872 void VymModel::editVymLink()
2874 BranchItem *bi=getSelectedBranch();
2877 QStringList filters;
2878 filters <<"VYM map (*.vym)";
2879 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2880 fd->setFilters (filters);
2881 fd->setCaption(vymName+" - " +tr("Link to another map"));
2882 fd->setDirectory (lastFileDir);
2883 if (! bi->getVymLink().isEmpty() )
2884 fd->selectFile( bi->getVymLink() );
2888 if ( fd->exec() == QDialog::Accepted )
2890 lastFileDir=QDir (fd->directory().path());
2893 "setVymLink (\""+bi->getVymLink()+"\")",
2895 "setVymLink (\""+fd->selectedFile()+"\")",
2896 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2898 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2903 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2905 // Internal function, no saveState needed
2906 TreeItem *selti=getSelectedItem();
2909 selti->setVymLink(s);
2911 emitDataHasChanged (selti);
2912 emitShowSelection();
2916 void VymModel::deleteVymLink()
2918 BranchItem *bi=getSelectedBranch();
2923 "setVymLink (\""+bi->getVymLink()+"\")",
2925 "setVymLink (\"\")",
2926 QString("Unset vymlink of %1").arg(getObjectName(bi))
2928 bi->setVymLink ("" );
2934 QString VymModel::getVymLink()
2936 BranchItem *bi=getSelectedBranch();
2938 return bi->getVymLink();
2944 QStringList VymModel::getVymLinks()
2947 BranchItem *selbi=getSelectedBranch();
2948 BranchItem *cur=selbi;
2949 BranchItem *prev=NULL;
2952 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2953 cur=nextBranch (cur,prev,true,selbi);
2959 void VymModel::followXLink(int i)
2962 BranchItem *selbi=getSelectedBranch();
2965 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2966 if (selbi) select (selbi);
2970 void VymModel::editXLink(int i)
2973 BranchItem *selbi=getSelectedBranch();
2976 XLinkItem *xli=selbi->getXLinkNum(i);
2979 EditXLinkDialog dia;
2981 dia.setSelection(selbi);
2982 if (dia.exec() == QDialog::Accepted)
2984 if (dia.useSettingsGlobal() )
2986 setMapDefXLinkColor (xli->getColor() );
2987 setMapDefXLinkWidth (xli->getWidth() );
2989 if (dia.deleteXLink()) deleteItem (xli);
2999 //////////////////////////////////////////////
3001 //////////////////////////////////////////////
3003 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3005 TreeItem* selti=getSelectedItem();
3006 BranchItem *selbi=getSelectedBranch();
3011 QVariant returnValue;
3013 // Split string s into command and parameters
3014 parser.parseAtom (atom);
3015 QString com=parser.getCommand();
3017 // External commands
3018 /////////////////////////////////////////////////////////////////////
3019 if (com=="addBranch")
3023 parser.setError (Aborted,"Nothing selected");
3024 } else if (! selbi )
3026 parser.setError (Aborted,"Type of selection is not a branch");
3031 if (parser.checkParCount(pl))
3033 if (parser.parCount()==0)
3037 n=parser.parInt (ok,0);
3038 if (ok ) addNewBranch (n);
3042 /////////////////////////////////////////////////////////////////////
3043 } else if (com=="addBranchBefore")
3047 parser.setError (Aborted,"Nothing selected");
3048 } else if (! selbi )
3050 parser.setError (Aborted,"Type of selection is not a branch");
3053 if (parser.parCount()==0)
3055 addNewBranchBefore ();
3058 /////////////////////////////////////////////////////////////////////
3059 } else if (com==QString("addMapCenter"))
3061 if (parser.checkParCount(2))
3063 x=parser.parDouble (ok,0);
3066 y=parser.parDouble (ok,1);
3067 if (ok) addMapCenter (QPointF(x,y));
3070 /////////////////////////////////////////////////////////////////////
3071 } else if (com==QString("addMapReplace"))
3075 parser.setError (Aborted,"Nothing selected");
3076 } else if (! selbi )
3078 parser.setError (Aborted,"Type of selection is not a branch");
3079 } else if (parser.checkParCount(1))
3081 //s=parser.parString (ok,0); // selection
3082 t=parser.parString (ok,0); // path to map
3083 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3084 addMapReplaceInt(getSelectString(selbi),t);
3086 /////////////////////////////////////////////////////////////////////
3087 } else if (com==QString("addMapInsert"))
3089 if (parser.parCount()==2)
3094 parser.setError (Aborted,"Nothing selected");
3095 } else if (! selbi )
3097 parser.setError (Aborted,"Type of selection is not a branch");
3100 t=parser.parString (ok,0); // path to map
3101 n=parser.parInt(ok,1); // position
3102 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3103 addMapInsertInt(t,n);
3105 } else if (parser.parCount()==1)
3107 t=parser.parString (ok,0); // path to map
3108 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3111 parser.setError (Aborted,"Wrong number of parameters");
3112 /////////////////////////////////////////////////////////////////////
3113 } else if (com==QString("addXLink"))
3115 if (parser.parCount()>1)
3117 s=parser.parString (ok,0); // begin
3118 t=parser.parString (ok,1); // end
3119 BranchItem *begin=(BranchItem*)findBySelectString(s);
3120 BranchItem *end=(BranchItem*)findBySelectString(t);
3123 if (begin->isBranchLikeType() && end->isBranchLikeType())
3125 XLinkItem *xl=createXLink (begin,true);
3131 parser.setError (Aborted,"Failed to create xLink");
3134 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3137 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3139 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3140 /////////////////////////////////////////////////////////////////////
3141 } else if (com=="clearFlags")
3145 parser.setError (Aborted,"Nothing selected");
3146 } else if (! selbi )
3148 parser.setError (Aborted,"Type of selection is not a branch");
3149 } else if (parser.checkParCount(0))
3151 selbi->deactivateAllStandardFlags();
3153 /////////////////////////////////////////////////////////////////////
3154 } else if (com=="colorBranch")
3158 parser.setError (Aborted,"Nothing selected");
3159 } else if (! selbi )
3161 parser.setError (Aborted,"Type of selection is not a branch");
3162 } else if (parser.checkParCount(1))
3164 QColor c=parser.parColor (ok,0);
3165 if (ok) colorBranch (c);
3167 /////////////////////////////////////////////////////////////////////
3168 } else if (com=="colorSubtree")
3172 parser.setError (Aborted,"Nothing selected");
3173 } else if (! selbi )
3175 parser.setError (Aborted,"Type of selection is not a branch");
3176 } else if (parser.checkParCount(1))
3178 QColor c=parser.parColor (ok,0);
3179 if (ok) colorSubtree (c);
3181 /////////////////////////////////////////////////////////////////////
3182 } else if (com=="copy")
3186 parser.setError (Aborted,"Nothing selected");
3187 } else if ( selectionType()!=TreeItem::Branch &&
3188 selectionType()!=TreeItem::MapCenter &&
3189 selectionType()!=TreeItem::Image )
3191 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3192 } else if (parser.checkParCount(0))
3196 /////////////////////////////////////////////////////////////////////
3197 } else if (com=="cut")
3201 parser.setError (Aborted,"Nothing selected");
3202 } else if ( selectionType()!=TreeItem::Branch &&
3203 selectionType()!=TreeItem::MapCenter &&
3204 selectionType()!=TreeItem::Image )
3206 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3207 } else if (parser.checkParCount(0))
3211 /////////////////////////////////////////////////////////////////////
3212 } else if (com=="delete")
3216 parser.setError (Aborted,"Nothing selected");
3218 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3220 parser.setError (Aborted,"Type of selection is wrong.");
3223 else if (parser.checkParCount(0))
3227 /////////////////////////////////////////////////////////////////////
3228 } else if (com=="deleteKeepChildren")
3232 parser.setError (Aborted,"Nothing selected");
3233 } else if (! selbi )
3235 parser.setError (Aborted,"Type of selection is not a branch");
3236 } else if (parser.checkParCount(0))
3238 deleteKeepChildren();
3240 /////////////////////////////////////////////////////////////////////
3241 } else if (com=="deleteChildren")
3245 parser.setError (Aborted,"Nothing selected");
3248 parser.setError (Aborted,"Type of selection is not a branch");
3249 } else if (parser.checkParCount(0))
3253 /////////////////////////////////////////////////////////////////////
3254 } else if (com=="exportAO")
3258 if (parser.parCount()>=1)
3259 // Hey, we even have a filename
3260 fname=parser.parString(ok,0);
3263 parser.setError (Aborted,"Could not read filename");
3266 exportAO (fname,false);
3268 /////////////////////////////////////////////////////////////////////
3269 } else if (com=="exportASCII")
3273 if (parser.parCount()>=1)
3274 // Hey, we even have a filename
3275 fname=parser.parString(ok,0);
3278 parser.setError (Aborted,"Could not read filename");
3281 exportASCII (fname,false);
3283 /////////////////////////////////////////////////////////////////////
3284 } else if (com=="exportImage")
3288 if (parser.parCount()>=2)
3289 // Hey, we even have a filename
3290 fname=parser.parString(ok,0);
3293 parser.setError (Aborted,"Could not read filename");
3296 QString format="PNG";
3297 if (parser.parCount()>=2)
3299 format=parser.parString(ok,1);
3301 exportImage (fname,false,format);
3303 /////////////////////////////////////////////////////////////////////
3304 } else if (com=="exportXHTML")
3308 if (parser.parCount()>=2)
3309 // Hey, we even have a filename
3310 fname=parser.parString(ok,1);
3313 parser.setError (Aborted,"Could not read filename");
3316 exportXHTML (fname,false);
3318 /////////////////////////////////////////////////////////////////////
3319 } else if (com=="exportXML")
3323 if (parser.parCount()>=2)
3324 // Hey, we even have a filename
3325 fname=parser.parString(ok,1);
3328 parser.setError (Aborted,"Could not read filename");
3331 exportXML (fname,false);
3333 /////////////////////////////////////////////////////////////////////
3334 } else if (com=="getHeading")
3338 parser.setError (Aborted,"Nothing selected");
3339 } else if (parser.checkParCount(0))
3340 returnValue=selti->getHeading();
3341 /////////////////////////////////////////////////////////////////////
3342 } else if (com=="importDir")
3346 parser.setError (Aborted,"Nothing selected");
3347 } else if (! selbi )
3349 parser.setError (Aborted,"Type of selection is not a branch");
3350 } else if (parser.checkParCount(1))
3352 s=parser.parString(ok,0);
3353 if (ok) importDirInt(s);
3355 /////////////////////////////////////////////////////////////////////
3356 } else if (com=="relinkTo")
3360 parser.setError (Aborted,"Nothing selected");
3363 if (parser.checkParCount(4))
3365 // 0 selectstring of parent
3366 // 1 num in parent (for branches)
3367 // 2,3 x,y of mainbranch or mapcenter
3368 s=parser.parString(ok,0);
3369 TreeItem *dst=findBySelectString (s);
3372 if (dst->getType()==TreeItem::Branch)
3374 // Get number in parent
3375 n=parser.parInt (ok,1);
3378 relinkBranch (selbi,(BranchItem*)dst,n);
3379 emitSelectionChanged();
3381 } else if (dst->getType()==TreeItem::MapCenter)
3383 relinkBranch (selbi,(BranchItem*)dst);
3384 // Get coordinates of mainbranch
3385 x=parser.parDouble(ok,2);
3388 y=parser.parDouble(ok,3);
3391 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3392 emitSelectionChanged();
3398 } else if ( selti->getType() == TreeItem::Image)
3400 if (parser.checkParCount(1))
3402 // 0 selectstring of parent
3403 s=parser.parString(ok,0);
3404 TreeItem *dst=findBySelectString (s);
3407 if (dst->isBranchLikeType())
3408 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3410 parser.setError (Aborted,"Destination is not a branch");
3413 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3414 /////////////////////////////////////////////////////////////////////
3415 } else if (com=="loadImage")
3419 parser.setError (Aborted,"Nothing selected");
3420 } else if (! selbi )
3422 parser.setError (Aborted,"Type of selection is not a branch");
3423 } else if (parser.checkParCount(1))
3425 s=parser.parString(ok,0);
3426 if (ok) loadFloatImageInt (selbi,s);
3428 /////////////////////////////////////////////////////////////////////
3429 } else if (com=="moveUp")
3433 parser.setError (Aborted,"Nothing selected");
3434 } else if (! selbi )
3436 parser.setError (Aborted,"Type of selection is not a branch");
3437 } else if (parser.checkParCount(0))
3441 /////////////////////////////////////////////////////////////////////
3442 } else if (com=="moveDown")
3446 parser.setError (Aborted,"Nothing selected");
3447 } else if (! selbi )
3449 parser.setError (Aborted,"Type of selection is not a branch");
3450 } else if (parser.checkParCount(0))
3454 /////////////////////////////////////////////////////////////////////
3455 } else if (com=="move")
3459 parser.setError (Aborted,"Nothing selected");
3460 } else if ( selectionType()!=TreeItem::Branch &&
3461 selectionType()!=TreeItem::MapCenter &&
3462 selectionType()!=TreeItem::Image )
3464 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3465 } else if (parser.checkParCount(2))
3467 x=parser.parDouble (ok,0);
3470 y=parser.parDouble (ok,1);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="moveRel")
3479 parser.setError (Aborted,"Nothing selected");
3480 } else if ( selectionType()!=TreeItem::Branch &&
3481 selectionType()!=TreeItem::MapCenter &&
3482 selectionType()!=TreeItem::Image )
3484 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3485 } else if (parser.checkParCount(2))
3487 x=parser.parDouble (ok,0);
3490 y=parser.parDouble (ok,1);
3491 if (ok) moveRel (x,y);
3494 /////////////////////////////////////////////////////////////////////
3495 } else if (com=="nop")
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="paste")
3502 parser.setError (Aborted,"Nothing selected");
3503 } else if (! selbi )
3505 parser.setError (Aborted,"Type of selection is not a branch");
3506 } else if (parser.checkParCount(1))
3508 n=parser.parInt (ok,0);
3509 if (ok) pasteNoSave(n);
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="qa")
3516 parser.setError (Aborted,"Nothing selected");
3517 } else if (! selbi )
3519 parser.setError (Aborted,"Type of selection is not a branch");
3520 } else if (parser.checkParCount(4))
3523 c=parser.parString (ok,0);
3526 parser.setError (Aborted,"No comment given");
3529 s=parser.parString (ok,1);
3532 parser.setError (Aborted,"First parameter is not a string");
3535 t=parser.parString (ok,2);
3538 parser.setError (Aborted,"Condition is not a string");
3541 u=parser.parString (ok,3);
3544 parser.setError (Aborted,"Third parameter is not a string");
3549 parser.setError (Aborted,"Unknown type: "+s);
3554 parser.setError (Aborted,"Unknown operator: "+t);
3559 parser.setError (Aborted,"Type of selection is not a branch");
3562 if (selbi->getHeading() == u)
3564 cout << "PASSED: " << qPrintable (c) << endl;
3567 cout << "FAILED: " << qPrintable (c) << endl;
3577 /////////////////////////////////////////////////////////////////////
3578 } else if (com=="saveImage")
3580 ImageItem *ii=getSelectedImage();
3583 parser.setError (Aborted,"No image selected");
3584 } else if (parser.checkParCount(2))
3586 s=parser.parString(ok,0);
3589 t=parser.parString(ok,1);
3590 if (ok) saveFloatImageInt (ii,t,s);
3593 /////////////////////////////////////////////////////////////////////
3594 } else if (com=="scroll")
3598 parser.setError (Aborted,"Nothing selected");
3599 } else if (! selbi )
3601 parser.setError (Aborted,"Type of selection is not a branch");
3602 } else if (parser.checkParCount(0))
3604 if (!scrollBranch (selbi))
3605 parser.setError (Aborted,"Could not scroll branch");
3607 /////////////////////////////////////////////////////////////////////
3608 } else if (com=="select")
3610 if (parser.checkParCount(1))
3612 s=parser.parString(ok,0);
3615 /////////////////////////////////////////////////////////////////////
3616 } else if (com=="selectLastBranch")
3620 parser.setError (Aborted,"Nothing selected");
3621 } else if (! selbi )
3623 parser.setError (Aborted,"Type of selection is not a branch");
3624 } else if (parser.checkParCount(0))
3626 BranchItem *bi=selbi->getLastBranch();
3628 parser.setError (Aborted,"Could not select last branch");
3629 select (bi); // FIXME-3 was selectInt
3632 /////////////////////////////////////////////////////////////////////
3633 } else /* FIXME-2 if (com=="selectLastImage")
3637 parser.setError (Aborted,"Nothing selected");
3638 } else if (! selbi )
3640 parser.setError (Aborted,"Type of selection is not a branch");
3641 } else if (parser.checkParCount(0))
3643 FloatImageObj *fio=selb->getLastFloatImage();
3645 parser.setError (Aborted,"Could not select last image");
3646 select (fio); // FIXME-3 was selectInt
3649 /////////////////////////////////////////////////////////////////////
3650 } else */ if (com=="selectLatestAdded")
3652 if (!latestAddedItem)
3654 parser.setError (Aborted,"No latest added object");
3657 if (!select (latestAddedItem))
3658 parser.setError (Aborted,"Could not select latest added object ");
3660 /////////////////////////////////////////////////////////////////////
3661 } else if (com=="setFlag")
3665 parser.setError (Aborted,"Nothing selected");
3666 } else if (! selbi )
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(1))
3671 s=parser.parString(ok,0);
3673 selbi->activateStandardFlag(s);
3675 /////////////////////////////////////////////////////////////////////
3676 } else if (com=="setFrameType")
3678 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3680 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3682 else if (parser.checkParCount(1))
3684 s=parser.parString(ok,0);
3685 if (ok) setFrameType (s);
3687 /////////////////////////////////////////////////////////////////////
3688 } else if (com=="setFramePenColor")
3690 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3692 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3694 else if (parser.checkParCount(1))
3696 QColor c=parser.parColor(ok,0);
3697 if (ok) setFramePenColor (c);
3699 /////////////////////////////////////////////////////////////////////
3700 } else if (com=="setFrameBrushColor")
3702 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3704 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3706 else if (parser.checkParCount(1))
3708 QColor c=parser.parColor(ok,0);
3709 if (ok) setFrameBrushColor (c);
3711 /////////////////////////////////////////////////////////////////////
3712 } else if (com=="setFramePadding")
3714 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3716 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3718 else if (parser.checkParCount(1))
3720 n=parser.parInt(ok,0);
3721 if (ok) setFramePadding(n);
3723 /////////////////////////////////////////////////////////////////////
3724 } else if (com=="setFrameBorderWidth")
3726 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3728 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3730 else if (parser.checkParCount(1))
3732 n=parser.parInt(ok,0);
3733 if (ok) setFrameBorderWidth (n);
3735 /////////////////////////////////////////////////////////////////////
3736 /* FIXME-2 else if (com=="setFrameType")
3740 parser.setError (Aborted,"Nothing selected");
3743 parser.setError (Aborted,"Type of selection is not a branch");
3744 } else if (parser.checkParCount(1))
3746 s=parser.parString(ok,0);
3750 /////////////////////////////////////////////////////////////////////
3752 /////////////////////////////////////////////////////////////////////
3753 } else if (com=="setHeading")
3757 parser.setError (Aborted,"Nothing selected");
3758 } else if (! selbi )
3760 parser.setError (Aborted,"Type of selection is not a branch");
3761 } else if (parser.checkParCount(1))
3763 s=parser.parString (ok,0);
3767 /////////////////////////////////////////////////////////////////////
3768 } else if (com=="setHideExport")
3772 parser.setError (Aborted,"Nothing selected");
3773 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3775 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3776 } else if (parser.checkParCount(1))
3778 b=parser.parBool(ok,0);
3779 if (ok) setHideExport (b);
3781 /////////////////////////////////////////////////////////////////////
3782 } else if (com=="setIncludeImagesHorizontally")
3786 parser.setError (Aborted,"Nothing selected");
3789 parser.setError (Aborted,"Type of selection is not a branch");
3790 } else if (parser.checkParCount(1))
3792 b=parser.parBool(ok,0);
3793 if (ok) setIncludeImagesHor(b);
3795 /////////////////////////////////////////////////////////////////////
3796 } else if (com=="setIncludeImagesVertically")
3800 parser.setError (Aborted,"Nothing selected");
3803 parser.setError (Aborted,"Type of selection is not a branch");
3804 } else if (parser.checkParCount(1))
3806 b=parser.parBool(ok,0);
3807 if (ok) setIncludeImagesVer(b);
3809 /////////////////////////////////////////////////////////////////////
3810 } else if (com=="setHideLinkUnselected")
3814 parser.setError (Aborted,"Nothing selected");
3815 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3817 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3818 } else if (parser.checkParCount(1))
3820 b=parser.parBool(ok,0);
3821 if (ok) setHideLinkUnselected(b);
3823 /////////////////////////////////////////////////////////////////////
3824 } else if (com=="setMapAuthor")
3826 if (parser.checkParCount(1))
3828 s=parser.parString(ok,0);
3829 if (ok) setAuthor (s);
3831 /////////////////////////////////////////////////////////////////////
3832 } else if (com=="setMapComment")
3834 if (parser.checkParCount(1))
3836 s=parser.parString(ok,0);
3837 if (ok) setComment(s);
3839 /////////////////////////////////////////////////////////////////////
3840 } else if (com=="setMapBackgroundColor")
3844 parser.setError (Aborted,"Nothing selected");
3845 } else if (! selbi )
3847 parser.setError (Aborted,"Type of selection is not a branch");
3848 } else if (parser.checkParCount(1))
3850 QColor c=parser.parColor (ok,0);
3851 if (ok) setMapBackgroundColor (c);
3853 /////////////////////////////////////////////////////////////////////
3854 } else if (com=="setMapDefLinkColor")
3858 parser.setError (Aborted,"Nothing selected");
3859 } else if (! selbi )
3861 parser.setError (Aborted,"Type of selection is not a branch");
3862 } else if (parser.checkParCount(1))
3864 QColor c=parser.parColor (ok,0);
3865 if (ok) setMapDefLinkColor (c);
3867 /////////////////////////////////////////////////////////////////////
3868 } else if (com=="setMapLinkStyle")
3870 if (parser.checkParCount(1))
3872 s=parser.parString (ok,0);
3873 if (ok) setMapLinkStyle(s);
3875 /////////////////////////////////////////////////////////////////////
3876 } else if (com=="setNote")
3880 parser.setError (Aborted,"Nothing selected");
3881 } else if (! selbi )
3883 parser.setError (Aborted,"Type of selection is not a branch");
3884 } else if (parser.checkParCount(1))
3886 s=parser.parString (ok,0);
3890 /////////////////////////////////////////////////////////////////////
3891 } else if (com=="setSelectionColor")
3893 if (parser.checkParCount(1))
3895 QColor c=parser.parColor (ok,0);
3896 if (ok) setSelectionColorInt (c);
3898 /////////////////////////////////////////////////////////////////////
3899 } else if (com=="setURL")
3903 parser.setError (Aborted,"Nothing selected");
3904 } else if (! selbi )
3906 parser.setError (Aborted,"Type of selection is not a branch");
3907 } else if (parser.checkParCount(1))
3909 s=parser.parString (ok,0);
3912 /////////////////////////////////////////////////////////////////////
3913 } else if (com=="setVymLink")
3917 parser.setError (Aborted,"Nothing selected");
3918 } else if (! selbi )
3920 parser.setError (Aborted,"Type of selection is not a branch");
3921 } else if (parser.checkParCount(1))
3923 s=parser.parString (ok,0);
3924 if (ok) setVymLink(s);
3926 } else if (com=="sortChildren")
3930 parser.setError (Aborted,"Nothing selected");
3931 } else if (! selbi )
3933 parser.setError (Aborted,"Type of selection is not a branch");
3934 } else if (parser.checkParCount(0))
3938 /////////////////////////////////////////////////////////////////////
3939 } else if (com=="toggleFlag")
3943 parser.setError (Aborted,"Nothing selected");
3944 } else if (! selbi )
3946 parser.setError (Aborted,"Type of selection is not a branch");
3947 } else if (parser.checkParCount(1))
3949 s=parser.parString(ok,0);
3951 selbi->toggleStandardFlag(s);
3953 /////////////////////////////////////////////////////////////////////
3954 } else if (com=="unscroll")
3958 parser.setError (Aborted,"Nothing selected");
3959 } else if (! selbi )
3961 parser.setError (Aborted,"Type of selection is not a branch");
3962 } else if (parser.checkParCount(0))
3964 if (!unscrollBranch (selbi))
3965 parser.setError (Aborted,"Could not unscroll branch");
3967 /////////////////////////////////////////////////////////////////////
3968 } else if (com=="unscrollChildren")
3972 parser.setError (Aborted,"Nothing selected");
3973 } else if (! selbi )
3975 parser.setError (Aborted,"Type of selection is not a branch");
3976 } else if (parser.checkParCount(0))
3978 unscrollChildren ();
3980 /////////////////////////////////////////////////////////////////////
3981 } else if (com=="unsetFlag")
3985 parser.setError (Aborted,"Nothing selected");
3986 } else if (! selbi )
3988 parser.setError (Aborted,"Type of selection is not a branch");
3989 } else if (parser.checkParCount(1))
3991 s=parser.parString(ok,0);
3993 selbi->deactivateStandardFlag(s);
3996 parser.setError (Aborted,"Unknown command");
3999 if (parser.errorLevel()==NoError)
4001 // setChanged(); FIXME-2 should not be called e.g. for export?!
4008 // TODO Error handling
4009 qWarning("VymModel::parseAtom: Error!");
4011 qWarning(parser.errorMessage());
4013 errorMsg=parser.errorMessage();
4018 QVariant VymModel::runScript (const QString &script)
4020 parser.setScript (script);
4025 while (parser.next() && noErr)
4027 r=parseAtom(parser.getAtom(),noErr,errMsg);
4028 if (!noErr) //FIXME-3 need dialog box here
4029 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4034 void VymModel::setExportMode (bool b)
4036 // should be called before and after exports
4037 // depending on the settings
4038 if (b && settings.value("/export/useHideExport","true")=="true")
4039 setHideTmpMode (TreeItem::HideExport);
4041 setHideTmpMode (TreeItem::HideNone);
4044 void VymModel::exportImage(QString fname, bool askName, QString format)
4048 fname=getMapName()+".png";
4055 QFileDialog *fd=new QFileDialog (NULL);
4056 fd->setCaption (tr("Export map as image"));
4057 fd->setDirectory (lastImageDir);
4058 fd->setFileMode(QFileDialog::AnyFile);
4059 fd->setFilters (imageIO.getFilters() );
4062 fl=fd->selectedFiles();
4064 format=imageIO.getType(fd->selectedFilter());
4068 setExportMode (true);
4069 QPixmap pix (mapEditor->getPixmap());
4070 pix.save(fname, format);
4071 setExportMode (false);
4075 void VymModel::exportXML(QString dir, bool askForName)
4079 dir=browseDirectory(NULL,tr("Export XML to directory"));
4080 if (dir =="" && !reallyWriteDirectory(dir) )
4084 // Hide stuff during export, if settings want this
4085 setExportMode (true);
4087 // Create subdirectories
4090 // write to directory //FIXME-4 check totalBBox here...
4091 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4094 file.setName ( dir + "/"+mapName+".xml");
4095 if ( !file.open( QIODevice::WriteOnly ) )
4097 // This should neverever happen
4098 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4102 // Write it finally, and write in UTF8, no matter what
4103 QTextStream ts( &file );
4104 ts.setEncoding (QTextStream::UnicodeUTF8);
4108 // Now write image, too
4109 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4111 setExportMode (false);
4114 void VymModel::exportAO (QString fname,bool askName)
4119 ex.setFile (mapName+".txt");
4125 //ex.addFilter ("TXT (*.txt)");
4126 ex.setDir(lastImageDir);
4127 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4132 setExportMode(true);
4134 setExportMode(false);
4138 void VymModel::exportASCII(QString fname,bool askName)
4143 ex.setFile (mapName+".txt");
4149 //ex.addFilter ("TXT (*.txt)");
4150 ex.setDir(lastImageDir);
4151 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4156 setExportMode(true);
4158 setExportMode(false);
4162 void VymModel::exportXHTML (const QString &dir, bool askForName)
4164 ExportXHTMLDialog dia(NULL);
4165 dia.setFilePath (filePath );
4166 dia.setMapName (mapName );
4168 if (dir!="") dia.setDir (dir);
4174 if (dia.exec()!=QDialog::Accepted)
4178 QDir d (dia.getDir());
4179 // Check, if warnings should be used before overwriting
4180 // the output directory
4181 if (d.exists() && d.count()>0)
4184 warn.showCancelButton (true);
4185 warn.setText(QString(
4186 "The directory %1 is not empty.\n"
4187 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4188 warn.setCaption("Warning: Directory not empty");
4189 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4191 if (warn.exec()!=QDialog::Accepted) ok=false;
4198 exportXML (dia.getDir(),false );
4199 dia.doExport(mapName );
4200 //if (dia.hasChanged()) setChanged();
4204 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4209 if (ex.setConfigFile(cf))
4211 setExportMode (true);
4212 ex.exportPresentation();
4213 setExportMode (false);
4220 //////////////////////////////////////////////
4222 //////////////////////////////////////////////
4224 void VymModel::registerEditor(QWidget *me)
4226 mapEditor=(MapEditor*)me;
4229 void VymModel::unregisterEditor(QWidget *)
4234 void VymModel::setContextPos(QPointF p)
4239 void VymModel::unsetContextPos()
4241 contextPos=QPointF();
4244 void VymModel::updateNoteFlag()
4247 TreeItem *selti=getSelectedItem();
4250 if (textEditor->isEmpty())
4253 selti->setNote (textEditor->getText());
4254 emitDataHasChanged(selti);
4255 emitSelectionChanged();
4260 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4262 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4263 if (blockReposition) return;
4265 for (int i=0;i<rootItem->branchCount(); i++)
4266 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4267 //emitSelectionChanged();
4271 void VymModel::setMapLinkStyle (const QString & s)
4276 case LinkableMapObj::Line :
4279 case LinkableMapObj::Parabel:
4280 snow="StyleParabel";
4282 case LinkableMapObj::PolyLine:
4283 snow="StylePolyLine";
4285 case LinkableMapObj::PolyParabel:
4286 snow="StylePolyParabel";
4289 snow="UndefinedStyle";
4294 QString("setMapLinkStyle (\"%1\")").arg(s),
4295 QString("setMapLinkStyle (\"%1\")").arg(snow),
4296 QString("Set map link style (\"%1\")").arg(s)
4300 linkstyle=LinkableMapObj::Line;
4301 else if (s=="StyleParabel")
4302 linkstyle=LinkableMapObj::Parabel;
4303 else if (s=="StylePolyLine")
4304 linkstyle=LinkableMapObj::PolyLine;
4305 else if (s=="StylePolyParabel")
4306 linkstyle=LinkableMapObj::PolyParabel;
4308 linkstyle=LinkableMapObj::UndefinedStyle;
4310 BranchItem *cur=NULL;
4311 BranchItem *prev=NULL;
4313 nextBranch (cur,prev);
4316 bo=(BranchObj*)(cur->getLMO() );
4317 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4318 cur=nextBranch(cur,prev);
4323 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4328 void VymModel::setMapDefLinkColor(QColor col)
4330 if ( !col.isValid() ) return;
4332 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4333 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4334 QString("Set map link color to %1").arg(col.name())
4338 BranchItem *cur=NULL;
4339 BranchItem *prev=NULL;
4341 cur=nextBranch(cur,prev);
4344 bo=(BranchObj*)(cur->getLMO() );
4346 nextBranch(cur,prev);
4351 void VymModel::setMapLinkColorHintInt()
4353 // called from setMapLinkColorHint(lch) or at end of parse
4354 BranchItem *cur=NULL;
4355 BranchItem *prev=NULL;
4357 cur=nextBranch(cur,prev);
4360 bo=(BranchObj*)(cur->getLMO() );
4362 cur=nextBranch(cur,prev);
4366 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4369 setMapLinkColorHintInt();
4372 void VymModel::toggleMapLinkColorHint()
4374 if (linkcolorhint==LinkableMapObj::HeadingColor)
4375 linkcolorhint=LinkableMapObj::DefaultColor;
4377 linkcolorhint=LinkableMapObj::HeadingColor;
4378 BranchItem *cur=NULL;
4379 BranchItem *prev=NULL;
4381 cur=nextBranch(cur,prev);
4384 bo=(BranchObj*)(cur->getLMO() );
4386 nextBranch(cur,prev);
4390 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4391 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4393 Q3FileDialog *fd=new Q3FileDialog( NULL);
4394 fd->setMode (Q3FileDialog::ExistingFile);
4395 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4396 ImagePreview *p =new ImagePreview (fd);
4397 fd->setContentsPreviewEnabled( TRUE );
4398 fd->setContentsPreview( p, p );
4399 fd->setPreviewMode( Q3FileDialog::Contents );
4400 fd->setCaption(vymName+" - " +tr("Load background image"));
4401 fd->setDir (lastImageDir);
4404 if ( fd->exec() == QDialog::Accepted )
4406 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4407 lastImageDir=QDir (fd->dirPath());
4408 setMapBackgroundImage (fd->selectedFile());
4412 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4414 QColor oldcol=mapScene->backgroundBrush().color();
4418 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4420 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4421 QString("Set background color of map to %1").arg(col.name()));
4424 brush.setTextureImage (QPixmap (fn));
4425 mapScene->setBackgroundBrush(brush);
4428 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4430 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4431 if ( !col.isValid() ) return;
4432 setMapBackgroundColor( col );
4436 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4438 QColor oldcol=mapScene->backgroundBrush().color();
4440 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4441 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4442 QString("Set background color of map to %1").arg(col.name()));
4443 mapScene->setBackgroundBrush(col);
4446 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4448 return mapScene->backgroundBrush().color();
4452 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4454 return linkcolorhint;
4457 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4459 return defLinkColor;
4462 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4467 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4469 return defXLinkColor;
4472 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4477 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4479 return defXLinkWidth;
4482 void VymModel::move(const double &x, const double &y)
4485 MapItem *seli = (MapItem*)getSelectedItem();
4486 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4488 LinkableMapObj *lmo=seli->getLMO();
4491 QPointF ap(lmo->getAbsPos());
4495 QString ps=qpointFToString(ap);
4496 QString s=getSelectString(seli);
4499 s, "move "+qpointFToString(to),
4500 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4503 emitSelectionChanged();
4509 void VymModel::moveRel (const double &x, const double &y)
4512 MapItem *seli = (MapItem*)getSelectedItem();
4513 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4515 LinkableMapObj *lmo=seli->getLMO();
4518 QPointF rp(lmo->getRelPos());
4522 QString ps=qpointFToString (lmo->getRelPos());
4523 QString s=getSelectString(seli);
4526 s, "moveRel "+qpointFToString(to),
4527 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4528 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4530 lmo->updateLinkGeometry();
4531 emitSelectionChanged();
4538 void VymModel::animate()
4540 animationTimer->stop();
4543 while (i<animObjList.size() )
4545 bo=(BranchObj*)animObjList.at(i);
4550 animObjList.removeAt(i);
4557 QItemSelection sel=selModel->selection();
4558 emit (selectionChanged(sel,sel));
4561 if (!animObjList.isEmpty()) animationTimer->start();
4565 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4567 if (start==dest) return;
4568 if (bo && bo->getTreeItem()->depth()>0)
4571 ap.setStart (start);
4573 ap.setTicks (animationTicks);
4574 ap.setAnimated (true);
4575 bo->setAnimation (ap);
4576 animObjList.append( bo );
4577 animationTimer->setSingleShot (true);
4578 animationTimer->start(animationInterval);
4582 void VymModel::stopAnimation (MapObj *mo)
4584 int i=animObjList.indexOf(mo);
4586 animObjList.removeAt (i);
4589 void VymModel::sendSelection()
4591 if (netstate!=Server) return;
4592 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4595 void VymModel::newServer()
4599 tcpServer = new QTcpServer(this);
4600 if (!tcpServer->listen(QHostAddress::Any,port)) {
4601 QMessageBox::critical(NULL, "vym server",
4602 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4603 //FIXME-3 needed? we are no widget any longer... close();
4606 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4608 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4611 void VymModel::connectToServer()
4614 server="salam.suse.de";
4616 clientSocket = new QTcpSocket (this);
4617 clientSocket->abort();
4618 clientSocket->connectToHost(server ,port);
4619 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4620 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4621 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4623 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4628 void VymModel::newClient()
4630 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4631 connect(newClient, SIGNAL(disconnected()),
4632 newClient, SLOT(deleteLater()));
4634 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4636 clientList.append (newClient);
4640 void VymModel::sendData(const QString &s)
4642 if (clientList.size()==0) return;
4644 // Create bytearray to send
4646 QDataStream out(&block, QIODevice::WriteOnly);
4647 out.setVersion(QDataStream::Qt_4_0);
4649 // Reserve some space for blocksize
4652 // Write sendCounter
4653 out << sendCounter++;
4658 // Go back and write blocksize so far
4659 out.device()->seek(0);
4660 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4664 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4666 for (int i=0; i<clientList.size(); ++i)
4668 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4669 clientList.at(i)->write (block);
4673 void VymModel::readData ()
4675 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4678 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4682 QDataStream in(clientSocket);
4683 in.setVersion(QDataStream::Qt_4_0);
4691 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4694 parseAtom (t,noErr,errMsg);
4700 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4702 switch (socketError) {
4703 case QAbstractSocket::RemoteHostClosedError:
4705 case QAbstractSocket::HostNotFoundError:
4706 QMessageBox::information(NULL, vymName +" Network client",
4707 "The host was not found. Please check the "
4708 "host name and port settings.");
4710 case QAbstractSocket::ConnectionRefusedError:
4711 QMessageBox::information(NULL, vymName + " Network client",
4712 "The connection was refused by the peer. "
4713 "Make sure the fortune server is running, "
4714 "and check that the host name and port "
4715 "settings are correct.");
4718 QMessageBox::information(NULL, vymName + " Network client",
4719 QString("The following error occurred: %1.")
4720 .arg(clientSocket->errorString()));
4724 /* FIXME-3 Playing with DBUS...
4725 QDBusVariant VymModel::query (const QString &query)
4727 TreeItem *selti=getSelectedItem();
4729 return QDBusVariant (selti->getHeading());
4731 return QDBusVariant ("Nothing selected.");
4735 void VymModel::testslot() //FIXME-3 Playing with DBUS
4737 cout << "VM::testslot called\n";
4740 void VymModel::selectMapSelectionColor()
4742 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4743 setSelectionColor (col);
4746 void VymModel::setSelectionColorInt (QColor col)
4748 if ( !col.isValid() ) return;
4750 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4751 QString("setSelectionColor (%1)").arg(col.name()),
4752 QString("Set color of selection box to %1").arg(col.name())
4755 mapEditor->setSelectionColor (col);
4758 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4760 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4761 //FIXME-3 emitShowSelection();
4765 void VymModel::emitSelectionChanged()
4767 QItemSelection newsel=selModel->selection();
4768 emitSelectionChanged (newsel);
4771 void VymModel::setSelectionColor(QColor col)
4773 if ( !col.isValid() ) return;
4775 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4776 QString("setSelectionColor (%1)").arg(col.name()),
4777 QString("Set color of selection box to %1").arg(col.name())
4779 setSelectionColorInt (col);
4782 QColor VymModel::getSelectionColor()
4784 return mapEditor->getSelectionColor();
4787 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4790 for (int i=0;i<rootItem->childCount();i++)
4791 rootItem->child(i)->setHideTmp (mode);
4793 // FIXME-3 needed? scene()->update();
4796 //////////////////////////////////////////////
4797 // Selection related
4798 //////////////////////////////////////////////
4800 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4805 QItemSelectionModel* VymModel::getSelectionModel()
4810 void VymModel::setSelectionBlocked (bool b)
4815 bool VymModel::isSelectionBlocked()
4817 return selectionBlocked;
4820 bool VymModel::select ()
4822 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4825 bool VymModel::select (const QString &s)
4832 TreeItem *ti=findBySelectString(s);
4833 if (ti) return select (index(ti));
4837 bool VymModel::select (LinkableMapObj *lmo)
4839 QItemSelection oldsel=selModel->selection();
4842 return select (index (lmo->getTreeItem()) );
4847 bool VymModel::select (TreeItem *ti)
4849 if (ti) return select (index(ti));
4853 bool VymModel::select (const QModelIndex &index)
4855 if (index.isValid() )
4857 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4858 BranchItem *bi=getSelectedBranch();
4859 if (bi) bi->setLastSelectedBranch();
4865 void VymModel::unselect()
4867 if (!selModel->selectedIndexes().isEmpty())
4869 lastSelectString=getSelectString();
4870 selModel->clearSelection();
4874 bool VymModel::reselect()
4876 return select (lastSelectString);
4879 void VymModel::emitShowSelection()
4881 if (!blockReposition)
4882 emit (showSelection() );
4885 void VymModel::emitNoteHasChanged (TreeItem *ti)
4887 QModelIndex ix=index(ti);
4888 emit (noteHasChanged (ix) );
4891 void VymModel::emitDataHasChanged (TreeItem *ti)
4893 QModelIndex ix=index(ti);
4894 emit (dataChanged (ix,ix) );
4898 bool VymModel::selectFirstBranch()
4900 TreeItem *ti=getSelectedBranch();
4903 TreeItem *par=ti->parent();
4906 TreeItem *ti2=par->getFirstBranch();
4907 if (ti2) return select(ti2);
4913 bool VymModel::selectLastBranch()
4915 TreeItem *ti=getSelectedBranch();
4918 TreeItem *par=ti->parent();
4921 TreeItem *ti2=par->getLastBranch();
4922 if (ti2) return select(ti2);
4928 bool VymModel::selectLastSelectedBranch()
4930 BranchItem *bi=getSelectedBranch();
4933 bi=bi->getLastSelectedBranch();
4934 if (bi) return select (bi);
4939 bool VymModel::selectParent()
4941 TreeItem *ti=getSelectedItem();
4952 TreeItem::Type VymModel::selectionType()
4954 QModelIndexList list=selModel->selectedIndexes();
4955 if (list.isEmpty()) return TreeItem::Undefined;
4956 TreeItem *ti = getItem (list.first() );
4957 return ti->getType();
4961 LinkableMapObj* VymModel::getSelectedLMO()
4963 QModelIndexList list=selModel->selectedIndexes();
4964 if (!list.isEmpty() )
4966 TreeItem *ti = getItem (list.first() );
4967 TreeItem::Type type=ti->getType();
4968 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4969 return ((MapItem*)ti)->getLMO();
4974 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4976 TreeItem *ti = getSelectedBranch();
4978 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4983 BranchItem* VymModel::getSelectedBranch()
4985 QModelIndexList list=selModel->selectedIndexes();
4986 if (!list.isEmpty() )
4988 TreeItem *ti = getItem (list.first() );
4989 TreeItem::Type type=ti->getType();
4990 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4991 return (BranchItem*)ti;
4996 ImageItem* VymModel::getSelectedImage()
4998 QModelIndexList list=selModel->selectedIndexes();
4999 if (!list.isEmpty())
5001 TreeItem *ti=getItem (list.first());
5002 if (ti && ti->getType()==TreeItem::Image)
5003 return (ImageItem*)ti;
5008 AttributeItem* VymModel::getSelectedAttribute()
5010 QModelIndexList list=selModel->selectedIndexes();
5011 if (!list.isEmpty() )
5013 TreeItem *ti = getItem (list.first() );
5014 TreeItem::Type type=ti->getType();
5015 if (type ==TreeItem::Attribute)
5016 return (AttributeItem*)ti;
5021 TreeItem* VymModel::getSelectedItem()
5023 QModelIndexList list=selModel->selectedIndexes();
5024 if (!list.isEmpty() )
5025 return getItem (list.first() );
5030 QModelIndex VymModel::getSelectedIndex()
5032 QModelIndexList list=selModel->selectedIndexes();
5033 if (list.isEmpty() )
5034 return QModelIndex();
5036 return list.first();
5039 QString VymModel::getSelectString ()
5041 return getSelectString (getSelectedItem());
5044 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5046 if (!lmo) return QString();
5047 return getSelectString (lmo->getTreeItem() );
5050 QString VymModel::getSelectString (TreeItem *ti)
5054 switch (ti->getType())
5056 case TreeItem::MapCenter: s="mc:"; break;
5057 case TreeItem::Branch: s="bo:";break;
5058 case TreeItem::Image: s="fi:";break;
5059 case TreeItem::Attribute: s="ai:";break;
5060 case TreeItem::XLink: s="xl:";break;
5062 s="unknown type in VymModel::getSelectString()";
5065 s= s + QString("%1").arg(ti->num());
5067 // call myself recursively
5068 s= getSelectString(ti->parent()) +","+s;