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());
998 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1001 if (!lmo) return QString("Error: NULL has no name!");
1003 if ((typeid(*lmo) == typeid(BranchObj) ||
1004 typeid(*lmo) == typeid(MapCenterObj)))
1007 s=lmo->getTreeItem()->getHeading();
1008 if (s=="") s="unnamed";
1009 return QString("branch (%1)").arg(s);
1011 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1012 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1013 return QString("Unknown type has no name!");
1017 QString VymModel::getObjectName (const TreeItem *ti)
1020 if (!ti) return QString("Error: NULL has no name!");
1022 if (ti->isBranchLikeType() )
1025 if (s=="") s="unnamed";
1026 return QString("branch (%1)").arg(s);
1028 /* FIXME-2 move floatimage to TreeModel first
1029 if (type==TreeItem::Image)
1030 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1032 return QString("Unknown type has no name!");
1035 void VymModel::redo()
1037 // Can we undo at all?
1038 if (redosAvail<1) return;
1040 bool blockSaveStateOrg=blockSaveState;
1041 blockSaveState=true;
1045 if (undosAvail<stepsTotal) undosAvail++;
1047 if (curStep>stepsTotal) curStep=1;
1048 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1049 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1050 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1051 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1052 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1053 QString version=undoSet.readEntry ("/history/version");
1055 /* TODO Maybe check for version, if we save the history
1056 if (!checkVersion(version))
1057 QMessageBox::warning(0,tr("Warning"),
1058 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1061 // Find out current undo directory
1062 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1066 cout << "VymModel::redo() begin\n";
1067 cout << " undosAvail="<<undosAvail<<endl;
1068 cout << " redosAvail="<<redosAvail<<endl;
1069 cout << " curStep="<<curStep<<endl;
1070 cout << " ---------------------------"<<endl;
1071 cout << " comment="<<comment.toStdString()<<endl;
1072 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1073 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1074 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1075 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1076 cout << " ---------------------------"<<endl<<endl;
1079 // select object before redo
1080 if (!redoSelection.isEmpty())
1081 select (redoSelection);
1084 parseAtom (redoCommand);
1087 blockSaveState=blockSaveStateOrg;
1089 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1090 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1091 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1092 undoSet.writeSettings(histPath);
1094 mainWindow->updateHistory (undoSet);
1097 /* TODO remove testing
1098 cout << "ME::redo() end\n";
1099 cout << " undosAvail="<<undosAvail<<endl;
1100 cout << " redosAvail="<<redosAvail<<endl;
1101 cout << " curStep="<<curStep<<endl;
1102 cout << " ---------------------------"<<endl<<endl;
1108 bool VymModel::isRedoAvailable()
1110 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1116 void VymModel::undo()
1118 // Can we undo at all?
1119 if (undosAvail<1) return;
1121 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1123 bool blockSaveStateOrg=blockSaveState;
1124 blockSaveState=true;
1126 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1127 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1128 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1129 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1130 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1131 QString version=undoSet.readEntry ("/history/version");
1133 /* TODO Maybe check for version, if we save the history
1134 if (!checkVersion(version))
1135 QMessageBox::warning(0,tr("Warning"),
1136 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1139 // Find out current undo directory
1140 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1142 // select object before undo
1143 if (!undoSelection.isEmpty())
1144 select (undoSelection);
1148 cout << "VymModel::undo() begin\n";
1149 cout << " undosAvail="<<undosAvail<<endl;
1150 cout << " redosAvail="<<redosAvail<<endl;
1151 cout << " curStep="<<curStep<<endl;
1152 cout << " ---------------------------"<<endl;
1153 cout << " comment="<<comment.toStdString()<<endl;
1154 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1155 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1156 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1157 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1158 cout << " ---------------------------"<<endl<<endl;
1160 parseAtom (undoCommand);
1165 if (curStep<1) curStep=stepsTotal;
1169 blockSaveState=blockSaveStateOrg;
1170 /* TODO remove testing
1171 cout << "VymModel::undo() end\n";
1172 cout << " undosAvail="<<undosAvail<<endl;
1173 cout << " redosAvail="<<redosAvail<<endl;
1174 cout << " curStep="<<curStep<<endl;
1175 cout << " ---------------------------"<<endl<<endl;
1178 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1179 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1180 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1181 undoSet.writeSettings(histPath);
1183 mainWindow->updateHistory (undoSet);
1186 ensureSelectionVisible();
1189 bool VymModel::isUndoAvailable()
1191 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1197 void VymModel::gotoHistoryStep (int i)
1199 // Restore variables
1200 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1201 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1203 if (i<0) i=undosAvail+redosAvail;
1205 // Clicking above current step makes us undo things
1208 for (int j=0; j<undosAvail-i; j++) undo();
1211 // Clicking below current step makes us redo things
1213 for (int j=undosAvail; j<i; j++)
1215 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1219 // And ignore clicking the current row ;-)
1223 QString VymModel::getHistoryPath()
1225 QString histName(QString("history-%1").arg(curStep));
1226 return (tmpMapDir+"/"+histName);
1229 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1231 sendData(redoCom); //FIXME-3 testing
1236 if (blockSaveState) return;
1238 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1240 // Find out current undo directory
1241 if (undosAvail<stepsTotal) undosAvail++;
1243 if (curStep>stepsTotal) curStep=1;
1245 QString backupXML="";
1246 QString histDir=getHistoryPath();
1247 QString bakMapPath=histDir+"/map.xml";
1249 // Create histDir if not available
1252 makeSubDirs (histDir);
1254 // Save depending on how much needs to be saved
1256 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1258 QString undoCommand="";
1259 if (savemode==UndoCommand)
1261 undoCommand=undoCom;
1263 else if (savemode==PartOfMap )
1265 undoCommand=undoCom;
1266 undoCommand.replace ("PATH",bakMapPath);
1270 if (!backupXML.isEmpty())
1271 // Write XML Data to disk
1272 saveStringToDisk (bakMapPath,backupXML);
1274 // We would have to save all actions in a tree, to keep track of
1275 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1278 // Write the current state to disk
1279 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1280 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1281 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1282 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1283 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1284 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1285 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1286 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1287 undoSet.setEntry (QString("/history/version"),vymVersion);
1288 undoSet.writeSettings(histPath);
1292 // TODO remove after testing
1293 //cout << " into="<< histPath.toStdString()<<endl;
1294 cout << " stepsTotal="<<stepsTotal<<
1295 ", undosAvail="<<undosAvail<<
1296 ", redosAvail="<<redosAvail<<
1297 ", curStep="<<curStep<<endl;
1298 cout << " ---------------------------"<<endl;
1299 cout << " comment="<<comment.toStdString()<<endl;
1300 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1301 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1302 cout << " redoCom="<<redoCom.toStdString()<<endl;
1303 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1304 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1305 cout << " ---------------------------"<<endl;
1308 mainWindow->updateHistory (undoSet);
1314 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1316 // save the selected part of the map, Undo will replace part of map
1317 QString undoSelection="";
1319 undoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1322 QString redoSelection="";
1324 redoSelection=getSelectString(undoSel);
1326 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1329 saveState (PartOfMap,
1330 undoSelection, "addMapReplace (\"PATH\")",
1336 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1340 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1343 QString undoSelection=getSelectString (redoSel->parent() );
1344 QString redoSelection=getSelectString(redoSel);
1345 if (redoSel->getType()==TreeItem::Branch)
1347 // save the selected branch of the map, Undo will insert part of map
1348 saveState (PartOfMap,
1349 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1350 redoSelection, "delete ()",
1357 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1359 // "Normal" savestate: save commands, selections and comment
1360 // so just save commands for undo and redo
1361 // and use current selection
1363 QString redoSelection="";
1364 if (redoSel) redoSelection=getSelectString(redoSel);
1365 QString undoSelection="";
1366 if (undoSel) undoSelection=getSelectString(undoSel);
1368 saveState (UndoCommand,
1375 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1377 // "Normal" savestate: save commands, selections and comment
1378 // so just save commands for undo and redo
1379 // and use current selection
1380 saveState (UndoCommand,
1387 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1389 // "Normal" savestate applied to model (no selection needed):
1390 // save commands and comment
1391 saveState (UndoCommand,
1399 QGraphicsScene* VymModel::getScene ()
1404 TreeItem* VymModel::findBySelectString(const QString &s) //FIXME-0
1412 part=s.section(",",0,0);
1414 num=part.right(part.length() - 3);
1415 if (typ=="mc" && num.toInt()>=0 && num.toInt() <rootItem->branchCount() )
1416 return rootItem->getBranchNum (num.toInt() );
1420 for (int i=0; i<rootItem->branchCount(); i++)
1422 // ti=rootItem->getBranchNum(i)->findBySelectString(s);
1428 TreeItem* VymModel::findID (const QString &s)
1431 for (int i=0; i<rootItem->branchCount(); i++)
1433 ti=rootItem->getBranchNum(i)->findID (s);
1439 //////////////////////////////////////////////
1441 //////////////////////////////////////////////
1442 void VymModel::setVersion (const QString &s)
1447 void VymModel::setAuthor (const QString &s)
1450 QString ("setMapAuthor (\"%1\")").arg(author),
1451 QString ("setMapAuthor (\"%1\")").arg(s),
1452 QString ("Set author of map to \"%1\"").arg(s)
1457 QString VymModel::getAuthor()
1462 void VymModel::setComment (const QString &s)
1465 QString ("setMapComment (\"%1\")").arg(comment),
1466 QString ("setMapComment (\"%1\")").arg(s),
1467 QString ("Set comment of map")
1472 QString VymModel::getComment ()
1477 QString VymModel::getDate ()
1479 return QDate::currentDate().toString ("yyyy-MM-dd");
1482 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1485 BranchItem *cur=NULL;
1486 BranchItem *prev=NULL;
1497 void VymModel::setHeading(const QString &s)
1499 BranchItem *selbi=getSelectedBranchItem();
1504 "setHeading (\""+selbi->getHeading()+"\")",
1506 "setHeading (\""+s+"\")",
1507 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1508 selbi->setHeading(s );
1509 QModelIndex ix2=index (selbi);
1510 emit (dataChanged ( ix2,ix2));
1511 /* FIXME-3 testing only
1515 // selection.update(); //FIXME-4
1516 ensureSelectionVisible();
1520 BranchItem* VymModel::findText (QString s, bool cs)
1523 QTextDocument::FindFlags flags=0;
1524 if (cs) flags=QTextDocument::FindCaseSensitively;
1527 { // Nothing found or new find process
1529 // nothing found, start again
1533 next (findCurrent,findPrevious,d);
1535 bool searching=true;
1536 bool foundNote=false;
1537 while (searching && !EOFind)
1541 // Searching in Note
1542 if (findCurrent->getNote().contains(s,cs))
1544 select (findCurrent);
1546 if (getSelectedBranch()!=itFind)
1549 ensureSelectionVisible();
1552 if (textEditor->findText(s,flags))
1558 // Searching in Heading
1559 if (searching && findCurrent->getHeading().contains (s,cs) )
1561 select(findCurrent);
1567 if (!next(findCurrent,findPrevious,d) )
1570 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1573 return getSelectedBranchItem();
1578 void VymModel::findReset()
1579 { // Necessary if text to find changes during a find process
1585 void VymModel::setScene (QGraphicsScene *s)
1587 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1588 //init(); // Here we have a mapScene set,
1589 // which is (still) needed to create MapCenters
1592 void VymModel::setURL(const QString &url) //FIXME-2
1595 BranchObj *bo=getSelectedBranch();
1598 QString oldurl=bo->getURL();
1602 QString ("setURL (\"%1\")").arg(oldurl),
1604 QString ("setURL (\"%1\")").arg(url),
1605 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1610 ensureSelectionVisible();
1615 QString VymModel::getURL() //FIXME-2
1618 BranchObj *bo=getSelectedBranch();
1620 return bo->getURL();
1626 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1628 return QStringList();
1631 BranchObj *bo=getSelectedBranch();
1637 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1645 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1647 FloatImageObj *fio=selection.getFloatImage();
1650 TreeItem *dst=findBySelectString (dstString);
1651 if (dst && dst->isBranchLikeType() )
1653 TreeItem *dstPar=dst->parent();
1654 QString parString=getSelectString(dstPar);
1655 QString fioPreSelectString=getSelectString(fio);
1656 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1657 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1659 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1660 fio=((BranchObj*)dst)->getLastFloatImage();
1665 getSelectString(fio),
1666 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1668 QString ("linkTo (\"%1\")").arg(dstString),
1669 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1675 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1678 BranchObj *bo=getSelectedBranch();
1681 QString s=bo->getFrameTypeName();
1682 bo->setFrameType (t);
1683 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1684 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1691 void VymModel::setFrameType(const QString &s) //FIXME-2
1694 BranchObj *bo=getSelectedBranch();
1697 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1698 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1699 bo->setFrameType (s);
1706 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1709 BranchObj *bo=getSelectedBranch();
1712 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1713 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1714 bo->setFramePenColor (c);
1719 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1722 BranchObj *bo=getSelectedBranch();
1725 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1726 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1727 bo->setFrameBrushColor (c);
1731 void VymModel::setFramePadding (const int &i) //FIXME-2
1734 BranchObj *bo=getSelectedBranch();
1737 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1738 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1739 bo->setFramePadding (i);
1746 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1749 BranchObj *bo=getSelectedBranch();
1752 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1753 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1754 bo->setFrameBorderWidth (i);
1761 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1764 BranchObj *bo=getSelectedBranch();
1767 QString u= b ? "false" : "true";
1768 QString r=!b ? "false" : "true";
1772 QString("setIncludeImagesVertically (%1)").arg(u),
1774 QString("setIncludeImagesVertically (%1)").arg(r),
1775 QString("Include images vertically in %1").arg(getObjectName(bo))
1777 bo->setIncludeImagesVer(b);
1782 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1785 BranchObj *bo=getSelectedBranch();
1788 QString u= b ? "false" : "true";
1789 QString r=!b ? "false" : "true";
1793 QString("setIncludeImagesHorizontally (%1)").arg(u),
1795 QString("setIncludeImagesHorizontally (%1)").arg(r),
1796 QString("Include images horizontally in %1").arg(getObjectName(bo))
1798 bo->setIncludeImagesHor(b);
1804 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1807 LinkableMapObj *sel=getSelectedLMO();
1809 (selectionType() == TreeItem::Branch ||
1810 selectionType() == TreeItem::MapCenter ||
1811 selectionType() == TreeItem::Image ))
1813 QString u= b ? "false" : "true";
1814 QString r=!b ? "false" : "true";
1818 QString("setHideLinkUnselected (%1)").arg(u),
1820 QString("setHideLinkUnselected (%1)").arg(r),
1821 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1823 sel->setHideLinkUnselected(b);
1828 void VymModel::setHideExport(bool b)
1830 BranchItem *bi=getSelectedBranchItem();
1833 bi->setHideInExport (b);
1834 QString u= b ? "false" : "true";
1835 QString r=!b ? "false" : "true";
1839 QString ("setHideExport (%1)").arg(u),
1841 QString ("setHideExport (%1)").arg(r),
1842 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1846 // selection.update();
1847 // FIXME-3 VM needed? scene()->update();
1851 void VymModel::toggleHideExport()
1853 BranchItem *selbi=getSelectedBranchItem();
1855 setHideExport ( !selbi->hideInExport() );
1859 void VymModel::copy() //FIXME-2
1862 LinkableMapObj *sel=getSelectedLMO();
1864 (selectionType() == TreeItem::Branch ||
1865 selectionType() == TreeItem::MapCenter ||
1866 selectionType() == TreeItem::Image ))
1868 if (redosAvail == 0)
1871 QString s=getSelectString(sel);
1872 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1873 curClipboard=curStep;
1876 // Copy also to global clipboard, because we are at last step in history
1877 QString bakMapName(QString("history-%1").arg(curStep));
1878 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1879 copyDir (bakMapDir,clipboardDir );
1881 clipboardEmpty=false;
1888 void VymModel::pasteNoSave(const int &n) //FIXME-2
1891 bool old=blockSaveState;
1892 blockSaveState=true;
1893 bool zippedOrg=zipped;
1894 if (redosAvail > 0 || n!=0)
1896 // Use the "historical" buffer
1897 QString bakMapName(QString("history-%1").arg(n));
1898 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1899 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1901 // Use the global buffer
1902 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1908 void VymModel::paste() //FIXME-2
1911 BranchObj *sel=getSelectedBranch();
1914 saveStateChangingPart(
1917 QString ("paste (%1)").arg(curClipboard),
1918 QString("Paste to %1").arg( getObjectName(sel))
1926 void VymModel::cut() //FIXME-2
1929 LinkableMapObj *sel=getSelectedLMO();
1930 if ( sel && (selectionType() == TreeItem::Branch ||
1931 selectionType()==TreeItem::MapCenter ||
1932 selectionType()==TreeItem::Image))
1935 /* No savestate! savestate is called in cutNoSave
1936 saveStateChangingPart(
1940 QString("Cut %1").arg(getObjectName(sel ))
1950 void VymModel::moveBranchUp() //FIXME-2
1953 BranchObj* bo=getSelectedBranch();
1957 if (!bo->canMoveBranchUp()) return;
1958 par=(BranchObj*)(bo->getParObj());
1959 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1960 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1962 //FIXME-3 VM needed? scene()->update();
1964 ensureSelectionVisible();
1969 void VymModel::moveBranchDown() //FIXME-2
1972 BranchObj* bo=getSelectedBranch();
1976 if (!bo->canMoveBranchDown()) return;
1977 par=(BranchObj*)(bo->getParObj());
1978 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1979 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1981 //FIXME-3 VM needed? scene()->update();
1983 ensureSelectionVisible();
1988 void VymModel::sortChildren() // FIXME-2 not implemented yet
1991 BranchObj* bo=getSelectedBranch();
1994 if(treeItem->branchCount()>1)
1996 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1999 ensureSelectionVisible();
2005 MapCenterItem* VymModel::createMapCenter()
2007 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
2012 BranchItem* VymModel::createBranch()
2014 return addNewBranchInt (-2);
2017 TreeItem* VymModel::createImage() //FIXME-2
2020 BranchObj *bo=getSelectedBranch();
2023 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
2026 QList<QVariant> cData;
2027 cData << "VM:createImage" << "undef"<<"undef";
2028 TreeItem *parti=bo->getTreeItem();
2029 TreeItem *ti=new TreeItem (cData,parti);
2030 ti->setLMO (newfio);
2031 ti->setType (TreeItem::Image);
2032 parti->appendChild (ti);
2036 newfio->setTreeItem (ti);
2037 select (newfio); // FIXME-2 VM really needed here?
2045 MapCenterItem* VymModel::addMapCenter ()
2047 MapCenterItem *mci=addMapCenter (contextPos); //FIXME-2 get rid of MCO here
2048 //FIXME-3 selection.select (mco);
2050 ensureSelectionVisible();
2055 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2056 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2061 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2065 QModelIndex parix=index(rootItem);
2067 int n=rootItem->branchCount();
2069 emit (layoutAboutToBeChanged() );
2070 beginInsertRows (parix,n,n+1);
2072 QList<QVariant> cData;
2073 cData << "VM:addMapCenter" << "undef"<<"undef";
2074 MapCenterItem *mci=new MapCenterItem (cData);
2075 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2076 rootItem->appendChild (mci);
2079 emit (newChildObject (parix));
2080 emit (layoutChanged() );
2083 BranchObj *newbo=mci->createMapObj(mapScene);
2087 if (!mci->getHeading().isEmpty() )
2089 newbo->updateHeading();
2090 newbo->setColor (headingColor);
2094 //newbo->updateLink(); //FIXME-3
2097 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2098 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2099 mci->setLMO (mapCenter);
2100 mapCenter->updateHeading();
2101 mapCenter->move (absPos);
2102 mapCenter->setVisibility (true);
2103 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2108 BranchItem* VymModel::addNewBranchInt(int num)
2110 // Depending on pos:
2111 // -3 insert in children of parent above selection
2112 // -2 add branch to selection
2113 // -1 insert in children of parent below selection
2114 // 0..n insert in children of parent at pos
2115 BranchObj *newbo=NULL;
2116 BranchObj *bo=getSelectedBranchObj(); //FIXME-2
2117 BranchItem *bi=getSelectedBranchItem();
2123 QList<QVariant> cData;
2124 cData << "new" << "undef"<<"undef";
2126 BranchItem *parbi=bi;
2127 QModelIndex parix=index(parbi);
2128 int n=parbi->childCount();
2130 emit (layoutAboutToBeChanged() );
2131 beginInsertRows (parix,n,n+1); //FIXME-1 check if n is correct: should be index below _last_ branch...
2132 bi=new BranchItem (cData);
2133 bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2135 parbi->appendChild (bi);
2137 emit (newChildObject (parix));
2138 emit (layoutChanged() );
2140 // save scroll state. If scrolled, automatically select
2141 // new branch in order to tmp unscroll parent...
2142 newbo=bi->createMapObj(mapScene);
2148 bo=(BranchObj*)bo->getParObj();
2149 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2155 bo=(BranchObj*)bo->getParObj();
2156 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2163 BranchItem* VymModel::addNewBranch(int pos)
2165 // Different meaning than num in addNewBranchInt!
2169 BranchItem *newbi=NULL;
2170 BranchItem *selbi=getSelectedBranchItem();
2174 // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2176 newbi=addNewBranchInt (pos-2);
2184 QString ("addBranch (%1)").arg(pos),
2185 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2188 // selection.update(); FIXME-3
2189 latestSelectionString=getSelectString(newbi);
2190 // In Network mode, the client needs to know where the new branch is,
2191 // so we have to pass on this information via saveState.
2192 // TODO: Get rid of this positioning workaround
2193 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2194 sendData ("selectLatestAdded ()");
2195 sendData (QString("move %1").arg(ps));
2204 BranchItem* VymModel::addNewBranchBefore() //FIXME-2
2207 BranchObj *newbo=NULL;
2208 BranchObj *bo = getSelectedBranch();
2209 if (bo && selectionType()==TreeItem::Branch)
2210 // We accept no MapCenterObj here, so we _have_ a parent
2212 QPointF p=bo->getRelPos();
2215 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2217 // add below selection
2218 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2222 newbo->move2RelPos (p);
2224 // Move selection to new branch
2225 bo->linkTo (newbo,-1);
2227 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2228 QString ("Add branch before %1").arg(getObjectName(bo)));
2231 // selection.update(); FIXME-3
2234 latestSelectionString=selection.getSelectString();
2240 BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2244 emit (layoutAboutToBeChanged() );
2245 BranchItem *branchpi=(BranchItem*)branch->parent();
2246 // Remove at current position
2247 int n=branch->childNum();
2248 beginRemoveRows (index(branchpi),n,n);
2249 branchpi->removeChild (n);
2252 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2254 // Append as last branch to dst
2255 if (dst->branchCount()==0)
2258 n=dst->getFirstBranch()->childNumber();
2259 beginInsertRows (index(dst),n+pos,n+pos);
2260 dst->insertBranch (pos,branch);
2263 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2264 emit (layoutChanged() );
2269 void VymModel::deleteSelection()
2271 BranchObj *bo = getSelectedBranchObj(); // FIXME-2 VM should not be necessary
2272 BranchItem *selbi=getSelectedBranchItem();
2276 TreeItem *pi=selbi->parent();
2277 QModelIndex parentIndex=index(pi);
2279 if (selbi->isBranchLikeType() )
2282 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2284 emit (layoutAboutToBeChanged() );
2286 int n=selbi->childNum();
2287 beginRemoveRows (parentIndex,n,n);
2288 removeRows (n,1,parentIndex);
2291 ensureSelectionVisible();
2294 emit (layoutChanged() );
2297 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2302 BranchObj* par=(BranchObj*)fio->getParObj();
2303 saveStateChangingPart(
2307 QString("Delete %1").arg(getObjectName(fio))
2310 par->removeFloatImage(fio);
2313 ensureSelectionVisible();
2319 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2323 BranchObj *bo=getSelectedBranch();
2327 par=(BranchObj*)(bo->getParObj());
2329 // Don't use this on mapcenter
2332 // Check if we have childs at all to keep
2333 if (bo->getTreeItem()->branchCount()==0)
2339 QPointF p=bo->getRelPos();
2340 saveStateChangingPart(
2343 "deleteKeepChildren ()",
2344 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2347 QString sel=getSelectString(bo);
2349 par->removeBranchHere(bo);
2352 getSelectedBranch()->move2RelPos (p);
2357 void VymModel::deleteChildren() //FIXME-2 VM still missing
2361 BranchObj *bo=getSelectedBranch();
2364 saveStateChangingPart(
2367 "deleteChildren ()",
2368 QString( "Remove children of branch %1").arg(getObjectName(bo))
2370 bo->removeChildren();
2376 bool VymModel::scrollBranch(BranchItem *bi)
2380 if (bi->isScrolled()) return false;
2381 if (bi->branchCount()==0) return false;
2382 if (bi->depth()==0) return false;
2386 /* FIXME-3 no savestate yet
2389 QString ("%1 ()").arg(u),
2391 QString ("%1 ()").arg(r),
2392 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2396 //selection.update();
2397 // FIXME-3 VM needed? scene()->update();
2403 bool VymModel::unscrollBranch(BranchItem *bi)
2407 if (bi->isScrolled()) return false;
2408 if (bi->branchCount()==0) return false;
2409 if (bi->depth()==0) return false;
2414 /* FIXME-3 no savestate yet
2417 QString ("%1 ()").arg(u),
2419 QString ("%1 ()").arg(r),
2420 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2424 // selection.update();
2425 // FIXME-3 VM needed? scene()->update();
2431 void VymModel::toggleScroll()
2433 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2434 if (bi && bi->getType()==TreeItem::Branch )
2436 if (bi->isScrolled())
2437 unscrollBranch (bi);
2443 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2447 BranchObj *bo=getSelectedBranch();
2453 if (bo->isScrolled()) unscrollBranch (bo);
2460 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2463 BranchObj *bo=getSelectedBranch();
2466 FloatImageObj *fio=bo->addFloatImage();
2468 fio->setOriginalFilename("No original filename (image added by dropevent)");
2469 QString s=getSelectString(bo);
2470 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2471 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2473 // FIXME-3 VM needed? scene()->update();
2479 void VymModel::colorBranch (QColor c) //FIXME-2
2482 BranchObj *bo=getSelectedBranch();
2487 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2489 QString ("colorBranch (\"%1\")").arg(c.name()),
2490 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2492 bo->setColor(c); // color branch
2497 void VymModel::colorSubtree (QColor c) //FIXME-2
2500 BranchObj *bo=getSelectedBranch();
2503 saveStateChangingPart(
2506 QString ("colorSubtree (\"%1\")").arg(c.name()),
2507 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2509 bo->setColorSubtree (c); // color links, color children
2514 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2517 BranchObj *bo=getSelectedBranch();
2518 if (bo) return bo->getColor();
2520 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2527 void VymModel::editURL() //FIXME-2
2530 BranchObj *bo=getSelectedBranch();
2534 QString text = QInputDialog::getText(
2535 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2536 bo->getURL(), &ok, NULL);
2538 // user entered something and pressed OK
2544 void VymModel::editLocalURL() //FIXME-2
2547 BranchObj *bo=getSelectedBranch();
2550 QStringList filters;
2551 filters <<"All files (*)";
2552 filters << tr("Text","Filedialog") + " (*.txt)";
2553 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2554 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2555 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2556 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2557 fd->setFilters (filters);
2558 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2559 fd->setDirectory (lastFileDir);
2560 if (! bo->getVymLink().isEmpty() )
2561 fd->selectFile( bo->getURL() );
2564 if ( fd->exec() == QDialog::Accepted )
2566 lastFileDir=QDir (fd->directory().path());
2567 setURL (fd->selectedFile() );
2574 void VymModel::editHeading2URL() //FIXME-2
2577 BranchObj *bo=getSelectedBranch();
2579 setURL (bo->getHeading());
2583 void VymModel::editBugzilla2URL() //FIXME-2
2586 BranchObj *bo=getSelectedBranch();
2589 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2595 void VymModel::editFATE2URL() //FIXME-2
2598 BranchObj *bo=getSelectedBranch();
2601 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2604 "setURL (\""+bo->getURL()+"\")",
2606 "setURL (\""+url+"\")",
2607 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2615 void VymModel::editVymLink()
2617 BranchItem *bi=getSelectedBranchItem();
2620 QStringList filters;
2621 filters <<"VYM map (*.vym)";
2622 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2623 fd->setFilters (filters);
2624 fd->setCaption(vymName+" - " +tr("Link to another map"));
2625 fd->setDirectory (lastFileDir);
2626 if (! bi->getVymLink().isEmpty() )
2627 fd->selectFile( bi->getVymLink() );
2631 if ( fd->exec() == QDialog::Accepted )
2633 lastFileDir=QDir (fd->directory().path());
2636 "setVymLink (\""+bi->getVymLink()+"\")",
2638 "setVymLink (\""+fd->selectedFile()+"\")",
2639 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2641 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2646 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2648 // Internal function, no saveState needed
2649 BranchItem *bi=getSelectedBranchItem();
2652 bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO
2655 //selection.update();
2656 ensureSelectionVisible();
2660 void VymModel::deleteVymLink()
2662 BranchItem *bi=getSelectedBranchItem();
2667 "setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO
2670 "setVymLink (\"\")",
2671 QString("Unset vymlink of %1").arg(getObjectName(bi))
2673 bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO
2676 // FIXME-3 VM needed? scene()->update();
2680 QString VymModel::getVymLink()
2682 BranchItem *bi=getSelectedBranchItem();
2684 return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here...
2690 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2692 return QStringList();
2695 BranchObj *bo=getSelectedBranch();
2701 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2710 void VymModel::followXLink(int i) // FIXME-2
2714 BranchObj *bo=getSelectedBranch();
2717 bo=bo->XLinkTargetAt(i);
2720 selection.select(bo);
2721 ensureSelectionVisible();
2727 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2731 BranchObj *bo=getSelectedBranch();
2734 XLinkObj *xlo=bo->XLinkAt(i);
2737 EditXLinkDialog dia;
2739 dia.setSelection(bo);
2740 if (dia.exec() == QDialog::Accepted)
2742 if (dia.useSettingsGlobal() )
2744 setMapDefXLinkColor (xlo->getColor() );
2745 setMapDefXLinkWidth (xlo->getWidth() );
2747 if (dia.deleteXLink())
2748 bo->deleteXLinkAt(i);
2759 //////////////////////////////////////////////
2761 //////////////////////////////////////////////
2763 void VymModel::parseAtom(const QString &atom)
2765 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2766 TreeItem* selti=getSelectedItem();
2767 BranchItem *selbi=getSelectedBranchItem();
2773 // Split string s into command and parameters
2774 parser.parseAtom (atom);
2775 QString com=parser.getCommand();
2777 // External commands
2778 /////////////////////////////////////////////////////////////////////
2779 if (com=="addBranch")
2783 parser.setError (Aborted,"Nothing selected");
2784 } else if (! selbi )
2786 parser.setError (Aborted,"Type of selection is not a branch");
2791 if (parser.checkParCount(pl))
2793 if (parser.parCount()==0)
2797 n=parser.parInt (ok,0);
2798 if (ok ) addNewBranch (n);
2802 /////////////////////////////////////////////////////////////////////
2803 } else if (com=="addBranchBefore")
2807 parser.setError (Aborted,"Nothing selected");
2808 } else if (! selbi )
2810 parser.setError (Aborted,"Type of selection is not a branch");
2813 if (parser.parCount()==0)
2815 addNewBranchBefore ();
2818 /////////////////////////////////////////////////////////////////////
2819 } else if (com==QString("addMapCenter"))
2821 if (parser.checkParCount(2))
2823 x=parser.parDouble (ok,0);
2826 y=parser.parDouble (ok,1);
2827 if (ok) addMapCenter (QPointF(x,y));
2830 /////////////////////////////////////////////////////////////////////
2831 } else if (com==QString("addMapReplace"))
2835 parser.setError (Aborted,"Nothing selected");
2836 } else if (! selbi )
2838 parser.setError (Aborted,"Type of selection is not a branch");
2839 } else if (parser.checkParCount(1))
2841 //s=parser.parString (ok,0); // selection
2842 t=parser.parString (ok,0); // path to map
2843 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2844 addMapReplaceInt(getSelectString(selbi),t);
2846 /////////////////////////////////////////////////////////////////////
2847 } else if (com==QString("addMapInsert"))
2851 parser.setError (Aborted,"Nothing selected");
2852 } else if (! selbi )
2854 parser.setError (Aborted,"Type of selection is not a branch");
2857 if (parser.checkParCount(2))
2859 t=parser.parString (ok,0); // path to map
2860 n=parser.parInt(ok,1); // position
2861 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2862 addMapInsertInt(t,n);
2865 /////////////////////////////////////////////////////////////////////
2866 } else /*if (com=="clearFlags") // FIXME-2
2870 parser.setError (Aborted,"Nothing selected");
2871 } else if (! selbi )
2873 parser.setError (Aborted,"Type of selection is not a branch");
2874 } else if (parser.checkParCount(0))
2876 selb->clearStandardFlags();
2877 selb->updateFlagsToolbar();
2879 /////////////////////////////////////////////////////////////////////
2880 } else */ if (com=="colorBranch")
2884 parser.setError (Aborted,"Nothing selected");
2885 } else if (! selbi )
2887 parser.setError (Aborted,"Type of selection is not a branch");
2888 } else if (parser.checkParCount(1))
2890 QColor c=parser.parColor (ok,0);
2891 if (ok) colorBranch (c);
2893 /////////////////////////////////////////////////////////////////////
2894 } else if (com=="colorSubtree")
2898 parser.setError (Aborted,"Nothing selected");
2899 } else if (! selbi )
2901 parser.setError (Aborted,"Type of selection is not a branch");
2902 } else if (parser.checkParCount(1))
2904 QColor c=parser.parColor (ok,0);
2905 if (ok) colorSubtree (c);
2907 /////////////////////////////////////////////////////////////////////
2908 } else if (com=="copy")
2912 parser.setError (Aborted,"Nothing selected");
2913 } else if (! selbi )
2915 parser.setError (Aborted,"Type of selection is not a branch");
2916 } else if (parser.checkParCount(0))
2918 //FIXME-1 missing action for copy
2920 /////////////////////////////////////////////////////////////////////
2921 } else if (com=="cut")
2925 parser.setError (Aborted,"Nothing selected");
2926 } else if ( selectionType()!=TreeItem::Branch &&
2927 selectionType()!=TreeItem::MapCenter &&
2928 selectionType()!=TreeItem::Image )
2930 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2931 } else if (parser.checkParCount(0))
2935 /////////////////////////////////////////////////////////////////////
2936 } else if (com=="delete")
2940 parser.setError (Aborted,"Nothing selected");
2942 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2944 parser.setError (Aborted,"Type of selection is wrong.");
2947 else if (parser.checkParCount(0))
2951 /////////////////////////////////////////////////////////////////////
2952 } else if (com=="deleteKeepChildren")
2956 parser.setError (Aborted,"Nothing selected");
2957 } else if (! selbi )
2959 parser.setError (Aborted,"Type of selection is not a branch");
2960 } else if (parser.checkParCount(0))
2962 deleteKeepChildren();
2964 /////////////////////////////////////////////////////////////////////
2965 } else if (com=="deleteChildren")
2969 parser.setError (Aborted,"Nothing selected");
2972 parser.setError (Aborted,"Type of selection is not a branch");
2973 } else if (parser.checkParCount(0))
2977 /////////////////////////////////////////////////////////////////////
2978 } else if (com=="exportASCII")
2982 if (parser.parCount()>=1)
2983 // Hey, we even have a filename
2984 fname=parser.parString(ok,0);
2987 parser.setError (Aborted,"Could not read filename");
2990 exportASCII (fname,false);
2992 /////////////////////////////////////////////////////////////////////
2993 } else if (com=="exportImage")
2997 if (parser.parCount()>=2)
2998 // Hey, we even have a filename
2999 fname=parser.parString(ok,0);
3002 parser.setError (Aborted,"Could not read filename");
3005 QString format="PNG";
3006 if (parser.parCount()>=2)
3008 format=parser.parString(ok,1);
3010 exportImage (fname,false,format);
3012 /////////////////////////////////////////////////////////////////////
3013 } else if (com=="exportXHTML")
3017 if (parser.parCount()>=2)
3018 // Hey, we even have a filename
3019 fname=parser.parString(ok,1);
3022 parser.setError (Aborted,"Could not read filename");
3025 exportXHTML (fname,false);
3027 /////////////////////////////////////////////////////////////////////
3028 } else if (com=="exportXML")
3032 if (parser.parCount()>=2)
3033 // Hey, we even have a filename
3034 fname=parser.parString(ok,1);
3037 parser.setError (Aborted,"Could not read filename");
3040 exportXML (fname,false);
3042 /////////////////////////////////////////////////////////////////////
3043 } else if (com=="importDir")
3047 parser.setError (Aborted,"Nothing selected");
3048 } else if (! selbi )
3050 parser.setError (Aborted,"Type of selection is not a branch");
3051 } else if (parser.checkParCount(1))
3053 s=parser.parString(ok,0);
3054 if (ok) importDirInt(s);
3056 /////////////////////////////////////////////////////////////////////
3057 } else /* FIXME-2 if (com=="linkTo")
3061 parser.setError (Aborted,"Nothing selected");
3064 if (parser.checkParCount(4))
3066 // 0 selectstring of parent
3067 // 1 num in parent (for branches)
3068 // 2,3 x,y of mainbranch or mapcenter
3069 s=parser.parString(ok,0);
3070 LinkableMapObj *dst=findObjBySelect (s);
3073 if (typeid(*dst) == typeid(BranchObj) )
3075 // Get number in parent
3076 n=parser.parInt (ok,1);
3079 selb->linkTo ((BranchObj*)(dst),n);
3082 } else if (typeid(*dst) == typeid(MapCenterObj) )
3084 selb->linkTo ((BranchObj*)(dst),-1);
3085 // Get coordinates of mainbranch
3086 x=parser.parDouble(ok,2);
3089 y=parser.parDouble(ok,3);
3099 } else if ( selectionType() == TreeItem::Image)
3101 if (parser.checkParCount(1))
3103 // 0 selectstring of parent
3104 s=parser.parString(ok,0);
3105 LinkableMapObj *dst=findObjBySelect (s);
3108 if (typeid(*dst) == typeid(BranchObj) ||
3109 typeid(*dst) == typeid(MapCenterObj))
3110 linkFloatImageTo (getSelectString(dst));
3112 parser.setError (Aborted,"Destination is not a branch");
3115 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3116 /////////////////////////////////////////////////////////////////////
3117 } else */ if (com=="loadImage")
3121 parser.setError (Aborted,"Nothing selected");
3122 } else if (! selbi )
3124 parser.setError (Aborted,"Type of selection is not a branch");
3125 } else if (parser.checkParCount(1))
3127 s=parser.parString(ok,0);
3128 if (ok) loadFloatImageInt (s);
3130 /////////////////////////////////////////////////////////////////////
3131 } else if (com=="moveBranchUp")
3135 parser.setError (Aborted,"Nothing selected");
3136 } else if (! selbi )
3138 parser.setError (Aborted,"Type of selection is not a branch");
3139 } else if (parser.checkParCount(0))
3143 /////////////////////////////////////////////////////////////////////
3144 } else if (com=="moveBranchDown")
3148 parser.setError (Aborted,"Nothing selected");
3149 } else if (! selbi )
3151 parser.setError (Aborted,"Type of selection is not a branch");
3152 } else if (parser.checkParCount(0))
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="move")
3161 parser.setError (Aborted,"Nothing selected");
3162 } else if ( selectionType()!=TreeItem::Branch &&
3163 selectionType()!=TreeItem::MapCenter &&
3164 selectionType()!=TreeItem::Image )
3166 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3167 } else if (parser.checkParCount(2))
3169 x=parser.parDouble (ok,0);
3172 y=parser.parDouble (ok,1);
3176 /////////////////////////////////////////////////////////////////////
3177 } else if (com=="moveRel")
3181 parser.setError (Aborted,"Nothing selected");
3182 } else if ( selectionType()!=TreeItem::Branch &&
3183 selectionType()!=TreeItem::MapCenter &&
3184 selectionType()!=TreeItem::Image )
3186 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3187 } else if (parser.checkParCount(2))
3189 x=parser.parDouble (ok,0);
3192 y=parser.parDouble (ok,1);
3193 if (ok) moveRel (x,y);
3196 /////////////////////////////////////////////////////////////////////
3197 } else if (com=="nop")
3199 /////////////////////////////////////////////////////////////////////
3200 } else if (com=="paste")
3204 parser.setError (Aborted,"Nothing selected");
3205 } else if (! selbi )
3207 parser.setError (Aborted,"Type of selection is not a branch");
3208 } else if (parser.checkParCount(1))
3210 n=parser.parInt (ok,0);
3211 if (ok) pasteNoSave(n);
3213 /////////////////////////////////////////////////////////////////////
3214 } else if (com=="qa")
3218 parser.setError (Aborted,"Nothing selected");
3219 } else if (! selbi )
3221 parser.setError (Aborted,"Type of selection is not a branch");
3222 } else if (parser.checkParCount(4))
3225 c=parser.parString (ok,0);
3228 parser.setError (Aborted,"No comment given");
3231 s=parser.parString (ok,1);
3234 parser.setError (Aborted,"First parameter is not a string");
3237 t=parser.parString (ok,2);
3240 parser.setError (Aborted,"Condition is not a string");
3243 u=parser.parString (ok,3);
3246 parser.setError (Aborted,"Third parameter is not a string");
3251 parser.setError (Aborted,"Unknown type: "+s);
3256 parser.setError (Aborted,"Unknown operator: "+t);
3261 parser.setError (Aborted,"Type of selection is not a branch");
3264 if (selbi->getHeading() == u)
3266 cout << "PASSED: " << qPrintable (c) << endl;
3269 cout << "FAILED: " << qPrintable (c) << endl;
3279 /////////////////////////////////////////////////////////////////////
3280 } else if (com=="saveImage")
3282 FloatImageObj *fio=selection.getFloatImage();
3285 parser.setError (Aborted,"Type of selection is not an image");
3286 } else if (parser.checkParCount(2))
3288 s=parser.parString(ok,0);
3291 t=parser.parString(ok,1);
3292 if (ok) saveFloatImageInt (fio,t,s);
3295 /////////////////////////////////////////////////////////////////////
3296 } else if (com=="scroll")
3300 parser.setError (Aborted,"Nothing selected");
3301 } else if (! selbi )
3303 parser.setError (Aborted,"Type of selection is not a branch");
3304 } else if (parser.checkParCount(0))
3306 if (!scrollBranch (selbi))
3307 parser.setError (Aborted,"Could not scroll branch");
3309 /////////////////////////////////////////////////////////////////////
3310 } else if (com=="select")
3312 if (parser.checkParCount(1))
3314 s=parser.parString(ok,0);
3317 /////////////////////////////////////////////////////////////////////
3318 } else if (com=="selectLastBranch")
3322 parser.setError (Aborted,"Nothing selected");
3323 } else if (! selbi )
3325 parser.setError (Aborted,"Type of selection is not a branch");
3326 } else if (parser.checkParCount(0))
3328 BranchItem *bi=selbi->getLastBranch();
3330 parser.setError (Aborted,"Could not select last branch");
3331 select (bi); // FIXME-3 was selectInt
3334 /////////////////////////////////////////////////////////////////////
3335 } else /* FIXME-2 if (com=="selectLastImage")
3339 parser.setError (Aborted,"Nothing selected");
3340 } else if (! selbi )
3342 parser.setError (Aborted,"Type of selection is not a branch");
3343 } else if (parser.checkParCount(0))
3345 FloatImageObj *fio=selb->getLastFloatImage();
3347 parser.setError (Aborted,"Could not select last image");
3348 select (fio); // FIXME-3 was selectInt
3351 /////////////////////////////////////////////////////////////////////
3352 } else */ if (com=="selectLatestAdded")
3354 if (latestSelectionString.isEmpty() )
3356 parser.setError (Aborted,"No latest added object");
3359 if (!select (latestSelectionString))
3360 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3362 /////////////////////////////////////////////////////////////////////
3363 } else if (com=="setFrameType")
3365 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3367 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3369 else if (parser.checkParCount(1))
3371 s=parser.parString(ok,0);
3372 if (ok) setFrameType (s);
3374 /////////////////////////////////////////////////////////////////////
3375 } else if (com=="setFramePenColor")
3377 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3379 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3381 else if (parser.checkParCount(1))
3383 QColor c=parser.parColor(ok,0);
3384 if (ok) setFramePenColor (c);
3386 /////////////////////////////////////////////////////////////////////
3387 } else if (com=="setFrameBrushColor")
3389 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3391 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3393 else if (parser.checkParCount(1))
3395 QColor c=parser.parColor(ok,0);
3396 if (ok) setFrameBrushColor (c);
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="setFramePadding")
3401 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3403 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3405 else if (parser.checkParCount(1))
3407 n=parser.parInt(ok,0);
3408 if (ok) setFramePadding(n);
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="setFrameBorderWidth")
3413 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3415 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3417 else if (parser.checkParCount(1))
3419 n=parser.parInt(ok,0);
3420 if (ok) setFrameBorderWidth (n);
3422 /////////////////////////////////////////////////////////////////////
3423 } else if (com=="setMapAuthor")
3425 if (parser.checkParCount(1))
3427 s=parser.parString(ok,0);
3428 if (ok) setAuthor (s);
3430 /////////////////////////////////////////////////////////////////////
3431 } else if (com=="setMapComment")
3433 if (parser.checkParCount(1))
3435 s=parser.parString(ok,0);
3436 if (ok) setComment(s);
3438 /////////////////////////////////////////////////////////////////////
3439 } else if (com=="setMapBackgroundColor")
3443 parser.setError (Aborted,"Nothing selected");
3444 } else if (! selbi )
3446 parser.setError (Aborted,"Type of selection is not a branch");
3447 } else if (parser.checkParCount(1))
3449 QColor c=parser.parColor (ok,0);
3450 if (ok) setMapBackgroundColor (c);
3452 /////////////////////////////////////////////////////////////////////
3453 } else if (com=="setMapDefLinkColor")
3457 parser.setError (Aborted,"Nothing selected");
3458 } else if (! selbi )
3460 parser.setError (Aborted,"Type of selection is not a branch");
3461 } else if (parser.checkParCount(1))
3463 QColor c=parser.parColor (ok,0);
3464 if (ok) setMapDefLinkColor (c);
3466 /////////////////////////////////////////////////////////////////////
3467 } else if (com=="setMapLinkStyle")
3469 if (parser.checkParCount(1))
3471 s=parser.parString (ok,0);
3472 if (ok) setMapLinkStyle(s);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="setHeading")
3479 parser.setError (Aborted,"Nothing selected");
3480 } else if (! selbi )
3482 parser.setError (Aborted,"Type of selection is not a branch");
3483 } else if (parser.checkParCount(1))
3485 s=parser.parString (ok,0);
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="setHideExport")
3494 parser.setError (Aborted,"Nothing selected");
3495 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3497 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3498 } else if (parser.checkParCount(1))
3500 b=parser.parBool(ok,0);
3501 if (ok) setHideExport (b);
3503 /////////////////////////////////////////////////////////////////////
3504 } else if (com=="setIncludeImagesHorizontally")
3508 parser.setError (Aborted,"Nothing selected");
3511 parser.setError (Aborted,"Type of selection is not a branch");
3512 } else if (parser.checkParCount(1))
3514 b=parser.parBool(ok,0);
3515 if (ok) setIncludeImagesHor(b);
3517 /////////////////////////////////////////////////////////////////////
3518 } else if (com=="setIncludeImagesVertically")
3522 parser.setError (Aborted,"Nothing selected");
3525 parser.setError (Aborted,"Type of selection is not a branch");
3526 } else if (parser.checkParCount(1))
3528 b=parser.parBool(ok,0);
3529 if (ok) setIncludeImagesVer(b);
3531 /////////////////////////////////////////////////////////////////////
3532 } else if (com=="setHideLinkUnselected")
3536 parser.setError (Aborted,"Nothing selected");
3537 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3539 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3540 } else if (parser.checkParCount(1))
3542 b=parser.parBool(ok,0);
3543 if (ok) setHideLinkUnselected(b);
3545 /////////////////////////////////////////////////////////////////////
3546 } else if (com=="setSelectionColor")
3548 if (parser.checkParCount(1))
3550 QColor c=parser.parColor (ok,0);
3551 if (ok) setSelectionColorInt (c);
3553 /////////////////////////////////////////////////////////////////////
3554 } else if (com=="setURL")
3558 parser.setError (Aborted,"Nothing selected");
3559 } else if (! selbi )
3561 parser.setError (Aborted,"Type of selection is not a branch");
3562 } else if (parser.checkParCount(1))
3564 s=parser.parString (ok,0);
3567 /////////////////////////////////////////////////////////////////////
3568 } else if (com=="setVymLink")
3572 parser.setError (Aborted,"Nothing selected");
3573 } else if (! selbi )
3575 parser.setError (Aborted,"Type of selection is not a branch");
3576 } else if (parser.checkParCount(1))
3578 s=parser.parString (ok,0);
3579 if (ok) setVymLink(s);
3582 /////////////////////////////////////////////////////////////////////
3583 else /* FIXME-2 if (com=="setFlag")
3587 parser.setError (Aborted,"Nothing selected");
3588 } else if (! selbi )
3590 parser.setError (Aborted,"Type of selection is not a branch");
3591 } else if (parser.checkParCount(1))
3593 s=parser.parString(ok,0);
3596 selb->activateStandardFlag(s);
3597 selb->updateFlagsToolbar();
3600 /////////////////////////////////////////////////////////////////////
3601 } else */ /* FIXME-2 if (com=="setFrameType")
3605 parser.setError (Aborted,"Nothing selected");
3608 parser.setError (Aborted,"Type of selection is not a branch");
3609 } else if (parser.checkParCount(1))
3611 s=parser.parString(ok,0);
3615 /////////////////////////////////////////////////////////////////////
3616 } else*/ if (com=="sortChildren")
3620 parser.setError (Aborted,"Nothing selected");
3621 } else if (! selbi )
3623 parser.setError (Aborted,"Type of selection is not a branch");
3624 } else if (parser.checkParCount(0))
3628 /////////////////////////////////////////////////////////////////////
3629 } else /* FIXME-2 if (com=="toggleFlag")
3633 parser.setError (Aborted,"Nothing selected");
3634 } else if (! selbi )
3636 parser.setError (Aborted,"Type of selection is not a branch");
3637 } else if (parser.checkParCount(1))
3639 s=parser.parString(ok,0);
3642 selbi->toggleStandardFlag(s);
3643 selb->updateFlagsToolbar();
3646 /////////////////////////////////////////////////////////////////////
3647 } else */ if (com=="unscroll")
3651 parser.setError (Aborted,"Nothing selected");
3652 } else if (! selbi )
3654 parser.setError (Aborted,"Type of selection is not a branch");
3655 } else if (parser.checkParCount(0))
3657 if (!unscrollBranch (selbi))
3658 parser.setError (Aborted,"Could not unscroll branch");
3660 /////////////////////////////////////////////////////////////////////
3661 } else if (com=="unscrollChildren")
3665 parser.setError (Aborted,"Nothing selected");
3666 } else if (! selbi )
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(0))
3671 unscrollChildren ();
3673 /////////////////////////////////////////////////////////////////////
3674 } else /* FIXME-2 if (com=="unsetFlag")
3676 if (selection.isEmpty() )
3678 parser.setError (Aborted,"Nothing selected");
3679 } else if (! selbi )
3681 parser.setError (Aborted,"Type of selection is not a branch");
3682 } else if (parser.checkParCount(1))
3684 s=parser.parString(ok,0);
3687 selb->deactivateStandardFlag(s);
3688 selb->updateFlagsToolbar();
3692 parser.setError (Aborted,"Unknown command");
3695 if (parser.errorLevel()==NoError)
3697 // setChanged(); FIXME-2 should not be called e.g. for export?!
3702 // TODO Error handling
3703 qWarning("VymModel::parseAtom: Error!");
3704 qWarning(parser.errorMessage());
3708 void VymModel::runScript (QString script)
3710 parser.setScript (script);
3712 while (parser.next() )
3713 parseAtom(parser.getAtom());
3716 void VymModel::setExportMode (bool b)
3718 // should be called before and after exports
3719 // depending on the settings
3720 if (b && settings.value("/export/useHideExport","true")=="true")
3721 setHideTmpMode (TreeItem::HideExport);
3723 setHideTmpMode (TreeItem::HideNone);
3726 void VymModel::exportImage(QString fname, bool askName, QString format)
3730 fname=getMapName()+".png";
3737 QFileDialog *fd=new QFileDialog (NULL);
3738 fd->setCaption (tr("Export map as image"));
3739 fd->setDirectory (lastImageDir);
3740 fd->setFileMode(QFileDialog::AnyFile);
3741 fd->setFilters (imageIO.getFilters() );
3744 fl=fd->selectedFiles();
3746 format=imageIO.getType(fd->selectedFilter());
3750 setExportMode (true);
3751 QPixmap pix (getPixmap());
3752 pix.save(fname, format);
3753 setExportMode (false);
3757 void VymModel::exportXML(QString dir, bool askForName)
3761 dir=browseDirectory(NULL,tr("Export XML to directory"));
3762 if (dir =="" && !reallyWriteDirectory(dir) )
3766 // Hide stuff during export, if settings want this
3767 setExportMode (true);
3769 // Create subdirectories
3772 // write to directory
3773 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3776 file.setName ( dir + "/"+mapName+".xml");
3777 if ( !file.open( QIODevice::WriteOnly ) )
3779 // This should neverever happen
3780 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3784 // Write it finally, and write in UTF8, no matter what
3785 QTextStream ts( &file );
3786 ts.setEncoding (QTextStream::UnicodeUTF8);
3790 // Now write image, too
3791 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3793 setExportMode (false);
3796 void VymModel::exportASCII(QString fname,bool askName)
3801 ex.setFile (mapName+".txt");
3807 //ex.addFilter ("TXT (*.txt)");
3808 ex.setDir(lastImageDir);
3809 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3814 setExportMode(true);
3816 setExportMode(false);
3820 void VymModel::exportXHTML (const QString &dir, bool askForName)
3822 ExportXHTMLDialog dia(NULL);
3823 dia.setFilePath (filePath );
3824 dia.setMapName (mapName );
3826 if (dir!="") dia.setDir (dir);
3832 if (dia.exec()!=QDialog::Accepted)
3836 QDir d (dia.getDir());
3837 // Check, if warnings should be used before overwriting
3838 // the output directory
3839 if (d.exists() && d.count()>0)
3842 warn.showCancelButton (true);
3843 warn.setText(QString(
3844 "The directory %1 is not empty.\n"
3845 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3846 warn.setCaption("Warning: Directory not empty");
3847 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3849 if (warn.exec()!=QDialog::Accepted) ok=false;
3856 exportXML (dia.getDir(),false );
3857 dia.doExport(mapName );
3858 //if (dia.hasChanged()) setChanged();
3862 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3867 if (ex.setConfigFile(cf))
3869 setExportMode (true);
3870 ex.exportPresentation();
3871 setExportMode (false);
3878 //////////////////////////////////////////////
3880 //////////////////////////////////////////////
3882 void VymModel::registerEditor(QWidget *me)
3884 mapEditor=(MapEditor*)me;
3886 for (int i=0; i<rootItem->branchCount(); i++)
3887 rootItem->getBranchNum(i)->setMapEditor(mapEditor);
3891 void VymModel::unregisterEditor(QWidget *)
3896 void VymModel::setContextPos(QPointF p)
3901 void VymModel::unsetContextPos()
3903 contextPos=QPointF();
3906 void VymModel::updateNoteFlag()
3909 cout << "VM::updateNoteFlag()\n";
3910 /* FIXME-1 modify note flag
3911 BranchObj *bo=getSelectedBranch();
3914 bo->updateNoteFlag();
3915 mainWindow->updateActions();
3920 void VymModel::updateRelPositions() //FIXME-2 VM should have no need to updateRelPos
3922 //cout << "VM::updateRelPos...\n";
3923 for (int i=0; i<rootItem->branchCount(); i++)
3924 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3927 void VymModel::reposition() //FIXME-2 VM should have no need to reposition, this is done in views???
3929 //cout << "VM::reposition ...\n";
3930 for (int i=0;i<rootItem->branchCount(); i++)
3931 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3934 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3937 // Creating (arbitrary) shapes
3940 QRectF rb=bo->getBBox();
3941 if (bo->getDepth()==0)
3943 // Just take BBox of this mapCenter
3944 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3948 // Take union of BBox and TotalBBox
3950 QRectF ra=bo->getTotalBBox();
3951 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3954 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3957 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3959 p <<ra.bottomRight()
3961 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3964 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3969 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3973 // Move all branches and MapCenters away from lmo
3974 // to avoid collisions
3980 BranchObj *boA=(BranchObj*)lmo;
3982 for (int i=0; i<rootItem->branchCount(); i++)
3984 boB=rootItem->getBranchNum(i);
3987 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3990 <<" ("<<qPrintable(boA->getHeading() )<<")"
3991 <<" with ("<< qPrintable (boB->getHeading() )
3994 <<" minT="<<r.minTranslation<<endl<<endl;
3999 QPixmap VymModel::getPixmap()
4001 QRectF mapRect=getTotalBBox();
4002 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4005 pp.setRenderHints(mapEditor->renderHints());
4007 // Don't print the visualisation of selection
4008 selection.unselect();
4010 mapScene->render ( &pp,
4011 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4012 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4014 // Restore selection
4015 selection.reselect();
4021 void VymModel::setMapLinkStyle (const QString & s)
4026 case LinkableMapObj::Line :
4029 case LinkableMapObj::Parabel:
4030 snow="StyleParabel";
4032 case LinkableMapObj::PolyLine:
4033 snow="StylePolyLine";
4035 case LinkableMapObj::PolyParabel:
4036 snow="StylePolyParabel";
4039 snow="UndefinedStyle";
4044 QString("setMapLinkStyle (\"%1\")").arg(s),
4045 QString("setMapLinkStyle (\"%1\")").arg(snow),
4046 QString("Set map link style (\"%1\")").arg(s)
4050 linkstyle=LinkableMapObj::Line;
4051 else if (s=="StyleParabel")
4052 linkstyle=LinkableMapObj::Parabel;
4053 else if (s=="StylePolyLine")
4054 linkstyle=LinkableMapObj::PolyLine;
4055 else if (s=="StylePolyParabel")
4056 linkstyle=LinkableMapObj::PolyParabel;
4058 linkstyle=LinkableMapObj::UndefinedStyle;
4060 BranchItem *cur=NULL;
4061 BranchItem *prev=NULL;
4067 bo=(BranchObj*)(cur->getLMO() );
4068 bo->setLinkStyle(bo->getDefLinkStyle());
4069 cur=next(cur,prev,d);
4074 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4079 void VymModel::setMapDefLinkColor(QColor col)
4081 if ( !col.isValid() ) return;
4083 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4084 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4085 QString("Set map link color to %1").arg(col.name())
4089 BranchItem *cur=NULL;
4090 BranchItem *prev=NULL;
4093 cur=next(cur,prev,d);
4096 bo=(BranchObj*)(cur->getLMO() );
4103 void VymModel::setMapLinkColorHintInt()
4105 // called from setMapLinkColorHint(lch) or at end of parse
4106 BranchItem *cur=NULL;
4107 BranchItem *prev=NULL;
4110 cur=next(cur,prev,d);
4113 bo=(BranchObj*)(cur->getLMO() );
4115 cur=next(cur,prev,d);
4119 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4122 setMapLinkColorHintInt();
4125 void VymModel::toggleMapLinkColorHint()
4127 if (linkcolorhint==LinkableMapObj::HeadingColor)
4128 linkcolorhint=LinkableMapObj::DefaultColor;
4130 linkcolorhint=LinkableMapObj::HeadingColor;
4131 BranchItem *cur=NULL;
4132 BranchItem *prev=NULL;
4135 cur=next(cur,prev,d);
4138 bo=(BranchObj*)(cur->getLMO() );
4144 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4146 Q3FileDialog *fd=new Q3FileDialog( NULL);
4147 fd->setMode (Q3FileDialog::ExistingFile);
4148 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4149 ImagePreview *p =new ImagePreview (fd);
4150 fd->setContentsPreviewEnabled( TRUE );
4151 fd->setContentsPreview( p, p );
4152 fd->setPreviewMode( Q3FileDialog::Contents );
4153 fd->setCaption(vymName+" - " +tr("Load background image"));
4154 fd->setDir (lastImageDir);
4157 if ( fd->exec() == QDialog::Accepted )
4159 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4160 lastImageDir=QDir (fd->dirPath());
4161 setMapBackgroundImage (fd->selectedFile());
4165 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4167 QColor oldcol=mapScene->backgroundBrush().color();
4171 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4173 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4174 QString("Set background color of map to %1").arg(col.name()));
4177 brush.setTextureImage (QPixmap (fn));
4178 mapScene->setBackgroundBrush(brush);
4181 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4183 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4184 if ( !col.isValid() ) return;
4185 setMapBackgroundColor( col );
4189 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4191 QColor oldcol=mapScene->backgroundBrush().color();
4193 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4194 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4195 QString("Set background color of map to %1").arg(col.name()));
4196 mapScene->setBackgroundBrush(col);
4199 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4201 return mapScene->backgroundBrush().color();
4205 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4207 return linkcolorhint;
4210 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4212 return defLinkColor;
4215 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4220 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4222 return defXLinkColor;
4225 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4230 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4232 return defXLinkWidth;
4235 void VymModel::move(const double &x, const double &y) // FIXME-3
4239 BranchObj *bo = getSelectedBranch();
4241 (selectionType()==TreeItem::Branch ||
4242 selectionType()==TreeItem::MapCenter ||
4243 selectionType()==TreeItem::Image
4246 QPointF ap(bo->getAbsPos());
4250 QString ps=qpointfToString(ap);
4251 QString s=getSelectString();
4254 s, "move "+qpointfToString(to),
4255 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4264 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4268 BranchObj *bo = getSelectedBranch();
4270 (selectionType()==TreeItem::Branch ||
4271 selectionType()==TreeItem::MapCenter ||
4272 selectionType()==TreeItem::Image
4276 QPointF rp(bo->getRelPos());
4280 QString ps=qpointfToString (bo->getRelPos());
4281 QString s=getSelectString(bo);
4284 s, "moveRel "+qpointfToString(to),
4285 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4286 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4296 void VymModel::animate()
4298 animationTimer->stop();
4301 while (i<animObjList.size() )
4303 bo=(BranchObj*)animObjList.at(i);
4308 animObjList.removeAt(i);
4315 QItemSelection sel=selModel->selection();
4316 emit (selectionChanged(sel,sel));
4319 if (!animObjList.isEmpty()) animationTimer->start();
4323 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4325 if (bo && bo->getTreeItem()->depth()>0)
4328 ap.setStart (start);
4330 ap.setTicks (animationTicks);
4331 ap.setAnimated (true);
4332 bo->setAnimation (ap);
4333 animObjList.append( bo );
4334 animationTimer->setSingleShot (true);
4335 animationTimer->start(animationInterval);
4339 void VymModel::stopAnimation (MapObj *mo)
4341 int i=animObjList.indexOf(mo);
4343 animObjList.removeAt (i);
4346 void VymModel::sendSelection()
4348 if (netstate!=Server) return;
4349 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4352 void VymModel::newServer()
4356 tcpServer = new QTcpServer(this);
4357 if (!tcpServer->listen(QHostAddress::Any,port)) {
4358 QMessageBox::critical(NULL, "vym server",
4359 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4360 //FIXME-3 needed? we are no widget any longer... close();
4363 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4365 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4368 void VymModel::connectToServer()
4371 server="salam.suse.de";
4373 clientSocket = new QTcpSocket (this);
4374 clientSocket->abort();
4375 clientSocket->connectToHost(server ,port);
4376 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4377 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4378 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4380 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4385 void VymModel::newClient()
4387 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4388 connect(newClient, SIGNAL(disconnected()),
4389 newClient, SLOT(deleteLater()));
4391 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4393 clientList.append (newClient);
4397 void VymModel::sendData(const QString &s)
4399 if (clientList.size()==0) return;
4401 // Create bytearray to send
4403 QDataStream out(&block, QIODevice::WriteOnly);
4404 out.setVersion(QDataStream::Qt_4_0);
4406 // Reserve some space for blocksize
4409 // Write sendCounter
4410 out << sendCounter++;
4415 // Go back and write blocksize so far
4416 out.device()->seek(0);
4417 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4421 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4423 for (int i=0; i<clientList.size(); ++i)
4425 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4426 clientList.at(i)->write (block);
4430 void VymModel::readData ()
4432 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4435 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4439 QDataStream in(clientSocket);
4440 in.setVersion(QDataStream::Qt_4_0);
4448 cout << " t="<<qPrintable (t)<<endl;
4454 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4456 switch (socketError) {
4457 case QAbstractSocket::RemoteHostClosedError:
4459 case QAbstractSocket::HostNotFoundError:
4460 QMessageBox::information(NULL, vymName +" Network client",
4461 "The host was not found. Please check the "
4462 "host name and port settings.");
4464 case QAbstractSocket::ConnectionRefusedError:
4465 QMessageBox::information(NULL, vymName + " Network client",
4466 "The connection was refused by the peer. "
4467 "Make sure the fortune server is running, "
4468 "and check that the host name and port "
4469 "settings are correct.");
4472 QMessageBox::information(NULL, vymName + " Network client",
4473 QString("The following error occurred: %1.")
4474 .arg(clientSocket->errorString()));
4481 void VymModel::selectMapSelectionColor()
4483 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4484 setSelectionColor (col);
4487 void VymModel::setSelectionColorInt (QColor col)
4489 if ( !col.isValid() ) return;
4491 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4492 QString("setSelectionColor (%1)").arg(col.name()),
4493 QString("Set color of selection box to %1").arg(col.name())
4496 mapEditor->setSelectionColor (col);
4500 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4502 cout << "VymModel::changeSelection (";
4503 if (!newsel.indexes().isEmpty() )
4504 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4506 if (!oldsel.indexes().isEmpty() )
4507 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4512 void VymModel::updateSelection(const QItemSelection &newsel)
4514 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4515 ensureSelectionVisible();
4519 void VymModel::updateSelection()
4521 QItemSelection newsel=selModel->selection();
4522 updateSelection (newsel);
4525 void VymModel::setSelectionColor(QColor col)
4527 if ( !col.isValid() ) return;
4529 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4530 QString("setSelectionColor (%1)").arg(col.name()),
4531 QString("Set color of selection box to %1").arg(col.name())
4533 setSelectionColorInt (col);
4536 QColor VymModel::getSelectionColor()
4538 return mapEditor->getSelectionColor();
4541 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4544 for (int i=0;i<rootItem->childCount();i++)
4545 rootItem->child(i)->setHideTmp (mode);
4547 // FIXME-3 needed? scene()->update();
4551 QRectF VymModel::getTotalBBox() //FIXME-2
4555 for (int i=0;i<rootItem->branchCount(); i++)
4556 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4561 //////////////////////////////////////////////
4562 // Selection related
4563 //////////////////////////////////////////////
4565 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4570 QItemSelectionModel* VymModel::getSelectionModel()
4575 void VymModel::setSelectionBlocked (bool b)
4580 selection.unblock();
4583 bool VymModel::isSelectionBlocked()
4585 return selection.isBlocked();
4588 bool VymModel::select ()
4590 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4592 TreeItem *item = getItem (index);
4593 return select (item->getLMO() );
4596 bool VymModel::select (const QString &s)
4598 TreeItem *ti=findBySelectString(s);
4608 bool VymModel::select (LinkableMapObj *lmo)
4610 QItemSelection oldsel=selModel->selection();
4613 return select (lmo->getTreeItem() );
4618 bool VymModel::select (TreeItem *ti)
4622 QModelIndex ix=index(ti);
4623 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4624 ti->setLastSelectedBranch();
4630 void VymModel::unselect()
4632 selModel->clearSelection();
4635 void VymModel::reselect()
4637 selection.reselect();
4640 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4642 LinkableMapObj *lmo=getSelectedLMO();
4643 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4646 void VymModel::emitNoteHasChanged (TreeItem *ti)
4648 QModelIndex ix=index(ti);
4649 emit (noteHasChanged (ix) );
4652 void VymModel::emitDataHasChanged (TreeItem *ti)
4654 QModelIndex ix=index(ti);
4655 emit (dataHasChanged (ix) );
4659 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4662 if (selection.select(lmo))
4664 //selection.update();
4665 sendSelection (); // FIXME-4 VM use signal
4669 void VymModel::selectInt (TreeItem *ti)
4671 if (selection.select(lmo))
4673 //selection.update();
4674 sendSelection (); // FIXME-4 VM use signal
4679 void VymModel::selectNextBranchInt()
4681 BranchItem *bi=getSelectedBranchItem();
4684 TreeItem *pi=bi->parent();
4688 if (i<pi->branchCount() )
4690 // select previous branch with same parent
4692 select (pi->getBranchNum(i));
4700 void VymModel::selectPrevBranchInt()
4703 BranchItem *bi=getSelectedBranchItem();
4706 BranchItem *pi=(BranchItem*)bi->parent();
4712 // select previous branch with same parent
4713 bi=pi->getBranchNum(i-1);
4718 while (bi->branchCount() >0)
4719 bi=bi->getLastBranch();
4722 // Try to select last branch in parent pi2 previous to own parent pi
4724 TreeItem *pi2=pi->parent();
4735 void VymModel::selectAboveBranchInt()
4737 BranchItem *bi=getSelectedBranchItem();
4740 BranchItem *newbi=NULL;
4741 BranchItem *pi=(BranchItem*)bi->parent();
4745 // goto previous branch with same parent
4746 newbi=pi->getBranchNum(i-1);
4747 while (newbi->branchCount() >0 )
4748 newbi=newbi->getLastBranch();
4752 if (newbi==rootItem)
4753 // already at top branch (resp. mapcenter)
4759 void VymModel::selectBelowBranchInt()
4761 BranchItem *bi=getSelectedBranchItem();
4764 BranchItem *newbi=NULL;
4766 if (bi->branchCount() >0)
4767 newbi=bi->getFirstBranch();
4774 pi=(BranchItem*)bi->parent();
4776 if (pi->branchCount()-1 > i)
4778 newbi=(BranchItem*)pi->getBranchNum(i+1);
4783 // look for siblings of myself
4784 // or parent, or parent of parent...
4795 void VymModel::selectUpperBranch()
4797 if (selection.isBlocked() ) return;
4799 BranchItem *bi=getSelectedBranchItem();
4800 if (bi && bi->isBranchLikeType())
4801 selectAboveBranchInt();
4804 void VymModel::selectLowerBranch()
4806 if (selection.isBlocked() ) return;
4808 BranchItem *bi=getSelectedBranchItem();
4809 if (bi && bi->isBranchLikeType())
4810 selectBelowBranchInt();
4814 void VymModel::selectLeftBranch()
4816 if (selection.isBlocked() ) return;
4818 QItemSelection oldsel=selModel->selection();
4821 BranchItem *selbi=getSelectedBranchItem();
4822 TreeItem::Type type=selbi->getType();
4825 if (type == TreeItem::MapCenter)
4827 QModelIndex ix=index(selbi);
4828 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4831 par=(BranchItem*)selbi->parent();
4832 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4835 if (type == TreeItem::Branch ||
4836 type == TreeItem::Image)
4838 QModelIndex ix=index (selbi->parent());
4839 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4844 if (type == TreeItem::Branch )
4846 cout << "VM::selLeft\n";
4847 selectLastSelectedBranch();
4855 void VymModel::selectRightBranch()
4857 if (selection.isBlocked() ) return;
4859 QItemSelection oldsel=selModel->selection();
4862 BranchItem *selbi=getSelectedBranchItem();
4863 TreeItem::Type type=selbi->getType();
4866 if (type==TreeItem::MapCenter)
4868 QModelIndex ix=index(selbi);
4869 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4872 par=(BranchItem*)selbi->parent();
4873 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4876 if ( type== TreeItem::Branch )
4878 selectLastSelectedBranch();
4884 if (type == TreeItem::Branch ||
4885 type == TreeItem::Image)
4887 cout << "VM::selRight\n";
4888 QModelIndex ix=index(selbi->parent());
4889 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4896 void VymModel::selectFirstBranch()
4898 TreeItem *ti=getSelectedBranchItem();
4901 TreeItem *par=ti->parent();
4903 TreeItem *ti2=par->getFirstBranch();
4907 ensureSelectionVisible();
4913 void VymModel::selectLastBranch()
4915 TreeItem *ti=getSelectedBranchItem();
4918 TreeItem *par=ti->parent();
4920 TreeItem *ti2=par->getLastBranch();
4924 ensureSelectionVisible();
4930 void VymModel::selectLastSelectedBranch()
4932 TreeItem *ti=getSelectedBranchItem();
4935 ti=ti->getLastSelectedBranch();
4936 if (ti) select (ti);
4940 void VymModel::selectParent()
4942 TreeItem *ti=getSelectedItem();
4950 ensureSelectionVisible();
4955 TreeItem::Type VymModel::selectionType()
4957 QModelIndexList list=selModel->selectedIndexes();
4958 if (list.isEmpty()) return TreeItem::Undefined;
4959 TreeItem *ti = getItem (list.first() );
4960 return ti->getType();
4964 LinkableMapObj* VymModel::getSelectedLMO()
4966 QModelIndexList list=selModel->selectedIndexes();
4967 if (!list.isEmpty() )
4969 TreeItem *ti = getItem (list.first() );
4970 TreeItem::Type type=ti->getType();
4971 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4973 return ti->getLMO();
4979 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4981 TreeItem *ti = getSelectedBranchItem();
4983 return (BranchObj*)ti->getLMO();
4988 BranchItem* VymModel::getSelectedBranchItem()
4990 QModelIndexList list=selModel->selectedIndexes();
4991 if (!list.isEmpty() )
4993 TreeItem *ti = getItem (list.first() );
4994 TreeItem::Type type=ti->getType();
4995 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4996 return (BranchItem*)ti;
5001 MapCenterItem* VymModel::getSelectedMapCenterItem()
5003 QModelIndexList list=selModel->selectedIndexes();
5004 if (!list.isEmpty() )
5006 TreeItem *ti = getItem (list.first() );
5007 TreeItem::Type type=ti->getType();
5008 if (ti->getType()==TreeItem::MapCenter)
5009 return (MapCenterItem*)ti;
5014 TreeItem* VymModel::getSelectedItem()
5016 QModelIndexList list=selModel->selectedIndexes();
5017 if (!list.isEmpty() )
5018 return getItem (list.first() );
5023 QModelIndex VymModel::getSelectedIndex()
5025 QModelIndexList list=selModel->selectedIndexes();
5026 if (list.isEmpty() )
5027 return QModelIndex();
5029 return list.first();
5032 FloatImageObj* VymModel::getSelectedFloatImage()
5034 return selection.getFloatImage();
5037 QString VymModel::getSelectString ()
5039 LinkableMapObj *lmo=getSelectedLMO();
5041 return getSelectString(lmo);
5046 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5048 if (!lmo) return QString();
5049 return getSelectString (lmo->getTreeItem() );
5052 QString VymModel::getSelectString (TreeItem *ti)
5056 if (ti->getType() == TreeItem::Branch ||
5057 ti->getType() == TreeItem::MapCenter)
5059 TreeItem *par=ti->parent();
5062 if (ti->depth() ==1)
5063 // Mainbranch, return
5064 s= "bo:" + QString("%1").arg(ti->num() );
5066 // Branch, call myself recursively
5067 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5071 int i=rootItem->num(ti);
5072 if (i>=0) s=QString("mc:%1").arg(i);