1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
18 #include "warningdialog.h"
19 #include "xlinkitem.h"
20 #include "xml-freemind.h"
26 extern Main *mainWindow;
27 extern QDBusConnection dbusConnection;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
33 extern FlagRow *standardFlagsMaster;
35 extern QString clipboardDir;
36 extern QString clipboardFile;
37 extern bool clipboardEmpty;
39 extern ImageIO imageIO;
41 extern QString vymName;
42 extern QString vymVersion;
43 extern QDir vymBaseDir;
45 extern QDir lastImageDir;
46 extern QDir lastFileDir;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 //cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 //cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 while (rootItem->childCount() >0)
73 deleteItem (rootItem->getChildNum(0) );
76 void VymModel::init ()
81 // Also no scene yet (should not be needed anyway) FIXME-3 VM
94 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
95 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
96 mainWindow->updateHistory (undoSet);
104 fileName=tr("unnamed");
106 blockReposition=false;
107 blockSaveState=false;
109 autosaveTimer=new QTimer (this);
110 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
112 fileChangedTimer=new QTimer (this);
113 fileChangedTimer->start(3000);
114 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
119 selectionBlocked=false;
124 // animations // FIXME-3 switch to new animation system
125 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
126 animationTicks=settings.readNumEntry("/animation/ticks",10);
127 animationInterval=settings.readNumEntry("/animation/interval",50);
129 animationTimer=new QTimer (this);
130 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
133 defLinkColor=QColor (0,0,255);
134 defXLinkColor=QColor (180,180,180);
135 linkcolorhint=LinkableMapObj::DefaultColor;
136 linkstyle=LinkableMapObj::PolyParabel;
138 defXLinkColor=QColor (230,230,230);
140 hidemode=TreeItem::HideNone;
146 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
148 //Initialize DBUS object
149 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
150 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
151 qWarning ("VymModel: Couldn't register DBUS object!");
154 void VymModel::makeTmpDirectories()
156 // Create unique temporary directories
157 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
158 histPath = tmpMapDir+"/history";
164 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
169 bool VymModel::isRepositionBlocked()
171 return blockReposition;
174 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
176 //cout << "VM::updateActions \n";
177 // Tell mainwindow to update states of actions
178 mainWindow->updateActions();
183 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
185 // tmpdir temporary directory to which data will be written
186 // prefix mapname, which will be appended to images etc.
187 // writeflags Only write flags for "real" save of map, not undo
188 // offset offset of bbox of whole map in scene.
189 // Needed for XML export
198 case LinkableMapObj::Line:
201 case LinkableMapObj::Parabel:
204 case LinkableMapObj::PolyLine:
208 ls="StylePolyParabel";
212 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
214 if (linkcolorhint==LinkableMapObj::HeadingColor)
215 colhint=xml.attribut("linkColorHint","HeadingColor");
217 QString mapAttr=xml.attribut("version",vymVersion);
219 mapAttr+= xml.attribut("author",author) +
220 xml.attribut("comment",comment) +
221 xml.attribut("date",getDate()) +
222 xml.attribut("branchCount", QString().number(branchCount())) +
223 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
224 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
225 xml.attribut("linkStyle", ls ) +
226 xml.attribut("linkColor", defLinkColor.name() ) +
227 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
228 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
230 s+=xml.beginElement("vymmap",mapAttr);
233 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
234 standardFlagsMaster->resetUsedCounter();
236 // Build xml recursivly
238 // Save all mapcenters as complete map, if saveSel not set
239 s+=saveTreeToDir(tmpdir,prefix,offset);
242 switch (saveSel->getType())
244 case TreeItem::Branch:
246 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
248 case TreeItem::MapCenter:
250 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
252 case TreeItem::Image:
254 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
257 // other types shouldn't be safed directly...
262 // Save local settings
263 s+=settings.getDataXML (destPath);
266 if (getSelectedItem() && !saveSel )
267 s+=xml.valueElement("select",getSelectString());
270 s+=xml.endElement("vymmap");
272 //cout << s.toStdString() << endl;
274 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
278 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
282 for (int i=0; i<rootItem->branchCount(); i++)
283 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
287 void VymModel::setFilePath(QString fpath, QString destname)
289 if (fpath.isEmpty() || fpath=="")
296 filePath=fpath; // becomes absolute path
297 fileName=fpath; // gets stripped of path
298 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
300 // If fpath is not an absolute path, complete it
301 filePath=QDir(fpath).absPath();
302 fileDir=filePath.left (1+filePath.findRev ("/"));
304 // Set short name, too. Search from behind:
305 int i=fileName.findRev("/");
306 if (i>=0) fileName=fileName.remove (0,i+1);
308 // Forget the .vym (or .xml) for name of map
309 mapName=fileName.left(fileName.findRev(".",-1,true) );
313 void VymModel::setFilePath(QString fpath)
315 setFilePath (fpath,fpath);
318 QString VymModel::getFilePath()
323 QString VymModel::getFileName()
328 QString VymModel::getMapName()
333 QString VymModel::getDestPath()
338 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
340 ErrorCode err=success;
342 parseBaseHandler *handler;
346 case VymMap: handler=new parseVYMHandler; break;
347 case FreemindMap : handler=new parseFreemindHandler; break;
349 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
350 "Unknown FileType in VymModel::load()");
354 bool zipped_org=zipped;
358 selModel->clearSelection();
359 // FIXME-2 VM not needed??? model->setMapEditor(this);
360 // (map state is set later at end of load...)
363 BranchItem *bi=getSelectedBranch();
364 if (!bi) return aborted;
365 if (lmode==ImportAdd)
366 saveStateChangingPart(
369 QString("addMapInsert (%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 saveStateChangingPart(
375 QString("addMapReplace(%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
380 // Create temporary directory for packing
382 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
385 QMessageBox::critical( 0, tr( "Critical Load Error" ),
386 tr("Couldn't create temporary directory before load\n"));
391 err=unzipDir (tmpZipDir,fname);
401 // Look for mapname.xml
402 xmlfile= fname.left(fname.findRev(".",-1,true));
403 xmlfile=xmlfile.section( '/', -1 );
404 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
405 if (!mfile.exists() )
407 // mapname.xml does not exist, well,
408 // maybe someone renamed the mapname.vym file...
409 // Try to find any .xml in the toplevel
410 // directory of the .vym file
411 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
412 if (flist.count()==1)
414 // Only one entry, take this one
415 xmlfile=tmpZipDir + "/"+flist.first();
418 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
419 *it=tmpZipDir + "/" + *it;
420 // TODO Multiple entries, load all (but only the first one into this ME)
421 //mainWindow->fileLoadFromTmp (flist);
422 //returnCode=1; // Silently forget this attempt to load
423 qWarning ("MainWindow::load (fn) multimap found...");
426 if (flist.isEmpty() )
428 QMessageBox::critical( 0, tr( "Critical Load Error" ),
429 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
432 } //file doesn't exist
434 xmlfile=mfile.name();
437 QFile file( xmlfile);
439 // I am paranoid: file should exist anyway
440 // according to check in mainwindow.
443 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
444 tr(QString("Couldn't open map %1").arg(file.name())));
448 bool blockSaveStateOrg=blockSaveState;
449 blockReposition=true;
451 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
452 QXmlInputSource source( file);
453 QXmlSimpleReader reader;
454 reader.setContentHandler( handler );
455 reader.setErrorHandler( handler );
456 handler->setModel ( this);
459 // We need to set the tmpDir in order to load files with rel. path
464 tmpdir=fname.left(fname.findRev("/",-1));
465 handler->setTmpDir (tmpdir);
466 handler->setInputFile (file.name());
467 handler->setLoadMode (lmode);
468 bool ok = reader.parse( source );
469 blockReposition=false;
470 blockSaveState=blockSaveStateOrg;
471 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
475 reposition(); // FIXME-2 VM reposition the view instead...
476 emitSelectionChanged();
482 autosaveTimer->stop();
485 // Reset timestamp to check for later updates of file
486 fileChangedTime=QFileInfo (destPath).lastModified();
489 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
490 tr( handler->errorProtocol() ) );
492 // Still return "success": the map maybe at least
493 // partially read by the parser
498 removeDir (QDir(tmpZipDir));
500 // Restore original zip state
507 ErrorCode VymModel::save (const SaveMode &savemode)
511 QString safeFilePath;
513 ErrorCode err=success;
517 mapFileName=mapName+".xml";
519 // use name given by user, even if he chooses .doc
520 mapFileName=fileName;
522 // Look, if we should zip the data:
525 QMessageBox mb( vymName,
526 tr("The map %1\ndid not use the compressed "
527 "vym file format.\nWriting it uncompressed will also write images \n"
528 "and flags and thus may overwrite files in the "
529 "given directory\n\nDo you want to write the map").arg(filePath),
530 QMessageBox::Warning,
531 QMessageBox::Yes | QMessageBox::Default,
533 QMessageBox::Cancel | QMessageBox::Escape);
534 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
535 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
536 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
539 case QMessageBox::Yes:
540 // save compressed (default file format)
543 case QMessageBox::No:
547 case QMessageBox::Cancel:
554 // First backup existing file, we
555 // don't want to add to old zip archives
559 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
561 QString backupFileName(destPath + "~");
562 QFile backupFile(backupFileName);
563 if (backupFile.exists() && !backupFile.remove())
565 QMessageBox::warning(0, tr("Save Error"),
566 tr("%1\ncould not be removed before saving").arg(backupFileName));
568 else if (!f.rename(backupFileName))
570 QMessageBox::warning(0, tr("Save Error"),
571 tr("%1\ncould not be renamed before saving").arg(destPath));
578 // Create temporary directory for packing
580 tmpZipDir=makeTmpDir (ok,"vym-zip");
583 QMessageBox::critical( 0, tr( "Critical Load Error" ),
584 tr("Couldn't create temporary directory before save\n"));
588 safeFilePath=filePath;
589 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
592 // Create mapName and fileDir
593 makeSubDirs (fileDir);
596 if (savemode==CompleteMap || selModel->selection().isEmpty())
599 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
602 autosaveTimer->stop();
607 if (selectionType()==TreeItem::Image)
610 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
611 // TODO take care of multiselections
614 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
617 qWarning ("ME::saveStringToDisk failed!");
623 if (err==success) err=zipDir (tmpZipDir,destPath);
626 removeDir (QDir(tmpZipDir));
628 // Restore original filepath outside of tmp zip dir
629 setFilePath (safeFilePath);
633 fileChangedTime=QFileInfo (destPath).lastModified();
637 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
639 QString pathDir=path.left(path.findRev("/"));
645 // We need to parse saved XML data
646 parseVYMHandler handler;
647 QXmlInputSource source( file);
648 QXmlSimpleReader reader;
649 reader.setContentHandler( &handler );
650 reader.setErrorHandler( &handler );
651 handler.setModel ( this);
652 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
653 if (undoSel.isEmpty())
657 handler.setLoadMode (NewMap);
661 handler.setLoadMode (ImportReplace);
663 blockReposition=true;
664 bool ok = reader.parse( source );
665 blockReposition=false;
668 // This should never ever happen
669 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
670 handler.errorProtocol());
673 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
676 bool VymModel::addMapInsertInt (const QString &path)
678 QString pathDir=path.left(path.findRev("/"));
684 // We need to parse saved XML data
685 parseVYMHandler handler;
686 QXmlInputSource source( file);
687 QXmlSimpleReader reader;
688 reader.setContentHandler( &handler );
689 reader.setErrorHandler( &handler );
690 handler.setModel (this);
691 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
692 handler.setLoadMode (ImportAdd);
693 blockReposition=true;
694 bool ok = reader.parse( source );
695 blockReposition=false;
696 if ( ok ) return true;
698 // This should never ever happen
699 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
700 handler.errorProtocol());
703 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
707 bool VymModel::addMapInsertInt (const QString &path, int pos)
709 BranchItem *selbi=getSelectedBranch();
712 if (addMapInsertInt (path))
714 if (selbi->depth()>0)
715 relinkBranch (selbi->getLastBranch(), selbi,pos);
719 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
723 qWarning ("ME::addMapInsertInt nothing selected");
727 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
729 ImageItem *ii=createImage(dst);
739 void VymModel::loadFloatImage ()
741 BranchItem *selbi=getSelectedBranch();
745 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
746 fd->setMode (Q3FileDialog::ExistingFiles);
747 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
748 ImagePreview *p =new ImagePreview (fd);
749 fd->setContentsPreviewEnabled( TRUE );
750 fd->setContentsPreview( p, p );
751 fd->setPreviewMode( Q3FileDialog::Contents );
752 fd->setCaption(vymName+" - " +tr("Load image"));
753 fd->setDir (lastImageDir);
756 if ( fd->exec() == QDialog::Accepted )
758 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
759 lastImageDir=QDir (fd->dirPath());
762 for (int j=0; j<fd->selectedFiles().count(); j++)
764 s=fd->selectedFiles().at(j);
765 ii=loadFloatImageInt (selbi,s);
766 //FIXME-3 check savestate for loadImage
772 QString ("loadImage (%1)").arg(s ),
773 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
776 // TODO loadFIO error handling
777 qWarning ("Failed to load "+s);
785 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
790 void VymModel::saveFloatImage ()
792 ImageItem *ii=getSelectedImage();
795 QFileDialog *fd=new QFileDialog( NULL);
796 fd->setFilters (imageIO.getFilters());
797 fd->setCaption(vymName+" - " +tr("Save image"));
798 fd->setFileMode( QFileDialog::AnyFile );
799 fd->setDirectory (lastImageDir);
800 // fd->setSelection (fio->getOriginalFilename());
804 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
806 fn=fd->selectedFiles().at(0);
807 if (QFile (fn).exists() )
809 QMessageBox mb( vymName,
810 tr("The file %1 exists already.\n"
811 "Do you want to overwrite it?").arg(fn),
812 QMessageBox::Warning,
813 QMessageBox::Yes | QMessageBox::Default,
814 QMessageBox::Cancel | QMessageBox::Escape,
815 QMessageBox::NoButton );
817 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
818 mb.setButtonText( QMessageBox::No, tr("Cancel"));
821 case QMessageBox::Yes:
824 case QMessageBox::Cancel:
831 saveFloatImageInt (ii,fd->selectedFilter(),fn );
838 void VymModel::importDirInt(BranchItem *dst, QDir d)
840 BranchItem *selbi=getSelectedBranch();
844 // Traverse directories
845 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
846 QFileInfoList list = d.entryInfoList();
849 for (int i = 0; i < list.size(); ++i)
852 if (fi.fileName() != "." && fi.fileName() != ".." )
854 bi=addNewBranchInt(dst,-2);
855 bi->setHeading (fi.fileName() ); // FIXME-3 check this
856 bi->setHeadingColor (QColor("blue"));
858 if ( !d.cd(fi.fileName()) )
859 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
862 // Recursively add subdirs
869 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
870 list = d.entryInfoList();
872 for (int i = 0; i < list.size(); ++i)
875 bi=addNewBranchInt (dst,-2);
876 bi->setHeading (fi.fileName() );
877 bi->setHeadingColor (QColor("black"));
878 if (fi.fileName().right(4) == ".vym" )
879 bi->setVymLink (fi.filePath());
884 void VymModel::importDirInt (const QString &s)
886 BranchItem *selbi=getSelectedBranch();
889 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
892 importDirInt (selbi,d);
896 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
898 BranchItem *selbi=getSelectedBranch();
902 filters <<"VYM map (*.vym)";
903 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
904 fd->setMode (QFileDialog::DirectoryOnly);
905 fd->setFilters (filters);
906 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
910 if ( fd->exec() == QDialog::Accepted )
912 importDirInt (fd->selectedFile() );
914 //FIXME-3 VM needed? scene()->update();
920 void VymModel::autosave()
925 cout << "VymModel::autosave rejected due to missing filePath\n";
928 QDateTime now=QDateTime().currentDateTime();
930 // Disable autosave, while we have gone back in history
931 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
932 if (redosAvail>0) return;
934 // Also disable autosave for new map without filename
935 if (filePath.isEmpty()) return;
938 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
940 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
941 mainWindow->fileSave (this);
944 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
949 void VymModel::fileChanged()
951 // Check if file on disk has changed meanwhile
952 if (!filePath.isEmpty())
954 QDateTime tmod=QFileInfo (filePath).lastModified();
955 if (tmod>fileChangedTime)
957 // FIXME-2 VM switch to current mapeditor and finish lineedits...
958 QMessageBox mb( vymName,
959 tr("The file of the map on disk has changed:\n\n"
960 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
961 QMessageBox::Question,
963 QMessageBox::Cancel | QMessageBox::Default,
964 QMessageBox::NoButton );
966 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
967 mb.setButtonText( QMessageBox::No, tr("Ignore"));
970 case QMessageBox::Yes:
972 load (filePath,NewMap,fileType);
973 case QMessageBox::Cancel:
974 fileChangedTime=tmod; // allow autosave to overwrite newer file!
980 bool VymModel::isDefault()
985 void VymModel::makeDefault()
991 bool VymModel::hasChanged()
996 void VymModel::setChanged()
999 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1003 latestAddedItem=NULL;
1007 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1009 if (!lmo || !lmo->getTreeItem() ) return QString();
1010 return getObjectName (lmo->getTreeItem() );
1014 QString VymModel::getObjectName (TreeItem *ti)
1017 if (!ti) return QString("Error: NULL has no name!");
1019 if (s=="") s="unnamed";
1021 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1024 void VymModel::redo()
1026 // Can we undo at all?
1027 if (redosAvail<1) return;
1029 bool blockSaveStateOrg=blockSaveState;
1030 blockSaveState=true;
1034 if (undosAvail<stepsTotal) undosAvail++;
1036 if (curStep>stepsTotal) curStep=1;
1037 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1038 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1039 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1040 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1041 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1042 QString version=undoSet.readEntry ("/history/version");
1044 /* TODO Maybe check for version, if we save the history
1045 if (!checkVersion(version))
1046 QMessageBox::warning(0,tr("Warning"),
1047 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1050 // Find out current undo directory
1051 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1055 cout << "VymModel::redo() begin\n";
1056 cout << " undosAvail="<<undosAvail<<endl;
1057 cout << " redosAvail="<<redosAvail<<endl;
1058 cout << " curStep="<<curStep<<endl;
1059 cout << " ---------------------------"<<endl;
1060 cout << " comment="<<comment.toStdString()<<endl;
1061 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1062 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1063 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1064 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1065 cout << " ---------------------------"<<endl<<endl;
1068 // select object before redo
1069 if (!redoSelection.isEmpty())
1070 select (redoSelection);
1075 parseAtom (redoCommand,noErr,errMsg);
1077 blockSaveState=blockSaveStateOrg;
1079 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1080 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1081 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1082 undoSet.writeSettings(histPath);
1084 mainWindow->updateHistory (undoSet);
1087 /* TODO remove testing
1088 cout << "ME::redo() end\n";
1089 cout << " undosAvail="<<undosAvail<<endl;
1090 cout << " redosAvail="<<redosAvail<<endl;
1091 cout << " curStep="<<curStep<<endl;
1092 cout << " ---------------------------"<<endl<<endl;
1098 bool VymModel::isRedoAvailable()
1100 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1106 void VymModel::undo()
1108 // Can we undo at all?
1109 if (undosAvail<1) return;
1111 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1113 bool blockSaveStateOrg=blockSaveState;
1114 blockSaveState=true;
1116 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1117 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1118 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1119 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1120 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1121 QString version=undoSet.readEntry ("/history/version");
1123 /* TODO Maybe check for version, if we save the history
1124 if (!checkVersion(version))
1125 QMessageBox::warning(0,tr("Warning"),
1126 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1129 // Find out current undo directory
1130 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1132 // select object before undo
1133 if (!select (undoSelection))
1135 qWarning ("VymModel::undo() Could not select object for undo");
1142 cout << "VymModel::undo() begin\n";
1143 cout << " undosAvail="<<undosAvail<<endl;
1144 cout << " redosAvail="<<redosAvail<<endl;
1145 cout << " curStep="<<curStep<<endl;
1146 cout << " ---------------------------"<<endl;
1147 cout << " comment="<<comment.toStdString()<<endl;
1148 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1149 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1150 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1151 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1152 cout << " ---------------------------"<<endl<<endl;
1157 parseAtom (undoCommand,noErr,errMsg);
1161 if (curStep<1) curStep=stepsTotal;
1165 blockSaveState=blockSaveStateOrg;
1167 cout << "VymModel::undo() end\n";
1168 cout << " undosAvail="<<undosAvail<<endl;
1169 cout << " redosAvail="<<redosAvail<<endl;
1170 cout << " curStep="<<curStep<<endl;
1171 cout << " ---------------------------"<<endl<<endl;
1174 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1175 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1176 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1177 undoSet.writeSettings(histPath);
1179 mainWindow->updateHistory (undoSet);
1181 //emitSelectionChanged();
1184 bool VymModel::isUndoAvailable()
1186 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1192 void VymModel::gotoHistoryStep (int i)
1194 // Restore variables
1195 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1196 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1198 if (i<0) i=undosAvail+redosAvail;
1200 // Clicking above current step makes us undo things
1203 for (int j=0; j<undosAvail-i; j++) undo();
1206 // Clicking below current step makes us redo things
1208 for (int j=undosAvail; j<i; j++)
1210 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1214 // And ignore clicking the current row ;-)
1218 QString VymModel::getHistoryPath()
1220 QString histName(QString("history-%1").arg(curStep));
1221 return (tmpMapDir+"/"+histName);
1224 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1226 sendData(redoCom); //FIXME-3 testing
1231 if (blockSaveState) return;
1233 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1235 // Find out current undo directory
1236 if (undosAvail<stepsTotal) undosAvail++;
1238 if (curStep>stepsTotal) curStep=1;
1240 QString backupXML="";
1241 QString histDir=getHistoryPath();
1242 QString bakMapPath=histDir+"/map.xml";
1244 // Create histDir if not available
1247 makeSubDirs (histDir);
1249 // Save depending on how much needs to be saved
1251 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1253 QString undoCommand="";
1254 if (savemode==UndoCommand)
1256 undoCommand=undoCom;
1258 else if (savemode==PartOfMap )
1260 undoCommand=undoCom;
1261 undoCommand.replace ("PATH",bakMapPath);
1265 if (!backupXML.isEmpty())
1266 // Write XML Data to disk
1267 saveStringToDisk (bakMapPath,backupXML);
1269 // We would have to save all actions in a tree, to keep track of
1270 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1273 // Write the current state to disk
1274 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1275 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1276 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1277 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1278 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1280 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1282 undoSet.setEntry (QString("/history/version"),vymVersion);
1283 undoSet.writeSettings(histPath);
1287 // TODO remove after testing
1288 //cout << " into="<< histPath.toStdString()<<endl;
1289 cout << " stepsTotal="<<stepsTotal<<
1290 ", undosAvail="<<undosAvail<<
1291 ", redosAvail="<<redosAvail<<
1292 ", curStep="<<curStep<<endl;
1293 cout << " ---------------------------"<<endl;
1294 cout << " comment="<<comment.toStdString()<<endl;
1295 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1296 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1297 cout << " redoCom="<<redoCom.toStdString()<<endl;
1298 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1299 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1300 cout << " ---------------------------"<<endl;
1303 mainWindow->updateHistory (undoSet);
1309 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1311 // save the selected part of the map, Undo will replace part of map
1312 QString undoSelection="";
1314 undoSelection=getSelectString(undoSel);
1316 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1317 QString redoSelection="";
1319 redoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1324 saveState (PartOfMap,
1325 undoSelection, "addMapReplace (\"PATH\")",
1331 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1335 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1338 QString undoSelection;
1339 QString redoSelection=getSelectString(redoSel);
1340 if (redoSel->getType()==TreeItem::Branch)
1342 undoSelection=getSelectString (redoSel->parent());
1343 // save the selected branch of the map, Undo will insert part of map
1344 saveState (PartOfMap,
1345 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1346 redoSelection, "delete ()",
1350 if (redoSel->getType()==TreeItem::MapCenter)
1352 // save the selected branch of the map, Undo will insert part of map
1353 saveState (PartOfMap,
1354 undoSelection, QString("addMapInsert (\"PATH\")"),
1355 redoSelection, "delete ()",
1362 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1364 // "Normal" savestate: save commands, selections and comment
1365 // so just save commands for undo and redo
1366 // and use current selection
1368 QString redoSelection="";
1369 if (redoSel) redoSelection=getSelectString(redoSel);
1370 QString undoSelection="";
1371 if (undoSel) undoSelection=getSelectString(undoSel);
1373 saveState (UndoCommand,
1380 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1382 // "Normal" savestate: save commands, selections and comment
1383 // so just save commands for undo and redo
1384 // and use current selection
1385 saveState (UndoCommand,
1392 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1394 // "Normal" savestate applied to model (no selection needed):
1395 // save commands and comment
1396 saveState (UndoCommand,
1404 QGraphicsScene* VymModel::getScene ()
1409 TreeItem* VymModel::findBySelectString(QString s)
1411 if (s.isEmpty() ) return NULL;
1413 // Old maps don't have multiple mapcenters and don't save full path
1414 if (s.left(2) !="mc")
1417 QStringList parts=s.split (",");
1420 TreeItem *ti=rootItem;
1422 while (!parts.isEmpty() )
1424 typ=parts.first().left(2);
1425 n=parts.first().right(parts.first().length() - 3).toInt();
1426 parts.removeFirst();
1427 if (typ=="mc" || typ=="bo")
1428 ti=ti->getBranchNum (n);
1430 ti=ti->getImageNum (n);
1432 ti=ti->getAttributeNum (n);
1434 ti=ti->getXLinkNum (n);
1435 if(!ti) return NULL;
1440 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1442 BranchItem *cur=NULL;
1443 BranchItem *prev=NULL;
1444 nextBranch(cur,prev);
1447 if (s==cur->getID() ) return cur;
1448 nextBranch(cur,prev);
1453 //////////////////////////////////////////////
1455 //////////////////////////////////////////////
1456 void VymModel::setVersion (const QString &s)
1461 QString VymModel::getVersion()
1466 void VymModel::setAuthor (const QString &s)
1469 QString ("setMapAuthor (\"%1\")").arg(author),
1470 QString ("setMapAuthor (\"%1\")").arg(s),
1471 QString ("Set author of map to \"%1\"").arg(s)
1476 QString VymModel::getAuthor()
1481 void VymModel::setComment (const QString &s)
1484 QString ("setMapComment (\"%1\")").arg(comment),
1485 QString ("setMapComment (\"%1\")").arg(s),
1486 QString ("Set comment of map")
1491 QString VymModel::getComment ()
1496 QString VymModel::getDate ()
1498 return QDate::currentDate().toString ("yyyy-MM-dd");
1501 int VymModel::branchCount()
1504 BranchItem *cur=NULL;
1505 BranchItem *prev=NULL;
1506 nextBranch(cur,prev);
1510 nextBranch(cur,prev);
1515 void VymModel::setSortFilter (const QString &s)
1518 emit (sortFilterChanged (sortFilter));
1521 QString VymModel::getSortFilter ()
1526 void VymModel::setHeading(const QString &s)
1528 BranchItem *selbi=getSelectedBranch();
1533 "setHeading (\""+selbi->getHeading()+"\")",
1535 "setHeading (\""+s+"\")",
1536 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1537 selbi->setHeading(s );
1538 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1540 emitSelectionChanged();
1544 QString VymModel::getHeading()
1546 TreeItem *selti=getSelectedItem();
1548 return selti->getHeading();
1553 void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here)
1555 TreeItem *selti=getSelectedItem();
1559 emitNoteHasChanged(selti);
1563 QString VymModel::getNote()
1565 TreeItem *selti=getSelectedItem();
1567 return selti->getNote();
1572 BranchItem* VymModel::findText (QString s, bool cs)
1574 if (!s.isEmpty() && s!=findString)
1580 QTextDocument::FindFlags flags=0;
1581 if (cs) flags=QTextDocument::FindCaseSensitively;
1584 { // Nothing found or new find process
1586 // nothing found, start again
1590 nextBranch (findCurrent,findPrevious);
1592 bool searching=true;
1593 bool foundNote=false;
1594 while (searching && !EOFind)
1598 // Searching in Note
1599 if (findCurrent->getNote().contains(findString,cs))
1601 select (findCurrent);
1603 if (getSelectedBranch()!=itFind)
1606 emitShowSelection();
1609 if (textEditor->findText(findString,flags))
1615 // Searching in Heading
1616 if (searching && findCurrent->getHeading().contains (findString,cs) )
1618 select(findCurrent);
1624 if (!nextBranch(findCurrent,findPrevious) )
1627 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1630 return getSelectedBranch();
1635 void VymModel::findReset()
1636 { // Necessary if text to find changes during a find process
1643 void VymModel::emitShowFindWidget()
1645 emit (showFindWidget());
1648 void VymModel::setScene (QGraphicsScene *s)
1653 void VymModel::setURL(const QString &url)
1655 TreeItem *selti=getSelectedItem();
1658 QString oldurl=selti->getURL();
1659 selti->setURL (url);
1662 QString ("setURL (\"%1\")").arg(oldurl),
1664 QString ("setURL (\"%1\")").arg(url),
1665 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1668 emitDataHasChanged (selti);
1669 emitShowSelection();
1673 QString VymModel::getURL()
1675 TreeItem *selti=getSelectedItem();
1677 return selti->getURL();
1682 QStringList VymModel::getURLs()
1685 BranchItem *selbi=getSelectedBranch();
1686 BranchItem *cur=selbi;
1687 BranchItem *prev=NULL;
1690 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1691 cur=nextBranch (cur,prev,true,selbi);
1697 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1699 BranchItem *bi=getSelectedBranch();
1702 BranchObj *bo=(BranchObj*)(bi->getLMO());
1705 QString s=bo->getFrameTypeName();
1706 bo->setFrameType (t);
1707 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1708 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1710 bo->updateLinkGeometry();
1715 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1717 BranchItem *bi=getSelectedBranch();
1720 BranchObj *bo=(BranchObj*)(bi->getLMO());
1723 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1724 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1725 bo->setFrameType (s);
1727 bo->updateLinkGeometry();
1732 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1735 BranchItem *bi=getSelectedBranch();
1738 BranchObj *bo=(BranchObj*)(bi->getLMO());
1741 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1742 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1743 bo->setFramePenColor (c);
1748 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1750 BranchItem *bi=getSelectedBranch();
1753 BranchObj *bo=(BranchObj*)(bi->getLMO());
1756 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1757 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1758 bo->setFrameBrushColor (c);
1763 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1765 BranchItem *bi=getSelectedBranch();
1768 BranchObj *bo=(BranchObj*)(bi->getLMO());
1771 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1772 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1773 bo->setFramePadding (i);
1775 bo->updateLinkGeometry();
1780 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1782 BranchItem *bi=getSelectedBranch();
1785 BranchObj *bo=(BranchObj*)(bi->getLMO());
1788 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1789 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1790 bo->setFrameBorderWidth (i);
1792 bo->updateLinkGeometry();
1797 void VymModel::setIncludeImagesVer(bool b)
1799 BranchItem *bi=getSelectedBranch();
1802 QString u= b ? "false" : "true";
1803 QString r=!b ? "false" : "true";
1807 QString("setIncludeImagesVertically (%1)").arg(u),
1809 QString("setIncludeImagesVertically (%1)").arg(r),
1810 QString("Include images vertically in %1").arg(getObjectName(bi))
1812 bi->setIncludeImagesVer(b);
1813 emitDataHasChanged ( bi);
1818 void VymModel::setIncludeImagesHor(bool b)
1820 BranchItem *bi=getSelectedBranch();
1823 QString u= b ? "false" : "true";
1824 QString r=!b ? "false" : "true";
1828 QString("setIncludeImagesHorizontally (%1)").arg(u),
1830 QString("setIncludeImagesHorizontally (%1)").arg(r),
1831 QString("Include images horizontally in %1").arg(getObjectName(bi))
1833 bi->setIncludeImagesHor(b);
1834 emitDataHasChanged ( bi);
1839 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1841 TreeItem *ti=getSelectedItem();
1842 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1844 QString u= b ? "false" : "true";
1845 QString r=!b ? "false" : "true";
1849 QString("setHideLinkUnselected (%1)").arg(u),
1851 QString("setHideLinkUnselected (%1)").arg(r),
1852 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1854 ((MapItem*)ti)->setHideLinkUnselected(b);
1858 void VymModel::setHideExport(bool b)
1860 TreeItem *ti=getSelectedItem();
1862 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1864 ti->setHideInExport (b);
1865 QString u= b ? "false" : "true";
1866 QString r=!b ? "false" : "true";
1870 QString ("setHideExport (%1)").arg(u),
1872 QString ("setHideExport (%1)").arg(r),
1873 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1875 emitDataHasChanged(ti);
1876 emitSelectionChanged();
1879 // emitSelectionChanged();
1880 // FIXME-3 VM needed? scene()->update();
1884 void VymModel::toggleHideExport()
1886 TreeItem *selti=getSelectedItem();
1888 setHideExport ( !selti->hideInExport() );
1891 void VymModel::addTimestamp() //FIXME-3 new function, localize
1893 BranchItem *selbi=addNewBranch();
1896 QDate today=QDate::currentDate();
1898 selbi->setHeading (QString ("%1-%2-%3")
1899 .arg(today.year(),4,10,c)
1900 .arg(today.month(),2,10,c)
1901 .arg(today.day(),2,10,c));
1902 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1909 void VymModel::copy()
1911 TreeItem *selti=getSelectedItem();
1913 (selti->getType() == TreeItem::Branch ||
1914 selti->getType() == TreeItem::MapCenter ||
1915 selti->getType() == TreeItem::Image ))
1917 if (redosAvail == 0)
1920 QString s=getSelectString(selti);
1921 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1922 curClipboard=curStep;
1925 // Copy also to global clipboard, because we are at last step in history
1926 QString bakMapName(QString("history-%1").arg(curStep));
1927 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1928 copyDir (bakMapDir,clipboardDir );
1930 clipboardEmpty=false;
1936 void VymModel::pasteNoSave(const int &n)
1938 bool old=blockSaveState;
1939 blockSaveState=true;
1940 bool zippedOrg=zipped;
1941 if (redosAvail > 0 || n!=0)
1943 // Use the "historical" buffer
1944 QString bakMapName(QString("history-%1").arg(n));
1945 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1946 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1948 // Use the global buffer
1949 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1954 void VymModel::paste()
1956 BranchItem *selbi=getSelectedBranch();
1959 saveStateChangingPart(
1962 QString ("paste (%1)").arg(curClipboard),
1963 QString("Paste to %1").arg( getObjectName(selbi))
1970 void VymModel::cut()
1972 TreeItem *selti=getSelectedItem();
1973 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1981 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1983 if (bi && bi->canMoveUp())
1984 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1989 void VymModel::moveUp()
1991 BranchItem *selbi=getSelectedBranch();
1994 QString oldsel=getSelectString();
1997 getSelectString(),"moveDown ()",
1999 QString("Move up %1").arg(getObjectName(selbi)));
2003 bool VymModel::moveDown(BranchItem *bi)
2005 if (bi && bi->canMoveDown())
2006 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2011 void VymModel::moveDown()
2013 BranchItem *selbi=getSelectedBranch();
2016 QString oldsel=getSelectString();
2017 if ( moveDown(selbi))
2019 getSelectString(),"moveUp ()",
2020 oldsel,"moveDown ()",
2021 QString("Move down %1").arg(getObjectName(selbi)));
2025 void VymModel::detach()
2027 BranchItem *selbi=getSelectedBranch();
2028 if (selbi && selbi->depth()>0)
2030 // if no relPos have been set before, try to use current rel positions
2031 if (selbi->getLMO())
2032 for (int i=0; i<selbi->branchCount();++i)
2033 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2035 QString oldsel=getSelectString();
2038 BranchObj *bo=selbi->getBranchObj();
2039 if (bo) p=bo->getAbsPos();
2040 QString parsel=getSelectString(selbi->parent());
2041 if ( relinkBranch (selbi,rootItem,-1) )
2043 getSelectString (selbi),
2044 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2047 QString("Detach %1").arg(getObjectName(selbi))
2052 void VymModel::sortChildren()
2054 BranchItem* selbi=getSelectedBranch();
2057 if(selbi->branchCount()>1)
2059 saveStateChangingPart(
2060 selbi,selbi, "sortChildren ()",
2061 QString("Sort children of %1").arg(getObjectName(selbi)));
2062 selbi->sortChildren();
2064 emitShowSelection();
2069 BranchItem* VymModel::createMapCenter()
2071 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2075 BranchItem* VymModel::createBranch(BranchItem *dst)
2078 return addNewBranchInt (dst,-2);
2083 ImageItem* VymModel::createImage(BranchItem *dst)
2090 QList<QVariant> cData;
2091 cData << "new" << "undef";
2093 ImageItem *newii=new ImageItem(cData) ;
2094 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2096 emit (layoutAboutToBeChanged() );
2099 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2100 n=dst->getRowNumAppend(newii);
2101 beginInsertRows (parix,n,n);
2102 dst->appendChild (newii);
2105 emit (layoutChanged() );
2107 // save scroll state. If scrolled, automatically select
2108 // new branch in order to tmp unscroll parent...
2109 newii->createMapObj(mapScene);
2116 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2123 QList<QVariant> cData;
2124 cData << "new xLink"<<"undef";
2126 XLinkItem *newxli=new XLinkItem(cData) ;
2127 newxli->setBegin (bi);
2129 emit (layoutAboutToBeChanged() );
2132 n=bi->getRowNumAppend(newxli);
2133 beginInsertRows (parix,n,n);
2134 bi->appendChild (newxli);
2137 emit (layoutChanged() );
2139 // save scroll state. If scrolled, automatically select
2140 // new branch in order to tmp unscroll parent...
2143 newxli->createMapObj(mapScene);
2151 AttributeItem* VymModel::addAttribute()
2153 BranchItem *selbi=getSelectedBranch();
2156 QList<QVariant> cData;
2157 cData << "new attribute" << "undef";
2158 AttributeItem *a=new AttributeItem (cData);
2159 if (addAttribute (a)) return a;
2164 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2166 BranchItem *selbi=getSelectedBranch();
2169 emit (layoutAboutToBeChanged() );
2171 QModelIndex parix=index(selbi);
2172 int n=selbi->getRowNumAppend (ai);
2173 beginInsertRows (parix,n,n);
2174 selbi->appendChild (ai);
2177 emit (layoutChanged() );
2185 BranchItem* VymModel::addMapCenter ()
2187 BranchItem *bi=addMapCenter (contextPos);
2189 emitShowSelection();
2194 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2195 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2200 BranchItem* VymModel::addMapCenter(QPointF absPos)
2201 // createMapCenter could then probably be merged with createBranch
2205 QModelIndex parix=index(rootItem);
2207 QList<QVariant> cData;
2208 cData << "VM:addMapCenter" << "undef";
2209 BranchItem *newbi=new BranchItem (cData,rootItem);
2210 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2211 int n=rootItem->getRowNumAppend (newbi);
2213 emit (layoutAboutToBeChanged() );
2214 beginInsertRows (parix,n,n);
2216 rootItem->appendChild (newbi);
2219 emit (layoutChanged() );
2222 newbi->setPositionMode (MapItem::Absolute);
2223 BranchObj *bo=newbi->createMapObj(mapScene);
2224 if (bo) bo->move (absPos);
2229 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2231 // Depending on pos:
2232 // -3 insert in children of parent above selection
2233 // -2 add branch to selection
2234 // -1 insert in children of parent below selection
2235 // 0..n insert in children of parent at pos
2238 QList<QVariant> cData;
2239 cData << "" << "undef";
2244 BranchItem *newbi=new BranchItem (cData);
2245 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2247 emit (layoutAboutToBeChanged() );
2253 n=parbi->getRowNumAppend (newbi);
2254 beginInsertRows (parix,n,n);
2255 parbi->appendChild (newbi);
2257 }else if (num==-1 || num==-3)
2259 // insert below selection
2260 parbi=(BranchItem*)dst->parent();
2263 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2264 beginInsertRows (parix,n,n);
2265 parbi->insertBranch(n,newbi);
2268 emit (layoutChanged() );
2270 // Set color of heading to that of parent
2271 newbi->setHeadingColor (parbi->getHeadingColor());
2273 // save scroll state. If scrolled, automatically select
2274 // new branch in order to tmp unscroll parent...
2275 newbi->createMapObj(mapScene);
2280 BranchItem* VymModel::addNewBranch(int pos)
2282 // Different meaning than num in addNewBranchInt!
2286 BranchItem *newbi=NULL;
2287 BranchItem *selbi=getSelectedBranch();
2291 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2293 newbi=addNewBranchInt (selbi,pos-2);
2301 QString ("addBranch (%1)").arg(pos),
2302 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2305 // emitSelectionChanged(); FIXME-3
2306 latestAddedItem=newbi;
2307 // In Network mode, the client needs to know where the new branch is,
2308 // so we have to pass on this information via saveState.
2309 // TODO: Get rid of this positioning workaround
2310 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2311 sendData ("selectLatestAdded ()");
2312 sendData (QString("move %1").arg(ps));
2321 BranchItem* VymModel::addNewBranchBefore()
2323 BranchItem *newbi=NULL;
2324 BranchItem *selbi=getSelectedBranch();
2325 if (selbi && selbi->getType()==TreeItem::Branch)
2326 // We accept no MapCenter here, so we _have_ a parent
2328 //QPointF p=bo->getRelPos();
2331 // add below selection
2332 newbi=addNewBranchInt (selbi,-1);
2336 //newbi->move2RelPos (p);
2338 // Move selection to new branch
2339 relinkBranch (selbi,newbi,0);
2341 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2342 QString ("Add branch before %1").arg(getObjectName(selbi)));
2344 // FIXME-3 needed? reposition();
2345 // emitSelectionChanged(); FIXME-3
2351 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2357 emit (layoutAboutToBeChanged() );
2358 BranchItem *branchpi=(BranchItem*)branch->parent();
2359 // Remove at current position
2360 int n=branch->childNum();
2362 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2363 // error occured if relinking branch to empty mainbranch
2364 cout<<"VM::relinkBranch:\n";
2365 cout<<" b="<<branch->getHeadingStd()<<endl;
2366 cout<<" dst="<<dst->getHeadingStd()<<endl;
2367 cout<<" pos="<<pos<<endl;
2368 cout<<" n1="<<n<<endl;
2370 beginRemoveRows (index(branchpi),n,n);
2371 branchpi->removeChild (n);
2374 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2376 // Append as last branch to dst
2377 if (dst->branchCount()==0)
2380 n=dst->getFirstBranch()->childNumber();
2381 beginInsertRows (index(dst),n+pos,n+pos);
2382 dst->insertBranch (pos,branch);
2385 // Correct type if necessesary
2386 if (branch->getType()==TreeItem::MapCenter)
2387 branch->setType(TreeItem::Branch);
2389 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2390 branch->updateStyles();
2392 emit (layoutChanged() );
2393 reposition(); // both for moveUp/Down and relinking
2394 if (dst->isScrolled() )
2397 branch->updateVisibility();
2406 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2410 emit (layoutAboutToBeChanged() );
2412 BranchItem *pi=(BranchItem*)(image->parent());
2413 QString oldParString=getSelectString (pi);
2414 // Remove at current position
2415 int n=image->childNum();
2416 beginRemoveRows (index(pi),n,n);
2417 pi->removeChild (n);
2421 QModelIndex dstix=index(dst);
2422 n=dst->getRowNumAppend (image);
2423 beginInsertRows (dstix,n,n+1);
2424 dst->appendChild (image);
2427 // Set new parent also for lmo
2428 if (image->getLMO() && dst->getLMO() )
2429 image->getLMO()->setParObj (dst->getLMO() );
2431 emit (layoutChanged() );
2434 QString("relinkTo (\"%1\")").arg(oldParString),
2436 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2437 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2443 void VymModel::deleteSelection()
2445 BranchItem *selbi=getSelectedBranch();
2450 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2452 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2455 if (pi->isScrolled() && pi->branchCount()==0)
2458 emitDataHasChanged(pi);
2461 emitShowSelection();
2465 TreeItem *ti=getSelectedItem();
2467 { // Delete other item
2468 TreeItem *pi=ti->parent();
2470 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2472 saveStateChangingPart(
2476 QString("Delete %1").arg(getObjectName(ti))
2480 emitDataHasChanged (pi);
2483 emitShowSelection();
2484 } else if (ti->getType()==TreeItem::XLink)
2486 //FIXME-2 savestate missing
2489 qWarning ("VymmModel::deleteSelection() unknown type?!");
2493 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2496 BranchItem *selbi=getSelectedBranch();
2500 // Don't use this on mapcenter
2501 if (selbi->depth()<2) return;
2503 pi=(BranchItem*)(selbi->parent());
2504 // Check if we have childs at all to keep
2505 if (selbi->branchCount()==0)
2512 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2513 saveStateChangingPart(
2516 "deleteKeepChildren ()",
2517 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2520 QString sel=getSelectString(selbi);
2522 int pos=selbi->num();
2523 BranchItem *bi=selbi->getFirstBranch();
2526 relinkBranch (bi,pi,pos);
2527 bi=selbi->getFirstBranch();
2533 BranchObj *bo=getSelectedBranchObj();
2536 bo->move2RelPos (p);
2542 void VymModel::deleteChildren()
2545 BranchItem *selbi=getSelectedBranch();
2548 saveStateChangingPart(
2551 "deleteChildren ()",
2552 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2554 emit (layoutAboutToBeChanged() );
2556 QModelIndex ix=index (selbi);
2557 int n=selbi->branchCount()-1;
2558 beginRemoveRows (ix,0,n);
2559 removeRows (0,n+1,ix);
2561 if (selbi->isScrolled()) selbi->unScroll();
2562 emit (layoutChanged() );
2567 TreeItem* VymModel::deleteItem (TreeItem *ti)
2571 TreeItem *pi=ti->parent();
2572 QModelIndex parentIndex=index(pi);
2574 emit (layoutAboutToBeChanged() );
2576 int n=ti->childNum();
2577 beginRemoveRows (parentIndex,n,n);
2578 removeRows (n,1,parentIndex);
2582 emit (layoutChanged() );
2583 if (pi->depth()>=0) return pi;
2588 void VymModel::clearItem (TreeItem *ti)
2592 QModelIndex parentIndex=index(ti);
2593 if (!parentIndex.isValid()) return;
2595 int n=ti->childCount();
2598 emit (layoutAboutToBeChanged() );
2600 beginRemoveRows (parentIndex,0,n-1);
2601 removeRows (0,n,parentIndex);
2605 emit (layoutChanged() );
2611 bool VymModel::scrollBranch(BranchItem *bi)
2615 if (bi->isScrolled()) return false;
2616 if (bi->branchCount()==0) return false;
2617 if (bi->depth()==0) return false;
2618 if (bi->toggleScroll())
2626 QString ("%1 ()").arg(u),
2628 QString ("%1 ()").arg(r),
2629 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2631 emitDataHasChanged(bi);
2632 emitSelectionChanged();
2633 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2640 bool VymModel::unscrollBranch(BranchItem *bi)
2644 if (!bi->isScrolled()) return false;
2645 if (bi->branchCount()==0) return false;
2646 if (bi->depth()==0) return false;
2647 if (bi->toggleScroll())
2655 QString ("%1 ()").arg(u),
2657 QString ("%1 ()").arg(r),
2658 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2660 emitDataHasChanged(bi);
2661 emitSelectionChanged();
2662 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2669 void VymModel::toggleScroll()
2671 BranchItem *bi=(BranchItem*)getSelectedBranch();
2672 if (bi && bi->isBranchLikeType() )
2674 if (bi->isScrolled())
2675 unscrollBranch (bi);
2679 // saveState & reposition are called in above functions
2682 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2684 BranchItem *selbi=getSelectedBranch();
2685 BranchItem *prev=NULL;
2686 BranchItem *cur=selbi;
2689 saveStateChangingPart(
2692 QString ("unscrollChildren ()"),
2693 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2697 if (cur->isScrolled())
2699 cur->toggleScroll();
2700 emitDataHasChanged (cur);
2702 cur=nextBranch (cur,prev,true,selbi);
2709 void VymModel::emitExpandAll()
2711 emit (expandAll() );
2714 void VymModel::emitExpandOneLevel()
2716 emit (expandOneLevel () );
2719 void VymModel::emitCollapseOneLevel()
2721 emit (collapseOneLevel () );
2724 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2726 BranchItem *bi=getSelectedBranch();
2730 if (bi->isActiveStandardFlag(name))
2742 QString("%1 (\"%2\")").arg(u).arg(name),
2744 QString("%1 (\"%2\")").arg(r).arg(name),
2745 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2746 bi->toggleStandardFlag (name, master);
2748 emitSelectionChanged();
2752 void VymModel::addFloatImage (const QPixmap &img)
2754 BranchItem *selbi=getSelectedBranch();
2757 ImageItem *ii=createImage (selbi);
2759 ii->setOriginalFilename("No original filename (image added by dropevent)");
2760 QString s=getSelectString(selbi);
2761 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2762 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2764 // FIXME-3 VM needed? scene()->update();
2769 void VymModel::colorBranch (QColor c)
2771 BranchItem *selbi=getSelectedBranch();
2776 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2778 QString ("colorBranch (\"%1\")").arg(c.name()),
2779 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2781 selbi->setHeadingColor(c); // color branch
2786 void VymModel::colorSubtree (QColor c)
2788 BranchItem *selbi=getSelectedBranch();
2791 saveStateChangingPart(
2794 QString ("colorSubtree (\"%1\")").arg(c.name()),
2795 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2797 BranchItem *prev=NULL;
2798 BranchItem *cur=selbi;
2801 cur->setHeadingColor(c); // color links, color children
2802 cur=nextBranch (cur,prev,true,selbi);
2808 QColor VymModel::getCurrentHeadingColor()
2810 BranchItem *selbi=getSelectedBranch();
2811 if (selbi) return selbi->getHeadingColor();
2813 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2819 void VymModel::editURL()
2821 TreeItem *selti=getSelectedItem();
2825 QString text = QInputDialog::getText(
2826 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2827 selti->getURL(), &ok, NULL);
2829 // user entered something and pressed OK
2834 void VymModel::editLocalURL()
2836 TreeItem *selti=getSelectedItem();
2839 QStringList filters;
2840 filters <<"All files (*)";
2841 filters << tr("Text","Filedialog") + " (*.txt)";
2842 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2843 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2844 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2845 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2846 fd->setFilters (filters);
2847 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2848 fd->setDirectory (lastFileDir);
2849 if (! selti->getVymLink().isEmpty() )
2850 fd->selectFile( selti->getURL() );
2853 if ( fd->exec() == QDialog::Accepted )
2855 lastFileDir=QDir (fd->directory().path());
2856 setURL (fd->selectedFile() );
2862 void VymModel::editHeading2URL()
2864 TreeItem *selti=getSelectedItem();
2866 setURL (selti->getHeading());
2869 void VymModel::editBugzilla2URL()
2871 TreeItem *selti=getSelectedItem();
2874 QString h=selti->getHeading();
2875 QRegExp rx("^(\\d+)");
2876 if (rx.indexIn(h) !=-1)
2877 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2881 void VymModel::editFATE2URL()
2883 TreeItem *selti=getSelectedItem();
2886 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2889 "setURL (\""+selti->getURL()+"\")",
2891 "setURL (\""+url+"\")",
2892 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2894 selti->setURL (url);
2895 // FIXME-4 updateActions();
2899 void VymModel::editVymLink()
2901 BranchItem *bi=getSelectedBranch();
2904 QStringList filters;
2905 filters <<"VYM map (*.vym)";
2906 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2907 fd->setFilters (filters);
2908 fd->setCaption(vymName+" - " +tr("Link to another map"));
2909 fd->setDirectory (lastFileDir);
2910 if (! bi->getVymLink().isEmpty() )
2911 fd->selectFile( bi->getVymLink() );
2915 if ( fd->exec() == QDialog::Accepted )
2917 lastFileDir=QDir (fd->directory().path());
2920 "setVymLink (\""+bi->getVymLink()+"\")",
2922 "setVymLink (\""+fd->selectedFile()+"\")",
2923 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2925 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2930 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2932 // Internal function, no saveState needed
2933 TreeItem *selti=getSelectedItem();
2936 selti->setVymLink(s);
2938 emitDataHasChanged (selti);
2939 emitShowSelection();
2943 void VymModel::deleteVymLink()
2945 BranchItem *bi=getSelectedBranch();
2950 "setVymLink (\""+bi->getVymLink()+"\")",
2952 "setVymLink (\"\")",
2953 QString("Unset vymlink of %1").arg(getObjectName(bi))
2955 bi->setVymLink ("" );
2961 QString VymModel::getVymLink()
2963 BranchItem *bi=getSelectedBranch();
2965 return bi->getVymLink();
2971 QStringList VymModel::getVymLinks()
2974 BranchItem *selbi=getSelectedBranch();
2975 BranchItem *cur=selbi;
2976 BranchItem *prev=NULL;
2979 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2980 cur=nextBranch (cur,prev,true,selbi);
2986 void VymModel::followXLink(int i)
2989 BranchItem *selbi=getSelectedBranch();
2992 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2993 if (selbi) select (selbi);
2997 void VymModel::editXLink(int i)
3000 BranchItem *selbi=getSelectedBranch();
3003 XLinkItem *xli=selbi->getXLinkNum(i);
3006 EditXLinkDialog dia;
3008 dia.setSelection(selbi);
3009 if (dia.exec() == QDialog::Accepted)
3011 if (dia.useSettingsGlobal() )
3013 setMapDefXLinkColor (xli->getColor() );
3014 setMapDefXLinkWidth (xli->getWidth() );
3016 if (dia.deleteXLink()) deleteItem (xli);
3026 //////////////////////////////////////////////
3028 //////////////////////////////////////////////
3030 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3032 TreeItem* selti=getSelectedItem();
3033 BranchItem *selbi=getSelectedBranch();
3038 QVariant returnValue;
3040 // Split string s into command and parameters
3041 parser.parseAtom (atom);
3042 QString com=parser.getCommand();
3044 // External commands
3045 /////////////////////////////////////////////////////////////////////
3046 if (com=="addBranch")
3050 parser.setError (Aborted,"Nothing selected");
3051 } else if (! selbi )
3053 parser.setError (Aborted,"Type of selection is not a branch");
3058 if (parser.checkParCount(pl))
3060 if (parser.parCount()==0)
3064 n=parser.parInt (ok,0);
3065 if (ok ) addNewBranch (n);
3069 /////////////////////////////////////////////////////////////////////
3070 } else if (com=="addBranchBefore")
3074 parser.setError (Aborted,"Nothing selected");
3075 } else if (! selbi )
3077 parser.setError (Aborted,"Type of selection is not a branch");
3080 if (parser.parCount()==0)
3082 addNewBranchBefore ();
3085 /////////////////////////////////////////////////////////////////////
3086 } else if (com==QString("addMapCenter"))
3088 if (parser.checkParCount(2))
3090 x=parser.parDouble (ok,0);
3093 y=parser.parDouble (ok,1);
3094 if (ok) addMapCenter (QPointF(x,y));
3097 /////////////////////////////////////////////////////////////////////
3098 } else if (com==QString("addMapReplace"))
3102 parser.setError (Aborted,"Nothing selected");
3103 } else if (! selbi )
3105 parser.setError (Aborted,"Type of selection is not a branch");
3106 } else if (parser.checkParCount(1))
3108 //s=parser.parString (ok,0); // selection
3109 t=parser.parString (ok,0); // path to map
3110 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3111 addMapReplaceInt(getSelectString(selbi),t);
3113 /////////////////////////////////////////////////////////////////////
3114 } else if (com==QString("addMapInsert"))
3116 if (parser.parCount()==2)
3121 parser.setError (Aborted,"Nothing selected");
3122 } else if (! selbi )
3124 parser.setError (Aborted,"Type of selection is not a branch");
3127 t=parser.parString (ok,0); // path to map
3128 n=parser.parInt(ok,1); // position
3129 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3130 addMapInsertInt(t,n);
3132 } else if (parser.parCount()==1)
3134 t=parser.parString (ok,0); // path to map
3135 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3138 parser.setError (Aborted,"Wrong number of parameters");
3139 /////////////////////////////////////////////////////////////////////
3140 } else if (com==QString("addXLink"))
3142 if (parser.parCount()>1)
3144 s=parser.parString (ok,0); // begin
3145 t=parser.parString (ok,1); // end
3146 BranchItem *begin=(BranchItem*)findBySelectString(s);
3147 BranchItem *end=(BranchItem*)findBySelectString(t);
3150 if (begin->isBranchLikeType() && end->isBranchLikeType())
3152 XLinkItem *xl=createXLink (begin,true);
3158 parser.setError (Aborted,"Failed to create xLink");
3161 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3164 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3166 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3167 /////////////////////////////////////////////////////////////////////
3168 } else if (com=="clearFlags")
3172 parser.setError (Aborted,"Nothing selected");
3173 } else if (! selbi )
3175 parser.setError (Aborted,"Type of selection is not a branch");
3176 } else if (parser.checkParCount(0))
3178 selbi->deactivateAllStandardFlags();
3180 /////////////////////////////////////////////////////////////////////
3181 } else if (com=="colorBranch")
3185 parser.setError (Aborted,"Nothing selected");
3186 } else if (! selbi )
3188 parser.setError (Aborted,"Type of selection is not a branch");
3189 } else if (parser.checkParCount(1))
3191 QColor c=parser.parColor (ok,0);
3192 if (ok) colorBranch (c);
3194 /////////////////////////////////////////////////////////////////////
3195 } else if (com=="colorSubtree")
3199 parser.setError (Aborted,"Nothing selected");
3200 } else if (! selbi )
3202 parser.setError (Aborted,"Type of selection is not a branch");
3203 } else if (parser.checkParCount(1))
3205 QColor c=parser.parColor (ok,0);
3206 if (ok) colorSubtree (c);
3208 /////////////////////////////////////////////////////////////////////
3209 } else if (com=="copy")
3213 parser.setError (Aborted,"Nothing selected");
3214 } else if ( selectionType()!=TreeItem::Branch &&
3215 selectionType()!=TreeItem::MapCenter &&
3216 selectionType()!=TreeItem::Image )
3218 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3219 } else if (parser.checkParCount(0))
3223 /////////////////////////////////////////////////////////////////////
3224 } else if (com=="cut")
3228 parser.setError (Aborted,"Nothing selected");
3229 } else if ( selectionType()!=TreeItem::Branch &&
3230 selectionType()!=TreeItem::MapCenter &&
3231 selectionType()!=TreeItem::Image )
3233 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3234 } else if (parser.checkParCount(0))
3238 /////////////////////////////////////////////////////////////////////
3239 } else if (com=="delete")
3243 parser.setError (Aborted,"Nothing selected");
3245 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3247 parser.setError (Aborted,"Type of selection is wrong.");
3250 else if (parser.checkParCount(0))
3254 /////////////////////////////////////////////////////////////////////
3255 } else if (com=="deleteKeepChildren")
3259 parser.setError (Aborted,"Nothing selected");
3260 } else if (! selbi )
3262 parser.setError (Aborted,"Type of selection is not a branch");
3263 } else if (parser.checkParCount(0))
3265 deleteKeepChildren();
3267 /////////////////////////////////////////////////////////////////////
3268 } else if (com=="deleteChildren")
3272 parser.setError (Aborted,"Nothing selected");
3275 parser.setError (Aborted,"Type of selection is not a branch");
3276 } else if (parser.checkParCount(0))
3280 /////////////////////////////////////////////////////////////////////
3281 } else if (com=="exportAO")
3285 if (parser.parCount()>=1)
3286 // Hey, we even have a filename
3287 fname=parser.parString(ok,0);
3290 parser.setError (Aborted,"Could not read filename");
3293 exportAO (fname,false);
3295 /////////////////////////////////////////////////////////////////////
3296 } else if (com=="exportASCII")
3300 if (parser.parCount()>=1)
3301 // Hey, we even have a filename
3302 fname=parser.parString(ok,0);
3305 parser.setError (Aborted,"Could not read filename");
3308 exportASCII (fname,false);
3310 /////////////////////////////////////////////////////////////////////
3311 } else if (com=="exportImage")
3315 if (parser.parCount()>=2)
3316 // Hey, we even have a filename
3317 fname=parser.parString(ok,0);
3320 parser.setError (Aborted,"Could not read filename");
3323 QString format="PNG";
3324 if (parser.parCount()>=2)
3326 format=parser.parString(ok,1);
3328 exportImage (fname,false,format);
3330 /////////////////////////////////////////////////////////////////////
3331 } else if (com=="exportXHTML")
3335 if (parser.parCount()>=2)
3336 // Hey, we even have a filename
3337 fname=parser.parString(ok,1);
3340 parser.setError (Aborted,"Could not read filename");
3343 exportXHTML (fname,false);
3345 /////////////////////////////////////////////////////////////////////
3346 } else if (com=="exportXML")
3350 if (parser.parCount()>=2)
3351 // Hey, we even have a filename
3352 fname=parser.parString(ok,1);
3355 parser.setError (Aborted,"Could not read filename");
3358 exportXML (fname,false);
3360 /////////////////////////////////////////////////////////////////////
3361 } else if (com=="getHeading")
3365 parser.setError (Aborted,"Nothing selected");
3366 } else if (parser.checkParCount(0))
3367 returnValue=selti->getHeading();
3368 /////////////////////////////////////////////////////////////////////
3369 } else if (com=="importDir")
3373 parser.setError (Aborted,"Nothing selected");
3374 } else if (! selbi )
3376 parser.setError (Aborted,"Type of selection is not a branch");
3377 } else if (parser.checkParCount(1))
3379 s=parser.parString(ok,0);
3380 if (ok) importDirInt(s);
3382 /////////////////////////////////////////////////////////////////////
3383 } else if (com=="relinkTo")
3387 parser.setError (Aborted,"Nothing selected");
3390 if (parser.checkParCount(4))
3392 // 0 selectstring of parent
3393 // 1 num in parent (for branches)
3394 // 2,3 x,y of mainbranch or mapcenter
3395 s=parser.parString(ok,0);
3396 TreeItem *dst=findBySelectString (s);
3399 if (dst->getType()==TreeItem::Branch)
3401 // Get number in parent
3402 n=parser.parInt (ok,1);
3405 relinkBranch (selbi,(BranchItem*)dst,n);
3406 emitSelectionChanged();
3408 } else if (dst->getType()==TreeItem::MapCenter)
3410 relinkBranch (selbi,(BranchItem*)dst);
3411 // Get coordinates of mainbranch
3412 x=parser.parDouble(ok,2);
3415 y=parser.parDouble(ok,3);
3418 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3419 emitSelectionChanged();
3425 } else if ( selti->getType() == TreeItem::Image)
3427 if (parser.checkParCount(1))
3429 // 0 selectstring of parent
3430 s=parser.parString(ok,0);
3431 TreeItem *dst=findBySelectString (s);
3434 if (dst->isBranchLikeType())
3435 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3437 parser.setError (Aborted,"Destination is not a branch");
3440 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3441 /////////////////////////////////////////////////////////////////////
3442 } else if (com=="loadImage")
3446 parser.setError (Aborted,"Nothing selected");
3447 } else if (! selbi )
3449 parser.setError (Aborted,"Type of selection is not a branch");
3450 } else if (parser.checkParCount(1))
3452 s=parser.parString(ok,0);
3453 if (ok) loadFloatImageInt (selbi,s);
3455 /////////////////////////////////////////////////////////////////////
3456 } else if (com=="moveUp")
3460 parser.setError (Aborted,"Nothing selected");
3461 } else if (! selbi )
3463 parser.setError (Aborted,"Type of selection is not a branch");
3464 } else if (parser.checkParCount(0))
3468 /////////////////////////////////////////////////////////////////////
3469 } else if (com=="moveDown")
3473 parser.setError (Aborted,"Nothing selected");
3474 } else if (! selbi )
3476 parser.setError (Aborted,"Type of selection is not a branch");
3477 } else if (parser.checkParCount(0))
3481 /////////////////////////////////////////////////////////////////////
3482 } else if (com=="move")
3486 parser.setError (Aborted,"Nothing selected");
3487 } else if ( selectionType()!=TreeItem::Branch &&
3488 selectionType()!=TreeItem::MapCenter &&
3489 selectionType()!=TreeItem::Image )
3491 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3492 } else if (parser.checkParCount(2))
3494 x=parser.parDouble (ok,0);
3497 y=parser.parDouble (ok,1);
3501 /////////////////////////////////////////////////////////////////////
3502 } else if (com=="moveRel")
3506 parser.setError (Aborted,"Nothing selected");
3507 } else if ( selectionType()!=TreeItem::Branch &&
3508 selectionType()!=TreeItem::MapCenter &&
3509 selectionType()!=TreeItem::Image )
3511 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3512 } else if (parser.checkParCount(2))
3514 x=parser.parDouble (ok,0);
3517 y=parser.parDouble (ok,1);
3518 if (ok) moveRel (x,y);
3521 /////////////////////////////////////////////////////////////////////
3522 } else if (com=="nop")
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="paste")
3529 parser.setError (Aborted,"Nothing selected");
3530 } else if (! selbi )
3532 parser.setError (Aborted,"Type of selection is not a branch");
3533 } else if (parser.checkParCount(1))
3535 n=parser.parInt (ok,0);
3536 if (ok) pasteNoSave(n);
3538 /////////////////////////////////////////////////////////////////////
3539 } else if (com=="qa")
3543 parser.setError (Aborted,"Nothing selected");
3544 } else if (! selbi )
3546 parser.setError (Aborted,"Type of selection is not a branch");
3547 } else if (parser.checkParCount(4))
3550 c=parser.parString (ok,0);
3553 parser.setError (Aborted,"No comment given");
3556 s=parser.parString (ok,1);
3559 parser.setError (Aborted,"First parameter is not a string");
3562 t=parser.parString (ok,2);
3565 parser.setError (Aborted,"Condition is not a string");
3568 u=parser.parString (ok,3);
3571 parser.setError (Aborted,"Third parameter is not a string");
3576 parser.setError (Aborted,"Unknown type: "+s);
3581 parser.setError (Aborted,"Unknown operator: "+t);
3586 parser.setError (Aborted,"Type of selection is not a branch");
3589 if (selbi->getHeading() == u)
3591 cout << "PASSED: " << qPrintable (c) << endl;
3594 cout << "FAILED: " << qPrintable (c) << endl;
3604 /////////////////////////////////////////////////////////////////////
3605 } else if (com=="saveImage")
3607 ImageItem *ii=getSelectedImage();
3610 parser.setError (Aborted,"No image selected");
3611 } else if (parser.checkParCount(2))
3613 s=parser.parString(ok,0);
3616 t=parser.parString(ok,1);
3617 if (ok) saveFloatImageInt (ii,t,s);
3620 /////////////////////////////////////////////////////////////////////
3621 } else if (com=="scroll")
3625 parser.setError (Aborted,"Nothing selected");
3626 } else if (! selbi )
3628 parser.setError (Aborted,"Type of selection is not a branch");
3629 } else if (parser.checkParCount(0))
3631 if (!scrollBranch (selbi))
3632 parser.setError (Aborted,"Could not scroll branch");
3634 /////////////////////////////////////////////////////////////////////
3635 } else if (com=="select")
3637 if (parser.checkParCount(1))
3639 s=parser.parString(ok,0);
3642 /////////////////////////////////////////////////////////////////////
3643 } else if (com=="selectLastBranch")
3647 parser.setError (Aborted,"Nothing selected");
3648 } else if (! selbi )
3650 parser.setError (Aborted,"Type of selection is not a branch");
3651 } else if (parser.checkParCount(0))
3653 BranchItem *bi=selbi->getLastBranch();
3655 parser.setError (Aborted,"Could not select last branch");
3656 select (bi); // FIXME-3 was selectInt
3659 /////////////////////////////////////////////////////////////////////
3660 } else /* FIXME-2 if (com=="selectLastImage")
3664 parser.setError (Aborted,"Nothing selected");
3665 } else if (! selbi )
3667 parser.setError (Aborted,"Type of selection is not a branch");
3668 } else if (parser.checkParCount(0))
3670 FloatImageObj *fio=selb->getLastFloatImage();
3672 parser.setError (Aborted,"Could not select last image");
3673 select (fio); // FIXME-3 was selectInt
3676 /////////////////////////////////////////////////////////////////////
3677 } else */ if (com=="selectLatestAdded")
3679 if (!latestAddedItem)
3681 parser.setError (Aborted,"No latest added object");
3684 if (!select (latestAddedItem))
3685 parser.setError (Aborted,"Could not select latest added object ");
3687 /////////////////////////////////////////////////////////////////////
3688 } else if (com=="setFlag")
3692 parser.setError (Aborted,"Nothing selected");
3693 } else if (! selbi )
3695 parser.setError (Aborted,"Type of selection is not a branch");
3696 } else if (parser.checkParCount(1))
3698 s=parser.parString(ok,0);
3700 selbi->activateStandardFlag(s);
3702 /////////////////////////////////////////////////////////////////////
3703 } else if (com=="setFrameType")
3705 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3707 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3709 else if (parser.checkParCount(1))
3711 s=parser.parString(ok,0);
3712 if (ok) setFrameType (s);
3714 /////////////////////////////////////////////////////////////////////
3715 } else if (com=="setFramePenColor")
3717 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3719 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3721 else if (parser.checkParCount(1))
3723 QColor c=parser.parColor(ok,0);
3724 if (ok) setFramePenColor (c);
3726 /////////////////////////////////////////////////////////////////////
3727 } else if (com=="setFrameBrushColor")
3729 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3731 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3733 else if (parser.checkParCount(1))
3735 QColor c=parser.parColor(ok,0);
3736 if (ok) setFrameBrushColor (c);
3738 /////////////////////////////////////////////////////////////////////
3739 } else if (com=="setFramePadding")
3741 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3743 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3745 else if (parser.checkParCount(1))
3747 n=parser.parInt(ok,0);
3748 if (ok) setFramePadding(n);
3750 /////////////////////////////////////////////////////////////////////
3751 } else if (com=="setFrameBorderWidth")
3753 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3755 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3757 else if (parser.checkParCount(1))
3759 n=parser.parInt(ok,0);
3760 if (ok) setFrameBorderWidth (n);
3762 /////////////////////////////////////////////////////////////////////
3763 /* FIXME-2 else if (com=="setFrameType")
3767 parser.setError (Aborted,"Nothing selected");
3770 parser.setError (Aborted,"Type of selection is not a branch");
3771 } else if (parser.checkParCount(1))
3773 s=parser.parString(ok,0);
3777 /////////////////////////////////////////////////////////////////////
3779 /////////////////////////////////////////////////////////////////////
3780 } else if (com=="setHeading")
3784 parser.setError (Aborted,"Nothing selected");
3785 } else if (! selbi )
3787 parser.setError (Aborted,"Type of selection is not a branch");
3788 } else if (parser.checkParCount(1))
3790 s=parser.parString (ok,0);
3794 /////////////////////////////////////////////////////////////////////
3795 } else if (com=="setHideExport")
3799 parser.setError (Aborted,"Nothing selected");
3800 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3802 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3803 } else if (parser.checkParCount(1))
3805 b=parser.parBool(ok,0);
3806 if (ok) setHideExport (b);
3808 /////////////////////////////////////////////////////////////////////
3809 } else if (com=="setIncludeImagesHorizontally")
3813 parser.setError (Aborted,"Nothing selected");
3816 parser.setError (Aborted,"Type of selection is not a branch");
3817 } else if (parser.checkParCount(1))
3819 b=parser.parBool(ok,0);
3820 if (ok) setIncludeImagesHor(b);
3822 /////////////////////////////////////////////////////////////////////
3823 } else if (com=="setIncludeImagesVertically")
3827 parser.setError (Aborted,"Nothing selected");
3830 parser.setError (Aborted,"Type of selection is not a branch");
3831 } else if (parser.checkParCount(1))
3833 b=parser.parBool(ok,0);
3834 if (ok) setIncludeImagesVer(b);
3836 /////////////////////////////////////////////////////////////////////
3837 } else if (com=="setHideLinkUnselected")
3841 parser.setError (Aborted,"Nothing selected");
3842 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3844 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3845 } else if (parser.checkParCount(1))
3847 b=parser.parBool(ok,0);
3848 if (ok) setHideLinkUnselected(b);
3850 /////////////////////////////////////////////////////////////////////
3851 } else if (com=="setMapAuthor")
3853 if (parser.checkParCount(1))
3855 s=parser.parString(ok,0);
3856 if (ok) setAuthor (s);
3858 /////////////////////////////////////////////////////////////////////
3859 } else if (com=="setMapComment")
3861 if (parser.checkParCount(1))
3863 s=parser.parString(ok,0);
3864 if (ok) setComment(s);
3866 /////////////////////////////////////////////////////////////////////
3867 } else if (com=="setMapBackgroundColor")
3871 parser.setError (Aborted,"Nothing selected");
3872 } else if (! selbi )
3874 parser.setError (Aborted,"Type of selection is not a branch");
3875 } else if (parser.checkParCount(1))
3877 QColor c=parser.parColor (ok,0);
3878 if (ok) setMapBackgroundColor (c);
3880 /////////////////////////////////////////////////////////////////////
3881 } else if (com=="setMapDefLinkColor")
3885 parser.setError (Aborted,"Nothing selected");
3886 } else if (! selbi )
3888 parser.setError (Aborted,"Type of selection is not a branch");
3889 } else if (parser.checkParCount(1))
3891 QColor c=parser.parColor (ok,0);
3892 if (ok) setMapDefLinkColor (c);
3894 /////////////////////////////////////////////////////////////////////
3895 } else if (com=="setMapLinkStyle")
3897 if (parser.checkParCount(1))
3899 s=parser.parString (ok,0);
3900 if (ok) setMapLinkStyle(s);
3902 /////////////////////////////////////////////////////////////////////
3903 } else if (com=="setNote")
3907 parser.setError (Aborted,"Nothing selected");
3908 } else if (! selbi )
3910 parser.setError (Aborted,"Type of selection is not a branch");
3911 } else if (parser.checkParCount(1))
3913 s=parser.parString (ok,0);
3917 /////////////////////////////////////////////////////////////////////
3918 } else if (com=="setSelectionColor")
3920 if (parser.checkParCount(1))
3922 QColor c=parser.parColor (ok,0);
3923 if (ok) setSelectionColorInt (c);
3925 /////////////////////////////////////////////////////////////////////
3926 } else if (com=="setURL")
3930 parser.setError (Aborted,"Nothing selected");
3931 } else if (! selbi )
3933 parser.setError (Aborted,"Type of selection is not a branch");
3934 } else if (parser.checkParCount(1))
3936 s=parser.parString (ok,0);
3939 /////////////////////////////////////////////////////////////////////
3940 } else if (com=="setVymLink")
3944 parser.setError (Aborted,"Nothing selected");
3945 } else if (! selbi )
3947 parser.setError (Aborted,"Type of selection is not a branch");
3948 } else if (parser.checkParCount(1))
3950 s=parser.parString (ok,0);
3951 if (ok) setVymLink(s);
3953 } else if (com=="sortChildren")
3957 parser.setError (Aborted,"Nothing selected");
3958 } else if (! selbi )
3960 parser.setError (Aborted,"Type of selection is not a branch");
3961 } else if (parser.checkParCount(0))
3965 /////////////////////////////////////////////////////////////////////
3966 } else if (com=="toggleFlag")
3970 parser.setError (Aborted,"Nothing selected");
3971 } else if (! selbi )
3973 parser.setError (Aborted,"Type of selection is not a branch");
3974 } else if (parser.checkParCount(1))
3976 s=parser.parString(ok,0);
3978 selbi->toggleStandardFlag(s);
3980 /////////////////////////////////////////////////////////////////////
3981 } else if (com=="unscroll")
3985 parser.setError (Aborted,"Nothing selected");
3986 } else if (! selbi )
3988 parser.setError (Aborted,"Type of selection is not a branch");
3989 } else if (parser.checkParCount(0))
3991 if (!unscrollBranch (selbi))
3992 parser.setError (Aborted,"Could not unscroll branch");
3994 /////////////////////////////////////////////////////////////////////
3995 } else if (com=="unscrollChildren")
3999 parser.setError (Aborted,"Nothing selected");
4000 } else if (! selbi )
4002 parser.setError (Aborted,"Type of selection is not a branch");
4003 } else if (parser.checkParCount(0))
4005 unscrollChildren ();
4007 /////////////////////////////////////////////////////////////////////
4008 } else if (com=="unsetFlag")
4012 parser.setError (Aborted,"Nothing selected");
4013 } else if (! selbi )
4015 parser.setError (Aborted,"Type of selection is not a branch");
4016 } else if (parser.checkParCount(1))
4018 s=parser.parString(ok,0);
4020 selbi->deactivateStandardFlag(s);
4023 parser.setError (Aborted,"Unknown command");
4026 if (parser.errorLevel()==NoError)
4028 // setChanged(); FIXME-2 should not be called e.g. for export?!
4035 // TODO Error handling
4036 qWarning("VymModel::parseAtom: Error!");
4038 qWarning(parser.errorMessage());
4040 errorMsg=parser.errorMessage();
4045 QVariant VymModel::runScript (const QString &script)
4047 parser.setScript (script);
4052 while (parser.next() && noErr)
4054 r=parseAtom(parser.getAtom(),noErr,errMsg);
4055 if (!noErr) //FIXME-3 need dialog box here
4056 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4061 void VymModel::setExportMode (bool b)
4063 // should be called before and after exports
4064 // depending on the settings
4065 if (b && settings.value("/export/useHideExport","true")=="true")
4066 setHideTmpMode (TreeItem::HideExport);
4068 setHideTmpMode (TreeItem::HideNone);
4071 void VymModel::exportImage(QString fname, bool askName, QString format)
4075 fname=getMapName()+".png";
4082 QFileDialog *fd=new QFileDialog (NULL);
4083 fd->setCaption (tr("Export map as image"));
4084 fd->setDirectory (lastImageDir);
4085 fd->setFileMode(QFileDialog::AnyFile);
4086 fd->setFilters (imageIO.getFilters() );
4089 fl=fd->selectedFiles();
4091 format=imageIO.getType(fd->selectedFilter());
4095 setExportMode (true);
4096 mapEditor->getScene()->update(); // FIXME-2 check this...
4097 QImage img (mapEditor->getImage()); //FIXME-2 calls getTotalBBox, but also in ExportHTML::doExport()
4098 img.save(fname, format);
4099 setExportMode (false);
4103 void VymModel::exportXML(QString dir, bool askForName)
4107 dir=browseDirectory(NULL,tr("Export XML to directory"));
4108 if (dir =="" && !reallyWriteDirectory(dir) )
4112 // Hide stuff during export, if settings want this
4113 setExportMode (true);
4115 // Create subdirectories
4118 // write to directory //FIXME-4 check totalBBox here...
4119 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4122 file.setName ( dir + "/"+mapName+".xml");
4123 if ( !file.open( QIODevice::WriteOnly ) )
4125 // This should neverever happen
4126 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4130 // Write it finally, and write in UTF8, no matter what
4131 QTextStream ts( &file );
4132 ts.setEncoding (QTextStream::UnicodeUTF8);
4136 // Now write image, too
4137 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4139 setExportMode (false);
4142 void VymModel::exportAO (QString fname,bool askName)
4147 ex.setFile (mapName+".txt");
4153 //ex.addFilter ("TXT (*.txt)");
4154 ex.setDir(lastImageDir);
4155 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4160 setExportMode(true);
4162 setExportMode(false);
4166 void VymModel::exportASCII(QString fname,bool askName)
4171 ex.setFile (mapName+".txt");
4177 //ex.addFilter ("TXT (*.txt)");
4178 ex.setDir(lastImageDir);
4179 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4184 setExportMode(true);
4186 setExportMode(false);
4190 void VymModel::exportHTML (const QString &dir, bool askForName)
4192 ExportXHTMLDialog dia(NULL);
4193 dia.setFilePath (filePath );
4194 dia.setMapName (mapName );
4196 if (dir!="") dia.setDir (dir);
4203 if (dia.exec()!=QDialog::Accepted)
4207 QDir d (dia.getDir());
4208 // Check, if warnings should be used before overwriting
4209 // the output directory
4210 if (d.exists() && d.count()>0)
4213 warn.showCancelButton (true);
4214 warn.setText(QString(
4215 "The directory %1 is not empty.\n"
4216 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4217 warn.setCaption("Warning: Directory not empty");
4218 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4220 if (warn.exec()!=QDialog::Accepted) ok=false;
4228 // Hide stuff during export, if settings want this
4229 setExportMode (true);
4231 ExportHTML ex (this);
4232 ex.setFile ("x/xxx.html");
4234 setExportMode (false);
4236 //exportXML (dia.getDir(),false );
4237 //dia.doExport(mapName );
4238 //if (dia.hasChanged()) setChanged();
4241 exportImage ("x/xxx.png",false,"PNG");
4246 void VymModel::exportXHTML (const QString &dir, bool askForName)
4248 ExportXHTMLDialog dia(NULL);
4249 dia.setFilePath (filePath );
4250 dia.setMapName (mapName );
4252 if (dir!="") dia.setDir (dir);
4258 if (dia.exec()!=QDialog::Accepted)
4262 QDir d (dia.getDir());
4263 // Check, if warnings should be used before overwriting
4264 // the output directory
4265 if (d.exists() && d.count()>0)
4268 warn.showCancelButton (true);
4269 warn.setText(QString(
4270 "The directory %1 is not empty.\n"
4271 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4272 warn.setCaption("Warning: Directory not empty");
4273 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4275 if (warn.exec()!=QDialog::Accepted) ok=false;
4282 exportXML (dia.getDir(),false );
4283 dia.doExport(mapName );
4284 //if (dia.hasChanged()) setChanged();
4288 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4293 if (ex.setConfigFile(cf))
4295 setExportMode (true);
4296 ex.exportPresentation();
4297 setExportMode (false);
4304 //////////////////////////////////////////////
4306 //////////////////////////////////////////////
4308 void VymModel::registerEditor(QWidget *me)
4310 mapEditor=(MapEditor*)me;
4313 void VymModel::unregisterEditor(QWidget *)
4318 void VymModel::setContextPos(QPointF p)
4323 void VymModel::unsetContextPos()
4325 contextPos=QPointF();
4328 void VymModel::updateNoteFlag()
4331 TreeItem *selti=getSelectedItem();
4334 if (textEditor->isEmpty())
4337 selti->setNote (textEditor->getText());
4338 emitDataHasChanged(selti);
4339 emitSelectionChanged();
4344 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4346 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4347 if (blockReposition) return;
4349 for (int i=0;i<rootItem->branchCount(); i++)
4350 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4351 //emitSelectionChanged();
4355 void VymModel::setMapLinkStyle (const QString & s)
4360 case LinkableMapObj::Line :
4363 case LinkableMapObj::Parabel:
4364 snow="StyleParabel";
4366 case LinkableMapObj::PolyLine:
4367 snow="StylePolyLine";
4369 case LinkableMapObj::PolyParabel:
4370 snow="StylePolyParabel";
4373 snow="UndefinedStyle";
4378 QString("setMapLinkStyle (\"%1\")").arg(s),
4379 QString("setMapLinkStyle (\"%1\")").arg(snow),
4380 QString("Set map link style (\"%1\")").arg(s)
4384 linkstyle=LinkableMapObj::Line;
4385 else if (s=="StyleParabel")
4386 linkstyle=LinkableMapObj::Parabel;
4387 else if (s=="StylePolyLine")
4388 linkstyle=LinkableMapObj::PolyLine;
4389 else if (s=="StylePolyParabel")
4390 linkstyle=LinkableMapObj::PolyParabel;
4392 linkstyle=LinkableMapObj::UndefinedStyle;
4394 BranchItem *cur=NULL;
4395 BranchItem *prev=NULL;
4397 nextBranch (cur,prev);
4400 bo=(BranchObj*)(cur->getLMO() );
4401 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4402 cur=nextBranch(cur,prev);
4407 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4412 void VymModel::setMapDefLinkColor(QColor col)
4414 if ( !col.isValid() ) return;
4416 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4417 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4418 QString("Set map link color to %1").arg(col.name())
4422 BranchItem *cur=NULL;
4423 BranchItem *prev=NULL;
4425 cur=nextBranch(cur,prev);
4428 bo=(BranchObj*)(cur->getLMO() );
4430 nextBranch(cur,prev);
4435 void VymModel::setMapLinkColorHintInt()
4437 // called from setMapLinkColorHint(lch) or at end of parse
4438 BranchItem *cur=NULL;
4439 BranchItem *prev=NULL;
4441 cur=nextBranch(cur,prev);
4444 bo=(BranchObj*)(cur->getLMO() );
4446 cur=nextBranch(cur,prev);
4450 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4453 setMapLinkColorHintInt();
4456 void VymModel::toggleMapLinkColorHint()
4458 if (linkcolorhint==LinkableMapObj::HeadingColor)
4459 linkcolorhint=LinkableMapObj::DefaultColor;
4461 linkcolorhint=LinkableMapObj::HeadingColor;
4462 BranchItem *cur=NULL;
4463 BranchItem *prev=NULL;
4465 cur=nextBranch(cur,prev);
4468 bo=(BranchObj*)(cur->getLMO() );
4470 nextBranch(cur,prev);
4474 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4475 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4477 Q3FileDialog *fd=new Q3FileDialog( NULL);
4478 fd->setMode (Q3FileDialog::ExistingFile);
4479 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4480 ImagePreview *p =new ImagePreview (fd);
4481 fd->setContentsPreviewEnabled( TRUE );
4482 fd->setContentsPreview( p, p );
4483 fd->setPreviewMode( Q3FileDialog::Contents );
4484 fd->setCaption(vymName+" - " +tr("Load background image"));
4485 fd->setDir (lastImageDir);
4488 if ( fd->exec() == QDialog::Accepted )
4490 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4491 lastImageDir=QDir (fd->dirPath());
4492 setMapBackgroundImage (fd->selectedFile());
4496 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4498 QColor oldcol=mapScene->backgroundBrush().color();
4502 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4504 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4505 QString("Set background color of map to %1").arg(col.name()));
4508 brush.setTextureImage (QPixmap (fn));
4509 mapScene->setBackgroundBrush(brush);
4512 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4514 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4515 if ( !col.isValid() ) return;
4516 setMapBackgroundColor( col );
4520 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4522 QColor oldcol=mapScene->backgroundBrush().color();
4524 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4525 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4526 QString("Set background color of map to %1").arg(col.name()));
4527 mapScene->setBackgroundBrush(col);
4530 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4532 return mapScene->backgroundBrush().color();
4536 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4538 return linkcolorhint;
4541 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4543 return defLinkColor;
4546 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4551 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4553 return defXLinkColor;
4556 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4561 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4563 return defXLinkWidth;
4566 void VymModel::move(const double &x, const double &y)
4569 MapItem *seli = (MapItem*)getSelectedItem();
4570 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4572 LinkableMapObj *lmo=seli->getLMO();
4575 QPointF ap(lmo->getAbsPos());
4579 QString ps=qpointFToString(ap);
4580 QString s=getSelectString(seli);
4583 s, "move "+qpointFToString(to),
4584 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4587 emitSelectionChanged();
4593 void VymModel::moveRel (const double &x, const double &y)
4596 MapItem *seli = (MapItem*)getSelectedItem();
4597 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4599 LinkableMapObj *lmo=seli->getLMO();
4602 QPointF rp(lmo->getRelPos());
4606 QString ps=qpointFToString (lmo->getRelPos());
4607 QString s=getSelectString(seli);
4610 s, "moveRel "+qpointFToString(to),
4611 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4612 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4614 lmo->updateLinkGeometry();
4615 emitSelectionChanged();
4622 void VymModel::animate()
4624 animationTimer->stop();
4627 while (i<animObjList.size() )
4629 bo=(BranchObj*)animObjList.at(i);
4634 animObjList.removeAt(i);
4641 QItemSelection sel=selModel->selection();
4642 emit (selectionChanged(sel,sel));
4645 if (!animObjList.isEmpty()) animationTimer->start();
4649 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4651 if (start==dest) return;
4652 if (bo && bo->getTreeItem()->depth()>0)
4655 ap.setStart (start);
4657 ap.setTicks (animationTicks);
4658 ap.setAnimated (true);
4659 bo->setAnimation (ap);
4660 animObjList.append( bo );
4661 animationTimer->setSingleShot (true);
4662 animationTimer->start(animationInterval);
4666 void VymModel::stopAnimation (MapObj *mo)
4668 int i=animObjList.indexOf(mo);
4670 animObjList.removeAt (i);
4673 void VymModel::sendSelection()
4675 if (netstate!=Server) return;
4676 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4679 void VymModel::newServer()
4683 tcpServer = new QTcpServer(this);
4684 if (!tcpServer->listen(QHostAddress::Any,port)) {
4685 QMessageBox::critical(NULL, "vym server",
4686 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4687 //FIXME-3 needed? we are no widget any longer... close();
4690 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4692 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4695 void VymModel::connectToServer()
4698 server="salam.suse.de";
4700 clientSocket = new QTcpSocket (this);
4701 clientSocket->abort();
4702 clientSocket->connectToHost(server ,port);
4703 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4704 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4705 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4707 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4712 void VymModel::newClient()
4714 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4715 connect(newClient, SIGNAL(disconnected()),
4716 newClient, SLOT(deleteLater()));
4718 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4720 clientList.append (newClient);
4724 void VymModel::sendData(const QString &s)
4726 if (clientList.size()==0) return;
4728 // Create bytearray to send
4730 QDataStream out(&block, QIODevice::WriteOnly);
4731 out.setVersion(QDataStream::Qt_4_0);
4733 // Reserve some space for blocksize
4736 // Write sendCounter
4737 out << sendCounter++;
4742 // Go back and write blocksize so far
4743 out.device()->seek(0);
4744 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4748 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4750 for (int i=0; i<clientList.size(); ++i)
4752 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4753 clientList.at(i)->write (block);
4757 void VymModel::readData ()
4759 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4762 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4766 QDataStream in(clientSocket);
4767 in.setVersion(QDataStream::Qt_4_0);
4775 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4778 parseAtom (t,noErr,errMsg);
4784 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4786 switch (socketError) {
4787 case QAbstractSocket::RemoteHostClosedError:
4789 case QAbstractSocket::HostNotFoundError:
4790 QMessageBox::information(NULL, vymName +" Network client",
4791 "The host was not found. Please check the "
4792 "host name and port settings.");
4794 case QAbstractSocket::ConnectionRefusedError:
4795 QMessageBox::information(NULL, vymName + " Network client",
4796 "The connection was refused by the peer. "
4797 "Make sure the fortune server is running, "
4798 "and check that the host name and port "
4799 "settings are correct.");
4802 QMessageBox::information(NULL, vymName + " Network client",
4803 QString("The following error occurred: %1.")
4804 .arg(clientSocket->errorString()));
4808 /* FIXME-3 Playing with DBUS...
4809 QDBusVariant VymModel::query (const QString &query)
4811 TreeItem *selti=getSelectedItem();
4813 return QDBusVariant (selti->getHeading());
4815 return QDBusVariant ("Nothing selected.");
4819 void VymModel::testslot() //FIXME-3 Playing with DBUS
4821 cout << "VM::testslot called\n";
4824 void VymModel::selectMapSelectionColor()
4826 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4827 setSelectionColor (col);
4830 void VymModel::setSelectionColorInt (QColor col)
4832 if ( !col.isValid() ) return;
4834 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4835 QString("setSelectionColor (%1)").arg(col.name()),
4836 QString("Set color of selection box to %1").arg(col.name())
4839 mapEditor->setSelectionColor (col);
4842 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4844 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4845 //FIXME-3 emitShowSelection();
4849 void VymModel::emitSelectionChanged()
4851 QItemSelection newsel=selModel->selection();
4852 emitSelectionChanged (newsel);
4855 void VymModel::setSelectionColor(QColor col)
4857 if ( !col.isValid() ) return;
4859 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4860 QString("setSelectionColor (%1)").arg(col.name()),
4861 QString("Set color of selection box to %1").arg(col.name())
4863 setSelectionColorInt (col);
4866 QColor VymModel::getSelectionColor()
4868 return mapEditor->getSelectionColor();
4871 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4874 for (int i=0;i<rootItem->branchCount();i++)
4875 rootItem->getBranchNum(i)->setHideTmp (mode);
4877 if (mode==TreeItem::HideExport)
4883 //////////////////////////////////////////////
4884 // Selection related
4885 //////////////////////////////////////////////
4887 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4892 QItemSelectionModel* VymModel::getSelectionModel()
4897 void VymModel::setSelectionBlocked (bool b)
4902 bool VymModel::isSelectionBlocked()
4904 return selectionBlocked;
4907 bool VymModel::select ()
4909 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4912 bool VymModel::select (const QString &s)
4919 TreeItem *ti=findBySelectString(s);
4920 if (ti) return select (index(ti));
4924 bool VymModel::select (LinkableMapObj *lmo)
4926 QItemSelection oldsel=selModel->selection();
4929 return select (index (lmo->getTreeItem()) );
4934 bool VymModel::select (TreeItem *ti)
4936 if (ti) return select (index(ti));
4940 bool VymModel::select (const QModelIndex &index)
4942 if (index.isValid() )
4944 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4945 BranchItem *bi=getSelectedBranch();
4946 if (bi) bi->setLastSelectedBranch();
4952 void VymModel::unselect()
4954 if (!selModel->selectedIndexes().isEmpty())
4956 lastSelectString=getSelectString();
4957 selModel->clearSelection();
4961 bool VymModel::reselect()
4963 return select (lastSelectString);
4966 void VymModel::emitShowSelection()
4968 if (!blockReposition)
4969 emit (showSelection() );
4972 void VymModel::emitNoteHasChanged (TreeItem *ti)
4974 QModelIndex ix=index(ti);
4975 emit (noteHasChanged (ix) );
4978 void VymModel::emitDataHasChanged (TreeItem *ti)
4980 QModelIndex ix=index(ti);
4981 emit (dataChanged (ix,ix) );
4985 bool VymModel::selectFirstBranch()
4987 TreeItem *ti=getSelectedBranch();
4990 TreeItem *par=ti->parent();
4993 TreeItem *ti2=par->getFirstBranch();
4994 if (ti2) return select(ti2);
5000 bool VymModel::selectLastBranch()
5002 TreeItem *ti=getSelectedBranch();
5005 TreeItem *par=ti->parent();
5008 TreeItem *ti2=par->getLastBranch();
5009 if (ti2) return select(ti2);
5015 bool VymModel::selectLastSelectedBranch()
5017 BranchItem *bi=getSelectedBranch();
5020 bi=bi->getLastSelectedBranch();
5021 if (bi) return select (bi);
5026 bool VymModel::selectParent()
5028 TreeItem *ti=getSelectedItem();
5039 TreeItem::Type VymModel::selectionType()
5041 QModelIndexList list=selModel->selectedIndexes();
5042 if (list.isEmpty()) return TreeItem::Undefined;
5043 TreeItem *ti = getItem (list.first() );
5044 return ti->getType();
5048 LinkableMapObj* VymModel::getSelectedLMO()
5050 QModelIndexList list=selModel->selectedIndexes();
5051 if (!list.isEmpty() )
5053 TreeItem *ti = getItem (list.first() );
5054 TreeItem::Type type=ti->getType();
5055 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5056 return ((MapItem*)ti)->getLMO();
5061 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5063 TreeItem *ti = getSelectedBranch();
5065 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5070 BranchItem* VymModel::getSelectedBranch()
5072 QModelIndexList list=selModel->selectedIndexes();
5073 if (!list.isEmpty() )
5075 TreeItem *ti = getItem (list.first() );
5076 TreeItem::Type type=ti->getType();
5077 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5078 return (BranchItem*)ti;
5083 ImageItem* VymModel::getSelectedImage()
5085 QModelIndexList list=selModel->selectedIndexes();
5086 if (!list.isEmpty())
5088 TreeItem *ti=getItem (list.first());
5089 if (ti && ti->getType()==TreeItem::Image)
5090 return (ImageItem*)ti;
5095 AttributeItem* VymModel::getSelectedAttribute()
5097 QModelIndexList list=selModel->selectedIndexes();
5098 if (!list.isEmpty() )
5100 TreeItem *ti = getItem (list.first() );
5101 TreeItem::Type type=ti->getType();
5102 if (type ==TreeItem::Attribute)
5103 return (AttributeItem*)ti;
5108 TreeItem* VymModel::getSelectedItem()
5110 QModelIndexList list=selModel->selectedIndexes();
5111 if (!list.isEmpty() )
5112 return getItem (list.first() );
5117 QModelIndex VymModel::getSelectedIndex()
5119 QModelIndexList list=selModel->selectedIndexes();
5120 if (list.isEmpty() )
5121 return QModelIndex();
5123 return list.first();
5126 QString VymModel::getSelectString ()
5128 return getSelectString (getSelectedItem());
5131 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5133 if (!lmo) return QString();
5134 return getSelectString (lmo->getTreeItem() );
5137 QString VymModel::getSelectString (TreeItem *ti)
5141 switch (ti->getType())
5143 case TreeItem::MapCenter: s="mc:"; break;
5144 case TreeItem::Branch: s="bo:";break;
5145 case TreeItem::Image: s="fi:";break;
5146 case TreeItem::Attribute: s="ai:";break;
5147 case TreeItem::XLink: s="xl:";break;
5149 s="unknown type in VymModel::getSelectString()";
5152 s= s + QString("%1").arg(ti->num());
5154 // call myself recursively
5155 s= getSelectString(ti->parent()) +","+s;