1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
14 #include "findresultmodel.h"
15 #include "geometry.h" // for addBBox
16 #include "mainwindow.h"
21 #include "warningdialog.h"
22 #include "xlinkitem.h"
23 #include "xml-freemind.h"
29 extern Main *mainWindow;
30 extern QDBusConnection dbusConnection;
32 extern Settings settings;
33 extern QString tmpVymDir;
35 extern TextEditor *textEditor;
36 extern FlagRow *standardFlagsMaster;
38 extern QString clipboardDir;
39 extern QString clipboardFile;
40 extern bool clipboardEmpty;
42 extern ImageIO imageIO;
44 extern QString vymName;
45 extern QString vymVersion;
46 extern QDir vymBaseDir;
48 extern QDir lastImageDir;
49 extern QDir lastFileDir;
51 extern Settings settings;
53 uint VymModel::idLast=0; // make instance
57 //cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 //cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
69 if (mapEditor) delete (mapEditor);
72 void VymModel::clear()
75 while (rootItem->childCount() >0)
76 deleteItem (rootItem->getChildNum(0) );
79 void VymModel::init ()
84 // Also no scene yet (should not be needed anyway) FIXME-3 VM
98 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
99 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
100 mainWindow->updateHistory (undoSet);
103 makeTmpDirectories();
108 fileName=tr("unnamed");
110 blockReposition=false;
111 blockSaveState=false;
113 autosaveTimer=new QTimer (this);
114 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
116 fileChangedTimer=new QTimer (this);
117 fileChangedTimer->start(3000);
118 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
123 selectionBlocked=false;
128 // animations // FIXME-3 switch to new animation system
129 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
130 animationTicks=settings.readNumEntry("/animation/ticks",10);
131 animationInterval=settings.readNumEntry("/animation/interval",50);
133 animationTimer=new QTimer (this);
134 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
137 defLinkColor=QColor (0,0,255);
138 defXLinkColor=QColor (180,180,180);
139 linkcolorhint=LinkableMapObj::DefaultColor;
140 linkstyle=LinkableMapObj::PolyParabel;
142 defXLinkColor=QColor (230,230,230);
145 hidemode=TreeItem::HideNone;
150 //Initialize DBUS object
151 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
152 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
153 qWarning ("VymModel: Couldn't register DBUS object!");
156 void VymModel::makeTmpDirectories()
158 // Create unique temporary directories
159 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
160 histPath = tmpMapDir+"/history";
166 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
171 bool VymModel::isRepositionBlocked()
173 return blockReposition;
176 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
178 //cout << "VM::updateActions \n";
179 // Tell mainwindow to update states of actions
180 mainWindow->updateActions();
185 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
187 // tmpdir temporary directory to which data will be written
188 // prefix mapname, which will be appended to images etc.
189 // writeflags Only write flags for "real" save of map, not undo
190 // offset offset of bbox of whole map in scene.
191 // Needed for XML export
200 case LinkableMapObj::Line:
203 case LinkableMapObj::Parabel:
206 case LinkableMapObj::PolyLine:
210 ls="StylePolyParabel";
214 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
216 if (linkcolorhint==LinkableMapObj::HeadingColor)
217 colhint=xml.attribut("linkColorHint","HeadingColor");
219 QString mapAttr=xml.attribut("version",vymVersion);
221 mapAttr+= xml.attribut("author",author) +
222 xml.attribut("comment",comment) +
223 xml.attribut("date",getDate()) +
224 xml.attribut("branchCount", QString().number(branchCount())) +
225 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
226 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
227 xml.attribut("linkStyle", ls ) +
228 xml.attribut("linkColor", defLinkColor.name() ) +
229 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
230 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
231 xml.attribut("mapZoomFactor", QString().setNum(mapEditor->getZoomFactorTarget()) ) +
233 s+=xml.beginElement("vymmap",mapAttr);
236 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
237 standardFlagsMaster->resetUsedCounter();
239 // Build xml recursivly
241 // Save all mapcenters as complete map, if saveSel not set
242 s+=saveTreeToDir(tmpdir,prefix,offset);
245 switch (saveSel->getType())
247 case TreeItem::Branch:
249 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
251 case TreeItem::MapCenter:
253 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
255 case TreeItem::Image:
257 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
260 // other types shouldn't be safed directly...
265 // Save local settings
266 s+=settings.getDataXML (destPath);
269 if (getSelectedItem() && !saveSel )
270 s+=xml.valueElement("select",getSelectString());
273 s+=xml.endElement("vymmap");
275 //cout << s.toStdString() << endl;
277 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
281 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
285 for (int i=0; i<rootItem->branchCount(); i++)
286 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
290 void VymModel::setFilePath(QString fpath, QString destname)
292 if (fpath.isEmpty() || fpath=="")
299 filePath=fpath; // becomes absolute path
300 fileName=fpath; // gets stripped of path
301 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
303 // If fpath is not an absolute path, complete it
304 filePath=QDir(fpath).absPath();
305 fileDir=filePath.left (1+filePath.findRev ("/"));
307 // Set short name, too. Search from behind:
308 int i=fileName.findRev("/");
309 if (i>=0) fileName=fileName.remove (0,i+1);
311 // Forget the .vym (or .xml) for name of map
312 mapName=fileName.left(fileName.findRev(".",-1,true) );
316 void VymModel::setFilePath(QString fpath)
318 setFilePath (fpath,fpath);
321 QString VymModel::getFilePath()
326 QString VymModel::getFileName()
331 QString VymModel::getMapName()
336 QString VymModel::getDestPath()
341 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
343 ErrorCode err=success;
345 parseBaseHandler *handler;
349 case VymMap: handler=new parseVYMHandler; break;
350 case FreemindMap : handler=new parseFreemindHandler; break;
352 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
353 "Unknown FileType in VymModel::load()");
357 bool zipped_org=zipped;
361 selModel->clearSelection();
364 BranchItem *bi=getSelectedBranch();
365 if (!bi) return aborted;
366 if (lmode==ImportAdd)
367 saveStateChangingPart(
370 QString("addMapInsert (%1)").arg(fname),
371 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
373 saveStateChangingPart(
376 QString("addMapReplace(%1)").arg(fname),
377 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
381 // Create temporary directory for packing
383 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
386 QMessageBox::critical( 0, tr( "Critical Load Error" ),
387 tr("Couldn't create temporary directory before load\n"));
392 err=unzipDir (tmpZipDir,fname);
402 // Look for mapname.xml
403 xmlfile= fname.left(fname.findRev(".",-1,true));
404 xmlfile=xmlfile.section( '/', -1 );
405 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
406 if (!mfile.exists() )
408 // mapname.xml does not exist, well,
409 // maybe someone renamed the mapname.vym file...
410 // Try to find any .xml in the toplevel
411 // directory of the .vym file
412 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
413 if (flist.count()==1)
415 // Only one entry, take this one
416 xmlfile=tmpZipDir + "/"+flist.first();
419 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
420 *it=tmpZipDir + "/" + *it;
421 // TODO Multiple entries, load all (but only the first one into this ME)
422 //mainWindow->fileLoadFromTmp (flist);
423 //returnCode=1; // Silently forget this attempt to load
424 qWarning ("MainWindow::load (fn) multimap found...");
427 if (flist.isEmpty() )
429 QMessageBox::critical( 0, tr( "Critical Load Error" ),
430 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
433 } //file doesn't exist
435 xmlfile=mfile.name();
438 QFile file( xmlfile);
440 // I am paranoid: file should exist anyway
441 // according to check in mainwindow.
444 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
445 tr(QString("Couldn't open map %1").arg(file.name())));
449 bool blockSaveStateOrg=blockSaveState;
450 blockReposition=true;
452 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
453 QXmlInputSource source( file);
454 QXmlSimpleReader reader;
455 reader.setContentHandler( handler );
456 reader.setErrorHandler( handler );
457 handler->setModel ( this);
460 // We need to set the tmpDir in order to load files with rel. path
465 tmpdir=fname.left(fname.findRev("/",-1));
466 handler->setTmpDir (tmpdir);
467 handler->setInputFile (file.name());
468 handler->setLoadMode (lmode);
469 bool ok = reader.parse( source );
470 blockReposition=false;
471 blockSaveState=blockSaveStateOrg;
472 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
477 emitSelectionChanged();
483 autosaveTimer->stop();
486 // Reset timestamp to check for later updates of file
487 fileChangedTime=QFileInfo (destPath).lastModified();
490 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
491 tr( handler->errorProtocol() ) );
493 // Still return "success": the map maybe at least
494 // partially read by the parser
499 removeDir (QDir(tmpZipDir));
501 // Restore original zip state
506 if (mapEditor) mapEditor->setZoomFactorTarget (zoomFactor);
508 //Update view (scene()->update() is not enough)
509 qApp->processEvents(); // Update view (scene()->update() is not enough)
513 ErrorCode VymModel::save (const SaveMode &savemode)
517 QString safeFilePath;
519 ErrorCode err=success;
523 mapFileName=mapName+".xml";
525 // use name given by user, even if he chooses .doc
526 mapFileName=fileName;
528 // Look, if we should zip the data:
531 QMessageBox mb( vymName,
532 tr("The map %1\ndid not use the compressed "
533 "vym file format.\nWriting it uncompressed will also write images \n"
534 "and flags and thus may overwrite files in the "
535 "given directory\n\nDo you want to write the map").arg(filePath),
536 QMessageBox::Warning,
537 QMessageBox::Yes | QMessageBox::Default,
539 QMessageBox::Cancel | QMessageBox::Escape);
540 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
541 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
542 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
545 case QMessageBox::Yes:
546 // save compressed (default file format)
549 case QMessageBox::No:
553 case QMessageBox::Cancel:
560 // First backup existing file, we
561 // don't want to add to old zip archives
565 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
567 QString backupFileName(destPath + "~");
568 QFile backupFile(backupFileName);
569 if (backupFile.exists() && !backupFile.remove())
571 QMessageBox::warning(0, tr("Save Error"),
572 tr("%1\ncould not be removed before saving").arg(backupFileName));
574 else if (!f.rename(backupFileName))
576 QMessageBox::warning(0, tr("Save Error"),
577 tr("%1\ncould not be renamed before saving").arg(destPath));
584 // Create temporary directory for packing
586 tmpZipDir=makeTmpDir (ok,"vym-zip");
589 QMessageBox::critical( 0, tr( "Critical Load Error" ),
590 tr("Couldn't create temporary directory before save\n"));
594 safeFilePath=filePath;
595 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
598 // Create mapName and fileDir
599 makeSubDirs (fileDir);
602 if (savemode==CompleteMap || selModel->selection().isEmpty())
605 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
608 autosaveTimer->stop();
613 if (selectionType()==TreeItem::Image)
616 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
617 // TODO take care of multiselections
620 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
623 qWarning ("ME::saveStringToDisk failed!");
629 if (err==success) err=zipDir (tmpZipDir,destPath);
632 removeDir (QDir(tmpZipDir));
634 // Restore original filepath outside of tmp zip dir
635 setFilePath (safeFilePath);
639 fileChangedTime=QFileInfo (destPath).lastModified();
643 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
645 QString pathDir=path.left(path.findRev("/"));
651 // We need to parse saved XML data
652 parseVYMHandler handler;
653 QXmlInputSource source( file);
654 QXmlSimpleReader reader;
655 reader.setContentHandler( &handler );
656 reader.setErrorHandler( &handler );
657 handler.setModel ( this);
658 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
659 if (undoSel.isEmpty())
663 handler.setLoadMode (NewMap);
667 handler.setLoadMode (ImportReplace);
669 blockReposition=true;
670 bool ok = reader.parse( source );
671 blockReposition=false;
674 // This should never ever happen
675 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
676 handler.errorProtocol());
679 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
682 bool VymModel::addMapInsertInt (const QString &path)
684 QString pathDir=path.left(path.findRev("/"));
690 // We need to parse saved XML data
691 parseVYMHandler handler;
692 QXmlInputSource source( file);
693 QXmlSimpleReader reader;
694 reader.setContentHandler( &handler );
695 reader.setErrorHandler( &handler );
696 handler.setModel (this);
697 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
698 handler.setLoadMode (ImportAdd);
699 blockReposition=true;
700 bool ok = reader.parse( source );
701 blockReposition=false;
702 if ( ok ) return true;
704 // This should never ever happen
705 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
706 handler.errorProtocol());
709 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
713 bool VymModel::addMapInsertInt (const QString &path, int pos)
715 BranchItem *selbi=getSelectedBranch();
718 if (addMapInsertInt (path))
720 if (selbi->depth()>0)
721 relinkBranch (selbi->getLastBranch(), selbi,pos);
725 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
729 qWarning ("ME::addMapInsertInt nothing selected");
733 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
735 ImageItem *ii=createImage(dst);
745 void VymModel::loadFloatImage ()
747 BranchItem *selbi=getSelectedBranch();
751 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
752 fd->setMode (Q3FileDialog::ExistingFiles);
753 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
754 ImagePreview *p =new ImagePreview (fd);
755 fd->setContentsPreviewEnabled( TRUE );
756 fd->setContentsPreview( p, p );
757 fd->setPreviewMode( Q3FileDialog::Contents );
758 fd->setCaption(vymName+" - " +tr("Load image"));
759 fd->setDir (lastImageDir);
762 if ( fd->exec() == QDialog::Accepted )
764 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
765 lastImageDir=QDir (fd->dirPath());
768 for (int j=0; j<fd->selectedFiles().count(); j++)
770 s=fd->selectedFiles().at(j);
771 ii=loadFloatImageInt (selbi,s);
772 //FIXME-3 check savestate for loadImage
778 QString ("loadImage (%1)").arg(s ),
779 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
782 // TODO loadFIO error handling
783 qWarning ("Failed to load "+s);
791 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
796 void VymModel::saveFloatImage ()
798 ImageItem *ii=getSelectedImage();
801 QFileDialog *fd=new QFileDialog( NULL);
802 fd->setFilters (imageIO.getFilters());
803 fd->setCaption(vymName+" - " +tr("Save image"));
804 fd->setFileMode( QFileDialog::AnyFile );
805 fd->setDirectory (lastImageDir);
806 // fd->setSelection (fio->getOriginalFilename());
810 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
812 fn=fd->selectedFiles().at(0);
813 if (QFile (fn).exists() )
815 QMessageBox mb( vymName,
816 tr("The file %1 exists already.\n"
817 "Do you want to overwrite it?").arg(fn),
818 QMessageBox::Warning,
819 QMessageBox::Yes | QMessageBox::Default,
820 QMessageBox::Cancel | QMessageBox::Escape,
821 QMessageBox::NoButton );
823 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
824 mb.setButtonText( QMessageBox::No, tr("Cancel"));
827 case QMessageBox::Yes:
830 case QMessageBox::Cancel:
837 saveFloatImageInt (ii,fd->selectedFilter(),fn );
844 void VymModel::importDirInt(BranchItem *dst, QDir d)
846 BranchItem *selbi=getSelectedBranch();
850 // Traverse directories
851 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
852 QFileInfoList list = d.entryInfoList();
855 for (int i = 0; i < list.size(); ++i)
858 if (fi.fileName() != "." && fi.fileName() != ".." )
860 bi=addNewBranchInt(dst,-2);
861 bi->setHeading (fi.fileName() ); // FIXME-3 check this
862 bi->setHeadingColor (QColor("blue"));
864 if ( !d.cd(fi.fileName()) )
865 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
868 // Recursively add subdirs
875 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
876 list = d.entryInfoList();
878 for (int i = 0; i < list.size(); ++i)
881 bi=addNewBranchInt (dst,-2);
882 bi->setHeading (fi.fileName() );
883 bi->setHeadingColor (QColor("black"));
884 if (fi.fileName().right(4) == ".vym" )
885 bi->setVymLink (fi.filePath());
890 void VymModel::importDirInt (const QString &s)
892 BranchItem *selbi=getSelectedBranch();
895 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
898 importDirInt (selbi,d);
902 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
904 BranchItem *selbi=getSelectedBranch();
908 filters <<"VYM map (*.vym)";
909 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
910 fd->setMode (QFileDialog::DirectoryOnly);
911 fd->setFilters (filters);
912 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
916 if ( fd->exec() == QDialog::Accepted )
918 importDirInt (fd->selectedFile() );
920 //FIXME-3 VM needed? scene()->update();
926 void VymModel::autosave()
931 cout << "VymModel::autosave rejected due to missing filePath\n";
934 QDateTime now=QDateTime().currentDateTime();
936 // Disable autosave, while we have gone back in history
937 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
938 if (redosAvail>0) return;
940 // Also disable autosave for new map without filename
941 if (filePath.isEmpty()) return;
944 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
946 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
947 mainWindow->fileSave (this);
950 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
955 void VymModel::fileChanged()
957 // Check if file on disk has changed meanwhile
958 if (!filePath.isEmpty())
960 QDateTime tmod=QFileInfo (filePath).lastModified();
961 if (tmod>fileChangedTime)
963 // FIXME-3 VM switch to current mapeditor and finish lineedits...
964 QMessageBox mb( vymName,
965 tr("The file of the map on disk has changed:\n\n"
966 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
967 QMessageBox::Question,
969 QMessageBox::Cancel | QMessageBox::Default,
970 QMessageBox::NoButton );
972 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
973 mb.setButtonText( QMessageBox::No, tr("Ignore"));
976 case QMessageBox::Yes:
978 load (filePath,NewMap,fileType);
979 case QMessageBox::Cancel:
980 fileChangedTime=tmod; // allow autosave to overwrite newer file!
986 bool VymModel::isDefault()
991 void VymModel::makeDefault()
997 bool VymModel::hasChanged()
1002 void VymModel::setChanged()
1005 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1009 latestAddedItem=NULL;
1013 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1015 if (!lmo || !lmo->getTreeItem() ) return QString();
1016 return getObjectName (lmo->getTreeItem() );
1020 QString VymModel::getObjectName (TreeItem *ti)
1023 if (!ti) return QString("Error: NULL has no name!");
1025 if (s=="") s="unnamed";
1027 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1030 void VymModel::redo()
1032 // Can we undo at all?
1033 if (redosAvail<1) return;
1035 bool blockSaveStateOrg=blockSaveState;
1036 blockSaveState=true;
1040 if (undosAvail<stepsTotal) undosAvail++;
1042 if (curStep>stepsTotal) curStep=1;
1043 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1044 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1045 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1046 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1047 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1048 QString version=undoSet.readEntry ("/history/version");
1050 /* TODO Maybe check for version, if we save the history
1051 if (!checkVersion(version))
1052 QMessageBox::warning(0,tr("Warning"),
1053 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1056 // Find out current undo directory
1057 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1061 cout << "VymModel::redo() begin\n";
1062 cout << " undosAvail="<<undosAvail<<endl;
1063 cout << " redosAvail="<<redosAvail<<endl;
1064 cout << " curStep="<<curStep<<endl;
1065 cout << " ---------------------------"<<endl;
1066 cout << " comment="<<comment.toStdString()<<endl;
1067 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1068 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1069 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1070 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1071 cout << " ---------------------------"<<endl<<endl;
1074 // select object before redo
1075 if (!redoSelection.isEmpty())
1076 select (redoSelection);
1081 parseAtom (redoCommand,noErr,errMsg);
1083 blockSaveState=blockSaveStateOrg;
1085 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1086 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1087 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1088 undoSet.writeSettings(histPath);
1090 mainWindow->updateHistory (undoSet);
1093 /* TODO remove testing
1094 cout << "ME::redo() end\n";
1095 cout << " undosAvail="<<undosAvail<<endl;
1096 cout << " redosAvail="<<redosAvail<<endl;
1097 cout << " curStep="<<curStep<<endl;
1098 cout << " ---------------------------"<<endl<<endl;
1104 bool VymModel::isRedoAvailable()
1106 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1112 void VymModel::undo()
1114 // Can we undo at all?
1115 if (undosAvail<1) return;
1117 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1119 bool blockSaveStateOrg=blockSaveState;
1120 blockSaveState=true;
1122 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1123 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1124 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1125 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1126 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1127 QString version=undoSet.readEntry ("/history/version");
1129 /* TODO Maybe check for version, if we save the history
1130 if (!checkVersion(version))
1131 QMessageBox::warning(0,tr("Warning"),
1132 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1135 // Find out current undo directory
1136 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1138 // select object before undo
1139 if (!select (undoSelection))
1141 qWarning ("VymModel::undo() Could not select object for undo");
1148 cout << "VymModel::undo() begin\n";
1149 cout << " undosAvail="<<undosAvail<<endl;
1150 cout << " redosAvail="<<redosAvail<<endl;
1151 cout << " curStep="<<curStep<<endl;
1152 cout << " ---------------------------"<<endl;
1153 cout << " comment="<<comment.toStdString()<<endl;
1154 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1155 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1156 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1157 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1158 cout << " ---------------------------"<<endl<<endl;
1163 parseAtom (undoCommand,noErr,errMsg);
1167 if (curStep<1) curStep=stepsTotal;
1171 blockSaveState=blockSaveStateOrg;
1173 cout << "VymModel::undo() end\n";
1174 cout << " undosAvail="<<undosAvail<<endl;
1175 cout << " redosAvail="<<redosAvail<<endl;
1176 cout << " curStep="<<curStep<<endl;
1177 cout << " ---------------------------"<<endl<<endl;
1180 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1181 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1182 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1183 undoSet.writeSettings(histPath);
1185 mainWindow->updateHistory (undoSet);
1187 //emitSelectionChanged();
1190 bool VymModel::isUndoAvailable()
1192 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1198 void VymModel::gotoHistoryStep (int i)
1200 // Restore variables
1201 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1202 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1204 if (i<0) i=undosAvail+redosAvail;
1206 // Clicking above current step makes us undo things
1209 for (int j=0; j<undosAvail-i; j++) undo();
1212 // Clicking below current step makes us redo things
1214 for (int j=undosAvail; j<i; j++)
1216 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1220 // And ignore clicking the current row ;-)
1224 QString VymModel::getHistoryPath()
1226 QString histName(QString("history-%1").arg(curStep));
1227 return (tmpMapDir+"/"+histName);
1230 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1232 sendData(redoCom); //FIXME-3 testing
1237 if (blockSaveState) return;
1239 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1241 // Find out current undo directory
1242 if (undosAvail<stepsTotal) undosAvail++;
1244 if (curStep>stepsTotal) curStep=1;
1246 QString backupXML="";
1247 QString histDir=getHistoryPath();
1248 QString bakMapPath=histDir+"/map.xml";
1250 // Create histDir if not available
1253 makeSubDirs (histDir);
1255 // Save depending on how much needs to be saved
1257 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1259 QString undoCommand="";
1260 if (savemode==UndoCommand)
1262 undoCommand=undoCom;
1264 else if (savemode==PartOfMap )
1266 undoCommand=undoCom;
1267 undoCommand.replace ("PATH",bakMapPath);
1271 if (!backupXML.isEmpty())
1272 // Write XML Data to disk
1273 saveStringToDisk (bakMapPath,backupXML);
1275 // We would have to save all actions in a tree, to keep track of
1276 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1279 // Write the current state to disk
1280 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1281 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1282 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1283 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1284 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1285 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1286 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1287 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1288 undoSet.setEntry (QString("/history/version"),vymVersion);
1289 undoSet.writeSettings(histPath);
1293 // TODO remove after testing
1294 //cout << " into="<< histPath.toStdString()<<endl;
1295 cout << " stepsTotal="<<stepsTotal<<
1296 ", undosAvail="<<undosAvail<<
1297 ", redosAvail="<<redosAvail<<
1298 ", curStep="<<curStep<<endl;
1299 cout << " ---------------------------"<<endl;
1300 cout << " comment="<<comment.toStdString()<<endl;
1301 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1302 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1303 cout << " redoCom="<<redoCom.toStdString()<<endl;
1304 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1305 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1306 cout << " ---------------------------"<<endl;
1309 mainWindow->updateHistory (undoSet);
1315 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1317 // save the selected part of the map, Undo will replace part of map
1318 QString undoSelection="";
1320 undoSelection=getSelectString(undoSel);
1322 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1323 QString redoSelection="";
1325 redoSelection=getSelectString(undoSel);
1327 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1330 saveState (PartOfMap,
1331 undoSelection, "addMapReplace (\"PATH\")",
1337 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1341 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1344 QString undoSelection;
1345 QString redoSelection=getSelectString(redoSel);
1346 if (redoSel->getType()==TreeItem::Branch)
1348 undoSelection=getSelectString (redoSel->parent());
1349 // save the selected branch of the map, Undo will insert part of map
1350 saveState (PartOfMap,
1351 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1352 redoSelection, "delete ()",
1356 if (redoSel->getType()==TreeItem::MapCenter)
1358 // save the selected branch of the map, Undo will insert part of map
1359 saveState (PartOfMap,
1360 undoSelection, QString("addMapInsert (\"PATH\")"),
1361 redoSelection, "delete ()",
1368 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1370 // "Normal" savestate: save commands, selections and comment
1371 // so just save commands for undo and redo
1372 // and use current selection
1374 QString redoSelection="";
1375 if (redoSel) redoSelection=getSelectString(redoSel);
1376 QString undoSelection="";
1377 if (undoSel) undoSelection=getSelectString(undoSel);
1379 saveState (UndoCommand,
1386 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1388 // "Normal" savestate: save commands, selections and comment
1389 // so just save commands for undo and redo
1390 // and use current selection
1391 saveState (UndoCommand,
1398 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1400 // "Normal" savestate applied to model (no selection needed):
1401 // save commands and comment
1402 saveState (UndoCommand,
1410 QGraphicsScene* VymModel::getScene ()
1415 TreeItem* VymModel::findBySelectString(QString s)
1417 if (s.isEmpty() ) return NULL;
1419 // Old maps don't have multiple mapcenters and don't save full path
1420 if (s.left(2) !="mc")
1423 QStringList parts=s.split (",");
1426 TreeItem *ti=rootItem;
1428 while (!parts.isEmpty() )
1430 typ=parts.first().left(2);
1431 n=parts.first().right(parts.first().length() - 3).toInt();
1432 parts.removeFirst();
1433 if (typ=="mc" || typ=="bo")
1434 ti=ti->getBranchNum (n);
1436 ti=ti->getImageNum (n);
1438 ti=ti->getAttributeNum (n);
1440 ti=ti->getXLinkNum (n);
1441 if(!ti) return NULL;
1446 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1448 BranchItem *cur=NULL;
1449 BranchItem *prev=NULL;
1450 nextBranch(cur,prev);
1453 if (i==cur->getID() ) return cur;
1454 nextBranch(cur,prev);
1459 //////////////////////////////////////////////
1461 //////////////////////////////////////////////
1462 void VymModel::setVersion (const QString &s)
1467 QString VymModel::getVersion()
1472 void VymModel::setAuthor (const QString &s)
1475 QString ("setMapAuthor (\"%1\")").arg(author),
1476 QString ("setMapAuthor (\"%1\")").arg(s),
1477 QString ("Set author of map to \"%1\"").arg(s)
1482 QString VymModel::getAuthor()
1487 void VymModel::setComment (const QString &s)
1490 QString ("setMapComment (\"%1\")").arg(comment),
1491 QString ("setMapComment (\"%1\")").arg(s),
1492 QString ("Set comment of map")
1497 QString VymModel::getComment ()
1502 QString VymModel::getDate ()
1504 return QDate::currentDate().toString ("yyyy-MM-dd");
1507 int VymModel::branchCount()
1510 BranchItem *cur=NULL;
1511 BranchItem *prev=NULL;
1512 nextBranch(cur,prev);
1516 nextBranch(cur,prev);
1521 void VymModel::setSortFilter (const QString &s)
1524 emit (sortFilterChanged (sortFilter));
1527 QString VymModel::getSortFilter ()
1532 void VymModel::setHeading(const QString &s)
1534 BranchItem *selbi=getSelectedBranch();
1539 "setHeading (\""+selbi->getHeading()+"\")",
1541 "setHeading (\""+s+"\")",
1542 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1543 selbi->setHeading(s );
1544 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1546 emitSelectionChanged();
1550 QString VymModel::getHeading()
1552 TreeItem *selti=getSelectedItem();
1554 return selti->getHeading();
1559 void VymModel::setNote(const QString &s)
1561 TreeItem *selti=getSelectedItem();
1566 "setNote (\""+selti->getNote()+"\")",
1568 "setNote (\""+s+"\")",
1569 QString("Set note of %1 ").arg(getObjectName(selti)) );
1572 emitNoteHasChanged(selti);
1573 emitDataHasChanged(selti);
1576 QString VymModel::getNote()
1578 TreeItem *selti=getSelectedItem();
1580 return selti->getNote();
1585 void VymModel::loadNote (const QString &fn)
1587 BranchItem *selbi=getSelectedBranch();
1591 if (!loadStringFromDisk (fn,n))
1592 qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
1596 qWarning ("VymModel::loadNote no branch selected");
1599 void VymModel::saveNote (const QString &fn)
1601 BranchItem *selbi=getSelectedBranch();
1604 QString n=selbi->getNote();
1606 qWarning ()<<"VymModel::saveNote note is empty, won't save to "<<fn;
1609 if (!saveStringToDisk (fn,n))
1610 qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
1615 qWarning ("VymModel::saveNote no branch selected");
1618 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1620 // Generate map containing _all_ URLs and branches
1622 QMap <QString,BranchItem*> map;
1623 BranchItem *cur=NULL;
1624 BranchItem *prev=NULL;
1625 nextBranch(cur,prev);
1630 map.insertMulti (u,cur);
1631 nextBranch(cur,prev);
1634 // Extract duplicate URLs
1635 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1636 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1637 while (i != map.constEnd())
1639 if (i!=map.constBegin() && i.key()==firstdup.key())
1641 if ( i-1==firstdup )
1643 cout << firstdup.key().toStdString() << endl;
1644 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1646 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1654 void VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)
1657 rmodel->setSearchString (s);
1658 rmodel->setSearchFlags (0); //FIXME-2 translate cs to QTextDocument::FindFlag
1659 BranchItem *cur=NULL;
1660 BranchItem *prev=NULL;
1661 nextBranch(cur,prev);
1663 FindResultItem *lastParent=NULL;
1667 if (cur->getHeading().contains (s,cs))
1668 lastParent=rmodel->addItem (cur);
1669 QString n=cur->getNoteASCII();
1674 i=n.indexOf (s,i,cs); //FIXME-2 add subitems to rmodel
1677 // If not there yet, add "parent" item
1680 lastParent=rmodel->addItem (cur);
1682 qWarning()<<"VymModel::findAll still no lastParent?!";
1685 lastParent->setSelectable (false);
1689 // save index of occurence
1690 rmodel->addSubItem (lastParent,QString(tr("Note","FindAll in VymModel")+" "+s),cur,j);
1695 nextBranch(cur,prev);
1699 BranchItem* VymModel::findText (QString s,Qt::CaseSensitivity cs)
1701 if (!s.isEmpty() && s!=findString)
1707 QTextDocument::FindFlags flags=0;
1708 if (cs==Qt::CaseSensitive) flags=QTextDocument::FindCaseSensitively;
1711 { // Nothing found or new find process
1713 // nothing found, start again
1717 nextBranch (findCurrent,findPrevious);
1719 bool searching=true;
1720 bool foundNote=false;
1721 while (searching && !EOFind)
1725 // Searching in Note
1726 if (findCurrent->getNote().contains(findString,cs))
1728 select (findCurrent);
1729 if (textEditor->findText(findString,flags))
1735 // Searching in Heading
1736 if (searching && findCurrent->getHeading().contains (findString,cs) )
1738 select(findCurrent);
1744 if (!nextBranch(findCurrent,findPrevious) )
1749 return getSelectedBranch();
1754 void VymModel::findReset()
1755 { // Necessary if text to find changes during a find process
1762 void VymModel::setScene (QGraphicsScene *s)
1767 void VymModel::setURL(const QString &url)
1769 TreeItem *selti=getSelectedItem();
1772 QString oldurl=selti->getURL();
1773 selti->setURL (url);
1776 QString ("setURL (\"%1\")").arg(oldurl),
1778 QString ("setURL (\"%1\")").arg(url),
1779 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1782 emitDataHasChanged (selti);
1783 emitShowSelection();
1787 QString VymModel::getURL()
1789 TreeItem *selti=getSelectedItem();
1791 return selti->getURL();
1796 QStringList VymModel::getURLs(bool ignoreScrolled)
1799 BranchItem *selbi=getSelectedBranch();
1800 BranchItem *cur=selbi;
1801 BranchItem *prev=NULL;
1804 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1805 urls.append( cur->getURL());
1806 cur=nextBranch (cur,prev,true,selbi);
1812 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1814 BranchItem *bi=getSelectedBranch();
1817 BranchObj *bo=(BranchObj*)(bi->getLMO());
1820 QString s=bo->getFrameTypeName();
1821 bo->setFrameType (t);
1822 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1823 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1825 bo->updateLinkGeometry();
1830 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1832 BranchItem *bi=getSelectedBranch();
1835 BranchObj *bo=(BranchObj*)(bi->getLMO());
1838 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1839 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1840 bo->setFrameType (s);
1842 bo->updateLinkGeometry();
1847 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1850 BranchItem *bi=getSelectedBranch();
1853 BranchObj *bo=(BranchObj*)(bi->getLMO());
1856 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1857 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1858 bo->setFramePenColor (c);
1863 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1865 BranchItem *bi=getSelectedBranch();
1868 BranchObj *bo=(BranchObj*)(bi->getLMO());
1871 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1872 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1873 bo->setFrameBrushColor (c);
1878 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1880 BranchItem *bi=getSelectedBranch();
1883 BranchObj *bo=(BranchObj*)(bi->getLMO());
1886 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1887 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1888 bo->setFramePadding (i);
1890 bo->updateLinkGeometry();
1895 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1897 BranchItem *bi=getSelectedBranch();
1900 BranchObj *bo=(BranchObj*)(bi->getLMO());
1903 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1904 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1905 bo->setFrameBorderWidth (i);
1907 bo->updateLinkGeometry();
1912 void VymModel::setIncludeImagesVer(bool b)
1914 BranchItem *bi=getSelectedBranch();
1917 QString u= b ? "false" : "true";
1918 QString r=!b ? "false" : "true";
1922 QString("setIncludeImagesVertically (%1)").arg(u),
1924 QString("setIncludeImagesVertically (%1)").arg(r),
1925 QString("Include images vertically in %1").arg(getObjectName(bi))
1927 bi->setIncludeImagesVer(b);
1928 emitDataHasChanged ( bi);
1933 void VymModel::setIncludeImagesHor(bool b)
1935 BranchItem *bi=getSelectedBranch();
1938 QString u= b ? "false" : "true";
1939 QString r=!b ? "false" : "true";
1943 QString("setIncludeImagesHorizontally (%1)").arg(u),
1945 QString("setIncludeImagesHorizontally (%1)").arg(r),
1946 QString("Include images horizontally in %1").arg(getObjectName(bi))
1948 bi->setIncludeImagesHor(b);
1949 emitDataHasChanged ( bi);
1954 void VymModel::setHideLinkUnselected (bool b)
1956 TreeItem *ti=getSelectedItem();
1957 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1959 QString u= b ? "false" : "true";
1960 QString r=!b ? "false" : "true";
1964 QString("setHideLinkUnselected (%1)").arg(u),
1966 QString("setHideLinkUnselected (%1)").arg(r),
1967 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1969 ((MapItem*)ti)->setHideLinkUnselected(b);
1973 void VymModel::setHideExport(bool b)
1975 TreeItem *ti=getSelectedItem();
1977 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1979 ti->setHideInExport (b);
1980 QString u= b ? "false" : "true";
1981 QString r=!b ? "false" : "true";
1985 QString ("setHideExport (%1)").arg(u),
1987 QString ("setHideExport (%1)").arg(r),
1988 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1990 emitDataHasChanged(ti);
1991 emitSelectionChanged();
1994 // emitSelectionChanged();
1995 // FIXME-3 VM needed? scene()->update();
1999 void VymModel::toggleHideExport()
2001 TreeItem *selti=getSelectedItem();
2003 setHideExport ( !selti->hideInExport() );
2006 void VymModel::addTimestamp() //FIXME-3 new function, localize
2008 BranchItem *selbi=addNewBranch();
2011 QDate today=QDate::currentDate();
2013 selbi->setHeading (QString ("%1-%2-%3")
2014 .arg(today.year(),4,10,c)
2015 .arg(today.month(),2,10,c)
2016 .arg(today.day(),2,10,c));
2017 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
2024 void VymModel::copy()
2026 TreeItem *selti=getSelectedItem();
2028 (selti->getType() == TreeItem::Branch ||
2029 selti->getType() == TreeItem::MapCenter ||
2030 selti->getType() == TreeItem::Image ))
2032 if (redosAvail == 0)
2035 QString s=getSelectString(selti);
2036 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
2037 curClipboard=curStep;
2040 // Copy also to global clipboard, because we are at last step in history
2041 QString bakMapName(QString("history-%1").arg(curStep));
2042 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2043 copyDir (bakMapDir,clipboardDir );
2045 clipboardEmpty=false;
2051 void VymModel::pasteNoSave(const int &n)
2053 bool old=blockSaveState;
2054 blockSaveState=true;
2055 bool zippedOrg=zipped;
2056 if (redosAvail > 0 || n!=0)
2058 // Use the "historical" buffer
2059 QString bakMapName(QString("history-%1").arg(n));
2060 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2061 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2063 // Use the global buffer
2064 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2069 void VymModel::paste()
2071 BranchItem *selbi=getSelectedBranch();
2074 saveStateChangingPart(
2077 QString ("paste (%1)").arg(curClipboard),
2078 QString("Paste to %1").arg( getObjectName(selbi))
2085 void VymModel::cut()
2087 TreeItem *selti=getSelectedItem();
2088 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2096 bool VymModel::moveUp(BranchItem *bi)
2098 if (bi && bi->canMoveUp())
2099 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2104 void VymModel::moveUp()
2106 BranchItem *selbi=getSelectedBranch();
2109 QString oldsel=getSelectString();
2112 getSelectString(),"moveDown ()",
2114 QString("Move up %1").arg(getObjectName(selbi)));
2118 bool VymModel::moveDown(BranchItem *bi)
2120 if (bi && bi->canMoveDown())
2121 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2126 void VymModel::moveDown()
2128 BranchItem *selbi=getSelectedBranch();
2131 QString oldsel=getSelectString();
2132 if ( moveDown(selbi))
2134 getSelectString(),"moveUp ()",
2135 oldsel,"moveDown ()",
2136 QString("Move down %1").arg(getObjectName(selbi)));
2140 void VymModel::detach()
2142 BranchItem *selbi=getSelectedBranch();
2143 if (selbi && selbi->depth()>0)
2145 // if no relPos have been set before, try to use current rel positions
2146 if (selbi->getLMO())
2147 for (int i=0; i<selbi->branchCount();++i)
2148 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2150 QString oldsel=getSelectString();
2153 BranchObj *bo=selbi->getBranchObj();
2154 if (bo) p=bo->getAbsPos();
2155 QString parsel=getSelectString(selbi->parent());
2156 if ( relinkBranch (selbi,rootItem,-1) )
2158 getSelectString (selbi),
2159 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2162 QString("Detach %1").arg(getObjectName(selbi))
2167 void VymModel::sortChildren(bool inverse)
2169 BranchItem* selbi=getSelectedBranch();
2172 if(selbi->branchCount()>1)
2176 saveStateChangingPart(
2177 selbi,selbi, "sortChildren ()",
2178 QString("Sort children of %1").arg(getObjectName(selbi)));
2180 selbi->sortChildren(inverse);
2182 emitShowSelection();
2187 BranchItem* VymModel::createMapCenter()
2189 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2193 BranchItem* VymModel::createBranch(BranchItem *dst)
2196 return addNewBranchInt (dst,-2);
2201 ImageItem* VymModel::createImage(BranchItem *dst)
2208 QList<QVariant> cData;
2209 cData << "new" << "undef";
2211 ImageItem *newii=new ImageItem(cData) ;
2212 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2214 emit (layoutAboutToBeChanged() );
2217 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2218 n=dst->getRowNumAppend(newii);
2219 beginInsertRows (parix,n,n);
2220 dst->appendChild (newii);
2223 emit (layoutChanged() );
2225 // save scroll state. If scrolled, automatically select
2226 // new branch in order to tmp unscroll parent...
2227 newii->createMapObj(mapScene);
2234 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2241 QList<QVariant> cData;
2242 cData << "new xLink"<<"undef";
2244 XLinkItem *newxli=new XLinkItem(cData) ;
2245 newxli->setBegin (bi);
2247 emit (layoutAboutToBeChanged() );
2250 n=bi->getRowNumAppend(newxli);
2251 beginInsertRows (parix,n,n);
2252 bi->appendChild (newxli);
2255 emit (layoutChanged() );
2257 // save scroll state. If scrolled, automatically select
2258 // new branch in order to tmp unscroll parent...
2261 newxli->createMapObj(mapScene);
2269 AttributeItem* VymModel::addAttribute()
2271 BranchItem *selbi=getSelectedBranch();
2274 QList<QVariant> cData;
2275 cData << "new attribute" << "undef";
2276 AttributeItem *a=new AttributeItem (cData);
2277 if (addAttribute (a)) return a;
2282 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2284 BranchItem *selbi=getSelectedBranch();
2287 emit (layoutAboutToBeChanged() );
2289 QModelIndex parix=index(selbi);
2290 int n=selbi->getRowNumAppend (ai);
2291 beginInsertRows (parix,n,n);
2292 selbi->appendChild (ai);
2295 emit (layoutChanged() );
2297 ai->createMapObj(mapScene); //FIXME-2 check that...
2304 BranchItem* VymModel::addMapCenter ()
2306 BranchItem *bi=addMapCenter (contextPos);
2308 emitShowSelection();
2313 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2314 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2320 BranchItem* VymModel::addMapCenter(QPointF absPos)
2321 // createMapCenter could then probably be merged with createBranch
2325 QModelIndex parix=index(rootItem);
2327 QList<QVariant> cData;
2328 cData << "VM:addMapCenter" << "undef";
2329 BranchItem *newbi=new BranchItem (cData,rootItem);
2330 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2331 int n=rootItem->getRowNumAppend (newbi);
2333 emit (layoutAboutToBeChanged() );
2334 beginInsertRows (parix,n,n);
2336 rootItem->appendChild (newbi);
2339 emit (layoutChanged() );
2342 newbi->setPositionMode (MapItem::Absolute);
2343 BranchObj *bo=newbi->createMapObj(mapScene);
2344 if (bo) bo->move (absPos);
2349 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2351 // Depending on pos:
2352 // -3 insert in children of parent above selection
2353 // -2 add branch to selection
2354 // -1 insert in children of parent below selection
2355 // 0..n insert in children of parent at pos
2358 QList<QVariant> cData;
2359 cData << "" << "undef";
2364 BranchItem *newbi=new BranchItem (cData);
2365 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2367 emit (layoutAboutToBeChanged() );
2373 n=parbi->getRowNumAppend (newbi);
2374 beginInsertRows (parix,n,n);
2375 parbi->appendChild (newbi);
2377 }else if (num==-1 || num==-3)
2379 // insert below selection
2380 parbi=(BranchItem*)dst->parent();
2383 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2384 beginInsertRows (parix,n,n);
2385 parbi->insertBranch(n,newbi);
2388 emit (layoutChanged() );
2390 // Set color of heading to that of parent
2391 newbi->setHeadingColor (parbi->getHeadingColor());
2393 // save scroll state. If scrolled, automatically select
2394 // new branch in order to tmp unscroll parent...
2395 newbi->createMapObj(mapScene);
2400 BranchItem* VymModel::addNewBranch(int pos)
2402 // Different meaning than num in addNewBranchInt!
2406 BranchItem *newbi=NULL;
2407 BranchItem *selbi=getSelectedBranch();
2411 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2413 newbi=addNewBranchInt (selbi,pos-2);
2421 QString ("addBranch (%1)").arg(pos),
2422 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2425 // emitSelectionChanged(); FIXME-3
2426 latestAddedItem=newbi;
2427 // In Network mode, the client needs to know where the new branch is,
2428 // so we have to pass on this information via saveState.
2429 // TODO: Get rid of this positioning workaround
2430 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2431 sendData ("selectLatestAdded ()");
2432 sendData (QString("move %1").arg(ps));
2441 BranchItem* VymModel::addNewBranchBefore()
2443 BranchItem *newbi=NULL;
2444 BranchItem *selbi=getSelectedBranch();
2445 if (selbi && selbi->getType()==TreeItem::Branch)
2446 // We accept no MapCenter here, so we _have_ a parent
2448 //QPointF p=bo->getRelPos();
2451 // add below selection
2452 newbi=addNewBranchInt (selbi,-1);
2456 //newbi->move2RelPos (p);
2458 // Move selection to new branch
2459 relinkBranch (selbi,newbi,0);
2461 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2462 QString ("Add branch before %1").arg(getObjectName(selbi)));
2464 // FIXME-3 needed? reposition();
2465 // emitSelectionChanged(); FIXME-3
2471 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2477 // Do we need to update frame type?
2478 bool keepFrame=false;
2481 emit (layoutAboutToBeChanged() );
2482 BranchItem *branchpi=(BranchItem*)branch->parent();
2483 // Remove at current position
2484 int n=branch->childNum();
2486 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2487 // error occured if relinking branch to empty mainbranch
2488 cout<<"VM::relinkBranch:\n";
2489 cout<<" b="<<branch->getHeadingStd()<<endl;
2490 cout<<" dst="<<dst->getHeadingStd()<<endl;
2491 cout<<" pos="<<pos<<endl;
2492 cout<<" n1="<<n<<endl;
2494 beginRemoveRows (index(branchpi),n,n);
2495 branchpi->removeChild (n);
2498 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2500 // Append as last branch to dst
2501 if (dst->branchCount()==0)
2504 n=dst->getFirstBranch()->childNumber();
2505 beginInsertRows (index(dst),n+pos,n+pos);
2506 dst->insertBranch (pos,branch);
2509 // Correct type if necessesary
2510 if (branch->getType()==TreeItem::MapCenter)
2511 branch->setType(TreeItem::Branch);
2513 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2514 branch->updateStyles(keepFrame);
2516 emit (layoutChanged() );
2517 reposition(); // both for moveUp/Down and relinking
2518 if (dst->isScrolled() )
2521 branch->updateVisibility();
2530 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2534 emit (layoutAboutToBeChanged() );
2536 BranchItem *pi=(BranchItem*)(image->parent());
2537 QString oldParString=getSelectString (pi);
2538 // Remove at current position
2539 int n=image->childNum();
2540 beginRemoveRows (index(pi),n,n);
2541 pi->removeChild (n);
2545 QModelIndex dstix=index(dst);
2546 n=dst->getRowNumAppend (image);
2547 beginInsertRows (dstix,n,n+1);
2548 dst->appendChild (image);
2551 // Set new parent also for lmo
2552 if (image->getLMO() && dst->getLMO() )
2553 image->getLMO()->setParObj (dst->getLMO() );
2555 emit (layoutChanged() );
2558 QString("relinkTo (\"%1\")").arg(oldParString),
2560 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2561 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2567 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2569 BranchItem *selbi=getSelectedBranch();
2574 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2576 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2579 if (pi->isScrolled() && pi->branchCount()==0)
2582 emitDataHasChanged(pi);
2585 emitShowSelection();
2589 TreeItem *ti=getSelectedItem();
2591 { // Delete other item
2592 TreeItem *pi=ti->parent();
2594 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2596 saveStateChangingPart(
2600 QString("Delete %1").arg(getObjectName(ti))
2604 emitDataHasChanged (pi);
2607 emitShowSelection();
2608 } else if (ti->getType()==TreeItem::XLink)
2610 //FIXME-2 savestate for deleting xlink missing
2613 qWarning ("VymmModel::deleteSelection() unknown type?!");
2617 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2620 BranchItem *selbi=getSelectedBranch();
2624 // Don't use this on mapcenter
2625 if (selbi->depth()<2) return;
2627 pi=(BranchItem*)(selbi->parent());
2628 // Check if we have children at all to keep
2629 if (selbi->branchCount()==0)
2636 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2637 saveStateChangingPart(
2640 "deleteKeepChildren ()",
2641 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2644 QString sel=getSelectString(selbi);
2646 int pos=selbi->num();
2647 BranchItem *bi=selbi->getFirstBranch();
2650 relinkBranch (bi,pi,pos);
2651 bi=selbi->getFirstBranch();
2657 BranchObj *bo=getSelectedBranchObj();
2660 bo->move2RelPos (p);
2666 void VymModel::deleteChildren()
2669 BranchItem *selbi=getSelectedBranch();
2672 saveStateChangingPart(
2675 "deleteChildren ()",
2676 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2678 emit (layoutAboutToBeChanged() );
2680 QModelIndex ix=index (selbi);
2681 int n=selbi->branchCount()-1;
2682 beginRemoveRows (ix,0,n);
2683 removeRows (0,n+1,ix);
2685 if (selbi->isScrolled()) selbi->unScroll();
2686 emit (layoutChanged() );
2691 TreeItem* VymModel::deleteItem (TreeItem *ti)
2695 TreeItem *pi=ti->parent();
2696 QModelIndex parentIndex=index(pi);
2698 emit (layoutAboutToBeChanged() );
2700 int n=ti->childNum();
2701 beginRemoveRows (parentIndex,n,n);
2702 removeRows (n,1,parentIndex);
2706 emit (layoutChanged() );
2707 if (pi->depth()>=0) return pi;
2712 void VymModel::clearItem (TreeItem *ti)
2716 QModelIndex parentIndex=index(ti);
2717 if (!parentIndex.isValid()) return;
2719 int n=ti->childCount();
2722 emit (layoutAboutToBeChanged() );
2724 beginRemoveRows (parentIndex,0,n-1);
2725 removeRows (0,n,parentIndex);
2729 emit (layoutChanged() );
2735 bool VymModel::scrollBranch(BranchItem *bi)
2739 if (bi->isScrolled()) return false;
2740 if (bi->branchCount()==0) return false;
2741 if (bi->depth()==0) return false;
2742 if (bi->toggleScroll())
2750 QString ("%1 ()").arg(u),
2752 QString ("%1 ()").arg(r),
2753 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2755 emitDataHasChanged(bi);
2756 emitSelectionChanged();
2757 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2764 bool VymModel::unscrollBranch(BranchItem *bi)
2768 if (!bi->isScrolled()) return false;
2769 if (bi->branchCount()==0) return false;
2770 if (bi->depth()==0) return false;
2771 if (bi->toggleScroll())
2779 QString ("%1 ()").arg(u),
2781 QString ("%1 ()").arg(r),
2782 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2784 emitDataHasChanged(bi);
2785 emitSelectionChanged();
2786 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2793 void VymModel::toggleScroll()
2795 BranchItem *bi=(BranchItem*)getSelectedBranch();
2796 if (bi && bi->isBranchLikeType() )
2798 if (bi->isScrolled())
2799 unscrollBranch (bi);
2803 // saveState & reposition are called in above functions
2806 void VymModel::unscrollChildren()
2808 BranchItem *selbi=getSelectedBranch();
2809 BranchItem *prev=NULL;
2810 BranchItem *cur=selbi;
2813 saveStateChangingPart(
2816 QString ("unscrollChildren ()"),
2817 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2821 if (cur->isScrolled())
2823 cur->toggleScroll();
2824 emitDataHasChanged (cur);
2826 cur=nextBranch (cur,prev,true,selbi);
2833 void VymModel::emitExpandAll()
2835 emit (expandAll() );
2838 void VymModel::emitExpandOneLevel()
2840 emit (expandOneLevel () );
2843 void VymModel::emitCollapseOneLevel()
2845 emit (collapseOneLevel () );
2848 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2850 BranchItem *bi=getSelectedBranch();
2854 if (bi->isActiveStandardFlag(name))
2866 QString("%1 (\"%2\")").arg(u).arg(name),
2868 QString("%1 (\"%2\")").arg(r).arg(name),
2869 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2870 bi->toggleStandardFlag (name, master);
2872 emitSelectionChanged();
2876 void VymModel::addFloatImage (const QPixmap &img)
2878 BranchItem *selbi=getSelectedBranch();
2881 ImageItem *ii=createImage (selbi);
2883 ii->setOriginalFilename("No original filename (image added by dropevent)");
2884 QString s=getSelectString(selbi);
2885 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2886 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2888 // FIXME-3 VM needed? scene()->update();
2893 void VymModel::colorBranch (QColor c)
2895 BranchItem *selbi=getSelectedBranch();
2900 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2902 QString ("colorBranch (\"%1\")").arg(c.name()),
2903 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2905 selbi->setHeadingColor(c); // color branch
2910 void VymModel::colorSubtree (QColor c)
2912 BranchItem *selbi=getSelectedBranch();
2915 saveStateChangingPart(
2918 QString ("colorSubtree (\"%1\")").arg(c.name()),
2919 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2921 BranchItem *prev=NULL;
2922 BranchItem *cur=selbi;
2925 cur->setHeadingColor(c); // color links, color children
2926 cur=nextBranch (cur,prev,true,selbi);
2932 QColor VymModel::getCurrentHeadingColor()
2934 BranchItem *selbi=getSelectedBranch();
2935 if (selbi) return selbi->getHeadingColor();
2937 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2943 void VymModel::editURL()
2945 TreeItem *selti=getSelectedItem();
2949 QString text = QInputDialog::getText(
2950 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2951 selti->getURL(), &ok, NULL);
2953 // user entered something and pressed OK
2958 void VymModel::editLocalURL()
2960 TreeItem *selti=getSelectedItem();
2963 QStringList filters;
2964 filters <<"All files (*)";
2965 filters << tr("Text","Filedialog") + " (*.txt)";
2966 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2967 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2968 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2969 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2970 fd->setFilters (filters);
2971 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2972 fd->setDirectory (lastFileDir);
2973 if (! selti->getVymLink().isEmpty() )
2974 fd->selectFile( selti->getURL() );
2977 if ( fd->exec() == QDialog::Accepted )
2979 lastFileDir=QDir (fd->directory().path());
2980 setURL (fd->selectedFile() );
2986 void VymModel::editHeading2URL()
2988 TreeItem *selti=getSelectedItem();
2990 setURL (selti->getHeading());
2993 void VymModel::editBugzilla2URL()
2995 TreeItem *selti=getSelectedItem();
2998 QString h=selti->getHeading();
2999 QRegExp rx("^(\\d+)");
3000 if (rx.indexIn(h) !=-1)
3001 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
3005 void VymModel::getBugzillaData()
3007 BranchItem *selbi=getSelectedBranch();
3010 QString url=selbi->getURL();
3013 QRegExp rx("(\\d+)");
3014 if (rx.indexIn(url) !=-1)
3016 QString bugID=rx.cap(1);
3017 qDebug()<< "VM::getBugzillaData bug="<<bugID;
3019 new BugAgent (selbi,bugID);
3025 void VymModel::editFATE2URL()
3027 TreeItem *selti=getSelectedItem();
3030 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3033 "setURL (\""+selti->getURL()+"\")",
3035 "setURL (\""+url+"\")",
3036 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3038 selti->setURL (url);
3039 // FIXME-4 updateActions();
3043 void VymModel::editVymLink()
3045 BranchItem *bi=getSelectedBranch();
3048 QStringList filters;
3049 filters <<"VYM map (*.vym)";
3050 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3051 fd->setFilters (filters);
3052 fd->setCaption(vymName+" - " +tr("Link to another map"));
3053 fd->setDirectory (lastFileDir);
3054 if (! bi->getVymLink().isEmpty() )
3055 fd->selectFile( bi->getVymLink() );
3059 if ( fd->exec() == QDialog::Accepted )
3061 lastFileDir=QDir (fd->directory().path());
3064 "setVymLink (\""+bi->getVymLink()+"\")",
3066 "setVymLink (\""+fd->selectedFile()+"\")",
3067 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3069 setVymLink (fd->selectedFile() );
3074 void VymModel::setVymLink (const QString &s)
3076 // Internal function, no saveState needed
3077 TreeItem *selti=getSelectedItem();
3080 selti->setVymLink(s);
3082 emitDataHasChanged (selti);
3083 emitShowSelection();
3087 void VymModel::deleteVymLink()
3089 BranchItem *bi=getSelectedBranch();
3094 "setVymLink (\""+bi->getVymLink()+"\")",
3096 "setVymLink (\"\")",
3097 QString("Unset vymlink of %1").arg(getObjectName(bi))
3099 bi->setVymLink ("" );
3105 QString VymModel::getVymLink()
3107 BranchItem *bi=getSelectedBranch();
3109 return bi->getVymLink();
3115 QStringList VymModel::getVymLinks()
3118 BranchItem *selbi=getSelectedBranch();
3119 BranchItem *cur=selbi;
3120 BranchItem *prev=NULL;
3123 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3124 cur=nextBranch (cur,prev,true,selbi);
3130 void VymModel::followXLink(int i)
3133 BranchItem *selbi=getSelectedBranch();
3136 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3137 if (selbi) select (selbi);
3141 void VymModel::editXLink(int i)
3144 BranchItem *selbi=getSelectedBranch();
3147 XLinkItem *xli=selbi->getXLinkNum(i);
3150 EditXLinkDialog dia;
3152 dia.setSelection(selbi);
3153 if (dia.exec() == QDialog::Accepted)
3155 if (dia.useSettingsGlobal() )
3157 setMapDefXLinkColor (xli->getColor() );
3158 setMapDefXLinkWidth (xli->getWidth() );
3160 if (dia.deleteXLink()) deleteItem (xli);
3170 //////////////////////////////////////////////
3172 //////////////////////////////////////////////
3174 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3176 TreeItem* selti=getSelectedItem();
3177 BranchItem *selbi=getSelectedBranch();
3182 QVariant returnValue="";
3184 // Split string s into command and parameters
3185 parser.parseAtom (atom);
3186 QString com=parser.getCommand();
3188 // External commands
3189 /////////////////////////////////////////////////////////////////////
3190 if (com=="addBranch")
3194 parser.setError (Aborted,"Nothing selected");
3195 } else if (! selbi )
3197 parser.setError (Aborted,"Type of selection is not a branch");
3202 if (parser.checkParCount(pl))
3204 if (parser.parCount()==0)
3208 n=parser.parInt (ok,0);
3209 if (ok ) addNewBranch (n);
3213 /////////////////////////////////////////////////////////////////////
3214 } else if (com=="addBranchBefore")
3218 parser.setError (Aborted,"Nothing selected");
3219 } else if (! selbi )
3221 parser.setError (Aborted,"Type of selection is not a branch");
3224 if (parser.parCount()==0)
3226 addNewBranchBefore ();
3229 /////////////////////////////////////////////////////////////////////
3230 } else if (com==QString("addMapCenter"))
3232 if (parser.checkParCount(2))
3234 x=parser.parDouble (ok,0);
3237 y=parser.parDouble (ok,1);
3238 if (ok) addMapCenter (QPointF(x,y));
3241 /////////////////////////////////////////////////////////////////////
3242 } else if (com==QString("addMapReplace"))
3246 parser.setError (Aborted,"Nothing selected");
3247 } else if (! selbi )
3249 parser.setError (Aborted,"Type of selection is not a branch");
3250 } else if (parser.checkParCount(1))
3252 //s=parser.parString (ok,0); // selection
3253 t=parser.parString (ok,0); // path to map
3254 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3255 addMapReplaceInt(getSelectString(selbi),t);
3257 /////////////////////////////////////////////////////////////////////
3258 } else if (com==QString("addMapInsert"))
3260 if (parser.parCount()==2)
3265 parser.setError (Aborted,"Nothing selected");
3266 } else if (! selbi )
3268 parser.setError (Aborted,"Type of selection is not a branch");
3271 t=parser.parString (ok,0); // path to map
3272 n=parser.parInt(ok,1); // position
3273 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3274 addMapInsertInt(t,n);
3276 } else if (parser.parCount()==1)
3278 t=parser.parString (ok,0); // path to map
3279 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3282 parser.setError (Aborted,"Wrong number of parameters");
3283 /////////////////////////////////////////////////////////////////////
3284 } else if (com==QString("addXLink"))
3286 if (parser.parCount()>1)
3288 s=parser.parString (ok,0); // begin
3289 t=parser.parString (ok,1); // end
3290 BranchItem *begin=(BranchItem*)findBySelectString(s);
3291 BranchItem *end=(BranchItem*)findBySelectString(t);
3294 if (begin->isBranchLikeType() && end->isBranchLikeType())
3296 XLinkItem *xl=createXLink (begin,true);
3302 parser.setError (Aborted,"Failed to create xLink");
3305 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3308 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3310 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3311 /////////////////////////////////////////////////////////////////////
3312 } else if (com=="clearFlags")
3316 parser.setError (Aborted,"Nothing selected");
3317 } else if (! selbi )
3319 parser.setError (Aborted,"Type of selection is not a branch");
3320 } else if (parser.checkParCount(0))
3322 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3324 /////////////////////////////////////////////////////////////////////
3325 } else if (com=="colorBranch")
3329 parser.setError (Aborted,"Nothing selected");
3330 } else if (! selbi )
3332 parser.setError (Aborted,"Type of selection is not a branch");
3333 } else if (parser.checkParCount(1))
3335 QColor c=parser.parColor (ok,0);
3336 if (ok) colorBranch (c);
3338 /////////////////////////////////////////////////////////////////////
3339 } else if (com=="colorSubtree")
3343 parser.setError (Aborted,"Nothing selected");
3344 } else if (! selbi )
3346 parser.setError (Aborted,"Type of selection is not a branch");
3347 } else if (parser.checkParCount(1))
3349 QColor c=parser.parColor (ok,0);
3350 if (ok) colorSubtree (c);
3352 /////////////////////////////////////////////////////////////////////
3353 } else if (com=="copy")
3357 parser.setError (Aborted,"Nothing selected");
3358 } else if ( selectionType()!=TreeItem::Branch &&
3359 selectionType()!=TreeItem::MapCenter &&
3360 selectionType()!=TreeItem::Image )
3362 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3363 } else if (parser.checkParCount(0))
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="cut")
3372 parser.setError (Aborted,"Nothing selected");
3373 } else if ( selectionType()!=TreeItem::Branch &&
3374 selectionType()!=TreeItem::MapCenter &&
3375 selectionType()!=TreeItem::Image )
3377 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3378 } else if (parser.checkParCount(0))
3382 /////////////////////////////////////////////////////////////////////
3383 } else if (com=="delete")
3387 parser.setError (Aborted,"Nothing selected");
3389 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3391 parser.setError (Aborted,"Type of selection is wrong.");
3394 else if (parser.checkParCount(0))
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="deleteKeepChildren")
3403 parser.setError (Aborted,"Nothing selected");
3404 } else if (! selbi )
3406 parser.setError (Aborted,"Type of selection is not a branch");
3407 } else if (parser.checkParCount(0))
3409 deleteKeepChildren();
3411 /////////////////////////////////////////////////////////////////////
3412 } else if (com=="deleteChildren")
3416 parser.setError (Aborted,"Nothing selected");
3419 parser.setError (Aborted,"Type of selection is not a branch");
3420 } else if (parser.checkParCount(0))
3424 /////////////////////////////////////////////////////////////////////
3425 } else if (com=="exportAO")
3429 if (parser.parCount()>=1)
3430 // Hey, we even have a filename
3431 fname=parser.parString(ok,0);
3434 parser.setError (Aborted,"Could not read filename");
3437 exportAO (fname,false);
3439 /////////////////////////////////////////////////////////////////////
3440 } else if (com=="exportASCII")
3444 if (parser.parCount()>=1)
3445 // Hey, we even have a filename
3446 fname=parser.parString(ok,0);
3449 parser.setError (Aborted,"Could not read filename");
3452 exportASCII (fname,false);
3454 /////////////////////////////////////////////////////////////////////
3455 } else if (com=="exportImage")
3459 if (parser.parCount()>=2)
3460 // Hey, we even have a filename
3461 fname=parser.parString(ok,0);
3464 parser.setError (Aborted,"Could not read filename");
3467 QString format="PNG";
3468 if (parser.parCount()>=2)
3470 format=parser.parString(ok,1);
3472 exportImage (fname,false,format);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="exportXML")
3479 if (parser.parCount()>=2)
3480 // Hey, we even have a filename
3481 fname=parser.parString(ok,1);
3484 parser.setError (Aborted,"Could not read filename");
3487 exportXML (fname,false);
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="getHeading")
3494 parser.setError (Aborted,"Nothing selected");
3495 } else if (parser.checkParCount(0))
3496 returnValue=selti->getHeading();
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="importDir")
3502 parser.setError (Aborted,"Nothing selected");
3503 } else if (! selbi )
3505 parser.setError (Aborted,"Type of selection is not a branch");
3506 } else if (parser.checkParCount(1))
3508 s=parser.parString(ok,0);
3509 if (ok) importDirInt(s);
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="relinkTo")
3516 parser.setError (Aborted,"Nothing selected");
3519 if (parser.checkParCount(4))
3521 // 0 selectstring of parent
3522 // 1 num in parent (for branches)
3523 // 2,3 x,y of mainbranch or mapcenter
3524 s=parser.parString(ok,0);
3525 TreeItem *dst=findBySelectString (s);
3528 if (dst->getType()==TreeItem::Branch)
3530 // Get number in parent
3531 n=parser.parInt (ok,1);
3534 relinkBranch (selbi,(BranchItem*)dst,n);
3535 emitSelectionChanged();
3537 } else if (dst->getType()==TreeItem::MapCenter)
3539 relinkBranch (selbi,(BranchItem*)dst);
3540 // Get coordinates of mainbranch
3541 x=parser.parDouble(ok,2);
3544 y=parser.parDouble(ok,3);
3547 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3548 emitSelectionChanged();
3554 } else if ( selti->getType() == TreeItem::Image)
3556 if (parser.checkParCount(1))
3558 // 0 selectstring of parent
3559 s=parser.parString(ok,0);
3560 TreeItem *dst=findBySelectString (s);
3563 if (dst->isBranchLikeType())
3564 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3566 parser.setError (Aborted,"Destination is not a branch");
3569 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3570 /////////////////////////////////////////////////////////////////////
3571 } else if (com=="loadImage")
3575 parser.setError (Aborted,"Nothing selected");
3576 } else if (! selbi )
3578 parser.setError (Aborted,"Type of selection is not a branch");
3579 } else if (parser.checkParCount(1))
3581 s=parser.parString(ok,0);
3582 if (ok) loadFloatImageInt (selbi,s);
3584 /////////////////////////////////////////////////////////////////////
3585 } else if (com=="loadNote")
3589 parser.setError (Aborted,"Nothing selected");
3590 } else if (! selbi )
3592 parser.setError (Aborted,"Type of selection is not a branch");
3593 } else if (parser.checkParCount(1))
3595 s=parser.parString(ok,0);
3596 if (ok) loadNote (s);
3598 /////////////////////////////////////////////////////////////////////
3599 } else if (com=="moveUp")
3603 parser.setError (Aborted,"Nothing selected");
3604 } else if (! selbi )
3606 parser.setError (Aborted,"Type of selection is not a branch");
3607 } else if (parser.checkParCount(0))
3611 /////////////////////////////////////////////////////////////////////
3612 } else if (com=="moveDown")
3616 parser.setError (Aborted,"Nothing selected");
3617 } else if (! selbi )
3619 parser.setError (Aborted,"Type of selection is not a branch");
3620 } else if (parser.checkParCount(0))
3624 /////////////////////////////////////////////////////////////////////
3625 } else if (com=="move")
3629 parser.setError (Aborted,"Nothing selected");
3630 } else if ( selectionType()!=TreeItem::Branch &&
3631 selectionType()!=TreeItem::MapCenter &&
3632 selectionType()!=TreeItem::Image )
3634 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3635 } else if (parser.checkParCount(2))
3637 x=parser.parDouble (ok,0);
3640 y=parser.parDouble (ok,1);
3644 /////////////////////////////////////////////////////////////////////
3645 } else if (com=="moveRel")
3649 parser.setError (Aborted,"Nothing selected");
3650 } else if ( selectionType()!=TreeItem::Branch &&
3651 selectionType()!=TreeItem::MapCenter &&
3652 selectionType()!=TreeItem::Image )
3654 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3655 } else if (parser.checkParCount(2))
3657 x=parser.parDouble (ok,0);
3660 y=parser.parDouble (ok,1);
3661 if (ok) moveRel (x,y);
3664 /////////////////////////////////////////////////////////////////////
3665 } else if (com=="nop")
3667 /////////////////////////////////////////////////////////////////////
3668 } else if (com=="paste")
3672 parser.setError (Aborted,"Nothing selected");
3673 } else if (! selbi )
3675 parser.setError (Aborted,"Type of selection is not a branch");
3676 } else if (parser.checkParCount(1))
3678 n=parser.parInt (ok,0);
3679 if (ok) pasteNoSave(n);
3681 /////////////////////////////////////////////////////////////////////
3682 } else if (com=="qa")
3686 parser.setError (Aborted,"Nothing selected");
3687 } else if (! selbi )
3689 parser.setError (Aborted,"Type of selection is not a branch");
3690 } else if (parser.checkParCount(4))
3693 c=parser.parString (ok,0);
3696 parser.setError (Aborted,"No comment given");
3699 s=parser.parString (ok,1);
3702 parser.setError (Aborted,"First parameter is not a string");
3705 t=parser.parString (ok,2);
3708 parser.setError (Aborted,"Condition is not a string");
3711 u=parser.parString (ok,3);
3714 parser.setError (Aborted,"Third parameter is not a string");
3719 parser.setError (Aborted,"Unknown type: "+s);
3724 parser.setError (Aborted,"Unknown operator: "+t);
3729 parser.setError (Aborted,"Type of selection is not a branch");
3732 if (selbi->getHeading() == u)
3734 cout << "PASSED: " << qPrintable (c) << endl;
3737 cout << "FAILED: " << qPrintable (c) << endl;
3747 /////////////////////////////////////////////////////////////////////
3748 } else if (com=="saveImage")
3750 ImageItem *ii=getSelectedImage();
3753 parser.setError (Aborted,"No image selected");
3754 } else if (parser.checkParCount(2))
3756 s=parser.parString(ok,0);
3759 t=parser.parString(ok,1);
3760 if (ok) saveFloatImageInt (ii,t,s);
3763 /////////////////////////////////////////////////////////////////////
3764 } else if (com=="saveNote")
3768 parser.setError (Aborted,"Nothing selected");
3769 } else if (! selbi )
3771 parser.setError (Aborted,"Type of selection is not a branch");
3772 } else if (parser.checkParCount(1))
3774 s=parser.parString(ok,0);
3775 if (ok) saveNote (s);
3777 /////////////////////////////////////////////////////////////////////
3778 } else if (com=="scroll")
3782 parser.setError (Aborted,"Nothing selected");
3783 } else if (! selbi )
3785 parser.setError (Aborted,"Type of selection is not a branch");
3786 } else if (parser.checkParCount(0))
3788 if (!scrollBranch (selbi))
3789 parser.setError (Aborted,"Could not scroll branch");
3791 /////////////////////////////////////////////////////////////////////
3792 } else if (com=="select")
3794 if (parser.checkParCount(1))
3796 s=parser.parString(ok,0);
3799 /////////////////////////////////////////////////////////////////////
3800 } else if (com=="selectLastBranch")
3804 parser.setError (Aborted,"Nothing selected");
3805 } else if (! selbi )
3807 parser.setError (Aborted,"Type of selection is not a branch");
3808 } else if (parser.checkParCount(0))
3810 BranchItem *bi=selbi->getLastBranch();
3812 parser.setError (Aborted,"Could not select last branch");
3813 select (bi); // FIXME-3 was selectInt
3816 /////////////////////////////////////////////////////////////////////
3817 } else /* FIXME-2 if (com=="selectLastImage")
3821 parser.setError (Aborted,"Nothing selected");
3822 } else if (! selbi )
3824 parser.setError (Aborted,"Type of selection is not a branch");
3825 } else if (parser.checkParCount(0))
3827 FloatImageObj *fio=selb->getLastFloatImage();
3829 parser.setError (Aborted,"Could not select last image");
3830 select (fio); // FIXME-3 was selectInt
3833 /////////////////////////////////////////////////////////////////////
3834 } else */ if (com=="selectLatestAdded")
3836 if (!latestAddedItem)
3838 parser.setError (Aborted,"No latest added object");
3841 if (!select (latestAddedItem))
3842 parser.setError (Aborted,"Could not select latest added object ");
3844 /////////////////////////////////////////////////////////////////////
3845 } else if (com=="setFlag")
3849 parser.setError (Aborted,"Nothing selected");
3850 } else if (! selbi )
3852 parser.setError (Aborted,"Type of selection is not a branch");
3853 } else if (parser.checkParCount(1))
3855 s=parser.parString(ok,0);
3857 selbi->activateStandardFlag(s);
3859 /////////////////////////////////////////////////////////////////////
3860 } else if (com=="setFrameType")
3862 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3864 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3866 else if (parser.checkParCount(1))
3868 s=parser.parString(ok,0);
3869 if (ok) setFrameType (s);
3871 /////////////////////////////////////////////////////////////////////
3872 } else if (com=="setFramePenColor")
3874 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3876 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3878 else if (parser.checkParCount(1))
3880 QColor c=parser.parColor(ok,0);
3881 if (ok) setFramePenColor (c);
3883 /////////////////////////////////////////////////////////////////////
3884 } else if (com=="setFrameBrushColor")
3886 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3888 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3890 else if (parser.checkParCount(1))
3892 QColor c=parser.parColor(ok,0);
3893 if (ok) setFrameBrushColor (c);
3895 /////////////////////////////////////////////////////////////////////
3896 } else if (com=="setFramePadding")
3898 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3900 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3902 else if (parser.checkParCount(1))
3904 n=parser.parInt(ok,0);
3905 if (ok) setFramePadding(n);
3907 /////////////////////////////////////////////////////////////////////
3908 } else if (com=="setFrameBorderWidth")
3910 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3912 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3914 else if (parser.checkParCount(1))
3916 n=parser.parInt(ok,0);
3917 if (ok) setFrameBorderWidth (n);
3919 /////////////////////////////////////////////////////////////////////
3920 /* FIXME-2 else if (com=="setFrameType")
3924 parser.setError (Aborted,"Nothing selected");
3927 parser.setError (Aborted,"Type of selection is not a branch");
3928 } else if (parser.checkParCount(1))
3930 s=parser.parString(ok,0);
3934 /////////////////////////////////////////////////////////////////////
3936 /////////////////////////////////////////////////////////////////////
3937 } else if (com=="setHeading")
3941 parser.setError (Aborted,"Nothing selected");
3942 } else if (! selbi )
3944 parser.setError (Aborted,"Type of selection is not a branch");
3945 } else if (parser.checkParCount(1))
3947 s=parser.parString (ok,0);
3951 /////////////////////////////////////////////////////////////////////
3952 } else if (com=="setHideExport")
3956 parser.setError (Aborted,"Nothing selected");
3957 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3959 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3960 } else if (parser.checkParCount(1))
3962 b=parser.parBool(ok,0);
3963 if (ok) setHideExport (b);
3965 /////////////////////////////////////////////////////////////////////
3966 } else if (com=="setIncludeImagesHorizontally")
3970 parser.setError (Aborted,"Nothing selected");
3973 parser.setError (Aborted,"Type of selection is not a branch");
3974 } else if (parser.checkParCount(1))
3976 b=parser.parBool(ok,0);
3977 if (ok) setIncludeImagesHor(b);
3979 /////////////////////////////////////////////////////////////////////
3980 } else if (com=="setIncludeImagesVertically")
3984 parser.setError (Aborted,"Nothing selected");
3987 parser.setError (Aborted,"Type of selection is not a branch");
3988 } else if (parser.checkParCount(1))
3990 b=parser.parBool(ok,0);
3991 if (ok) setIncludeImagesVer(b);
3993 /////////////////////////////////////////////////////////////////////
3994 } else if (com=="setHideLinkUnselected")
3998 parser.setError (Aborted,"Nothing selected");
3999 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
4001 parser.setError (Aborted,"Type of selection does not allow hiding the link");
4002 } else if (parser.checkParCount(1))
4004 b=parser.parBool(ok,0);
4005 if (ok) setHideLinkUnselected(b);
4007 /////////////////////////////////////////////////////////////////////
4008 } else if (com=="setMapAuthor")
4010 if (parser.checkParCount(1))
4012 s=parser.parString(ok,0);
4013 if (ok) setAuthor (s);
4015 /////////////////////////////////////////////////////////////////////
4016 } else if (com=="setMapComment")
4018 if (parser.checkParCount(1))
4020 s=parser.parString(ok,0);
4021 if (ok) setComment(s);
4023 /////////////////////////////////////////////////////////////////////
4024 } else if (com=="setMapBackgroundColor")
4028 parser.setError (Aborted,"Nothing selected");
4029 } else if (! selbi )
4031 parser.setError (Aborted,"Type of selection is not a branch");
4032 } else if (parser.checkParCount(1))
4034 QColor c=parser.parColor (ok,0);
4035 if (ok) setMapBackgroundColor (c);
4037 /////////////////////////////////////////////////////////////////////
4038 } else if (com=="setMapDefLinkColor")
4042 parser.setError (Aborted,"Nothing selected");
4043 } else if (! selbi )
4045 parser.setError (Aborted,"Type of selection is not a branch");
4046 } else if (parser.checkParCount(1))
4048 QColor c=parser.parColor (ok,0);
4049 if (ok) setMapDefLinkColor (c);
4051 /////////////////////////////////////////////////////////////////////
4052 } else if (com=="setMapLinkStyle")
4054 if (parser.checkParCount(1))
4056 s=parser.parString (ok,0);
4057 if (ok) setMapLinkStyle(s);
4059 /////////////////////////////////////////////////////////////////////
4060 } else if (com=="setNote")
4064 parser.setError (Aborted,"Nothing selected");
4065 } else if (! selbi )
4067 parser.setError (Aborted,"Type of selection is not a branch");
4068 } else if (parser.checkParCount(1))
4070 s=parser.parString (ok,0);
4074 /////////////////////////////////////////////////////////////////////
4075 } else if (com=="setSelectionColor")
4077 if (parser.checkParCount(1))
4079 QColor c=parser.parColor (ok,0);
4080 if (ok) setSelectionColorInt (c);
4082 /////////////////////////////////////////////////////////////////////
4083 } else if (com=="setURL")
4087 parser.setError (Aborted,"Nothing selected");
4088 } else if (! selbi )
4090 parser.setError (Aborted,"Type of selection is not a branch");
4091 } else if (parser.checkParCount(1))
4093 s=parser.parString (ok,0);
4096 /////////////////////////////////////////////////////////////////////
4097 } else if (com=="setVymLink")
4101 parser.setError (Aborted,"Nothing selected");
4102 } else if (! selbi )
4104 parser.setError (Aborted,"Type of selection is not a branch");
4105 } else if (parser.checkParCount(1))
4107 s=parser.parString (ok,0);
4108 if (ok) setVymLink(s);
4110 } else if (com=="sortChildren")
4114 parser.setError (Aborted,"Nothing selected");
4115 } else if (! selbi )
4117 parser.setError (Aborted,"Type of selection is not a branch");
4118 } else if (parser.checkParCount(0))
4121 } else if (parser.checkParCount(1))
4123 b=parser.parBool(ok,0);
4124 if (ok) sortChildren(b);
4126 /////////////////////////////////////////////////////////////////////
4127 } else if (com=="toggleFlag")
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(1))
4137 s=parser.parString(ok,0);
4139 selbi->toggleStandardFlag(s);
4141 /////////////////////////////////////////////////////////////////////
4142 } else if (com=="unscroll")
4146 parser.setError (Aborted,"Nothing selected");
4147 } else if (! selbi )
4149 parser.setError (Aborted,"Type of selection is not a branch");
4150 } else if (parser.checkParCount(0))
4152 if (!unscrollBranch (selbi))
4153 parser.setError (Aborted,"Could not unscroll branch");
4155 /////////////////////////////////////////////////////////////////////
4156 } else if (com=="unscrollChildren")
4160 parser.setError (Aborted,"Nothing selected");
4161 } else if (! selbi )
4163 parser.setError (Aborted,"Type of selection is not a branch");
4164 } else if (parser.checkParCount(0))
4166 unscrollChildren ();
4168 /////////////////////////////////////////////////////////////////////
4169 } else if (com=="unsetFlag")
4173 parser.setError (Aborted,"Nothing selected");
4174 } else if (! selbi )
4176 parser.setError (Aborted,"Type of selection is not a branch");
4177 } else if (parser.checkParCount(1))
4179 s=parser.parString(ok,0);
4181 selbi->deactivateStandardFlag(s);
4184 parser.setError (Aborted,"Unknown command");
4187 if (parser.errorLevel()==NoError)
4195 // TODO Error handling
4196 qWarning("VymModel::parseAtom: Error!");
4198 qWarning(parser.errorMessage());
4200 errorMsg=parser.errorMessage();
4201 returnValue=errorMsg;
4206 QVariant VymModel::runScript (const QString &script)
4208 parser.setScript (script);
4213 while (parser.next() && noErr)
4215 r=parseAtom(parser.getAtom(),noErr,errMsg);
4216 if (!noErr) //FIXME-3 need dialog box here
4217 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4222 void VymModel::setExportMode (bool b)
4224 // should be called before and after exports
4225 // depending on the settings
4226 if (b && settings.value("/export/useHideExport","true")=="true")
4227 setHideTmpMode (TreeItem::HideExport);
4229 setHideTmpMode (TreeItem::HideNone);
4232 void VymModel::exportImage(QString fname, bool askName, QString format)
4236 fname=getMapName()+".png";
4243 QFileDialog *fd=new QFileDialog (NULL);
4244 fd->setCaption (tr("Export map as image"));
4245 fd->setDirectory (lastImageDir);
4246 fd->setFileMode(QFileDialog::AnyFile);
4247 fd->setFilters (imageIO.getFilters() );
4250 fl=fd->selectedFiles();
4252 format=imageIO.getType(fd->selectedFilter());
4256 setExportMode (true);
4257 mapEditor->getScene()->update(); // FIXME-3 check this...
4258 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4259 img.save(fname, format);
4260 setExportMode (false);
4264 void VymModel::exportXML(QString dir, bool askForName)
4268 dir=browseDirectory(NULL,tr("Export XML to directory"));
4269 if (dir =="" && !reallyWriteDirectory(dir) )
4273 // Hide stuff during export, if settings want this
4274 setExportMode (true);
4276 // Create subdirectories
4279 // write to directory //FIXME-4 check totalBBox here...
4280 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4283 file.setName ( dir + "/"+mapName+".xml");
4284 if ( !file.open( QIODevice::WriteOnly ) )
4286 // This should neverever happen
4287 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4291 // Write it finally, and write in UTF8, no matter what
4292 QTextStream ts( &file );
4293 ts.setEncoding (QTextStream::UnicodeUTF8);
4297 // Now write image, too
4298 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4300 setExportMode (false);
4303 void VymModel::exportAO (QString fname,bool askName)
4308 ex.setFile (mapName+".txt");
4314 //ex.addFilter ("TXT (*.txt)");
4315 ex.setDir(lastImageDir);
4316 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4321 setExportMode(true);
4323 setExportMode(false);
4327 void VymModel::exportASCII(QString fname,bool askName)
4332 ex.setFile (mapName+".txt");
4338 //ex.addFilter ("TXT (*.txt)");
4339 ex.setDir(lastImageDir);
4340 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4345 setExportMode(true);
4347 setExportMode(false);
4351 void VymModel::exportHTML (const QString &dir, bool useDialog)
4353 ExportHTML ex (this);
4355 ex.doExport(useDialog);
4358 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4363 if (ex.setConfigFile(cf))
4365 setExportMode (true);
4366 ex.exportPresentation();
4367 setExportMode (false);
4374 //////////////////////////////////////////////
4376 //////////////////////////////////////////////
4378 void VymModel::registerEditor(QWidget *me)
4380 mapEditor=(MapEditor*)me;
4383 void VymModel::unregisterEditor(QWidget *)
4388 void VymModel::setMapZoomFactor (const double &d)
4393 void VymModel::setContextPos(QPointF p)
4398 void VymModel::unsetContextPos()
4400 contextPos=QPointF();
4403 void VymModel::updateNoteFlag()
4405 TreeItem *selti=getSelectedItem();
4414 if (textEditor->isEmpty())
4417 selti->setNote (textEditor->getText());
4418 emitDataHasChanged(selti);
4422 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4424 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4425 if (blockReposition) return;
4427 for (int i=0;i<rootItem->branchCount(); i++)
4428 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4429 //emitSelectionChanged();
4433 void VymModel::setMapLinkStyle (const QString & s)
4438 case LinkableMapObj::Line :
4441 case LinkableMapObj::Parabel:
4442 snow="StyleParabel";
4444 case LinkableMapObj::PolyLine:
4445 snow="StylePolyLine";
4447 case LinkableMapObj::PolyParabel:
4448 snow="StylePolyParabel";
4451 snow="UndefinedStyle";
4456 QString("setMapLinkStyle (\"%1\")").arg(s),
4457 QString("setMapLinkStyle (\"%1\")").arg(snow),
4458 QString("Set map link style (\"%1\")").arg(s)
4462 linkstyle=LinkableMapObj::Line;
4463 else if (s=="StyleParabel")
4464 linkstyle=LinkableMapObj::Parabel;
4465 else if (s=="StylePolyLine")
4466 linkstyle=LinkableMapObj::PolyLine;
4467 else if (s=="StylePolyParabel")
4468 linkstyle=LinkableMapObj::PolyParabel;
4470 linkstyle=LinkableMapObj::UndefinedStyle;
4472 BranchItem *cur=NULL;
4473 BranchItem *prev=NULL;
4475 nextBranch (cur,prev);
4478 bo=(BranchObj*)(cur->getLMO() );
4479 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4480 cur=nextBranch(cur,prev);
4485 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4490 uint VymModel::getID()
4495 void VymModel::setMapDefLinkColor(QColor col)
4497 if ( !col.isValid() ) return;
4499 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4500 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4501 QString("Set map link color to %1").arg(col.name())
4505 BranchItem *cur=NULL;
4506 BranchItem *prev=NULL;
4508 cur=nextBranch(cur,prev);
4511 bo=(BranchObj*)(cur->getLMO() );
4513 nextBranch(cur,prev);
4518 void VymModel::setMapLinkColorHintInt()
4520 // called from setMapLinkColorHint(lch) or at end of parse
4521 BranchItem *cur=NULL;
4522 BranchItem *prev=NULL;
4524 cur=nextBranch(cur,prev);
4527 bo=(BranchObj*)(cur->getLMO() );
4529 cur=nextBranch(cur,prev);
4533 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4536 setMapLinkColorHintInt();
4539 void VymModel::toggleMapLinkColorHint()
4541 if (linkcolorhint==LinkableMapObj::HeadingColor)
4542 linkcolorhint=LinkableMapObj::DefaultColor;
4544 linkcolorhint=LinkableMapObj::HeadingColor;
4545 BranchItem *cur=NULL;
4546 BranchItem *prev=NULL;
4548 cur=nextBranch(cur,prev);
4551 bo=(BranchObj*)(cur->getLMO() );
4553 nextBranch(cur,prev);
4557 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4559 Q3FileDialog *fd=new Q3FileDialog( NULL);
4560 fd->setMode (Q3FileDialog::ExistingFile);
4561 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4562 ImagePreview *p =new ImagePreview (fd);
4563 fd->setContentsPreviewEnabled( TRUE );
4564 fd->setContentsPreview( p, p );
4565 fd->setPreviewMode( Q3FileDialog::Contents );
4566 fd->setCaption(vymName+" - " +tr("Load background image"));
4567 fd->setDir (lastImageDir);
4570 if ( fd->exec() == QDialog::Accepted )
4572 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4573 lastImageDir=QDir (fd->dirPath());
4574 setMapBackgroundImage (fd->selectedFile());
4578 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4580 QColor oldcol=mapScene->backgroundBrush().color();
4584 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4586 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4587 QString("Set background color of map to %1").arg(col.name()));
4590 brush.setTextureImage (QPixmap (fn));
4591 mapScene->setBackgroundBrush(brush);
4594 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4596 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4597 if ( !col.isValid() ) return;
4598 setMapBackgroundColor( col );
4602 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4604 QColor oldcol=mapScene->backgroundBrush().color();
4606 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4607 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4608 QString("Set background color of map to %1").arg(col.name()));
4609 mapScene->setBackgroundBrush(col);
4612 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4614 return mapScene->backgroundBrush().color();
4618 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4620 return linkcolorhint;
4623 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4625 return defLinkColor;
4628 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4633 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4635 return defXLinkColor;
4638 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4643 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4645 return defXLinkWidth;
4648 void VymModel::move(const double &x, const double &y)
4651 MapItem *seli = (MapItem*)getSelectedItem();
4652 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4654 LinkableMapObj *lmo=seli->getLMO();
4657 QPointF ap(lmo->getAbsPos());
4661 QString ps=qpointFToString(ap);
4662 QString s=getSelectString(seli);
4665 s, "move "+qpointFToString(to),
4666 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4669 emitSelectionChanged();
4675 void VymModel::moveRel (const double &x, const double &y)
4678 MapItem *seli = (MapItem*)getSelectedItem();
4679 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4681 LinkableMapObj *lmo=seli->getLMO();
4684 QPointF rp(lmo->getRelPos());
4688 QString ps=qpointFToString (lmo->getRelPos());
4689 QString s=getSelectString(seli);
4692 s, "moveRel "+qpointFToString(to),
4693 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4694 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4696 lmo->updateLinkGeometry();
4697 emitSelectionChanged();
4704 void VymModel::animate()
4706 animationTimer->stop();
4709 while (i<animObjList.size() )
4711 bo=(BranchObj*)animObjList.at(i);
4716 animObjList.removeAt(i);
4723 QItemSelection sel=selModel->selection();
4724 emit (selectionChanged(sel,sel));
4727 if (!animObjList.isEmpty()) animationTimer->start();
4731 void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
4735 if (bo->getUseRelPos())
4736 startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
4738 startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
4741 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4743 if (start==dest) return;
4744 if (bo && bo->getTreeItem()->depth()>=0)
4747 ap.setStart (start);
4749 ap.setTicks (animationTicks);
4750 ap.setAnimated (true);
4751 bo->setAnimation (ap);
4752 if (!animObjList.contains(bo))
4753 animObjList.append( bo );
4754 animationTimer->setSingleShot (true);
4755 animationTimer->start(animationInterval);
4759 void VymModel::stopAnimation (MapObj *mo)
4761 int i=animObjList.indexOf(mo);
4763 animObjList.removeAt (i);
4766 void VymModel::sendSelection()
4768 if (netstate!=Server) return;
4769 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4772 void VymModel::newServer()
4776 tcpServer = new QTcpServer(this);
4777 if (!tcpServer->listen(QHostAddress::Any,port)) {
4778 QMessageBox::critical(NULL, "vym server",
4779 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4780 //FIXME-3 needed? we are no widget any longer... close();
4783 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4785 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4788 void VymModel::connectToServer()
4791 server="salam.suse.de";
4793 clientSocket = new QTcpSocket (this);
4794 clientSocket->abort();
4795 clientSocket->connectToHost(server ,port);
4796 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4797 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4798 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4800 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4805 void VymModel::newClient()
4807 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4808 connect(newClient, SIGNAL(disconnected()),
4809 newClient, SLOT(deleteLater()));
4811 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4813 clientList.append (newClient);
4817 void VymModel::sendData(const QString &s)
4819 if (clientList.size()==0) return;
4821 // Create bytearray to send
4823 QDataStream out(&block, QIODevice::WriteOnly);
4824 out.setVersion(QDataStream::Qt_4_0);
4826 // Reserve some space for blocksize
4829 // Write sendCounter
4830 out << sendCounter++;
4835 // Go back and write blocksize so far
4836 out.device()->seek(0);
4837 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4841 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4843 for (int i=0; i<clientList.size(); ++i)
4845 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4846 clientList.at(i)->write (block);
4850 void VymModel::readData ()
4852 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4855 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4859 QDataStream in(clientSocket);
4860 in.setVersion(QDataStream::Qt_4_0);
4868 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4871 parseAtom (t,noErr,errMsg);
4877 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4879 switch (socketError) {
4880 case QAbstractSocket::RemoteHostClosedError:
4882 case QAbstractSocket::HostNotFoundError:
4883 QMessageBox::information(NULL, vymName +" Network client",
4884 "The host was not found. Please check the "
4885 "host name and port settings.");
4887 case QAbstractSocket::ConnectionRefusedError:
4888 QMessageBox::information(NULL, vymName + " Network client",
4889 "The connection was refused by the peer. "
4890 "Make sure the fortune server is running, "
4891 "and check that the host name and port "
4892 "settings are correct.");
4895 QMessageBox::information(NULL, vymName + " Network client",
4896 QString("The following error occurred: %1.")
4897 .arg(clientSocket->errorString()));
4901 /* FIXME-3 Playing with DBUS...
4902 QDBusVariant VymModel::query (const QString &query)
4904 TreeItem *selti=getSelectedItem();
4906 return QDBusVariant (selti->getHeading());
4908 return QDBusVariant ("Nothing selected.");
4912 void VymModel::testslot() //FIXME-3 Playing with DBUS
4914 cout << "VM::testslot called\n";
4917 void VymModel::selectMapSelectionColor()
4919 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4920 setSelectionColor (col);
4923 void VymModel::setSelectionColorInt (QColor col)
4925 if ( !col.isValid() ) return;
4927 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4928 QString("setSelectionColor (%1)").arg(col.name()),
4929 QString("Set color of selection box to %1").arg(col.name())
4932 mapEditor->setSelectionColor (col);
4935 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4937 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4938 //FIXME-3 emitShowSelection();
4942 void VymModel::emitSelectionChanged()
4944 QItemSelection newsel=selModel->selection();
4945 emitSelectionChanged (newsel);
4948 void VymModel::setSelectionColor(QColor col)
4950 if ( !col.isValid() ) return;
4952 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4953 QString("setSelectionColor (%1)").arg(col.name()),
4954 QString("Set color of selection box to %1").arg(col.name())
4956 setSelectionColorInt (col);
4959 QColor VymModel::getSelectionColor()
4961 return mapEditor->getSelectionColor();
4964 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4967 for (int i=0;i<rootItem->branchCount();i++)
4968 rootItem->getBranchNum(i)->setHideTmp (mode);
4970 if (mode==TreeItem::HideExport)
4976 //////////////////////////////////////////////
4977 // Selection related
4978 //////////////////////////////////////////////
4980 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4985 QItemSelectionModel* VymModel::getSelectionModel()
4990 void VymModel::setSelectionBlocked (bool b)
4995 bool VymModel::isSelectionBlocked()
4997 return selectionBlocked;
5000 bool VymModel::select ()
5002 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5005 bool VymModel::select (const QString &s)
5012 TreeItem *ti=findBySelectString(s);
5013 if (ti) return select (index(ti));
5017 bool VymModel::select (LinkableMapObj *lmo)
5019 QItemSelection oldsel=selModel->selection();
5022 return select (index (lmo->getTreeItem()) );
5027 bool VymModel::select (TreeItem *ti)
5029 if (ti) return select (index(ti));
5033 bool VymModel::select (TreeItem *ti, int i)
5035 if (!ti || i<0) return false;
5036 if (select (index(ti)))
5038 qDebug ()<<"VM::select with index: "<<i<<" Trying to find text in note ";
5039 QTextCursor c=textEditor->getTextCursor();
5040 c.setPosition (i-1,QTextCursor::MoveAnchor);
5041 textEditor->setTextCursor (c);
5043 qDebug ()<<"VM::select with index: "<<i<<" Giving up to find text in note ";
5047 bool VymModel::select (const QModelIndex &index)
5049 if (index.isValid() )
5051 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5052 BranchItem *bi=getSelectedBranch();
5053 if (bi) bi->setLastSelectedBranch();
5059 void VymModel::unselect()
5061 if (!selModel->selectedIndexes().isEmpty())
5063 lastSelectString=getSelectString();
5064 selModel->clearSelection();
5068 bool VymModel::reselect()
5070 return select (lastSelectString);
5073 void VymModel::emitShowSelection()
5075 if (!blockReposition)
5076 emit (showSelection() );
5079 void VymModel::emitNoteHasChanged (TreeItem *ti)
5081 QModelIndex ix=index(ti);
5082 emit (noteHasChanged (ix) );
5085 void VymModel::emitDataHasChanged (TreeItem *ti)
5087 QModelIndex ix=index(ti);
5088 emit (dataChanged (ix,ix) );
5091 void VymModel::emitUpdateLayout()
5093 if (settings.value("/mainwindow/autoLayout/use","true")=="true")
5094 emit (updateLayout());
5097 bool VymModel::selectFirstBranch()
5099 TreeItem *ti=getSelectedBranch();
5102 TreeItem *par=ti->parent();
5105 TreeItem *ti2=par->getFirstBranch();
5106 if (ti2) return select(ti2);
5112 bool VymModel::selectLastBranch()
5114 TreeItem *ti=getSelectedBranch();
5117 TreeItem *par=ti->parent();
5120 TreeItem *ti2=par->getLastBranch();
5121 if (ti2) return select(ti2);
5127 bool VymModel::selectLastSelectedBranch()
5129 BranchItem *bi=getSelectedBranch();
5132 bi=bi->getLastSelectedBranch();
5133 if (bi) return select (bi);
5138 bool VymModel::selectParent()
5140 TreeItem *ti=getSelectedItem();
5151 TreeItem::Type VymModel::selectionType()
5153 QModelIndexList list=selModel->selectedIndexes();
5154 if (list.isEmpty()) return TreeItem::Undefined;
5155 TreeItem *ti = getItem (list.first() );
5156 return ti->getType();
5160 LinkableMapObj* VymModel::getSelectedLMO()
5162 QModelIndexList list=selModel->selectedIndexes();
5163 if (!list.isEmpty() )
5165 TreeItem *ti = getItem (list.first() );
5166 TreeItem::Type type=ti->getType();
5167 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5168 return ((MapItem*)ti)->getLMO();
5173 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5175 TreeItem *ti = getSelectedBranch();
5177 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5182 BranchItem* VymModel::getSelectedBranch()
5184 QModelIndexList list=selModel->selectedIndexes();
5185 if (!list.isEmpty() )
5187 TreeItem *ti = getItem (list.first() );
5188 TreeItem::Type type=ti->getType();
5189 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5190 return (BranchItem*)ti;
5195 ImageItem* VymModel::getSelectedImage()
5197 QModelIndexList list=selModel->selectedIndexes();
5198 if (!list.isEmpty())
5200 TreeItem *ti=getItem (list.first());
5201 if (ti && ti->getType()==TreeItem::Image)
5202 return (ImageItem*)ti;
5207 AttributeItem* VymModel::getSelectedAttribute()
5209 QModelIndexList list=selModel->selectedIndexes();
5210 if (!list.isEmpty() )
5212 TreeItem *ti = getItem (list.first() );
5213 TreeItem::Type type=ti->getType();
5214 if (type ==TreeItem::Attribute)
5215 return (AttributeItem*)ti;
5220 TreeItem* VymModel::getSelectedItem()
5222 QModelIndexList list=selModel->selectedIndexes();
5223 if (!list.isEmpty() )
5224 return getItem (list.first() );
5229 QModelIndex VymModel::getSelectedIndex()
5231 QModelIndexList list=selModel->selectedIndexes();
5232 if (list.isEmpty() )
5233 return QModelIndex();
5235 return list.first();
5238 QString VymModel::getSelectString ()
5240 return getSelectString (getSelectedItem());
5243 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5245 if (!lmo) return QString();
5246 return getSelectString (lmo->getTreeItem() );
5249 QString VymModel::getSelectString (TreeItem *ti)
5253 switch (ti->getType())
5255 case TreeItem::MapCenter: s="mc:"; break;
5256 case TreeItem::Branch: s="bo:";break;
5257 case TreeItem::Image: s="fi:";break;
5258 case TreeItem::Attribute: s="ai:";break;
5259 case TreeItem::XLink: s="xl:";break;
5261 s="unknown type in VymModel::getSelectString()";
5264 s= s + QString("%1").arg(ti->num());
5266 // call myself recursively
5267 s= getSelectString(ti->parent()) +","+s;