1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
13 #include "exportxhtmldialog.h"
15 #include "findresultmodel.h"
16 #include "geometry.h" // for addBBox
17 #include "mainwindow.h"
22 #include "warningdialog.h"
23 #include "xlinkitem.h"
24 #include "xml-freemind.h"
30 extern Main *mainWindow;
31 extern QDBusConnection dbusConnection;
33 extern Settings settings;
34 extern QString tmpVymDir;
36 extern TextEditor *textEditor;
37 extern FlagRow *standardFlagsMaster;
39 extern QString clipboardDir;
40 extern QString clipboardFile;
41 extern bool clipboardEmpty;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
47 extern QDir vymBaseDir;
49 extern QDir lastImageDir;
50 extern QDir lastFileDir;
52 extern Settings settings;
54 uint VymModel::idLast=0; // make instance
58 //cout << "Const VymModel\n";
60 rootItem->setModel (this);
66 //cout << "Destr VymModel\n";
67 autosaveTimer->stop();
68 fileChangedTimer->stop();
70 if (mapEditor) delete (mapEditor);
73 void VymModel::clear()
76 while (rootItem->childCount() >0)
77 deleteItem (rootItem->getChildNum(0) );
80 void VymModel::init ()
85 // Also no scene yet (should not be needed anyway) FIXME-3 VM
99 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
100 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
101 mainWindow->updateHistory (undoSet);
104 makeTmpDirectories();
109 fileName=tr("unnamed");
111 blockReposition=false;
112 blockSaveState=false;
114 autosaveTimer=new QTimer (this);
115 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
117 fileChangedTimer=new QTimer (this);
118 fileChangedTimer->start(3000);
119 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
124 selectionBlocked=false;
129 // animations // FIXME-3 switch to new animation system
130 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
131 animationTicks=settings.readNumEntry("/animation/ticks",10);
132 animationInterval=settings.readNumEntry("/animation/interval",50);
134 animationTimer=new QTimer (this);
135 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
138 defLinkColor=QColor (0,0,255);
139 defXLinkColor=QColor (180,180,180);
140 linkcolorhint=LinkableMapObj::DefaultColor;
141 linkstyle=LinkableMapObj::PolyParabel;
143 defXLinkColor=QColor (230,230,230);
146 hidemode=TreeItem::HideNone;
151 //Initialize DBUS object
152 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
153 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
154 qWarning ("VymModel: Couldn't register DBUS object!");
157 void VymModel::makeTmpDirectories()
159 // Create unique temporary directories
160 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
161 histPath = tmpMapDir+"/history";
167 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
172 bool VymModel::isRepositionBlocked()
174 return blockReposition;
177 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
179 //cout << "VM::updateActions \n";
180 // Tell mainwindow to update states of actions
181 mainWindow->updateActions();
186 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
188 // tmpdir temporary directory to which data will be written
189 // prefix mapname, which will be appended to images etc.
190 // writeflags Only write flags for "real" save of map, not undo
191 // offset offset of bbox of whole map in scene.
192 // Needed for XML export
201 case LinkableMapObj::Line:
204 case LinkableMapObj::Parabel:
207 case LinkableMapObj::PolyLine:
211 ls="StylePolyParabel";
215 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
217 if (linkcolorhint==LinkableMapObj::HeadingColor)
218 colhint=xml.attribut("linkColorHint","HeadingColor");
220 QString mapAttr=xml.attribut("version",vymVersion);
222 mapAttr+= xml.attribut("author",author) +
223 xml.attribut("comment",comment) +
224 xml.attribut("date",getDate()) +
225 xml.attribut("branchCount", QString().number(branchCount())) +
226 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
227 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
228 xml.attribut("linkStyle", ls ) +
229 xml.attribut("linkColor", defLinkColor.name() ) +
230 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
231 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
232 xml.attribut("mapZoomFactor", QString().setNum(mapEditor->getZoomFactorTarget()) ) +
234 s+=xml.beginElement("vymmap",mapAttr);
237 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
238 standardFlagsMaster->resetUsedCounter();
240 // Build xml recursivly
242 // Save all mapcenters as complete map, if saveSel not set
243 s+=saveTreeToDir(tmpdir,prefix,offset);
246 switch (saveSel->getType())
248 case TreeItem::Branch:
250 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
252 case TreeItem::MapCenter:
254 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
256 case TreeItem::Image:
258 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
261 // other types shouldn't be safed directly...
266 // Save local settings
267 s+=settings.getDataXML (destPath);
270 if (getSelectedItem() && !saveSel )
271 s+=xml.valueElement("select",getSelectString());
274 s+=xml.endElement("vymmap");
276 //cout << s.toStdString() << endl;
278 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
282 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
286 for (int i=0; i<rootItem->branchCount(); i++)
287 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
291 void VymModel::setFilePath(QString fpath, QString destname)
293 if (fpath.isEmpty() || fpath=="")
300 filePath=fpath; // becomes absolute path
301 fileName=fpath; // gets stripped of path
302 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
304 // If fpath is not an absolute path, complete it
305 filePath=QDir(fpath).absPath();
306 fileDir=filePath.left (1+filePath.findRev ("/"));
308 // Set short name, too. Search from behind:
309 int i=fileName.findRev("/");
310 if (i>=0) fileName=fileName.remove (0,i+1);
312 // Forget the .vym (or .xml) for name of map
313 mapName=fileName.left(fileName.findRev(".",-1,true) );
317 void VymModel::setFilePath(QString fpath)
319 setFilePath (fpath,fpath);
322 QString VymModel::getFilePath()
327 QString VymModel::getFileName()
332 QString VymModel::getMapName()
337 QString VymModel::getDestPath()
342 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
344 ErrorCode err=success;
346 parseBaseHandler *handler;
350 case VymMap: handler=new parseVYMHandler; break;
351 case FreemindMap : handler=new parseFreemindHandler; break;
353 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
354 "Unknown FileType in VymModel::load()");
358 bool zipped_org=zipped;
362 selModel->clearSelection();
365 BranchItem *bi=getSelectedBranch();
366 if (!bi) return aborted;
367 if (lmode==ImportAdd)
368 saveStateChangingPart(
371 QString("addMapInsert (%1)").arg(fname),
372 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
374 saveStateChangingPart(
377 QString("addMapReplace(%1)").arg(fname),
378 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
382 // Create temporary directory for packing
384 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
387 QMessageBox::critical( 0, tr( "Critical Load Error" ),
388 tr("Couldn't create temporary directory before load\n"));
393 err=unzipDir (tmpZipDir,fname);
403 // Look for mapname.xml
404 xmlfile= fname.left(fname.findRev(".",-1,true));
405 xmlfile=xmlfile.section( '/', -1 );
406 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
407 if (!mfile.exists() )
409 // mapname.xml does not exist, well,
410 // maybe someone renamed the mapname.vym file...
411 // Try to find any .xml in the toplevel
412 // directory of the .vym file
413 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
414 if (flist.count()==1)
416 // Only one entry, take this one
417 xmlfile=tmpZipDir + "/"+flist.first();
420 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
421 *it=tmpZipDir + "/" + *it;
422 // TODO Multiple entries, load all (but only the first one into this ME)
423 //mainWindow->fileLoadFromTmp (flist);
424 //returnCode=1; // Silently forget this attempt to load
425 qWarning ("MainWindow::load (fn) multimap found...");
428 if (flist.isEmpty() )
430 QMessageBox::critical( 0, tr( "Critical Load Error" ),
431 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
434 } //file doesn't exist
436 xmlfile=mfile.name();
439 QFile file( xmlfile);
441 // I am paranoid: file should exist anyway
442 // according to check in mainwindow.
445 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
446 tr(QString("Couldn't open map %1").arg(file.name())));
450 bool blockSaveStateOrg=blockSaveState;
451 blockReposition=true;
453 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
454 QXmlInputSource source( file);
455 QXmlSimpleReader reader;
456 reader.setContentHandler( handler );
457 reader.setErrorHandler( handler );
458 handler->setModel ( this);
461 // We need to set the tmpDir in order to load files with rel. path
466 tmpdir=fname.left(fname.findRev("/",-1));
467 handler->setTmpDir (tmpdir);
468 handler->setInputFile (file.name());
469 handler->setLoadMode (lmode);
470 bool ok = reader.parse( source );
471 blockReposition=false;
472 blockSaveState=blockSaveStateOrg;
473 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
478 emitSelectionChanged();
484 autosaveTimer->stop();
487 // Reset timestamp to check for later updates of file
488 fileChangedTime=QFileInfo (destPath).lastModified();
491 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
492 tr( handler->errorProtocol() ) );
494 // Still return "success": the map maybe at least
495 // partially read by the parser
500 removeDir (QDir(tmpZipDir));
502 // Restore original zip state
507 if (mapEditor) mapEditor->setZoomFactorTarget (zoomFactor);
509 //Update view (scene()->update() is not enough)
510 qApp->processEvents(); // Update view (scene()->update() is not enough)
514 ErrorCode VymModel::save (const SaveMode &savemode)
518 QString safeFilePath;
520 ErrorCode err=success;
524 mapFileName=mapName+".xml";
526 // use name given by user, even if he chooses .doc
527 mapFileName=fileName;
529 // Look, if we should zip the data:
532 QMessageBox mb( vymName,
533 tr("The map %1\ndid not use the compressed "
534 "vym file format.\nWriting it uncompressed will also write images \n"
535 "and flags and thus may overwrite files in the "
536 "given directory\n\nDo you want to write the map").arg(filePath),
537 QMessageBox::Warning,
538 QMessageBox::Yes | QMessageBox::Default,
540 QMessageBox::Cancel | QMessageBox::Escape);
541 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
542 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
543 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
546 case QMessageBox::Yes:
547 // save compressed (default file format)
550 case QMessageBox::No:
554 case QMessageBox::Cancel:
561 // First backup existing file, we
562 // don't want to add to old zip archives
566 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
568 QString backupFileName(destPath + "~");
569 QFile backupFile(backupFileName);
570 if (backupFile.exists() && !backupFile.remove())
572 QMessageBox::warning(0, tr("Save Error"),
573 tr("%1\ncould not be removed before saving").arg(backupFileName));
575 else if (!f.rename(backupFileName))
577 QMessageBox::warning(0, tr("Save Error"),
578 tr("%1\ncould not be renamed before saving").arg(destPath));
585 // Create temporary directory for packing
587 tmpZipDir=makeTmpDir (ok,"vym-zip");
590 QMessageBox::critical( 0, tr( "Critical Load Error" ),
591 tr("Couldn't create temporary directory before save\n"));
595 safeFilePath=filePath;
596 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
599 // Create mapName and fileDir
600 makeSubDirs (fileDir);
603 if (savemode==CompleteMap || selModel->selection().isEmpty())
606 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
609 autosaveTimer->stop();
614 if (selectionType()==TreeItem::Image)
617 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
618 // TODO take care of multiselections
621 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
624 qWarning ("ME::saveStringToDisk failed!");
630 if (err==success) err=zipDir (tmpZipDir,destPath);
633 removeDir (QDir(tmpZipDir));
635 // Restore original filepath outside of tmp zip dir
636 setFilePath (safeFilePath);
640 fileChangedTime=QFileInfo (destPath).lastModified();
644 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
646 QString pathDir=path.left(path.findRev("/"));
652 // We need to parse saved XML data
653 parseVYMHandler handler;
654 QXmlInputSource source( file);
655 QXmlSimpleReader reader;
656 reader.setContentHandler( &handler );
657 reader.setErrorHandler( &handler );
658 handler.setModel ( this);
659 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
660 if (undoSel.isEmpty())
664 handler.setLoadMode (NewMap);
668 handler.setLoadMode (ImportReplace);
670 blockReposition=true;
671 bool ok = reader.parse( source );
672 blockReposition=false;
675 // This should never ever happen
676 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
677 handler.errorProtocol());
680 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
683 bool VymModel::addMapInsertInt (const QString &path)
685 QString pathDir=path.left(path.findRev("/"));
691 // We need to parse saved XML data
692 parseVYMHandler handler;
693 QXmlInputSource source( file);
694 QXmlSimpleReader reader;
695 reader.setContentHandler( &handler );
696 reader.setErrorHandler( &handler );
697 handler.setModel (this);
698 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
699 handler.setLoadMode (ImportAdd);
700 blockReposition=true;
701 bool ok = reader.parse( source );
702 blockReposition=false;
703 if ( ok ) return true;
705 // This should never ever happen
706 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
707 handler.errorProtocol());
710 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
714 bool VymModel::addMapInsertInt (const QString &path, int pos)
716 BranchItem *selbi=getSelectedBranch();
719 if (addMapInsertInt (path))
721 if (selbi->depth()>0)
722 relinkBranch (selbi->getLastBranch(), selbi,pos);
726 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
730 qWarning ("ME::addMapInsertInt nothing selected");
734 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
736 ImageItem *ii=createImage(dst);
746 void VymModel::loadFloatImage ()
748 BranchItem *selbi=getSelectedBranch();
752 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
753 fd->setMode (Q3FileDialog::ExistingFiles);
754 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
755 ImagePreview *p =new ImagePreview (fd);
756 fd->setContentsPreviewEnabled( TRUE );
757 fd->setContentsPreview( p, p );
758 fd->setPreviewMode( Q3FileDialog::Contents );
759 fd->setCaption(vymName+" - " +tr("Load image"));
760 fd->setDir (lastImageDir);
763 if ( fd->exec() == QDialog::Accepted )
765 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
766 lastImageDir=QDir (fd->dirPath());
769 for (int j=0; j<fd->selectedFiles().count(); j++)
771 s=fd->selectedFiles().at(j);
772 ii=loadFloatImageInt (selbi,s);
773 //FIXME-3 check savestate for loadImage
779 QString ("loadImage (%1)").arg(s ),
780 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
783 // TODO loadFIO error handling
784 qWarning ("Failed to load "+s);
792 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
797 void VymModel::saveFloatImage ()
799 ImageItem *ii=getSelectedImage();
802 QFileDialog *fd=new QFileDialog( NULL);
803 fd->setFilters (imageIO.getFilters());
804 fd->setCaption(vymName+" - " +tr("Save image"));
805 fd->setFileMode( QFileDialog::AnyFile );
806 fd->setDirectory (lastImageDir);
807 // fd->setSelection (fio->getOriginalFilename());
811 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
813 fn=fd->selectedFiles().at(0);
814 if (QFile (fn).exists() )
816 QMessageBox mb( vymName,
817 tr("The file %1 exists already.\n"
818 "Do you want to overwrite it?").arg(fn),
819 QMessageBox::Warning,
820 QMessageBox::Yes | QMessageBox::Default,
821 QMessageBox::Cancel | QMessageBox::Escape,
822 QMessageBox::NoButton );
824 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
825 mb.setButtonText( QMessageBox::No, tr("Cancel"));
828 case QMessageBox::Yes:
831 case QMessageBox::Cancel:
838 saveFloatImageInt (ii,fd->selectedFilter(),fn );
845 void VymModel::importDirInt(BranchItem *dst, QDir d)
847 BranchItem *selbi=getSelectedBranch();
851 // Traverse directories
852 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
853 QFileInfoList list = d.entryInfoList();
856 for (int i = 0; i < list.size(); ++i)
859 if (fi.fileName() != "." && fi.fileName() != ".." )
861 bi=addNewBranchInt(dst,-2);
862 bi->setHeading (fi.fileName() ); // FIXME-3 check this
863 bi->setHeadingColor (QColor("blue"));
865 if ( !d.cd(fi.fileName()) )
866 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
869 // Recursively add subdirs
876 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
877 list = d.entryInfoList();
879 for (int i = 0; i < list.size(); ++i)
882 bi=addNewBranchInt (dst,-2);
883 bi->setHeading (fi.fileName() );
884 bi->setHeadingColor (QColor("black"));
885 if (fi.fileName().right(4) == ".vym" )
886 bi->setVymLink (fi.filePath());
891 void VymModel::importDirInt (const QString &s)
893 BranchItem *selbi=getSelectedBranch();
896 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
899 importDirInt (selbi,d);
903 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
905 BranchItem *selbi=getSelectedBranch();
909 filters <<"VYM map (*.vym)";
910 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
911 fd->setMode (QFileDialog::DirectoryOnly);
912 fd->setFilters (filters);
913 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
917 if ( fd->exec() == QDialog::Accepted )
919 importDirInt (fd->selectedFile() );
921 //FIXME-3 VM needed? scene()->update();
927 void VymModel::autosave()
932 cout << "VymModel::autosave rejected due to missing filePath\n";
935 QDateTime now=QDateTime().currentDateTime();
937 // Disable autosave, while we have gone back in history
938 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
939 if (redosAvail>0) return;
941 // Also disable autosave for new map without filename
942 if (filePath.isEmpty()) return;
945 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
947 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
948 mainWindow->fileSave (this);
951 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
956 void VymModel::fileChanged()
958 // Check if file on disk has changed meanwhile
959 if (!filePath.isEmpty())
961 QDateTime tmod=QFileInfo (filePath).lastModified();
962 if (tmod>fileChangedTime)
964 // FIXME-3 VM switch to current mapeditor and finish lineedits...
965 QMessageBox mb( vymName,
966 tr("The file of the map on disk has changed:\n\n"
967 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
968 QMessageBox::Question,
970 QMessageBox::Cancel | QMessageBox::Default,
971 QMessageBox::NoButton );
973 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
974 mb.setButtonText( QMessageBox::No, tr("Ignore"));
977 case QMessageBox::Yes:
979 load (filePath,NewMap,fileType);
980 case QMessageBox::Cancel:
981 fileChangedTime=tmod; // allow autosave to overwrite newer file!
987 bool VymModel::isDefault()
992 void VymModel::makeDefault()
998 bool VymModel::hasChanged()
1003 void VymModel::setChanged()
1006 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1010 latestAddedItem=NULL;
1014 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1016 if (!lmo || !lmo->getTreeItem() ) return QString();
1017 return getObjectName (lmo->getTreeItem() );
1021 QString VymModel::getObjectName (TreeItem *ti)
1024 if (!ti) return QString("Error: NULL has no name!");
1026 if (s=="") s="unnamed";
1028 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1031 void VymModel::redo()
1033 // Can we undo at all?
1034 if (redosAvail<1) return;
1036 bool blockSaveStateOrg=blockSaveState;
1037 blockSaveState=true;
1041 if (undosAvail<stepsTotal) undosAvail++;
1043 if (curStep>stepsTotal) curStep=1;
1044 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1045 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1046 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1047 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1048 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1049 QString version=undoSet.readEntry ("/history/version");
1051 /* TODO Maybe check for version, if we save the history
1052 if (!checkVersion(version))
1053 QMessageBox::warning(0,tr("Warning"),
1054 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1057 // Find out current undo directory
1058 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1062 cout << "VymModel::redo() begin\n";
1063 cout << " undosAvail="<<undosAvail<<endl;
1064 cout << " redosAvail="<<redosAvail<<endl;
1065 cout << " curStep="<<curStep<<endl;
1066 cout << " ---------------------------"<<endl;
1067 cout << " comment="<<comment.toStdString()<<endl;
1068 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1069 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1070 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1071 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1072 cout << " ---------------------------"<<endl<<endl;
1075 // select object before redo
1076 if (!redoSelection.isEmpty())
1077 select (redoSelection);
1082 parseAtom (redoCommand,noErr,errMsg);
1084 blockSaveState=blockSaveStateOrg;
1086 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1087 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1088 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1089 undoSet.writeSettings(histPath);
1091 mainWindow->updateHistory (undoSet);
1094 /* TODO remove testing
1095 cout << "ME::redo() end\n";
1096 cout << " undosAvail="<<undosAvail<<endl;
1097 cout << " redosAvail="<<redosAvail<<endl;
1098 cout << " curStep="<<curStep<<endl;
1099 cout << " ---------------------------"<<endl<<endl;
1105 bool VymModel::isRedoAvailable()
1107 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1113 void VymModel::undo()
1115 // Can we undo at all?
1116 if (undosAvail<1) return;
1118 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1120 bool blockSaveStateOrg=blockSaveState;
1121 blockSaveState=true;
1123 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1124 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1125 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1126 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1127 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1128 QString version=undoSet.readEntry ("/history/version");
1130 /* TODO Maybe check for version, if we save the history
1131 if (!checkVersion(version))
1132 QMessageBox::warning(0,tr("Warning"),
1133 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1136 // Find out current undo directory
1137 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1139 // select object before undo
1140 if (!select (undoSelection))
1142 qWarning ("VymModel::undo() Could not select object for undo");
1149 cout << "VymModel::undo() begin\n";
1150 cout << " undosAvail="<<undosAvail<<endl;
1151 cout << " redosAvail="<<redosAvail<<endl;
1152 cout << " curStep="<<curStep<<endl;
1153 cout << " ---------------------------"<<endl;
1154 cout << " comment="<<comment.toStdString()<<endl;
1155 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1156 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1157 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1158 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1159 cout << " ---------------------------"<<endl<<endl;
1164 parseAtom (undoCommand,noErr,errMsg);
1168 if (curStep<1) curStep=stepsTotal;
1172 blockSaveState=blockSaveStateOrg;
1174 cout << "VymModel::undo() end\n";
1175 cout << " undosAvail="<<undosAvail<<endl;
1176 cout << " redosAvail="<<redosAvail<<endl;
1177 cout << " curStep="<<curStep<<endl;
1178 cout << " ---------------------------"<<endl<<endl;
1181 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1182 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1183 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1184 undoSet.writeSettings(histPath);
1186 mainWindow->updateHistory (undoSet);
1188 //emitSelectionChanged();
1191 bool VymModel::isUndoAvailable()
1193 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1199 void VymModel::gotoHistoryStep (int i)
1201 // Restore variables
1202 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1203 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1205 if (i<0) i=undosAvail+redosAvail;
1207 // Clicking above current step makes us undo things
1210 for (int j=0; j<undosAvail-i; j++) undo();
1213 // Clicking below current step makes us redo things
1215 for (int j=undosAvail; j<i; j++)
1217 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1221 // And ignore clicking the current row ;-)
1225 QString VymModel::getHistoryPath()
1227 QString histName(QString("history-%1").arg(curStep));
1228 return (tmpMapDir+"/"+histName);
1231 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1233 sendData(redoCom); //FIXME-3 testing
1238 if (blockSaveState) return;
1240 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1242 // Find out current undo directory
1243 if (undosAvail<stepsTotal) undosAvail++;
1245 if (curStep>stepsTotal) curStep=1;
1247 QString backupXML="";
1248 QString histDir=getHistoryPath();
1249 QString bakMapPath=histDir+"/map.xml";
1251 // Create histDir if not available
1254 makeSubDirs (histDir);
1256 // Save depending on how much needs to be saved
1258 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1260 QString undoCommand="";
1261 if (savemode==UndoCommand)
1263 undoCommand=undoCom;
1265 else if (savemode==PartOfMap )
1267 undoCommand=undoCom;
1268 undoCommand.replace ("PATH",bakMapPath);
1272 if (!backupXML.isEmpty())
1273 // Write XML Data to disk
1274 saveStringToDisk (bakMapPath,backupXML);
1276 // We would have to save all actions in a tree, to keep track of
1277 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1280 // Write the current state to disk
1281 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1282 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1283 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1284 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1285 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1286 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1287 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1288 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1289 undoSet.setEntry (QString("/history/version"),vymVersion);
1290 undoSet.writeSettings(histPath);
1294 // TODO remove after testing
1295 //cout << " into="<< histPath.toStdString()<<endl;
1296 cout << " stepsTotal="<<stepsTotal<<
1297 ", undosAvail="<<undosAvail<<
1298 ", redosAvail="<<redosAvail<<
1299 ", curStep="<<curStep<<endl;
1300 cout << " ---------------------------"<<endl;
1301 cout << " comment="<<comment.toStdString()<<endl;
1302 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1303 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1304 cout << " redoCom="<<redoCom.toStdString()<<endl;
1305 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1306 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1307 cout << " ---------------------------"<<endl;
1310 mainWindow->updateHistory (undoSet);
1316 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1318 // save the selected part of the map, Undo will replace part of map
1319 QString undoSelection="";
1321 undoSelection=getSelectString(undoSel);
1323 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1324 QString redoSelection="";
1326 redoSelection=getSelectString(undoSel);
1328 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1331 saveState (PartOfMap,
1332 undoSelection, "addMapReplace (\"PATH\")",
1338 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1342 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1345 QString undoSelection;
1346 QString redoSelection=getSelectString(redoSel);
1347 if (redoSel->getType()==TreeItem::Branch)
1349 undoSelection=getSelectString (redoSel->parent());
1350 // save the selected branch of the map, Undo will insert part of map
1351 saveState (PartOfMap,
1352 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1353 redoSelection, "delete ()",
1357 if (redoSel->getType()==TreeItem::MapCenter)
1359 // save the selected branch of the map, Undo will insert part of map
1360 saveState (PartOfMap,
1361 undoSelection, QString("addMapInsert (\"PATH\")"),
1362 redoSelection, "delete ()",
1369 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1371 // "Normal" savestate: save commands, selections and comment
1372 // so just save commands for undo and redo
1373 // and use current selection
1375 QString redoSelection="";
1376 if (redoSel) redoSelection=getSelectString(redoSel);
1377 QString undoSelection="";
1378 if (undoSel) undoSelection=getSelectString(undoSel);
1380 saveState (UndoCommand,
1387 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1389 // "Normal" savestate: save commands, selections and comment
1390 // so just save commands for undo and redo
1391 // and use current selection
1392 saveState (UndoCommand,
1399 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1401 // "Normal" savestate applied to model (no selection needed):
1402 // save commands and comment
1403 saveState (UndoCommand,
1411 QGraphicsScene* VymModel::getScene ()
1416 TreeItem* VymModel::findBySelectString(QString s)
1418 if (s.isEmpty() ) return NULL;
1420 // Old maps don't have multiple mapcenters and don't save full path
1421 if (s.left(2) !="mc")
1424 QStringList parts=s.split (",");
1427 TreeItem *ti=rootItem;
1429 while (!parts.isEmpty() )
1431 typ=parts.first().left(2);
1432 n=parts.first().right(parts.first().length() - 3).toInt();
1433 parts.removeFirst();
1434 if (typ=="mc" || typ=="bo")
1435 ti=ti->getBranchNum (n);
1437 ti=ti->getImageNum (n);
1439 ti=ti->getAttributeNum (n);
1441 ti=ti->getXLinkNum (n);
1442 if(!ti) return NULL;
1447 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1449 BranchItem *cur=NULL;
1450 BranchItem *prev=NULL;
1451 nextBranch(cur,prev);
1454 if (i==cur->getID() ) return cur;
1455 nextBranch(cur,prev);
1460 //////////////////////////////////////////////
1462 //////////////////////////////////////////////
1463 void VymModel::setVersion (const QString &s)
1468 QString VymModel::getVersion()
1473 void VymModel::setAuthor (const QString &s)
1476 QString ("setMapAuthor (\"%1\")").arg(author),
1477 QString ("setMapAuthor (\"%1\")").arg(s),
1478 QString ("Set author of map to \"%1\"").arg(s)
1483 QString VymModel::getAuthor()
1488 void VymModel::setComment (const QString &s)
1491 QString ("setMapComment (\"%1\")").arg(comment),
1492 QString ("setMapComment (\"%1\")").arg(s),
1493 QString ("Set comment of map")
1498 QString VymModel::getComment ()
1503 QString VymModel::getDate ()
1505 return QDate::currentDate().toString ("yyyy-MM-dd");
1508 int VymModel::branchCount()
1511 BranchItem *cur=NULL;
1512 BranchItem *prev=NULL;
1513 nextBranch(cur,prev);
1517 nextBranch(cur,prev);
1522 void VymModel::setSortFilter (const QString &s)
1525 emit (sortFilterChanged (sortFilter));
1528 QString VymModel::getSortFilter ()
1533 void VymModel::setHeading(const QString &s)
1535 BranchItem *selbi=getSelectedBranch();
1540 "setHeading (\""+selbi->getHeading()+"\")",
1542 "setHeading (\""+s+"\")",
1543 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1544 selbi->setHeading(s );
1545 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1547 emitSelectionChanged();
1551 QString VymModel::getHeading()
1553 TreeItem *selti=getSelectedItem();
1555 return selti->getHeading();
1560 void VymModel::setNote(const QString &s)
1562 TreeItem *selti=getSelectedItem();
1567 "setNote (\""+selti->getNote()+"\")",
1569 "setNote (\""+s+"\")",
1570 QString("Set note of %1 ").arg(getObjectName(selti)) );
1573 emitNoteHasChanged(selti);
1574 emitDataHasChanged(selti);
1577 QString VymModel::getNote()
1579 TreeItem *selti=getSelectedItem();
1581 return selti->getNote();
1586 void VymModel::loadNote (const QString &fn)
1588 BranchItem *selbi=getSelectedBranch();
1592 if (!loadStringFromDisk (fn,n))
1593 qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
1597 qWarning ("VymModel::loadNote no branch selected");
1600 void VymModel::saveNote (const QString &fn)
1602 BranchItem *selbi=getSelectedBranch();
1605 QString n=selbi->getNote();
1607 qWarning ()<<"VymModel::saveNote note is empty, won't save to "<<fn;
1610 if (!saveStringToDisk (fn,n))
1611 qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
1616 qWarning ("VymModel::saveNote no branch selected");
1619 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1621 // Generate map containing _all_ URLs and branches
1623 QMap <QString,BranchItem*> map;
1624 BranchItem *cur=NULL;
1625 BranchItem *prev=NULL;
1626 nextBranch(cur,prev);
1631 map.insertMulti (u,cur);
1632 nextBranch(cur,prev);
1635 // Extract duplicate URLs
1636 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1637 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1638 while (i != map.constEnd())
1640 if (i!=map.constBegin() && i.key()==firstdup.key())
1642 if ( i-1==firstdup )
1644 cout << firstdup.key().toStdString() << endl;
1645 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1647 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1655 void VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)
1658 rmodel->setSearchString (s);
1659 rmodel->setSearchFlags (0); //FIXME-2 translate cs to QTextDocument::FindFlag
1660 BranchItem *cur=NULL;
1661 BranchItem *prev=NULL;
1662 nextBranch(cur,prev);
1664 FindResultItem *lastParent=NULL;
1668 if (cur->getHeading().contains (s,cs))
1669 lastParent=rmodel->addItem (cur);
1670 QString n=cur->getNoteASCII();
1675 i=n.indexOf (s,i,cs); //FIXME-2 add subitems to rmodel
1678 // If not there yet, add "parent" item
1681 lastParent=rmodel->addItem (cur);
1683 qWarning()<<"VymModel::findAll still no lastParent?!";
1686 lastParent->setSelectable (false);
1690 // save index of occurence
1691 rmodel->addSubItem (lastParent,QString(tr("Note","FindAll in VymModel")+" "+s),cur,j);
1696 nextBranch(cur,prev);
1700 BranchItem* VymModel::findText (QString s,Qt::CaseSensitivity cs)
1702 if (!s.isEmpty() && s!=findString)
1708 QTextDocument::FindFlags flags=0;
1709 if (cs==Qt::CaseSensitive) flags=QTextDocument::FindCaseSensitively;
1712 { // Nothing found or new find process
1714 // nothing found, start again
1718 nextBranch (findCurrent,findPrevious);
1720 bool searching=true;
1721 bool foundNote=false;
1722 while (searching && !EOFind)
1726 // Searching in Note
1727 if (findCurrent->getNote().contains(findString,cs))
1729 select (findCurrent);
1730 if (textEditor->findText(findString,flags))
1736 // Searching in Heading
1737 if (searching && findCurrent->getHeading().contains (findString,cs) )
1739 select(findCurrent);
1745 if (!nextBranch(findCurrent,findPrevious) )
1750 return getSelectedBranch();
1755 void VymModel::findReset()
1756 { // Necessary if text to find changes during a find process
1763 void VymModel::setScene (QGraphicsScene *s)
1768 void VymModel::setURL(const QString &url)
1770 TreeItem *selti=getSelectedItem();
1773 QString oldurl=selti->getURL();
1774 selti->setURL (url);
1777 QString ("setURL (\"%1\")").arg(oldurl),
1779 QString ("setURL (\"%1\")").arg(url),
1780 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1783 emitDataHasChanged (selti);
1784 emitShowSelection();
1788 QString VymModel::getURL()
1790 TreeItem *selti=getSelectedItem();
1792 return selti->getURL();
1797 QStringList VymModel::getURLs(bool ignoreScrolled)
1800 BranchItem *selbi=getSelectedBranch();
1801 BranchItem *cur=selbi;
1802 BranchItem *prev=NULL;
1805 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1806 urls.append( cur->getURL());
1807 cur=nextBranch (cur,prev,true,selbi);
1813 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1815 BranchItem *bi=getSelectedBranch();
1818 BranchObj *bo=(BranchObj*)(bi->getLMO());
1821 QString s=bo->getFrameTypeName();
1822 bo->setFrameType (t);
1823 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1824 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1826 bo->updateLinkGeometry();
1831 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1833 BranchItem *bi=getSelectedBranch();
1836 BranchObj *bo=(BranchObj*)(bi->getLMO());
1839 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1840 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1841 bo->setFrameType (s);
1843 bo->updateLinkGeometry();
1848 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1851 BranchItem *bi=getSelectedBranch();
1854 BranchObj *bo=(BranchObj*)(bi->getLMO());
1857 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1858 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1859 bo->setFramePenColor (c);
1864 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1866 BranchItem *bi=getSelectedBranch();
1869 BranchObj *bo=(BranchObj*)(bi->getLMO());
1872 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1873 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1874 bo->setFrameBrushColor (c);
1879 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1881 BranchItem *bi=getSelectedBranch();
1884 BranchObj *bo=(BranchObj*)(bi->getLMO());
1887 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1888 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1889 bo->setFramePadding (i);
1891 bo->updateLinkGeometry();
1896 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1898 BranchItem *bi=getSelectedBranch();
1901 BranchObj *bo=(BranchObj*)(bi->getLMO());
1904 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1905 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1906 bo->setFrameBorderWidth (i);
1908 bo->updateLinkGeometry();
1913 void VymModel::setIncludeImagesVer(bool b)
1915 BranchItem *bi=getSelectedBranch();
1918 QString u= b ? "false" : "true";
1919 QString r=!b ? "false" : "true";
1923 QString("setIncludeImagesVertically (%1)").arg(u),
1925 QString("setIncludeImagesVertically (%1)").arg(r),
1926 QString("Include images vertically in %1").arg(getObjectName(bi))
1928 bi->setIncludeImagesVer(b);
1929 emitDataHasChanged ( bi);
1934 void VymModel::setIncludeImagesHor(bool b)
1936 BranchItem *bi=getSelectedBranch();
1939 QString u= b ? "false" : "true";
1940 QString r=!b ? "false" : "true";
1944 QString("setIncludeImagesHorizontally (%1)").arg(u),
1946 QString("setIncludeImagesHorizontally (%1)").arg(r),
1947 QString("Include images horizontally in %1").arg(getObjectName(bi))
1949 bi->setIncludeImagesHor(b);
1950 emitDataHasChanged ( bi);
1955 void VymModel::setHideLinkUnselected (bool b)
1957 TreeItem *ti=getSelectedItem();
1958 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1960 QString u= b ? "false" : "true";
1961 QString r=!b ? "false" : "true";
1965 QString("setHideLinkUnselected (%1)").arg(u),
1967 QString("setHideLinkUnselected (%1)").arg(r),
1968 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1970 ((MapItem*)ti)->setHideLinkUnselected(b);
1974 void VymModel::setHideExport(bool b)
1976 TreeItem *ti=getSelectedItem();
1978 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1980 ti->setHideInExport (b);
1981 QString u= b ? "false" : "true";
1982 QString r=!b ? "false" : "true";
1986 QString ("setHideExport (%1)").arg(u),
1988 QString ("setHideExport (%1)").arg(r),
1989 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1991 emitDataHasChanged(ti);
1992 emitSelectionChanged();
1995 // emitSelectionChanged();
1996 // FIXME-3 VM needed? scene()->update();
2000 void VymModel::toggleHideExport()
2002 TreeItem *selti=getSelectedItem();
2004 setHideExport ( !selti->hideInExport() );
2007 void VymModel::addTimestamp() //FIXME-3 new function, localize
2009 BranchItem *selbi=addNewBranch();
2012 QDate today=QDate::currentDate();
2014 selbi->setHeading (QString ("%1-%2-%3")
2015 .arg(today.year(),4,10,c)
2016 .arg(today.month(),2,10,c)
2017 .arg(today.day(),2,10,c));
2018 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
2025 void VymModel::copy()
2027 TreeItem *selti=getSelectedItem();
2029 (selti->getType() == TreeItem::Branch ||
2030 selti->getType() == TreeItem::MapCenter ||
2031 selti->getType() == TreeItem::Image ))
2033 if (redosAvail == 0)
2036 QString s=getSelectString(selti);
2037 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
2038 curClipboard=curStep;
2041 // Copy also to global clipboard, because we are at last step in history
2042 QString bakMapName(QString("history-%1").arg(curStep));
2043 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2044 copyDir (bakMapDir,clipboardDir );
2046 clipboardEmpty=false;
2052 void VymModel::pasteNoSave(const int &n)
2054 bool old=blockSaveState;
2055 blockSaveState=true;
2056 bool zippedOrg=zipped;
2057 if (redosAvail > 0 || n!=0)
2059 // Use the "historical" buffer
2060 QString bakMapName(QString("history-%1").arg(n));
2061 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2062 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2064 // Use the global buffer
2065 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2070 void VymModel::paste()
2072 BranchItem *selbi=getSelectedBranch();
2075 saveStateChangingPart(
2078 QString ("paste (%1)").arg(curClipboard),
2079 QString("Paste to %1").arg( getObjectName(selbi))
2086 void VymModel::cut()
2088 TreeItem *selti=getSelectedItem();
2089 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2097 bool VymModel::moveUp(BranchItem *bi)
2099 if (bi && bi->canMoveUp())
2100 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2105 void VymModel::moveUp()
2107 BranchItem *selbi=getSelectedBranch();
2110 QString oldsel=getSelectString();
2113 getSelectString(),"moveDown ()",
2115 QString("Move up %1").arg(getObjectName(selbi)));
2119 bool VymModel::moveDown(BranchItem *bi)
2121 if (bi && bi->canMoveDown())
2122 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2127 void VymModel::moveDown()
2129 BranchItem *selbi=getSelectedBranch();
2132 QString oldsel=getSelectString();
2133 if ( moveDown(selbi))
2135 getSelectString(),"moveUp ()",
2136 oldsel,"moveDown ()",
2137 QString("Move down %1").arg(getObjectName(selbi)));
2141 void VymModel::detach()
2143 BranchItem *selbi=getSelectedBranch();
2144 if (selbi && selbi->depth()>0)
2146 // if no relPos have been set before, try to use current rel positions
2147 if (selbi->getLMO())
2148 for (int i=0; i<selbi->branchCount();++i)
2149 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2151 QString oldsel=getSelectString();
2154 BranchObj *bo=selbi->getBranchObj();
2155 if (bo) p=bo->getAbsPos();
2156 QString parsel=getSelectString(selbi->parent());
2157 if ( relinkBranch (selbi,rootItem,-1) )
2159 getSelectString (selbi),
2160 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2163 QString("Detach %1").arg(getObjectName(selbi))
2168 void VymModel::sortChildren(bool inverse)
2170 BranchItem* selbi=getSelectedBranch();
2173 if(selbi->branchCount()>1)
2177 saveStateChangingPart(
2178 selbi,selbi, "sortChildren ()",
2179 QString("Sort children of %1").arg(getObjectName(selbi)));
2181 selbi->sortChildren(inverse);
2183 emitShowSelection();
2188 BranchItem* VymModel::createMapCenter()
2190 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2194 BranchItem* VymModel::createBranch(BranchItem *dst)
2197 return addNewBranchInt (dst,-2);
2202 ImageItem* VymModel::createImage(BranchItem *dst)
2209 QList<QVariant> cData;
2210 cData << "new" << "undef";
2212 ImageItem *newii=new ImageItem(cData) ;
2213 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2215 emit (layoutAboutToBeChanged() );
2218 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2219 n=dst->getRowNumAppend(newii);
2220 beginInsertRows (parix,n,n);
2221 dst->appendChild (newii);
2224 emit (layoutChanged() );
2226 // save scroll state. If scrolled, automatically select
2227 // new branch in order to tmp unscroll parent...
2228 newii->createMapObj(mapScene);
2235 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2242 QList<QVariant> cData;
2243 cData << "new xLink"<<"undef";
2245 XLinkItem *newxli=new XLinkItem(cData) ;
2246 newxli->setBegin (bi);
2248 emit (layoutAboutToBeChanged() );
2251 n=bi->getRowNumAppend(newxli);
2252 beginInsertRows (parix,n,n);
2253 bi->appendChild (newxli);
2256 emit (layoutChanged() );
2258 // save scroll state. If scrolled, automatically select
2259 // new branch in order to tmp unscroll parent...
2262 newxli->createMapObj(mapScene);
2270 AttributeItem* VymModel::addAttribute()
2272 BranchItem *selbi=getSelectedBranch();
2275 QList<QVariant> cData;
2276 cData << "new attribute" << "undef";
2277 AttributeItem *a=new AttributeItem (cData);
2278 if (addAttribute (a)) return a;
2283 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2285 BranchItem *selbi=getSelectedBranch();
2288 emit (layoutAboutToBeChanged() );
2290 QModelIndex parix=index(selbi);
2291 int n=selbi->getRowNumAppend (ai);
2292 beginInsertRows (parix,n,n);
2293 selbi->appendChild (ai);
2296 emit (layoutChanged() );
2298 ai->createMapObj(mapScene); //FIXME-2 check that...
2305 BranchItem* VymModel::addMapCenter ()
2307 BranchItem *bi=addMapCenter (contextPos);
2309 emitShowSelection();
2314 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2315 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2321 BranchItem* VymModel::addMapCenter(QPointF absPos)
2322 // createMapCenter could then probably be merged with createBranch
2326 QModelIndex parix=index(rootItem);
2328 QList<QVariant> cData;
2329 cData << "VM:addMapCenter" << "undef";
2330 BranchItem *newbi=new BranchItem (cData,rootItem);
2331 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2332 int n=rootItem->getRowNumAppend (newbi);
2334 emit (layoutAboutToBeChanged() );
2335 beginInsertRows (parix,n,n);
2337 rootItem->appendChild (newbi);
2340 emit (layoutChanged() );
2343 newbi->setPositionMode (MapItem::Absolute);
2344 BranchObj *bo=newbi->createMapObj(mapScene);
2345 if (bo) bo->move (absPos);
2350 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2352 // Depending on pos:
2353 // -3 insert in children of parent above selection
2354 // -2 add branch to selection
2355 // -1 insert in children of parent below selection
2356 // 0..n insert in children of parent at pos
2359 QList<QVariant> cData;
2360 cData << "" << "undef";
2365 BranchItem *newbi=new BranchItem (cData);
2366 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2368 emit (layoutAboutToBeChanged() );
2374 n=parbi->getRowNumAppend (newbi);
2375 beginInsertRows (parix,n,n);
2376 parbi->appendChild (newbi);
2378 }else if (num==-1 || num==-3)
2380 // insert below selection
2381 parbi=(BranchItem*)dst->parent();
2384 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2385 beginInsertRows (parix,n,n);
2386 parbi->insertBranch(n,newbi);
2389 emit (layoutChanged() );
2391 // Set color of heading to that of parent
2392 newbi->setHeadingColor (parbi->getHeadingColor());
2394 // save scroll state. If scrolled, automatically select
2395 // new branch in order to tmp unscroll parent...
2396 newbi->createMapObj(mapScene);
2401 BranchItem* VymModel::addNewBranch(int pos)
2403 // Different meaning than num in addNewBranchInt!
2407 BranchItem *newbi=NULL;
2408 BranchItem *selbi=getSelectedBranch();
2412 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2414 newbi=addNewBranchInt (selbi,pos-2);
2422 QString ("addBranch (%1)").arg(pos),
2423 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2426 // emitSelectionChanged(); FIXME-3
2427 latestAddedItem=newbi;
2428 // In Network mode, the client needs to know where the new branch is,
2429 // so we have to pass on this information via saveState.
2430 // TODO: Get rid of this positioning workaround
2431 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2432 sendData ("selectLatestAdded ()");
2433 sendData (QString("move %1").arg(ps));
2442 BranchItem* VymModel::addNewBranchBefore()
2444 BranchItem *newbi=NULL;
2445 BranchItem *selbi=getSelectedBranch();
2446 if (selbi && selbi->getType()==TreeItem::Branch)
2447 // We accept no MapCenter here, so we _have_ a parent
2449 //QPointF p=bo->getRelPos();
2452 // add below selection
2453 newbi=addNewBranchInt (selbi,-1);
2457 //newbi->move2RelPos (p);
2459 // Move selection to new branch
2460 relinkBranch (selbi,newbi,0);
2462 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2463 QString ("Add branch before %1").arg(getObjectName(selbi)));
2465 // FIXME-3 needed? reposition();
2466 // emitSelectionChanged(); FIXME-3
2472 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2478 // Do we need to update frame type?
2479 bool keepFrame=false;
2482 emit (layoutAboutToBeChanged() );
2483 BranchItem *branchpi=(BranchItem*)branch->parent();
2484 // Remove at current position
2485 int n=branch->childNum();
2487 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2488 // error occured if relinking branch to empty mainbranch
2489 cout<<"VM::relinkBranch:\n";
2490 cout<<" b="<<branch->getHeadingStd()<<endl;
2491 cout<<" dst="<<dst->getHeadingStd()<<endl;
2492 cout<<" pos="<<pos<<endl;
2493 cout<<" n1="<<n<<endl;
2495 beginRemoveRows (index(branchpi),n,n);
2496 branchpi->removeChild (n);
2499 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2501 // Append as last branch to dst
2502 if (dst->branchCount()==0)
2505 n=dst->getFirstBranch()->childNumber();
2506 beginInsertRows (index(dst),n+pos,n+pos);
2507 dst->insertBranch (pos,branch);
2510 // Correct type if necessesary
2511 if (branch->getType()==TreeItem::MapCenter)
2512 branch->setType(TreeItem::Branch);
2514 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2515 branch->updateStyles(keepFrame);
2517 emit (layoutChanged() );
2518 reposition(); // both for moveUp/Down and relinking
2519 if (dst->isScrolled() )
2522 branch->updateVisibility();
2531 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2535 emit (layoutAboutToBeChanged() );
2537 BranchItem *pi=(BranchItem*)(image->parent());
2538 QString oldParString=getSelectString (pi);
2539 // Remove at current position
2540 int n=image->childNum();
2541 beginRemoveRows (index(pi),n,n);
2542 pi->removeChild (n);
2546 QModelIndex dstix=index(dst);
2547 n=dst->getRowNumAppend (image);
2548 beginInsertRows (dstix,n,n+1);
2549 dst->appendChild (image);
2552 // Set new parent also for lmo
2553 if (image->getLMO() && dst->getLMO() )
2554 image->getLMO()->setParObj (dst->getLMO() );
2556 emit (layoutChanged() );
2559 QString("relinkTo (\"%1\")").arg(oldParString),
2561 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2562 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2568 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2570 BranchItem *selbi=getSelectedBranch();
2575 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2577 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2580 if (pi->isScrolled() && pi->branchCount()==0)
2583 emitDataHasChanged(pi);
2586 emitShowSelection();
2590 TreeItem *ti=getSelectedItem();
2592 { // Delete other item
2593 TreeItem *pi=ti->parent();
2595 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2597 saveStateChangingPart(
2601 QString("Delete %1").arg(getObjectName(ti))
2605 emitDataHasChanged (pi);
2608 emitShowSelection();
2609 } else if (ti->getType()==TreeItem::XLink)
2611 //FIXME-2 savestate for deleting xlink missing
2614 qWarning ("VymmModel::deleteSelection() unknown type?!");
2618 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2621 BranchItem *selbi=getSelectedBranch();
2625 // Don't use this on mapcenter
2626 if (selbi->depth()<2) return;
2628 pi=(BranchItem*)(selbi->parent());
2629 // Check if we have children at all to keep
2630 if (selbi->branchCount()==0)
2637 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2638 saveStateChangingPart(
2641 "deleteKeepChildren ()",
2642 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2645 QString sel=getSelectString(selbi);
2647 int pos=selbi->num();
2648 BranchItem *bi=selbi->getFirstBranch();
2651 relinkBranch (bi,pi,pos);
2652 bi=selbi->getFirstBranch();
2658 BranchObj *bo=getSelectedBranchObj();
2661 bo->move2RelPos (p);
2667 void VymModel::deleteChildren()
2670 BranchItem *selbi=getSelectedBranch();
2673 saveStateChangingPart(
2676 "deleteChildren ()",
2677 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2679 emit (layoutAboutToBeChanged() );
2681 QModelIndex ix=index (selbi);
2682 int n=selbi->branchCount()-1;
2683 beginRemoveRows (ix,0,n);
2684 removeRows (0,n+1,ix);
2686 if (selbi->isScrolled()) selbi->unScroll();
2687 emit (layoutChanged() );
2692 TreeItem* VymModel::deleteItem (TreeItem *ti)
2696 TreeItem *pi=ti->parent();
2697 QModelIndex parentIndex=index(pi);
2699 emit (layoutAboutToBeChanged() );
2701 int n=ti->childNum();
2702 beginRemoveRows (parentIndex,n,n);
2703 removeRows (n,1,parentIndex);
2707 emit (layoutChanged() );
2708 if (pi->depth()>=0) return pi;
2713 void VymModel::clearItem (TreeItem *ti)
2717 QModelIndex parentIndex=index(ti);
2718 if (!parentIndex.isValid()) return;
2720 int n=ti->childCount();
2723 emit (layoutAboutToBeChanged() );
2725 beginRemoveRows (parentIndex,0,n-1);
2726 removeRows (0,n,parentIndex);
2730 emit (layoutChanged() );
2736 bool VymModel::scrollBranch(BranchItem *bi)
2740 if (bi->isScrolled()) return false;
2741 if (bi->branchCount()==0) return false;
2742 if (bi->depth()==0) return false;
2743 if (bi->toggleScroll())
2751 QString ("%1 ()").arg(u),
2753 QString ("%1 ()").arg(r),
2754 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2756 emitDataHasChanged(bi);
2757 emitSelectionChanged();
2758 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2765 bool VymModel::unscrollBranch(BranchItem *bi)
2769 if (!bi->isScrolled()) return false;
2770 if (bi->branchCount()==0) return false;
2771 if (bi->depth()==0) return false;
2772 if (bi->toggleScroll())
2780 QString ("%1 ()").arg(u),
2782 QString ("%1 ()").arg(r),
2783 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2785 emitDataHasChanged(bi);
2786 emitSelectionChanged();
2787 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2794 void VymModel::toggleScroll()
2796 BranchItem *bi=(BranchItem*)getSelectedBranch();
2797 if (bi && bi->isBranchLikeType() )
2799 if (bi->isScrolled())
2800 unscrollBranch (bi);
2804 // saveState & reposition are called in above functions
2807 void VymModel::unscrollChildren()
2809 BranchItem *selbi=getSelectedBranch();
2810 BranchItem *prev=NULL;
2811 BranchItem *cur=selbi;
2814 saveStateChangingPart(
2817 QString ("unscrollChildren ()"),
2818 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2822 if (cur->isScrolled())
2824 cur->toggleScroll();
2825 emitDataHasChanged (cur);
2827 cur=nextBranch (cur,prev,true,selbi);
2834 void VymModel::emitExpandAll()
2836 emit (expandAll() );
2839 void VymModel::emitExpandOneLevel()
2841 emit (expandOneLevel () );
2844 void VymModel::emitCollapseOneLevel()
2846 emit (collapseOneLevel () );
2849 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2851 BranchItem *bi=getSelectedBranch();
2855 if (bi->isActiveStandardFlag(name))
2867 QString("%1 (\"%2\")").arg(u).arg(name),
2869 QString("%1 (\"%2\")").arg(r).arg(name),
2870 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2871 bi->toggleStandardFlag (name, master);
2873 emitSelectionChanged();
2877 void VymModel::addFloatImage (const QPixmap &img)
2879 BranchItem *selbi=getSelectedBranch();
2882 ImageItem *ii=createImage (selbi);
2884 ii->setOriginalFilename("No original filename (image added by dropevent)");
2885 QString s=getSelectString(selbi);
2886 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2887 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2889 // FIXME-3 VM needed? scene()->update();
2894 void VymModel::colorBranch (QColor c)
2896 BranchItem *selbi=getSelectedBranch();
2901 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2903 QString ("colorBranch (\"%1\")").arg(c.name()),
2904 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2906 selbi->setHeadingColor(c); // color branch
2911 void VymModel::colorSubtree (QColor c)
2913 BranchItem *selbi=getSelectedBranch();
2916 saveStateChangingPart(
2919 QString ("colorSubtree (\"%1\")").arg(c.name()),
2920 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2922 BranchItem *prev=NULL;
2923 BranchItem *cur=selbi;
2926 cur->setHeadingColor(c); // color links, color children
2927 cur=nextBranch (cur,prev,true,selbi);
2933 QColor VymModel::getCurrentHeadingColor()
2935 BranchItem *selbi=getSelectedBranch();
2936 if (selbi) return selbi->getHeadingColor();
2938 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2944 void VymModel::editURL()
2946 TreeItem *selti=getSelectedItem();
2950 QString text = QInputDialog::getText(
2951 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2952 selti->getURL(), &ok, NULL);
2954 // user entered something and pressed OK
2959 void VymModel::editLocalURL()
2961 TreeItem *selti=getSelectedItem();
2964 QStringList filters;
2965 filters <<"All files (*)";
2966 filters << tr("Text","Filedialog") + " (*.txt)";
2967 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2968 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2969 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2970 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2971 fd->setFilters (filters);
2972 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2973 fd->setDirectory (lastFileDir);
2974 if (! selti->getVymLink().isEmpty() )
2975 fd->selectFile( selti->getURL() );
2978 if ( fd->exec() == QDialog::Accepted )
2980 lastFileDir=QDir (fd->directory().path());
2981 setURL (fd->selectedFile() );
2987 void VymModel::editHeading2URL()
2989 TreeItem *selti=getSelectedItem();
2991 setURL (selti->getHeading());
2994 void VymModel::editBugzilla2URL()
2996 TreeItem *selti=getSelectedItem();
2999 QString h=selti->getHeading();
3000 QRegExp rx("^(\\d+)");
3001 if (rx.indexIn(h) !=-1)
3002 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
3006 void VymModel::getBugzillaData()
3008 BranchItem *selbi=getSelectedBranch();
3011 QString url=selbi->getURL();
3014 QRegExp rx("(\\d+)");
3015 if (rx.indexIn(url) !=-1)
3017 QString bugID=rx.cap(1);
3018 qDebug()<< "VM::getBugzillaData bug="<<bugID;
3020 new BugAgent (selbi,bugID);
3026 void VymModel::editFATE2URL()
3028 TreeItem *selti=getSelectedItem();
3031 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3034 "setURL (\""+selti->getURL()+"\")",
3036 "setURL (\""+url+"\")",
3037 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3039 selti->setURL (url);
3040 // FIXME-4 updateActions();
3044 void VymModel::editVymLink()
3046 BranchItem *bi=getSelectedBranch();
3049 QStringList filters;
3050 filters <<"VYM map (*.vym)";
3051 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3052 fd->setFilters (filters);
3053 fd->setCaption(vymName+" - " +tr("Link to another map"));
3054 fd->setDirectory (lastFileDir);
3055 if (! bi->getVymLink().isEmpty() )
3056 fd->selectFile( bi->getVymLink() );
3060 if ( fd->exec() == QDialog::Accepted )
3062 lastFileDir=QDir (fd->directory().path());
3065 "setVymLink (\""+bi->getVymLink()+"\")",
3067 "setVymLink (\""+fd->selectedFile()+"\")",
3068 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3070 setVymLink (fd->selectedFile() );
3075 void VymModel::setVymLink (const QString &s)
3077 // Internal function, no saveState needed
3078 TreeItem *selti=getSelectedItem();
3081 selti->setVymLink(s);
3083 emitDataHasChanged (selti);
3084 emitShowSelection();
3088 void VymModel::deleteVymLink()
3090 BranchItem *bi=getSelectedBranch();
3095 "setVymLink (\""+bi->getVymLink()+"\")",
3097 "setVymLink (\"\")",
3098 QString("Unset vymlink of %1").arg(getObjectName(bi))
3100 bi->setVymLink ("" );
3106 QString VymModel::getVymLink()
3108 BranchItem *bi=getSelectedBranch();
3110 return bi->getVymLink();
3116 QStringList VymModel::getVymLinks()
3119 BranchItem *selbi=getSelectedBranch();
3120 BranchItem *cur=selbi;
3121 BranchItem *prev=NULL;
3124 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3125 cur=nextBranch (cur,prev,true,selbi);
3131 void VymModel::followXLink(int i)
3134 BranchItem *selbi=getSelectedBranch();
3137 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3138 if (selbi) select (selbi);
3142 void VymModel::editXLink(int i)
3145 BranchItem *selbi=getSelectedBranch();
3148 XLinkItem *xli=selbi->getXLinkNum(i);
3151 EditXLinkDialog dia;
3153 dia.setSelection(selbi);
3154 if (dia.exec() == QDialog::Accepted)
3156 if (dia.useSettingsGlobal() )
3158 setMapDefXLinkColor (xli->getColor() );
3159 setMapDefXLinkWidth (xli->getWidth() );
3161 if (dia.deleteXLink()) deleteItem (xli);
3171 //////////////////////////////////////////////
3173 //////////////////////////////////////////////
3175 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3177 TreeItem* selti=getSelectedItem();
3178 BranchItem *selbi=getSelectedBranch();
3183 QVariant returnValue="";
3185 // Split string s into command and parameters
3186 parser.parseAtom (atom);
3187 QString com=parser.getCommand();
3189 // External commands
3190 /////////////////////////////////////////////////////////////////////
3191 if (com=="addBranch")
3195 parser.setError (Aborted,"Nothing selected");
3196 } else if (! selbi )
3198 parser.setError (Aborted,"Type of selection is not a branch");
3203 if (parser.checkParCount(pl))
3205 if (parser.parCount()==0)
3209 n=parser.parInt (ok,0);
3210 if (ok ) addNewBranch (n);
3214 /////////////////////////////////////////////////////////////////////
3215 } else if (com=="addBranchBefore")
3219 parser.setError (Aborted,"Nothing selected");
3220 } else if (! selbi )
3222 parser.setError (Aborted,"Type of selection is not a branch");
3225 if (parser.parCount()==0)
3227 addNewBranchBefore ();
3230 /////////////////////////////////////////////////////////////////////
3231 } else if (com==QString("addMapCenter"))
3233 if (parser.checkParCount(2))
3235 x=parser.parDouble (ok,0);
3238 y=parser.parDouble (ok,1);
3239 if (ok) addMapCenter (QPointF(x,y));
3242 /////////////////////////////////////////////////////////////////////
3243 } else if (com==QString("addMapReplace"))
3247 parser.setError (Aborted,"Nothing selected");
3248 } else if (! selbi )
3250 parser.setError (Aborted,"Type of selection is not a branch");
3251 } else if (parser.checkParCount(1))
3253 //s=parser.parString (ok,0); // selection
3254 t=parser.parString (ok,0); // path to map
3255 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3256 addMapReplaceInt(getSelectString(selbi),t);
3258 /////////////////////////////////////////////////////////////////////
3259 } else if (com==QString("addMapInsert"))
3261 if (parser.parCount()==2)
3266 parser.setError (Aborted,"Nothing selected");
3267 } else if (! selbi )
3269 parser.setError (Aborted,"Type of selection is not a branch");
3272 t=parser.parString (ok,0); // path to map
3273 n=parser.parInt(ok,1); // position
3274 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3275 addMapInsertInt(t,n);
3277 } else if (parser.parCount()==1)
3279 t=parser.parString (ok,0); // path to map
3280 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3283 parser.setError (Aborted,"Wrong number of parameters");
3284 /////////////////////////////////////////////////////////////////////
3285 } else if (com==QString("addXLink"))
3287 if (parser.parCount()>1)
3289 s=parser.parString (ok,0); // begin
3290 t=parser.parString (ok,1); // end
3291 BranchItem *begin=(BranchItem*)findBySelectString(s);
3292 BranchItem *end=(BranchItem*)findBySelectString(t);
3295 if (begin->isBranchLikeType() && end->isBranchLikeType())
3297 XLinkItem *xl=createXLink (begin,true);
3303 parser.setError (Aborted,"Failed to create xLink");
3306 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3309 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3311 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3312 /////////////////////////////////////////////////////////////////////
3313 } else if (com=="clearFlags")
3317 parser.setError (Aborted,"Nothing selected");
3318 } else if (! selbi )
3320 parser.setError (Aborted,"Type of selection is not a branch");
3321 } else if (parser.checkParCount(0))
3323 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3325 /////////////////////////////////////////////////////////////////////
3326 } else if (com=="colorBranch")
3330 parser.setError (Aborted,"Nothing selected");
3331 } else if (! selbi )
3333 parser.setError (Aborted,"Type of selection is not a branch");
3334 } else if (parser.checkParCount(1))
3336 QColor c=parser.parColor (ok,0);
3337 if (ok) colorBranch (c);
3339 /////////////////////////////////////////////////////////////////////
3340 } else if (com=="colorSubtree")
3344 parser.setError (Aborted,"Nothing selected");
3345 } else if (! selbi )
3347 parser.setError (Aborted,"Type of selection is not a branch");
3348 } else if (parser.checkParCount(1))
3350 QColor c=parser.parColor (ok,0);
3351 if (ok) colorSubtree (c);
3353 /////////////////////////////////////////////////////////////////////
3354 } else if (com=="copy")
3358 parser.setError (Aborted,"Nothing selected");
3359 } else if ( selectionType()!=TreeItem::Branch &&
3360 selectionType()!=TreeItem::MapCenter &&
3361 selectionType()!=TreeItem::Image )
3363 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3364 } else if (parser.checkParCount(0))
3368 /////////////////////////////////////////////////////////////////////
3369 } else if (com=="cut")
3373 parser.setError (Aborted,"Nothing selected");
3374 } else if ( selectionType()!=TreeItem::Branch &&
3375 selectionType()!=TreeItem::MapCenter &&
3376 selectionType()!=TreeItem::Image )
3378 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3379 } else if (parser.checkParCount(0))
3383 /////////////////////////////////////////////////////////////////////
3384 } else if (com=="delete")
3388 parser.setError (Aborted,"Nothing selected");
3390 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3392 parser.setError (Aborted,"Type of selection is wrong.");
3395 else if (parser.checkParCount(0))
3399 /////////////////////////////////////////////////////////////////////
3400 } else if (com=="deleteKeepChildren")
3404 parser.setError (Aborted,"Nothing selected");
3405 } else if (! selbi )
3407 parser.setError (Aborted,"Type of selection is not a branch");
3408 } else if (parser.checkParCount(0))
3410 deleteKeepChildren();
3412 /////////////////////////////////////////////////////////////////////
3413 } else if (com=="deleteChildren")
3417 parser.setError (Aborted,"Nothing selected");
3420 parser.setError (Aborted,"Type of selection is not a branch");
3421 } else if (parser.checkParCount(0))
3425 /////////////////////////////////////////////////////////////////////
3426 } else if (com=="exportAO")
3430 if (parser.parCount()>=1)
3431 // Hey, we even have a filename
3432 fname=parser.parString(ok,0);
3435 parser.setError (Aborted,"Could not read filename");
3438 exportAO (fname,false);
3440 /////////////////////////////////////////////////////////////////////
3441 } else if (com=="exportASCII")
3445 if (parser.parCount()>=1)
3446 // Hey, we even have a filename
3447 fname=parser.parString(ok,0);
3450 parser.setError (Aborted,"Could not read filename");
3453 exportASCII (fname,false);
3455 /////////////////////////////////////////////////////////////////////
3456 } else if (com=="exportImage")
3460 if (parser.parCount()>=2)
3461 // Hey, we even have a filename
3462 fname=parser.parString(ok,0);
3465 parser.setError (Aborted,"Could not read filename");
3468 QString format="PNG";
3469 if (parser.parCount()>=2)
3471 format=parser.parString(ok,1);
3473 exportImage (fname,false,format);
3475 /////////////////////////////////////////////////////////////////////
3476 } else if (com=="exportXHTML")
3480 if (parser.parCount()>=2)
3481 // Hey, we even have a filename
3482 fname=parser.parString(ok,1);
3485 parser.setError (Aborted,"Could not read filename");
3488 exportXHTML (fname,false);
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="exportXML")
3495 if (parser.parCount()>=2)
3496 // Hey, we even have a filename
3497 fname=parser.parString(ok,1);
3500 parser.setError (Aborted,"Could not read filename");
3503 exportXML (fname,false);
3505 /////////////////////////////////////////////////////////////////////
3506 } else if (com=="getHeading")
3510 parser.setError (Aborted,"Nothing selected");
3511 } else if (parser.checkParCount(0))
3512 returnValue=selti->getHeading();
3513 /////////////////////////////////////////////////////////////////////
3514 } else if (com=="importDir")
3518 parser.setError (Aborted,"Nothing selected");
3519 } else if (! selbi )
3521 parser.setError (Aborted,"Type of selection is not a branch");
3522 } else if (parser.checkParCount(1))
3524 s=parser.parString(ok,0);
3525 if (ok) importDirInt(s);
3527 /////////////////////////////////////////////////////////////////////
3528 } else if (com=="relinkTo")
3532 parser.setError (Aborted,"Nothing selected");
3535 if (parser.checkParCount(4))
3537 // 0 selectstring of parent
3538 // 1 num in parent (for branches)
3539 // 2,3 x,y of mainbranch or mapcenter
3540 s=parser.parString(ok,0);
3541 TreeItem *dst=findBySelectString (s);
3544 if (dst->getType()==TreeItem::Branch)
3546 // Get number in parent
3547 n=parser.parInt (ok,1);
3550 relinkBranch (selbi,(BranchItem*)dst,n);
3551 emitSelectionChanged();
3553 } else if (dst->getType()==TreeItem::MapCenter)
3555 relinkBranch (selbi,(BranchItem*)dst);
3556 // Get coordinates of mainbranch
3557 x=parser.parDouble(ok,2);
3560 y=parser.parDouble(ok,3);
3563 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3564 emitSelectionChanged();
3570 } else if ( selti->getType() == TreeItem::Image)
3572 if (parser.checkParCount(1))
3574 // 0 selectstring of parent
3575 s=parser.parString(ok,0);
3576 TreeItem *dst=findBySelectString (s);
3579 if (dst->isBranchLikeType())
3580 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3582 parser.setError (Aborted,"Destination is not a branch");
3585 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3586 /////////////////////////////////////////////////////////////////////
3587 } else if (com=="loadImage")
3591 parser.setError (Aborted,"Nothing selected");
3592 } else if (! selbi )
3594 parser.setError (Aborted,"Type of selection is not a branch");
3595 } else if (parser.checkParCount(1))
3597 s=parser.parString(ok,0);
3598 if (ok) loadFloatImageInt (selbi,s);
3600 /////////////////////////////////////////////////////////////////////
3601 } else if (com=="loadNote")
3605 parser.setError (Aborted,"Nothing selected");
3606 } else if (! selbi )
3608 parser.setError (Aborted,"Type of selection is not a branch");
3609 } else if (parser.checkParCount(1))
3611 s=parser.parString(ok,0);
3612 if (ok) loadNote (s);
3614 /////////////////////////////////////////////////////////////////////
3615 } else if (com=="moveUp")
3619 parser.setError (Aborted,"Nothing selected");
3620 } else if (! selbi )
3622 parser.setError (Aborted,"Type of selection is not a branch");
3623 } else if (parser.checkParCount(0))
3627 /////////////////////////////////////////////////////////////////////
3628 } else if (com=="moveDown")
3632 parser.setError (Aborted,"Nothing selected");
3633 } else if (! selbi )
3635 parser.setError (Aborted,"Type of selection is not a branch");
3636 } else if (parser.checkParCount(0))
3640 /////////////////////////////////////////////////////////////////////
3641 } else if (com=="move")
3645 parser.setError (Aborted,"Nothing selected");
3646 } else if ( selectionType()!=TreeItem::Branch &&
3647 selectionType()!=TreeItem::MapCenter &&
3648 selectionType()!=TreeItem::Image )
3650 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3651 } else if (parser.checkParCount(2))
3653 x=parser.parDouble (ok,0);
3656 y=parser.parDouble (ok,1);
3660 /////////////////////////////////////////////////////////////////////
3661 } else if (com=="moveRel")
3665 parser.setError (Aborted,"Nothing selected");
3666 } else if ( selectionType()!=TreeItem::Branch &&
3667 selectionType()!=TreeItem::MapCenter &&
3668 selectionType()!=TreeItem::Image )
3670 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3671 } else if (parser.checkParCount(2))
3673 x=parser.parDouble (ok,0);
3676 y=parser.parDouble (ok,1);
3677 if (ok) moveRel (x,y);
3680 /////////////////////////////////////////////////////////////////////
3681 } else if (com=="nop")
3683 /////////////////////////////////////////////////////////////////////
3684 } else if (com=="paste")
3688 parser.setError (Aborted,"Nothing selected");
3689 } else if (! selbi )
3691 parser.setError (Aborted,"Type of selection is not a branch");
3692 } else if (parser.checkParCount(1))
3694 n=parser.parInt (ok,0);
3695 if (ok) pasteNoSave(n);
3697 /////////////////////////////////////////////////////////////////////
3698 } else if (com=="qa")
3702 parser.setError (Aborted,"Nothing selected");
3703 } else if (! selbi )
3705 parser.setError (Aborted,"Type of selection is not a branch");
3706 } else if (parser.checkParCount(4))
3709 c=parser.parString (ok,0);
3712 parser.setError (Aborted,"No comment given");
3715 s=parser.parString (ok,1);
3718 parser.setError (Aborted,"First parameter is not a string");
3721 t=parser.parString (ok,2);
3724 parser.setError (Aborted,"Condition is not a string");
3727 u=parser.parString (ok,3);
3730 parser.setError (Aborted,"Third parameter is not a string");
3735 parser.setError (Aborted,"Unknown type: "+s);
3740 parser.setError (Aborted,"Unknown operator: "+t);
3745 parser.setError (Aborted,"Type of selection is not a branch");
3748 if (selbi->getHeading() == u)
3750 cout << "PASSED: " << qPrintable (c) << endl;
3753 cout << "FAILED: " << qPrintable (c) << endl;
3763 /////////////////////////////////////////////////////////////////////
3764 } else if (com=="saveImage")
3766 ImageItem *ii=getSelectedImage();
3769 parser.setError (Aborted,"No image selected");
3770 } else if (parser.checkParCount(2))
3772 s=parser.parString(ok,0);
3775 t=parser.parString(ok,1);
3776 if (ok) saveFloatImageInt (ii,t,s);
3779 /////////////////////////////////////////////////////////////////////
3780 } else if (com=="saveNote")
3784 parser.setError (Aborted,"Nothing selected");
3785 } else if (! selbi )
3787 parser.setError (Aborted,"Type of selection is not a branch");
3788 } else if (parser.checkParCount(1))
3790 s=parser.parString(ok,0);
3791 if (ok) saveNote (s);
3793 /////////////////////////////////////////////////////////////////////
3794 } else if (com=="scroll")
3798 parser.setError (Aborted,"Nothing selected");
3799 } else if (! selbi )
3801 parser.setError (Aborted,"Type of selection is not a branch");
3802 } else if (parser.checkParCount(0))
3804 if (!scrollBranch (selbi))
3805 parser.setError (Aborted,"Could not scroll branch");
3807 /////////////////////////////////////////////////////////////////////
3808 } else if (com=="select")
3810 if (parser.checkParCount(1))
3812 s=parser.parString(ok,0);
3815 /////////////////////////////////////////////////////////////////////
3816 } else if (com=="selectLastBranch")
3820 parser.setError (Aborted,"Nothing selected");
3821 } else if (! selbi )
3823 parser.setError (Aborted,"Type of selection is not a branch");
3824 } else if (parser.checkParCount(0))
3826 BranchItem *bi=selbi->getLastBranch();
3828 parser.setError (Aborted,"Could not select last branch");
3829 select (bi); // FIXME-3 was selectInt
3832 /////////////////////////////////////////////////////////////////////
3833 } else /* FIXME-2 if (com=="selectLastImage")
3837 parser.setError (Aborted,"Nothing selected");
3838 } else if (! selbi )
3840 parser.setError (Aborted,"Type of selection is not a branch");
3841 } else if (parser.checkParCount(0))
3843 FloatImageObj *fio=selb->getLastFloatImage();
3845 parser.setError (Aborted,"Could not select last image");
3846 select (fio); // FIXME-3 was selectInt
3849 /////////////////////////////////////////////////////////////////////
3850 } else */ if (com=="selectLatestAdded")
3852 if (!latestAddedItem)
3854 parser.setError (Aborted,"No latest added object");
3857 if (!select (latestAddedItem))
3858 parser.setError (Aborted,"Could not select latest added object ");
3860 /////////////////////////////////////////////////////////////////////
3861 } else if (com=="setFlag")
3865 parser.setError (Aborted,"Nothing selected");
3866 } else if (! selbi )
3868 parser.setError (Aborted,"Type of selection is not a branch");
3869 } else if (parser.checkParCount(1))
3871 s=parser.parString(ok,0);
3873 selbi->activateStandardFlag(s);
3875 /////////////////////////////////////////////////////////////////////
3876 } else if (com=="setFrameType")
3878 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3880 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3882 else if (parser.checkParCount(1))
3884 s=parser.parString(ok,0);
3885 if (ok) setFrameType (s);
3887 /////////////////////////////////////////////////////////////////////
3888 } else if (com=="setFramePenColor")
3890 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3892 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3894 else if (parser.checkParCount(1))
3896 QColor c=parser.parColor(ok,0);
3897 if (ok) setFramePenColor (c);
3899 /////////////////////////////////////////////////////////////////////
3900 } else if (com=="setFrameBrushColor")
3902 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3904 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3906 else if (parser.checkParCount(1))
3908 QColor c=parser.parColor(ok,0);
3909 if (ok) setFrameBrushColor (c);
3911 /////////////////////////////////////////////////////////////////////
3912 } else if (com=="setFramePadding")
3914 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3916 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3918 else if (parser.checkParCount(1))
3920 n=parser.parInt(ok,0);
3921 if (ok) setFramePadding(n);
3923 /////////////////////////////////////////////////////////////////////
3924 } else if (com=="setFrameBorderWidth")
3926 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3928 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3930 else if (parser.checkParCount(1))
3932 n=parser.parInt(ok,0);
3933 if (ok) setFrameBorderWidth (n);
3935 /////////////////////////////////////////////////////////////////////
3936 /* FIXME-2 else if (com=="setFrameType")
3940 parser.setError (Aborted,"Nothing selected");
3943 parser.setError (Aborted,"Type of selection is not a branch");
3944 } else if (parser.checkParCount(1))
3946 s=parser.parString(ok,0);
3950 /////////////////////////////////////////////////////////////////////
3952 /////////////////////////////////////////////////////////////////////
3953 } else if (com=="setHeading")
3957 parser.setError (Aborted,"Nothing selected");
3958 } else if (! selbi )
3960 parser.setError (Aborted,"Type of selection is not a branch");
3961 } else if (parser.checkParCount(1))
3963 s=parser.parString (ok,0);
3967 /////////////////////////////////////////////////////////////////////
3968 } else if (com=="setHideExport")
3972 parser.setError (Aborted,"Nothing selected");
3973 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3975 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3976 } else if (parser.checkParCount(1))
3978 b=parser.parBool(ok,0);
3979 if (ok) setHideExport (b);
3981 /////////////////////////////////////////////////////////////////////
3982 } else if (com=="setIncludeImagesHorizontally")
3986 parser.setError (Aborted,"Nothing selected");
3989 parser.setError (Aborted,"Type of selection is not a branch");
3990 } else if (parser.checkParCount(1))
3992 b=parser.parBool(ok,0);
3993 if (ok) setIncludeImagesHor(b);
3995 /////////////////////////////////////////////////////////////////////
3996 } else if (com=="setIncludeImagesVertically")
4000 parser.setError (Aborted,"Nothing selected");
4003 parser.setError (Aborted,"Type of selection is not a branch");
4004 } else if (parser.checkParCount(1))
4006 b=parser.parBool(ok,0);
4007 if (ok) setIncludeImagesVer(b);
4009 /////////////////////////////////////////////////////////////////////
4010 } else if (com=="setHideLinkUnselected")
4014 parser.setError (Aborted,"Nothing selected");
4015 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
4017 parser.setError (Aborted,"Type of selection does not allow hiding the link");
4018 } else if (parser.checkParCount(1))
4020 b=parser.parBool(ok,0);
4021 if (ok) setHideLinkUnselected(b);
4023 /////////////////////////////////////////////////////////////////////
4024 } else if (com=="setMapAuthor")
4026 if (parser.checkParCount(1))
4028 s=parser.parString(ok,0);
4029 if (ok) setAuthor (s);
4031 /////////////////////////////////////////////////////////////////////
4032 } else if (com=="setMapComment")
4034 if (parser.checkParCount(1))
4036 s=parser.parString(ok,0);
4037 if (ok) setComment(s);
4039 /////////////////////////////////////////////////////////////////////
4040 } else if (com=="setMapBackgroundColor")
4044 parser.setError (Aborted,"Nothing selected");
4045 } else if (! selbi )
4047 parser.setError (Aborted,"Type of selection is not a branch");
4048 } else if (parser.checkParCount(1))
4050 QColor c=parser.parColor (ok,0);
4051 if (ok) setMapBackgroundColor (c);
4053 /////////////////////////////////////////////////////////////////////
4054 } else if (com=="setMapDefLinkColor")
4058 parser.setError (Aborted,"Nothing selected");
4059 } else if (! selbi )
4061 parser.setError (Aborted,"Type of selection is not a branch");
4062 } else if (parser.checkParCount(1))
4064 QColor c=parser.parColor (ok,0);
4065 if (ok) setMapDefLinkColor (c);
4067 /////////////////////////////////////////////////////////////////////
4068 } else if (com=="setMapLinkStyle")
4070 if (parser.checkParCount(1))
4072 s=parser.parString (ok,0);
4073 if (ok) setMapLinkStyle(s);
4075 /////////////////////////////////////////////////////////////////////
4076 } else if (com=="setNote")
4080 parser.setError (Aborted,"Nothing selected");
4081 } else if (! selbi )
4083 parser.setError (Aborted,"Type of selection is not a branch");
4084 } else if (parser.checkParCount(1))
4086 s=parser.parString (ok,0);
4090 /////////////////////////////////////////////////////////////////////
4091 } else if (com=="setSelectionColor")
4093 if (parser.checkParCount(1))
4095 QColor c=parser.parColor (ok,0);
4096 if (ok) setSelectionColorInt (c);
4098 /////////////////////////////////////////////////////////////////////
4099 } else if (com=="setURL")
4103 parser.setError (Aborted,"Nothing selected");
4104 } else if (! selbi )
4106 parser.setError (Aborted,"Type of selection is not a branch");
4107 } else if (parser.checkParCount(1))
4109 s=parser.parString (ok,0);
4112 /////////////////////////////////////////////////////////////////////
4113 } else if (com=="setVymLink")
4117 parser.setError (Aborted,"Nothing selected");
4118 } else if (! selbi )
4120 parser.setError (Aborted,"Type of selection is not a branch");
4121 } else if (parser.checkParCount(1))
4123 s=parser.parString (ok,0);
4124 if (ok) setVymLink(s);
4126 } else if (com=="sortChildren")
4130 parser.setError (Aborted,"Nothing selected");
4131 } else if (! selbi )
4133 parser.setError (Aborted,"Type of selection is not a branch");
4134 } else if (parser.checkParCount(0))
4137 } else if (parser.checkParCount(1))
4139 b=parser.parBool(ok,0);
4140 if (ok) sortChildren(b);
4142 /////////////////////////////////////////////////////////////////////
4143 } else if (com=="toggleFlag")
4147 parser.setError (Aborted,"Nothing selected");
4148 } else if (! selbi )
4150 parser.setError (Aborted,"Type of selection is not a branch");
4151 } else if (parser.checkParCount(1))
4153 s=parser.parString(ok,0);
4155 selbi->toggleStandardFlag(s);
4157 /////////////////////////////////////////////////////////////////////
4158 } else if (com=="unscroll")
4162 parser.setError (Aborted,"Nothing selected");
4163 } else if (! selbi )
4165 parser.setError (Aborted,"Type of selection is not a branch");
4166 } else if (parser.checkParCount(0))
4168 if (!unscrollBranch (selbi))
4169 parser.setError (Aborted,"Could not unscroll branch");
4171 /////////////////////////////////////////////////////////////////////
4172 } else if (com=="unscrollChildren")
4176 parser.setError (Aborted,"Nothing selected");
4177 } else if (! selbi )
4179 parser.setError (Aborted,"Type of selection is not a branch");
4180 } else if (parser.checkParCount(0))
4182 unscrollChildren ();
4184 /////////////////////////////////////////////////////////////////////
4185 } else if (com=="unsetFlag")
4189 parser.setError (Aborted,"Nothing selected");
4190 } else if (! selbi )
4192 parser.setError (Aborted,"Type of selection is not a branch");
4193 } else if (parser.checkParCount(1))
4195 s=parser.parString(ok,0);
4197 selbi->deactivateStandardFlag(s);
4200 parser.setError (Aborted,"Unknown command");
4203 if (parser.errorLevel()==NoError)
4211 // TODO Error handling
4212 qWarning("VymModel::parseAtom: Error!");
4214 qWarning(parser.errorMessage());
4216 errorMsg=parser.errorMessage();
4217 returnValue=errorMsg;
4222 QVariant VymModel::runScript (const QString &script)
4224 parser.setScript (script);
4229 while (parser.next() && noErr)
4231 r=parseAtom(parser.getAtom(),noErr,errMsg);
4232 if (!noErr) //FIXME-3 need dialog box here
4233 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4238 void VymModel::setExportMode (bool b)
4240 // should be called before and after exports
4241 // depending on the settings
4242 if (b && settings.value("/export/useHideExport","true")=="true")
4243 setHideTmpMode (TreeItem::HideExport);
4245 setHideTmpMode (TreeItem::HideNone);
4248 void VymModel::exportImage(QString fname, bool askName, QString format)
4252 fname=getMapName()+".png";
4259 QFileDialog *fd=new QFileDialog (NULL);
4260 fd->setCaption (tr("Export map as image"));
4261 fd->setDirectory (lastImageDir);
4262 fd->setFileMode(QFileDialog::AnyFile);
4263 fd->setFilters (imageIO.getFilters() );
4266 fl=fd->selectedFiles();
4268 format=imageIO.getType(fd->selectedFilter());
4272 setExportMode (true);
4273 mapEditor->getScene()->update(); // FIXME-3 check this...
4274 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4275 img.save(fname, format);
4276 setExportMode (false);
4280 void VymModel::exportXML(QString dir, bool askForName)
4284 dir=browseDirectory(NULL,tr("Export XML to directory"));
4285 if (dir =="" && !reallyWriteDirectory(dir) )
4289 // Hide stuff during export, if settings want this
4290 setExportMode (true);
4292 // Create subdirectories
4295 // write to directory //FIXME-4 check totalBBox here...
4296 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4299 file.setName ( dir + "/"+mapName+".xml");
4300 if ( !file.open( QIODevice::WriteOnly ) )
4302 // This should neverever happen
4303 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4307 // Write it finally, and write in UTF8, no matter what
4308 QTextStream ts( &file );
4309 ts.setEncoding (QTextStream::UnicodeUTF8);
4313 // Now write image, too
4314 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4316 setExportMode (false);
4319 void VymModel::exportAO (QString fname,bool askName)
4324 ex.setFile (mapName+".txt");
4330 //ex.addFilter ("TXT (*.txt)");
4331 ex.setDir(lastImageDir);
4332 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4337 setExportMode(true);
4339 setExportMode(false);
4343 void VymModel::exportASCII(QString fname,bool askName)
4348 ex.setFile (mapName+".txt");
4354 //ex.addFilter ("TXT (*.txt)");
4355 ex.setDir(lastImageDir);
4356 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4361 setExportMode(true);
4363 setExportMode(false);
4367 void VymModel::exportHTML (const QString &dir, bool useDialog)
4369 ExportHTML ex (this);
4371 ex.doExport(useDialog);
4374 void VymModel::exportXHTML (const QString &dir, bool askForName)
4376 ExportXHTMLDialog dia(NULL);
4377 dia.setFilePath (filePath );
4378 dia.setMapName (mapName );
4380 if (dir!="") dia.setDir (dir);
4386 if (dia.exec()!=QDialog::Accepted)
4390 QDir d (dia.getDir());
4391 // Check, if warnings should be used before overwriting
4392 // the output directory
4393 if (d.exists() && d.count()>0)
4396 warn.showCancelButton (true);
4397 warn.setText(QString(
4398 "The directory %1 is not empty.\n"
4399 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4400 warn.setCaption("Warning: Directory not empty");
4401 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4403 if (warn.exec()!=QDialog::Accepted) ok=false;
4410 exportXML (dia.getDir(),false );
4411 dia.doExport(mapName );
4412 //if (dia.hasChanged()) setChanged();
4416 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4421 if (ex.setConfigFile(cf))
4423 setExportMode (true);
4424 ex.exportPresentation();
4425 setExportMode (false);
4432 //////////////////////////////////////////////
4434 //////////////////////////////////////////////
4436 void VymModel::registerEditor(QWidget *me)
4438 mapEditor=(MapEditor*)me;
4441 void VymModel::unregisterEditor(QWidget *)
4446 void VymModel::setMapZoomFactor (const double &d)
4451 void VymModel::setContextPos(QPointF p)
4456 void VymModel::unsetContextPos()
4458 contextPos=QPointF();
4461 void VymModel::updateNoteFlag()
4463 TreeItem *selti=getSelectedItem();
4472 if (textEditor->isEmpty())
4475 selti->setNote (textEditor->getText());
4476 emitDataHasChanged(selti);
4480 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4482 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4483 if (blockReposition) return;
4485 for (int i=0;i<rootItem->branchCount(); i++)
4486 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4487 //emitSelectionChanged();
4491 void VymModel::setMapLinkStyle (const QString & s)
4496 case LinkableMapObj::Line :
4499 case LinkableMapObj::Parabel:
4500 snow="StyleParabel";
4502 case LinkableMapObj::PolyLine:
4503 snow="StylePolyLine";
4505 case LinkableMapObj::PolyParabel:
4506 snow="StylePolyParabel";
4509 snow="UndefinedStyle";
4514 QString("setMapLinkStyle (\"%1\")").arg(s),
4515 QString("setMapLinkStyle (\"%1\")").arg(snow),
4516 QString("Set map link style (\"%1\")").arg(s)
4520 linkstyle=LinkableMapObj::Line;
4521 else if (s=="StyleParabel")
4522 linkstyle=LinkableMapObj::Parabel;
4523 else if (s=="StylePolyLine")
4524 linkstyle=LinkableMapObj::PolyLine;
4525 else if (s=="StylePolyParabel")
4526 linkstyle=LinkableMapObj::PolyParabel;
4528 linkstyle=LinkableMapObj::UndefinedStyle;
4530 BranchItem *cur=NULL;
4531 BranchItem *prev=NULL;
4533 nextBranch (cur,prev);
4536 bo=(BranchObj*)(cur->getLMO() );
4537 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4538 cur=nextBranch(cur,prev);
4543 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4548 uint VymModel::getID()
4553 void VymModel::setMapDefLinkColor(QColor col)
4555 if ( !col.isValid() ) return;
4557 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4558 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4559 QString("Set map link color to %1").arg(col.name())
4563 BranchItem *cur=NULL;
4564 BranchItem *prev=NULL;
4566 cur=nextBranch(cur,prev);
4569 bo=(BranchObj*)(cur->getLMO() );
4571 nextBranch(cur,prev);
4576 void VymModel::setMapLinkColorHintInt()
4578 // called from setMapLinkColorHint(lch) or at end of parse
4579 BranchItem *cur=NULL;
4580 BranchItem *prev=NULL;
4582 cur=nextBranch(cur,prev);
4585 bo=(BranchObj*)(cur->getLMO() );
4587 cur=nextBranch(cur,prev);
4591 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4594 setMapLinkColorHintInt();
4597 void VymModel::toggleMapLinkColorHint()
4599 if (linkcolorhint==LinkableMapObj::HeadingColor)
4600 linkcolorhint=LinkableMapObj::DefaultColor;
4602 linkcolorhint=LinkableMapObj::HeadingColor;
4603 BranchItem *cur=NULL;
4604 BranchItem *prev=NULL;
4606 cur=nextBranch(cur,prev);
4609 bo=(BranchObj*)(cur->getLMO() );
4611 nextBranch(cur,prev);
4615 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4617 Q3FileDialog *fd=new Q3FileDialog( NULL);
4618 fd->setMode (Q3FileDialog::ExistingFile);
4619 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4620 ImagePreview *p =new ImagePreview (fd);
4621 fd->setContentsPreviewEnabled( TRUE );
4622 fd->setContentsPreview( p, p );
4623 fd->setPreviewMode( Q3FileDialog::Contents );
4624 fd->setCaption(vymName+" - " +tr("Load background image"));
4625 fd->setDir (lastImageDir);
4628 if ( fd->exec() == QDialog::Accepted )
4630 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4631 lastImageDir=QDir (fd->dirPath());
4632 setMapBackgroundImage (fd->selectedFile());
4636 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4638 QColor oldcol=mapScene->backgroundBrush().color();
4642 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4644 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4645 QString("Set background color of map to %1").arg(col.name()));
4648 brush.setTextureImage (QPixmap (fn));
4649 mapScene->setBackgroundBrush(brush);
4652 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4654 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4655 if ( !col.isValid() ) return;
4656 setMapBackgroundColor( col );
4660 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4662 QColor oldcol=mapScene->backgroundBrush().color();
4664 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4665 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4666 QString("Set background color of map to %1").arg(col.name()));
4667 mapScene->setBackgroundBrush(col);
4670 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4672 return mapScene->backgroundBrush().color();
4676 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4678 return linkcolorhint;
4681 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4683 return defLinkColor;
4686 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4691 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4693 return defXLinkColor;
4696 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4701 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4703 return defXLinkWidth;
4706 void VymModel::move(const double &x, const double &y)
4709 MapItem *seli = (MapItem*)getSelectedItem();
4710 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4712 LinkableMapObj *lmo=seli->getLMO();
4715 QPointF ap(lmo->getAbsPos());
4719 QString ps=qpointFToString(ap);
4720 QString s=getSelectString(seli);
4723 s, "move "+qpointFToString(to),
4724 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4727 emitSelectionChanged();
4733 void VymModel::moveRel (const double &x, const double &y)
4736 MapItem *seli = (MapItem*)getSelectedItem();
4737 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4739 LinkableMapObj *lmo=seli->getLMO();
4742 QPointF rp(lmo->getRelPos());
4746 QString ps=qpointFToString (lmo->getRelPos());
4747 QString s=getSelectString(seli);
4750 s, "moveRel "+qpointFToString(to),
4751 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4752 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4754 lmo->updateLinkGeometry();
4755 emitSelectionChanged();
4762 void VymModel::animate()
4764 animationTimer->stop();
4767 while (i<animObjList.size() )
4769 bo=(BranchObj*)animObjList.at(i);
4774 animObjList.removeAt(i);
4781 QItemSelection sel=selModel->selection();
4782 emit (selectionChanged(sel,sel));
4785 if (!animObjList.isEmpty()) animationTimer->start();
4789 void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
4793 if (bo->getUseRelPos())
4794 startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
4796 startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
4799 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4801 if (start==dest) return;
4802 if (bo && bo->getTreeItem()->depth()>=0)
4805 ap.setStart (start);
4807 ap.setTicks (animationTicks);
4808 ap.setAnimated (true);
4809 bo->setAnimation (ap);
4810 if (!animObjList.contains(bo))
4811 animObjList.append( bo );
4812 animationTimer->setSingleShot (true);
4813 animationTimer->start(animationInterval);
4817 void VymModel::stopAnimation (MapObj *mo)
4819 int i=animObjList.indexOf(mo);
4821 animObjList.removeAt (i);
4824 void VymModel::sendSelection()
4826 if (netstate!=Server) return;
4827 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4830 void VymModel::newServer()
4834 tcpServer = new QTcpServer(this);
4835 if (!tcpServer->listen(QHostAddress::Any,port)) {
4836 QMessageBox::critical(NULL, "vym server",
4837 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4838 //FIXME-3 needed? we are no widget any longer... close();
4841 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4843 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4846 void VymModel::connectToServer()
4849 server="salam.suse.de";
4851 clientSocket = new QTcpSocket (this);
4852 clientSocket->abort();
4853 clientSocket->connectToHost(server ,port);
4854 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4855 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4856 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4858 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4863 void VymModel::newClient()
4865 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4866 connect(newClient, SIGNAL(disconnected()),
4867 newClient, SLOT(deleteLater()));
4869 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4871 clientList.append (newClient);
4875 void VymModel::sendData(const QString &s)
4877 if (clientList.size()==0) return;
4879 // Create bytearray to send
4881 QDataStream out(&block, QIODevice::WriteOnly);
4882 out.setVersion(QDataStream::Qt_4_0);
4884 // Reserve some space for blocksize
4887 // Write sendCounter
4888 out << sendCounter++;
4893 // Go back and write blocksize so far
4894 out.device()->seek(0);
4895 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4899 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4901 for (int i=0; i<clientList.size(); ++i)
4903 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4904 clientList.at(i)->write (block);
4908 void VymModel::readData ()
4910 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4913 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4917 QDataStream in(clientSocket);
4918 in.setVersion(QDataStream::Qt_4_0);
4926 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4929 parseAtom (t,noErr,errMsg);
4935 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4937 switch (socketError) {
4938 case QAbstractSocket::RemoteHostClosedError:
4940 case QAbstractSocket::HostNotFoundError:
4941 QMessageBox::information(NULL, vymName +" Network client",
4942 "The host was not found. Please check the "
4943 "host name and port settings.");
4945 case QAbstractSocket::ConnectionRefusedError:
4946 QMessageBox::information(NULL, vymName + " Network client",
4947 "The connection was refused by the peer. "
4948 "Make sure the fortune server is running, "
4949 "and check that the host name and port "
4950 "settings are correct.");
4953 QMessageBox::information(NULL, vymName + " Network client",
4954 QString("The following error occurred: %1.")
4955 .arg(clientSocket->errorString()));
4959 /* FIXME-3 Playing with DBUS...
4960 QDBusVariant VymModel::query (const QString &query)
4962 TreeItem *selti=getSelectedItem();
4964 return QDBusVariant (selti->getHeading());
4966 return QDBusVariant ("Nothing selected.");
4970 void VymModel::testslot() //FIXME-3 Playing with DBUS
4972 cout << "VM::testslot called\n";
4975 void VymModel::selectMapSelectionColor()
4977 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4978 setSelectionColor (col);
4981 void VymModel::setSelectionColorInt (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())
4990 mapEditor->setSelectionColor (col);
4993 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4995 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4996 //FIXME-3 emitShowSelection();
5000 void VymModel::emitSelectionChanged()
5002 QItemSelection newsel=selModel->selection();
5003 emitSelectionChanged (newsel);
5006 void VymModel::setSelectionColor(QColor col)
5008 if ( !col.isValid() ) return;
5010 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
5011 QString("setSelectionColor (%1)").arg(col.name()),
5012 QString("Set color of selection box to %1").arg(col.name())
5014 setSelectionColorInt (col);
5017 QColor VymModel::getSelectionColor()
5019 return mapEditor->getSelectionColor();
5022 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
5025 for (int i=0;i<rootItem->branchCount();i++)
5026 rootItem->getBranchNum(i)->setHideTmp (mode);
5028 if (mode==TreeItem::HideExport)
5034 //////////////////////////////////////////////
5035 // Selection related
5036 //////////////////////////////////////////////
5038 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5043 QItemSelectionModel* VymModel::getSelectionModel()
5048 void VymModel::setSelectionBlocked (bool b)
5053 bool VymModel::isSelectionBlocked()
5055 return selectionBlocked;
5058 bool VymModel::select ()
5060 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5063 bool VymModel::select (const QString &s)
5070 TreeItem *ti=findBySelectString(s);
5071 if (ti) return select (index(ti));
5075 bool VymModel::select (LinkableMapObj *lmo)
5077 QItemSelection oldsel=selModel->selection();
5080 return select (index (lmo->getTreeItem()) );
5085 bool VymModel::select (TreeItem *ti)
5087 if (ti) return select (index(ti));
5091 bool VymModel::select (TreeItem *ti, int i)
5093 if (!ti || i<0) return false;
5094 if (select (index(ti)))
5096 qDebug ()<<"VM::select with index: "<<i<<" Trying to find text in note ";
5097 QTextCursor c=textEditor->getTextCursor();
5098 c.setPosition (i-1,QTextCursor::MoveAnchor);
5099 textEditor->setTextCursor (c);
5101 qDebug ()<<"VM::select with index: "<<i<<" Giving up to find text in note ";
5105 bool VymModel::select (const QModelIndex &index)
5107 if (index.isValid() )
5109 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5110 BranchItem *bi=getSelectedBranch();
5111 if (bi) bi->setLastSelectedBranch();
5117 void VymModel::unselect()
5119 if (!selModel->selectedIndexes().isEmpty())
5121 lastSelectString=getSelectString();
5122 selModel->clearSelection();
5126 bool VymModel::reselect()
5128 return select (lastSelectString);
5131 void VymModel::emitShowSelection()
5133 if (!blockReposition)
5134 emit (showSelection() );
5137 void VymModel::emitNoteHasChanged (TreeItem *ti)
5139 QModelIndex ix=index(ti);
5140 emit (noteHasChanged (ix) );
5143 void VymModel::emitDataHasChanged (TreeItem *ti)
5145 QModelIndex ix=index(ti);
5146 emit (dataChanged (ix,ix) );
5149 void VymModel::emitUpdateLayout()
5151 if (settings.value("/mainwindow/autoLayout/use","true")=="true")
5152 emit (updateLayout());
5155 bool VymModel::selectFirstBranch()
5157 TreeItem *ti=getSelectedBranch();
5160 TreeItem *par=ti->parent();
5163 TreeItem *ti2=par->getFirstBranch();
5164 if (ti2) return select(ti2);
5170 bool VymModel::selectLastBranch()
5172 TreeItem *ti=getSelectedBranch();
5175 TreeItem *par=ti->parent();
5178 TreeItem *ti2=par->getLastBranch();
5179 if (ti2) return select(ti2);
5185 bool VymModel::selectLastSelectedBranch()
5187 BranchItem *bi=getSelectedBranch();
5190 bi=bi->getLastSelectedBranch();
5191 if (bi) return select (bi);
5196 bool VymModel::selectParent()
5198 TreeItem *ti=getSelectedItem();
5209 TreeItem::Type VymModel::selectionType()
5211 QModelIndexList list=selModel->selectedIndexes();
5212 if (list.isEmpty()) return TreeItem::Undefined;
5213 TreeItem *ti = getItem (list.first() );
5214 return ti->getType();
5218 LinkableMapObj* VymModel::getSelectedLMO()
5220 QModelIndexList list=selModel->selectedIndexes();
5221 if (!list.isEmpty() )
5223 TreeItem *ti = getItem (list.first() );
5224 TreeItem::Type type=ti->getType();
5225 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5226 return ((MapItem*)ti)->getLMO();
5231 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5233 TreeItem *ti = getSelectedBranch();
5235 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5240 BranchItem* VymModel::getSelectedBranch()
5242 QModelIndexList list=selModel->selectedIndexes();
5243 if (!list.isEmpty() )
5245 TreeItem *ti = getItem (list.first() );
5246 TreeItem::Type type=ti->getType();
5247 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5248 return (BranchItem*)ti;
5253 ImageItem* VymModel::getSelectedImage()
5255 QModelIndexList list=selModel->selectedIndexes();
5256 if (!list.isEmpty())
5258 TreeItem *ti=getItem (list.first());
5259 if (ti && ti->getType()==TreeItem::Image)
5260 return (ImageItem*)ti;
5265 AttributeItem* VymModel::getSelectedAttribute()
5267 QModelIndexList list=selModel->selectedIndexes();
5268 if (!list.isEmpty() )
5270 TreeItem *ti = getItem (list.first() );
5271 TreeItem::Type type=ti->getType();
5272 if (type ==TreeItem::Attribute)
5273 return (AttributeItem*)ti;
5278 TreeItem* VymModel::getSelectedItem()
5280 QModelIndexList list=selModel->selectedIndexes();
5281 if (!list.isEmpty() )
5282 return getItem (list.first() );
5287 QModelIndex VymModel::getSelectedIndex()
5289 QModelIndexList list=selModel->selectedIndexes();
5290 if (list.isEmpty() )
5291 return QModelIndex();
5293 return list.first();
5296 QString VymModel::getSelectString ()
5298 return getSelectString (getSelectedItem());
5301 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5303 if (!lmo) return QString();
5304 return getSelectString (lmo->getTreeItem() );
5307 QString VymModel::getSelectString (TreeItem *ti)
5311 switch (ti->getType())
5313 case TreeItem::MapCenter: s="mc:"; break;
5314 case TreeItem::Branch: s="bo:";break;
5315 case TreeItem::Image: s="fi:";break;
5316 case TreeItem::Attribute: s="ai:";break;
5317 case TreeItem::XLink: s="xl:";break;
5319 s="unknown type in VymModel::getSelectString()";
5322 s= s + QString("%1").arg(ti->num());
5324 // call myself recursively
5325 s= getSelectString(ti->parent()) +","+s;