1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
13 #include "exportxhtmldialog.h"
15 #include "findresultmodel.h"
16 #include "geometry.h" // for addBBox
17 #include "mainwindow.h"
22 #include "warningdialog.h"
23 #include "xlinkitem.h"
24 #include "xml-freemind.h"
30 extern Main *mainWindow;
31 extern QDBusConnection dbusConnection;
33 extern Settings settings;
34 extern QString tmpVymDir;
36 extern TextEditor *textEditor;
37 extern FlagRow *standardFlagsMaster;
39 extern QString clipboardDir;
40 extern QString clipboardFile;
41 extern bool clipboardEmpty;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
47 extern QDir vymBaseDir;
49 extern QDir lastImageDir;
50 extern QDir lastFileDir;
52 extern Settings settings;
54 uint VymModel::idLast=0; // make instance
58 //cout << "Const VymModel\n";
60 rootItem->setModel (this);
66 //cout << "Destr VymModel\n";
67 autosaveTimer->stop();
68 fileChangedTimer->stop();
72 void VymModel::clear()
74 while (rootItem->childCount() >0)
75 deleteItem (rootItem->getChildNum(0) );
78 void VymModel::init ()
83 // Also no scene yet (should not be needed anyway) FIXME-3 VM
97 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
98 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
99 mainWindow->updateHistory (undoSet);
102 makeTmpDirectories();
107 fileName=tr("unnamed");
109 blockReposition=false;
110 blockSaveState=false;
112 autosaveTimer=new QTimer (this);
113 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
115 fileChangedTimer=new QTimer (this);
116 fileChangedTimer->start(3000);
117 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
122 selectionBlocked=false;
127 // animations // FIXME-3 switch to new animation system
128 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
129 animationTicks=settings.readNumEntry("/animation/ticks",10);
130 animationInterval=settings.readNumEntry("/animation/interval",50);
132 animationTimer=new QTimer (this);
133 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
136 defLinkColor=QColor (0,0,255);
137 defXLinkColor=QColor (180,180,180);
138 linkcolorhint=LinkableMapObj::DefaultColor;
139 linkstyle=LinkableMapObj::PolyParabel;
141 defXLinkColor=QColor (230,230,230);
143 hidemode=TreeItem::HideNone;
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(mapID),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(mapID);
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-4 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();
361 BranchItem *bi=getSelectedBranch();
362 if (!bi) return aborted;
363 if (lmode==ImportAdd)
364 saveStateChangingPart(
367 QString("addMapInsert (%1)").arg(fname),
368 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
370 saveStateChangingPart(
373 QString("addMapReplace(%1)").arg(fname),
374 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
378 // Create temporary directory for packing
380 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
383 QMessageBox::critical( 0, tr( "Critical Load Error" ),
384 tr("Couldn't create temporary directory before load\n"));
389 err=unzipDir (tmpZipDir,fname);
399 // Look for mapname.xml
400 xmlfile= fname.left(fname.findRev(".",-1,true));
401 xmlfile=xmlfile.section( '/', -1 );
402 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
403 if (!mfile.exists() )
405 // mapname.xml does not exist, well,
406 // maybe someone renamed the mapname.vym file...
407 // Try to find any .xml in the toplevel
408 // directory of the .vym file
409 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
410 if (flist.count()==1)
412 // Only one entry, take this one
413 xmlfile=tmpZipDir + "/"+flist.first();
416 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
417 *it=tmpZipDir + "/" + *it;
418 // TODO Multiple entries, load all (but only the first one into this ME)
419 //mainWindow->fileLoadFromTmp (flist);
420 //returnCode=1; // Silently forget this attempt to load
421 qWarning ("MainWindow::load (fn) multimap found...");
424 if (flist.isEmpty() )
426 QMessageBox::critical( 0, tr( "Critical Load Error" ),
427 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
430 } //file doesn't exist
432 xmlfile=mfile.name();
435 QFile file( xmlfile);
437 // I am paranoid: file should exist anyway
438 // according to check in mainwindow.
441 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
442 tr(QString("Couldn't open map %1").arg(file.name())));
446 bool blockSaveStateOrg=blockSaveState;
447 blockReposition=true;
449 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
450 QXmlInputSource source( file);
451 QXmlSimpleReader reader;
452 reader.setContentHandler( handler );
453 reader.setErrorHandler( handler );
454 handler->setModel ( this);
457 // We need to set the tmpDir in order to load files with rel. path
462 tmpdir=fname.left(fname.findRev("/",-1));
463 handler->setTmpDir (tmpdir);
464 handler->setInputFile (file.name());
465 handler->setLoadMode (lmode);
466 bool ok = reader.parse( source );
467 blockReposition=false;
468 blockSaveState=blockSaveStateOrg;
469 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
474 emitSelectionChanged();
480 autosaveTimer->stop();
483 // Reset timestamp to check for later updates of file
484 fileChangedTime=QFileInfo (destPath).lastModified();
487 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
488 tr( handler->errorProtocol() ) );
490 // Still return "success": the map maybe at least
491 // partially read by the parser
496 removeDir (QDir(tmpZipDir));
498 // Restore original zip state
505 ErrorCode VymModel::save (const SaveMode &savemode)
509 QString safeFilePath;
511 ErrorCode err=success;
515 mapFileName=mapName+".xml";
517 // use name given by user, even if he chooses .doc
518 mapFileName=fileName;
520 // Look, if we should zip the data:
523 QMessageBox mb( vymName,
524 tr("The map %1\ndid not use the compressed "
525 "vym file format.\nWriting it uncompressed will also write images \n"
526 "and flags and thus may overwrite files in the "
527 "given directory\n\nDo you want to write the map").arg(filePath),
528 QMessageBox::Warning,
529 QMessageBox::Yes | QMessageBox::Default,
531 QMessageBox::Cancel | QMessageBox::Escape);
532 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
533 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
534 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
537 case QMessageBox::Yes:
538 // save compressed (default file format)
541 case QMessageBox::No:
545 case QMessageBox::Cancel:
552 // First backup existing file, we
553 // don't want to add to old zip archives
557 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
559 QString backupFileName(destPath + "~");
560 QFile backupFile(backupFileName);
561 if (backupFile.exists() && !backupFile.remove())
563 QMessageBox::warning(0, tr("Save Error"),
564 tr("%1\ncould not be removed before saving").arg(backupFileName));
566 else if (!f.rename(backupFileName))
568 QMessageBox::warning(0, tr("Save Error"),
569 tr("%1\ncould not be renamed before saving").arg(destPath));
576 // Create temporary directory for packing
578 tmpZipDir=makeTmpDir (ok,"vym-zip");
581 QMessageBox::critical( 0, tr( "Critical Load Error" ),
582 tr("Couldn't create temporary directory before save\n"));
586 safeFilePath=filePath;
587 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
590 // Create mapName and fileDir
591 makeSubDirs (fileDir);
594 if (savemode==CompleteMap || selModel->selection().isEmpty())
597 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
600 autosaveTimer->stop();
605 if (selectionType()==TreeItem::Image)
608 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
609 // TODO take care of multiselections
612 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
615 qWarning ("ME::saveStringToDisk failed!");
621 if (err==success) err=zipDir (tmpZipDir,destPath);
624 removeDir (QDir(tmpZipDir));
626 // Restore original filepath outside of tmp zip dir
627 setFilePath (safeFilePath);
631 fileChangedTime=QFileInfo (destPath).lastModified();
635 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
637 QString pathDir=path.left(path.findRev("/"));
643 // We need to parse saved XML data
644 parseVYMHandler handler;
645 QXmlInputSource source( file);
646 QXmlSimpleReader reader;
647 reader.setContentHandler( &handler );
648 reader.setErrorHandler( &handler );
649 handler.setModel ( this);
650 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
651 if (undoSel.isEmpty())
655 handler.setLoadMode (NewMap);
659 handler.setLoadMode (ImportReplace);
661 blockReposition=true;
662 bool ok = reader.parse( source );
663 blockReposition=false;
666 // This should never ever happen
667 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
668 handler.errorProtocol());
671 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
674 bool VymModel::addMapInsertInt (const QString &path)
676 QString pathDir=path.left(path.findRev("/"));
682 // We need to parse saved XML data
683 parseVYMHandler handler;
684 QXmlInputSource source( file);
685 QXmlSimpleReader reader;
686 reader.setContentHandler( &handler );
687 reader.setErrorHandler( &handler );
688 handler.setModel (this);
689 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
690 handler.setLoadMode (ImportAdd);
691 blockReposition=true;
692 bool ok = reader.parse( source );
693 blockReposition=false;
694 if ( ok ) return true;
696 // This should never ever happen
697 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
698 handler.errorProtocol());
701 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
705 bool VymModel::addMapInsertInt (const QString &path, int pos)
707 BranchItem *selbi=getSelectedBranch();
710 if (addMapInsertInt (path))
712 if (selbi->depth()>0)
713 relinkBranch (selbi->getLastBranch(), selbi,pos);
717 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
721 qWarning ("ME::addMapInsertInt nothing selected");
725 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
727 ImageItem *ii=createImage(dst);
737 void VymModel::loadFloatImage ()
739 BranchItem *selbi=getSelectedBranch();
743 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
744 fd->setMode (Q3FileDialog::ExistingFiles);
745 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
746 ImagePreview *p =new ImagePreview (fd);
747 fd->setContentsPreviewEnabled( TRUE );
748 fd->setContentsPreview( p, p );
749 fd->setPreviewMode( Q3FileDialog::Contents );
750 fd->setCaption(vymName+" - " +tr("Load image"));
751 fd->setDir (lastImageDir);
754 if ( fd->exec() == QDialog::Accepted )
756 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
757 lastImageDir=QDir (fd->dirPath());
760 for (int j=0; j<fd->selectedFiles().count(); j++)
762 s=fd->selectedFiles().at(j);
763 ii=loadFloatImageInt (selbi,s);
764 //FIXME-3 check savestate for loadImage
770 QString ("loadImage (%1)").arg(s ),
771 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
774 // TODO loadFIO error handling
775 qWarning ("Failed to load "+s);
783 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
788 void VymModel::saveFloatImage ()
790 ImageItem *ii=getSelectedImage();
793 QFileDialog *fd=new QFileDialog( NULL);
794 fd->setFilters (imageIO.getFilters());
795 fd->setCaption(vymName+" - " +tr("Save image"));
796 fd->setFileMode( QFileDialog::AnyFile );
797 fd->setDirectory (lastImageDir);
798 // fd->setSelection (fio->getOriginalFilename());
802 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
804 fn=fd->selectedFiles().at(0);
805 if (QFile (fn).exists() )
807 QMessageBox mb( vymName,
808 tr("The file %1 exists already.\n"
809 "Do you want to overwrite it?").arg(fn),
810 QMessageBox::Warning,
811 QMessageBox::Yes | QMessageBox::Default,
812 QMessageBox::Cancel | QMessageBox::Escape,
813 QMessageBox::NoButton );
815 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
816 mb.setButtonText( QMessageBox::No, tr("Cancel"));
819 case QMessageBox::Yes:
822 case QMessageBox::Cancel:
829 saveFloatImageInt (ii,fd->selectedFilter(),fn );
836 void VymModel::importDirInt(BranchItem *dst, QDir d)
838 BranchItem *selbi=getSelectedBranch();
842 // Traverse directories
843 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
844 QFileInfoList list = d.entryInfoList();
847 for (int i = 0; i < list.size(); ++i)
850 if (fi.fileName() != "." && fi.fileName() != ".." )
852 bi=addNewBranchInt(dst,-2);
853 bi->setHeading (fi.fileName() ); // FIXME-3 check this
854 bi->setHeadingColor (QColor("blue"));
856 if ( !d.cd(fi.fileName()) )
857 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
860 // Recursively add subdirs
867 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
868 list = d.entryInfoList();
870 for (int i = 0; i < list.size(); ++i)
873 bi=addNewBranchInt (dst,-2);
874 bi->setHeading (fi.fileName() );
875 bi->setHeadingColor (QColor("black"));
876 if (fi.fileName().right(4) == ".vym" )
877 bi->setVymLink (fi.filePath());
882 void VymModel::importDirInt (const QString &s)
884 BranchItem *selbi=getSelectedBranch();
887 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
890 importDirInt (selbi,d);
894 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
896 BranchItem *selbi=getSelectedBranch();
900 filters <<"VYM map (*.vym)";
901 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
902 fd->setMode (QFileDialog::DirectoryOnly);
903 fd->setFilters (filters);
904 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
908 if ( fd->exec() == QDialog::Accepted )
910 importDirInt (fd->selectedFile() );
912 //FIXME-3 VM needed? scene()->update();
918 void VymModel::autosave()
923 cout << "VymModel::autosave rejected due to missing filePath\n";
926 QDateTime now=QDateTime().currentDateTime();
928 // Disable autosave, while we have gone back in history
929 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
930 if (redosAvail>0) return;
932 // Also disable autosave for new map without filename
933 if (filePath.isEmpty()) return;
936 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
938 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
939 mainWindow->fileSave (this);
942 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
947 void VymModel::fileChanged()
949 // Check if file on disk has changed meanwhile
950 if (!filePath.isEmpty())
952 QDateTime tmod=QFileInfo (filePath).lastModified();
953 if (tmod>fileChangedTime)
955 // FIXME-3 VM switch to current mapeditor and finish lineedits...
956 QMessageBox mb( vymName,
957 tr("The file of the map on disk has changed:\n\n"
958 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
959 QMessageBox::Question,
961 QMessageBox::Cancel | QMessageBox::Default,
962 QMessageBox::NoButton );
964 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
965 mb.setButtonText( QMessageBox::No, tr("Ignore"));
968 case QMessageBox::Yes:
970 load (filePath,NewMap,fileType);
971 case QMessageBox::Cancel:
972 fileChangedTime=tmod; // allow autosave to overwrite newer file!
978 bool VymModel::isDefault()
983 void VymModel::makeDefault()
989 bool VymModel::hasChanged()
994 void VymModel::setChanged()
997 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1001 latestAddedItem=NULL;
1005 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1007 if (!lmo || !lmo->getTreeItem() ) return QString();
1008 return getObjectName (lmo->getTreeItem() );
1012 QString VymModel::getObjectName (TreeItem *ti)
1015 if (!ti) return QString("Error: NULL has no name!");
1017 if (s=="") s="unnamed";
1019 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1022 void VymModel::redo()
1024 // Can we undo at all?
1025 if (redosAvail<1) return;
1027 bool blockSaveStateOrg=blockSaveState;
1028 blockSaveState=true;
1032 if (undosAvail<stepsTotal) undosAvail++;
1034 if (curStep>stepsTotal) curStep=1;
1035 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1036 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1037 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1038 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1039 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1040 QString version=undoSet.readEntry ("/history/version");
1042 /* TODO Maybe check for version, if we save the history
1043 if (!checkVersion(version))
1044 QMessageBox::warning(0,tr("Warning"),
1045 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1048 // Find out current undo directory
1049 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1053 cout << "VymModel::redo() begin\n";
1054 cout << " undosAvail="<<undosAvail<<endl;
1055 cout << " redosAvail="<<redosAvail<<endl;
1056 cout << " curStep="<<curStep<<endl;
1057 cout << " ---------------------------"<<endl;
1058 cout << " comment="<<comment.toStdString()<<endl;
1059 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1060 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1061 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1062 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1063 cout << " ---------------------------"<<endl<<endl;
1066 // select object before redo
1067 if (!redoSelection.isEmpty())
1068 select (redoSelection);
1073 parseAtom (redoCommand,noErr,errMsg);
1075 blockSaveState=blockSaveStateOrg;
1077 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1078 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1079 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1080 undoSet.writeSettings(histPath);
1082 mainWindow->updateHistory (undoSet);
1085 /* TODO remove testing
1086 cout << "ME::redo() end\n";
1087 cout << " undosAvail="<<undosAvail<<endl;
1088 cout << " redosAvail="<<redosAvail<<endl;
1089 cout << " curStep="<<curStep<<endl;
1090 cout << " ---------------------------"<<endl<<endl;
1096 bool VymModel::isRedoAvailable()
1098 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1104 void VymModel::undo()
1106 // Can we undo at all?
1107 if (undosAvail<1) return;
1109 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1111 bool blockSaveStateOrg=blockSaveState;
1112 blockSaveState=true;
1114 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1115 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1116 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1117 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1118 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1119 QString version=undoSet.readEntry ("/history/version");
1121 /* TODO Maybe check for version, if we save the history
1122 if (!checkVersion(version))
1123 QMessageBox::warning(0,tr("Warning"),
1124 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1127 // Find out current undo directory
1128 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1130 // select object before undo
1131 if (!select (undoSelection))
1133 qWarning ("VymModel::undo() Could not select object for undo");
1140 cout << "VymModel::undo() begin\n";
1141 cout << " undosAvail="<<undosAvail<<endl;
1142 cout << " redosAvail="<<redosAvail<<endl;
1143 cout << " curStep="<<curStep<<endl;
1144 cout << " ---------------------------"<<endl;
1145 cout << " comment="<<comment.toStdString()<<endl;
1146 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1147 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1148 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1149 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1150 cout << " ---------------------------"<<endl<<endl;
1155 parseAtom (undoCommand,noErr,errMsg);
1159 if (curStep<1) curStep=stepsTotal;
1163 blockSaveState=blockSaveStateOrg;
1165 cout << "VymModel::undo() end\n";
1166 cout << " undosAvail="<<undosAvail<<endl;
1167 cout << " redosAvail="<<redosAvail<<endl;
1168 cout << " curStep="<<curStep<<endl;
1169 cout << " ---------------------------"<<endl<<endl;
1172 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1173 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1174 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1175 undoSet.writeSettings(histPath);
1177 mainWindow->updateHistory (undoSet);
1179 //emitSelectionChanged();
1182 bool VymModel::isUndoAvailable()
1184 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1190 void VymModel::gotoHistoryStep (int i)
1192 // Restore variables
1193 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1194 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1196 if (i<0) i=undosAvail+redosAvail;
1198 // Clicking above current step makes us undo things
1201 for (int j=0; j<undosAvail-i; j++) undo();
1204 // Clicking below current step makes us redo things
1206 for (int j=undosAvail; j<i; j++)
1208 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1212 // And ignore clicking the current row ;-)
1216 QString VymModel::getHistoryPath()
1218 QString histName(QString("history-%1").arg(curStep));
1219 return (tmpMapDir+"/"+histName);
1222 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1224 sendData(redoCom); //FIXME-3 testing
1229 if (blockSaveState) return;
1231 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1233 // Find out current undo directory
1234 if (undosAvail<stepsTotal) undosAvail++;
1236 if (curStep>stepsTotal) curStep=1;
1238 QString backupXML="";
1239 QString histDir=getHistoryPath();
1240 QString bakMapPath=histDir+"/map.xml";
1242 // Create histDir if not available
1245 makeSubDirs (histDir);
1247 // Save depending on how much needs to be saved
1249 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1251 QString undoCommand="";
1252 if (savemode==UndoCommand)
1254 undoCommand=undoCom;
1256 else if (savemode==PartOfMap )
1258 undoCommand=undoCom;
1259 undoCommand.replace ("PATH",bakMapPath);
1263 if (!backupXML.isEmpty())
1264 // Write XML Data to disk
1265 saveStringToDisk (bakMapPath,backupXML);
1267 // We would have to save all actions in a tree, to keep track of
1268 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1271 // Write the current state to disk
1272 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1273 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1274 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1275 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1276 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1277 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1278 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1280 undoSet.setEntry (QString("/history/version"),vymVersion);
1281 undoSet.writeSettings(histPath);
1285 // TODO remove after testing
1286 //cout << " into="<< histPath.toStdString()<<endl;
1287 cout << " stepsTotal="<<stepsTotal<<
1288 ", undosAvail="<<undosAvail<<
1289 ", redosAvail="<<redosAvail<<
1290 ", curStep="<<curStep<<endl;
1291 cout << " ---------------------------"<<endl;
1292 cout << " comment="<<comment.toStdString()<<endl;
1293 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1294 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1295 cout << " redoCom="<<redoCom.toStdString()<<endl;
1296 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1297 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1298 cout << " ---------------------------"<<endl;
1301 mainWindow->updateHistory (undoSet);
1307 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1309 // save the selected part of the map, Undo will replace part of map
1310 QString undoSelection="";
1312 undoSelection=getSelectString(undoSel);
1314 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1315 QString redoSelection="";
1317 redoSelection=getSelectString(undoSel);
1319 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1322 saveState (PartOfMap,
1323 undoSelection, "addMapReplace (\"PATH\")",
1329 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1333 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1336 QString undoSelection;
1337 QString redoSelection=getSelectString(redoSel);
1338 if (redoSel->getType()==TreeItem::Branch)
1340 undoSelection=getSelectString (redoSel->parent());
1341 // save the selected branch of the map, Undo will insert part of map
1342 saveState (PartOfMap,
1343 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1344 redoSelection, "delete ()",
1348 if (redoSel->getType()==TreeItem::MapCenter)
1350 // save the selected branch of the map, Undo will insert part of map
1351 saveState (PartOfMap,
1352 undoSelection, QString("addMapInsert (\"PATH\")"),
1353 redoSelection, "delete ()",
1360 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1362 // "Normal" savestate: save commands, selections and comment
1363 // so just save commands for undo and redo
1364 // and use current selection
1366 QString redoSelection="";
1367 if (redoSel) redoSelection=getSelectString(redoSel);
1368 QString undoSelection="";
1369 if (undoSel) undoSelection=getSelectString(undoSel);
1371 saveState (UndoCommand,
1378 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1380 // "Normal" savestate: save commands, selections and comment
1381 // so just save commands for undo and redo
1382 // and use current selection
1383 saveState (UndoCommand,
1390 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1392 // "Normal" savestate applied to model (no selection needed):
1393 // save commands and comment
1394 saveState (UndoCommand,
1402 QGraphicsScene* VymModel::getScene ()
1407 TreeItem* VymModel::findBySelectString(QString s)
1409 if (s.isEmpty() ) return NULL;
1411 // Old maps don't have multiple mapcenters and don't save full path
1412 if (s.left(2) !="mc")
1415 QStringList parts=s.split (",");
1418 TreeItem *ti=rootItem;
1420 while (!parts.isEmpty() )
1422 typ=parts.first().left(2);
1423 n=parts.first().right(parts.first().length() - 3).toInt();
1424 parts.removeFirst();
1425 if (typ=="mc" || typ=="bo")
1426 ti=ti->getBranchNum (n);
1428 ti=ti->getImageNum (n);
1430 ti=ti->getAttributeNum (n);
1432 ti=ti->getXLinkNum (n);
1433 if(!ti) return NULL;
1438 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1440 BranchItem *cur=NULL;
1441 BranchItem *prev=NULL;
1442 nextBranch(cur,prev);
1445 if (i==cur->getID() ) return cur;
1446 nextBranch(cur,prev);
1451 //////////////////////////////////////////////
1453 //////////////////////////////////////////////
1454 void VymModel::setVersion (const QString &s)
1459 QString VymModel::getVersion()
1464 void VymModel::setAuthor (const QString &s)
1467 QString ("setMapAuthor (\"%1\")").arg(author),
1468 QString ("setMapAuthor (\"%1\")").arg(s),
1469 QString ("Set author of map to \"%1\"").arg(s)
1474 QString VymModel::getAuthor()
1479 void VymModel::setComment (const QString &s)
1482 QString ("setMapComment (\"%1\")").arg(comment),
1483 QString ("setMapComment (\"%1\")").arg(s),
1484 QString ("Set comment of map")
1489 QString VymModel::getComment ()
1494 QString VymModel::getDate ()
1496 return QDate::currentDate().toString ("yyyy-MM-dd");
1499 int VymModel::branchCount()
1502 BranchItem *cur=NULL;
1503 BranchItem *prev=NULL;
1504 nextBranch(cur,prev);
1508 nextBranch(cur,prev);
1513 void VymModel::setSortFilter (const QString &s)
1516 emit (sortFilterChanged (sortFilter));
1519 QString VymModel::getSortFilter ()
1524 void VymModel::setHeading(const QString &s)
1526 BranchItem *selbi=getSelectedBranch();
1531 "setHeading (\""+selbi->getHeading()+"\")",
1533 "setHeading (\""+s+"\")",
1534 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1535 selbi->setHeading(s );
1536 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1538 emitSelectionChanged();
1542 QString VymModel::getHeading()
1544 TreeItem *selti=getSelectedItem();
1546 return selti->getHeading();
1551 void VymModel::setNote(const QString &s)
1553 TreeItem *selti=getSelectedItem();
1558 "setNote (\""+selti->getNote()+"\")",
1560 "setNote (\""+s+"\")",
1561 QString("Set note of %1 ").arg(getObjectName(selti)) );
1564 emitNoteHasChanged(selti);
1567 QString VymModel::getNote()
1569 TreeItem *selti=getSelectedItem();
1571 return selti->getNote();
1576 void VymModel::loadNote (const QString &fn)
1578 BranchItem *selbi=getSelectedBranch();
1582 if (!loadStringFromDisk (fn,n))
1583 qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
1587 qWarning ("VymModel::loadNote no branch selected");
1590 void VymModel::saveNote (const QString &fn)
1592 BranchItem *selbi=getSelectedBranch();
1595 QString n=selbi->getNote();
1597 qWarning ()<<"VymModel::saveNote note is empty, won't save to "<<fn;
1600 if (!saveStringToDisk (fn,n))
1601 qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
1606 qWarning ("VymModel::saveNote no branch selected");
1609 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1611 // Generate map containing _all_ URLs and branches
1613 QMap <QString,BranchItem*> map;
1614 BranchItem *cur=NULL;
1615 BranchItem *prev=NULL;
1616 nextBranch(cur,prev);
1621 map.insertMulti (u,cur);
1622 nextBranch(cur,prev);
1625 // Extract duplicate URLs
1626 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1627 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1628 while (i != map.constEnd())
1630 if (i!=map.constBegin() && i.key()==firstdup.key())
1632 if ( i-1==firstdup )
1634 cout << firstdup.key().toStdString() << endl;
1635 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1637 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1645 void VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)
1649 BranchItem *cur=NULL;
1650 BranchItem *prev=NULL;
1651 nextBranch(cur,prev);
1654 if (cur->getHeading().contains (s,cs))
1656 rmodel->addItem (cur);
1658 //if (cur->getNote().contains (s,cs)) //FIXME-2 does not detect multiple occurences yet
1661 i=cur->getNote().indexOf (s,i,cs);
1666 nextBranch(cur,prev);
1670 BranchItem* VymModel::findText (QString s,Qt::CaseSensitivity cs,QTextCursor &cursor)
1672 if (!s.isEmpty() && s!=findString)
1678 QTextDocument::FindFlags flags=0;
1679 if (cs==Qt::CaseSensitive) flags=QTextDocument::FindCaseSensitively;
1682 { // Nothing found or new find process
1684 // nothing found, start again
1688 nextBranch (findCurrent,findPrevious);
1690 bool searching=true;
1691 bool foundNote=false;
1692 while (searching && !EOFind)
1696 // Searching in Note
1697 if (findCurrent->getNote().contains(findString,cs))
1699 select (findCurrent);
1700 if (textEditor->findText(findString,flags,cursor))
1706 // Searching in Heading
1707 if (searching && findCurrent->getHeading().contains (findString,cs) )
1709 select(findCurrent);
1715 if (!nextBranch(findCurrent,findPrevious) )
1720 return getSelectedBranch();
1725 void VymModel::findReset()
1726 { // Necessary if text to find changes during a find process
1733 void VymModel::setScene (QGraphicsScene *s)
1738 void VymModel::setURL(const QString &url)
1740 TreeItem *selti=getSelectedItem();
1743 QString oldurl=selti->getURL();
1744 selti->setURL (url);
1747 QString ("setURL (\"%1\")").arg(oldurl),
1749 QString ("setURL (\"%1\")").arg(url),
1750 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1753 emitDataHasChanged (selti);
1754 emitShowSelection();
1758 QString VymModel::getURL()
1760 TreeItem *selti=getSelectedItem();
1762 return selti->getURL();
1767 QStringList VymModel::getURLs(bool ignoreScrolled)
1770 BranchItem *selbi=getSelectedBranch();
1771 BranchItem *cur=selbi;
1772 BranchItem *prev=NULL;
1775 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1776 urls.append( cur->getURL());
1777 cur=nextBranch (cur,prev,true,selbi);
1783 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1785 BranchItem *bi=getSelectedBranch();
1788 BranchObj *bo=(BranchObj*)(bi->getLMO());
1791 QString s=bo->getFrameTypeName();
1792 bo->setFrameType (t);
1793 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1794 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1796 bo->updateLinkGeometry();
1801 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1803 BranchItem *bi=getSelectedBranch();
1806 BranchObj *bo=(BranchObj*)(bi->getLMO());
1809 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1810 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1811 bo->setFrameType (s);
1813 bo->updateLinkGeometry();
1818 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1821 BranchItem *bi=getSelectedBranch();
1824 BranchObj *bo=(BranchObj*)(bi->getLMO());
1827 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1828 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1829 bo->setFramePenColor (c);
1834 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1836 BranchItem *bi=getSelectedBranch();
1839 BranchObj *bo=(BranchObj*)(bi->getLMO());
1842 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1843 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1844 bo->setFrameBrushColor (c);
1849 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1851 BranchItem *bi=getSelectedBranch();
1854 BranchObj *bo=(BranchObj*)(bi->getLMO());
1857 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1858 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1859 bo->setFramePadding (i);
1861 bo->updateLinkGeometry();
1866 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1868 BranchItem *bi=getSelectedBranch();
1871 BranchObj *bo=(BranchObj*)(bi->getLMO());
1874 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1875 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1876 bo->setFrameBorderWidth (i);
1878 bo->updateLinkGeometry();
1883 void VymModel::setIncludeImagesVer(bool b)
1885 BranchItem *bi=getSelectedBranch();
1888 QString u= b ? "false" : "true";
1889 QString r=!b ? "false" : "true";
1893 QString("setIncludeImagesVertically (%1)").arg(u),
1895 QString("setIncludeImagesVertically (%1)").arg(r),
1896 QString("Include images vertically in %1").arg(getObjectName(bi))
1898 bi->setIncludeImagesVer(b);
1899 emitDataHasChanged ( bi);
1904 void VymModel::setIncludeImagesHor(bool b)
1906 BranchItem *bi=getSelectedBranch();
1909 QString u= b ? "false" : "true";
1910 QString r=!b ? "false" : "true";
1914 QString("setIncludeImagesHorizontally (%1)").arg(u),
1916 QString("setIncludeImagesHorizontally (%1)").arg(r),
1917 QString("Include images horizontally in %1").arg(getObjectName(bi))
1919 bi->setIncludeImagesHor(b);
1920 emitDataHasChanged ( bi);
1925 void VymModel::setHideLinkUnselected (bool b)
1927 TreeItem *ti=getSelectedItem();
1928 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1930 QString u= b ? "false" : "true";
1931 QString r=!b ? "false" : "true";
1935 QString("setHideLinkUnselected (%1)").arg(u),
1937 QString("setHideLinkUnselected (%1)").arg(r),
1938 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1940 ((MapItem*)ti)->setHideLinkUnselected(b);
1944 void VymModel::setHideExport(bool b)
1946 TreeItem *ti=getSelectedItem();
1948 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1950 ti->setHideInExport (b);
1951 QString u= b ? "false" : "true";
1952 QString r=!b ? "false" : "true";
1956 QString ("setHideExport (%1)").arg(u),
1958 QString ("setHideExport (%1)").arg(r),
1959 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1961 emitDataHasChanged(ti);
1962 emitSelectionChanged();
1965 // emitSelectionChanged();
1966 // FIXME-3 VM needed? scene()->update();
1970 void VymModel::toggleHideExport()
1972 TreeItem *selti=getSelectedItem();
1974 setHideExport ( !selti->hideInExport() );
1977 void VymModel::addTimestamp() //FIXME-3 new function, localize
1979 BranchItem *selbi=addNewBranch();
1982 QDate today=QDate::currentDate();
1984 selbi->setHeading (QString ("%1-%2-%3")
1985 .arg(today.year(),4,10,c)
1986 .arg(today.month(),2,10,c)
1987 .arg(today.day(),2,10,c));
1988 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1995 void VymModel::copy()
1997 TreeItem *selti=getSelectedItem();
1999 (selti->getType() == TreeItem::Branch ||
2000 selti->getType() == TreeItem::MapCenter ||
2001 selti->getType() == TreeItem::Image ))
2003 if (redosAvail == 0)
2006 QString s=getSelectString(selti);
2007 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
2008 curClipboard=curStep;
2011 // Copy also to global clipboard, because we are at last step in history
2012 QString bakMapName(QString("history-%1").arg(curStep));
2013 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2014 copyDir (bakMapDir,clipboardDir );
2016 clipboardEmpty=false;
2022 void VymModel::pasteNoSave(const int &n)
2024 bool old=blockSaveState;
2025 blockSaveState=true;
2026 bool zippedOrg=zipped;
2027 if (redosAvail > 0 || n!=0)
2029 // Use the "historical" buffer
2030 QString bakMapName(QString("history-%1").arg(n));
2031 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2032 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2034 // Use the global buffer
2035 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2040 void VymModel::paste()
2042 BranchItem *selbi=getSelectedBranch();
2045 saveStateChangingPart(
2048 QString ("paste (%1)").arg(curClipboard),
2049 QString("Paste to %1").arg( getObjectName(selbi))
2056 void VymModel::cut()
2058 TreeItem *selti=getSelectedItem();
2059 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2067 bool VymModel::moveUp(BranchItem *bi)
2069 if (bi && bi->canMoveUp())
2070 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2075 void VymModel::moveUp()
2077 BranchItem *selbi=getSelectedBranch();
2080 QString oldsel=getSelectString();
2083 getSelectString(),"moveDown ()",
2085 QString("Move up %1").arg(getObjectName(selbi)));
2089 bool VymModel::moveDown(BranchItem *bi)
2091 if (bi && bi->canMoveDown())
2092 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2097 void VymModel::moveDown()
2099 BranchItem *selbi=getSelectedBranch();
2102 QString oldsel=getSelectString();
2103 if ( moveDown(selbi))
2105 getSelectString(),"moveUp ()",
2106 oldsel,"moveDown ()",
2107 QString("Move down %1").arg(getObjectName(selbi)));
2111 void VymModel::detach()
2113 BranchItem *selbi=getSelectedBranch();
2114 if (selbi && selbi->depth()>0)
2116 // if no relPos have been set before, try to use current rel positions
2117 if (selbi->getLMO())
2118 for (int i=0; i<selbi->branchCount();++i)
2119 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2121 QString oldsel=getSelectString();
2124 BranchObj *bo=selbi->getBranchObj();
2125 if (bo) p=bo->getAbsPos();
2126 QString parsel=getSelectString(selbi->parent());
2127 if ( relinkBranch (selbi,rootItem,-1) )
2129 getSelectString (selbi),
2130 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2133 QString("Detach %1").arg(getObjectName(selbi))
2138 void VymModel::sortChildren(bool inverse)
2140 BranchItem* selbi=getSelectedBranch();
2143 if(selbi->branchCount()>1)
2147 saveStateChangingPart(
2148 selbi,selbi, "sortChildren ()",
2149 QString("Sort children of %1").arg(getObjectName(selbi)));
2151 selbi->sortChildren(inverse);
2153 emitShowSelection();
2158 BranchItem* VymModel::createMapCenter()
2160 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2164 BranchItem* VymModel::createBranch(BranchItem *dst)
2167 return addNewBranchInt (dst,-2);
2172 ImageItem* VymModel::createImage(BranchItem *dst)
2179 QList<QVariant> cData;
2180 cData << "new" << "undef";
2182 ImageItem *newii=new ImageItem(cData) ;
2183 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2185 emit (layoutAboutToBeChanged() );
2188 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2189 n=dst->getRowNumAppend(newii);
2190 beginInsertRows (parix,n,n);
2191 dst->appendChild (newii);
2194 emit (layoutChanged() );
2196 // save scroll state. If scrolled, automatically select
2197 // new branch in order to tmp unscroll parent...
2198 newii->createMapObj(mapScene);
2205 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2212 QList<QVariant> cData;
2213 cData << "new xLink"<<"undef";
2215 XLinkItem *newxli=new XLinkItem(cData) ;
2216 newxli->setBegin (bi);
2218 emit (layoutAboutToBeChanged() );
2221 n=bi->getRowNumAppend(newxli);
2222 beginInsertRows (parix,n,n);
2223 bi->appendChild (newxli);
2226 emit (layoutChanged() );
2228 // save scroll state. If scrolled, automatically select
2229 // new branch in order to tmp unscroll parent...
2232 newxli->createMapObj(mapScene);
2240 AttributeItem* VymModel::addAttribute()
2242 BranchItem *selbi=getSelectedBranch();
2245 QList<QVariant> cData;
2246 cData << "new attribute" << "undef";
2247 AttributeItem *a=new AttributeItem (cData);
2248 if (addAttribute (a)) return a;
2253 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2255 BranchItem *selbi=getSelectedBranch();
2258 emit (layoutAboutToBeChanged() );
2260 QModelIndex parix=index(selbi);
2261 int n=selbi->getRowNumAppend (ai);
2262 beginInsertRows (parix,n,n);
2263 selbi->appendChild (ai);
2266 emit (layoutChanged() );
2268 ai->createMapObj(mapScene); //FIXME-2 check that...
2275 BranchItem* VymModel::addMapCenter ()
2277 BranchItem *bi=addMapCenter (contextPos);
2279 emitShowSelection();
2284 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2285 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2290 BranchItem* VymModel::addMapCenter(QPointF absPos)
2291 // createMapCenter could then probably be merged with createBranch
2295 QModelIndex parix=index(rootItem);
2297 QList<QVariant> cData;
2298 cData << "VM:addMapCenter" << "undef";
2299 BranchItem *newbi=new BranchItem (cData,rootItem);
2300 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2301 int n=rootItem->getRowNumAppend (newbi);
2303 emit (layoutAboutToBeChanged() );
2304 beginInsertRows (parix,n,n);
2306 rootItem->appendChild (newbi);
2309 emit (layoutChanged() );
2312 newbi->setPositionMode (MapItem::Absolute);
2313 BranchObj *bo=newbi->createMapObj(mapScene);
2314 if (bo) bo->move (absPos);
2319 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2321 // Depending on pos:
2322 // -3 insert in children of parent above selection
2323 // -2 add branch to selection
2324 // -1 insert in children of parent below selection
2325 // 0..n insert in children of parent at pos
2328 QList<QVariant> cData;
2329 cData << "" << "undef";
2334 BranchItem *newbi=new BranchItem (cData);
2335 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2337 emit (layoutAboutToBeChanged() );
2343 n=parbi->getRowNumAppend (newbi);
2344 beginInsertRows (parix,n,n);
2345 parbi->appendChild (newbi);
2347 }else if (num==-1 || num==-3)
2349 // insert below selection
2350 parbi=(BranchItem*)dst->parent();
2353 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2354 beginInsertRows (parix,n,n);
2355 parbi->insertBranch(n,newbi);
2358 emit (layoutChanged() );
2360 // Set color of heading to that of parent
2361 newbi->setHeadingColor (parbi->getHeadingColor());
2363 // save scroll state. If scrolled, automatically select
2364 // new branch in order to tmp unscroll parent...
2365 newbi->createMapObj(mapScene);
2370 BranchItem* VymModel::addNewBranch(int pos)
2372 // Different meaning than num in addNewBranchInt!
2376 BranchItem *newbi=NULL;
2377 BranchItem *selbi=getSelectedBranch();
2381 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2383 newbi=addNewBranchInt (selbi,pos-2);
2391 QString ("addBranch (%1)").arg(pos),
2392 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2395 // emitSelectionChanged(); FIXME-3
2396 latestAddedItem=newbi;
2397 // In Network mode, the client needs to know where the new branch is,
2398 // so we have to pass on this information via saveState.
2399 // TODO: Get rid of this positioning workaround
2400 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2401 sendData ("selectLatestAdded ()");
2402 sendData (QString("move %1").arg(ps));
2411 BranchItem* VymModel::addNewBranchBefore()
2413 BranchItem *newbi=NULL;
2414 BranchItem *selbi=getSelectedBranch();
2415 if (selbi && selbi->getType()==TreeItem::Branch)
2416 // We accept no MapCenter here, so we _have_ a parent
2418 //QPointF p=bo->getRelPos();
2421 // add below selection
2422 newbi=addNewBranchInt (selbi,-1);
2426 //newbi->move2RelPos (p);
2428 // Move selection to new branch
2429 relinkBranch (selbi,newbi,0);
2431 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2432 QString ("Add branch before %1").arg(getObjectName(selbi)));
2434 // FIXME-3 needed? reposition();
2435 // emitSelectionChanged(); FIXME-3
2441 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2447 // Do we need to update frame type?
2448 bool keepFrame=false;
2451 emit (layoutAboutToBeChanged() );
2452 BranchItem *branchpi=(BranchItem*)branch->parent();
2453 // Remove at current position
2454 int n=branch->childNum();
2456 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2457 // error occured if relinking branch to empty mainbranch
2458 cout<<"VM::relinkBranch:\n";
2459 cout<<" b="<<branch->getHeadingStd()<<endl;
2460 cout<<" dst="<<dst->getHeadingStd()<<endl;
2461 cout<<" pos="<<pos<<endl;
2462 cout<<" n1="<<n<<endl;
2464 beginRemoveRows (index(branchpi),n,n);
2465 branchpi->removeChild (n);
2468 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2470 // Append as last branch to dst
2471 if (dst->branchCount()==0)
2474 n=dst->getFirstBranch()->childNumber();
2475 beginInsertRows (index(dst),n+pos,n+pos);
2476 dst->insertBranch (pos,branch);
2479 // Correct type if necessesary
2480 if (branch->getType()==TreeItem::MapCenter)
2481 branch->setType(TreeItem::Branch);
2483 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2484 branch->updateStyles(keepFrame);
2486 emit (layoutChanged() );
2487 reposition(); // both for moveUp/Down and relinking
2488 if (dst->isScrolled() )
2491 branch->updateVisibility();
2500 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2504 emit (layoutAboutToBeChanged() );
2506 BranchItem *pi=(BranchItem*)(image->parent());
2507 QString oldParString=getSelectString (pi);
2508 // Remove at current position
2509 int n=image->childNum();
2510 beginRemoveRows (index(pi),n,n);
2511 pi->removeChild (n);
2515 QModelIndex dstix=index(dst);
2516 n=dst->getRowNumAppend (image);
2517 beginInsertRows (dstix,n,n+1);
2518 dst->appendChild (image);
2521 // Set new parent also for lmo
2522 if (image->getLMO() && dst->getLMO() )
2523 image->getLMO()->setParObj (dst->getLMO() );
2525 emit (layoutChanged() );
2528 QString("relinkTo (\"%1\")").arg(oldParString),
2530 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2531 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2537 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2539 BranchItem *selbi=getSelectedBranch();
2544 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2546 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2549 if (pi->isScrolled() && pi->branchCount()==0)
2552 emitDataHasChanged(pi);
2555 emitShowSelection();
2559 TreeItem *ti=getSelectedItem();
2561 { // Delete other item
2562 TreeItem *pi=ti->parent();
2564 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2566 saveStateChangingPart(
2570 QString("Delete %1").arg(getObjectName(ti))
2574 emitDataHasChanged (pi);
2577 emitShowSelection();
2578 } else if (ti->getType()==TreeItem::XLink)
2580 //FIXME-2 savestate for deleting xlink missing
2583 qWarning ("VymmModel::deleteSelection() unknown type?!");
2587 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2590 BranchItem *selbi=getSelectedBranch();
2594 // Don't use this on mapcenter
2595 if (selbi->depth()<2) return;
2597 pi=(BranchItem*)(selbi->parent());
2598 // Check if we have children at all to keep
2599 if (selbi->branchCount()==0)
2606 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2607 saveStateChangingPart(
2610 "deleteKeepChildren ()",
2611 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2614 QString sel=getSelectString(selbi);
2616 int pos=selbi->num();
2617 BranchItem *bi=selbi->getFirstBranch();
2620 relinkBranch (bi,pi,pos);
2621 bi=selbi->getFirstBranch();
2627 BranchObj *bo=getSelectedBranchObj();
2630 bo->move2RelPos (p);
2636 void VymModel::deleteChildren()
2639 BranchItem *selbi=getSelectedBranch();
2642 saveStateChangingPart(
2645 "deleteChildren ()",
2646 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2648 emit (layoutAboutToBeChanged() );
2650 QModelIndex ix=index (selbi);
2651 int n=selbi->branchCount()-1;
2652 beginRemoveRows (ix,0,n);
2653 removeRows (0,n+1,ix);
2655 if (selbi->isScrolled()) selbi->unScroll();
2656 emit (layoutChanged() );
2661 TreeItem* VymModel::deleteItem (TreeItem *ti)
2665 TreeItem *pi=ti->parent();
2666 QModelIndex parentIndex=index(pi);
2668 emit (layoutAboutToBeChanged() );
2670 int n=ti->childNum();
2671 beginRemoveRows (parentIndex,n,n);
2672 removeRows (n,1,parentIndex);
2676 emit (layoutChanged() );
2677 if (pi->depth()>=0) return pi;
2682 void VymModel::clearItem (TreeItem *ti)
2686 QModelIndex parentIndex=index(ti);
2687 if (!parentIndex.isValid()) return;
2689 int n=ti->childCount();
2692 emit (layoutAboutToBeChanged() );
2694 beginRemoveRows (parentIndex,0,n-1);
2695 removeRows (0,n,parentIndex);
2699 emit (layoutChanged() );
2705 bool VymModel::scrollBranch(BranchItem *bi)
2709 if (bi->isScrolled()) return false;
2710 if (bi->branchCount()==0) return false;
2711 if (bi->depth()==0) return false;
2712 if (bi->toggleScroll())
2720 QString ("%1 ()").arg(u),
2722 QString ("%1 ()").arg(r),
2723 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2725 emitDataHasChanged(bi);
2726 emitSelectionChanged();
2727 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2734 bool VymModel::unscrollBranch(BranchItem *bi)
2738 if (!bi->isScrolled()) return false;
2739 if (bi->branchCount()==0) return false;
2740 if (bi->depth()==0) return false;
2741 if (bi->toggleScroll())
2749 QString ("%1 ()").arg(u),
2751 QString ("%1 ()").arg(r),
2752 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2754 emitDataHasChanged(bi);
2755 emitSelectionChanged();
2756 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2763 void VymModel::toggleScroll()
2765 BranchItem *bi=(BranchItem*)getSelectedBranch();
2766 if (bi && bi->isBranchLikeType() )
2768 if (bi->isScrolled())
2769 unscrollBranch (bi);
2773 // saveState & reposition are called in above functions
2776 void VymModel::unscrollChildren()
2778 BranchItem *selbi=getSelectedBranch();
2779 BranchItem *prev=NULL;
2780 BranchItem *cur=selbi;
2783 saveStateChangingPart(
2786 QString ("unscrollChildren ()"),
2787 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2791 if (cur->isScrolled())
2793 cur->toggleScroll();
2794 emitDataHasChanged (cur);
2796 cur=nextBranch (cur,prev,true,selbi);
2803 void VymModel::emitExpandAll()
2805 emit (expandAll() );
2808 void VymModel::emitExpandOneLevel()
2810 emit (expandOneLevel () );
2813 void VymModel::emitCollapseOneLevel()
2815 emit (collapseOneLevel () );
2818 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2820 BranchItem *bi=getSelectedBranch();
2824 if (bi->isActiveStandardFlag(name))
2836 QString("%1 (\"%2\")").arg(u).arg(name),
2838 QString("%1 (\"%2\")").arg(r).arg(name),
2839 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2840 bi->toggleStandardFlag (name, master);
2842 emitSelectionChanged();
2846 void VymModel::addFloatImage (const QPixmap &img)
2848 BranchItem *selbi=getSelectedBranch();
2851 ImageItem *ii=createImage (selbi);
2853 ii->setOriginalFilename("No original filename (image added by dropevent)");
2854 QString s=getSelectString(selbi);
2855 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2856 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2858 // FIXME-3 VM needed? scene()->update();
2863 void VymModel::colorBranch (QColor c)
2865 BranchItem *selbi=getSelectedBranch();
2870 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2872 QString ("colorBranch (\"%1\")").arg(c.name()),
2873 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2875 selbi->setHeadingColor(c); // color branch
2880 void VymModel::colorSubtree (QColor c)
2882 BranchItem *selbi=getSelectedBranch();
2885 saveStateChangingPart(
2888 QString ("colorSubtree (\"%1\")").arg(c.name()),
2889 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2891 BranchItem *prev=NULL;
2892 BranchItem *cur=selbi;
2895 cur->setHeadingColor(c); // color links, color children
2896 cur=nextBranch (cur,prev,true,selbi);
2902 QColor VymModel::getCurrentHeadingColor()
2904 BranchItem *selbi=getSelectedBranch();
2905 if (selbi) return selbi->getHeadingColor();
2907 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2913 void VymModel::editURL()
2915 TreeItem *selti=getSelectedItem();
2919 QString text = QInputDialog::getText(
2920 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2921 selti->getURL(), &ok, NULL);
2923 // user entered something and pressed OK
2928 void VymModel::editLocalURL()
2930 TreeItem *selti=getSelectedItem();
2933 QStringList filters;
2934 filters <<"All files (*)";
2935 filters << tr("Text","Filedialog") + " (*.txt)";
2936 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2937 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2938 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2939 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2940 fd->setFilters (filters);
2941 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2942 fd->setDirectory (lastFileDir);
2943 if (! selti->getVymLink().isEmpty() )
2944 fd->selectFile( selti->getURL() );
2947 if ( fd->exec() == QDialog::Accepted )
2949 lastFileDir=QDir (fd->directory().path());
2950 setURL (fd->selectedFile() );
2956 void VymModel::editHeading2URL()
2958 TreeItem *selti=getSelectedItem();
2960 setURL (selti->getHeading());
2963 void VymModel::editBugzilla2URL()
2965 TreeItem *selti=getSelectedItem();
2968 QString h=selti->getHeading();
2969 QRegExp rx("^(\\d+)");
2970 if (rx.indexIn(h) !=-1)
2971 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2975 void VymModel::getBugzillaData()
2977 BranchItem *selbi=getSelectedBranch();
2980 QString url=selbi->getURL();
2983 QRegExp rx("(\\d+)");
2984 if (rx.indexIn(url) !=-1)
2986 QString bugID=rx.cap(1);
2987 qDebug()<< "VM::getBugzillaData bug="<<bugID;
2989 new BugAgent (selbi,bugID);
2995 void VymModel::editFATE2URL()
2997 TreeItem *selti=getSelectedItem();
3000 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3003 "setURL (\""+selti->getURL()+"\")",
3005 "setURL (\""+url+"\")",
3006 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3008 selti->setURL (url);
3009 // FIXME-4 updateActions();
3013 void VymModel::editVymLink()
3015 BranchItem *bi=getSelectedBranch();
3018 QStringList filters;
3019 filters <<"VYM map (*.vym)";
3020 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3021 fd->setFilters (filters);
3022 fd->setCaption(vymName+" - " +tr("Link to another map"));
3023 fd->setDirectory (lastFileDir);
3024 if (! bi->getVymLink().isEmpty() )
3025 fd->selectFile( bi->getVymLink() );
3029 if ( fd->exec() == QDialog::Accepted )
3031 lastFileDir=QDir (fd->directory().path());
3034 "setVymLink (\""+bi->getVymLink()+"\")",
3036 "setVymLink (\""+fd->selectedFile()+"\")",
3037 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3039 setVymLink (fd->selectedFile() );
3044 void VymModel::setVymLink (const QString &s)
3046 // Internal function, no saveState needed
3047 TreeItem *selti=getSelectedItem();
3050 selti->setVymLink(s);
3052 emitDataHasChanged (selti);
3053 emitShowSelection();
3057 void VymModel::deleteVymLink()
3059 BranchItem *bi=getSelectedBranch();
3064 "setVymLink (\""+bi->getVymLink()+"\")",
3066 "setVymLink (\"\")",
3067 QString("Unset vymlink of %1").arg(getObjectName(bi))
3069 bi->setVymLink ("" );
3075 QString VymModel::getVymLink()
3077 BranchItem *bi=getSelectedBranch();
3079 return bi->getVymLink();
3085 QStringList VymModel::getVymLinks()
3088 BranchItem *selbi=getSelectedBranch();
3089 BranchItem *cur=selbi;
3090 BranchItem *prev=NULL;
3093 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3094 cur=nextBranch (cur,prev,true,selbi);
3100 void VymModel::followXLink(int i)
3103 BranchItem *selbi=getSelectedBranch();
3106 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3107 if (selbi) select (selbi);
3111 void VymModel::editXLink(int i)
3114 BranchItem *selbi=getSelectedBranch();
3117 XLinkItem *xli=selbi->getXLinkNum(i);
3120 EditXLinkDialog dia;
3122 dia.setSelection(selbi);
3123 if (dia.exec() == QDialog::Accepted)
3125 if (dia.useSettingsGlobal() )
3127 setMapDefXLinkColor (xli->getColor() );
3128 setMapDefXLinkWidth (xli->getWidth() );
3130 if (dia.deleteXLink()) deleteItem (xli);
3140 //////////////////////////////////////////////
3142 //////////////////////////////////////////////
3144 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3146 TreeItem* selti=getSelectedItem();
3147 BranchItem *selbi=getSelectedBranch();
3152 QVariant returnValue;
3154 // Split string s into command and parameters
3155 parser.parseAtom (atom);
3156 QString com=parser.getCommand();
3158 // External commands
3159 /////////////////////////////////////////////////////////////////////
3160 if (com=="addBranch")
3164 parser.setError (Aborted,"Nothing selected");
3165 } else if (! selbi )
3167 parser.setError (Aborted,"Type of selection is not a branch");
3172 if (parser.checkParCount(pl))
3174 if (parser.parCount()==0)
3178 n=parser.parInt (ok,0);
3179 if (ok ) addNewBranch (n);
3183 /////////////////////////////////////////////////////////////////////
3184 } else if (com=="addBranchBefore")
3188 parser.setError (Aborted,"Nothing selected");
3189 } else if (! selbi )
3191 parser.setError (Aborted,"Type of selection is not a branch");
3194 if (parser.parCount()==0)
3196 addNewBranchBefore ();
3199 /////////////////////////////////////////////////////////////////////
3200 } else if (com==QString("addMapCenter"))
3202 if (parser.checkParCount(2))
3204 x=parser.parDouble (ok,0);
3207 y=parser.parDouble (ok,1);
3208 if (ok) addMapCenter (QPointF(x,y));
3211 /////////////////////////////////////////////////////////////////////
3212 } else if (com==QString("addMapReplace"))
3216 parser.setError (Aborted,"Nothing selected");
3217 } else if (! selbi )
3219 parser.setError (Aborted,"Type of selection is not a branch");
3220 } else if (parser.checkParCount(1))
3222 //s=parser.parString (ok,0); // selection
3223 t=parser.parString (ok,0); // path to map
3224 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3225 addMapReplaceInt(getSelectString(selbi),t);
3227 /////////////////////////////////////////////////////////////////////
3228 } else if (com==QString("addMapInsert"))
3230 if (parser.parCount()==2)
3235 parser.setError (Aborted,"Nothing selected");
3236 } else if (! selbi )
3238 parser.setError (Aborted,"Type of selection is not a branch");
3241 t=parser.parString (ok,0); // path to map
3242 n=parser.parInt(ok,1); // position
3243 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3244 addMapInsertInt(t,n);
3246 } else if (parser.parCount()==1)
3248 t=parser.parString (ok,0); // path to map
3249 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3252 parser.setError (Aborted,"Wrong number of parameters");
3253 /////////////////////////////////////////////////////////////////////
3254 } else if (com==QString("addXLink"))
3256 if (parser.parCount()>1)
3258 s=parser.parString (ok,0); // begin
3259 t=parser.parString (ok,1); // end
3260 BranchItem *begin=(BranchItem*)findBySelectString(s);
3261 BranchItem *end=(BranchItem*)findBySelectString(t);
3264 if (begin->isBranchLikeType() && end->isBranchLikeType())
3266 XLinkItem *xl=createXLink (begin,true);
3272 parser.setError (Aborted,"Failed to create xLink");
3275 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3278 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3280 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3281 /////////////////////////////////////////////////////////////////////
3282 } else if (com=="clearFlags")
3286 parser.setError (Aborted,"Nothing selected");
3287 } else if (! selbi )
3289 parser.setError (Aborted,"Type of selection is not a branch");
3290 } else if (parser.checkParCount(0))
3292 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3294 /////////////////////////////////////////////////////////////////////
3295 } else if (com=="colorBranch")
3299 parser.setError (Aborted,"Nothing selected");
3300 } else if (! selbi )
3302 parser.setError (Aborted,"Type of selection is not a branch");
3303 } else if (parser.checkParCount(1))
3305 QColor c=parser.parColor (ok,0);
3306 if (ok) colorBranch (c);
3308 /////////////////////////////////////////////////////////////////////
3309 } else if (com=="colorSubtree")
3313 parser.setError (Aborted,"Nothing selected");
3314 } else if (! selbi )
3316 parser.setError (Aborted,"Type of selection is not a branch");
3317 } else if (parser.checkParCount(1))
3319 QColor c=parser.parColor (ok,0);
3320 if (ok) colorSubtree (c);
3322 /////////////////////////////////////////////////////////////////////
3323 } else if (com=="copy")
3327 parser.setError (Aborted,"Nothing selected");
3328 } else if ( selectionType()!=TreeItem::Branch &&
3329 selectionType()!=TreeItem::MapCenter &&
3330 selectionType()!=TreeItem::Image )
3332 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3333 } else if (parser.checkParCount(0))
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="cut")
3342 parser.setError (Aborted,"Nothing selected");
3343 } else if ( selectionType()!=TreeItem::Branch &&
3344 selectionType()!=TreeItem::MapCenter &&
3345 selectionType()!=TreeItem::Image )
3347 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3348 } else if (parser.checkParCount(0))
3352 /////////////////////////////////////////////////////////////////////
3353 } else if (com=="delete")
3357 parser.setError (Aborted,"Nothing selected");
3359 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3361 parser.setError (Aborted,"Type of selection is wrong.");
3364 else if (parser.checkParCount(0))
3368 /////////////////////////////////////////////////////////////////////
3369 } else if (com=="deleteKeepChildren")
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(0))
3379 deleteKeepChildren();
3381 /////////////////////////////////////////////////////////////////////
3382 } else if (com=="deleteChildren")
3386 parser.setError (Aborted,"Nothing selected");
3389 parser.setError (Aborted,"Type of selection is not a branch");
3390 } else if (parser.checkParCount(0))
3394 /////////////////////////////////////////////////////////////////////
3395 } else if (com=="exportAO")
3399 if (parser.parCount()>=1)
3400 // Hey, we even have a filename
3401 fname=parser.parString(ok,0);
3404 parser.setError (Aborted,"Could not read filename");
3407 exportAO (fname,false);
3409 /////////////////////////////////////////////////////////////////////
3410 } else if (com=="exportASCII")
3414 if (parser.parCount()>=1)
3415 // Hey, we even have a filename
3416 fname=parser.parString(ok,0);
3419 parser.setError (Aborted,"Could not read filename");
3422 exportASCII (fname,false);
3424 /////////////////////////////////////////////////////////////////////
3425 } else if (com=="exportImage")
3429 if (parser.parCount()>=2)
3430 // Hey, we even have a filename
3431 fname=parser.parString(ok,0);
3434 parser.setError (Aborted,"Could not read filename");
3437 QString format="PNG";
3438 if (parser.parCount()>=2)
3440 format=parser.parString(ok,1);
3442 exportImage (fname,false,format);
3444 /////////////////////////////////////////////////////////////////////
3445 } else if (com=="exportXHTML")
3449 if (parser.parCount()>=2)
3450 // Hey, we even have a filename
3451 fname=parser.parString(ok,1);
3454 parser.setError (Aborted,"Could not read filename");
3457 exportXHTML (fname,false);
3459 /////////////////////////////////////////////////////////////////////
3460 } else if (com=="exportXML")
3464 if (parser.parCount()>=2)
3465 // Hey, we even have a filename
3466 fname=parser.parString(ok,1);
3469 parser.setError (Aborted,"Could not read filename");
3472 exportXML (fname,false);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="getHeading")
3479 parser.setError (Aborted,"Nothing selected");
3480 } else if (parser.checkParCount(0))
3481 returnValue=selti->getHeading();
3482 /////////////////////////////////////////////////////////////////////
3483 } else if (com=="importDir")
3487 parser.setError (Aborted,"Nothing selected");
3488 } else if (! selbi )
3490 parser.setError (Aborted,"Type of selection is not a branch");
3491 } else if (parser.checkParCount(1))
3493 s=parser.parString(ok,0);
3494 if (ok) importDirInt(s);
3496 /////////////////////////////////////////////////////////////////////
3497 } else if (com=="relinkTo")
3501 parser.setError (Aborted,"Nothing selected");
3504 if (parser.checkParCount(4))
3506 // 0 selectstring of parent
3507 // 1 num in parent (for branches)
3508 // 2,3 x,y of mainbranch or mapcenter
3509 s=parser.parString(ok,0);
3510 TreeItem *dst=findBySelectString (s);
3513 if (dst->getType()==TreeItem::Branch)
3515 // Get number in parent
3516 n=parser.parInt (ok,1);
3519 relinkBranch (selbi,(BranchItem*)dst,n);
3520 emitSelectionChanged();
3522 } else if (dst->getType()==TreeItem::MapCenter)
3524 relinkBranch (selbi,(BranchItem*)dst);
3525 // Get coordinates of mainbranch
3526 x=parser.parDouble(ok,2);
3529 y=parser.parDouble(ok,3);
3532 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3533 emitSelectionChanged();
3539 } else if ( selti->getType() == TreeItem::Image)
3541 if (parser.checkParCount(1))
3543 // 0 selectstring of parent
3544 s=parser.parString(ok,0);
3545 TreeItem *dst=findBySelectString (s);
3548 if (dst->isBranchLikeType())
3549 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3551 parser.setError (Aborted,"Destination is not a branch");
3554 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3555 /////////////////////////////////////////////////////////////////////
3556 } else if (com=="loadImage")
3560 parser.setError (Aborted,"Nothing selected");
3561 } else if (! selbi )
3563 parser.setError (Aborted,"Type of selection is not a branch");
3564 } else if (parser.checkParCount(1))
3566 s=parser.parString(ok,0);
3567 if (ok) loadFloatImageInt (selbi,s);
3569 /////////////////////////////////////////////////////////////////////
3570 } else if (com=="loadNote")
3574 parser.setError (Aborted,"Nothing selected");
3575 } else if (! selbi )
3577 parser.setError (Aborted,"Type of selection is not a branch");
3578 } else if (parser.checkParCount(1))
3580 s=parser.parString(ok,0);
3581 if (ok) loadNote (s);
3583 /////////////////////////////////////////////////////////////////////
3584 } else if (com=="moveUp")
3588 parser.setError (Aborted,"Nothing selected");
3589 } else if (! selbi )
3591 parser.setError (Aborted,"Type of selection is not a branch");
3592 } else if (parser.checkParCount(0))
3596 /////////////////////////////////////////////////////////////////////
3597 } else if (com=="moveDown")
3601 parser.setError (Aborted,"Nothing selected");
3602 } else if (! selbi )
3604 parser.setError (Aborted,"Type of selection is not a branch");
3605 } else if (parser.checkParCount(0))
3609 /////////////////////////////////////////////////////////////////////
3610 } else if (com=="move")
3614 parser.setError (Aborted,"Nothing selected");
3615 } else if ( selectionType()!=TreeItem::Branch &&
3616 selectionType()!=TreeItem::MapCenter &&
3617 selectionType()!=TreeItem::Image )
3619 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3620 } else if (parser.checkParCount(2))
3622 x=parser.parDouble (ok,0);
3625 y=parser.parDouble (ok,1);
3629 /////////////////////////////////////////////////////////////////////
3630 } else if (com=="moveRel")
3634 parser.setError (Aborted,"Nothing selected");
3635 } else if ( selectionType()!=TreeItem::Branch &&
3636 selectionType()!=TreeItem::MapCenter &&
3637 selectionType()!=TreeItem::Image )
3639 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3640 } else if (parser.checkParCount(2))
3642 x=parser.parDouble (ok,0);
3645 y=parser.parDouble (ok,1);
3646 if (ok) moveRel (x,y);
3649 /////////////////////////////////////////////////////////////////////
3650 } else if (com=="nop")
3652 /////////////////////////////////////////////////////////////////////
3653 } else if (com=="paste")
3657 parser.setError (Aborted,"Nothing selected");
3658 } else if (! selbi )
3660 parser.setError (Aborted,"Type of selection is not a branch");
3661 } else if (parser.checkParCount(1))
3663 n=parser.parInt (ok,0);
3664 if (ok) pasteNoSave(n);
3666 /////////////////////////////////////////////////////////////////////
3667 } else if (com=="qa")
3671 parser.setError (Aborted,"Nothing selected");
3672 } else if (! selbi )
3674 parser.setError (Aborted,"Type of selection is not a branch");
3675 } else if (parser.checkParCount(4))
3678 c=parser.parString (ok,0);
3681 parser.setError (Aborted,"No comment given");
3684 s=parser.parString (ok,1);
3687 parser.setError (Aborted,"First parameter is not a string");
3690 t=parser.parString (ok,2);
3693 parser.setError (Aborted,"Condition is not a string");
3696 u=parser.parString (ok,3);
3699 parser.setError (Aborted,"Third parameter is not a string");
3704 parser.setError (Aborted,"Unknown type: "+s);
3709 parser.setError (Aborted,"Unknown operator: "+t);
3714 parser.setError (Aborted,"Type of selection is not a branch");
3717 if (selbi->getHeading() == u)
3719 cout << "PASSED: " << qPrintable (c) << endl;
3722 cout << "FAILED: " << qPrintable (c) << endl;
3732 /////////////////////////////////////////////////////////////////////
3733 } else if (com=="saveImage")
3735 ImageItem *ii=getSelectedImage();
3738 parser.setError (Aborted,"No image selected");
3739 } else if (parser.checkParCount(2))
3741 s=parser.parString(ok,0);
3744 t=parser.parString(ok,1);
3745 if (ok) saveFloatImageInt (ii,t,s);
3748 /////////////////////////////////////////////////////////////////////
3749 } else if (com=="saveNote")
3753 parser.setError (Aborted,"Nothing selected");
3754 } else if (! selbi )
3756 parser.setError (Aborted,"Type of selection is not a branch");
3757 } else if (parser.checkParCount(1))
3759 s=parser.parString(ok,0);
3760 if (ok) saveNote (s);
3762 /////////////////////////////////////////////////////////////////////
3763 } else if (com=="scroll")
3767 parser.setError (Aborted,"Nothing selected");
3768 } else if (! selbi )
3770 parser.setError (Aborted,"Type of selection is not a branch");
3771 } else if (parser.checkParCount(0))
3773 if (!scrollBranch (selbi))
3774 parser.setError (Aborted,"Could not scroll branch");
3776 /////////////////////////////////////////////////////////////////////
3777 } else if (com=="select")
3779 if (parser.checkParCount(1))
3781 s=parser.parString(ok,0);
3784 /////////////////////////////////////////////////////////////////////
3785 } else if (com=="selectLastBranch")
3789 parser.setError (Aborted,"Nothing selected");
3790 } else if (! selbi )
3792 parser.setError (Aborted,"Type of selection is not a branch");
3793 } else if (parser.checkParCount(0))
3795 BranchItem *bi=selbi->getLastBranch();
3797 parser.setError (Aborted,"Could not select last branch");
3798 select (bi); // FIXME-3 was selectInt
3801 /////////////////////////////////////////////////////////////////////
3802 } else /* FIXME-2 if (com=="selectLastImage")
3806 parser.setError (Aborted,"Nothing selected");
3807 } else if (! selbi )
3809 parser.setError (Aborted,"Type of selection is not a branch");
3810 } else if (parser.checkParCount(0))
3812 FloatImageObj *fio=selb->getLastFloatImage();
3814 parser.setError (Aborted,"Could not select last image");
3815 select (fio); // FIXME-3 was selectInt
3818 /////////////////////////////////////////////////////////////////////
3819 } else */ if (com=="selectLatestAdded")
3821 if (!latestAddedItem)
3823 parser.setError (Aborted,"No latest added object");
3826 if (!select (latestAddedItem))
3827 parser.setError (Aborted,"Could not select latest added object ");
3829 /////////////////////////////////////////////////////////////////////
3830 } else if (com=="setFlag")
3834 parser.setError (Aborted,"Nothing selected");
3835 } else if (! selbi )
3837 parser.setError (Aborted,"Type of selection is not a branch");
3838 } else if (parser.checkParCount(1))
3840 s=parser.parString(ok,0);
3842 selbi->activateStandardFlag(s);
3844 /////////////////////////////////////////////////////////////////////
3845 } else if (com=="setFrameType")
3847 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3849 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3851 else if (parser.checkParCount(1))
3853 s=parser.parString(ok,0);
3854 if (ok) setFrameType (s);
3856 /////////////////////////////////////////////////////////////////////
3857 } else if (com=="setFramePenColor")
3859 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3861 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3863 else if (parser.checkParCount(1))
3865 QColor c=parser.parColor(ok,0);
3866 if (ok) setFramePenColor (c);
3868 /////////////////////////////////////////////////////////////////////
3869 } else if (com=="setFrameBrushColor")
3871 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3873 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3875 else if (parser.checkParCount(1))
3877 QColor c=parser.parColor(ok,0);
3878 if (ok) setFrameBrushColor (c);
3880 /////////////////////////////////////////////////////////////////////
3881 } else if (com=="setFramePadding")
3883 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3885 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3887 else if (parser.checkParCount(1))
3889 n=parser.parInt(ok,0);
3890 if (ok) setFramePadding(n);
3892 /////////////////////////////////////////////////////////////////////
3893 } else if (com=="setFrameBorderWidth")
3895 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3897 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3899 else if (parser.checkParCount(1))
3901 n=parser.parInt(ok,0);
3902 if (ok) setFrameBorderWidth (n);
3904 /////////////////////////////////////////////////////////////////////
3905 /* FIXME-2 else if (com=="setFrameType")
3909 parser.setError (Aborted,"Nothing selected");
3912 parser.setError (Aborted,"Type of selection is not a branch");
3913 } else if (parser.checkParCount(1))
3915 s=parser.parString(ok,0);
3919 /////////////////////////////////////////////////////////////////////
3921 /////////////////////////////////////////////////////////////////////
3922 } else if (com=="setHeading")
3926 parser.setError (Aborted,"Nothing selected");
3927 } else if (! selbi )
3929 parser.setError (Aborted,"Type of selection is not a branch");
3930 } else if (parser.checkParCount(1))
3932 s=parser.parString (ok,0);
3936 /////////////////////////////////////////////////////////////////////
3937 } else if (com=="setHideExport")
3941 parser.setError (Aborted,"Nothing selected");
3942 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3944 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3945 } else if (parser.checkParCount(1))
3947 b=parser.parBool(ok,0);
3948 if (ok) setHideExport (b);
3950 /////////////////////////////////////////////////////////////////////
3951 } else if (com=="setIncludeImagesHorizontally")
3955 parser.setError (Aborted,"Nothing selected");
3958 parser.setError (Aborted,"Type of selection is not a branch");
3959 } else if (parser.checkParCount(1))
3961 b=parser.parBool(ok,0);
3962 if (ok) setIncludeImagesHor(b);
3964 /////////////////////////////////////////////////////////////////////
3965 } else if (com=="setIncludeImagesVertically")
3969 parser.setError (Aborted,"Nothing selected");
3972 parser.setError (Aborted,"Type of selection is not a branch");
3973 } else if (parser.checkParCount(1))
3975 b=parser.parBool(ok,0);
3976 if (ok) setIncludeImagesVer(b);
3978 /////////////////////////////////////////////////////////////////////
3979 } else if (com=="setHideLinkUnselected")
3983 parser.setError (Aborted,"Nothing selected");
3984 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3986 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3987 } else if (parser.checkParCount(1))
3989 b=parser.parBool(ok,0);
3990 if (ok) setHideLinkUnselected(b);
3992 /////////////////////////////////////////////////////////////////////
3993 } else if (com=="setMapAuthor")
3995 if (parser.checkParCount(1))
3997 s=parser.parString(ok,0);
3998 if (ok) setAuthor (s);
4000 /////////////////////////////////////////////////////////////////////
4001 } else if (com=="setMapComment")
4003 if (parser.checkParCount(1))
4005 s=parser.parString(ok,0);
4006 if (ok) setComment(s);
4008 /////////////////////////////////////////////////////////////////////
4009 } else if (com=="setMapBackgroundColor")
4013 parser.setError (Aborted,"Nothing selected");
4014 } else if (! selbi )
4016 parser.setError (Aborted,"Type of selection is not a branch");
4017 } else if (parser.checkParCount(1))
4019 QColor c=parser.parColor (ok,0);
4020 if (ok) setMapBackgroundColor (c);
4022 /////////////////////////////////////////////////////////////////////
4023 } else if (com=="setMapDefLinkColor")
4027 parser.setError (Aborted,"Nothing selected");
4028 } else if (! selbi )
4030 parser.setError (Aborted,"Type of selection is not a branch");
4031 } else if (parser.checkParCount(1))
4033 QColor c=parser.parColor (ok,0);
4034 if (ok) setMapDefLinkColor (c);
4036 /////////////////////////////////////////////////////////////////////
4037 } else if (com=="setMapLinkStyle")
4039 if (parser.checkParCount(1))
4041 s=parser.parString (ok,0);
4042 if (ok) setMapLinkStyle(s);
4044 /////////////////////////////////////////////////////////////////////
4045 } else if (com=="setNote")
4049 parser.setError (Aborted,"Nothing selected");
4050 } else if (! selbi )
4052 parser.setError (Aborted,"Type of selection is not a branch");
4053 } else if (parser.checkParCount(1))
4055 s=parser.parString (ok,0);
4059 /////////////////////////////////////////////////////////////////////
4060 } else if (com=="setSelectionColor")
4062 if (parser.checkParCount(1))
4064 QColor c=parser.parColor (ok,0);
4065 if (ok) setSelectionColorInt (c);
4067 /////////////////////////////////////////////////////////////////////
4068 } else if (com=="setURL")
4072 parser.setError (Aborted,"Nothing selected");
4073 } else if (! selbi )
4075 parser.setError (Aborted,"Type of selection is not a branch");
4076 } else if (parser.checkParCount(1))
4078 s=parser.parString (ok,0);
4081 /////////////////////////////////////////////////////////////////////
4082 } else if (com=="setVymLink")
4086 parser.setError (Aborted,"Nothing selected");
4087 } else if (! selbi )
4089 parser.setError (Aborted,"Type of selection is not a branch");
4090 } else if (parser.checkParCount(1))
4092 s=parser.parString (ok,0);
4093 if (ok) setVymLink(s);
4095 } else if (com=="sortChildren")
4099 parser.setError (Aborted,"Nothing selected");
4100 } else if (! selbi )
4102 parser.setError (Aborted,"Type of selection is not a branch");
4103 } else if (parser.checkParCount(0))
4106 } else if (parser.checkParCount(1))
4108 b=parser.parBool(ok,0);
4109 if (ok) sortChildren(b);
4111 /////////////////////////////////////////////////////////////////////
4112 } else if (com=="toggleFlag")
4116 parser.setError (Aborted,"Nothing selected");
4117 } else if (! selbi )
4119 parser.setError (Aborted,"Type of selection is not a branch");
4120 } else if (parser.checkParCount(1))
4122 s=parser.parString(ok,0);
4124 selbi->toggleStandardFlag(s);
4126 /////////////////////////////////////////////////////////////////////
4127 } else if (com=="unscroll")
4131 parser.setError (Aborted,"Nothing selected");
4132 } else if (! selbi )
4134 parser.setError (Aborted,"Type of selection is not a branch");
4135 } else if (parser.checkParCount(0))
4137 if (!unscrollBranch (selbi))
4138 parser.setError (Aborted,"Could not unscroll branch");
4140 /////////////////////////////////////////////////////////////////////
4141 } else if (com=="unscrollChildren")
4145 parser.setError (Aborted,"Nothing selected");
4146 } else if (! selbi )
4148 parser.setError (Aborted,"Type of selection is not a branch");
4149 } else if (parser.checkParCount(0))
4151 unscrollChildren ();
4153 /////////////////////////////////////////////////////////////////////
4154 } else if (com=="unsetFlag")
4158 parser.setError (Aborted,"Nothing selected");
4159 } else if (! selbi )
4161 parser.setError (Aborted,"Type of selection is not a branch");
4162 } else if (parser.checkParCount(1))
4164 s=parser.parString(ok,0);
4166 selbi->deactivateStandardFlag(s);
4169 parser.setError (Aborted,"Unknown command");
4172 if (parser.errorLevel()==NoError)
4180 // TODO Error handling
4181 qWarning("VymModel::parseAtom: Error!");
4183 qWarning(parser.errorMessage());
4185 errorMsg=parser.errorMessage();
4190 QVariant VymModel::runScript (const QString &script)
4192 parser.setScript (script);
4197 while (parser.next() && noErr)
4199 r=parseAtom(parser.getAtom(),noErr,errMsg);
4200 if (!noErr) //FIXME-3 need dialog box here
4201 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4206 void VymModel::setExportMode (bool b)
4208 // should be called before and after exports
4209 // depending on the settings
4210 if (b && settings.value("/export/useHideExport","true")=="true")
4211 setHideTmpMode (TreeItem::HideExport);
4213 setHideTmpMode (TreeItem::HideNone);
4216 void VymModel::exportImage(QString fname, bool askName, QString format)
4220 fname=getMapName()+".png";
4227 QFileDialog *fd=new QFileDialog (NULL);
4228 fd->setCaption (tr("Export map as image"));
4229 fd->setDirectory (lastImageDir);
4230 fd->setFileMode(QFileDialog::AnyFile);
4231 fd->setFilters (imageIO.getFilters() );
4234 fl=fd->selectedFiles();
4236 format=imageIO.getType(fd->selectedFilter());
4240 setExportMode (true);
4241 mapEditor->getScene()->update(); // FIXME-3 check this...
4242 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4243 img.save(fname, format);
4244 setExportMode (false);
4248 void VymModel::exportXML(QString dir, bool askForName)
4252 dir=browseDirectory(NULL,tr("Export XML to directory"));
4253 if (dir =="" && !reallyWriteDirectory(dir) )
4257 // Hide stuff during export, if settings want this
4258 setExportMode (true);
4260 // Create subdirectories
4263 // write to directory //FIXME-4 check totalBBox here...
4264 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4267 file.setName ( dir + "/"+mapName+".xml");
4268 if ( !file.open( QIODevice::WriteOnly ) )
4270 // This should neverever happen
4271 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4275 // Write it finally, and write in UTF8, no matter what
4276 QTextStream ts( &file );
4277 ts.setEncoding (QTextStream::UnicodeUTF8);
4281 // Now write image, too
4282 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4284 setExportMode (false);
4287 void VymModel::exportAO (QString fname,bool askName)
4292 ex.setFile (mapName+".txt");
4298 //ex.addFilter ("TXT (*.txt)");
4299 ex.setDir(lastImageDir);
4300 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4305 setExportMode(true);
4307 setExportMode(false);
4311 void VymModel::exportASCII(QString fname,bool askName)
4316 ex.setFile (mapName+".txt");
4322 //ex.addFilter ("TXT (*.txt)");
4323 ex.setDir(lastImageDir);
4324 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4329 setExportMode(true);
4331 setExportMode(false);
4335 void VymModel::exportHTML (const QString &dir, bool useDialog)
4337 ExportHTML ex (this);
4339 ex.doExport(useDialog);
4342 void VymModel::exportXHTML (const QString &dir, bool askForName)
4344 ExportXHTMLDialog dia(NULL);
4345 dia.setFilePath (filePath );
4346 dia.setMapName (mapName );
4348 if (dir!="") dia.setDir (dir);
4354 if (dia.exec()!=QDialog::Accepted)
4358 QDir d (dia.getDir());
4359 // Check, if warnings should be used before overwriting
4360 // the output directory
4361 if (d.exists() && d.count()>0)
4364 warn.showCancelButton (true);
4365 warn.setText(QString(
4366 "The directory %1 is not empty.\n"
4367 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4368 warn.setCaption("Warning: Directory not empty");
4369 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4371 if (warn.exec()!=QDialog::Accepted) ok=false;
4378 exportXML (dia.getDir(),false );
4379 dia.doExport(mapName );
4380 //if (dia.hasChanged()) setChanged();
4384 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4389 if (ex.setConfigFile(cf))
4391 setExportMode (true);
4392 ex.exportPresentation();
4393 setExportMode (false);
4400 //////////////////////////////////////////////
4402 //////////////////////////////////////////////
4404 void VymModel::registerEditor(QWidget *me)
4406 mapEditor=(MapEditor*)me;
4409 void VymModel::unregisterEditor(QWidget *)
4414 void VymModel::setContextPos(QPointF p)
4419 void VymModel::unsetContextPos()
4421 contextPos=QPointF();
4424 void VymModel::updateNoteFlag()
4426 TreeItem *selti=getSelectedItem();
4435 if (textEditor->isEmpty())
4438 selti->setNote (textEditor->getText());
4439 emitDataHasChanged(selti);
4443 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4445 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4446 if (blockReposition) return;
4448 for (int i=0;i<rootItem->branchCount(); i++)
4449 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4450 //emitSelectionChanged();
4454 void VymModel::setMapLinkStyle (const QString & s)
4459 case LinkableMapObj::Line :
4462 case LinkableMapObj::Parabel:
4463 snow="StyleParabel";
4465 case LinkableMapObj::PolyLine:
4466 snow="StylePolyLine";
4468 case LinkableMapObj::PolyParabel:
4469 snow="StylePolyParabel";
4472 snow="UndefinedStyle";
4477 QString("setMapLinkStyle (\"%1\")").arg(s),
4478 QString("setMapLinkStyle (\"%1\")").arg(snow),
4479 QString("Set map link style (\"%1\")").arg(s)
4483 linkstyle=LinkableMapObj::Line;
4484 else if (s=="StyleParabel")
4485 linkstyle=LinkableMapObj::Parabel;
4486 else if (s=="StylePolyLine")
4487 linkstyle=LinkableMapObj::PolyLine;
4488 else if (s=="StylePolyParabel")
4489 linkstyle=LinkableMapObj::PolyParabel;
4491 linkstyle=LinkableMapObj::UndefinedStyle;
4493 BranchItem *cur=NULL;
4494 BranchItem *prev=NULL;
4496 nextBranch (cur,prev);
4499 bo=(BranchObj*)(cur->getLMO() );
4500 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4501 cur=nextBranch(cur,prev);
4506 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4511 uint VymModel::getID()
4516 void VymModel::setMapDefLinkColor(QColor col)
4518 if ( !col.isValid() ) return;
4520 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4521 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4522 QString("Set map link color to %1").arg(col.name())
4526 BranchItem *cur=NULL;
4527 BranchItem *prev=NULL;
4529 cur=nextBranch(cur,prev);
4532 bo=(BranchObj*)(cur->getLMO() );
4534 nextBranch(cur,prev);
4539 void VymModel::setMapLinkColorHintInt()
4541 // called from setMapLinkColorHint(lch) or at end of parse
4542 BranchItem *cur=NULL;
4543 BranchItem *prev=NULL;
4545 cur=nextBranch(cur,prev);
4548 bo=(BranchObj*)(cur->getLMO() );
4550 cur=nextBranch(cur,prev);
4554 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4557 setMapLinkColorHintInt();
4560 void VymModel::toggleMapLinkColorHint()
4562 if (linkcolorhint==LinkableMapObj::HeadingColor)
4563 linkcolorhint=LinkableMapObj::DefaultColor;
4565 linkcolorhint=LinkableMapObj::HeadingColor;
4566 BranchItem *cur=NULL;
4567 BranchItem *prev=NULL;
4569 cur=nextBranch(cur,prev);
4572 bo=(BranchObj*)(cur->getLMO() );
4574 nextBranch(cur,prev);
4578 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4580 Q3FileDialog *fd=new Q3FileDialog( NULL);
4581 fd->setMode (Q3FileDialog::ExistingFile);
4582 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4583 ImagePreview *p =new ImagePreview (fd);
4584 fd->setContentsPreviewEnabled( TRUE );
4585 fd->setContentsPreview( p, p );
4586 fd->setPreviewMode( Q3FileDialog::Contents );
4587 fd->setCaption(vymName+" - " +tr("Load background image"));
4588 fd->setDir (lastImageDir);
4591 if ( fd->exec() == QDialog::Accepted )
4593 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4594 lastImageDir=QDir (fd->dirPath());
4595 setMapBackgroundImage (fd->selectedFile());
4599 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4601 QColor oldcol=mapScene->backgroundBrush().color();
4605 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4607 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4608 QString("Set background color of map to %1").arg(col.name()));
4611 brush.setTextureImage (QPixmap (fn));
4612 mapScene->setBackgroundBrush(brush);
4615 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4617 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4618 if ( !col.isValid() ) return;
4619 setMapBackgroundColor( col );
4623 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4625 QColor oldcol=mapScene->backgroundBrush().color();
4627 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4628 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4629 QString("Set background color of map to %1").arg(col.name()));
4630 mapScene->setBackgroundBrush(col);
4633 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4635 return mapScene->backgroundBrush().color();
4639 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4641 return linkcolorhint;
4644 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4646 return defLinkColor;
4649 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4654 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4656 return defXLinkColor;
4659 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4664 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4666 return defXLinkWidth;
4669 void VymModel::move(const double &x, const double &y)
4672 MapItem *seli = (MapItem*)getSelectedItem();
4673 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4675 LinkableMapObj *lmo=seli->getLMO();
4678 QPointF ap(lmo->getAbsPos());
4682 QString ps=qpointFToString(ap);
4683 QString s=getSelectString(seli);
4686 s, "move "+qpointFToString(to),
4687 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4690 emitSelectionChanged();
4696 void VymModel::moveRel (const double &x, const double &y)
4699 MapItem *seli = (MapItem*)getSelectedItem();
4700 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4702 LinkableMapObj *lmo=seli->getLMO();
4705 QPointF rp(lmo->getRelPos());
4709 QString ps=qpointFToString (lmo->getRelPos());
4710 QString s=getSelectString(seli);
4713 s, "moveRel "+qpointFToString(to),
4714 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4715 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4717 lmo->updateLinkGeometry();
4718 emitSelectionChanged();
4725 void VymModel::animate()
4727 animationTimer->stop();
4730 while (i<animObjList.size() )
4732 bo=(BranchObj*)animObjList.at(i);
4737 animObjList.removeAt(i);
4744 QItemSelection sel=selModel->selection();
4745 emit (selectionChanged(sel,sel));
4748 if (!animObjList.isEmpty()) animationTimer->start();
4752 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4754 if (start==dest) return;
4755 if (bo && bo->getTreeItem()->depth()>0)
4758 ap.setStart (start);
4760 ap.setTicks (animationTicks);
4761 ap.setAnimated (true);
4762 bo->setAnimation (ap);
4763 animObjList.append( bo );
4764 animationTimer->setSingleShot (true);
4765 animationTimer->start(animationInterval);
4769 void VymModel::stopAnimation (MapObj *mo)
4771 int i=animObjList.indexOf(mo);
4773 animObjList.removeAt (i);
4776 void VymModel::sendSelection()
4778 if (netstate!=Server) return;
4779 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4782 void VymModel::newServer()
4786 tcpServer = new QTcpServer(this);
4787 if (!tcpServer->listen(QHostAddress::Any,port)) {
4788 QMessageBox::critical(NULL, "vym server",
4789 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4790 //FIXME-3 needed? we are no widget any longer... close();
4793 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4795 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4798 void VymModel::connectToServer()
4801 server="salam.suse.de";
4803 clientSocket = new QTcpSocket (this);
4804 clientSocket->abort();
4805 clientSocket->connectToHost(server ,port);
4806 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4807 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4808 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4810 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4815 void VymModel::newClient()
4817 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4818 connect(newClient, SIGNAL(disconnected()),
4819 newClient, SLOT(deleteLater()));
4821 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4823 clientList.append (newClient);
4827 void VymModel::sendData(const QString &s)
4829 if (clientList.size()==0) return;
4831 // Create bytearray to send
4833 QDataStream out(&block, QIODevice::WriteOnly);
4834 out.setVersion(QDataStream::Qt_4_0);
4836 // Reserve some space for blocksize
4839 // Write sendCounter
4840 out << sendCounter++;
4845 // Go back and write blocksize so far
4846 out.device()->seek(0);
4847 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4851 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4853 for (int i=0; i<clientList.size(); ++i)
4855 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4856 clientList.at(i)->write (block);
4860 void VymModel::readData ()
4862 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4865 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4869 QDataStream in(clientSocket);
4870 in.setVersion(QDataStream::Qt_4_0);
4878 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4881 parseAtom (t,noErr,errMsg);
4887 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4889 switch (socketError) {
4890 case QAbstractSocket::RemoteHostClosedError:
4892 case QAbstractSocket::HostNotFoundError:
4893 QMessageBox::information(NULL, vymName +" Network client",
4894 "The host was not found. Please check the "
4895 "host name and port settings.");
4897 case QAbstractSocket::ConnectionRefusedError:
4898 QMessageBox::information(NULL, vymName + " Network client",
4899 "The connection was refused by the peer. "
4900 "Make sure the fortune server is running, "
4901 "and check that the host name and port "
4902 "settings are correct.");
4905 QMessageBox::information(NULL, vymName + " Network client",
4906 QString("The following error occurred: %1.")
4907 .arg(clientSocket->errorString()));
4911 /* FIXME-3 Playing with DBUS...
4912 QDBusVariant VymModel::query (const QString &query)
4914 TreeItem *selti=getSelectedItem();
4916 return QDBusVariant (selti->getHeading());
4918 return QDBusVariant ("Nothing selected.");
4922 void VymModel::testslot() //FIXME-3 Playing with DBUS
4924 cout << "VM::testslot called\n";
4927 void VymModel::selectMapSelectionColor()
4929 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4930 setSelectionColor (col);
4933 void VymModel::setSelectionColorInt (QColor col)
4935 if ( !col.isValid() ) return;
4937 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4938 QString("setSelectionColor (%1)").arg(col.name()),
4939 QString("Set color of selection box to %1").arg(col.name())
4942 mapEditor->setSelectionColor (col);
4945 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4947 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4948 //FIXME-3 emitShowSelection();
4952 void VymModel::emitSelectionChanged()
4954 QItemSelection newsel=selModel->selection();
4955 emitSelectionChanged (newsel);
4958 void VymModel::setSelectionColor(QColor col)
4960 if ( !col.isValid() ) return;
4962 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4963 QString("setSelectionColor (%1)").arg(col.name()),
4964 QString("Set color of selection box to %1").arg(col.name())
4966 setSelectionColorInt (col);
4969 QColor VymModel::getSelectionColor()
4971 return mapEditor->getSelectionColor();
4974 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4977 for (int i=0;i<rootItem->branchCount();i++)
4978 rootItem->getBranchNum(i)->setHideTmp (mode);
4980 if (mode==TreeItem::HideExport)
4986 //////////////////////////////////////////////
4987 // Selection related
4988 //////////////////////////////////////////////
4990 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4995 QItemSelectionModel* VymModel::getSelectionModel()
5000 void VymModel::setSelectionBlocked (bool b)
5005 bool VymModel::isSelectionBlocked()
5007 return selectionBlocked;
5010 bool VymModel::select ()
5012 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5015 bool VymModel::select (const QString &s)
5022 TreeItem *ti=findBySelectString(s);
5023 if (ti) return select (index(ti));
5027 bool VymModel::select (LinkableMapObj *lmo)
5029 QItemSelection oldsel=selModel->selection();
5032 return select (index (lmo->getTreeItem()) );
5037 bool VymModel::select (TreeItem *ti)
5039 if (ti) return select (index(ti));
5043 bool VymModel::select (const QModelIndex &index)
5045 if (index.isValid() )
5047 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5048 BranchItem *bi=getSelectedBranch();
5049 if (bi) bi->setLastSelectedBranch();
5055 void VymModel::unselect()
5057 if (!selModel->selectedIndexes().isEmpty())
5059 lastSelectString=getSelectString();
5060 selModel->clearSelection();
5064 bool VymModel::reselect()
5066 return select (lastSelectString);
5069 void VymModel::emitShowSelection()
5071 if (!blockReposition)
5072 emit (showSelection() );
5075 void VymModel::emitNoteHasChanged (TreeItem *ti)
5077 QModelIndex ix=index(ti);
5078 emit (noteHasChanged (ix) );
5081 void VymModel::emitDataHasChanged (TreeItem *ti)
5083 QModelIndex ix=index(ti);
5084 emit (dataChanged (ix,ix) );
5088 bool VymModel::selectFirstBranch()
5090 TreeItem *ti=getSelectedBranch();
5093 TreeItem *par=ti->parent();
5096 TreeItem *ti2=par->getFirstBranch();
5097 if (ti2) return select(ti2);
5103 bool VymModel::selectLastBranch()
5105 TreeItem *ti=getSelectedBranch();
5108 TreeItem *par=ti->parent();
5111 TreeItem *ti2=par->getLastBranch();
5112 if (ti2) return select(ti2);
5118 bool VymModel::selectLastSelectedBranch()
5120 BranchItem *bi=getSelectedBranch();
5123 bi=bi->getLastSelectedBranch();
5124 if (bi) return select (bi);
5129 bool VymModel::selectParent()
5131 TreeItem *ti=getSelectedItem();
5142 TreeItem::Type VymModel::selectionType()
5144 QModelIndexList list=selModel->selectedIndexes();
5145 if (list.isEmpty()) return TreeItem::Undefined;
5146 TreeItem *ti = getItem (list.first() );
5147 return ti->getType();
5151 LinkableMapObj* VymModel::getSelectedLMO()
5153 QModelIndexList list=selModel->selectedIndexes();
5154 if (!list.isEmpty() )
5156 TreeItem *ti = getItem (list.first() );
5157 TreeItem::Type type=ti->getType();
5158 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5159 return ((MapItem*)ti)->getLMO();
5164 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5166 TreeItem *ti = getSelectedBranch();
5168 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5173 BranchItem* VymModel::getSelectedBranch()
5175 QModelIndexList list=selModel->selectedIndexes();
5176 if (!list.isEmpty() )
5178 TreeItem *ti = getItem (list.first() );
5179 TreeItem::Type type=ti->getType();
5180 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5181 return (BranchItem*)ti;
5186 ImageItem* VymModel::getSelectedImage()
5188 QModelIndexList list=selModel->selectedIndexes();
5189 if (!list.isEmpty())
5191 TreeItem *ti=getItem (list.first());
5192 if (ti && ti->getType()==TreeItem::Image)
5193 return (ImageItem*)ti;
5198 AttributeItem* VymModel::getSelectedAttribute()
5200 QModelIndexList list=selModel->selectedIndexes();
5201 if (!list.isEmpty() )
5203 TreeItem *ti = getItem (list.first() );
5204 TreeItem::Type type=ti->getType();
5205 if (type ==TreeItem::Attribute)
5206 return (AttributeItem*)ti;
5211 TreeItem* VymModel::getSelectedItem()
5213 QModelIndexList list=selModel->selectedIndexes();
5214 if (!list.isEmpty() )
5215 return getItem (list.first() );
5220 QModelIndex VymModel::getSelectedIndex()
5222 QModelIndexList list=selModel->selectedIndexes();
5223 if (list.isEmpty() )
5224 return QModelIndex();
5226 return list.first();
5229 QString VymModel::getSelectString ()
5231 return getSelectString (getSelectedItem());
5234 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5236 if (!lmo) return QString();
5237 return getSelectString (lmo->getTreeItem() );
5240 QString VymModel::getSelectString (TreeItem *ti)
5244 switch (ti->getType())
5246 case TreeItem::MapCenter: s="mc:"; break;
5247 case TreeItem::Branch: s="bo:";break;
5248 case TreeItem::Image: s="fi:";break;
5249 case TreeItem::Attribute: s="ai:";break;
5250 case TreeItem::XLink: s="xl:";break;
5252 s="unknown type in VymModel::getSelectString()";
5255 s= s + QString("%1").arg(ti->num());
5257 // call myself recursively
5258 s= getSelectString(ti->parent()) +","+s;