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,writeflags,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, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
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();
2032 if ( relinkBranch (selbi,rootItem,-1) )
2034 selbi,QString("relink()"), //FIXME-1 add paramters when detaching
2036 QString("Detach %1").arg(getObjectName(selbi))
2041 void VymModel::sortChildren()
2043 BranchItem* selbi=getSelectedBranch();
2046 if(selbi->branchCount()>1)
2048 saveStateChangingPart(
2049 selbi,selbi, "sortChildren ()",
2050 QString("Sort children of %1").arg(getObjectName(selbi)));
2051 selbi->sortChildren();
2053 emitShowSelection();
2058 BranchItem* VymModel::createMapCenter()
2060 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2064 BranchItem* VymModel::createBranch(BranchItem *dst)
2067 return addNewBranchInt (dst,-2);
2072 ImageItem* VymModel::createImage(BranchItem *dst)
2079 QList<QVariant> cData;
2080 cData << "new" << "undef";
2082 ImageItem *newii=new ImageItem(cData) ;
2083 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2085 emit (layoutAboutToBeChanged() );
2088 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2089 n=dst->getRowNumAppend(newii);
2090 beginInsertRows (parix,n,n);
2091 dst->appendChild (newii);
2094 emit (layoutChanged() );
2096 // save scroll state. If scrolled, automatically select
2097 // new branch in order to tmp unscroll parent...
2098 newii->createMapObj(mapScene);
2105 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2112 QList<QVariant> cData;
2113 cData << "new xLink"<<"undef";
2115 XLinkItem *newxli=new XLinkItem(cData) ;
2116 newxli->setBegin (bi);
2118 emit (layoutAboutToBeChanged() );
2121 n=bi->getRowNumAppend(newxli);
2122 beginInsertRows (parix,n,n);
2123 bi->appendChild (newxli);
2126 emit (layoutChanged() );
2128 // save scroll state. If scrolled, automatically select
2129 // new branch in order to tmp unscroll parent...
2132 newxli->createMapObj(mapScene);
2140 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2142 BranchItem *selbi=getSelectedBranch();
2145 QList<QVariant> cData;
2146 cData << "new attribute" << "undef";
2147 AttributeItem *a=new AttributeItem (cData);
2149 emit (layoutAboutToBeChanged() );
2151 QModelIndex parix=index(selbi);
2152 int n=selbi->getRowNumAppend (a);
2153 beginInsertRows (parix,n,n);
2154 selbi->appendChild (a);
2157 emit (layoutChanged() );
2165 BranchItem* VymModel::addMapCenter ()
2167 BranchItem *bi=addMapCenter (contextPos);
2169 emitShowSelection();
2174 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2175 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2180 BranchItem* VymModel::addMapCenter(QPointF absPos)
2181 // createMapCenter could then probably be merged with createBranch
2185 QModelIndex parix=index(rootItem);
2187 QList<QVariant> cData;
2188 cData << "VM:addMapCenter" << "undef";
2189 BranchItem *newbi=new BranchItem (cData,rootItem);
2190 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2191 int n=rootItem->getRowNumAppend (newbi);
2193 emit (layoutAboutToBeChanged() );
2194 beginInsertRows (parix,n,n);
2196 rootItem->appendChild (newbi);
2199 emit (layoutChanged() );
2202 newbi->setPositionMode (MapItem::Absolute);
2203 BranchObj *bo=newbi->createMapObj(mapScene);
2204 if (bo) bo->move (absPos);
2209 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2211 // Depending on pos:
2212 // -3 insert in children of parent above selection
2213 // -2 add branch to selection
2214 // -1 insert in children of parent below selection
2215 // 0..n insert in children of parent at pos
2218 QList<QVariant> cData;
2219 cData << "" << "undef";
2224 BranchItem *newbi=new BranchItem (cData);
2225 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2227 emit (layoutAboutToBeChanged() );
2233 n=parbi->getRowNumAppend (newbi);
2234 beginInsertRows (parix,n,n);
2235 parbi->appendChild (newbi);
2237 }else if (num==-1 || num==-3)
2239 // insert below selection
2240 parbi=(BranchItem*)dst->parent();
2243 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2244 beginInsertRows (parix,n,n);
2245 parbi->insertBranch(n,newbi);
2248 emit (layoutChanged() );
2250 // Set color of heading to that of parent
2251 newbi->setHeadingColor (parbi->getHeadingColor());
2253 // save scroll state. If scrolled, automatically select
2254 // new branch in order to tmp unscroll parent...
2255 newbi->createMapObj(mapScene);
2260 BranchItem* VymModel::addNewBranch(int pos)
2262 // Different meaning than num in addNewBranchInt!
2266 BranchItem *newbi=NULL;
2267 BranchItem *selbi=getSelectedBranch();
2271 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2273 newbi=addNewBranchInt (selbi,pos-2);
2281 QString ("addBranch (%1)").arg(pos),
2282 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2285 // emitSelectionChanged(); FIXME-3
2286 latestAddedItem=newbi;
2287 // In Network mode, the client needs to know where the new branch is,
2288 // so we have to pass on this information via saveState.
2289 // TODO: Get rid of this positioning workaround
2290 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2291 sendData ("selectLatestAdded ()");
2292 sendData (QString("move %1").arg(ps));
2301 BranchItem* VymModel::addNewBranchBefore()
2303 BranchItem *newbi=NULL;
2304 BranchItem *selbi=getSelectedBranch();
2305 if (selbi && selbi->getType()==TreeItem::Branch)
2306 // We accept no MapCenter here, so we _have_ a parent
2308 //QPointF p=bo->getRelPos();
2311 // add below selection
2312 newbi=addNewBranchInt (selbi,-1);
2316 //newbi->move2RelPos (p);
2318 // Move selection to new branch
2319 relinkBranch (selbi,newbi,0);
2321 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2322 QString ("Add branch before %1").arg(getObjectName(selbi)));
2324 // FIXME-3 needed? reposition();
2325 // emitSelectionChanged(); FIXME-3
2331 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2337 emit (layoutAboutToBeChanged() );
2338 BranchItem *branchpi=(BranchItem*)branch->parent();
2339 // Remove at current position
2340 int n=branch->childNum();
2341 beginRemoveRows (index(branchpi),n,n);
2342 branchpi->removeChild (n);
2345 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2347 // Append as last branch to dst
2348 if (dst->branchCount()==0)
2351 n=dst->getFirstBranch()->childNumber();
2352 beginInsertRows (index(dst),n+pos,n+pos);
2353 dst->insertBranch (pos,branch);
2356 // Correct type if necessesary
2357 if (branch->getType()==TreeItem::MapCenter)
2358 branch->setType(TreeItem::Branch);
2360 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2361 branch->updateStyles();
2363 emit (layoutChanged() );
2364 reposition(); // both for moveUp/Down and relinking
2365 if (dst->isScrolled() )
2368 branch->updateVisibility();
2377 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2381 emit (layoutAboutToBeChanged() );
2383 BranchItem *pi=(BranchItem*)(image->parent());
2384 QString oldParString=getSelectString (pi);
2385 // Remove at current position
2386 int n=image->childNum();
2387 beginRemoveRows (index(pi),n,n);
2388 pi->removeChild (n);
2392 QModelIndex dstix=index(dst);
2393 n=dst->getRowNumAppend (image);
2394 beginInsertRows (dstix,n,n+1);
2395 dst->appendChild (image);
2398 // Set new parent also for lmo
2399 if (image->getLMO() && dst->getLMO() )
2400 image->getLMO()->setParObj (dst->getLMO() );
2402 emit (layoutChanged() );
2405 QString("relinkTo (\"%1\")").arg(oldParString),
2407 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2408 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2414 void VymModel::deleteSelection()
2416 BranchItem *selbi=getSelectedBranch();
2421 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2423 TreeItem *pi=deleteItem (selbi);
2427 emitShowSelection();
2431 TreeItem *ti=getSelectedItem();
2433 { // Delete other item
2434 TreeItem *pi=ti->parent();
2436 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2438 saveStateChangingPart(
2442 QString("Delete %1").arg(getObjectName(ti))
2446 emitDataHasChanged (pi);
2449 emitShowSelection();
2450 } else if (ti->getType()==TreeItem::XLink)
2452 //FIXME-2 savestate missing
2455 qWarning ("VymmModel::deleteSelection() unknown type?!");
2459 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2462 BranchItem *selbi=getSelectedBranch();
2466 // Don't use this on mapcenter
2467 if (selbi->depth()<2) return;
2469 pi=(BranchItem*)(selbi->parent());
2470 // Check if we have childs at all to keep
2471 if (selbi->branchCount()==0)
2478 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2479 saveStateChangingPart(
2482 "deleteKeepChildren ()",
2483 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2486 QString sel=getSelectString(selbi);
2488 int pos=selbi->num();
2489 BranchItem *bi=selbi->getFirstBranch();
2492 relinkBranch (bi,pi,pos);
2493 bi=selbi->getFirstBranch();
2499 BranchObj *bo=getSelectedBranchObj();
2502 bo->move2RelPos (p);
2508 void VymModel::deleteChildren()
2511 BranchItem *selbi=getSelectedBranch();
2514 saveStateChangingPart(
2517 "deleteChildren ()",
2518 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2520 emit (layoutAboutToBeChanged() );
2522 QModelIndex ix=index (selbi);
2523 int n=selbi->branchCount()-1;
2524 beginRemoveRows (ix,0,n);
2525 removeRows (0,n+1,ix);
2527 if (selbi->isScrolled()) selbi->unScroll();
2528 emit (layoutChanged() );
2533 TreeItem* VymModel::deleteItem (TreeItem *ti)
2537 TreeItem *pi=ti->parent();
2538 QModelIndex parentIndex=index(pi);
2540 emit (layoutAboutToBeChanged() );
2542 int n=ti->childNum();
2543 beginRemoveRows (parentIndex,n,n);
2544 removeRows (n,1,parentIndex);
2548 emit (layoutChanged() );
2549 if (pi->depth()>=0) return pi;
2554 void VymModel::clearItem (TreeItem *ti)
2558 QModelIndex parentIndex=index(ti);
2559 if (!parentIndex.isValid()) return;
2561 int n=ti->childCount();
2564 emit (layoutAboutToBeChanged() );
2566 beginRemoveRows (parentIndex,0,n-1);
2567 removeRows (0,n,parentIndex);
2571 emit (layoutChanged() );
2577 bool VymModel::scrollBranch(BranchItem *bi)
2581 if (bi->isScrolled()) return false;
2582 if (bi->branchCount()==0) return false;
2583 if (bi->depth()==0) return false;
2584 if (bi->toggleScroll())
2592 QString ("%1 ()").arg(u),
2594 QString ("%1 ()").arg(r),
2595 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2597 emitDataHasChanged(bi);
2598 emitSelectionChanged();
2599 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2606 bool VymModel::unscrollBranch(BranchItem *bi)
2610 if (!bi->isScrolled()) return false;
2611 if (bi->branchCount()==0) return false;
2612 if (bi->depth()==0) return false;
2613 if (bi->toggleScroll())
2621 QString ("%1 ()").arg(u),
2623 QString ("%1 ()").arg(r),
2624 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2626 emitDataHasChanged(bi);
2627 emitSelectionChanged();
2628 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2635 void VymModel::toggleScroll()
2637 BranchItem *bi=(BranchItem*)getSelectedBranch();
2638 if (bi && bi->isBranchLikeType() )
2640 if (bi->isScrolled())
2641 unscrollBranch (bi);
2645 // saveState & reposition are called in above functions
2648 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2650 BranchItem *selbi=getSelectedBranch();
2651 BranchItem *prev=NULL;
2652 BranchItem *cur=selbi;
2655 saveStateChangingPart(
2658 QString ("unscrollChildren ()"),
2659 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2663 if (cur->isScrolled())
2665 cur->toggleScroll();
2666 emitDataHasChanged (cur);
2668 cur=nextBranch (cur,prev,true,selbi);
2675 void VymModel::emitExpandAll()
2677 emit (expandAll() );
2680 void VymModel::emitExpandOneLevel()
2682 emit (expandOneLevel () );
2685 void VymModel::emitCollapseOneLevel()
2687 emit (collapseOneLevel () );
2690 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2692 BranchItem *bi=getSelectedBranch();
2696 if (bi->isActiveStandardFlag(name))
2708 QString("%1 (\"%2\")").arg(u).arg(name),
2710 QString("%1 (\"%2\")").arg(r).arg(name),
2711 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2712 bi->toggleStandardFlag (name, master);
2714 emitSelectionChanged();
2718 void VymModel::addFloatImage (const QPixmap &img)
2720 BranchItem *selbi=getSelectedBranch();
2723 ImageItem *ii=createImage (selbi);
2725 ii->setOriginalFilename("No original filename (image added by dropevent)");
2726 QString s=getSelectString(selbi);
2727 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2728 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2730 // FIXME-3 VM needed? scene()->update();
2735 void VymModel::colorBranch (QColor c)
2737 BranchItem *selbi=getSelectedBranch();
2742 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2744 QString ("colorBranch (\"%1\")").arg(c.name()),
2745 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2747 selbi->setHeadingColor(c); // color branch
2752 void VymModel::colorSubtree (QColor c)
2754 BranchItem *selbi=getSelectedBranch();
2757 saveStateChangingPart(
2760 QString ("colorSubtree (\"%1\")").arg(c.name()),
2761 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2763 BranchItem *prev=NULL;
2764 BranchItem *cur=selbi;
2767 cur->setHeadingColor(c); // color links, color children
2768 cur=nextBranch (cur,prev,true,selbi);
2774 QColor VymModel::getCurrentHeadingColor()
2776 BranchItem *selbi=getSelectedBranch();
2777 if (selbi) return selbi->getHeadingColor();
2779 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2785 void VymModel::editURL()
2787 TreeItem *selti=getSelectedItem();
2791 QString text = QInputDialog::getText(
2792 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2793 selti->getURL(), &ok, NULL);
2795 // user entered something and pressed OK
2800 void VymModel::editLocalURL()
2802 TreeItem *selti=getSelectedItem();
2805 QStringList filters;
2806 filters <<"All files (*)";
2807 filters << tr("Text","Filedialog") + " (*.txt)";
2808 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2809 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2810 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2811 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2812 fd->setFilters (filters);
2813 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2814 fd->setDirectory (lastFileDir);
2815 if (! selti->getVymLink().isEmpty() )
2816 fd->selectFile( selti->getURL() );
2819 if ( fd->exec() == QDialog::Accepted )
2821 lastFileDir=QDir (fd->directory().path());
2822 setURL (fd->selectedFile() );
2828 void VymModel::editHeading2URL()
2830 TreeItem *selti=getSelectedItem();
2832 setURL (selti->getHeading());
2835 void VymModel::editBugzilla2URL()
2837 TreeItem *selti=getSelectedItem();
2840 QString h=selti->getHeading();
2841 QRegExp rx("^(\\d+)");
2842 if (rx.indexIn(h) !=-1)
2843 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2847 void VymModel::editFATE2URL()
2849 TreeItem *selti=getSelectedItem();
2852 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2855 "setURL (\""+selti->getURL()+"\")",
2857 "setURL (\""+url+"\")",
2858 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2860 selti->setURL (url);
2861 // FIXME-4 updateActions();
2865 void VymModel::editVymLink()
2867 BranchItem *bi=getSelectedBranch();
2870 QStringList filters;
2871 filters <<"VYM map (*.vym)";
2872 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2873 fd->setFilters (filters);
2874 fd->setCaption(vymName+" - " +tr("Link to another map"));
2875 fd->setDirectory (lastFileDir);
2876 if (! bi->getVymLink().isEmpty() )
2877 fd->selectFile( bi->getVymLink() );
2881 if ( fd->exec() == QDialog::Accepted )
2883 lastFileDir=QDir (fd->directory().path());
2886 "setVymLink (\""+bi->getVymLink()+"\")",
2888 "setVymLink (\""+fd->selectedFile()+"\")",
2889 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2891 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2896 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2898 // Internal function, no saveState needed
2899 TreeItem *selti=getSelectedItem();
2902 selti->setVymLink(s);
2904 emitDataHasChanged (selti);
2905 emitShowSelection();
2909 void VymModel::deleteVymLink()
2911 BranchItem *bi=getSelectedBranch();
2916 "setVymLink (\""+bi->getVymLink()+"\")",
2918 "setVymLink (\"\")",
2919 QString("Unset vymlink of %1").arg(getObjectName(bi))
2921 bi->setVymLink ("" );
2927 QString VymModel::getVymLink()
2929 BranchItem *bi=getSelectedBranch();
2931 return bi->getVymLink();
2937 QStringList VymModel::getVymLinks()
2940 BranchItem *selbi=getSelectedBranch();
2941 BranchItem *cur=selbi;
2942 BranchItem *prev=NULL;
2945 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2946 cur=nextBranch (cur,prev,true,selbi);
2952 void VymModel::followXLink(int i)
2955 BranchItem *selbi=getSelectedBranch();
2958 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2959 if (selbi) select (selbi);
2963 void VymModel::editXLink(int i)
2966 BranchItem *selbi=getSelectedBranch();
2969 XLinkItem *xli=selbi->getXLinkNum(i);
2972 EditXLinkDialog dia;
2974 dia.setSelection(selbi);
2975 if (dia.exec() == QDialog::Accepted)
2977 if (dia.useSettingsGlobal() )
2979 setMapDefXLinkColor (xli->getColor() );
2980 setMapDefXLinkWidth (xli->getWidth() );
2982 if (dia.deleteXLink()) deleteItem (xli);
2992 //////////////////////////////////////////////
2994 //////////////////////////////////////////////
2996 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
2998 TreeItem* selti=getSelectedItem();
2999 BranchItem *selbi=getSelectedBranch();
3004 QVariant returnValue;
3006 // Split string s into command and parameters
3007 parser.parseAtom (atom);
3008 QString com=parser.getCommand();
3010 // External commands
3011 /////////////////////////////////////////////////////////////////////
3012 if (com=="addBranch")
3016 parser.setError (Aborted,"Nothing selected");
3017 } else if (! selbi )
3019 parser.setError (Aborted,"Type of selection is not a branch");
3024 if (parser.checkParCount(pl))
3026 if (parser.parCount()==0)
3030 n=parser.parInt (ok,0);
3031 if (ok ) addNewBranch (n);
3035 /////////////////////////////////////////////////////////////////////
3036 } else if (com=="addBranchBefore")
3040 parser.setError (Aborted,"Nothing selected");
3041 } else if (! selbi )
3043 parser.setError (Aborted,"Type of selection is not a branch");
3046 if (parser.parCount()==0)
3048 addNewBranchBefore ();
3051 /////////////////////////////////////////////////////////////////////
3052 } else if (com==QString("addMapCenter"))
3054 if (parser.checkParCount(2))
3056 x=parser.parDouble (ok,0);
3059 y=parser.parDouble (ok,1);
3060 if (ok) addMapCenter (QPointF(x,y));
3063 /////////////////////////////////////////////////////////////////////
3064 } else if (com==QString("addMapReplace"))
3068 parser.setError (Aborted,"Nothing selected");
3069 } else if (! selbi )
3071 parser.setError (Aborted,"Type of selection is not a branch");
3072 } else if (parser.checkParCount(1))
3074 //s=parser.parString (ok,0); // selection
3075 t=parser.parString (ok,0); // path to map
3076 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3077 addMapReplaceInt(getSelectString(selbi),t);
3079 /////////////////////////////////////////////////////////////////////
3080 } else if (com==QString("addMapInsert"))
3082 if (parser.parCount()==2)
3087 parser.setError (Aborted,"Nothing selected");
3088 } else if (! selbi )
3090 parser.setError (Aborted,"Type of selection is not a branch");
3093 t=parser.parString (ok,0); // path to map
3094 n=parser.parInt(ok,1); // position
3095 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3096 addMapInsertInt(t,n);
3098 } else if (parser.parCount()==1)
3100 t=parser.parString (ok,0); // path to map
3101 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3104 parser.setError (Aborted,"Wrong number of parameters");
3105 /////////////////////////////////////////////////////////////////////
3106 } else if (com==QString("addXLink"))
3108 if (parser.parCount()>1)
3110 s=parser.parString (ok,0); // begin
3111 t=parser.parString (ok,1); // end
3112 BranchItem *begin=(BranchItem*)findBySelectString(s);
3113 BranchItem *end=(BranchItem*)findBySelectString(t);
3116 if (begin->isBranchLikeType() && end->isBranchLikeType())
3118 XLinkItem *xl=createXLink (begin,true);
3124 parser.setError (Aborted,"Failed to create xLink");
3127 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3130 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3132 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3133 /////////////////////////////////////////////////////////////////////
3134 } else if (com=="clearFlags")
3138 parser.setError (Aborted,"Nothing selected");
3139 } else if (! selbi )
3141 parser.setError (Aborted,"Type of selection is not a branch");
3142 } else if (parser.checkParCount(0))
3144 selbi->deactivateAllStandardFlags();
3146 /////////////////////////////////////////////////////////////////////
3147 } else if (com=="colorBranch")
3151 parser.setError (Aborted,"Nothing selected");
3152 } else if (! selbi )
3154 parser.setError (Aborted,"Type of selection is not a branch");
3155 } else if (parser.checkParCount(1))
3157 QColor c=parser.parColor (ok,0);
3158 if (ok) colorBranch (c);
3160 /////////////////////////////////////////////////////////////////////
3161 } else if (com=="colorSubtree")
3165 parser.setError (Aborted,"Nothing selected");
3166 } else if (! selbi )
3168 parser.setError (Aborted,"Type of selection is not a branch");
3169 } else if (parser.checkParCount(1))
3171 QColor c=parser.parColor (ok,0);
3172 if (ok) colorSubtree (c);
3174 /////////////////////////////////////////////////////////////////////
3175 } else if (com=="copy")
3179 parser.setError (Aborted,"Nothing selected");
3180 } else if ( selectionType()!=TreeItem::Branch &&
3181 selectionType()!=TreeItem::MapCenter &&
3182 selectionType()!=TreeItem::Image )
3184 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3185 } else if (parser.checkParCount(0))
3189 /////////////////////////////////////////////////////////////////////
3190 } else if (com=="cut")
3194 parser.setError (Aborted,"Nothing selected");
3195 } else if ( selectionType()!=TreeItem::Branch &&
3196 selectionType()!=TreeItem::MapCenter &&
3197 selectionType()!=TreeItem::Image )
3199 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3200 } else if (parser.checkParCount(0))
3204 /////////////////////////////////////////////////////////////////////
3205 } else if (com=="delete")
3209 parser.setError (Aborted,"Nothing selected");
3211 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3213 parser.setError (Aborted,"Type of selection is wrong.");
3216 else if (parser.checkParCount(0))
3220 /////////////////////////////////////////////////////////////////////
3221 } else if (com=="deleteKeepChildren")
3225 parser.setError (Aborted,"Nothing selected");
3226 } else if (! selbi )
3228 parser.setError (Aborted,"Type of selection is not a branch");
3229 } else if (parser.checkParCount(0))
3231 deleteKeepChildren();
3233 /////////////////////////////////////////////////////////////////////
3234 } else if (com=="deleteChildren")
3238 parser.setError (Aborted,"Nothing selected");
3241 parser.setError (Aborted,"Type of selection is not a branch");
3242 } else if (parser.checkParCount(0))
3246 /////////////////////////////////////////////////////////////////////
3247 } else if (com=="exportAO")
3251 if (parser.parCount()>=1)
3252 // Hey, we even have a filename
3253 fname=parser.parString(ok,0);
3256 parser.setError (Aborted,"Could not read filename");
3259 exportAO (fname,false);
3261 /////////////////////////////////////////////////////////////////////
3262 } else if (com=="exportASCII")
3266 if (parser.parCount()>=1)
3267 // Hey, we even have a filename
3268 fname=parser.parString(ok,0);
3271 parser.setError (Aborted,"Could not read filename");
3274 exportASCII (fname,false);
3276 /////////////////////////////////////////////////////////////////////
3277 } else if (com=="exportImage")
3281 if (parser.parCount()>=2)
3282 // Hey, we even have a filename
3283 fname=parser.parString(ok,0);
3286 parser.setError (Aborted,"Could not read filename");
3289 QString format="PNG";
3290 if (parser.parCount()>=2)
3292 format=parser.parString(ok,1);
3294 exportImage (fname,false,format);
3296 /////////////////////////////////////////////////////////////////////
3297 } else if (com=="exportXHTML")
3301 if (parser.parCount()>=2)
3302 // Hey, we even have a filename
3303 fname=parser.parString(ok,1);
3306 parser.setError (Aborted,"Could not read filename");
3309 exportXHTML (fname,false);
3311 /////////////////////////////////////////////////////////////////////
3312 } else if (com=="exportXML")
3316 if (parser.parCount()>=2)
3317 // Hey, we even have a filename
3318 fname=parser.parString(ok,1);
3321 parser.setError (Aborted,"Could not read filename");
3324 exportXML (fname,false);
3326 /////////////////////////////////////////////////////////////////////
3327 } else if (com=="getHeading")
3331 parser.setError (Aborted,"Nothing selected");
3332 } else if (parser.checkParCount(0))
3333 returnValue=selti->getHeading();
3334 /////////////////////////////////////////////////////////////////////
3335 } else if (com=="importDir")
3339 parser.setError (Aborted,"Nothing selected");
3340 } else if (! selbi )
3342 parser.setError (Aborted,"Type of selection is not a branch");
3343 } else if (parser.checkParCount(1))
3345 s=parser.parString(ok,0);
3346 if (ok) importDirInt(s);
3348 /////////////////////////////////////////////////////////////////////
3349 } else if (com=="relinkTo")
3353 parser.setError (Aborted,"Nothing selected");
3356 if (parser.checkParCount(4))
3358 // 0 selectstring of parent
3359 // 1 num in parent (for branches)
3360 // 2,3 x,y of mainbranch or mapcenter
3361 s=parser.parString(ok,0);
3362 TreeItem *dst=findBySelectString (s);
3365 if (dst->getType()==TreeItem::Branch)
3367 // Get number in parent
3368 n=parser.parInt (ok,1);
3371 relinkBranch (selbi,(BranchItem*)dst,n);
3372 emitSelectionChanged();
3374 } else if (dst->getType()==TreeItem::MapCenter)
3376 relinkBranch (selbi,(BranchItem*)dst);
3377 // Get coordinates of mainbranch
3378 x=parser.parDouble(ok,2);
3381 y=parser.parDouble(ok,3);
3384 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3385 emitSelectionChanged();
3391 } else if ( selti->getType() == TreeItem::Image)
3393 if (parser.checkParCount(1))
3395 // 0 selectstring of parent
3396 s=parser.parString(ok,0);
3397 TreeItem *dst=findBySelectString (s);
3400 if (dst->isBranchLikeType())
3401 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3403 parser.setError (Aborted,"Destination is not a branch");
3406 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3407 /////////////////////////////////////////////////////////////////////
3408 } else if (com=="loadImage")
3412 parser.setError (Aborted,"Nothing selected");
3413 } else if (! selbi )
3415 parser.setError (Aborted,"Type of selection is not a branch");
3416 } else if (parser.checkParCount(1))
3418 s=parser.parString(ok,0);
3419 if (ok) loadFloatImageInt (selbi,s);
3421 /////////////////////////////////////////////////////////////////////
3422 } else if (com=="moveUp")
3426 parser.setError (Aborted,"Nothing selected");
3427 } else if (! selbi )
3429 parser.setError (Aborted,"Type of selection is not a branch");
3430 } else if (parser.checkParCount(0))
3434 /////////////////////////////////////////////////////////////////////
3435 } else if (com=="moveDown")
3439 parser.setError (Aborted,"Nothing selected");
3440 } else if (! selbi )
3442 parser.setError (Aborted,"Type of selection is not a branch");
3443 } else if (parser.checkParCount(0))
3447 /////////////////////////////////////////////////////////////////////
3448 } else if (com=="move")
3452 parser.setError (Aborted,"Nothing selected");
3453 } else if ( selectionType()!=TreeItem::Branch &&
3454 selectionType()!=TreeItem::MapCenter &&
3455 selectionType()!=TreeItem::Image )
3457 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3458 } else if (parser.checkParCount(2))
3460 x=parser.parDouble (ok,0);
3463 y=parser.parDouble (ok,1);
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="moveRel")
3472 parser.setError (Aborted,"Nothing selected");
3473 } else if ( selectionType()!=TreeItem::Branch &&
3474 selectionType()!=TreeItem::MapCenter &&
3475 selectionType()!=TreeItem::Image )
3477 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3478 } else if (parser.checkParCount(2))
3480 x=parser.parDouble (ok,0);
3483 y=parser.parDouble (ok,1);
3484 if (ok) moveRel (x,y);
3487 /////////////////////////////////////////////////////////////////////
3488 } else if (com=="nop")
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="paste")
3495 parser.setError (Aborted,"Nothing selected");
3496 } else if (! selbi )
3498 parser.setError (Aborted,"Type of selection is not a branch");
3499 } else if (parser.checkParCount(1))
3501 n=parser.parInt (ok,0);
3502 if (ok) pasteNoSave(n);
3504 /////////////////////////////////////////////////////////////////////
3505 } else if (com=="qa")
3509 parser.setError (Aborted,"Nothing selected");
3510 } else if (! selbi )
3512 parser.setError (Aborted,"Type of selection is not a branch");
3513 } else if (parser.checkParCount(4))
3516 c=parser.parString (ok,0);
3519 parser.setError (Aborted,"No comment given");
3522 s=parser.parString (ok,1);
3525 parser.setError (Aborted,"First parameter is not a string");
3528 t=parser.parString (ok,2);
3531 parser.setError (Aborted,"Condition is not a string");
3534 u=parser.parString (ok,3);
3537 parser.setError (Aborted,"Third parameter is not a string");
3542 parser.setError (Aborted,"Unknown type: "+s);
3547 parser.setError (Aborted,"Unknown operator: "+t);
3552 parser.setError (Aborted,"Type of selection is not a branch");
3555 if (selbi->getHeading() == u)
3557 cout << "PASSED: " << qPrintable (c) << endl;
3560 cout << "FAILED: " << qPrintable (c) << endl;
3570 /////////////////////////////////////////////////////////////////////
3571 } else if (com=="saveImage")
3573 ImageItem *ii=getSelectedImage();
3576 parser.setError (Aborted,"No image selected");
3577 } else if (parser.checkParCount(2))
3579 s=parser.parString(ok,0);
3582 t=parser.parString(ok,1);
3583 if (ok) saveFloatImageInt (ii,t,s);
3586 /////////////////////////////////////////////////////////////////////
3587 } else if (com=="scroll")
3591 parser.setError (Aborted,"Nothing selected");
3592 } else if (! selbi )
3594 parser.setError (Aborted,"Type of selection is not a branch");
3595 } else if (parser.checkParCount(0))
3597 if (!scrollBranch (selbi))
3598 parser.setError (Aborted,"Could not scroll branch");
3600 /////////////////////////////////////////////////////////////////////
3601 } else if (com=="select")
3603 if (parser.checkParCount(1))
3605 s=parser.parString(ok,0);
3608 /////////////////////////////////////////////////////////////////////
3609 } else if (com=="selectLastBranch")
3613 parser.setError (Aborted,"Nothing selected");
3614 } else if (! selbi )
3616 parser.setError (Aborted,"Type of selection is not a branch");
3617 } else if (parser.checkParCount(0))
3619 BranchItem *bi=selbi->getLastBranch();
3621 parser.setError (Aborted,"Could not select last branch");
3622 select (bi); // FIXME-3 was selectInt
3625 /////////////////////////////////////////////////////////////////////
3626 } else /* FIXME-2 if (com=="selectLastImage")
3630 parser.setError (Aborted,"Nothing selected");
3631 } else if (! selbi )
3633 parser.setError (Aborted,"Type of selection is not a branch");
3634 } else if (parser.checkParCount(0))
3636 FloatImageObj *fio=selb->getLastFloatImage();
3638 parser.setError (Aborted,"Could not select last image");
3639 select (fio); // FIXME-3 was selectInt
3642 /////////////////////////////////////////////////////////////////////
3643 } else */ if (com=="selectLatestAdded")
3645 if (!latestAddedItem)
3647 parser.setError (Aborted,"No latest added object");
3650 if (!select (latestAddedItem))
3651 parser.setError (Aborted,"Could not select latest added object ");
3653 /////////////////////////////////////////////////////////////////////
3654 } else if (com=="setFlag")
3658 parser.setError (Aborted,"Nothing selected");
3659 } else if (! selbi )
3661 parser.setError (Aborted,"Type of selection is not a branch");
3662 } else if (parser.checkParCount(1))
3664 s=parser.parString(ok,0);
3666 selbi->activateStandardFlag(s);
3668 /////////////////////////////////////////////////////////////////////
3669 } else if (com=="setFrameType")
3671 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3673 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3675 else if (parser.checkParCount(1))
3677 s=parser.parString(ok,0);
3678 if (ok) setFrameType (s);
3680 /////////////////////////////////////////////////////////////////////
3681 } else if (com=="setFramePenColor")
3683 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3685 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3687 else if (parser.checkParCount(1))
3689 QColor c=parser.parColor(ok,0);
3690 if (ok) setFramePenColor (c);
3692 /////////////////////////////////////////////////////////////////////
3693 } else if (com=="setFrameBrushColor")
3695 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3697 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3699 else if (parser.checkParCount(1))
3701 QColor c=parser.parColor(ok,0);
3702 if (ok) setFrameBrushColor (c);
3704 /////////////////////////////////////////////////////////////////////
3705 } else if (com=="setFramePadding")
3707 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3709 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3711 else if (parser.checkParCount(1))
3713 n=parser.parInt(ok,0);
3714 if (ok) setFramePadding(n);
3716 /////////////////////////////////////////////////////////////////////
3717 } else if (com=="setFrameBorderWidth")
3719 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3721 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3723 else if (parser.checkParCount(1))
3725 n=parser.parInt(ok,0);
3726 if (ok) setFrameBorderWidth (n);
3728 /////////////////////////////////////////////////////////////////////
3729 /* FIXME-2 else if (com=="setFrameType")
3733 parser.setError (Aborted,"Nothing selected");
3736 parser.setError (Aborted,"Type of selection is not a branch");
3737 } else if (parser.checkParCount(1))
3739 s=parser.parString(ok,0);
3743 /////////////////////////////////////////////////////////////////////
3745 /////////////////////////////////////////////////////////////////////
3746 } else if (com=="setHeading")
3750 parser.setError (Aborted,"Nothing selected");
3751 } else if (! selbi )
3753 parser.setError (Aborted,"Type of selection is not a branch");
3754 } else if (parser.checkParCount(1))
3756 s=parser.parString (ok,0);
3760 /////////////////////////////////////////////////////////////////////
3761 } else if (com=="setHideExport")
3765 parser.setError (Aborted,"Nothing selected");
3766 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3768 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3769 } else if (parser.checkParCount(1))
3771 b=parser.parBool(ok,0);
3772 if (ok) setHideExport (b);
3774 /////////////////////////////////////////////////////////////////////
3775 } else if (com=="setIncludeImagesHorizontally")
3779 parser.setError (Aborted,"Nothing selected");
3782 parser.setError (Aborted,"Type of selection is not a branch");
3783 } else if (parser.checkParCount(1))
3785 b=parser.parBool(ok,0);
3786 if (ok) setIncludeImagesHor(b);
3788 /////////////////////////////////////////////////////////////////////
3789 } else if (com=="setIncludeImagesVertically")
3793 parser.setError (Aborted,"Nothing selected");
3796 parser.setError (Aborted,"Type of selection is not a branch");
3797 } else if (parser.checkParCount(1))
3799 b=parser.parBool(ok,0);
3800 if (ok) setIncludeImagesVer(b);
3802 /////////////////////////////////////////////////////////////////////
3803 } else if (com=="setHideLinkUnselected")
3807 parser.setError (Aborted,"Nothing selected");
3808 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3810 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3811 } else if (parser.checkParCount(1))
3813 b=parser.parBool(ok,0);
3814 if (ok) setHideLinkUnselected(b);
3816 /////////////////////////////////////////////////////////////////////
3817 } else if (com=="setMapAuthor")
3819 if (parser.checkParCount(1))
3821 s=parser.parString(ok,0);
3822 if (ok) setAuthor (s);
3824 /////////////////////////////////////////////////////////////////////
3825 } else if (com=="setMapComment")
3827 if (parser.checkParCount(1))
3829 s=parser.parString(ok,0);
3830 if (ok) setComment(s);
3832 /////////////////////////////////////////////////////////////////////
3833 } else if (com=="setMapBackgroundColor")
3837 parser.setError (Aborted,"Nothing selected");
3838 } else if (! selbi )
3840 parser.setError (Aborted,"Type of selection is not a branch");
3841 } else if (parser.checkParCount(1))
3843 QColor c=parser.parColor (ok,0);
3844 if (ok) setMapBackgroundColor (c);
3846 /////////////////////////////////////////////////////////////////////
3847 } else if (com=="setMapDefLinkColor")
3851 parser.setError (Aborted,"Nothing selected");
3852 } else if (! selbi )
3854 parser.setError (Aborted,"Type of selection is not a branch");
3855 } else if (parser.checkParCount(1))
3857 QColor c=parser.parColor (ok,0);
3858 if (ok) setMapDefLinkColor (c);
3860 /////////////////////////////////////////////////////////////////////
3861 } else if (com=="setMapLinkStyle")
3863 if (parser.checkParCount(1))
3865 s=parser.parString (ok,0);
3866 if (ok) setMapLinkStyle(s);
3868 /////////////////////////////////////////////////////////////////////
3869 } else if (com=="setNote")
3873 parser.setError (Aborted,"Nothing selected");
3874 } else if (! selbi )
3876 parser.setError (Aborted,"Type of selection is not a branch");
3877 } else if (parser.checkParCount(1))
3879 s=parser.parString (ok,0);
3883 /////////////////////////////////////////////////////////////////////
3884 } else if (com=="setSelectionColor")
3886 if (parser.checkParCount(1))
3888 QColor c=parser.parColor (ok,0);
3889 if (ok) setSelectionColorInt (c);
3891 /////////////////////////////////////////////////////////////////////
3892 } else if (com=="setURL")
3896 parser.setError (Aborted,"Nothing selected");
3897 } else if (! selbi )
3899 parser.setError (Aborted,"Type of selection is not a branch");
3900 } else if (parser.checkParCount(1))
3902 s=parser.parString (ok,0);
3905 /////////////////////////////////////////////////////////////////////
3906 } else if (com=="setVymLink")
3910 parser.setError (Aborted,"Nothing selected");
3911 } else if (! selbi )
3913 parser.setError (Aborted,"Type of selection is not a branch");
3914 } else if (parser.checkParCount(1))
3916 s=parser.parString (ok,0);
3917 if (ok) setVymLink(s);
3919 } else if (com=="sortChildren")
3923 parser.setError (Aborted,"Nothing selected");
3924 } else if (! selbi )
3926 parser.setError (Aborted,"Type of selection is not a branch");
3927 } else if (parser.checkParCount(0))
3931 /////////////////////////////////////////////////////////////////////
3932 } else if (com=="toggleFlag")
3936 parser.setError (Aborted,"Nothing selected");
3937 } else if (! selbi )
3939 parser.setError (Aborted,"Type of selection is not a branch");
3940 } else if (parser.checkParCount(1))
3942 s=parser.parString(ok,0);
3944 selbi->toggleStandardFlag(s);
3946 /////////////////////////////////////////////////////////////////////
3947 } else if (com=="unscroll")
3951 parser.setError (Aborted,"Nothing selected");
3952 } else if (! selbi )
3954 parser.setError (Aborted,"Type of selection is not a branch");
3955 } else if (parser.checkParCount(0))
3957 if (!unscrollBranch (selbi))
3958 parser.setError (Aborted,"Could not unscroll branch");
3960 /////////////////////////////////////////////////////////////////////
3961 } else if (com=="unscrollChildren")
3965 parser.setError (Aborted,"Nothing selected");
3966 } else if (! selbi )
3968 parser.setError (Aborted,"Type of selection is not a branch");
3969 } else if (parser.checkParCount(0))
3971 unscrollChildren ();
3973 /////////////////////////////////////////////////////////////////////
3974 } else if (com=="unsetFlag")
3978 parser.setError (Aborted,"Nothing selected");
3979 } else if (! selbi )
3981 parser.setError (Aborted,"Type of selection is not a branch");
3982 } else if (parser.checkParCount(1))
3984 s=parser.parString(ok,0);
3986 selbi->deactivateStandardFlag(s);
3989 parser.setError (Aborted,"Unknown command");
3992 if (parser.errorLevel()==NoError)
3994 // setChanged(); FIXME-2 should not be called e.g. for export?!
4001 // TODO Error handling
4002 qWarning("VymModel::parseAtom: Error!");
4004 qWarning(parser.errorMessage());
4006 errorMsg=parser.errorMessage();
4011 QVariant VymModel::runScript (const QString &script)
4013 parser.setScript (script);
4018 while (parser.next() && noErr)
4020 r=parseAtom(parser.getAtom(),noErr,errMsg);
4021 if (!noErr) //FIXME-3 need dialog box here
4022 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4027 void VymModel::setExportMode (bool b)
4029 // should be called before and after exports
4030 // depending on the settings
4031 if (b && settings.value("/export/useHideExport","true")=="true")
4032 setHideTmpMode (TreeItem::HideExport);
4034 setHideTmpMode (TreeItem::HideNone);
4037 void VymModel::exportImage(QString fname, bool askName, QString format)
4041 fname=getMapName()+".png";
4048 QFileDialog *fd=new QFileDialog (NULL);
4049 fd->setCaption (tr("Export map as image"));
4050 fd->setDirectory (lastImageDir);
4051 fd->setFileMode(QFileDialog::AnyFile);
4052 fd->setFilters (imageIO.getFilters() );
4055 fl=fd->selectedFiles();
4057 format=imageIO.getType(fd->selectedFilter());
4061 setExportMode (true);
4062 QPixmap pix (mapEditor->getPixmap());
4063 pix.save(fname, format);
4064 setExportMode (false);
4068 void VymModel::exportXML(QString dir, bool askForName)
4072 dir=browseDirectory(NULL,tr("Export XML to directory"));
4073 if (dir =="" && !reallyWriteDirectory(dir) )
4077 // Hide stuff during export, if settings want this
4078 setExportMode (true);
4080 // Create subdirectories
4083 // write to directory //FIXME-4 check totalBBox here...
4084 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4087 file.setName ( dir + "/"+mapName+".xml");
4088 if ( !file.open( QIODevice::WriteOnly ) )
4090 // This should neverever happen
4091 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4095 // Write it finally, and write in UTF8, no matter what
4096 QTextStream ts( &file );
4097 ts.setEncoding (QTextStream::UnicodeUTF8);
4101 // Now write image, too
4102 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4104 setExportMode (false);
4107 void VymModel::exportAO (QString fname,bool askName)
4112 ex.setFile (mapName+".txt");
4118 //ex.addFilter ("TXT (*.txt)");
4119 ex.setDir(lastImageDir);
4120 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4125 setExportMode(true);
4127 setExportMode(false);
4131 void VymModel::exportASCII(QString fname,bool askName)
4136 ex.setFile (mapName+".txt");
4142 //ex.addFilter ("TXT (*.txt)");
4143 ex.setDir(lastImageDir);
4144 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4149 setExportMode(true);
4151 setExportMode(false);
4155 void VymModel::exportXHTML (const QString &dir, bool askForName)
4157 ExportXHTMLDialog dia(NULL);
4158 dia.setFilePath (filePath );
4159 dia.setMapName (mapName );
4161 if (dir!="") dia.setDir (dir);
4167 if (dia.exec()!=QDialog::Accepted)
4171 QDir d (dia.getDir());
4172 // Check, if warnings should be used before overwriting
4173 // the output directory
4174 if (d.exists() && d.count()>0)
4177 warn.showCancelButton (true);
4178 warn.setText(QString(
4179 "The directory %1 is not empty.\n"
4180 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4181 warn.setCaption("Warning: Directory not empty");
4182 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4184 if (warn.exec()!=QDialog::Accepted) ok=false;
4191 exportXML (dia.getDir(),false );
4192 dia.doExport(mapName );
4193 //if (dia.hasChanged()) setChanged();
4197 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4202 if (ex.setConfigFile(cf))
4204 setExportMode (true);
4205 ex.exportPresentation();
4206 setExportMode (false);
4213 //////////////////////////////////////////////
4215 //////////////////////////////////////////////
4217 void VymModel::registerEditor(QWidget *me)
4219 mapEditor=(MapEditor*)me;
4222 void VymModel::unregisterEditor(QWidget *)
4227 void VymModel::setContextPos(QPointF p)
4232 void VymModel::unsetContextPos()
4234 contextPos=QPointF();
4237 void VymModel::updateNoteFlag()
4240 TreeItem *selti=getSelectedItem();
4243 if (textEditor->isEmpty())
4246 selti->setNote (textEditor->getText());
4247 emitDataHasChanged(selti);
4248 emitSelectionChanged();
4253 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4255 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4256 if (blockReposition) return;
4258 for (int i=0;i<rootItem->branchCount(); i++)
4259 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4260 //emitSelectionChanged();
4264 void VymModel::setMapLinkStyle (const QString & s)
4269 case LinkableMapObj::Line :
4272 case LinkableMapObj::Parabel:
4273 snow="StyleParabel";
4275 case LinkableMapObj::PolyLine:
4276 snow="StylePolyLine";
4278 case LinkableMapObj::PolyParabel:
4279 snow="StylePolyParabel";
4282 snow="UndefinedStyle";
4287 QString("setMapLinkStyle (\"%1\")").arg(s),
4288 QString("setMapLinkStyle (\"%1\")").arg(snow),
4289 QString("Set map link style (\"%1\")").arg(s)
4293 linkstyle=LinkableMapObj::Line;
4294 else if (s=="StyleParabel")
4295 linkstyle=LinkableMapObj::Parabel;
4296 else if (s=="StylePolyLine")
4297 linkstyle=LinkableMapObj::PolyLine;
4298 else if (s=="StylePolyParabel")
4299 linkstyle=LinkableMapObj::PolyParabel;
4301 linkstyle=LinkableMapObj::UndefinedStyle;
4303 BranchItem *cur=NULL;
4304 BranchItem *prev=NULL;
4306 nextBranch (cur,prev);
4309 bo=(BranchObj*)(cur->getLMO() );
4310 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4311 cur=nextBranch(cur,prev);
4316 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4321 void VymModel::setMapDefLinkColor(QColor col)
4323 if ( !col.isValid() ) return;
4325 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4326 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4327 QString("Set map link color to %1").arg(col.name())
4331 BranchItem *cur=NULL;
4332 BranchItem *prev=NULL;
4334 cur=nextBranch(cur,prev);
4337 bo=(BranchObj*)(cur->getLMO() );
4339 nextBranch(cur,prev);
4344 void VymModel::setMapLinkColorHintInt()
4346 // called from setMapLinkColorHint(lch) or at end of parse
4347 BranchItem *cur=NULL;
4348 BranchItem *prev=NULL;
4350 cur=nextBranch(cur,prev);
4353 bo=(BranchObj*)(cur->getLMO() );
4355 cur=nextBranch(cur,prev);
4359 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4362 setMapLinkColorHintInt();
4365 void VymModel::toggleMapLinkColorHint()
4367 if (linkcolorhint==LinkableMapObj::HeadingColor)
4368 linkcolorhint=LinkableMapObj::DefaultColor;
4370 linkcolorhint=LinkableMapObj::HeadingColor;
4371 BranchItem *cur=NULL;
4372 BranchItem *prev=NULL;
4374 cur=nextBranch(cur,prev);
4377 bo=(BranchObj*)(cur->getLMO() );
4379 nextBranch(cur,prev);
4383 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4384 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4386 Q3FileDialog *fd=new Q3FileDialog( NULL);
4387 fd->setMode (Q3FileDialog::ExistingFile);
4388 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4389 ImagePreview *p =new ImagePreview (fd);
4390 fd->setContentsPreviewEnabled( TRUE );
4391 fd->setContentsPreview( p, p );
4392 fd->setPreviewMode( Q3FileDialog::Contents );
4393 fd->setCaption(vymName+" - " +tr("Load background image"));
4394 fd->setDir (lastImageDir);
4397 if ( fd->exec() == QDialog::Accepted )
4399 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4400 lastImageDir=QDir (fd->dirPath());
4401 setMapBackgroundImage (fd->selectedFile());
4405 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4407 QColor oldcol=mapScene->backgroundBrush().color();
4411 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4413 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4414 QString("Set background color of map to %1").arg(col.name()));
4417 brush.setTextureImage (QPixmap (fn));
4418 mapScene->setBackgroundBrush(brush);
4421 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4423 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4424 if ( !col.isValid() ) return;
4425 setMapBackgroundColor( col );
4429 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4431 QColor oldcol=mapScene->backgroundBrush().color();
4433 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4434 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4435 QString("Set background color of map to %1").arg(col.name()));
4436 mapScene->setBackgroundBrush(col);
4439 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4441 return mapScene->backgroundBrush().color();
4445 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4447 return linkcolorhint;
4450 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4452 return defLinkColor;
4455 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4460 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4462 return defXLinkColor;
4465 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4470 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4472 return defXLinkWidth;
4475 void VymModel::move(const double &x, const double &y)
4478 MapItem *seli = (MapItem*)getSelectedItem();
4479 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4481 LinkableMapObj *lmo=seli->getLMO();
4484 QPointF ap(lmo->getAbsPos());
4488 QString ps=qpointFToString(ap);
4489 QString s=getSelectString(seli);
4492 s, "move "+qpointFToString(to),
4493 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4496 emitSelectionChanged();
4502 void VymModel::moveRel (const double &x, const double &y)
4505 MapItem *seli = (MapItem*)getSelectedItem();
4506 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4508 LinkableMapObj *lmo=seli->getLMO();
4511 QPointF rp(lmo->getRelPos());
4515 QString ps=qpointFToString (lmo->getRelPos());
4516 QString s=getSelectString(seli);
4519 s, "moveRel "+qpointFToString(to),
4520 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4521 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4523 lmo->updateLinkGeometry();
4524 emitSelectionChanged();
4531 void VymModel::animate()
4533 animationTimer->stop();
4536 while (i<animObjList.size() )
4538 bo=(BranchObj*)animObjList.at(i);
4543 animObjList.removeAt(i);
4550 QItemSelection sel=selModel->selection();
4551 emit (selectionChanged(sel,sel));
4554 if (!animObjList.isEmpty()) animationTimer->start();
4558 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4560 if (start==dest) return;
4561 if (bo && bo->getTreeItem()->depth()>0)
4564 ap.setStart (start);
4566 ap.setTicks (animationTicks);
4567 ap.setAnimated (true);
4568 bo->setAnimation (ap);
4569 animObjList.append( bo );
4570 animationTimer->setSingleShot (true);
4571 animationTimer->start(animationInterval);
4575 void VymModel::stopAnimation (MapObj *mo)
4577 int i=animObjList.indexOf(mo);
4579 animObjList.removeAt (i);
4582 void VymModel::sendSelection()
4584 if (netstate!=Server) return;
4585 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4588 void VymModel::newServer()
4592 tcpServer = new QTcpServer(this);
4593 if (!tcpServer->listen(QHostAddress::Any,port)) {
4594 QMessageBox::critical(NULL, "vym server",
4595 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4596 //FIXME-3 needed? we are no widget any longer... close();
4599 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4601 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4604 void VymModel::connectToServer()
4607 server="salam.suse.de";
4609 clientSocket = new QTcpSocket (this);
4610 clientSocket->abort();
4611 clientSocket->connectToHost(server ,port);
4612 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4613 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4614 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4616 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4621 void VymModel::newClient()
4623 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4624 connect(newClient, SIGNAL(disconnected()),
4625 newClient, SLOT(deleteLater()));
4627 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4629 clientList.append (newClient);
4633 void VymModel::sendData(const QString &s)
4635 if (clientList.size()==0) return;
4637 // Create bytearray to send
4639 QDataStream out(&block, QIODevice::WriteOnly);
4640 out.setVersion(QDataStream::Qt_4_0);
4642 // Reserve some space for blocksize
4645 // Write sendCounter
4646 out << sendCounter++;
4651 // Go back and write blocksize so far
4652 out.device()->seek(0);
4653 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4657 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4659 for (int i=0; i<clientList.size(); ++i)
4661 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4662 clientList.at(i)->write (block);
4666 void VymModel::readData ()
4668 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4671 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4675 QDataStream in(clientSocket);
4676 in.setVersion(QDataStream::Qt_4_0);
4684 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4687 parseAtom (t,noErr,errMsg);
4693 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4695 switch (socketError) {
4696 case QAbstractSocket::RemoteHostClosedError:
4698 case QAbstractSocket::HostNotFoundError:
4699 QMessageBox::information(NULL, vymName +" Network client",
4700 "The host was not found. Please check the "
4701 "host name and port settings.");
4703 case QAbstractSocket::ConnectionRefusedError:
4704 QMessageBox::information(NULL, vymName + " Network client",
4705 "The connection was refused by the peer. "
4706 "Make sure the fortune server is running, "
4707 "and check that the host name and port "
4708 "settings are correct.");
4711 QMessageBox::information(NULL, vymName + " Network client",
4712 QString("The following error occurred: %1.")
4713 .arg(clientSocket->errorString()));
4717 /* FIXME-3 Playing with DBUS...
4718 QDBusVariant VymModel::query (const QString &query)
4720 TreeItem *selti=getSelectedItem();
4722 return QDBusVariant (selti->getHeading());
4724 return QDBusVariant ("Nothing selected.");
4728 void VymModel::testslot() //FIXME-3 Playing with DBUS
4730 cout << "VM::testslot called\n";
4733 void VymModel::selectMapSelectionColor()
4735 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4736 setSelectionColor (col);
4739 void VymModel::setSelectionColorInt (QColor col)
4741 if ( !col.isValid() ) return;
4743 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4744 QString("setSelectionColor (%1)").arg(col.name()),
4745 QString("Set color of selection box to %1").arg(col.name())
4748 mapEditor->setSelectionColor (col);
4751 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4753 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4754 //FIXME-3 emitShowSelection();
4758 void VymModel::emitSelectionChanged()
4760 QItemSelection newsel=selModel->selection();
4761 emitSelectionChanged (newsel);
4764 void VymModel::setSelectionColor(QColor col)
4766 if ( !col.isValid() ) return;
4768 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4769 QString("setSelectionColor (%1)").arg(col.name()),
4770 QString("Set color of selection box to %1").arg(col.name())
4772 setSelectionColorInt (col);
4775 QColor VymModel::getSelectionColor()
4777 return mapEditor->getSelectionColor();
4780 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4783 for (int i=0;i<rootItem->childCount();i++)
4784 rootItem->child(i)->setHideTmp (mode);
4786 // FIXME-3 needed? scene()->update();
4789 //////////////////////////////////////////////
4790 // Selection related
4791 //////////////////////////////////////////////
4793 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4798 QItemSelectionModel* VymModel::getSelectionModel()
4803 void VymModel::setSelectionBlocked (bool b)
4808 bool VymModel::isSelectionBlocked()
4810 return selectionBlocked;
4813 bool VymModel::select ()
4815 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4818 bool VymModel::select (const QString &s)
4825 TreeItem *ti=findBySelectString(s);
4826 if (ti) return select (index(ti));
4830 bool VymModel::select (LinkableMapObj *lmo)
4832 QItemSelection oldsel=selModel->selection();
4835 return select (index (lmo->getTreeItem()) );
4840 bool VymModel::select (TreeItem *ti)
4842 if (ti) return select (index(ti));
4846 bool VymModel::select (const QModelIndex &index)
4848 if (index.isValid() )
4850 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4851 BranchItem *bi=getSelectedBranch();
4852 if (bi) bi->setLastSelectedBranch();
4858 void VymModel::unselect()
4860 if (!selModel->selectedIndexes().isEmpty())
4862 lastSelectString=getSelectString();
4863 selModel->clearSelection();
4867 bool VymModel::reselect()
4869 return select (lastSelectString);
4872 void VymModel::emitShowSelection()
4874 if (!blockReposition)
4875 emit (showSelection() );
4878 void VymModel::emitNoteHasChanged (TreeItem *ti)
4880 QModelIndex ix=index(ti);
4881 emit (noteHasChanged (ix) );
4884 void VymModel::emitDataHasChanged (TreeItem *ti)
4886 QModelIndex ix=index(ti);
4887 emit (dataChanged (ix,ix) );
4891 bool VymModel::selectFirstBranch()
4893 TreeItem *ti=getSelectedBranch();
4896 TreeItem *par=ti->parent();
4899 TreeItem *ti2=par->getFirstBranch();
4900 if (ti2) return select(ti2);
4906 bool VymModel::selectLastBranch()
4908 TreeItem *ti=getSelectedBranch();
4911 TreeItem *par=ti->parent();
4914 TreeItem *ti2=par->getLastBranch();
4915 if (ti2) return select(ti2);
4921 bool VymModel::selectLastSelectedBranch()
4923 BranchItem *bi=getSelectedBranch();
4926 bi=bi->getLastSelectedBranch();
4927 if (bi) return select (bi);
4932 bool VymModel::selectParent()
4934 TreeItem *ti=getSelectedItem();
4945 TreeItem::Type VymModel::selectionType()
4947 QModelIndexList list=selModel->selectedIndexes();
4948 if (list.isEmpty()) return TreeItem::Undefined;
4949 TreeItem *ti = getItem (list.first() );
4950 return ti->getType();
4954 LinkableMapObj* VymModel::getSelectedLMO()
4956 QModelIndexList list=selModel->selectedIndexes();
4957 if (!list.isEmpty() )
4959 TreeItem *ti = getItem (list.first() );
4960 TreeItem::Type type=ti->getType();
4961 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4962 return ((MapItem*)ti)->getLMO();
4967 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4969 TreeItem *ti = getSelectedBranch();
4971 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4976 BranchItem* VymModel::getSelectedBranch()
4978 QModelIndexList list=selModel->selectedIndexes();
4979 if (!list.isEmpty() )
4981 TreeItem *ti = getItem (list.first() );
4982 TreeItem::Type type=ti->getType();
4983 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4984 return (BranchItem*)ti;
4989 ImageItem* VymModel::getSelectedImage()
4991 QModelIndexList list=selModel->selectedIndexes();
4992 if (!list.isEmpty())
4994 TreeItem *ti=getItem (list.first());
4995 if (ti && ti->getType()==TreeItem::Image)
4996 return (ImageItem*)ti;
5001 AttributeItem* VymModel::getSelectedAttribute()
5003 QModelIndexList list=selModel->selectedIndexes();
5004 if (!list.isEmpty() )
5006 TreeItem *ti = getItem (list.first() );
5007 TreeItem::Type type=ti->getType();
5008 if (type ==TreeItem::Attribute)
5009 return (AttributeItem*)ti;
5014 TreeItem* VymModel::getSelectedItem()
5016 QModelIndexList list=selModel->selectedIndexes();
5017 if (!list.isEmpty() )
5018 return getItem (list.first() );
5023 QModelIndex VymModel::getSelectedIndex()
5025 QModelIndexList list=selModel->selectedIndexes();
5026 if (list.isEmpty() )
5027 return QModelIndex();
5029 return list.first();
5032 QString VymModel::getSelectString ()
5034 return getSelectString (getSelectedItem());
5037 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5039 if (!lmo) return QString();
5040 return getSelectString (lmo->getTreeItem() );
5043 QString VymModel::getSelectString (TreeItem *ti)
5047 switch (ti->getType())
5049 case TreeItem::MapCenter: s="mc:"; break;
5050 case TreeItem::Branch: s="bo:";break;
5051 case TreeItem::Image: s="fi:";break;
5052 case TreeItem::Attribute: s="ai:";break;
5053 case TreeItem::XLink: s="xl:";break;
5055 s="unknown type in VymModel::getSelectString()";
5058 s= s + QString("%1").arg(ti->num());
5060 // call myself recursively
5061 s= getSelectString(ti->parent()) +","+s;