1 #include <QApplication>
7 #include "branchitem.h"
8 #include "mapcenteritem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
15 #include "mapcenterobj.h"
18 #include "selection.h"
21 #include "warningdialog.h"
22 #include "xml-freemind.h"
28 extern Main *mainWindow;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
34 extern QString clipboardDir;
35 extern QString clipboardFile;
36 extern bool clipboardEmpty;
38 extern ImageIO imageIO;
40 extern QString vymName;
41 extern QString vymVersion;
42 extern QDir vymBaseDir;
44 extern QDir lastImageDir;
45 extern QDir lastFileDir;
47 extern FlagRowObj *standardFlagsDefault;
49 extern Settings settings;
53 int VymModel::mapNum=0; // make instance
57 // cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 // cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
71 void VymModel::clear()
73 selModel->clearSelection();
75 //QModelIndex ri=index(rootItem);
76 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
79 void VymModel::init ()
81 // We should have at least one map center to start with
82 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
87 // Also no scene yet (should not be needed anyway) FIXME-3 VM
100 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
101 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
102 mainWindow->updateHistory (undoSet);
105 makeTmpDirectories();
110 fileName=tr("unnamed");
112 blockReposition=false;
113 blockSaveState=false;
115 autosaveTimer=new QTimer (this);
116 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
118 fileChangedTimer=new QTimer (this);
119 fileChangedTimer->start(3000);
120 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
132 animationUse=settings.readBoolEntry("/animation/use",false);
133 animationTicks=settings.readNumEntry("/animation/ticks",10);
134 animationInterval=settings.readNumEntry("/animation/interval",50);
136 animationTimer=new QTimer (this);
137 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
140 defLinkColor=QColor (0,0,255);
141 defXLinkColor=QColor (180,180,180);
142 linkcolorhint=LinkableMapObj::DefaultColor;
143 linkstyle=LinkableMapObj::PolyParabel;
145 defXLinkColor=QColor (230,230,230);
147 hidemode=TreeItem::HideNone;
153 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
157 void VymModel::makeTmpDirectories()
159 // Create unique temporary directories
160 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
161 histPath = tmpMapDir+"/history";
167 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
172 bool VymModel::isRepositionBlocked()
174 return blockReposition;
177 void VymModel::updateActions() // FIXME-2 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) ) +
233 s+=xml.beginElement("vymmap",mapAttr);
236 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
237 standardFlagsDefault->resetUsedCounter();
239 // Reset the counters before saving
240 // TODO constr. of FIO creates lots of objects, better do this in some other way...
241 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
243 cout << "VM::saveToDir 0 " <<saveSel<<endl;
244 // Build xml recursivly
245 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
246 // Save all mapcenters as complete map, if saveSel not set
247 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
250 if (saveSel->getType()==TreeItem::Branch)
252 s+=saveSel->saveToDir(tmpdir,prefix,offset);
253 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
255 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
258 cout << "VM::saveToDir 1 \n";
259 // Save local settings
260 s+=settings.getDataXML (destPath);
262 cout << "VM::saveToDir 2 \n";
264 if (getSelectedItem() && !saveSel )
265 s+=xml.valueElement("select",getSelectString());
268 s+=xml.endElement("vymmap");
271 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
275 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
279 for (int i=0; i<rootItem->branchCount(); i++)
280 s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
284 void VymModel::setFilePath(QString fpath, QString destname)
286 if (fpath.isEmpty() || fpath=="")
293 filePath=fpath; // becomes absolute path
294 fileName=fpath; // gets stripped of path
295 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
297 // If fpath is not an absolute path, complete it
298 filePath=QDir(fpath).absPath();
299 fileDir=filePath.left (1+filePath.findRev ("/"));
301 // Set short name, too. Search from behind:
302 int i=fileName.findRev("/");
303 if (i>=0) fileName=fileName.remove (0,i+1);
305 // Forget the .vym (or .xml) for name of map
306 mapName=fileName.left(fileName.findRev(".",-1,true) );
310 void VymModel::setFilePath(QString fpath)
312 setFilePath (fpath,fpath);
315 QString VymModel::getFilePath()
320 QString VymModel::getFileName()
325 QString VymModel::getMapName()
330 QString VymModel::getDestPath()
335 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
337 ErrorCode err=success;
339 parseBaseHandler *handler;
343 case VymMap: handler=new parseVYMHandler; break;
344 case FreemindMap : handler=new parseFreemindHandler; break;
346 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
347 "Unknown FileType in VymModel::load()");
351 bool zipped_org=zipped;
355 selModel->clearSelection();
356 // FIXME-2 VM not needed??? model->setMapEditor(this);
357 // (map state is set later at end of load...)
360 BranchItem *bi=getSelectedBranchItem();
361 if (!bi) return aborted;
362 if (lmode==ImportAdd)
363 saveStateChangingPart(
366 QString("addMapInsert (%1)").arg(fname),
367 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
369 saveStateChangingPart(
372 QString("addMapReplace(%1)").arg(fname),
373 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
377 // Create temporary directory for packing
379 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
382 QMessageBox::critical( 0, tr( "Critical Load Error" ),
383 tr("Couldn't create temporary directory before load\n"));
388 err=unzipDir (tmpZipDir,fname);
398 // Look for mapname.xml
399 xmlfile= fname.left(fname.findRev(".",-1,true));
400 xmlfile=xmlfile.section( '/', -1 );
401 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
402 if (!mfile.exists() )
404 // mapname.xml does not exist, well,
405 // maybe someone renamed the mapname.vym file...
406 // Try to find any .xml in the toplevel
407 // directory of the .vym file
408 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
409 if (flist.count()==1)
411 // Only one entry, take this one
412 xmlfile=tmpZipDir + "/"+flist.first();
415 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
416 *it=tmpZipDir + "/" + *it;
417 // TODO Multiple entries, load all (but only the first one into this ME)
418 //mainWindow->fileLoadFromTmp (flist);
419 //returnCode=1; // Silently forget this attempt to load
420 qWarning ("MainWindow::load (fn) multimap found...");
423 if (flist.isEmpty() )
425 QMessageBox::critical( 0, tr( "Critical Load Error" ),
426 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
429 } //file doesn't exist
431 xmlfile=mfile.name();
434 QFile file( xmlfile);
436 // I am paranoid: file should exist anyway
437 // according to check in mainwindow.
440 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
441 tr(QString("Couldn't open map %1").arg(file.name())));
445 bool blockSaveStateOrg=blockSaveState;
446 blockReposition=true;
448 QXmlInputSource source( file);
449 QXmlSimpleReader reader;
450 reader.setContentHandler( handler );
451 reader.setErrorHandler( handler );
452 handler->setModel ( this);
455 // We need to set the tmpDir in order to load files with rel. path
460 tmpdir=fname.left(fname.findRev("/",-1));
461 handler->setTmpDir (tmpdir);
462 handler->setInputFile (file.name());
463 handler->setLoadMode (lmode);
464 bool ok = reader.parse( source );
465 blockReposition=false;
466 blockSaveState=blockSaveStateOrg;
470 reposition(); // FIXME-2 VM reposition the view instead...
477 autosaveTimer->stop();
480 // Reset timestamp to check for later updates of file
481 fileChangedTime=QFileInfo (destPath).lastModified();
484 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
485 tr( handler->errorProtocol() ) );
487 // Still return "success": the map maybe at least
488 // partially read by the parser
493 removeDir (QDir(tmpZipDir));
495 // Restore original zip state
502 ErrorCode VymModel::save (const SaveMode &savemode)
506 QString safeFilePath;
508 ErrorCode err=success;
512 mapFileName=mapName+".xml";
514 // use name given by user, even if he chooses .doc
515 mapFileName=fileName;
517 // Look, if we should zip the data:
520 QMessageBox mb( vymName,
521 tr("The map %1\ndid not use the compressed "
522 "vym file format.\nWriting it uncompressed will also write images \n"
523 "and flags and thus may overwrite files in the "
524 "given directory\n\nDo you want to write the map").arg(filePath),
525 QMessageBox::Warning,
526 QMessageBox::Yes | QMessageBox::Default,
528 QMessageBox::Cancel | QMessageBox::Escape);
529 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
530 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
531 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
534 case QMessageBox::Yes:
535 // save compressed (default file format)
538 case QMessageBox::No:
542 case QMessageBox::Cancel:
549 // First backup existing file, we
550 // don't want to add to old zip archives
554 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
556 QString backupFileName(destPath + "~");
557 QFile backupFile(backupFileName);
558 if (backupFile.exists() && !backupFile.remove())
560 QMessageBox::warning(0, tr("Save Error"),
561 tr("%1\ncould not be removed before saving").arg(backupFileName));
563 else if (!f.rename(backupFileName))
565 QMessageBox::warning(0, tr("Save Error"),
566 tr("%1\ncould not be renamed before saving").arg(destPath));
573 // Create temporary directory for packing
575 tmpZipDir=makeTmpDir (ok,"vym-zip");
578 QMessageBox::critical( 0, tr( "Critical Load Error" ),
579 tr("Couldn't create temporary directory before save\n"));
583 safeFilePath=filePath;
584 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
587 // Create mapName and fileDir
588 makeSubDirs (fileDir);
591 if (savemode==CompleteMap || selection.isEmpty())
594 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
597 autosaveTimer->stop();
602 if (selectionType()==TreeItem::Image)
605 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
606 // TODO take care of multiselections
609 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
612 qWarning ("ME::saveStringToDisk failed!");
618 if (err==success) err=zipDir (tmpZipDir,destPath);
621 removeDir (QDir(tmpZipDir));
623 // Restore original filepath outside of tmp zip dir
624 setFilePath (safeFilePath);
628 fileChangedTime=QFileInfo (destPath).lastModified();
632 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
634 QString pathDir=path.left(path.findRev("/"));
640 // We need to parse saved XML data
641 parseVYMHandler handler;
642 QXmlInputSource source( file);
643 QXmlSimpleReader reader;
644 reader.setContentHandler( &handler );
645 reader.setErrorHandler( &handler );
646 handler.setModel ( this);
647 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
648 if (undoSel.isEmpty())
652 handler.setLoadMode (NewMap);
656 handler.setLoadMode (ImportReplace);
658 blockReposition=true;
659 bool ok = reader.parse( source );
660 blockReposition=false;
663 // This should never ever happen
664 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
665 handler.errorProtocol());
668 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
671 void VymModel::addMapInsertInt (const QString &path, int pos)
673 /* FIXME-2 addMapInsertInt not ported yet
674 BranchObj *sel=getSelectedBranch();
677 QString pathDir=path.left(path.findRev("/"));
683 // We need to parse saved XML data
684 parseVYMHandler handler;
685 QXmlInputSource source( file);
686 QXmlSimpleReader reader;
687 reader.setContentHandler( &handler );
688 reader.setErrorHandler( &handler );
689 handler.setModel (this);
690 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
691 handler.setLoadMode (ImportAdd);
692 blockReposition=true;
693 bool ok = reader.parse( source );
694 blockReposition=false;
697 // This should never ever happen
698 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
699 handler.errorProtocol());
701 if (sel->getDepth()>0)
702 sel->getLastBranch()->linkTo (sel,pos);
704 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
709 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
711 TreeItem *fi=createImage();
714 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
722 void VymModel::loadFloatImage () // FIXME-2
725 BranchObj *bo=getSelectedBranch();
729 Q3FileDialog *fd=new Q3FileDialog( NULL);
730 fd->setMode (Q3FileDialog::ExistingFiles);
731 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
732 ImagePreview *p =new ImagePreview (fd);
733 fd->setContentsPreviewEnabled( TRUE );
734 fd->setContentsPreview( p, p );
735 fd->setPreviewMode( Q3FileDialog::Contents );
736 fd->setCaption(vymName+" - " +tr("Load image"));
737 fd->setDir (lastImageDir);
740 if ( fd->exec() == QDialog::Accepted )
742 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
743 lastImageDir=QDir (fd->dirPath());
746 for (int j=0; j<fd->selectedFiles().count(); j++)
748 s=fd->selectedFiles().at(j);
749 fio=loadFloatImageInt (s);
752 (LinkableMapObj*)fio,
755 QString ("loadImage (%1)").arg(s ),
756 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
759 // TODO loadFIO error handling
760 qWarning ("Failed to load "+s);
769 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
774 void VymModel::saveFloatImage ()
776 FloatImageObj *fio=selection.getFloatImage();
779 QFileDialog *fd=new QFileDialog( NULL);
780 fd->setFilters (imageIO.getFilters());
781 fd->setCaption(vymName+" - " +tr("Save image"));
782 fd->setFileMode( QFileDialog::AnyFile );
783 fd->setDirectory (lastImageDir);
784 // fd->setSelection (fio->getOriginalFilename());
788 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
790 fn=fd->selectedFiles().at(0);
791 if (QFile (fn).exists() )
793 QMessageBox mb( vymName,
794 tr("The file %1 exists already.\n"
795 "Do you want to overwrite it?").arg(fn),
796 QMessageBox::Warning,
797 QMessageBox::Yes | QMessageBox::Default,
798 QMessageBox::Cancel | QMessageBox::Escape,
799 QMessageBox::NoButton );
801 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
802 mb.setButtonText( QMessageBox::No, tr("Cancel"));
805 case QMessageBox::Yes:
808 case QMessageBox::Cancel:
815 saveFloatImageInt (fio,fd->selectedFilter(),fn );
822 void VymModel::importDirInt(BranchObj *dst, QDir d)
824 /* FIXME-2 importDirInt not ported yet
825 BranchObj *bo=getSelectedBranch();
828 // Traverse directories
829 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
830 QFileInfoList list = d.entryInfoList();
833 for (int i = 0; i < list.size(); ++i)
836 if (fi.fileName() != "." && fi.fileName() != ".." )
839 bo=dst->getLastBranch();
840 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
841 bi->setHeading (fi.fileName() ); // FIXME-3 check this
842 bo->setColor (QColor("blue"));
844 if ( !d.cd(fi.fileName()) )
845 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
848 // Recursively add subdirs
855 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
856 list = d.entryInfoList();
858 for (int i = 0; i < list.size(); ++i)
862 bo=dst->getLastBranch();
863 bo->setHeading (fi.fileName() );
864 bo->setColor (QColor("black"));
865 if (fi.fileName().right(4) == ".vym" )
866 bo->setVymLink (fi.filePath());
872 void VymModel::importDirInt (const QString &s) // FIXME-2
875 BranchObj *bo=getSelectedBranch();
878 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
886 void VymModel::importDir() //FIXME-2
889 BranchObj *bo=getSelectedBranch();
893 filters <<"VYM map (*.vym)";
894 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
895 fd->setMode (QFileDialog::DirectoryOnly);
896 fd->setFilters (filters);
897 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
901 if ( fd->exec() == QDialog::Accepted )
903 importDirInt (fd->selectedFile() );
905 //FIXME-3 VM needed? scene()->update();
912 void VymModel::autosave()
917 cout << "VymModel::autosave rejected due to missing filePath\n";
920 QDateTime now=QDateTime().currentDateTime();
922 // Disable autosave, while we have gone back in history
923 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
924 if (redosAvail>0) return;
926 // Also disable autosave for new map without filename
927 if (filePath.isEmpty()) return;
930 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
932 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
933 mainWindow->fileSave (this);
936 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
941 void VymModel::fileChanged()
943 // Check if file on disk has changed meanwhile
944 if (!filePath.isEmpty())
946 QDateTime tmod=QFileInfo (filePath).lastModified();
947 if (tmod>fileChangedTime)
949 // FIXME-2 VM switch to current mapeditor and finish lineedits...
950 QMessageBox mb( vymName,
951 tr("The file of the map on disk has changed:\n\n"
952 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
953 QMessageBox::Question,
955 QMessageBox::Cancel | QMessageBox::Default,
956 QMessageBox::NoButton );
958 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
959 mb.setButtonText( QMessageBox::No, tr("Ignore"));
962 case QMessageBox::Yes:
964 load (filePath,NewMap,fileType);
965 case QMessageBox::Cancel:
966 fileChangedTime=tmod; // allow autosave to overwrite newer file!
972 bool VymModel::isDefault()
977 void VymModel::makeDefault()
983 bool VymModel::hasChanged()
988 void VymModel::setChanged()
991 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
995 latestAddedItem=NULL;
999 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1002 if (!lmo) return QString("Error: NULL has no name!");
1004 if ((typeid(*lmo) == typeid(BranchObj) ||
1005 typeid(*lmo) == typeid(MapCenterObj)))
1008 s=lmo->getTreeItem()->getHeading();
1009 if (s=="") s="unnamed";
1010 return QString("branch (%1)").arg(s);
1012 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1013 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1014 return QString("Unknown type has no name!");
1018 QString VymModel::getObjectName (const TreeItem *ti)
1021 if (!ti) return QString("Error: NULL has no name!");
1023 if (ti->isBranchLikeType() )
1026 if (s=="") s="unnamed";
1027 return QString("branch (%1)").arg(s);
1029 /* FIXME-2 move floatimage to TreeModel first
1030 if (type==TreeItem::Image)
1031 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1033 return QString("Unknown type has no name!");
1036 void VymModel::redo()
1038 // Can we undo at all?
1039 if (redosAvail<1) return;
1041 bool blockSaveStateOrg=blockSaveState;
1042 blockSaveState=true;
1046 if (undosAvail<stepsTotal) undosAvail++;
1048 if (curStep>stepsTotal) curStep=1;
1049 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1050 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1051 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1052 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1053 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1054 QString version=undoSet.readEntry ("/history/version");
1056 /* TODO Maybe check for version, if we save the history
1057 if (!checkVersion(version))
1058 QMessageBox::warning(0,tr("Warning"),
1059 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1062 // Find out current undo directory
1063 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1067 cout << "VymModel::redo() begin\n";
1068 cout << " undosAvail="<<undosAvail<<endl;
1069 cout << " redosAvail="<<redosAvail<<endl;
1070 cout << " curStep="<<curStep<<endl;
1071 cout << " ---------------------------"<<endl;
1072 cout << " comment="<<comment.toStdString()<<endl;
1073 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1074 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1075 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1076 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1077 cout << " ---------------------------"<<endl<<endl;
1080 // select object before redo
1081 if (!redoSelection.isEmpty())
1082 select (redoSelection);
1085 parseAtom (redoCommand);
1088 blockSaveState=blockSaveStateOrg;
1090 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1091 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1092 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1093 undoSet.writeSettings(histPath);
1095 mainWindow->updateHistory (undoSet);
1098 /* TODO remove testing
1099 cout << "ME::redo() end\n";
1100 cout << " undosAvail="<<undosAvail<<endl;
1101 cout << " redosAvail="<<redosAvail<<endl;
1102 cout << " curStep="<<curStep<<endl;
1103 cout << " ---------------------------"<<endl<<endl;
1109 bool VymModel::isRedoAvailable()
1111 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1117 void VymModel::undo()
1119 // Can we undo at all?
1120 if (undosAvail<1) return;
1122 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1124 bool blockSaveStateOrg=blockSaveState;
1125 blockSaveState=true;
1127 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1128 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1129 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1130 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1131 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1132 QString version=undoSet.readEntry ("/history/version");
1134 /* TODO Maybe check for version, if we save the history
1135 if (!checkVersion(version))
1136 QMessageBox::warning(0,tr("Warning"),
1137 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1140 // Find out current undo directory
1141 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1143 // select object before undo
1144 if (!undoSelection.isEmpty())
1145 select (undoSelection);
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;
1161 parseAtom (undoCommand);
1166 if (curStep<1) curStep=stepsTotal;
1170 blockSaveState=blockSaveStateOrg;
1171 /* TODO remove testing
1172 cout << "VymModel::undo() end\n";
1173 cout << " undosAvail="<<undosAvail<<endl;
1174 cout << " redosAvail="<<redosAvail<<endl;
1175 cout << " curStep="<<curStep<<endl;
1176 cout << " ---------------------------"<<endl<<endl;
1179 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1180 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1181 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1182 undoSet.writeSettings(histPath);
1184 mainWindow->updateHistory (undoSet);
1187 ensureSelectionVisible();
1190 bool VymModel::isUndoAvailable()
1192 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1198 void VymModel::gotoHistoryStep (int i)
1200 // Restore variables
1201 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1202 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1204 if (i<0) i=undosAvail+redosAvail;
1206 // Clicking above current step makes us undo things
1209 for (int j=0; j<undosAvail-i; j++) undo();
1212 // Clicking below current step makes us redo things
1214 for (int j=undosAvail; j<i; j++)
1216 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1220 // And ignore clicking the current row ;-)
1224 QString VymModel::getHistoryPath()
1226 QString histName(QString("history-%1").arg(curStep));
1227 return (tmpMapDir+"/"+histName);
1230 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1232 sendData(redoCom); //FIXME-3 testing
1237 if (blockSaveState) return;
1239 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1241 // Find out current undo directory
1242 if (undosAvail<stepsTotal) undosAvail++;
1244 if (curStep>stepsTotal) curStep=1;
1246 QString backupXML="";
1247 QString histDir=getHistoryPath();
1248 QString bakMapPath=histDir+"/map.xml";
1250 // Create histDir if not available
1253 makeSubDirs (histDir);
1255 // Save depending on how much needs to be saved
1257 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1259 QString undoCommand="";
1260 if (savemode==UndoCommand)
1262 undoCommand=undoCom;
1264 else if (savemode==PartOfMap )
1266 undoCommand=undoCom;
1267 undoCommand.replace ("PATH",bakMapPath);
1271 if (!backupXML.isEmpty())
1272 // Write XML Data to disk
1273 saveStringToDisk (bakMapPath,backupXML);
1275 // We would have to save all actions in a tree, to keep track of
1276 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1279 // Write the current state to disk
1280 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1281 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1282 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1283 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1284 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1285 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1286 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1287 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1288 undoSet.setEntry (QString("/history/version"),vymVersion);
1289 undoSet.writeSettings(histPath);
1293 // TODO remove after testing
1294 //cout << " into="<< histPath.toStdString()<<endl;
1295 cout << " stepsTotal="<<stepsTotal<<
1296 ", undosAvail="<<undosAvail<<
1297 ", redosAvail="<<redosAvail<<
1298 ", curStep="<<curStep<<endl;
1299 cout << " ---------------------------"<<endl;
1300 cout << " comment="<<comment.toStdString()<<endl;
1301 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1302 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1303 cout << " redoCom="<<redoCom.toStdString()<<endl;
1304 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1305 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1306 cout << " ---------------------------"<<endl;
1309 mainWindow->updateHistory (undoSet);
1315 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1317 // save the selected part of the map, Undo will replace part of map
1318 QString undoSelection="";
1320 undoSelection=getSelectString(undoSel);
1322 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1323 QString redoSelection="";
1325 redoSelection=getSelectString(undoSel);
1327 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1330 saveState (PartOfMap,
1331 undoSelection, "addMapReplace (\"PATH\")",
1337 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1341 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1344 QString undoSelection=getSelectString (redoSel->parent() );
1345 QString redoSelection=getSelectString(redoSel);
1346 if (redoSel->getType()==TreeItem::Branch)
1348 // save the selected branch of the map, Undo will insert part of map
1349 saveState (PartOfMap,
1350 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1351 redoSelection, "delete ()",
1358 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1360 // "Normal" savestate: save commands, selections and comment
1361 // so just save commands for undo and redo
1362 // and use current selection
1364 QString redoSelection="";
1365 if (redoSel) redoSelection=getSelectString(redoSel);
1366 QString undoSelection="";
1367 if (undoSel) undoSelection=getSelectString(undoSel);
1369 saveState (UndoCommand,
1376 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1378 // "Normal" savestate: save commands, selections and comment
1379 // so just save commands for undo and redo
1380 // and use current selection
1381 saveState (UndoCommand,
1388 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1390 // "Normal" savestate applied to model (no selection needed):
1391 // save commands and comment
1392 saveState (UndoCommand,
1400 QGraphicsScene* VymModel::getScene ()
1405 TreeItem* VymModel::findBySelectString(QString s)
1407 if (s.isEmpty() ) return NULL;
1409 // Old maps don't have multiple mapcenters and don't save full path
1410 if (s.left(2) !="mc")
1413 QStringList parts=s.split (",");
1416 TreeItem *ti=rootItem;
1418 while (!parts.isEmpty() )
1420 typ=parts.first().left(2);
1421 n=parts.first().right(parts.first().length() - 3).toInt();
1422 parts.removeFirst();
1423 if (typ=="mc" || typ=="bo")
1424 ti=ti->getBranchNum (n);
1428 ti=ti->getImageNum (n);
1434 TreeItem* VymModel::findID (const QString &s)
1437 for (int i=0; i<rootItem->branchCount(); i++)
1439 ti=rootItem->getBranchNum(i)->findID (s);
1445 //////////////////////////////////////////////
1447 //////////////////////////////////////////////
1448 void VymModel::setVersion (const QString &s)
1453 void VymModel::setAuthor (const QString &s)
1456 QString ("setMapAuthor (\"%1\")").arg(author),
1457 QString ("setMapAuthor (\"%1\")").arg(s),
1458 QString ("Set author of map to \"%1\"").arg(s)
1463 QString VymModel::getAuthor()
1468 void VymModel::setComment (const QString &s)
1471 QString ("setMapComment (\"%1\")").arg(comment),
1472 QString ("setMapComment (\"%1\")").arg(s),
1473 QString ("Set comment of map")
1478 QString VymModel::getComment ()
1483 QString VymModel::getDate ()
1485 return QDate::currentDate().toString ("yyyy-MM-dd");
1488 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1491 BranchItem *cur=NULL;
1492 BranchItem *prev=NULL;
1503 void VymModel::setHeading(const QString &s)
1505 BranchItem *selbi=getSelectedBranchItem();
1510 "setHeading (\""+selbi->getHeading()+"\")",
1512 "setHeading (\""+s+"\")",
1513 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1514 selbi->setHeading(s );
1515 QModelIndex ix2=index (selbi);
1516 emit (dataChanged ( ix2,ix2));
1517 /* FIXME-3 testing only
1521 // selection.update(); //FIXME-4
1522 ensureSelectionVisible();
1526 BranchItem* VymModel::findText (QString s, bool cs)
1529 QTextDocument::FindFlags flags=0;
1530 if (cs) flags=QTextDocument::FindCaseSensitively;
1533 { // Nothing found or new find process
1535 // nothing found, start again
1539 next (findCurrent,findPrevious,d);
1541 bool searching=true;
1542 bool foundNote=false;
1543 while (searching && !EOFind)
1547 // Searching in Note
1548 if (findCurrent->getNote().contains(s,cs))
1550 select (findCurrent);
1552 if (getSelectedBranch()!=itFind)
1555 ensureSelectionVisible();
1558 if (textEditor->findText(s,flags))
1564 // Searching in Heading
1565 if (searching && findCurrent->getHeading().contains (s,cs) )
1567 select(findCurrent);
1573 if (!next(findCurrent,findPrevious,d) )
1576 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1579 return getSelectedBranchItem();
1584 void VymModel::findReset()
1585 { // Necessary if text to find changes during a find process
1591 void VymModel::setScene (QGraphicsScene *s)
1593 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1594 //init(); // Here we have a mapScene set,
1595 // which is (still) needed to create MapCenters
1598 void VymModel::setURL(const QString &url) //FIXME-2
1601 BranchObj *bo=getSelectedBranch();
1604 QString oldurl=bo->getURL();
1608 QString ("setURL (\"%1\")").arg(oldurl),
1610 QString ("setURL (\"%1\")").arg(url),
1611 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1616 ensureSelectionVisible();
1621 QString VymModel::getURL() //FIXME-2
1624 BranchObj *bo=getSelectedBranch();
1626 return bo->getURL();
1632 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1634 return QStringList();
1637 BranchObj *bo=getSelectedBranch();
1643 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1651 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1653 FloatImageObj *fio=selection.getFloatImage();
1656 TreeItem *dst=findBySelectString (dstString);
1657 if (dst && dst->isBranchLikeType() )
1659 TreeItem *dstPar=dst->parent();
1660 QString parString=getSelectString(dstPar);
1661 QString fioPreSelectString=getSelectString(fio);
1662 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1663 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1665 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1666 fio=((BranchObj*)dst)->getLastFloatImage();
1671 getSelectString(fio),
1672 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1674 QString ("linkTo (\"%1\")").arg(dstString),
1675 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1681 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1684 BranchObj *bo=getSelectedBranch();
1687 QString s=bo->getFrameTypeName();
1688 bo->setFrameType (t);
1689 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1690 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1697 void VymModel::setFrameType(const QString &s) //FIXME-2
1700 BranchObj *bo=getSelectedBranch();
1703 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1704 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1705 bo->setFrameType (s);
1712 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1715 BranchObj *bo=getSelectedBranch();
1718 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1719 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1720 bo->setFramePenColor (c);
1725 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1728 BranchObj *bo=getSelectedBranch();
1731 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1732 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1733 bo->setFrameBrushColor (c);
1737 void VymModel::setFramePadding (const int &i) //FIXME-2
1740 BranchObj *bo=getSelectedBranch();
1743 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1744 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1745 bo->setFramePadding (i);
1752 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1755 BranchObj *bo=getSelectedBranch();
1758 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1759 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1760 bo->setFrameBorderWidth (i);
1767 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1770 BranchObj *bo=getSelectedBranch();
1773 QString u= b ? "false" : "true";
1774 QString r=!b ? "false" : "true";
1778 QString("setIncludeImagesVertically (%1)").arg(u),
1780 QString("setIncludeImagesVertically (%1)").arg(r),
1781 QString("Include images vertically in %1").arg(getObjectName(bo))
1783 bo->setIncludeImagesVer(b);
1788 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1791 BranchObj *bo=getSelectedBranch();
1794 QString u= b ? "false" : "true";
1795 QString r=!b ? "false" : "true";
1799 QString("setIncludeImagesHorizontally (%1)").arg(u),
1801 QString("setIncludeImagesHorizontally (%1)").arg(r),
1802 QString("Include images horizontally in %1").arg(getObjectName(bo))
1804 bo->setIncludeImagesHor(b);
1810 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1813 LinkableMapObj *sel=getSelectedLMO();
1815 (selectionType() == TreeItem::Branch ||
1816 selectionType() == TreeItem::MapCenter ||
1817 selectionType() == TreeItem::Image ))
1819 QString u= b ? "false" : "true";
1820 QString r=!b ? "false" : "true";
1824 QString("setHideLinkUnselected (%1)").arg(u),
1826 QString("setHideLinkUnselected (%1)").arg(r),
1827 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1829 sel->setHideLinkUnselected(b);
1834 void VymModel::setHideExport(bool b)
1836 BranchItem *bi=getSelectedBranchItem();
1839 bi->setHideInExport (b);
1840 QString u= b ? "false" : "true";
1841 QString r=!b ? "false" : "true";
1845 QString ("setHideExport (%1)").arg(u),
1847 QString ("setHideExport (%1)").arg(r),
1848 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1852 // selection.update();
1853 // FIXME-3 VM needed? scene()->update();
1857 void VymModel::toggleHideExport()
1859 BranchItem *selbi=getSelectedBranchItem();
1861 setHideExport ( !selbi->hideInExport() );
1865 void VymModel::copy() //FIXME-2
1868 LinkableMapObj *sel=getSelectedLMO();
1870 (selectionType() == TreeItem::Branch ||
1871 selectionType() == TreeItem::MapCenter ||
1872 selectionType() == TreeItem::Image ))
1874 if (redosAvail == 0)
1877 QString s=getSelectString(sel);
1878 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1879 curClipboard=curStep;
1882 // Copy also to global clipboard, because we are at last step in history
1883 QString bakMapName(QString("history-%1").arg(curStep));
1884 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1885 copyDir (bakMapDir,clipboardDir );
1887 clipboardEmpty=false;
1894 void VymModel::pasteNoSave(const int &n) //FIXME-2
1897 bool old=blockSaveState;
1898 blockSaveState=true;
1899 bool zippedOrg=zipped;
1900 if (redosAvail > 0 || n!=0)
1902 // Use the "historical" buffer
1903 QString bakMapName(QString("history-%1").arg(n));
1904 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1905 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1907 // Use the global buffer
1908 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1914 void VymModel::paste() //FIXME-2
1917 BranchObj *sel=getSelectedBranch();
1920 saveStateChangingPart(
1923 QString ("paste (%1)").arg(curClipboard),
1924 QString("Paste to %1").arg( getObjectName(sel))
1932 void VymModel::cut() //FIXME-2
1935 LinkableMapObj *sel=getSelectedLMO();
1936 if ( sel && (selectionType() == TreeItem::Branch ||
1937 selectionType()==TreeItem::MapCenter ||
1938 selectionType()==TreeItem::Image))
1941 /* No savestate! savestate is called in cutNoSave
1942 saveStateChangingPart(
1946 QString("Cut %1").arg(getObjectName(sel ))
1956 void VymModel::moveBranchUp() //FIXME-2
1959 BranchObj* bo=getSelectedBranch();
1963 if (!bo->canMoveBranchUp()) return;
1964 par=(BranchObj*)(bo->getParObj());
1965 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1966 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1968 //FIXME-3 VM needed? scene()->update();
1970 ensureSelectionVisible();
1975 void VymModel::moveBranchDown() //FIXME-2
1978 BranchObj* bo=getSelectedBranch();
1982 if (!bo->canMoveBranchDown()) return;
1983 par=(BranchObj*)(bo->getParObj());
1984 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1985 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1987 //FIXME-3 VM needed? scene()->update();
1989 ensureSelectionVisible();
1994 void VymModel::sortChildren() // FIXME-2 not implemented yet
1997 BranchObj* bo=getSelectedBranch();
2000 if(treeItem->branchCount()>1)
2002 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
2005 ensureSelectionVisible();
2011 MapCenterItem* VymModel::createMapCenter()
2013 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
2018 BranchItem* VymModel::createBranch()
2020 return addNewBranchInt (-2);
2023 TreeItem* VymModel::createImage() //FIXME-2
2026 BranchObj *bo=getSelectedBranch();
2029 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
2032 QList<QVariant> cData;
2033 cData << "VM:createImage" << "undef"<<"undef";
2034 TreeItem *parti=bo->getTreeItem();
2035 TreeItem *ti=new TreeItem (cData,parti);
2036 ti->setLMO (newfio);
2037 ti->setType (TreeItem::Image);
2038 parti->appendChild (ti);
2042 newfio->setTreeItem (ti);
2043 select (newfio); // FIXME-2 VM really needed here?
2051 MapCenterItem* VymModel::addMapCenter ()
2053 MapCenterItem *mci=addMapCenter (contextPos);
2054 //FIXME-3 selection.select (mco);
2056 ensureSelectionVisible();
2061 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2062 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2067 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2071 QModelIndex parix=index(rootItem);
2073 int n=rootItem->branchCount();
2075 emit (layoutAboutToBeChanged() );
2076 beginInsertRows (parix,n,n+1);
2078 QList<QVariant> cData;
2079 cData << "VM:addMapCenter" << "undef"<<"undef";
2080 MapCenterItem *mci=new MapCenterItem (cData);
2081 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2082 rootItem->appendChild (mci);
2085 emit (newChildObject (parix));
2086 emit (layoutChanged() );
2089 BranchObj *newbo=mci->createMapObj(mapScene);
2093 if (!mci->getHeading().isEmpty() )
2095 newbo->updateHeading();
2096 newbo->setColor (headingColor);
2100 //newbo->updateLink(); //FIXME-3
2103 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2104 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2105 mci->setLMO (mapCenter);
2106 mapCenter->updateHeading();
2107 mapCenter->move (absPos);
2108 mapCenter->setVisibility (true);
2109 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2114 BranchItem* VymModel::addNewBranchInt(int num)
2116 // Depending on pos:
2117 // -3 insert in children of parent above selection
2118 // -2 add branch to selection
2119 // -1 insert in children of parent below selection
2120 // 0..n insert in children of parent at pos
2121 BranchObj *newbo=NULL;
2122 BranchObj *bo=getSelectedBranchObj(); //FIXME-2
2123 BranchItem *bi=getSelectedBranchItem();
2129 QList<QVariant> cData;
2130 cData << "new" << "undef"<<"undef";
2132 BranchItem *parbi=bi;
2133 QModelIndex parix=index(parbi);
2134 int n=parbi->childCount();
2136 emit (layoutAboutToBeChanged() );
2137 beginInsertRows (parix,n,n+1); //FIXME-1 check if n is correct: should be index below _last_ branch...
2138 bi=new BranchItem (cData);
2139 bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2141 parbi->appendChild (bi);
2143 emit (newChildObject (parix));
2144 emit (layoutChanged() );
2146 // save scroll state. If scrolled, automatically select
2147 // new branch in order to tmp unscroll parent...
2148 newbo=bi->createMapObj(mapScene);
2154 bo=(BranchObj*)bo->getParObj();
2155 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2161 bo=(BranchObj*)bo->getParObj();
2162 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2169 BranchItem* VymModel::addNewBranch(int pos)
2171 // Different meaning than num in addNewBranchInt!
2175 BranchItem *newbi=NULL;
2176 BranchItem *selbi=getSelectedBranchItem();
2180 // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2182 newbi=addNewBranchInt (pos-2);
2190 QString ("addBranch (%1)").arg(pos),
2191 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2194 // selection.update(); FIXME-3
2195 latestAddedItem=newbi;
2196 // In Network mode, the client needs to know where the new branch is,
2197 // so we have to pass on this information via saveState.
2198 // TODO: Get rid of this positioning workaround
2199 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2200 sendData ("selectLatestAdded ()");
2201 sendData (QString("move %1").arg(ps));
2210 BranchItem* VymModel::addNewBranchBefore() //FIXME-2
2213 BranchObj *newbo=NULL;
2214 BranchObj *bo = getSelectedBranch();
2215 if (bo && selectionType()==TreeItem::Branch)
2216 // We accept no MapCenterObj here, so we _have_ a parent
2218 QPointF p=bo->getRelPos();
2221 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2223 // add below selection
2224 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2228 newbo->move2RelPos (p);
2230 // Move selection to new branch
2231 bo->linkTo (newbo,-1);
2233 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2234 QString ("Add branch before %1").arg(getObjectName(bo)));
2237 // selection.update(); FIXME-3
2240 latestSelectionString=selection.getSelectString();
2246 BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2250 emit (layoutAboutToBeChanged() );
2251 BranchItem *branchpi=(BranchItem*)branch->parent();
2252 // Remove at current position
2253 int n=branch->childNum();
2254 beginRemoveRows (index(branchpi),n,n);
2255 branchpi->removeChild (n);
2258 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2260 // Append as last branch to dst
2261 if (dst->branchCount()==0)
2264 n=dst->getFirstBranch()->childNumber();
2265 beginInsertRows (index(dst),n+pos,n+pos);
2266 dst->insertBranch (pos,branch);
2269 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2270 emit (layoutChanged() );
2275 void VymModel::deleteSelection()
2277 BranchItem *selbi=getSelectedBranchItem();
2281 TreeItem *pi=selbi->parent();
2282 QModelIndex parentIndex=index(pi);
2284 if (selbi->isBranchLikeType() )
2287 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2289 emit (layoutAboutToBeChanged() );
2291 int n=selbi->childNum();
2292 beginRemoveRows (parentIndex,n,n);
2293 removeRows (n,1,parentIndex);
2296 ensureSelectionVisible();
2299 emit (layoutChanged() );
2302 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2307 BranchObj* par=(BranchObj*)fio->getParObj();
2308 saveStateChangingPart(
2312 QString("Delete %1").arg(getObjectName(fio))
2315 par->removeFloatImage(fio);
2318 ensureSelectionVisible();
2324 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2328 BranchObj *bo=getSelectedBranch();
2332 par=(BranchObj*)(bo->getParObj());
2334 // Don't use this on mapcenter
2337 // Check if we have childs at all to keep
2338 if (bo->getTreeItem()->branchCount()==0)
2344 QPointF p=bo->getRelPos();
2345 saveStateChangingPart(
2348 "deleteKeepChildren ()",
2349 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2352 QString sel=getSelectString(bo);
2354 par->removeBranchHere(bo);
2357 getSelectedBranch()->move2RelPos (p);
2362 void VymModel::deleteChildren() //FIXME-2 VM still missing
2366 BranchObj *bo=getSelectedBranch();
2369 saveStateChangingPart(
2372 "deleteChildren ()",
2373 QString( "Remove children of branch %1").arg(getObjectName(bo))
2375 bo->removeChildren();
2381 bool VymModel::scrollBranch(BranchItem *bi)
2385 if (bi->isScrolled()) return false;
2386 if (bi->branchCount()==0) return false;
2387 if (bi->depth()==0) return false;
2391 /* FIXME-3 no savestate yet
2394 QString ("%1 ()").arg(u),
2396 QString ("%1 ()").arg(r),
2397 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2401 //selection.update();
2402 // FIXME-3 VM needed? scene()->update();
2408 bool VymModel::unscrollBranch(BranchItem *bi)
2412 if (bi->isScrolled()) return false;
2413 if (bi->branchCount()==0) return false;
2414 if (bi->depth()==0) return false;
2419 /* FIXME-3 no savestate yet
2422 QString ("%1 ()").arg(u),
2424 QString ("%1 ()").arg(r),
2425 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2429 // selection.update();
2430 // FIXME-3 VM needed? scene()->update();
2436 void VymModel::toggleScroll()
2438 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2439 if (bi && bi->getType()==TreeItem::Branch )
2441 if (bi->isScrolled())
2442 unscrollBranch (bi);
2448 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2452 BranchObj *bo=getSelectedBranch();
2458 if (bo->isScrolled()) unscrollBranch (bo);
2465 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2468 BranchObj *bo=getSelectedBranch();
2471 FloatImageObj *fio=bo->addFloatImage();
2473 fio->setOriginalFilename("No original filename (image added by dropevent)");
2474 QString s=getSelectString(bo);
2475 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2476 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2478 // FIXME-3 VM needed? scene()->update();
2484 void VymModel::colorBranch (QColor c) //FIXME-2
2487 BranchObj *bo=getSelectedBranch();
2492 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2494 QString ("colorBranch (\"%1\")").arg(c.name()),
2495 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2497 bo->setColor(c); // color branch
2502 void VymModel::colorSubtree (QColor c) //FIXME-2
2505 BranchObj *bo=getSelectedBranch();
2508 saveStateChangingPart(
2511 QString ("colorSubtree (\"%1\")").arg(c.name()),
2512 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2514 bo->setColorSubtree (c); // color links, color children
2519 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2522 BranchObj *bo=getSelectedBranch();
2523 if (bo) return bo->getColor();
2525 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2532 void VymModel::editURL() //FIXME-2
2535 BranchObj *bo=getSelectedBranch();
2539 QString text = QInputDialog::getText(
2540 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2541 bo->getURL(), &ok, NULL);
2543 // user entered something and pressed OK
2549 void VymModel::editLocalURL() //FIXME-2
2552 BranchObj *bo=getSelectedBranch();
2555 QStringList filters;
2556 filters <<"All files (*)";
2557 filters << tr("Text","Filedialog") + " (*.txt)";
2558 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2559 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2560 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2561 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2562 fd->setFilters (filters);
2563 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2564 fd->setDirectory (lastFileDir);
2565 if (! bo->getVymLink().isEmpty() )
2566 fd->selectFile( bo->getURL() );
2569 if ( fd->exec() == QDialog::Accepted )
2571 lastFileDir=QDir (fd->directory().path());
2572 setURL (fd->selectedFile() );
2579 void VymModel::editHeading2URL() //FIXME-2
2582 BranchObj *bo=getSelectedBranch();
2584 setURL (bo->getHeading());
2588 void VymModel::editBugzilla2URL() //FIXME-2
2591 BranchObj *bo=getSelectedBranch();
2594 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2600 void VymModel::editFATE2URL() //FIXME-2
2603 BranchObj *bo=getSelectedBranch();
2606 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2609 "setURL (\""+bo->getURL()+"\")",
2611 "setURL (\""+url+"\")",
2612 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2620 void VymModel::editVymLink()
2622 BranchItem *bi=getSelectedBranchItem();
2625 QStringList filters;
2626 filters <<"VYM map (*.vym)";
2627 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2628 fd->setFilters (filters);
2629 fd->setCaption(vymName+" - " +tr("Link to another map"));
2630 fd->setDirectory (lastFileDir);
2631 if (! bi->getVymLink().isEmpty() )
2632 fd->selectFile( bi->getVymLink() );
2636 if ( fd->exec() == QDialog::Accepted )
2638 lastFileDir=QDir (fd->directory().path());
2641 "setVymLink (\""+bi->getVymLink()+"\")",
2643 "setVymLink (\""+fd->selectedFile()+"\")",
2644 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2646 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2651 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2653 // Internal function, no saveState needed
2654 BranchItem *bi=getSelectedBranchItem();
2657 bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO
2660 //selection.update();
2661 ensureSelectionVisible();
2665 void VymModel::deleteVymLink()
2667 BranchItem *bi=getSelectedBranchItem();
2672 "setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO
2675 "setVymLink (\"\")",
2676 QString("Unset vymlink of %1").arg(getObjectName(bi))
2678 bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO
2681 // FIXME-3 VM needed? scene()->update();
2685 QString VymModel::getVymLink()
2687 BranchItem *bi=getSelectedBranchItem();
2689 return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here...
2695 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2697 return QStringList();
2700 BranchObj *bo=getSelectedBranch();
2706 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2715 void VymModel::followXLink(int i) // FIXME-2
2719 BranchObj *bo=getSelectedBranch();
2722 bo=bo->XLinkTargetAt(i);
2725 selection.select(bo);
2726 ensureSelectionVisible();
2732 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2736 BranchObj *bo=getSelectedBranch();
2739 XLinkObj *xlo=bo->XLinkAt(i);
2742 EditXLinkDialog dia;
2744 dia.setSelection(bo);
2745 if (dia.exec() == QDialog::Accepted)
2747 if (dia.useSettingsGlobal() )
2749 setMapDefXLinkColor (xlo->getColor() );
2750 setMapDefXLinkWidth (xlo->getWidth() );
2752 if (dia.deleteXLink())
2753 bo->deleteXLinkAt(i);
2764 //////////////////////////////////////////////
2766 //////////////////////////////////////////////
2768 void VymModel::parseAtom(const QString &atom)
2770 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2771 TreeItem* selti=getSelectedItem();
2772 BranchItem *selbi=getSelectedBranchItem();
2778 // Split string s into command and parameters
2779 parser.parseAtom (atom);
2780 QString com=parser.getCommand();
2782 // External commands
2783 /////////////////////////////////////////////////////////////////////
2784 if (com=="addBranch")
2788 parser.setError (Aborted,"Nothing selected");
2789 } else if (! selbi )
2791 parser.setError (Aborted,"Type of selection is not a branch");
2796 if (parser.checkParCount(pl))
2798 if (parser.parCount()==0)
2802 n=parser.parInt (ok,0);
2803 if (ok ) addNewBranch (n);
2807 /////////////////////////////////////////////////////////////////////
2808 } else if (com=="addBranchBefore")
2812 parser.setError (Aborted,"Nothing selected");
2813 } else if (! selbi )
2815 parser.setError (Aborted,"Type of selection is not a branch");
2818 if (parser.parCount()==0)
2820 addNewBranchBefore ();
2823 /////////////////////////////////////////////////////////////////////
2824 } else if (com==QString("addMapCenter"))
2826 if (parser.checkParCount(2))
2828 x=parser.parDouble (ok,0);
2831 y=parser.parDouble (ok,1);
2832 if (ok) addMapCenter (QPointF(x,y));
2835 /////////////////////////////////////////////////////////////////////
2836 } else if (com==QString("addMapReplace"))
2840 parser.setError (Aborted,"Nothing selected");
2841 } else if (! selbi )
2843 parser.setError (Aborted,"Type of selection is not a branch");
2844 } else if (parser.checkParCount(1))
2846 //s=parser.parString (ok,0); // selection
2847 t=parser.parString (ok,0); // path to map
2848 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2849 addMapReplaceInt(getSelectString(selbi),t);
2851 /////////////////////////////////////////////////////////////////////
2852 } else if (com==QString("addMapInsert"))
2856 parser.setError (Aborted,"Nothing selected");
2857 } else if (! selbi )
2859 parser.setError (Aborted,"Type of selection is not a branch");
2862 if (parser.checkParCount(2))
2864 t=parser.parString (ok,0); // path to map
2865 n=parser.parInt(ok,1); // position
2866 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2867 addMapInsertInt(t,n);
2870 /////////////////////////////////////////////////////////////////////
2871 } else /*if (com=="clearFlags") // FIXME-2
2875 parser.setError (Aborted,"Nothing selected");
2876 } else if (! selbi )
2878 parser.setError (Aborted,"Type of selection is not a branch");
2879 } else if (parser.checkParCount(0))
2881 selb->clearStandardFlags();
2882 selb->updateFlagsToolbar();
2884 /////////////////////////////////////////////////////////////////////
2885 } else */ if (com=="colorBranch")
2889 parser.setError (Aborted,"Nothing selected");
2890 } else if (! selbi )
2892 parser.setError (Aborted,"Type of selection is not a branch");
2893 } else if (parser.checkParCount(1))
2895 QColor c=parser.parColor (ok,0);
2896 if (ok) colorBranch (c);
2898 /////////////////////////////////////////////////////////////////////
2899 } else if (com=="colorSubtree")
2903 parser.setError (Aborted,"Nothing selected");
2904 } else if (! selbi )
2906 parser.setError (Aborted,"Type of selection is not a branch");
2907 } else if (parser.checkParCount(1))
2909 QColor c=parser.parColor (ok,0);
2910 if (ok) colorSubtree (c);
2912 /////////////////////////////////////////////////////////////////////
2913 } else if (com=="copy")
2917 parser.setError (Aborted,"Nothing selected");
2918 } else if (! selbi )
2920 parser.setError (Aborted,"Type of selection is not a branch");
2921 } else if (parser.checkParCount(0))
2923 //FIXME-1 missing action for copy
2925 /////////////////////////////////////////////////////////////////////
2926 } else if (com=="cut")
2930 parser.setError (Aborted,"Nothing selected");
2931 } else if ( selectionType()!=TreeItem::Branch &&
2932 selectionType()!=TreeItem::MapCenter &&
2933 selectionType()!=TreeItem::Image )
2935 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2936 } else if (parser.checkParCount(0))
2940 /////////////////////////////////////////////////////////////////////
2941 } else if (com=="delete")
2945 parser.setError (Aborted,"Nothing selected");
2947 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2949 parser.setError (Aborted,"Type of selection is wrong.");
2952 else if (parser.checkParCount(0))
2956 /////////////////////////////////////////////////////////////////////
2957 } else if (com=="deleteKeepChildren")
2961 parser.setError (Aborted,"Nothing selected");
2962 } else if (! selbi )
2964 parser.setError (Aborted,"Type of selection is not a branch");
2965 } else if (parser.checkParCount(0))
2967 deleteKeepChildren();
2969 /////////////////////////////////////////////////////////////////////
2970 } else if (com=="deleteChildren")
2974 parser.setError (Aborted,"Nothing selected");
2977 parser.setError (Aborted,"Type of selection is not a branch");
2978 } else if (parser.checkParCount(0))
2982 /////////////////////////////////////////////////////////////////////
2983 } else if (com=="exportASCII")
2987 if (parser.parCount()>=1)
2988 // Hey, we even have a filename
2989 fname=parser.parString(ok,0);
2992 parser.setError (Aborted,"Could not read filename");
2995 exportASCII (fname,false);
2997 /////////////////////////////////////////////////////////////////////
2998 } else if (com=="exportImage")
3002 if (parser.parCount()>=2)
3003 // Hey, we even have a filename
3004 fname=parser.parString(ok,0);
3007 parser.setError (Aborted,"Could not read filename");
3010 QString format="PNG";
3011 if (parser.parCount()>=2)
3013 format=parser.parString(ok,1);
3015 exportImage (fname,false,format);
3017 /////////////////////////////////////////////////////////////////////
3018 } else if (com=="exportXHTML")
3022 if (parser.parCount()>=2)
3023 // Hey, we even have a filename
3024 fname=parser.parString(ok,1);
3027 parser.setError (Aborted,"Could not read filename");
3030 exportXHTML (fname,false);
3032 /////////////////////////////////////////////////////////////////////
3033 } else if (com=="exportXML")
3037 if (parser.parCount()>=2)
3038 // Hey, we even have a filename
3039 fname=parser.parString(ok,1);
3042 parser.setError (Aborted,"Could not read filename");
3045 exportXML (fname,false);
3047 /////////////////////////////////////////////////////////////////////
3048 } else if (com=="importDir")
3052 parser.setError (Aborted,"Nothing selected");
3053 } else if (! selbi )
3055 parser.setError (Aborted,"Type of selection is not a branch");
3056 } else if (parser.checkParCount(1))
3058 s=parser.parString(ok,0);
3059 if (ok) importDirInt(s);
3061 /////////////////////////////////////////////////////////////////////
3062 } else /* FIXME-2 if (com=="linkTo")
3066 parser.setError (Aborted,"Nothing selected");
3069 if (parser.checkParCount(4))
3071 // 0 selectstring of parent
3072 // 1 num in parent (for branches)
3073 // 2,3 x,y of mainbranch or mapcenter
3074 s=parser.parString(ok,0);
3075 LinkableMapObj *dst=findObjBySelect (s);
3078 if (typeid(*dst) == typeid(BranchObj) )
3080 // Get number in parent
3081 n=parser.parInt (ok,1);
3084 selb->linkTo ((BranchObj*)(dst),n);
3087 } else if (typeid(*dst) == typeid(MapCenterObj) )
3089 selb->linkTo ((BranchObj*)(dst),-1);
3090 // Get coordinates of mainbranch
3091 x=parser.parDouble(ok,2);
3094 y=parser.parDouble(ok,3);
3104 } else if ( selectionType() == TreeItem::Image)
3106 if (parser.checkParCount(1))
3108 // 0 selectstring of parent
3109 s=parser.parString(ok,0);
3110 LinkableMapObj *dst=findObjBySelect (s);
3113 if (typeid(*dst) == typeid(BranchObj) ||
3114 typeid(*dst) == typeid(MapCenterObj))
3115 linkFloatImageTo (getSelectString(dst));
3117 parser.setError (Aborted,"Destination is not a branch");
3120 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3121 /////////////////////////////////////////////////////////////////////
3122 } else */ if (com=="loadImage")
3126 parser.setError (Aborted,"Nothing selected");
3127 } else if (! selbi )
3129 parser.setError (Aborted,"Type of selection is not a branch");
3130 } else if (parser.checkParCount(1))
3132 s=parser.parString(ok,0);
3133 if (ok) loadFloatImageInt (s);
3135 /////////////////////////////////////////////////////////////////////
3136 } else if (com=="moveBranchUp")
3140 parser.setError (Aborted,"Nothing selected");
3141 } else if (! selbi )
3143 parser.setError (Aborted,"Type of selection is not a branch");
3144 } else if (parser.checkParCount(0))
3148 /////////////////////////////////////////////////////////////////////
3149 } else if (com=="moveBranchDown")
3153 parser.setError (Aborted,"Nothing selected");
3154 } else if (! selbi )
3156 parser.setError (Aborted,"Type of selection is not a branch");
3157 } else if (parser.checkParCount(0))
3161 /////////////////////////////////////////////////////////////////////
3162 } else if (com=="move")
3166 parser.setError (Aborted,"Nothing selected");
3167 } else if ( selectionType()!=TreeItem::Branch &&
3168 selectionType()!=TreeItem::MapCenter &&
3169 selectionType()!=TreeItem::Image )
3171 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3172 } else if (parser.checkParCount(2))
3174 x=parser.parDouble (ok,0);
3177 y=parser.parDouble (ok,1);
3181 /////////////////////////////////////////////////////////////////////
3182 } else if (com=="moveRel")
3186 parser.setError (Aborted,"Nothing selected");
3187 } else if ( selectionType()!=TreeItem::Branch &&
3188 selectionType()!=TreeItem::MapCenter &&
3189 selectionType()!=TreeItem::Image )
3191 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3192 } else if (parser.checkParCount(2))
3194 x=parser.parDouble (ok,0);
3197 y=parser.parDouble (ok,1);
3198 if (ok) moveRel (x,y);
3201 /////////////////////////////////////////////////////////////////////
3202 } else if (com=="nop")
3204 /////////////////////////////////////////////////////////////////////
3205 } else if (com=="paste")
3209 parser.setError (Aborted,"Nothing selected");
3210 } else if (! selbi )
3212 parser.setError (Aborted,"Type of selection is not a branch");
3213 } else if (parser.checkParCount(1))
3215 n=parser.parInt (ok,0);
3216 if (ok) pasteNoSave(n);
3218 /////////////////////////////////////////////////////////////////////
3219 } else if (com=="qa")
3223 parser.setError (Aborted,"Nothing selected");
3224 } else if (! selbi )
3226 parser.setError (Aborted,"Type of selection is not a branch");
3227 } else if (parser.checkParCount(4))
3230 c=parser.parString (ok,0);
3233 parser.setError (Aborted,"No comment given");
3236 s=parser.parString (ok,1);
3239 parser.setError (Aborted,"First parameter is not a string");
3242 t=parser.parString (ok,2);
3245 parser.setError (Aborted,"Condition is not a string");
3248 u=parser.parString (ok,3);
3251 parser.setError (Aborted,"Third parameter is not a string");
3256 parser.setError (Aborted,"Unknown type: "+s);
3261 parser.setError (Aborted,"Unknown operator: "+t);
3266 parser.setError (Aborted,"Type of selection is not a branch");
3269 if (selbi->getHeading() == u)
3271 cout << "PASSED: " << qPrintable (c) << endl;
3274 cout << "FAILED: " << qPrintable (c) << endl;
3284 /////////////////////////////////////////////////////////////////////
3285 } else if (com=="saveImage")
3287 FloatImageObj *fio=selection.getFloatImage();
3290 parser.setError (Aborted,"Type of selection is not an image");
3291 } else if (parser.checkParCount(2))
3293 s=parser.parString(ok,0);
3296 t=parser.parString(ok,1);
3297 if (ok) saveFloatImageInt (fio,t,s);
3300 /////////////////////////////////////////////////////////////////////
3301 } else if (com=="scroll")
3305 parser.setError (Aborted,"Nothing selected");
3306 } else if (! selbi )
3308 parser.setError (Aborted,"Type of selection is not a branch");
3309 } else if (parser.checkParCount(0))
3311 if (!scrollBranch (selbi))
3312 parser.setError (Aborted,"Could not scroll branch");
3314 /////////////////////////////////////////////////////////////////////
3315 } else if (com=="select")
3317 if (parser.checkParCount(1))
3319 s=parser.parString(ok,0);
3322 /////////////////////////////////////////////////////////////////////
3323 } else if (com=="selectLastBranch")
3327 parser.setError (Aborted,"Nothing selected");
3328 } else if (! selbi )
3330 parser.setError (Aborted,"Type of selection is not a branch");
3331 } else if (parser.checkParCount(0))
3333 BranchItem *bi=selbi->getLastBranch();
3335 parser.setError (Aborted,"Could not select last branch");
3336 select (bi); // FIXME-3 was selectInt
3339 /////////////////////////////////////////////////////////////////////
3340 } else /* FIXME-2 if (com=="selectLastImage")
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(0))
3350 FloatImageObj *fio=selb->getLastFloatImage();
3352 parser.setError (Aborted,"Could not select last image");
3353 select (fio); // FIXME-3 was selectInt
3356 /////////////////////////////////////////////////////////////////////
3357 } else */ if (com=="selectLatestAdded")
3359 if (!latestAddedItem)
3361 parser.setError (Aborted,"No latest added object");
3364 if (!select (latestAddedItem))
3365 parser.setError (Aborted,"Could not select latest added object ");
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="setFrameType")
3370 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3372 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3374 else if (parser.checkParCount(1))
3376 s=parser.parString(ok,0);
3377 if (ok) setFrameType (s);
3379 /////////////////////////////////////////////////////////////////////
3380 } else if (com=="setFramePenColor")
3382 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3384 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3386 else if (parser.checkParCount(1))
3388 QColor c=parser.parColor(ok,0);
3389 if (ok) setFramePenColor (c);
3391 /////////////////////////////////////////////////////////////////////
3392 } else if (com=="setFrameBrushColor")
3394 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3396 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3398 else if (parser.checkParCount(1))
3400 QColor c=parser.parColor(ok,0);
3401 if (ok) setFrameBrushColor (c);
3403 /////////////////////////////////////////////////////////////////////
3404 } else if (com=="setFramePadding")
3406 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3408 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3410 else if (parser.checkParCount(1))
3412 n=parser.parInt(ok,0);
3413 if (ok) setFramePadding(n);
3415 /////////////////////////////////////////////////////////////////////
3416 } else if (com=="setFrameBorderWidth")
3418 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3420 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3422 else if (parser.checkParCount(1))
3424 n=parser.parInt(ok,0);
3425 if (ok) setFrameBorderWidth (n);
3427 /////////////////////////////////////////////////////////////////////
3428 } else if (com=="setMapAuthor")
3430 if (parser.checkParCount(1))
3432 s=parser.parString(ok,0);
3433 if (ok) setAuthor (s);
3435 /////////////////////////////////////////////////////////////////////
3436 } else if (com=="setMapComment")
3438 if (parser.checkParCount(1))
3440 s=parser.parString(ok,0);
3441 if (ok) setComment(s);
3443 /////////////////////////////////////////////////////////////////////
3444 } else if (com=="setMapBackgroundColor")
3448 parser.setError (Aborted,"Nothing selected");
3449 } else if (! selbi )
3451 parser.setError (Aborted,"Type of selection is not a branch");
3452 } else if (parser.checkParCount(1))
3454 QColor c=parser.parColor (ok,0);
3455 if (ok) setMapBackgroundColor (c);
3457 /////////////////////////////////////////////////////////////////////
3458 } else if (com=="setMapDefLinkColor")
3462 parser.setError (Aborted,"Nothing selected");
3463 } else if (! selbi )
3465 parser.setError (Aborted,"Type of selection is not a branch");
3466 } else if (parser.checkParCount(1))
3468 QColor c=parser.parColor (ok,0);
3469 if (ok) setMapDefLinkColor (c);
3471 /////////////////////////////////////////////////////////////////////
3472 } else if (com=="setMapLinkStyle")
3474 if (parser.checkParCount(1))
3476 s=parser.parString (ok,0);
3477 if (ok) setMapLinkStyle(s);
3479 /////////////////////////////////////////////////////////////////////
3480 } else if (com=="setHeading")
3484 parser.setError (Aborted,"Nothing selected");
3485 } else if (! selbi )
3487 parser.setError (Aborted,"Type of selection is not a branch");
3488 } else if (parser.checkParCount(1))
3490 s=parser.parString (ok,0);
3494 /////////////////////////////////////////////////////////////////////
3495 } else if (com=="setHideExport")
3499 parser.setError (Aborted,"Nothing selected");
3500 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3502 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3503 } else if (parser.checkParCount(1))
3505 b=parser.parBool(ok,0);
3506 if (ok) setHideExport (b);
3508 /////////////////////////////////////////////////////////////////////
3509 } else if (com=="setIncludeImagesHorizontally")
3513 parser.setError (Aborted,"Nothing selected");
3516 parser.setError (Aborted,"Type of selection is not a branch");
3517 } else if (parser.checkParCount(1))
3519 b=parser.parBool(ok,0);
3520 if (ok) setIncludeImagesHor(b);
3522 /////////////////////////////////////////////////////////////////////
3523 } else if (com=="setIncludeImagesVertically")
3527 parser.setError (Aborted,"Nothing selected");
3530 parser.setError (Aborted,"Type of selection is not a branch");
3531 } else if (parser.checkParCount(1))
3533 b=parser.parBool(ok,0);
3534 if (ok) setIncludeImagesVer(b);
3536 /////////////////////////////////////////////////////////////////////
3537 } else if (com=="setHideLinkUnselected")
3541 parser.setError (Aborted,"Nothing selected");
3542 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3544 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3545 } else if (parser.checkParCount(1))
3547 b=parser.parBool(ok,0);
3548 if (ok) setHideLinkUnselected(b);
3550 /////////////////////////////////////////////////////////////////////
3551 } else if (com=="setSelectionColor")
3553 if (parser.checkParCount(1))
3555 QColor c=parser.parColor (ok,0);
3556 if (ok) setSelectionColorInt (c);
3558 /////////////////////////////////////////////////////////////////////
3559 } else if (com=="setURL")
3563 parser.setError (Aborted,"Nothing selected");
3564 } else if (! selbi )
3566 parser.setError (Aborted,"Type of selection is not a branch");
3567 } else if (parser.checkParCount(1))
3569 s=parser.parString (ok,0);
3572 /////////////////////////////////////////////////////////////////////
3573 } else if (com=="setVymLink")
3577 parser.setError (Aborted,"Nothing selected");
3578 } else if (! selbi )
3580 parser.setError (Aborted,"Type of selection is not a branch");
3581 } else if (parser.checkParCount(1))
3583 s=parser.parString (ok,0);
3584 if (ok) setVymLink(s);
3587 /////////////////////////////////////////////////////////////////////
3588 else /* FIXME-2 if (com=="setFlag")
3592 parser.setError (Aborted,"Nothing selected");
3593 } else if (! selbi )
3595 parser.setError (Aborted,"Type of selection is not a branch");
3596 } else if (parser.checkParCount(1))
3598 s=parser.parString(ok,0);
3601 selb->activateStandardFlag(s);
3602 selb->updateFlagsToolbar();
3605 /////////////////////////////////////////////////////////////////////
3606 } else */ /* FIXME-2 if (com=="setFrameType")
3610 parser.setError (Aborted,"Nothing selected");
3613 parser.setError (Aborted,"Type of selection is not a branch");
3614 } else if (parser.checkParCount(1))
3616 s=parser.parString(ok,0);
3620 /////////////////////////////////////////////////////////////////////
3621 } else*/ if (com=="sortChildren")
3625 parser.setError (Aborted,"Nothing selected");
3626 } else if (! selbi )
3628 parser.setError (Aborted,"Type of selection is not a branch");
3629 } else if (parser.checkParCount(0))
3633 /////////////////////////////////////////////////////////////////////
3634 } else /* FIXME-2 if (com=="toggleFlag")
3638 parser.setError (Aborted,"Nothing selected");
3639 } else if (! selbi )
3641 parser.setError (Aborted,"Type of selection is not a branch");
3642 } else if (parser.checkParCount(1))
3644 s=parser.parString(ok,0);
3647 selbi->toggleStandardFlag(s);
3648 selb->updateFlagsToolbar();
3651 /////////////////////////////////////////////////////////////////////
3652 } else */ if (com=="unscroll")
3656 parser.setError (Aborted,"Nothing selected");
3657 } else if (! selbi )
3659 parser.setError (Aborted,"Type of selection is not a branch");
3660 } else if (parser.checkParCount(0))
3662 if (!unscrollBranch (selbi))
3663 parser.setError (Aborted,"Could not unscroll branch");
3665 /////////////////////////////////////////////////////////////////////
3666 } else if (com=="unscrollChildren")
3670 parser.setError (Aborted,"Nothing selected");
3671 } else if (! selbi )
3673 parser.setError (Aborted,"Type of selection is not a branch");
3674 } else if (parser.checkParCount(0))
3676 unscrollChildren ();
3678 /////////////////////////////////////////////////////////////////////
3679 } else /* FIXME-2 if (com=="unsetFlag")
3681 if (selection.isEmpty() )
3683 parser.setError (Aborted,"Nothing selected");
3684 } else if (! selbi )
3686 parser.setError (Aborted,"Type of selection is not a branch");
3687 } else if (parser.checkParCount(1))
3689 s=parser.parString(ok,0);
3692 selb->deactivateStandardFlag(s);
3693 selb->updateFlagsToolbar();
3697 parser.setError (Aborted,"Unknown command");
3700 if (parser.errorLevel()==NoError)
3702 // setChanged(); FIXME-2 should not be called e.g. for export?!
3707 // TODO Error handling
3708 qWarning("VymModel::parseAtom: Error!");
3709 qWarning(parser.errorMessage());
3713 void VymModel::runScript (QString script)
3715 parser.setScript (script);
3717 while (parser.next() )
3718 parseAtom(parser.getAtom());
3721 void VymModel::setExportMode (bool b)
3723 // should be called before and after exports
3724 // depending on the settings
3725 if (b && settings.value("/export/useHideExport","true")=="true")
3726 setHideTmpMode (TreeItem::HideExport);
3728 setHideTmpMode (TreeItem::HideNone);
3731 void VymModel::exportImage(QString fname, bool askName, QString format)
3735 fname=getMapName()+".png";
3742 QFileDialog *fd=new QFileDialog (NULL);
3743 fd->setCaption (tr("Export map as image"));
3744 fd->setDirectory (lastImageDir);
3745 fd->setFileMode(QFileDialog::AnyFile);
3746 fd->setFilters (imageIO.getFilters() );
3749 fl=fd->selectedFiles();
3751 format=imageIO.getType(fd->selectedFilter());
3755 setExportMode (true);
3756 QPixmap pix (getPixmap());
3757 pix.save(fname, format);
3758 setExportMode (false);
3762 void VymModel::exportXML(QString dir, bool askForName)
3766 dir=browseDirectory(NULL,tr("Export XML to directory"));
3767 if (dir =="" && !reallyWriteDirectory(dir) )
3771 // Hide stuff during export, if settings want this
3772 setExportMode (true);
3774 // Create subdirectories
3777 // write to directory
3778 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3781 file.setName ( dir + "/"+mapName+".xml");
3782 if ( !file.open( QIODevice::WriteOnly ) )
3784 // This should neverever happen
3785 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3789 // Write it finally, and write in UTF8, no matter what
3790 QTextStream ts( &file );
3791 ts.setEncoding (QTextStream::UnicodeUTF8);
3795 // Now write image, too
3796 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3798 setExportMode (false);
3801 void VymModel::exportASCII(QString fname,bool askName)
3806 ex.setFile (mapName+".txt");
3812 //ex.addFilter ("TXT (*.txt)");
3813 ex.setDir(lastImageDir);
3814 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3819 setExportMode(true);
3821 setExportMode(false);
3825 void VymModel::exportXHTML (const QString &dir, bool askForName)
3827 ExportXHTMLDialog dia(NULL);
3828 dia.setFilePath (filePath );
3829 dia.setMapName (mapName );
3831 if (dir!="") dia.setDir (dir);
3837 if (dia.exec()!=QDialog::Accepted)
3841 QDir d (dia.getDir());
3842 // Check, if warnings should be used before overwriting
3843 // the output directory
3844 if (d.exists() && d.count()>0)
3847 warn.showCancelButton (true);
3848 warn.setText(QString(
3849 "The directory %1 is not empty.\n"
3850 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3851 warn.setCaption("Warning: Directory not empty");
3852 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3854 if (warn.exec()!=QDialog::Accepted) ok=false;
3861 exportXML (dia.getDir(),false );
3862 dia.doExport(mapName );
3863 //if (dia.hasChanged()) setChanged();
3867 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3872 if (ex.setConfigFile(cf))
3874 setExportMode (true);
3875 ex.exportPresentation();
3876 setExportMode (false);
3883 //////////////////////////////////////////////
3885 //////////////////////////////////////////////
3887 void VymModel::registerEditor(QWidget *me)
3889 mapEditor=(MapEditor*)me;
3892 void VymModel::unregisterEditor(QWidget *)
3897 void VymModel::setContextPos(QPointF p)
3902 void VymModel::unsetContextPos()
3904 contextPos=QPointF();
3907 void VymModel::updateNoteFlag()
3910 cout << "VM::updateNoteFlag()\n";
3911 /* FIXME-1 modify note flag
3912 BranchObj *bo=getSelectedBranch();
3915 bo->updateNoteFlag();
3916 mainWindow->updateActions();
3921 void VymModel::updateRelPositions() //FIXME-2 VM should have no need to updateRelPos
3923 //cout << "VM::updateRelPos...\n";
3924 for (int i=0; i<rootItem->branchCount(); i++)
3925 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3928 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3930 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3931 if (blockReposition) return;
3933 for (int i=0;i<rootItem->branchCount(); i++)
3934 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3937 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3940 // Creating (arbitrary) shapes
3943 QRectF rb=bo->getBBox();
3944 if (bo->getDepth()==0)
3946 // Just take BBox of this mapCenter
3947 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3951 // Take union of BBox and TotalBBox
3953 QRectF ra=bo->getTotalBBox();
3954 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3957 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3960 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3962 p <<ra.bottomRight()
3964 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3967 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3972 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3976 // Move all branches and MapCenters away from lmo
3977 // to avoid collisions
3983 BranchObj *boA=(BranchObj*)lmo;
3985 for (int i=0; i<rootItem->branchCount(); i++)
3987 boB=rootItem->getBranchNum(i);
3990 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3993 <<" ("<<qPrintable(boA->getHeading() )<<")"
3994 <<" with ("<< qPrintable (boB->getHeading() )
3997 <<" minT="<<r.minTranslation<<endl<<endl;
4002 QPixmap VymModel::getPixmap()
4004 QRectF mapRect=getTotalBBox();
4005 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4008 pp.setRenderHints(mapEditor->renderHints());
4010 // Don't print the visualisation of selection
4011 selection.unselect();
4013 mapScene->render ( &pp,
4014 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4015 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4017 // Restore selection
4018 selection.reselect();
4024 void VymModel::setMapLinkStyle (const QString & s)
4029 case LinkableMapObj::Line :
4032 case LinkableMapObj::Parabel:
4033 snow="StyleParabel";
4035 case LinkableMapObj::PolyLine:
4036 snow="StylePolyLine";
4038 case LinkableMapObj::PolyParabel:
4039 snow="StylePolyParabel";
4042 snow="UndefinedStyle";
4047 QString("setMapLinkStyle (\"%1\")").arg(s),
4048 QString("setMapLinkStyle (\"%1\")").arg(snow),
4049 QString("Set map link style (\"%1\")").arg(s)
4053 linkstyle=LinkableMapObj::Line;
4054 else if (s=="StyleParabel")
4055 linkstyle=LinkableMapObj::Parabel;
4056 else if (s=="StylePolyLine")
4057 linkstyle=LinkableMapObj::PolyLine;
4058 else if (s=="StylePolyParabel")
4059 linkstyle=LinkableMapObj::PolyParabel;
4061 linkstyle=LinkableMapObj::UndefinedStyle;
4063 BranchItem *cur=NULL;
4064 BranchItem *prev=NULL;
4070 bo=(BranchObj*)(cur->getLMO() );
4071 bo->setLinkStyle(bo->getDefLinkStyle());
4072 cur=next(cur,prev,d);
4077 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4082 void VymModel::setMapDefLinkColor(QColor col)
4084 if ( !col.isValid() ) return;
4086 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4087 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4088 QString("Set map link color to %1").arg(col.name())
4092 BranchItem *cur=NULL;
4093 BranchItem *prev=NULL;
4096 cur=next(cur,prev,d);
4099 bo=(BranchObj*)(cur->getLMO() );
4106 void VymModel::setMapLinkColorHintInt()
4108 // called from setMapLinkColorHint(lch) or at end of parse
4109 BranchItem *cur=NULL;
4110 BranchItem *prev=NULL;
4113 cur=next(cur,prev,d);
4116 bo=(BranchObj*)(cur->getLMO() );
4118 cur=next(cur,prev,d);
4122 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4125 setMapLinkColorHintInt();
4128 void VymModel::toggleMapLinkColorHint()
4130 if (linkcolorhint==LinkableMapObj::HeadingColor)
4131 linkcolorhint=LinkableMapObj::DefaultColor;
4133 linkcolorhint=LinkableMapObj::HeadingColor;
4134 BranchItem *cur=NULL;
4135 BranchItem *prev=NULL;
4138 cur=next(cur,prev,d);
4141 bo=(BranchObj*)(cur->getLMO() );
4147 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4149 Q3FileDialog *fd=new Q3FileDialog( NULL);
4150 fd->setMode (Q3FileDialog::ExistingFile);
4151 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4152 ImagePreview *p =new ImagePreview (fd);
4153 fd->setContentsPreviewEnabled( TRUE );
4154 fd->setContentsPreview( p, p );
4155 fd->setPreviewMode( Q3FileDialog::Contents );
4156 fd->setCaption(vymName+" - " +tr("Load background image"));
4157 fd->setDir (lastImageDir);
4160 if ( fd->exec() == QDialog::Accepted )
4162 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4163 lastImageDir=QDir (fd->dirPath());
4164 setMapBackgroundImage (fd->selectedFile());
4168 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4170 QColor oldcol=mapScene->backgroundBrush().color();
4174 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4176 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4177 QString("Set background color of map to %1").arg(col.name()));
4180 brush.setTextureImage (QPixmap (fn));
4181 mapScene->setBackgroundBrush(brush);
4184 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4186 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4187 if ( !col.isValid() ) return;
4188 setMapBackgroundColor( col );
4192 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4194 QColor oldcol=mapScene->backgroundBrush().color();
4196 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4197 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4198 QString("Set background color of map to %1").arg(col.name()));
4199 mapScene->setBackgroundBrush(col);
4202 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4204 return mapScene->backgroundBrush().color();
4208 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4210 return linkcolorhint;
4213 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4215 return defLinkColor;
4218 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4223 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4225 return defXLinkColor;
4228 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4233 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4235 return defXLinkWidth;
4238 void VymModel::move(const double &x, const double &y) // FIXME-3
4242 BranchObj *bo = getSelectedBranch();
4244 (selectionType()==TreeItem::Branch ||
4245 selectionType()==TreeItem::MapCenter ||
4246 selectionType()==TreeItem::Image
4249 QPointF ap(bo->getAbsPos());
4253 QString ps=qpointfToString(ap);
4254 QString s=getSelectString();
4257 s, "move "+qpointfToString(to),
4258 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4267 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4271 BranchObj *bo = getSelectedBranch();
4273 (selectionType()==TreeItem::Branch ||
4274 selectionType()==TreeItem::MapCenter ||
4275 selectionType()==TreeItem::Image
4279 QPointF rp(bo->getRelPos());
4283 QString ps=qpointfToString (bo->getRelPos());
4284 QString s=getSelectString(bo);
4287 s, "moveRel "+qpointfToString(to),
4288 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4289 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4299 void VymModel::animate()
4301 animationTimer->stop();
4304 while (i<animObjList.size() )
4306 bo=(BranchObj*)animObjList.at(i);
4311 animObjList.removeAt(i);
4318 QItemSelection sel=selModel->selection();
4319 emit (selectionChanged(sel,sel));
4322 if (!animObjList.isEmpty()) animationTimer->start();
4326 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4328 if (bo && bo->getTreeItem()->depth()>0)
4331 ap.setStart (start);
4333 ap.setTicks (animationTicks);
4334 ap.setAnimated (true);
4335 bo->setAnimation (ap);
4336 animObjList.append( bo );
4337 animationTimer->setSingleShot (true);
4338 animationTimer->start(animationInterval);
4342 void VymModel::stopAnimation (MapObj *mo)
4344 int i=animObjList.indexOf(mo);
4346 animObjList.removeAt (i);
4349 void VymModel::sendSelection()
4351 if (netstate!=Server) return;
4352 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4355 void VymModel::newServer()
4359 tcpServer = new QTcpServer(this);
4360 if (!tcpServer->listen(QHostAddress::Any,port)) {
4361 QMessageBox::critical(NULL, "vym server",
4362 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4363 //FIXME-3 needed? we are no widget any longer... close();
4366 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4368 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4371 void VymModel::connectToServer()
4374 server="salam.suse.de";
4376 clientSocket = new QTcpSocket (this);
4377 clientSocket->abort();
4378 clientSocket->connectToHost(server ,port);
4379 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4380 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4381 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4383 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4388 void VymModel::newClient()
4390 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4391 connect(newClient, SIGNAL(disconnected()),
4392 newClient, SLOT(deleteLater()));
4394 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4396 clientList.append (newClient);
4400 void VymModel::sendData(const QString &s)
4402 if (clientList.size()==0) return;
4404 // Create bytearray to send
4406 QDataStream out(&block, QIODevice::WriteOnly);
4407 out.setVersion(QDataStream::Qt_4_0);
4409 // Reserve some space for blocksize
4412 // Write sendCounter
4413 out << sendCounter++;
4418 // Go back and write blocksize so far
4419 out.device()->seek(0);
4420 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4424 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4426 for (int i=0; i<clientList.size(); ++i)
4428 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4429 clientList.at(i)->write (block);
4433 void VymModel::readData ()
4435 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4438 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4442 QDataStream in(clientSocket);
4443 in.setVersion(QDataStream::Qt_4_0);
4451 cout << " t="<<qPrintable (t)<<endl;
4457 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4459 switch (socketError) {
4460 case QAbstractSocket::RemoteHostClosedError:
4462 case QAbstractSocket::HostNotFoundError:
4463 QMessageBox::information(NULL, vymName +" Network client",
4464 "The host was not found. Please check the "
4465 "host name and port settings.");
4467 case QAbstractSocket::ConnectionRefusedError:
4468 QMessageBox::information(NULL, vymName + " Network client",
4469 "The connection was refused by the peer. "
4470 "Make sure the fortune server is running, "
4471 "and check that the host name and port "
4472 "settings are correct.");
4475 QMessageBox::information(NULL, vymName + " Network client",
4476 QString("The following error occurred: %1.")
4477 .arg(clientSocket->errorString()));
4484 void VymModel::selectMapSelectionColor()
4486 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4487 setSelectionColor (col);
4490 void VymModel::setSelectionColorInt (QColor col)
4492 if ( !col.isValid() ) return;
4494 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4495 QString("setSelectionColor (%1)").arg(col.name()),
4496 QString("Set color of selection box to %1").arg(col.name())
4499 mapEditor->setSelectionColor (col);
4503 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4505 cout << "VymModel::changeSelection (";
4506 if (!newsel.indexes().isEmpty() )
4507 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4509 if (!oldsel.indexes().isEmpty() )
4510 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4515 void VymModel::updateSelection(const QItemSelection &newsel)
4517 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4518 ensureSelectionVisible();
4522 void VymModel::updateSelection()
4524 QItemSelection newsel=selModel->selection();
4525 updateSelection (newsel);
4528 void VymModel::setSelectionColor(QColor col)
4530 if ( !col.isValid() ) return;
4532 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4533 QString("setSelectionColor (%1)").arg(col.name()),
4534 QString("Set color of selection box to %1").arg(col.name())
4536 setSelectionColorInt (col);
4539 QColor VymModel::getSelectionColor()
4541 return mapEditor->getSelectionColor();
4544 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4547 for (int i=0;i<rootItem->childCount();i++)
4548 rootItem->child(i)->setHideTmp (mode);
4550 // FIXME-3 needed? scene()->update();
4554 QRectF VymModel::getTotalBBox() //FIXME-2
4558 for (int i=0;i<rootItem->branchCount(); i++)
4559 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4564 //////////////////////////////////////////////
4565 // Selection related
4566 //////////////////////////////////////////////
4568 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4573 QItemSelectionModel* VymModel::getSelectionModel()
4578 void VymModel::setSelectionBlocked (bool b)
4583 selection.unblock();
4586 bool VymModel::isSelectionBlocked()
4588 return selection.isBlocked();
4591 bool VymModel::select ()
4593 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4595 TreeItem *item = getItem (index);
4596 return select (item->getLMO() );
4599 bool VymModel::select (const QString &s)
4601 TreeItem *ti=findBySelectString(s);
4611 bool VymModel::select (LinkableMapObj *lmo)
4613 QItemSelection oldsel=selModel->selection();
4616 return select (lmo->getTreeItem() );
4621 bool VymModel::select (TreeItem *ti)
4625 QModelIndex ix=index(ti);
4626 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4627 ti->setLastSelectedBranch();
4633 void VymModel::unselect()
4635 selModel->clearSelection();
4638 void VymModel::reselect()
4640 selection.reselect();
4643 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4645 LinkableMapObj *lmo=getSelectedLMO();
4646 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4649 void VymModel::emitNoteHasChanged (TreeItem *ti)
4651 QModelIndex ix=index(ti);
4652 emit (noteHasChanged (ix) );
4655 void VymModel::emitDataHasChanged (TreeItem *ti)
4657 QModelIndex ix=index(ti);
4658 emit (dataHasChanged (ix) );
4662 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4665 if (selection.select(lmo))
4667 //selection.update();
4668 sendSelection (); // FIXME-4 VM use signal
4672 void VymModel::selectInt (TreeItem *ti)
4674 if (selection.select(lmo))
4676 //selection.update();
4677 sendSelection (); // FIXME-4 VM use signal
4682 void VymModel::selectNextBranchInt()
4684 BranchItem *bi=getSelectedBranchItem();
4687 TreeItem *pi=bi->parent();
4691 if (i<pi->branchCount() )
4693 // select previous branch with same parent
4695 select (pi->getBranchNum(i));
4703 void VymModel::selectPrevBranchInt()
4706 BranchItem *bi=getSelectedBranchItem();
4709 BranchItem *pi=(BranchItem*)bi->parent();
4715 // select previous branch with same parent
4716 bi=pi->getBranchNum(i-1);
4721 while (bi->branchCount() >0)
4722 bi=bi->getLastBranch();
4725 // Try to select last branch in parent pi2 previous to own parent pi
4727 TreeItem *pi2=pi->parent();
4738 void VymModel::selectAboveBranchInt()
4740 BranchItem *bi=getSelectedBranchItem();
4743 BranchItem *newbi=NULL;
4744 BranchItem *pi=(BranchItem*)bi->parent();
4748 // goto previous branch with same parent
4749 newbi=pi->getBranchNum(i-1);
4750 while (newbi->branchCount() >0 )
4751 newbi=newbi->getLastBranch();
4755 if (newbi==rootItem)
4756 // already at top branch (resp. mapcenter)
4762 void VymModel::selectBelowBranchInt()
4764 BranchItem *bi=getSelectedBranchItem();
4767 BranchItem *newbi=NULL;
4769 if (bi->branchCount() >0)
4770 newbi=bi->getFirstBranch();
4777 pi=(BranchItem*)bi->parent();
4779 if (pi->branchCount()-1 > i)
4781 newbi=(BranchItem*)pi->getBranchNum(i+1);
4786 // look for siblings of myself
4787 // or parent, or parent of parent...
4798 void VymModel::selectUpperBranch()
4800 if (selection.isBlocked() ) return;
4802 BranchItem *bi=getSelectedBranchItem();
4803 if (bi && bi->isBranchLikeType())
4804 selectAboveBranchInt();
4807 void VymModel::selectLowerBranch()
4809 if (selection.isBlocked() ) return;
4811 BranchItem *bi=getSelectedBranchItem();
4812 if (bi && bi->isBranchLikeType())
4813 selectBelowBranchInt();
4817 void VymModel::selectLeftBranch()
4819 if (selection.isBlocked() ) return;
4821 QItemSelection oldsel=selModel->selection();
4824 BranchItem *selbi=getSelectedBranchItem();
4825 TreeItem::Type type=selbi->getType();
4828 if (type == TreeItem::MapCenter)
4830 QModelIndex ix=index(selbi);
4831 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4834 par=(BranchItem*)selbi->parent();
4835 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4838 if (type == TreeItem::Branch ||
4839 type == TreeItem::Image)
4841 QModelIndex ix=index (selbi->parent());
4842 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4847 if (type == TreeItem::Branch )
4849 cout << "VM::selLeft\n";
4850 selectLastSelectedBranch();
4858 void VymModel::selectRightBranch()
4860 if (selection.isBlocked() ) return;
4862 QItemSelection oldsel=selModel->selection();
4865 BranchItem *selbi=getSelectedBranchItem();
4866 TreeItem::Type type=selbi->getType();
4869 if (type==TreeItem::MapCenter)
4871 QModelIndex ix=index(selbi);
4872 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4875 par=(BranchItem*)selbi->parent();
4876 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4879 if ( type== TreeItem::Branch )
4881 selectLastSelectedBranch();
4887 if (type == TreeItem::Branch ||
4888 type == TreeItem::Image)
4890 cout << "VM::selRight\n";
4891 QModelIndex ix=index(selbi->parent());
4892 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4899 void VymModel::selectFirstBranch()
4901 TreeItem *ti=getSelectedBranchItem();
4904 TreeItem *par=ti->parent();
4906 TreeItem *ti2=par->getFirstBranch();
4910 ensureSelectionVisible();
4916 void VymModel::selectLastBranch()
4918 TreeItem *ti=getSelectedBranchItem();
4921 TreeItem *par=ti->parent();
4923 TreeItem *ti2=par->getLastBranch();
4927 ensureSelectionVisible();
4933 void VymModel::selectLastSelectedBranch()
4935 TreeItem *ti=getSelectedBranchItem();
4938 ti=ti->getLastSelectedBranch();
4939 if (ti) select (ti);
4943 void VymModel::selectParent()
4945 TreeItem *ti=getSelectedItem();
4953 ensureSelectionVisible();
4958 TreeItem::Type VymModel::selectionType()
4960 QModelIndexList list=selModel->selectedIndexes();
4961 if (list.isEmpty()) return TreeItem::Undefined;
4962 TreeItem *ti = getItem (list.first() );
4963 return ti->getType();
4967 LinkableMapObj* VymModel::getSelectedLMO()
4969 QModelIndexList list=selModel->selectedIndexes();
4970 if (!list.isEmpty() )
4972 TreeItem *ti = getItem (list.first() );
4973 TreeItem::Type type=ti->getType();
4974 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4976 return ti->getLMO();
4982 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4984 TreeItem *ti = getSelectedBranchItem();
4986 return (BranchObj*)ti->getLMO();
4991 BranchItem* VymModel::getSelectedBranchItem()
4993 QModelIndexList list=selModel->selectedIndexes();
4994 if (!list.isEmpty() )
4996 TreeItem *ti = getItem (list.first() );
4997 TreeItem::Type type=ti->getType();
4998 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4999 return (BranchItem*)ti;
5004 TreeItem* VymModel::getSelectedItem()
5006 QModelIndexList list=selModel->selectedIndexes();
5007 if (!list.isEmpty() )
5008 return getItem (list.first() );
5013 QModelIndex VymModel::getSelectedIndex()
5015 QModelIndexList list=selModel->selectedIndexes();
5016 if (list.isEmpty() )
5017 return QModelIndex();
5019 return list.first();
5022 FloatImageObj* VymModel::getSelectedFloatImage()
5024 return selection.getFloatImage();
5027 QString VymModel::getSelectString ()
5029 LinkableMapObj *lmo=getSelectedLMO();
5031 return getSelectString(lmo);
5036 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5038 if (!lmo) return QString();
5039 return getSelectString (lmo->getTreeItem() );
5042 QString VymModel::getSelectString (TreeItem *ti)
5046 if (ti->getType() == TreeItem::Branch ||
5047 ti->getType() == TreeItem::MapCenter)
5049 TreeItem *par=ti->parent();
5052 if (ti->depth() ==1)
5053 // Mainbranch, return
5054 s= "bo:" + QString("%1").arg(ti->num() );
5056 // Branch, call myself recursively
5057 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5061 int i=rootItem->num(ti);
5062 if (i>=0) s=QString("mc:%1").arg(i);