1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
19 #include "warningdialog.h"
20 #include "xlinkitem.h"
21 #include "xml-freemind.h"
27 extern Main *mainWindow;
28 extern QDBusConnection dbusConnection;
30 extern Settings settings;
31 extern QString tmpVymDir;
33 extern TextEditor *textEditor;
34 extern FlagRow *standardFlagsMaster;
36 extern QString clipboardDir;
37 extern QString clipboardFile;
38 extern bool clipboardEmpty;
40 extern ImageIO imageIO;
42 extern QString vymName;
43 extern QString vymVersion;
44 extern QDir vymBaseDir;
46 extern QDir lastImageDir;
47 extern QDir lastFileDir;
49 extern Settings settings;
53 int VymModel::mapNum=0; // make instance
57 //cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 //cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
71 void VymModel::clear()
73 while (rootItem->childCount() >0)
74 deleteItem (rootItem->getChildNum(0) );
77 void VymModel::init ()
82 // Also no scene yet (should not be needed anyway) FIXME-3 VM
95 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
96 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
97 mainWindow->updateHistory (undoSet);
100 makeTmpDirectories();
105 fileName=tr("unnamed");
107 blockReposition=false;
108 blockSaveState=false;
110 autosaveTimer=new QTimer (this);
111 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
113 fileChangedTimer=new QTimer (this);
114 fileChangedTimer->start(3000);
115 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
120 selectionBlocked=false;
125 // animations // FIXME-3 switch to new animation system
126 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
127 animationTicks=settings.readNumEntry("/animation/ticks",10);
128 animationInterval=settings.readNumEntry("/animation/interval",50);
130 animationTimer=new QTimer (this);
131 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
134 defLinkColor=QColor (0,0,255);
135 defXLinkColor=QColor (180,180,180);
136 linkcolorhint=LinkableMapObj::DefaultColor;
137 linkstyle=LinkableMapObj::PolyParabel;
139 defXLinkColor=QColor (230,230,230);
141 hidemode=TreeItem::HideNone;
146 //Initialize DBUS object
147 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
148 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
149 qWarning ("VymModel: Couldn't register DBUS object!");
152 void VymModel::makeTmpDirectories()
154 // Create unique temporary directories
155 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
156 histPath = tmpMapDir+"/history";
162 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
167 bool VymModel::isRepositionBlocked()
169 return blockReposition;
172 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
174 //cout << "VM::updateActions \n";
175 // Tell mainwindow to update states of actions
176 mainWindow->updateActions();
181 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
183 // tmpdir temporary directory to which data will be written
184 // prefix mapname, which will be appended to images etc.
185 // writeflags Only write flags for "real" save of map, not undo
186 // offset offset of bbox of whole map in scene.
187 // Needed for XML export
196 case LinkableMapObj::Line:
199 case LinkableMapObj::Parabel:
202 case LinkableMapObj::PolyLine:
206 ls="StylePolyParabel";
210 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
212 if (linkcolorhint==LinkableMapObj::HeadingColor)
213 colhint=xml.attribut("linkColorHint","HeadingColor");
215 QString mapAttr=xml.attribut("version",vymVersion);
217 mapAttr+= xml.attribut("author",author) +
218 xml.attribut("comment",comment) +
219 xml.attribut("date",getDate()) +
220 xml.attribut("branchCount", QString().number(branchCount())) +
221 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
222 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
223 xml.attribut("linkStyle", ls ) +
224 xml.attribut("linkColor", defLinkColor.name() ) +
225 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
226 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
228 s+=xml.beginElement("vymmap",mapAttr);
231 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
232 standardFlagsMaster->resetUsedCounter();
234 // Build xml recursivly
236 // Save all mapcenters as complete map, if saveSel not set
237 s+=saveTreeToDir(tmpdir,prefix,offset);
240 switch (saveSel->getType())
242 case TreeItem::Branch:
244 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
246 case TreeItem::MapCenter:
248 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
250 case TreeItem::Image:
252 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
255 // other types shouldn't be safed directly...
260 // Save local settings
261 s+=settings.getDataXML (destPath);
264 if (getSelectedItem() && !saveSel )
265 s+=xml.valueElement("select",getSelectString());
268 s+=xml.endElement("vymmap");
270 //cout << s.toStdString() << endl;
272 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
276 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
280 for (int i=0; i<rootItem->branchCount(); i++)
281 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
285 void VymModel::setFilePath(QString fpath, QString destname)
287 if (fpath.isEmpty() || fpath=="")
294 filePath=fpath; // becomes absolute path
295 fileName=fpath; // gets stripped of path
296 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
298 // If fpath is not an absolute path, complete it
299 filePath=QDir(fpath).absPath();
300 fileDir=filePath.left (1+filePath.findRev ("/"));
302 // Set short name, too. Search from behind:
303 int i=fileName.findRev("/");
304 if (i>=0) fileName=fileName.remove (0,i+1);
306 // Forget the .vym (or .xml) for name of map
307 mapName=fileName.left(fileName.findRev(".",-1,true) );
311 void VymModel::setFilePath(QString fpath)
313 setFilePath (fpath,fpath);
316 QString VymModel::getFilePath()
321 QString VymModel::getFileName()
326 QString VymModel::getMapName()
331 QString VymModel::getDestPath()
336 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
338 ErrorCode err=success;
340 parseBaseHandler *handler;
344 case VymMap: handler=new parseVYMHandler; break;
345 case FreemindMap : handler=new parseFreemindHandler; break;
347 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
348 "Unknown FileType in VymModel::load()");
352 bool zipped_org=zipped;
356 selModel->clearSelection();
357 // FIXME-2 VM not needed??? model->setMapEditor(this);
358 // (map state is set later at end of load...)
361 BranchItem *bi=getSelectedBranch();
362 if (!bi) return aborted;
363 if (lmode==ImportAdd)
364 saveStateChangingPart(
367 QString("addMapInsert (%1)").arg(fname),
368 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
370 saveStateChangingPart(
373 QString("addMapReplace(%1)").arg(fname),
374 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
378 // Create temporary directory for packing
380 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
383 QMessageBox::critical( 0, tr( "Critical Load Error" ),
384 tr("Couldn't create temporary directory before load\n"));
389 err=unzipDir (tmpZipDir,fname);
399 // Look for mapname.xml
400 xmlfile= fname.left(fname.findRev(".",-1,true));
401 xmlfile=xmlfile.section( '/', -1 );
402 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
403 if (!mfile.exists() )
405 // mapname.xml does not exist, well,
406 // maybe someone renamed the mapname.vym file...
407 // Try to find any .xml in the toplevel
408 // directory of the .vym file
409 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
410 if (flist.count()==1)
412 // Only one entry, take this one
413 xmlfile=tmpZipDir + "/"+flist.first();
416 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
417 *it=tmpZipDir + "/" + *it;
418 // TODO Multiple entries, load all (but only the first one into this ME)
419 //mainWindow->fileLoadFromTmp (flist);
420 //returnCode=1; // Silently forget this attempt to load
421 qWarning ("MainWindow::load (fn) multimap found...");
424 if (flist.isEmpty() )
426 QMessageBox::critical( 0, tr( "Critical Load Error" ),
427 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
430 } //file doesn't exist
432 xmlfile=mfile.name();
435 QFile file( xmlfile);
437 // I am paranoid: file should exist anyway
438 // according to check in mainwindow.
441 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
442 tr(QString("Couldn't open map %1").arg(file.name())));
446 bool blockSaveStateOrg=blockSaveState;
447 blockReposition=true;
449 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
450 QXmlInputSource source( file);
451 QXmlSimpleReader reader;
452 reader.setContentHandler( handler );
453 reader.setErrorHandler( handler );
454 handler->setModel ( this);
457 // We need to set the tmpDir in order to load files with rel. path
462 tmpdir=fname.left(fname.findRev("/",-1));
463 handler->setTmpDir (tmpdir);
464 handler->setInputFile (file.name());
465 handler->setLoadMode (lmode);
466 bool ok = reader.parse( source );
467 blockReposition=false;
468 blockSaveState=blockSaveStateOrg;
469 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
473 reposition(); // FIXME-2 VM reposition the view instead...
474 emitSelectionChanged();
480 autosaveTimer->stop();
483 // Reset timestamp to check for later updates of file
484 fileChangedTime=QFileInfo (destPath).lastModified();
487 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
488 tr( handler->errorProtocol() ) );
490 // Still return "success": the map maybe at least
491 // partially read by the parser
496 removeDir (QDir(tmpZipDir));
498 // Restore original zip state
505 ErrorCode VymModel::save (const SaveMode &savemode)
509 QString safeFilePath;
511 ErrorCode err=success;
515 mapFileName=mapName+".xml";
517 // use name given by user, even if he chooses .doc
518 mapFileName=fileName;
520 // Look, if we should zip the data:
523 QMessageBox mb( vymName,
524 tr("The map %1\ndid not use the compressed "
525 "vym file format.\nWriting it uncompressed will also write images \n"
526 "and flags and thus may overwrite files in the "
527 "given directory\n\nDo you want to write the map").arg(filePath),
528 QMessageBox::Warning,
529 QMessageBox::Yes | QMessageBox::Default,
531 QMessageBox::Cancel | QMessageBox::Escape);
532 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
533 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
534 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
537 case QMessageBox::Yes:
538 // save compressed (default file format)
541 case QMessageBox::No:
545 case QMessageBox::Cancel:
552 // First backup existing file, we
553 // don't want to add to old zip archives
557 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
559 QString backupFileName(destPath + "~");
560 QFile backupFile(backupFileName);
561 if (backupFile.exists() && !backupFile.remove())
563 QMessageBox::warning(0, tr("Save Error"),
564 tr("%1\ncould not be removed before saving").arg(backupFileName));
566 else if (!f.rename(backupFileName))
568 QMessageBox::warning(0, tr("Save Error"),
569 tr("%1\ncould not be renamed before saving").arg(destPath));
576 // Create temporary directory for packing
578 tmpZipDir=makeTmpDir (ok,"vym-zip");
581 QMessageBox::critical( 0, tr( "Critical Load Error" ),
582 tr("Couldn't create temporary directory before save\n"));
586 safeFilePath=filePath;
587 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
590 // Create mapName and fileDir
591 makeSubDirs (fileDir);
594 if (savemode==CompleteMap || selModel->selection().isEmpty())
597 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
600 autosaveTimer->stop();
605 if (selectionType()==TreeItem::Image)
608 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
609 // TODO take care of multiselections
612 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
615 qWarning ("ME::saveStringToDisk failed!");
621 if (err==success) err=zipDir (tmpZipDir,destPath);
624 removeDir (QDir(tmpZipDir));
626 // Restore original filepath outside of tmp zip dir
627 setFilePath (safeFilePath);
631 fileChangedTime=QFileInfo (destPath).lastModified();
635 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
637 QString pathDir=path.left(path.findRev("/"));
643 // We need to parse saved XML data
644 parseVYMHandler handler;
645 QXmlInputSource source( file);
646 QXmlSimpleReader reader;
647 reader.setContentHandler( &handler );
648 reader.setErrorHandler( &handler );
649 handler.setModel ( this);
650 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
651 if (undoSel.isEmpty())
655 handler.setLoadMode (NewMap);
659 handler.setLoadMode (ImportReplace);
661 blockReposition=true;
662 bool ok = reader.parse( source );
663 blockReposition=false;
666 // This should never ever happen
667 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
668 handler.errorProtocol());
671 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
674 bool VymModel::addMapInsertInt (const QString &path)
676 QString pathDir=path.left(path.findRev("/"));
682 // We need to parse saved XML data
683 parseVYMHandler handler;
684 QXmlInputSource source( file);
685 QXmlSimpleReader reader;
686 reader.setContentHandler( &handler );
687 reader.setErrorHandler( &handler );
688 handler.setModel (this);
689 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
690 handler.setLoadMode (ImportAdd);
691 blockReposition=true;
692 bool ok = reader.parse( source );
693 blockReposition=false;
694 if ( ok ) return true;
696 // This should never ever happen
697 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
698 handler.errorProtocol());
701 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
705 bool VymModel::addMapInsertInt (const QString &path, int pos)
707 BranchItem *selbi=getSelectedBranch();
710 if (addMapInsertInt (path))
712 if (selbi->depth()>0)
713 relinkBranch (selbi->getLastBranch(), selbi,pos);
717 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
721 qWarning ("ME::addMapInsertInt nothing selected");
725 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
727 ImageItem *ii=createImage(dst);
737 void VymModel::loadFloatImage ()
739 BranchItem *selbi=getSelectedBranch();
743 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
744 fd->setMode (Q3FileDialog::ExistingFiles);
745 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
746 ImagePreview *p =new ImagePreview (fd);
747 fd->setContentsPreviewEnabled( TRUE );
748 fd->setContentsPreview( p, p );
749 fd->setPreviewMode( Q3FileDialog::Contents );
750 fd->setCaption(vymName+" - " +tr("Load image"));
751 fd->setDir (lastImageDir);
754 if ( fd->exec() == QDialog::Accepted )
756 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
757 lastImageDir=QDir (fd->dirPath());
760 for (int j=0; j<fd->selectedFiles().count(); j++)
762 s=fd->selectedFiles().at(j);
763 ii=loadFloatImageInt (selbi,s);
764 //FIXME-3 check savestate for loadImage
770 QString ("loadImage (%1)").arg(s ),
771 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
774 // TODO loadFIO error handling
775 qWarning ("Failed to load "+s);
783 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
788 void VymModel::saveFloatImage ()
790 ImageItem *ii=getSelectedImage();
793 QFileDialog *fd=new QFileDialog( NULL);
794 fd->setFilters (imageIO.getFilters());
795 fd->setCaption(vymName+" - " +tr("Save image"));
796 fd->setFileMode( QFileDialog::AnyFile );
797 fd->setDirectory (lastImageDir);
798 // fd->setSelection (fio->getOriginalFilename());
802 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
804 fn=fd->selectedFiles().at(0);
805 if (QFile (fn).exists() )
807 QMessageBox mb( vymName,
808 tr("The file %1 exists already.\n"
809 "Do you want to overwrite it?").arg(fn),
810 QMessageBox::Warning,
811 QMessageBox::Yes | QMessageBox::Default,
812 QMessageBox::Cancel | QMessageBox::Escape,
813 QMessageBox::NoButton );
815 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
816 mb.setButtonText( QMessageBox::No, tr("Cancel"));
819 case QMessageBox::Yes:
822 case QMessageBox::Cancel:
829 saveFloatImageInt (ii,fd->selectedFilter(),fn );
836 void VymModel::importDirInt(BranchItem *dst, QDir d)
838 BranchItem *selbi=getSelectedBranch();
842 // Traverse directories
843 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
844 QFileInfoList list = d.entryInfoList();
847 for (int i = 0; i < list.size(); ++i)
850 if (fi.fileName() != "." && fi.fileName() != ".." )
852 bi=addNewBranchInt(dst,-2);
853 bi->setHeading (fi.fileName() ); // FIXME-3 check this
854 bi->setHeadingColor (QColor("blue"));
856 if ( !d.cd(fi.fileName()) )
857 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
860 // Recursively add subdirs
867 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
868 list = d.entryInfoList();
870 for (int i = 0; i < list.size(); ++i)
873 bi=addNewBranchInt (dst,-2);
874 bi->setHeading (fi.fileName() );
875 bi->setHeadingColor (QColor("black"));
876 if (fi.fileName().right(4) == ".vym" )
877 bi->setVymLink (fi.filePath());
882 void VymModel::importDirInt (const QString &s)
884 BranchItem *selbi=getSelectedBranch();
887 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
890 importDirInt (selbi,d);
894 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
896 BranchItem *selbi=getSelectedBranch();
900 filters <<"VYM map (*.vym)";
901 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
902 fd->setMode (QFileDialog::DirectoryOnly);
903 fd->setFilters (filters);
904 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
908 if ( fd->exec() == QDialog::Accepted )
910 importDirInt (fd->selectedFile() );
912 //FIXME-3 VM needed? scene()->update();
918 void VymModel::autosave()
923 cout << "VymModel::autosave rejected due to missing filePath\n";
926 QDateTime now=QDateTime().currentDateTime();
928 // Disable autosave, while we have gone back in history
929 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
930 if (redosAvail>0) return;
932 // Also disable autosave for new map without filename
933 if (filePath.isEmpty()) return;
936 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
938 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
939 mainWindow->fileSave (this);
942 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
947 void VymModel::fileChanged()
949 // Check if file on disk has changed meanwhile
950 if (!filePath.isEmpty())
952 QDateTime tmod=QFileInfo (filePath).lastModified();
953 if (tmod>fileChangedTime)
955 // FIXME-2 VM switch to current mapeditor and finish lineedits...
956 QMessageBox mb( vymName,
957 tr("The file of the map on disk has changed:\n\n"
958 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
959 QMessageBox::Question,
961 QMessageBox::Cancel | QMessageBox::Default,
962 QMessageBox::NoButton );
964 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
965 mb.setButtonText( QMessageBox::No, tr("Ignore"));
968 case QMessageBox::Yes:
970 load (filePath,NewMap,fileType);
971 case QMessageBox::Cancel:
972 fileChangedTime=tmod; // allow autosave to overwrite newer file!
978 bool VymModel::isDefault()
983 void VymModel::makeDefault()
989 bool VymModel::hasChanged()
994 void VymModel::setChanged()
997 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1001 latestAddedItem=NULL;
1005 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1007 if (!lmo || !lmo->getTreeItem() ) return QString();
1008 return getObjectName (lmo->getTreeItem() );
1012 QString VymModel::getObjectName (TreeItem *ti)
1015 if (!ti) return QString("Error: NULL has no name!");
1017 if (s=="") s="unnamed";
1019 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1022 void VymModel::redo()
1024 // Can we undo at all?
1025 if (redosAvail<1) return;
1027 bool blockSaveStateOrg=blockSaveState;
1028 blockSaveState=true;
1032 if (undosAvail<stepsTotal) undosAvail++;
1034 if (curStep>stepsTotal) curStep=1;
1035 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1036 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1037 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1038 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1039 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1040 QString version=undoSet.readEntry ("/history/version");
1042 /* TODO Maybe check for version, if we save the history
1043 if (!checkVersion(version))
1044 QMessageBox::warning(0,tr("Warning"),
1045 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1048 // Find out current undo directory
1049 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1053 cout << "VymModel::redo() begin\n";
1054 cout << " undosAvail="<<undosAvail<<endl;
1055 cout << " redosAvail="<<redosAvail<<endl;
1056 cout << " curStep="<<curStep<<endl;
1057 cout << " ---------------------------"<<endl;
1058 cout << " comment="<<comment.toStdString()<<endl;
1059 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1060 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1061 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1062 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1063 cout << " ---------------------------"<<endl<<endl;
1066 // select object before redo
1067 if (!redoSelection.isEmpty())
1068 select (redoSelection);
1073 parseAtom (redoCommand,noErr,errMsg);
1075 blockSaveState=blockSaveStateOrg;
1077 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1078 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1079 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1080 undoSet.writeSettings(histPath);
1082 mainWindow->updateHistory (undoSet);
1085 /* TODO remove testing
1086 cout << "ME::redo() end\n";
1087 cout << " undosAvail="<<undosAvail<<endl;
1088 cout << " redosAvail="<<redosAvail<<endl;
1089 cout << " curStep="<<curStep<<endl;
1090 cout << " ---------------------------"<<endl<<endl;
1096 bool VymModel::isRedoAvailable()
1098 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1104 void VymModel::undo()
1106 // Can we undo at all?
1107 if (undosAvail<1) return;
1109 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1111 bool blockSaveStateOrg=blockSaveState;
1112 blockSaveState=true;
1114 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1115 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1116 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1117 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1118 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1119 QString version=undoSet.readEntry ("/history/version");
1121 /* TODO Maybe check for version, if we save the history
1122 if (!checkVersion(version))
1123 QMessageBox::warning(0,tr("Warning"),
1124 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1127 // Find out current undo directory
1128 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1130 // select object before undo
1131 if (!select (undoSelection))
1133 qWarning ("VymModel::undo() Could not select object for undo");
1140 cout << "VymModel::undo() begin\n";
1141 cout << " undosAvail="<<undosAvail<<endl;
1142 cout << " redosAvail="<<redosAvail<<endl;
1143 cout << " curStep="<<curStep<<endl;
1144 cout << " ---------------------------"<<endl;
1145 cout << " comment="<<comment.toStdString()<<endl;
1146 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1147 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1148 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1149 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1150 cout << " ---------------------------"<<endl<<endl;
1155 parseAtom (undoCommand,noErr,errMsg);
1159 if (curStep<1) curStep=stepsTotal;
1163 blockSaveState=blockSaveStateOrg;
1165 cout << "VymModel::undo() end\n";
1166 cout << " undosAvail="<<undosAvail<<endl;
1167 cout << " redosAvail="<<redosAvail<<endl;
1168 cout << " curStep="<<curStep<<endl;
1169 cout << " ---------------------------"<<endl<<endl;
1172 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1173 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1174 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1175 undoSet.writeSettings(histPath);
1177 mainWindow->updateHistory (undoSet);
1179 //emitSelectionChanged();
1182 bool VymModel::isUndoAvailable()
1184 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1190 void VymModel::gotoHistoryStep (int i)
1192 // Restore variables
1193 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1194 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1196 if (i<0) i=undosAvail+redosAvail;
1198 // Clicking above current step makes us undo things
1201 for (int j=0; j<undosAvail-i; j++) undo();
1204 // Clicking below current step makes us redo things
1206 for (int j=undosAvail; j<i; j++)
1208 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1212 // And ignore clicking the current row ;-)
1216 QString VymModel::getHistoryPath()
1218 QString histName(QString("history-%1").arg(curStep));
1219 return (tmpMapDir+"/"+histName);
1222 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1224 sendData(redoCom); //FIXME-3 testing
1229 if (blockSaveState) return;
1231 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1233 // Find out current undo directory
1234 if (undosAvail<stepsTotal) undosAvail++;
1236 if (curStep>stepsTotal) curStep=1;
1238 QString backupXML="";
1239 QString histDir=getHistoryPath();
1240 QString bakMapPath=histDir+"/map.xml";
1242 // Create histDir if not available
1245 makeSubDirs (histDir);
1247 // Save depending on how much needs to be saved
1249 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1251 QString undoCommand="";
1252 if (savemode==UndoCommand)
1254 undoCommand=undoCom;
1256 else if (savemode==PartOfMap )
1258 undoCommand=undoCom;
1259 undoCommand.replace ("PATH",bakMapPath);
1263 if (!backupXML.isEmpty())
1264 // Write XML Data to disk
1265 saveStringToDisk (bakMapPath,backupXML);
1267 // We would have to save all actions in a tree, to keep track of
1268 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1271 // Write the current state to disk
1272 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1273 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1274 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1275 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1276 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1277 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1278 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1280 undoSet.setEntry (QString("/history/version"),vymVersion);
1281 undoSet.writeSettings(histPath);
1285 // TODO remove after testing
1286 //cout << " into="<< histPath.toStdString()<<endl;
1287 cout << " stepsTotal="<<stepsTotal<<
1288 ", undosAvail="<<undosAvail<<
1289 ", redosAvail="<<redosAvail<<
1290 ", curStep="<<curStep<<endl;
1291 cout << " ---------------------------"<<endl;
1292 cout << " comment="<<comment.toStdString()<<endl;
1293 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1294 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1295 cout << " redoCom="<<redoCom.toStdString()<<endl;
1296 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1297 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1298 cout << " ---------------------------"<<endl;
1301 mainWindow->updateHistory (undoSet);
1307 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1309 // save the selected part of the map, Undo will replace part of map
1310 QString undoSelection="";
1312 undoSelection=getSelectString(undoSel);
1314 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1315 QString redoSelection="";
1317 redoSelection=getSelectString(undoSel);
1319 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1322 saveState (PartOfMap,
1323 undoSelection, "addMapReplace (\"PATH\")",
1329 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1333 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1336 QString undoSelection;
1337 QString redoSelection=getSelectString(redoSel);
1338 if (redoSel->getType()==TreeItem::Branch)
1340 undoSelection=getSelectString (redoSel->parent());
1341 // save the selected branch of the map, Undo will insert part of map
1342 saveState (PartOfMap,
1343 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1344 redoSelection, "delete ()",
1348 if (redoSel->getType()==TreeItem::MapCenter)
1350 // save the selected branch of the map, Undo will insert part of map
1351 saveState (PartOfMap,
1352 undoSelection, QString("addMapInsert (\"PATH\")"),
1353 redoSelection, "delete ()",
1360 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1362 // "Normal" savestate: save commands, selections and comment
1363 // so just save commands for undo and redo
1364 // and use current selection
1366 QString redoSelection="";
1367 if (redoSel) redoSelection=getSelectString(redoSel);
1368 QString undoSelection="";
1369 if (undoSel) undoSelection=getSelectString(undoSel);
1371 saveState (UndoCommand,
1378 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1380 // "Normal" savestate: save commands, selections and comment
1381 // so just save commands for undo and redo
1382 // and use current selection
1383 saveState (UndoCommand,
1390 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1392 // "Normal" savestate applied to model (no selection needed):
1393 // save commands and comment
1394 saveState (UndoCommand,
1402 QGraphicsScene* VymModel::getScene ()
1407 TreeItem* VymModel::findBySelectString(QString s)
1409 if (s.isEmpty() ) return NULL;
1411 // Old maps don't have multiple mapcenters and don't save full path
1412 if (s.left(2) !="mc")
1415 QStringList parts=s.split (",");
1418 TreeItem *ti=rootItem;
1420 while (!parts.isEmpty() )
1422 typ=parts.first().left(2);
1423 n=parts.first().right(parts.first().length() - 3).toInt();
1424 parts.removeFirst();
1425 if (typ=="mc" || typ=="bo")
1426 ti=ti->getBranchNum (n);
1428 ti=ti->getImageNum (n);
1430 ti=ti->getAttributeNum (n);
1432 ti=ti->getXLinkNum (n);
1433 if(!ti) return NULL;
1438 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1440 BranchItem *cur=NULL;
1441 BranchItem *prev=NULL;
1442 nextBranch(cur,prev);
1445 if (i==cur->getID() ) return cur;
1446 nextBranch(cur,prev);
1451 //////////////////////////////////////////////
1453 //////////////////////////////////////////////
1454 void VymModel::setVersion (const QString &s)
1459 QString VymModel::getVersion()
1464 void VymModel::setAuthor (const QString &s)
1467 QString ("setMapAuthor (\"%1\")").arg(author),
1468 QString ("setMapAuthor (\"%1\")").arg(s),
1469 QString ("Set author of map to \"%1\"").arg(s)
1474 QString VymModel::getAuthor()
1479 void VymModel::setComment (const QString &s)
1482 QString ("setMapComment (\"%1\")").arg(comment),
1483 QString ("setMapComment (\"%1\")").arg(s),
1484 QString ("Set comment of map")
1489 QString VymModel::getComment ()
1494 QString VymModel::getDate ()
1496 return QDate::currentDate().toString ("yyyy-MM-dd");
1499 int VymModel::branchCount()
1502 BranchItem *cur=NULL;
1503 BranchItem *prev=NULL;
1504 nextBranch(cur,prev);
1508 nextBranch(cur,prev);
1513 void VymModel::setSortFilter (const QString &s)
1516 emit (sortFilterChanged (sortFilter));
1519 QString VymModel::getSortFilter ()
1524 void VymModel::setHeading(const QString &s)
1526 BranchItem *selbi=getSelectedBranch();
1531 "setHeading (\""+selbi->getHeading()+"\")",
1533 "setHeading (\""+s+"\")",
1534 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1535 selbi->setHeading(s );
1536 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1538 emitSelectionChanged();
1542 QString VymModel::getHeading()
1544 TreeItem *selti=getSelectedItem();
1546 return selti->getHeading();
1551 void VymModel::setNote(const QString &s)
1553 TreeItem *selti=getSelectedItem();
1556 emitNoteHasChanged(selti);
1559 "setNote (\""+selti->getNote()+"\")",
1561 "setNote (\""+s+"\")",
1562 QString("Set note of %1 ").arg(getObjectName(selti)) );
1567 QString VymModel::getNote()
1569 TreeItem *selti=getSelectedItem();
1571 return selti->getNote();
1576 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1578 // Generate map containing _all_ URLs and branches
1580 QMap <QString,BranchItem*> map;
1581 BranchItem *cur=NULL;
1582 BranchItem *prev=NULL;
1583 nextBranch(cur,prev);
1588 map.insertMulti (u,cur);
1589 nextBranch(cur,prev);
1592 // Extract duplicate URLs
1593 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1594 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1595 while (i != map.constEnd())
1597 if (i!=map.constBegin() && i.key()==firstdup.key())
1599 if ( i-1==firstdup )
1601 cout << firstdup.key().toStdString() << endl;
1602 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1604 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1612 BranchItem* VymModel::findText (QString s, bool cs)
1614 if (!s.isEmpty() && s!=findString)
1620 QTextDocument::FindFlags flags=0;
1621 if (cs) flags=QTextDocument::FindCaseSensitively;
1624 { // Nothing found or new find process
1626 // nothing found, start again
1630 nextBranch (findCurrent,findPrevious);
1632 bool searching=true;
1633 bool foundNote=false;
1634 while (searching && !EOFind)
1638 // Searching in Note
1639 if (findCurrent->getNote().contains(findString,cs))
1641 select (findCurrent);
1643 if (getSelectedBranch()!=itFind)
1646 emitShowSelection();
1649 if (textEditor->findText(findString,flags))
1655 // Searching in Heading
1656 if (searching && findCurrent->getHeading().contains (findString,cs) )
1658 select(findCurrent);
1664 if (!nextBranch(findCurrent,findPrevious) )
1667 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1670 return getSelectedBranch();
1675 void VymModel::findReset()
1676 { // Necessary if text to find changes during a find process
1683 void VymModel::emitShowFindWidget()
1685 emit (showFindWidget());
1688 void VymModel::setScene (QGraphicsScene *s)
1693 void VymModel::setURL(const QString &url)
1695 TreeItem *selti=getSelectedItem();
1698 QString oldurl=selti->getURL();
1699 selti->setURL (url);
1702 QString ("setURL (\"%1\")").arg(oldurl),
1704 QString ("setURL (\"%1\")").arg(url),
1705 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1708 emitDataHasChanged (selti);
1709 emitShowSelection();
1713 QString VymModel::getURL()
1715 TreeItem *selti=getSelectedItem();
1717 return selti->getURL();
1722 QStringList VymModel::getURLs(bool ignoreScrolled)
1725 BranchItem *selbi=getSelectedBranch();
1726 BranchItem *cur=selbi;
1727 BranchItem *prev=NULL;
1730 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1731 urls.append( cur->getURL());
1732 cur=nextBranch (cur,prev,true,selbi);
1738 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1740 BranchItem *bi=getSelectedBranch();
1743 BranchObj *bo=(BranchObj*)(bi->getLMO());
1746 QString s=bo->getFrameTypeName();
1747 bo->setFrameType (t);
1748 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1749 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1751 bo->updateLinkGeometry();
1756 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1758 BranchItem *bi=getSelectedBranch();
1761 BranchObj *bo=(BranchObj*)(bi->getLMO());
1764 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1765 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1766 bo->setFrameType (s);
1768 bo->updateLinkGeometry();
1773 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1776 BranchItem *bi=getSelectedBranch();
1779 BranchObj *bo=(BranchObj*)(bi->getLMO());
1782 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1783 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1784 bo->setFramePenColor (c);
1789 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1791 BranchItem *bi=getSelectedBranch();
1794 BranchObj *bo=(BranchObj*)(bi->getLMO());
1797 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1798 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1799 bo->setFrameBrushColor (c);
1804 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1806 BranchItem *bi=getSelectedBranch();
1809 BranchObj *bo=(BranchObj*)(bi->getLMO());
1812 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1813 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1814 bo->setFramePadding (i);
1816 bo->updateLinkGeometry();
1821 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1823 BranchItem *bi=getSelectedBranch();
1826 BranchObj *bo=(BranchObj*)(bi->getLMO());
1829 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1830 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1831 bo->setFrameBorderWidth (i);
1833 bo->updateLinkGeometry();
1838 void VymModel::setIncludeImagesVer(bool b)
1840 BranchItem *bi=getSelectedBranch();
1843 QString u= b ? "false" : "true";
1844 QString r=!b ? "false" : "true";
1848 QString("setIncludeImagesVertically (%1)").arg(u),
1850 QString("setIncludeImagesVertically (%1)").arg(r),
1851 QString("Include images vertically in %1").arg(getObjectName(bi))
1853 bi->setIncludeImagesVer(b);
1854 emitDataHasChanged ( bi);
1859 void VymModel::setIncludeImagesHor(bool b)
1861 BranchItem *bi=getSelectedBranch();
1864 QString u= b ? "false" : "true";
1865 QString r=!b ? "false" : "true";
1869 QString("setIncludeImagesHorizontally (%1)").arg(u),
1871 QString("setIncludeImagesHorizontally (%1)").arg(r),
1872 QString("Include images horizontally in %1").arg(getObjectName(bi))
1874 bi->setIncludeImagesHor(b);
1875 emitDataHasChanged ( bi);
1880 void VymModel::setHideLinkUnselected (bool b) // FIXME-2 Images still have visible link after load
1882 TreeItem *ti=getSelectedItem();
1883 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1885 QString u= b ? "false" : "true";
1886 QString r=!b ? "false" : "true";
1890 QString("setHideLinkUnselected (%1)").arg(u),
1892 QString("setHideLinkUnselected (%1)").arg(r),
1893 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1895 ((MapItem*)ti)->setHideLinkUnselected(b);
1899 void VymModel::setHideExport(bool b)
1901 TreeItem *ti=getSelectedItem();
1903 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1905 ti->setHideInExport (b);
1906 QString u= b ? "false" : "true";
1907 QString r=!b ? "false" : "true";
1911 QString ("setHideExport (%1)").arg(u),
1913 QString ("setHideExport (%1)").arg(r),
1914 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1916 emitDataHasChanged(ti);
1917 emitSelectionChanged();
1920 // emitSelectionChanged();
1921 // FIXME-3 VM needed? scene()->update();
1925 void VymModel::toggleHideExport()
1927 TreeItem *selti=getSelectedItem();
1929 setHideExport ( !selti->hideInExport() );
1932 void VymModel::addTimestamp() //FIXME-3 new function, localize
1934 BranchItem *selbi=addNewBranch();
1937 QDate today=QDate::currentDate();
1939 selbi->setHeading (QString ("%1-%2-%3")
1940 .arg(today.year(),4,10,c)
1941 .arg(today.month(),2,10,c)
1942 .arg(today.day(),2,10,c));
1943 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1950 void VymModel::copy()
1952 TreeItem *selti=getSelectedItem();
1954 (selti->getType() == TreeItem::Branch ||
1955 selti->getType() == TreeItem::MapCenter ||
1956 selti->getType() == TreeItem::Image ))
1958 if (redosAvail == 0)
1961 QString s=getSelectString(selti);
1962 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1963 curClipboard=curStep;
1966 // Copy also to global clipboard, because we are at last step in history
1967 QString bakMapName(QString("history-%1").arg(curStep));
1968 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1969 copyDir (bakMapDir,clipboardDir );
1971 clipboardEmpty=false;
1977 void VymModel::pasteNoSave(const int &n)
1979 bool old=blockSaveState;
1980 blockSaveState=true;
1981 bool zippedOrg=zipped;
1982 if (redosAvail > 0 || n!=0)
1984 // Use the "historical" buffer
1985 QString bakMapName(QString("history-%1").arg(n));
1986 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1987 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1989 // Use the global buffer
1990 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1995 void VymModel::paste()
1997 BranchItem *selbi=getSelectedBranch();
2000 saveStateChangingPart(
2003 QString ("paste (%1)").arg(curClipboard),
2004 QString("Paste to %1").arg( getObjectName(selbi))
2011 void VymModel::cut()
2013 TreeItem *selti=getSelectedItem();
2014 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2022 bool VymModel::moveUp(BranchItem *bi)
2024 if (bi && bi->canMoveUp())
2025 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2030 void VymModel::moveUp()
2032 BranchItem *selbi=getSelectedBranch();
2035 QString oldsel=getSelectString();
2038 getSelectString(),"moveDown ()",
2040 QString("Move up %1").arg(getObjectName(selbi)));
2044 bool VymModel::moveDown(BranchItem *bi)
2046 if (bi && bi->canMoveDown())
2047 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2052 void VymModel::moveDown()
2054 BranchItem *selbi=getSelectedBranch();
2057 QString oldsel=getSelectString();
2058 if ( moveDown(selbi))
2060 getSelectString(),"moveUp ()",
2061 oldsel,"moveDown ()",
2062 QString("Move down %1").arg(getObjectName(selbi)));
2066 void VymModel::detach()
2068 BranchItem *selbi=getSelectedBranch();
2069 if (selbi && selbi->depth()>0)
2071 // if no relPos have been set before, try to use current rel positions
2072 if (selbi->getLMO())
2073 for (int i=0; i<selbi->branchCount();++i)
2074 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2076 QString oldsel=getSelectString();
2079 BranchObj *bo=selbi->getBranchObj();
2080 if (bo) p=bo->getAbsPos();
2081 QString parsel=getSelectString(selbi->parent());
2082 if ( relinkBranch (selbi,rootItem,-1) )
2084 getSelectString (selbi),
2085 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2088 QString("Detach %1").arg(getObjectName(selbi))
2093 void VymModel::sortChildren(bool inverse)
2095 BranchItem* selbi=getSelectedBranch();
2098 if(selbi->branchCount()>1)
2102 saveStateChangingPart(
2103 selbi,selbi, "sortChildren ()",
2104 QString("Sort children of %1").arg(getObjectName(selbi)));
2106 selbi->sortChildren(inverse);
2108 emitShowSelection();
2113 BranchItem* VymModel::createMapCenter()
2115 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2119 BranchItem* VymModel::createBranch(BranchItem *dst)
2122 return addNewBranchInt (dst,-2);
2127 ImageItem* VymModel::createImage(BranchItem *dst)
2134 QList<QVariant> cData;
2135 cData << "new" << "undef";
2137 ImageItem *newii=new ImageItem(cData) ;
2138 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2140 emit (layoutAboutToBeChanged() );
2143 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2144 n=dst->getRowNumAppend(newii);
2145 beginInsertRows (parix,n,n);
2146 dst->appendChild (newii);
2149 emit (layoutChanged() );
2151 // save scroll state. If scrolled, automatically select
2152 // new branch in order to tmp unscroll parent...
2153 newii->createMapObj(mapScene);
2160 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2167 QList<QVariant> cData;
2168 cData << "new xLink"<<"undef";
2170 XLinkItem *newxli=new XLinkItem(cData) ;
2171 newxli->setBegin (bi);
2173 emit (layoutAboutToBeChanged() );
2176 n=bi->getRowNumAppend(newxli);
2177 beginInsertRows (parix,n,n);
2178 bi->appendChild (newxli);
2181 emit (layoutChanged() );
2183 // save scroll state. If scrolled, automatically select
2184 // new branch in order to tmp unscroll parent...
2187 newxli->createMapObj(mapScene);
2195 AttributeItem* VymModel::addAttribute()
2197 BranchItem *selbi=getSelectedBranch();
2200 QList<QVariant> cData;
2201 cData << "new attribute" << "undef";
2202 AttributeItem *a=new AttributeItem (cData);
2203 if (addAttribute (a)) return a;
2208 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2210 BranchItem *selbi=getSelectedBranch();
2213 emit (layoutAboutToBeChanged() );
2215 QModelIndex parix=index(selbi);
2216 int n=selbi->getRowNumAppend (ai);
2217 beginInsertRows (parix,n,n);
2218 selbi->appendChild (ai);
2221 emit (layoutChanged() );
2223 ai->createMapObj(mapScene); //FIXME-2 check that...
2230 BranchItem* VymModel::addMapCenter ()
2232 BranchItem *bi=addMapCenter (contextPos);
2234 emitShowSelection();
2239 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2240 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2245 BranchItem* VymModel::addMapCenter(QPointF absPos)
2246 // createMapCenter could then probably be merged with createBranch
2250 QModelIndex parix=index(rootItem);
2252 QList<QVariant> cData;
2253 cData << "VM:addMapCenter" << "undef";
2254 BranchItem *newbi=new BranchItem (cData,rootItem);
2255 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2256 int n=rootItem->getRowNumAppend (newbi);
2258 emit (layoutAboutToBeChanged() );
2259 beginInsertRows (parix,n,n);
2261 rootItem->appendChild (newbi);
2264 emit (layoutChanged() );
2267 newbi->setPositionMode (MapItem::Absolute);
2268 BranchObj *bo=newbi->createMapObj(mapScene);
2269 if (bo) bo->move (absPos);
2274 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2276 // Depending on pos:
2277 // -3 insert in children of parent above selection
2278 // -2 add branch to selection
2279 // -1 insert in children of parent below selection
2280 // 0..n insert in children of parent at pos
2283 QList<QVariant> cData;
2284 cData << "" << "undef";
2289 BranchItem *newbi=new BranchItem (cData);
2290 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2292 emit (layoutAboutToBeChanged() );
2298 n=parbi->getRowNumAppend (newbi);
2299 beginInsertRows (parix,n,n);
2300 parbi->appendChild (newbi);
2302 }else if (num==-1 || num==-3)
2304 // insert below selection
2305 parbi=(BranchItem*)dst->parent();
2308 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2309 beginInsertRows (parix,n,n);
2310 parbi->insertBranch(n,newbi);
2313 emit (layoutChanged() );
2315 // Set color of heading to that of parent
2316 newbi->setHeadingColor (parbi->getHeadingColor());
2318 // save scroll state. If scrolled, automatically select
2319 // new branch in order to tmp unscroll parent...
2320 newbi->createMapObj(mapScene);
2325 BranchItem* VymModel::addNewBranch(int pos)
2327 // Different meaning than num in addNewBranchInt!
2331 BranchItem *newbi=NULL;
2332 BranchItem *selbi=getSelectedBranch();
2336 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2338 newbi=addNewBranchInt (selbi,pos-2);
2346 QString ("addBranch (%1)").arg(pos),
2347 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2350 // emitSelectionChanged(); FIXME-3
2351 latestAddedItem=newbi;
2352 // In Network mode, the client needs to know where the new branch is,
2353 // so we have to pass on this information via saveState.
2354 // TODO: Get rid of this positioning workaround
2355 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2356 sendData ("selectLatestAdded ()");
2357 sendData (QString("move %1").arg(ps));
2366 BranchItem* VymModel::addNewBranchBefore()
2368 BranchItem *newbi=NULL;
2369 BranchItem *selbi=getSelectedBranch();
2370 if (selbi && selbi->getType()==TreeItem::Branch)
2371 // We accept no MapCenter here, so we _have_ a parent
2373 //QPointF p=bo->getRelPos();
2376 // add below selection
2377 newbi=addNewBranchInt (selbi,-1);
2381 //newbi->move2RelPos (p);
2383 // Move selection to new branch
2384 relinkBranch (selbi,newbi,0);
2386 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2387 QString ("Add branch before %1").arg(getObjectName(selbi)));
2389 // FIXME-3 needed? reposition();
2390 // emitSelectionChanged(); FIXME-3
2396 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2402 // Do we need to update frame type?
2403 bool keepFrame=false;
2406 emit (layoutAboutToBeChanged() );
2407 BranchItem *branchpi=(BranchItem*)branch->parent();
2408 // Remove at current position
2409 int n=branch->childNum();
2411 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2412 // error occured if relinking branch to empty mainbranch
2413 cout<<"VM::relinkBranch:\n";
2414 cout<<" b="<<branch->getHeadingStd()<<endl;
2415 cout<<" dst="<<dst->getHeadingStd()<<endl;
2416 cout<<" pos="<<pos<<endl;
2417 cout<<" n1="<<n<<endl;
2419 beginRemoveRows (index(branchpi),n,n);
2420 branchpi->removeChild (n);
2423 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2425 // Append as last branch to dst
2426 if (dst->branchCount()==0)
2429 n=dst->getFirstBranch()->childNumber();
2430 beginInsertRows (index(dst),n+pos,n+pos);
2431 dst->insertBranch (pos,branch);
2434 // Correct type if necessesary
2435 if (branch->getType()==TreeItem::MapCenter)
2436 branch->setType(TreeItem::Branch);
2438 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2439 branch->updateStyles(keepFrame);
2441 emit (layoutChanged() );
2442 reposition(); // both for moveUp/Down and relinking
2443 if (dst->isScrolled() )
2446 branch->updateVisibility();
2455 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2459 emit (layoutAboutToBeChanged() );
2461 BranchItem *pi=(BranchItem*)(image->parent());
2462 QString oldParString=getSelectString (pi);
2463 // Remove at current position
2464 int n=image->childNum();
2465 beginRemoveRows (index(pi),n,n);
2466 pi->removeChild (n);
2470 QModelIndex dstix=index(dst);
2471 n=dst->getRowNumAppend (image);
2472 beginInsertRows (dstix,n,n+1);
2473 dst->appendChild (image);
2476 // Set new parent also for lmo
2477 if (image->getLMO() && dst->getLMO() )
2478 image->getLMO()->setParObj (dst->getLMO() );
2480 emit (layoutChanged() );
2483 QString("relinkTo (\"%1\")").arg(oldParString),
2485 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2486 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2492 void VymModel::deleteSelection()
2494 BranchItem *selbi=getSelectedBranch();
2499 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2501 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2504 if (pi->isScrolled() && pi->branchCount()==0)
2507 emitDataHasChanged(pi);
2510 emitShowSelection();
2514 TreeItem *ti=getSelectedItem();
2516 { // Delete other item
2517 TreeItem *pi=ti->parent();
2519 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2521 saveStateChangingPart(
2525 QString("Delete %1").arg(getObjectName(ti))
2529 emitDataHasChanged (pi);
2532 emitShowSelection();
2533 } else if (ti->getType()==TreeItem::XLink)
2535 //FIXME-2 savestate missing
2538 qWarning ("VymmModel::deleteSelection() unknown type?!");
2542 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2545 BranchItem *selbi=getSelectedBranch();
2549 // Don't use this on mapcenter
2550 if (selbi->depth()<2) return;
2552 pi=(BranchItem*)(selbi->parent());
2553 // Check if we have childs at all to keep
2554 if (selbi->branchCount()==0)
2561 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2562 saveStateChangingPart(
2565 "deleteKeepChildren ()",
2566 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2569 QString sel=getSelectString(selbi);
2571 int pos=selbi->num();
2572 BranchItem *bi=selbi->getFirstBranch();
2575 relinkBranch (bi,pi,pos);
2576 bi=selbi->getFirstBranch();
2582 BranchObj *bo=getSelectedBranchObj();
2585 bo->move2RelPos (p);
2591 void VymModel::deleteChildren()
2594 BranchItem *selbi=getSelectedBranch();
2597 saveStateChangingPart(
2600 "deleteChildren ()",
2601 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2603 emit (layoutAboutToBeChanged() );
2605 QModelIndex ix=index (selbi);
2606 int n=selbi->branchCount()-1;
2607 beginRemoveRows (ix,0,n);
2608 removeRows (0,n+1,ix);
2610 if (selbi->isScrolled()) selbi->unScroll();
2611 emit (layoutChanged() );
2616 TreeItem* VymModel::deleteItem (TreeItem *ti)
2620 TreeItem *pi=ti->parent();
2621 QModelIndex parentIndex=index(pi);
2623 emit (layoutAboutToBeChanged() );
2625 int n=ti->childNum();
2626 beginRemoveRows (parentIndex,n,n);
2627 removeRows (n,1,parentIndex);
2631 emit (layoutChanged() );
2632 if (pi->depth()>=0) return pi;
2637 void VymModel::clearItem (TreeItem *ti)
2641 QModelIndex parentIndex=index(ti);
2642 if (!parentIndex.isValid()) return;
2644 int n=ti->childCount();
2647 emit (layoutAboutToBeChanged() );
2649 beginRemoveRows (parentIndex,0,n-1);
2650 removeRows (0,n,parentIndex);
2654 emit (layoutChanged() );
2660 bool VymModel::scrollBranch(BranchItem *bi)
2664 if (bi->isScrolled()) return false;
2665 if (bi->branchCount()==0) return false;
2666 if (bi->depth()==0) return false;
2667 if (bi->toggleScroll())
2675 QString ("%1 ()").arg(u),
2677 QString ("%1 ()").arg(r),
2678 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2680 emitDataHasChanged(bi);
2681 emitSelectionChanged();
2682 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2689 bool VymModel::unscrollBranch(BranchItem *bi)
2693 if (!bi->isScrolled()) return false;
2694 if (bi->branchCount()==0) return false;
2695 if (bi->depth()==0) return false;
2696 if (bi->toggleScroll())
2704 QString ("%1 ()").arg(u),
2706 QString ("%1 ()").arg(r),
2707 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2709 emitDataHasChanged(bi);
2710 emitSelectionChanged();
2711 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2718 void VymModel::toggleScroll()
2720 BranchItem *bi=(BranchItem*)getSelectedBranch();
2721 if (bi && bi->isBranchLikeType() )
2723 if (bi->isScrolled())
2724 unscrollBranch (bi);
2728 // saveState & reposition are called in above functions
2731 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2733 BranchItem *selbi=getSelectedBranch();
2734 BranchItem *prev=NULL;
2735 BranchItem *cur=selbi;
2738 saveStateChangingPart(
2741 QString ("unscrollChildren ()"),
2742 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2746 if (cur->isScrolled())
2748 cur->toggleScroll();
2749 emitDataHasChanged (cur);
2751 cur=nextBranch (cur,prev,true,selbi);
2758 void VymModel::emitExpandAll()
2760 emit (expandAll() );
2763 void VymModel::emitExpandOneLevel()
2765 emit (expandOneLevel () );
2768 void VymModel::emitCollapseOneLevel()
2770 emit (collapseOneLevel () );
2773 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2775 BranchItem *bi=getSelectedBranch();
2779 if (bi->isActiveStandardFlag(name))
2791 QString("%1 (\"%2\")").arg(u).arg(name),
2793 QString("%1 (\"%2\")").arg(r).arg(name),
2794 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2795 bi->toggleStandardFlag (name, master);
2797 emitSelectionChanged();
2801 void VymModel::addFloatImage (const QPixmap &img)
2803 BranchItem *selbi=getSelectedBranch();
2806 ImageItem *ii=createImage (selbi);
2808 ii->setOriginalFilename("No original filename (image added by dropevent)");
2809 QString s=getSelectString(selbi);
2810 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2811 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2813 // FIXME-3 VM needed? scene()->update();
2818 void VymModel::colorBranch (QColor c)
2820 BranchItem *selbi=getSelectedBranch();
2825 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2827 QString ("colorBranch (\"%1\")").arg(c.name()),
2828 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2830 selbi->setHeadingColor(c); // color branch
2835 void VymModel::colorSubtree (QColor c)
2837 BranchItem *selbi=getSelectedBranch();
2840 saveStateChangingPart(
2843 QString ("colorSubtree (\"%1\")").arg(c.name()),
2844 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2846 BranchItem *prev=NULL;
2847 BranchItem *cur=selbi;
2850 cur->setHeadingColor(c); // color links, color children
2851 cur=nextBranch (cur,prev,true,selbi);
2857 QColor VymModel::getCurrentHeadingColor()
2859 BranchItem *selbi=getSelectedBranch();
2860 if (selbi) return selbi->getHeadingColor();
2862 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2868 void VymModel::editURL()
2870 TreeItem *selti=getSelectedItem();
2874 QString text = QInputDialog::getText(
2875 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2876 selti->getURL(), &ok, NULL);
2878 // user entered something and pressed OK
2883 void VymModel::editLocalURL()
2885 TreeItem *selti=getSelectedItem();
2888 QStringList filters;
2889 filters <<"All files (*)";
2890 filters << tr("Text","Filedialog") + " (*.txt)";
2891 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2892 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2893 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2894 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2895 fd->setFilters (filters);
2896 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2897 fd->setDirectory (lastFileDir);
2898 if (! selti->getVymLink().isEmpty() )
2899 fd->selectFile( selti->getURL() );
2902 if ( fd->exec() == QDialog::Accepted )
2904 lastFileDir=QDir (fd->directory().path());
2905 setURL (fd->selectedFile() );
2911 void VymModel::editHeading2URL()
2913 TreeItem *selti=getSelectedItem();
2915 setURL (selti->getHeading());
2918 void VymModel::editBugzilla2URL()
2920 TreeItem *selti=getSelectedItem();
2923 QString h=selti->getHeading();
2924 QRegExp rx("^(\\d+)");
2925 if (rx.indexIn(h) !=-1)
2926 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2930 void VymModel::getBugzillaData()
2932 TreeItem *selti=getSelectedItem();
2935 QString url=selti->getURL();
2938 QRegExp rx("(\\d+)");
2939 if (rx.indexIn(url) !=-1)
2941 QString bugID=rx.cap(1);
2942 cout << "VM::getBugzillaData bug="<<bugID.toStdString()<<endl;
2945 //QString script="test/sleep.sh";
2946 QString script="test/vym-bug.pl";
2947 p.start (script,QStringList()<<bugID);
2948 if (!p.waitForStarted())
2950 cout <<"VM::getBugzillaData couldn't start "<<script.toStdString()<<endl;
2953 if (!p.waitForFinished())
2955 cout <<"VM::getBugzillaData couldn't finish "<<script.toStdString()<<endl;
2958 //QByteArray result=p.readAll();
2959 QString result=p.getStdout();
2960 while (result.endsWith("\n")) result.chop(1);
2961 //cout << QString(result).toStdString()<<endl;
2962 QString err=p.getErrout();
2965 cout << "VM::getBugzillaData Error:\n";
2966 cout <<err.toStdString()<<endl;
2968 else if (!result.isEmpty())
2970 QString heading,cdate,mdate,state,whiteboard;
2971 QRegExp re("short_desc:(.*)\n");
2972 re.setMinimal(true);
2973 if (re.indexIn (result) !=-1) heading=re.cap(1);
2975 re.setPattern ("creation_ts:(.*)\\s");
2976 if (re.indexIn (result) !=-1) cdate=re.cap(1);
2978 re.setPattern ("delta_ts:(.*)\\s");
2979 if (re.indexIn (result) !=-1) mdate=re.cap(1);
2981 re.setPattern ("bug_status:(.*)\n");
2982 if (re.indexIn (result) !=-1) state=re.cap(1);
2984 re.setPattern ("status_whiteboard:(.*)\n");
2985 if (re.indexIn (result) !=-1) whiteboard=re.cap(1);
2987 setHeading (bugID + " - " + heading);
2988 cout << "VM: heading="<<heading.toStdString()<<endl;
2989 cout << "VM: cdate="<<cdate.toStdString()<<endl;
2990 cout << "VM: mdate="<<mdate.toStdString()<<endl;
2991 cout << "VM: state="<<state.toStdString()<<endl;
2992 cout << "VM: wboard="<<whiteboard.toStdString()<<endl;
2994 //cout <<"VM::getBugzillaData "<<script.toStdString()<<" returned:\n";
2995 //cout <<QString(result).toStdString()<<endl;
2997 cout << "VM::getBugzillaData "<<script.toStdString()<<" returned nothing\n";
3003 void VymModel::editFATE2URL()
3005 TreeItem *selti=getSelectedItem();
3008 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3011 "setURL (\""+selti->getURL()+"\")",
3013 "setURL (\""+url+"\")",
3014 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3016 selti->setURL (url);
3017 // FIXME-4 updateActions();
3021 void VymModel::editVymLink()
3023 BranchItem *bi=getSelectedBranch();
3026 QStringList filters;
3027 filters <<"VYM map (*.vym)";
3028 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3029 fd->setFilters (filters);
3030 fd->setCaption(vymName+" - " +tr("Link to another map"));
3031 fd->setDirectory (lastFileDir);
3032 if (! bi->getVymLink().isEmpty() )
3033 fd->selectFile( bi->getVymLink() );
3037 if ( fd->exec() == QDialog::Accepted )
3039 lastFileDir=QDir (fd->directory().path());
3042 "setVymLink (\""+bi->getVymLink()+"\")",
3044 "setVymLink (\""+fd->selectedFile()+"\")",
3045 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3047 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
3052 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
3054 // Internal function, no saveState needed
3055 TreeItem *selti=getSelectedItem();
3058 selti->setVymLink(s);
3060 emitDataHasChanged (selti);
3061 emitShowSelection();
3065 void VymModel::deleteVymLink()
3067 BranchItem *bi=getSelectedBranch();
3072 "setVymLink (\""+bi->getVymLink()+"\")",
3074 "setVymLink (\"\")",
3075 QString("Unset vymlink of %1").arg(getObjectName(bi))
3077 bi->setVymLink ("" );
3083 QString VymModel::getVymLink()
3085 BranchItem *bi=getSelectedBranch();
3087 return bi->getVymLink();
3093 QStringList VymModel::getVymLinks()
3096 BranchItem *selbi=getSelectedBranch();
3097 BranchItem *cur=selbi;
3098 BranchItem *prev=NULL;
3101 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3102 cur=nextBranch (cur,prev,true,selbi);
3108 void VymModel::followXLink(int i)
3111 BranchItem *selbi=getSelectedBranch();
3114 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3115 if (selbi) select (selbi);
3119 void VymModel::editXLink(int i)
3122 BranchItem *selbi=getSelectedBranch();
3125 XLinkItem *xli=selbi->getXLinkNum(i);
3128 EditXLinkDialog dia;
3130 dia.setSelection(selbi);
3131 if (dia.exec() == QDialog::Accepted)
3133 if (dia.useSettingsGlobal() )
3135 setMapDefXLinkColor (xli->getColor() );
3136 setMapDefXLinkWidth (xli->getWidth() );
3138 if (dia.deleteXLink()) deleteItem (xli);
3148 //////////////////////////////////////////////
3150 //////////////////////////////////////////////
3152 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3154 TreeItem* selti=getSelectedItem();
3155 BranchItem *selbi=getSelectedBranch();
3160 QVariant returnValue;
3162 // Split string s into command and parameters
3163 parser.parseAtom (atom);
3164 QString com=parser.getCommand();
3166 // External commands
3167 /////////////////////////////////////////////////////////////////////
3168 if (com=="addBranch")
3172 parser.setError (Aborted,"Nothing selected");
3173 } else if (! selbi )
3175 parser.setError (Aborted,"Type of selection is not a branch");
3180 if (parser.checkParCount(pl))
3182 if (parser.parCount()==0)
3186 n=parser.parInt (ok,0);
3187 if (ok ) addNewBranch (n);
3191 /////////////////////////////////////////////////////////////////////
3192 } else if (com=="addBranchBefore")
3196 parser.setError (Aborted,"Nothing selected");
3197 } else if (! selbi )
3199 parser.setError (Aborted,"Type of selection is not a branch");
3202 if (parser.parCount()==0)
3204 addNewBranchBefore ();
3207 /////////////////////////////////////////////////////////////////////
3208 } else if (com==QString("addMapCenter"))
3210 if (parser.checkParCount(2))
3212 x=parser.parDouble (ok,0);
3215 y=parser.parDouble (ok,1);
3216 if (ok) addMapCenter (QPointF(x,y));
3219 /////////////////////////////////////////////////////////////////////
3220 } else if (com==QString("addMapReplace"))
3224 parser.setError (Aborted,"Nothing selected");
3225 } else if (! selbi )
3227 parser.setError (Aborted,"Type of selection is not a branch");
3228 } else if (parser.checkParCount(1))
3230 //s=parser.parString (ok,0); // selection
3231 t=parser.parString (ok,0); // path to map
3232 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3233 addMapReplaceInt(getSelectString(selbi),t);
3235 /////////////////////////////////////////////////////////////////////
3236 } else if (com==QString("addMapInsert"))
3238 if (parser.parCount()==2)
3243 parser.setError (Aborted,"Nothing selected");
3244 } else if (! selbi )
3246 parser.setError (Aborted,"Type of selection is not a branch");
3249 t=parser.parString (ok,0); // path to map
3250 n=parser.parInt(ok,1); // position
3251 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3252 addMapInsertInt(t,n);
3254 } else if (parser.parCount()==1)
3256 t=parser.parString (ok,0); // path to map
3257 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3260 parser.setError (Aborted,"Wrong number of parameters");
3261 /////////////////////////////////////////////////////////////////////
3262 } else if (com==QString("addXLink"))
3264 if (parser.parCount()>1)
3266 s=parser.parString (ok,0); // begin
3267 t=parser.parString (ok,1); // end
3268 BranchItem *begin=(BranchItem*)findBySelectString(s);
3269 BranchItem *end=(BranchItem*)findBySelectString(t);
3272 if (begin->isBranchLikeType() && end->isBranchLikeType())
3274 XLinkItem *xl=createXLink (begin,true);
3280 parser.setError (Aborted,"Failed to create xLink");
3283 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3286 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3288 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3289 /////////////////////////////////////////////////////////////////////
3290 } else if (com=="clearFlags")
3294 parser.setError (Aborted,"Nothing selected");
3295 } else if (! selbi )
3297 parser.setError (Aborted,"Type of selection is not a branch");
3298 } else if (parser.checkParCount(0))
3300 selbi->deactivateAllStandardFlags();
3302 /////////////////////////////////////////////////////////////////////
3303 } else if (com=="colorBranch")
3307 parser.setError (Aborted,"Nothing selected");
3308 } else if (! selbi )
3310 parser.setError (Aborted,"Type of selection is not a branch");
3311 } else if (parser.checkParCount(1))
3313 QColor c=parser.parColor (ok,0);
3314 if (ok) colorBranch (c);
3316 /////////////////////////////////////////////////////////////////////
3317 } else if (com=="colorSubtree")
3321 parser.setError (Aborted,"Nothing selected");
3322 } else if (! selbi )
3324 parser.setError (Aborted,"Type of selection is not a branch");
3325 } else if (parser.checkParCount(1))
3327 QColor c=parser.parColor (ok,0);
3328 if (ok) colorSubtree (c);
3330 /////////////////////////////////////////////////////////////////////
3331 } else if (com=="copy")
3335 parser.setError (Aborted,"Nothing selected");
3336 } else if ( selectionType()!=TreeItem::Branch &&
3337 selectionType()!=TreeItem::MapCenter &&
3338 selectionType()!=TreeItem::Image )
3340 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3341 } else if (parser.checkParCount(0))
3345 /////////////////////////////////////////////////////////////////////
3346 } else if (com=="cut")
3350 parser.setError (Aborted,"Nothing selected");
3351 } else if ( selectionType()!=TreeItem::Branch &&
3352 selectionType()!=TreeItem::MapCenter &&
3353 selectionType()!=TreeItem::Image )
3355 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3356 } else if (parser.checkParCount(0))
3360 /////////////////////////////////////////////////////////////////////
3361 } else if (com=="delete")
3365 parser.setError (Aborted,"Nothing selected");
3367 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3369 parser.setError (Aborted,"Type of selection is wrong.");
3372 else if (parser.checkParCount(0))
3376 /////////////////////////////////////////////////////////////////////
3377 } else if (com=="deleteKeepChildren")
3381 parser.setError (Aborted,"Nothing selected");
3382 } else if (! selbi )
3384 parser.setError (Aborted,"Type of selection is not a branch");
3385 } else if (parser.checkParCount(0))
3387 deleteKeepChildren();
3389 /////////////////////////////////////////////////////////////////////
3390 } else if (com=="deleteChildren")
3394 parser.setError (Aborted,"Nothing selected");
3397 parser.setError (Aborted,"Type of selection is not a branch");
3398 } else if (parser.checkParCount(0))
3402 /////////////////////////////////////////////////////////////////////
3403 } else if (com=="exportAO")
3407 if (parser.parCount()>=1)
3408 // Hey, we even have a filename
3409 fname=parser.parString(ok,0);
3412 parser.setError (Aborted,"Could not read filename");
3415 exportAO (fname,false);
3417 /////////////////////////////////////////////////////////////////////
3418 } else if (com=="exportASCII")
3422 if (parser.parCount()>=1)
3423 // Hey, we even have a filename
3424 fname=parser.parString(ok,0);
3427 parser.setError (Aborted,"Could not read filename");
3430 exportASCII (fname,false);
3432 /////////////////////////////////////////////////////////////////////
3433 } else if (com=="exportImage")
3437 if (parser.parCount()>=2)
3438 // Hey, we even have a filename
3439 fname=parser.parString(ok,0);
3442 parser.setError (Aborted,"Could not read filename");
3445 QString format="PNG";
3446 if (parser.parCount()>=2)
3448 format=parser.parString(ok,1);
3450 exportImage (fname,false,format);
3452 /////////////////////////////////////////////////////////////////////
3453 } else if (com=="exportXHTML")
3457 if (parser.parCount()>=2)
3458 // Hey, we even have a filename
3459 fname=parser.parString(ok,1);
3462 parser.setError (Aborted,"Could not read filename");
3465 exportXHTML (fname,false);
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="exportXML")
3472 if (parser.parCount()>=2)
3473 // Hey, we even have a filename
3474 fname=parser.parString(ok,1);
3477 parser.setError (Aborted,"Could not read filename");
3480 exportXML (fname,false);
3482 /////////////////////////////////////////////////////////////////////
3483 } else if (com=="getHeading")
3487 parser.setError (Aborted,"Nothing selected");
3488 } else if (parser.checkParCount(0))
3489 returnValue=selti->getHeading();
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="importDir")
3495 parser.setError (Aborted,"Nothing selected");
3496 } else if (! selbi )
3498 parser.setError (Aborted,"Type of selection is not a branch");
3499 } else if (parser.checkParCount(1))
3501 s=parser.parString(ok,0);
3502 if (ok) importDirInt(s);
3504 /////////////////////////////////////////////////////////////////////
3505 } else if (com=="relinkTo")
3509 parser.setError (Aborted,"Nothing selected");
3512 if (parser.checkParCount(4))
3514 // 0 selectstring of parent
3515 // 1 num in parent (for branches)
3516 // 2,3 x,y of mainbranch or mapcenter
3517 s=parser.parString(ok,0);
3518 TreeItem *dst=findBySelectString (s);
3521 if (dst->getType()==TreeItem::Branch)
3523 // Get number in parent
3524 n=parser.parInt (ok,1);
3527 relinkBranch (selbi,(BranchItem*)dst,n);
3528 emitSelectionChanged();
3530 } else if (dst->getType()==TreeItem::MapCenter)
3532 relinkBranch (selbi,(BranchItem*)dst);
3533 // Get coordinates of mainbranch
3534 x=parser.parDouble(ok,2);
3537 y=parser.parDouble(ok,3);
3540 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3541 emitSelectionChanged();
3547 } else if ( selti->getType() == TreeItem::Image)
3549 if (parser.checkParCount(1))
3551 // 0 selectstring of parent
3552 s=parser.parString(ok,0);
3553 TreeItem *dst=findBySelectString (s);
3556 if (dst->isBranchLikeType())
3557 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3559 parser.setError (Aborted,"Destination is not a branch");
3562 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3563 /////////////////////////////////////////////////////////////////////
3564 } else if (com=="loadImage")
3568 parser.setError (Aborted,"Nothing selected");
3569 } else if (! selbi )
3571 parser.setError (Aborted,"Type of selection is not a branch");
3572 } else if (parser.checkParCount(1))
3574 s=parser.parString(ok,0);
3575 if (ok) loadFloatImageInt (selbi,s);
3577 /////////////////////////////////////////////////////////////////////
3578 } else if (com=="moveUp")
3582 parser.setError (Aborted,"Nothing selected");
3583 } else if (! selbi )
3585 parser.setError (Aborted,"Type of selection is not a branch");
3586 } else if (parser.checkParCount(0))
3590 /////////////////////////////////////////////////////////////////////
3591 } else if (com=="moveDown")
3595 parser.setError (Aborted,"Nothing selected");
3596 } else if (! selbi )
3598 parser.setError (Aborted,"Type of selection is not a branch");
3599 } else if (parser.checkParCount(0))
3603 /////////////////////////////////////////////////////////////////////
3604 } else if (com=="move")
3608 parser.setError (Aborted,"Nothing selected");
3609 } else if ( selectionType()!=TreeItem::Branch &&
3610 selectionType()!=TreeItem::MapCenter &&
3611 selectionType()!=TreeItem::Image )
3613 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3614 } else if (parser.checkParCount(2))
3616 x=parser.parDouble (ok,0);
3619 y=parser.parDouble (ok,1);
3623 /////////////////////////////////////////////////////////////////////
3624 } else if (com=="moveRel")
3628 parser.setError (Aborted,"Nothing selected");
3629 } else if ( selectionType()!=TreeItem::Branch &&
3630 selectionType()!=TreeItem::MapCenter &&
3631 selectionType()!=TreeItem::Image )
3633 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3634 } else if (parser.checkParCount(2))
3636 x=parser.parDouble (ok,0);
3639 y=parser.parDouble (ok,1);
3640 if (ok) moveRel (x,y);
3643 /////////////////////////////////////////////////////////////////////
3644 } else if (com=="nop")
3646 /////////////////////////////////////////////////////////////////////
3647 } else if (com=="paste")
3651 parser.setError (Aborted,"Nothing selected");
3652 } else if (! selbi )
3654 parser.setError (Aborted,"Type of selection is not a branch");
3655 } else if (parser.checkParCount(1))
3657 n=parser.parInt (ok,0);
3658 if (ok) pasteNoSave(n);
3660 /////////////////////////////////////////////////////////////////////
3661 } else if (com=="qa")
3665 parser.setError (Aborted,"Nothing selected");
3666 } else if (! selbi )
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(4))
3672 c=parser.parString (ok,0);
3675 parser.setError (Aborted,"No comment given");
3678 s=parser.parString (ok,1);
3681 parser.setError (Aborted,"First parameter is not a string");
3684 t=parser.parString (ok,2);
3687 parser.setError (Aborted,"Condition is not a string");
3690 u=parser.parString (ok,3);
3693 parser.setError (Aborted,"Third parameter is not a string");
3698 parser.setError (Aborted,"Unknown type: "+s);
3703 parser.setError (Aborted,"Unknown operator: "+t);
3708 parser.setError (Aborted,"Type of selection is not a branch");
3711 if (selbi->getHeading() == u)
3713 cout << "PASSED: " << qPrintable (c) << endl;
3716 cout << "FAILED: " << qPrintable (c) << endl;
3726 /////////////////////////////////////////////////////////////////////
3727 } else if (com=="saveImage")
3729 ImageItem *ii=getSelectedImage();
3732 parser.setError (Aborted,"No image selected");
3733 } else if (parser.checkParCount(2))
3735 s=parser.parString(ok,0);
3738 t=parser.parString(ok,1);
3739 if (ok) saveFloatImageInt (ii,t,s);
3742 /////////////////////////////////////////////////////////////////////
3743 } else if (com=="scroll")
3747 parser.setError (Aborted,"Nothing selected");
3748 } else if (! selbi )
3750 parser.setError (Aborted,"Type of selection is not a branch");
3751 } else if (parser.checkParCount(0))
3753 if (!scrollBranch (selbi))
3754 parser.setError (Aborted,"Could not scroll branch");
3756 /////////////////////////////////////////////////////////////////////
3757 } else if (com=="select")
3759 if (parser.checkParCount(1))
3761 s=parser.parString(ok,0);
3764 /////////////////////////////////////////////////////////////////////
3765 } else if (com=="selectLastBranch")
3769 parser.setError (Aborted,"Nothing selected");
3770 } else if (! selbi )
3772 parser.setError (Aborted,"Type of selection is not a branch");
3773 } else if (parser.checkParCount(0))
3775 BranchItem *bi=selbi->getLastBranch();
3777 parser.setError (Aborted,"Could not select last branch");
3778 select (bi); // FIXME-3 was selectInt
3781 /////////////////////////////////////////////////////////////////////
3782 } else /* FIXME-2 if (com=="selectLastImage")
3786 parser.setError (Aborted,"Nothing selected");
3787 } else if (! selbi )
3789 parser.setError (Aborted,"Type of selection is not a branch");
3790 } else if (parser.checkParCount(0))
3792 FloatImageObj *fio=selb->getLastFloatImage();
3794 parser.setError (Aborted,"Could not select last image");
3795 select (fio); // FIXME-3 was selectInt
3798 /////////////////////////////////////////////////////////////////////
3799 } else */ if (com=="selectLatestAdded")
3801 if (!latestAddedItem)
3803 parser.setError (Aborted,"No latest added object");
3806 if (!select (latestAddedItem))
3807 parser.setError (Aborted,"Could not select latest added object ");
3809 /////////////////////////////////////////////////////////////////////
3810 } else if (com=="setFlag")
3814 parser.setError (Aborted,"Nothing selected");
3815 } else if (! selbi )
3817 parser.setError (Aborted,"Type of selection is not a branch");
3818 } else if (parser.checkParCount(1))
3820 s=parser.parString(ok,0);
3822 selbi->activateStandardFlag(s);
3824 /////////////////////////////////////////////////////////////////////
3825 } else if (com=="setFrameType")
3827 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3829 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3831 else if (parser.checkParCount(1))
3833 s=parser.parString(ok,0);
3834 if (ok) setFrameType (s);
3836 /////////////////////////////////////////////////////////////////////
3837 } else if (com=="setFramePenColor")
3839 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3841 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3843 else if (parser.checkParCount(1))
3845 QColor c=parser.parColor(ok,0);
3846 if (ok) setFramePenColor (c);
3848 /////////////////////////////////////////////////////////////////////
3849 } else if (com=="setFrameBrushColor")
3851 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3853 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3855 else if (parser.checkParCount(1))
3857 QColor c=parser.parColor(ok,0);
3858 if (ok) setFrameBrushColor (c);
3860 /////////////////////////////////////////////////////////////////////
3861 } else if (com=="setFramePadding")
3863 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3865 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3867 else if (parser.checkParCount(1))
3869 n=parser.parInt(ok,0);
3870 if (ok) setFramePadding(n);
3872 /////////////////////////////////////////////////////////////////////
3873 } else if (com=="setFrameBorderWidth")
3875 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3877 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3879 else if (parser.checkParCount(1))
3881 n=parser.parInt(ok,0);
3882 if (ok) setFrameBorderWidth (n);
3884 /////////////////////////////////////////////////////////////////////
3885 /* FIXME-2 else if (com=="setFrameType")
3889 parser.setError (Aborted,"Nothing selected");
3892 parser.setError (Aborted,"Type of selection is not a branch");
3893 } else if (parser.checkParCount(1))
3895 s=parser.parString(ok,0);
3899 /////////////////////////////////////////////////////////////////////
3901 /////////////////////////////////////////////////////////////////////
3902 } else if (com=="setHeading")
3906 parser.setError (Aborted,"Nothing selected");
3907 } else if (! selbi )
3909 parser.setError (Aborted,"Type of selection is not a branch");
3910 } else if (parser.checkParCount(1))
3912 s=parser.parString (ok,0);
3916 /////////////////////////////////////////////////////////////////////
3917 } else if (com=="setHideExport")
3921 parser.setError (Aborted,"Nothing selected");
3922 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3924 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3925 } else if (parser.checkParCount(1))
3927 b=parser.parBool(ok,0);
3928 if (ok) setHideExport (b);
3930 /////////////////////////////////////////////////////////////////////
3931 } else if (com=="setIncludeImagesHorizontally")
3935 parser.setError (Aborted,"Nothing selected");
3938 parser.setError (Aborted,"Type of selection is not a branch");
3939 } else if (parser.checkParCount(1))
3941 b=parser.parBool(ok,0);
3942 if (ok) setIncludeImagesHor(b);
3944 /////////////////////////////////////////////////////////////////////
3945 } else if (com=="setIncludeImagesVertically")
3949 parser.setError (Aborted,"Nothing selected");
3952 parser.setError (Aborted,"Type of selection is not a branch");
3953 } else if (parser.checkParCount(1))
3955 b=parser.parBool(ok,0);
3956 if (ok) setIncludeImagesVer(b);
3958 /////////////////////////////////////////////////////////////////////
3959 } else if (com=="setHideLinkUnselected")
3963 parser.setError (Aborted,"Nothing selected");
3964 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3966 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3967 } else if (parser.checkParCount(1))
3969 b=parser.parBool(ok,0);
3970 if (ok) setHideLinkUnselected(b);
3972 /////////////////////////////////////////////////////////////////////
3973 } else if (com=="setMapAuthor")
3975 if (parser.checkParCount(1))
3977 s=parser.parString(ok,0);
3978 if (ok) setAuthor (s);
3980 /////////////////////////////////////////////////////////////////////
3981 } else if (com=="setMapComment")
3983 if (parser.checkParCount(1))
3985 s=parser.parString(ok,0);
3986 if (ok) setComment(s);
3988 /////////////////////////////////////////////////////////////////////
3989 } else if (com=="setMapBackgroundColor")
3993 parser.setError (Aborted,"Nothing selected");
3994 } else if (! selbi )
3996 parser.setError (Aborted,"Type of selection is not a branch");
3997 } else if (parser.checkParCount(1))
3999 QColor c=parser.parColor (ok,0);
4000 if (ok) setMapBackgroundColor (c);
4002 /////////////////////////////////////////////////////////////////////
4003 } else if (com=="setMapDefLinkColor")
4007 parser.setError (Aborted,"Nothing selected");
4008 } else if (! selbi )
4010 parser.setError (Aborted,"Type of selection is not a branch");
4011 } else if (parser.checkParCount(1))
4013 QColor c=parser.parColor (ok,0);
4014 if (ok) setMapDefLinkColor (c);
4016 /////////////////////////////////////////////////////////////////////
4017 } else if (com=="setMapLinkStyle")
4019 if (parser.checkParCount(1))
4021 s=parser.parString (ok,0);
4022 if (ok) setMapLinkStyle(s);
4024 /////////////////////////////////////////////////////////////////////
4025 } else if (com=="setNote")
4029 parser.setError (Aborted,"Nothing selected");
4030 } else if (! selbi )
4032 parser.setError (Aborted,"Type of selection is not a branch");
4033 } else if (parser.checkParCount(1))
4035 s=parser.parString (ok,0);
4039 /////////////////////////////////////////////////////////////////////
4040 } else if (com=="setSelectionColor")
4042 if (parser.checkParCount(1))
4044 QColor c=parser.parColor (ok,0);
4045 if (ok) setSelectionColorInt (c);
4047 /////////////////////////////////////////////////////////////////////
4048 } else if (com=="setURL")
4052 parser.setError (Aborted,"Nothing selected");
4053 } else if (! selbi )
4055 parser.setError (Aborted,"Type of selection is not a branch");
4056 } else if (parser.checkParCount(1))
4058 s=parser.parString (ok,0);
4061 /////////////////////////////////////////////////////////////////////
4062 } else if (com=="setVymLink")
4066 parser.setError (Aborted,"Nothing selected");
4067 } else if (! selbi )
4069 parser.setError (Aborted,"Type of selection is not a branch");
4070 } else if (parser.checkParCount(1))
4072 s=parser.parString (ok,0);
4073 if (ok) setVymLink(s);
4075 } else if (com=="sortChildren")
4079 parser.setError (Aborted,"Nothing selected");
4080 } else if (! selbi )
4082 parser.setError (Aborted,"Type of selection is not a branch");
4083 } else if (parser.checkParCount(0))
4086 } else if (parser.checkParCount(1))
4088 b=parser.parBool(ok,0);
4089 if (ok) sortChildren(b);
4091 /////////////////////////////////////////////////////////////////////
4092 } else if (com=="toggleFlag")
4096 parser.setError (Aborted,"Nothing selected");
4097 } else if (! selbi )
4099 parser.setError (Aborted,"Type of selection is not a branch");
4100 } else if (parser.checkParCount(1))
4102 s=parser.parString(ok,0);
4104 selbi->toggleStandardFlag(s);
4106 /////////////////////////////////////////////////////////////////////
4107 } else if (com=="unscroll")
4111 parser.setError (Aborted,"Nothing selected");
4112 } else if (! selbi )
4114 parser.setError (Aborted,"Type of selection is not a branch");
4115 } else if (parser.checkParCount(0))
4117 if (!unscrollBranch (selbi))
4118 parser.setError (Aborted,"Could not unscroll branch");
4120 /////////////////////////////////////////////////////////////////////
4121 } else if (com=="unscrollChildren")
4125 parser.setError (Aborted,"Nothing selected");
4126 } else if (! selbi )
4128 parser.setError (Aborted,"Type of selection is not a branch");
4129 } else if (parser.checkParCount(0))
4131 unscrollChildren ();
4133 /////////////////////////////////////////////////////////////////////
4134 } else if (com=="unsetFlag")
4138 parser.setError (Aborted,"Nothing selected");
4139 } else if (! selbi )
4141 parser.setError (Aborted,"Type of selection is not a branch");
4142 } else if (parser.checkParCount(1))
4144 s=parser.parString(ok,0);
4146 selbi->deactivateStandardFlag(s);
4149 parser.setError (Aborted,"Unknown command");
4152 if (parser.errorLevel()==NoError)
4154 // setChanged(); FIXME-2 should not be called e.g. for export?!
4161 // TODO Error handling
4162 qWarning("VymModel::parseAtom: Error!");
4164 qWarning(parser.errorMessage());
4166 errorMsg=parser.errorMessage();
4171 QVariant VymModel::runScript (const QString &script)
4173 parser.setScript (script);
4178 while (parser.next() && noErr)
4180 r=parseAtom(parser.getAtom(),noErr,errMsg);
4181 if (!noErr) //FIXME-3 need dialog box here
4182 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4187 void VymModel::setExportMode (bool b)
4189 // should be called before and after exports
4190 // depending on the settings
4191 if (b && settings.value("/export/useHideExport","true")=="true")
4192 setHideTmpMode (TreeItem::HideExport);
4194 setHideTmpMode (TreeItem::HideNone);
4197 void VymModel::exportImage(QString fname, bool askName, QString format)
4201 fname=getMapName()+".png";
4208 QFileDialog *fd=new QFileDialog (NULL);
4209 fd->setCaption (tr("Export map as image"));
4210 fd->setDirectory (lastImageDir);
4211 fd->setFileMode(QFileDialog::AnyFile);
4212 fd->setFilters (imageIO.getFilters() );
4215 fl=fd->selectedFiles();
4217 format=imageIO.getType(fd->selectedFilter());
4221 setExportMode (true);
4222 mapEditor->getScene()->update(); // FIXME-3 check this...
4223 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4224 img.save(fname, format);
4225 setExportMode (false);
4229 void VymModel::exportXML(QString dir, bool askForName)
4233 dir=browseDirectory(NULL,tr("Export XML to directory"));
4234 if (dir =="" && !reallyWriteDirectory(dir) )
4238 // Hide stuff during export, if settings want this
4239 setExportMode (true);
4241 // Create subdirectories
4244 // write to directory //FIXME-4 check totalBBox here...
4245 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4248 file.setName ( dir + "/"+mapName+".xml");
4249 if ( !file.open( QIODevice::WriteOnly ) )
4251 // This should neverever happen
4252 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4256 // Write it finally, and write in UTF8, no matter what
4257 QTextStream ts( &file );
4258 ts.setEncoding (QTextStream::UnicodeUTF8);
4262 // Now write image, too
4263 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4265 setExportMode (false);
4268 void VymModel::exportAO (QString fname,bool askName)
4273 ex.setFile (mapName+".txt");
4279 //ex.addFilter ("TXT (*.txt)");
4280 ex.setDir(lastImageDir);
4281 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4286 setExportMode(true);
4288 setExportMode(false);
4292 void VymModel::exportASCII(QString fname,bool askName)
4297 ex.setFile (mapName+".txt");
4303 //ex.addFilter ("TXT (*.txt)");
4304 ex.setDir(lastImageDir);
4305 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4310 setExportMode(true);
4312 setExportMode(false);
4316 void VymModel::exportHTML (const QString &dir, bool askForName) //FIXME-2 own dialogue missing and also option to save settings in map
4318 ExportXHTMLDialog dia(NULL);
4319 dia.setFilePath (filePath );
4320 dia.setMapName (mapName );
4322 if (dir!="") dia.setDir (dir);
4328 if (dia.exec()!=QDialog::Accepted)
4333 // Check, if warnings should be used before overwriting
4334 // the output directory
4335 if (d.exists() && d.count()>0)
4338 warn.showCancelButton (true);
4339 warn.setText(QString(
4340 "The directory %1 is not empty.\n"
4341 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4342 warn.setCaption("Warning: Directory not empty");
4343 warn.setShowAgainName("mainwindow/export-XML-overwrite-dir");
4345 if (warn.exec()!=QDialog::Accepted) ok=false;
4351 // Hide stuff during export, if settings want this
4352 setExportMode (true);
4354 ExportHTML ex (this);
4355 ex.setFile (d.path()+"/"+mapName+".html");
4356 cout << "VM::exportHTML writing "<<ex.getFile().toStdString()<<endl;
4358 setExportMode (false);
4360 //exportXML (dia.getDir(),false );
4361 //dia.doExport(mapName );
4362 //if (dia.hasChanged()) setChanged();
4365 exportImage (d.path()+"/"+mapName+".png",false,"PNG");
4370 void VymModel::exportXHTML (const QString &dir, bool askForName)
4372 ExportXHTMLDialog dia(NULL);
4373 dia.setFilePath (filePath );
4374 dia.setMapName (mapName );
4376 if (dir!="") dia.setDir (dir);
4382 if (dia.exec()!=QDialog::Accepted)
4386 QDir d (dia.getDir());
4387 // Check, if warnings should be used before overwriting
4388 // the output directory
4389 if (d.exists() && d.count()>0)
4392 warn.showCancelButton (true);
4393 warn.setText(QString(
4394 "The directory %1 is not empty.\n"
4395 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4396 warn.setCaption("Warning: Directory not empty");
4397 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4399 if (warn.exec()!=QDialog::Accepted) ok=false;
4406 exportXML (dia.getDir(),false );
4407 dia.doExport(mapName );
4408 //if (dia.hasChanged()) setChanged();
4412 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4417 if (ex.setConfigFile(cf))
4419 setExportMode (true);
4420 ex.exportPresentation();
4421 setExportMode (false);
4428 //////////////////////////////////////////////
4430 //////////////////////////////////////////////
4432 void VymModel::registerEditor(QWidget *me)
4434 mapEditor=(MapEditor*)me;
4437 void VymModel::unregisterEditor(QWidget *)
4442 void VymModel::setContextPos(QPointF p)
4447 void VymModel::unsetContextPos()
4449 contextPos=QPointF();
4452 void VymModel::updateNoteFlag()
4454 TreeItem *selti=getSelectedItem();
4463 if (textEditor->isEmpty())
4466 selti->setNote (textEditor->getText());
4467 emitDataHasChanged(selti);
4471 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4473 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4474 if (blockReposition) return;
4476 for (int i=0;i<rootItem->branchCount(); i++)
4477 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4478 //emitSelectionChanged();
4482 void VymModel::setMapLinkStyle (const QString & s)
4487 case LinkableMapObj::Line :
4490 case LinkableMapObj::Parabel:
4491 snow="StyleParabel";
4493 case LinkableMapObj::PolyLine:
4494 snow="StylePolyLine";
4496 case LinkableMapObj::PolyParabel:
4497 snow="StylePolyParabel";
4500 snow="UndefinedStyle";
4505 QString("setMapLinkStyle (\"%1\")").arg(s),
4506 QString("setMapLinkStyle (\"%1\")").arg(snow),
4507 QString("Set map link style (\"%1\")").arg(s)
4511 linkstyle=LinkableMapObj::Line;
4512 else if (s=="StyleParabel")
4513 linkstyle=LinkableMapObj::Parabel;
4514 else if (s=="StylePolyLine")
4515 linkstyle=LinkableMapObj::PolyLine;
4516 else if (s=="StylePolyParabel")
4517 linkstyle=LinkableMapObj::PolyParabel;
4519 linkstyle=LinkableMapObj::UndefinedStyle;
4521 BranchItem *cur=NULL;
4522 BranchItem *prev=NULL;
4524 nextBranch (cur,prev);
4527 bo=(BranchObj*)(cur->getLMO() );
4528 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4529 cur=nextBranch(cur,prev);
4534 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4539 void VymModel::setMapDefLinkColor(QColor col)
4541 if ( !col.isValid() ) return;
4543 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4544 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4545 QString("Set map link color to %1").arg(col.name())
4549 BranchItem *cur=NULL;
4550 BranchItem *prev=NULL;
4552 cur=nextBranch(cur,prev);
4555 bo=(BranchObj*)(cur->getLMO() );
4557 nextBranch(cur,prev);
4562 void VymModel::setMapLinkColorHintInt()
4564 // called from setMapLinkColorHint(lch) or at end of parse
4565 BranchItem *cur=NULL;
4566 BranchItem *prev=NULL;
4568 cur=nextBranch(cur,prev);
4571 bo=(BranchObj*)(cur->getLMO() );
4573 cur=nextBranch(cur,prev);
4577 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4580 setMapLinkColorHintInt();
4583 void VymModel::toggleMapLinkColorHint()
4585 if (linkcolorhint==LinkableMapObj::HeadingColor)
4586 linkcolorhint=LinkableMapObj::DefaultColor;
4588 linkcolorhint=LinkableMapObj::HeadingColor;
4589 BranchItem *cur=NULL;
4590 BranchItem *prev=NULL;
4592 cur=nextBranch(cur,prev);
4595 bo=(BranchObj*)(cur->getLMO() );
4597 nextBranch(cur,prev);
4601 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4603 Q3FileDialog *fd=new Q3FileDialog( NULL);
4604 fd->setMode (Q3FileDialog::ExistingFile);
4605 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4606 ImagePreview *p =new ImagePreview (fd);
4607 fd->setContentsPreviewEnabled( TRUE );
4608 fd->setContentsPreview( p, p );
4609 fd->setPreviewMode( Q3FileDialog::Contents );
4610 fd->setCaption(vymName+" - " +tr("Load background image"));
4611 fd->setDir (lastImageDir);
4614 if ( fd->exec() == QDialog::Accepted )
4616 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4617 lastImageDir=QDir (fd->dirPath());
4618 setMapBackgroundImage (fd->selectedFile());
4622 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4624 QColor oldcol=mapScene->backgroundBrush().color();
4628 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4630 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4631 QString("Set background color of map to %1").arg(col.name()));
4634 brush.setTextureImage (QPixmap (fn));
4635 mapScene->setBackgroundBrush(brush);
4638 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4640 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4641 if ( !col.isValid() ) return;
4642 setMapBackgroundColor( col );
4646 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4648 QColor oldcol=mapScene->backgroundBrush().color();
4650 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4651 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4652 QString("Set background color of map to %1").arg(col.name()));
4653 mapScene->setBackgroundBrush(col);
4656 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4658 return mapScene->backgroundBrush().color();
4662 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4664 return linkcolorhint;
4667 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4669 return defLinkColor;
4672 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4677 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4679 return defXLinkColor;
4682 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4687 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4689 return defXLinkWidth;
4692 void VymModel::move(const double &x, const double &y)
4695 MapItem *seli = (MapItem*)getSelectedItem();
4696 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4698 LinkableMapObj *lmo=seli->getLMO();
4701 QPointF ap(lmo->getAbsPos());
4705 QString ps=qpointFToString(ap);
4706 QString s=getSelectString(seli);
4709 s, "move "+qpointFToString(to),
4710 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4713 emitSelectionChanged();
4719 void VymModel::moveRel (const double &x, const double &y)
4722 MapItem *seli = (MapItem*)getSelectedItem();
4723 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4725 LinkableMapObj *lmo=seli->getLMO();
4728 QPointF rp(lmo->getRelPos());
4732 QString ps=qpointFToString (lmo->getRelPos());
4733 QString s=getSelectString(seli);
4736 s, "moveRel "+qpointFToString(to),
4737 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4738 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4740 lmo->updateLinkGeometry();
4741 emitSelectionChanged();
4748 void VymModel::animate()
4750 animationTimer->stop();
4753 while (i<animObjList.size() )
4755 bo=(BranchObj*)animObjList.at(i);
4760 animObjList.removeAt(i);
4767 QItemSelection sel=selModel->selection();
4768 emit (selectionChanged(sel,sel));
4771 if (!animObjList.isEmpty()) animationTimer->start();
4775 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4777 if (start==dest) return;
4778 if (bo && bo->getTreeItem()->depth()>0)
4781 ap.setStart (start);
4783 ap.setTicks (animationTicks);
4784 ap.setAnimated (true);
4785 bo->setAnimation (ap);
4786 animObjList.append( bo );
4787 animationTimer->setSingleShot (true);
4788 animationTimer->start(animationInterval);
4792 void VymModel::stopAnimation (MapObj *mo)
4794 int i=animObjList.indexOf(mo);
4796 animObjList.removeAt (i);
4799 void VymModel::sendSelection()
4801 if (netstate!=Server) return;
4802 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4805 void VymModel::newServer()
4809 tcpServer = new QTcpServer(this);
4810 if (!tcpServer->listen(QHostAddress::Any,port)) {
4811 QMessageBox::critical(NULL, "vym server",
4812 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4813 //FIXME-3 needed? we are no widget any longer... close();
4816 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4818 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4821 void VymModel::connectToServer()
4824 server="salam.suse.de";
4826 clientSocket = new QTcpSocket (this);
4827 clientSocket->abort();
4828 clientSocket->connectToHost(server ,port);
4829 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4830 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4831 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4833 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4838 void VymModel::newClient()
4840 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4841 connect(newClient, SIGNAL(disconnected()),
4842 newClient, SLOT(deleteLater()));
4844 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4846 clientList.append (newClient);
4850 void VymModel::sendData(const QString &s)
4852 if (clientList.size()==0) return;
4854 // Create bytearray to send
4856 QDataStream out(&block, QIODevice::WriteOnly);
4857 out.setVersion(QDataStream::Qt_4_0);
4859 // Reserve some space for blocksize
4862 // Write sendCounter
4863 out << sendCounter++;
4868 // Go back and write blocksize so far
4869 out.device()->seek(0);
4870 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4874 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4876 for (int i=0; i<clientList.size(); ++i)
4878 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4879 clientList.at(i)->write (block);
4883 void VymModel::readData ()
4885 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4888 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4892 QDataStream in(clientSocket);
4893 in.setVersion(QDataStream::Qt_4_0);
4901 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4904 parseAtom (t,noErr,errMsg);
4910 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4912 switch (socketError) {
4913 case QAbstractSocket::RemoteHostClosedError:
4915 case QAbstractSocket::HostNotFoundError:
4916 QMessageBox::information(NULL, vymName +" Network client",
4917 "The host was not found. Please check the "
4918 "host name and port settings.");
4920 case QAbstractSocket::ConnectionRefusedError:
4921 QMessageBox::information(NULL, vymName + " Network client",
4922 "The connection was refused by the peer. "
4923 "Make sure the fortune server is running, "
4924 "and check that the host name and port "
4925 "settings are correct.");
4928 QMessageBox::information(NULL, vymName + " Network client",
4929 QString("The following error occurred: %1.")
4930 .arg(clientSocket->errorString()));
4934 /* FIXME-3 Playing with DBUS...
4935 QDBusVariant VymModel::query (const QString &query)
4937 TreeItem *selti=getSelectedItem();
4939 return QDBusVariant (selti->getHeading());
4941 return QDBusVariant ("Nothing selected.");
4945 void VymModel::testslot() //FIXME-3 Playing with DBUS
4947 cout << "VM::testslot called\n";
4950 void VymModel::selectMapSelectionColor()
4952 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4953 setSelectionColor (col);
4956 void VymModel::setSelectionColorInt (QColor col)
4958 if ( !col.isValid() ) return;
4960 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4961 QString("setSelectionColor (%1)").arg(col.name()),
4962 QString("Set color of selection box to %1").arg(col.name())
4965 mapEditor->setSelectionColor (col);
4968 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4970 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4971 //FIXME-3 emitShowSelection();
4975 void VymModel::emitSelectionChanged()
4977 QItemSelection newsel=selModel->selection();
4978 emitSelectionChanged (newsel);
4981 void VymModel::setSelectionColor(QColor col)
4983 if ( !col.isValid() ) return;
4985 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4986 QString("setSelectionColor (%1)").arg(col.name()),
4987 QString("Set color of selection box to %1").arg(col.name())
4989 setSelectionColorInt (col);
4992 QColor VymModel::getSelectionColor()
4994 return mapEditor->getSelectionColor();
4997 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
5000 for (int i=0;i<rootItem->branchCount();i++)
5001 rootItem->getBranchNum(i)->setHideTmp (mode);
5003 if (mode==TreeItem::HideExport)
5009 //////////////////////////////////////////////
5010 // Selection related
5011 //////////////////////////////////////////////
5013 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5018 QItemSelectionModel* VymModel::getSelectionModel()
5023 void VymModel::setSelectionBlocked (bool b)
5028 bool VymModel::isSelectionBlocked()
5030 return selectionBlocked;
5033 bool VymModel::select ()
5035 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5038 bool VymModel::select (const QString &s)
5045 TreeItem *ti=findBySelectString(s);
5046 if (ti) return select (index(ti));
5050 bool VymModel::select (LinkableMapObj *lmo)
5052 QItemSelection oldsel=selModel->selection();
5055 return select (index (lmo->getTreeItem()) );
5060 bool VymModel::select (TreeItem *ti)
5062 if (ti) return select (index(ti));
5066 bool VymModel::select (const QModelIndex &index)
5068 if (index.isValid() )
5070 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5071 BranchItem *bi=getSelectedBranch();
5072 if (bi) bi->setLastSelectedBranch();
5078 void VymModel::unselect()
5080 if (!selModel->selectedIndexes().isEmpty())
5082 lastSelectString=getSelectString();
5083 selModel->clearSelection();
5087 bool VymModel::reselect()
5089 return select (lastSelectString);
5092 void VymModel::emitShowSelection()
5094 if (!blockReposition)
5095 emit (showSelection() );
5098 void VymModel::emitNoteHasChanged (TreeItem *ti)
5100 QModelIndex ix=index(ti);
5101 emit (noteHasChanged (ix) );
5104 void VymModel::emitDataHasChanged (TreeItem *ti)
5106 QModelIndex ix=index(ti);
5107 emit (dataChanged (ix,ix) );
5111 bool VymModel::selectFirstBranch()
5113 TreeItem *ti=getSelectedBranch();
5116 TreeItem *par=ti->parent();
5119 TreeItem *ti2=par->getFirstBranch();
5120 if (ti2) return select(ti2);
5126 bool VymModel::selectLastBranch()
5128 TreeItem *ti=getSelectedBranch();
5131 TreeItem *par=ti->parent();
5134 TreeItem *ti2=par->getLastBranch();
5135 if (ti2) return select(ti2);
5141 bool VymModel::selectLastSelectedBranch()
5143 BranchItem *bi=getSelectedBranch();
5146 bi=bi->getLastSelectedBranch();
5147 if (bi) return select (bi);
5152 bool VymModel::selectParent()
5154 TreeItem *ti=getSelectedItem();
5165 TreeItem::Type VymModel::selectionType()
5167 QModelIndexList list=selModel->selectedIndexes();
5168 if (list.isEmpty()) return TreeItem::Undefined;
5169 TreeItem *ti = getItem (list.first() );
5170 return ti->getType();
5174 LinkableMapObj* VymModel::getSelectedLMO()
5176 QModelIndexList list=selModel->selectedIndexes();
5177 if (!list.isEmpty() )
5179 TreeItem *ti = getItem (list.first() );
5180 TreeItem::Type type=ti->getType();
5181 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5182 return ((MapItem*)ti)->getLMO();
5187 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5189 TreeItem *ti = getSelectedBranch();
5191 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5196 BranchItem* VymModel::getSelectedBranch()
5198 QModelIndexList list=selModel->selectedIndexes();
5199 if (!list.isEmpty() )
5201 TreeItem *ti = getItem (list.first() );
5202 TreeItem::Type type=ti->getType();
5203 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5204 return (BranchItem*)ti;
5209 ImageItem* VymModel::getSelectedImage()
5211 QModelIndexList list=selModel->selectedIndexes();
5212 if (!list.isEmpty())
5214 TreeItem *ti=getItem (list.first());
5215 if (ti && ti->getType()==TreeItem::Image)
5216 return (ImageItem*)ti;
5221 AttributeItem* VymModel::getSelectedAttribute()
5223 QModelIndexList list=selModel->selectedIndexes();
5224 if (!list.isEmpty() )
5226 TreeItem *ti = getItem (list.first() );
5227 TreeItem::Type type=ti->getType();
5228 if (type ==TreeItem::Attribute)
5229 return (AttributeItem*)ti;
5234 TreeItem* VymModel::getSelectedItem()
5236 QModelIndexList list=selModel->selectedIndexes();
5237 if (!list.isEmpty() )
5238 return getItem (list.first() );
5243 QModelIndex VymModel::getSelectedIndex()
5245 QModelIndexList list=selModel->selectedIndexes();
5246 if (list.isEmpty() )
5247 return QModelIndex();
5249 return list.first();
5252 QString VymModel::getSelectString ()
5254 return getSelectString (getSelectedItem());
5257 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5259 if (!lmo) return QString();
5260 return getSelectString (lmo->getTreeItem() );
5263 QString VymModel::getSelectString (TreeItem *ti)
5267 switch (ti->getType())
5269 case TreeItem::MapCenter: s="mc:"; break;
5270 case TreeItem::Branch: s="bo:";break;
5271 case TreeItem::Image: s="fi:";break;
5272 case TreeItem::Attribute: s="ai:";break;
5273 case TreeItem::XLink: s="xl:";break;
5275 s="unknown type in VymModel::getSelectString()";
5278 s= s + QString("%1").arg(ti->num());
5280 // call myself recursively
5281 s= getSelectString(ti->parent()) +","+s;