further speedup during load. positions of branches are saved (again)
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 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
449 QXmlInputSource source( file);
450 QXmlSimpleReader reader;
451 reader.setContentHandler( handler );
452 reader.setErrorHandler( handler );
453 handler->setModel ( this);
456 // We need to set the tmpDir in order to load files with rel. path
461 tmpdir=fname.left(fname.findRev("/",-1));
462 handler->setTmpDir (tmpdir);
463 handler->setInputFile (file.name());
464 handler->setLoadMode (lmode);
465 bool ok = reader.parse( source );
466 blockReposition=false;
467 blockSaveState=blockSaveStateOrg;
468 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
472 reposition(); // FIXME-2 VM reposition the view instead...
479 autosaveTimer->stop();
482 // Reset timestamp to check for later updates of file
483 fileChangedTime=QFileInfo (destPath).lastModified();
486 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
487 tr( handler->errorProtocol() ) );
489 // Still return "success": the map maybe at least
490 // partially read by the parser
495 removeDir (QDir(tmpZipDir));
497 // Restore original zip state
504 ErrorCode VymModel::save (const SaveMode &savemode)
508 QString safeFilePath;
510 ErrorCode err=success;
514 mapFileName=mapName+".xml";
516 // use name given by user, even if he chooses .doc
517 mapFileName=fileName;
519 // Look, if we should zip the data:
522 QMessageBox mb( vymName,
523 tr("The map %1\ndid not use the compressed "
524 "vym file format.\nWriting it uncompressed will also write images \n"
525 "and flags and thus may overwrite files in the "
526 "given directory\n\nDo you want to write the map").arg(filePath),
527 QMessageBox::Warning,
528 QMessageBox::Yes | QMessageBox::Default,
530 QMessageBox::Cancel | QMessageBox::Escape);
531 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
532 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
533 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
536 case QMessageBox::Yes:
537 // save compressed (default file format)
540 case QMessageBox::No:
544 case QMessageBox::Cancel:
551 // First backup existing file, we
552 // don't want to add to old zip archives
556 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
558 QString backupFileName(destPath + "~");
559 QFile backupFile(backupFileName);
560 if (backupFile.exists() && !backupFile.remove())
562 QMessageBox::warning(0, tr("Save Error"),
563 tr("%1\ncould not be removed before saving").arg(backupFileName));
565 else if (!f.rename(backupFileName))
567 QMessageBox::warning(0, tr("Save Error"),
568 tr("%1\ncould not be renamed before saving").arg(destPath));
575 // Create temporary directory for packing
577 tmpZipDir=makeTmpDir (ok,"vym-zip");
580 QMessageBox::critical( 0, tr( "Critical Load Error" ),
581 tr("Couldn't create temporary directory before save\n"));
585 safeFilePath=filePath;
586 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
589 // Create mapName and fileDir
590 makeSubDirs (fileDir);
593 if (savemode==CompleteMap || selection.isEmpty())
596 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
599 autosaveTimer->stop();
604 if (selectionType()==TreeItem::Image)
607 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
608 // TODO take care of multiselections
611 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
614 qWarning ("ME::saveStringToDisk failed!");
620 if (err==success) err=zipDir (tmpZipDir,destPath);
623 removeDir (QDir(tmpZipDir));
625 // Restore original filepath outside of tmp zip dir
626 setFilePath (safeFilePath);
630 fileChangedTime=QFileInfo (destPath).lastModified();
634 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
636 QString pathDir=path.left(path.findRev("/"));
642 // We need to parse saved XML data
643 parseVYMHandler handler;
644 QXmlInputSource source( file);
645 QXmlSimpleReader reader;
646 reader.setContentHandler( &handler );
647 reader.setErrorHandler( &handler );
648 handler.setModel ( this);
649 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
650 if (undoSel.isEmpty())
654 handler.setLoadMode (NewMap);
658 handler.setLoadMode (ImportReplace);
660 blockReposition=true;
661 bool ok = reader.parse( source );
662 blockReposition=false;
665 // This should never ever happen
666 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
667 handler.errorProtocol());
670 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
673 void VymModel::addMapInsertInt (const QString &path, int pos)
675 /* FIXME-2 addMapInsertInt not ported yet
676 BranchObj *sel=getSelectedBranch();
679 QString pathDir=path.left(path.findRev("/"));
685 // We need to parse saved XML data
686 parseVYMHandler handler;
687 QXmlInputSource source( file);
688 QXmlSimpleReader reader;
689 reader.setContentHandler( &handler );
690 reader.setErrorHandler( &handler );
691 handler.setModel (this);
692 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
693 handler.setLoadMode (ImportAdd);
694 blockReposition=true;
695 bool ok = reader.parse( source );
696 blockReposition=false;
699 // This should never ever happen
700 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
701 handler.errorProtocol());
703 if (sel->getDepth()>0)
704 sel->getLastBranch()->linkTo (sel,pos);
706 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
711 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
713 TreeItem *fi=createImage();
716 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
724 void VymModel::loadFloatImage () // FIXME-2
727 BranchObj *bo=getSelectedBranch();
731 Q3FileDialog *fd=new Q3FileDialog( NULL);
732 fd->setMode (Q3FileDialog::ExistingFiles);
733 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
734 ImagePreview *p =new ImagePreview (fd);
735 fd->setContentsPreviewEnabled( TRUE );
736 fd->setContentsPreview( p, p );
737 fd->setPreviewMode( Q3FileDialog::Contents );
738 fd->setCaption(vymName+" - " +tr("Load image"));
739 fd->setDir (lastImageDir);
742 if ( fd->exec() == QDialog::Accepted )
744 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
745 lastImageDir=QDir (fd->dirPath());
748 for (int j=0; j<fd->selectedFiles().count(); j++)
750 s=fd->selectedFiles().at(j);
751 fio=loadFloatImageInt (s);
754 (LinkableMapObj*)fio,
757 QString ("loadImage (%1)").arg(s ),
758 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
761 // TODO loadFIO error handling
762 qWarning ("Failed to load "+s);
771 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
776 void VymModel::saveFloatImage ()
778 FloatImageObj *fio=selection.getFloatImage();
781 QFileDialog *fd=new QFileDialog( NULL);
782 fd->setFilters (imageIO.getFilters());
783 fd->setCaption(vymName+" - " +tr("Save image"));
784 fd->setFileMode( QFileDialog::AnyFile );
785 fd->setDirectory (lastImageDir);
786 // fd->setSelection (fio->getOriginalFilename());
790 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
792 fn=fd->selectedFiles().at(0);
793 if (QFile (fn).exists() )
795 QMessageBox mb( vymName,
796 tr("The file %1 exists already.\n"
797 "Do you want to overwrite it?").arg(fn),
798 QMessageBox::Warning,
799 QMessageBox::Yes | QMessageBox::Default,
800 QMessageBox::Cancel | QMessageBox::Escape,
801 QMessageBox::NoButton );
803 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
804 mb.setButtonText( QMessageBox::No, tr("Cancel"));
807 case QMessageBox::Yes:
810 case QMessageBox::Cancel:
817 saveFloatImageInt (fio,fd->selectedFilter(),fn );
824 void VymModel::importDirInt(BranchObj *dst, QDir d)
826 /* FIXME-2 importDirInt not ported yet
827 BranchObj *bo=getSelectedBranch();
830 // Traverse directories
831 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
832 QFileInfoList list = d.entryInfoList();
835 for (int i = 0; i < list.size(); ++i)
838 if (fi.fileName() != "." && fi.fileName() != ".." )
841 bo=dst->getLastBranch();
842 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
843 bi->setHeading (fi.fileName() ); // FIXME-3 check this
844 bo->setColor (QColor("blue"));
846 if ( !d.cd(fi.fileName()) )
847 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
850 // Recursively add subdirs
857 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
858 list = d.entryInfoList();
860 for (int i = 0; i < list.size(); ++i)
864 bo=dst->getLastBranch();
865 bo->setHeading (fi.fileName() );
866 bo->setColor (QColor("black"));
867 if (fi.fileName().right(4) == ".vym" )
868 bo->setVymLink (fi.filePath());
874 void VymModel::importDirInt (const QString &s) // FIXME-2
877 BranchObj *bo=getSelectedBranch();
880 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
888 void VymModel::importDir() //FIXME-2
891 BranchObj *bo=getSelectedBranch();
895 filters <<"VYM map (*.vym)";
896 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
897 fd->setMode (QFileDialog::DirectoryOnly);
898 fd->setFilters (filters);
899 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
903 if ( fd->exec() == QDialog::Accepted )
905 importDirInt (fd->selectedFile() );
907 //FIXME-3 VM needed? scene()->update();
914 void VymModel::autosave()
919 cout << "VymModel::autosave rejected due to missing filePath\n";
922 QDateTime now=QDateTime().currentDateTime();
924 // Disable autosave, while we have gone back in history
925 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
926 if (redosAvail>0) return;
928 // Also disable autosave for new map without filename
929 if (filePath.isEmpty()) return;
932 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
934 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
935 mainWindow->fileSave (this);
938 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
943 void VymModel::fileChanged()
945 // Check if file on disk has changed meanwhile
946 if (!filePath.isEmpty())
948 QDateTime tmod=QFileInfo (filePath).lastModified();
949 if (tmod>fileChangedTime)
951 // FIXME-2 VM switch to current mapeditor and finish lineedits...
952 QMessageBox mb( vymName,
953 tr("The file of the map on disk has changed:\n\n"
954 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
955 QMessageBox::Question,
957 QMessageBox::Cancel | QMessageBox::Default,
958 QMessageBox::NoButton );
960 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
961 mb.setButtonText( QMessageBox::No, tr("Ignore"));
964 case QMessageBox::Yes:
966 load (filePath,NewMap,fileType);
967 case QMessageBox::Cancel:
968 fileChangedTime=tmod; // allow autosave to overwrite newer file!
974 bool VymModel::isDefault()
979 void VymModel::makeDefault()
985 bool VymModel::hasChanged()
990 void VymModel::setChanged()
993 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
997 latestAddedItem=NULL;
1001 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1004 if (!lmo) return QString("Error: NULL has no name!");
1006 if ((typeid(*lmo) == typeid(BranchObj) ||
1007 typeid(*lmo) == typeid(MapCenterObj)))
1010 s=lmo->getTreeItem()->getHeading();
1011 if (s=="") s="unnamed";
1012 return QString("branch (%1)").arg(s);
1014 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1015 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1016 return QString("Unknown type has no name!");
1020 QString VymModel::getObjectName (const TreeItem *ti)
1023 if (!ti) return QString("Error: NULL has no name!");
1025 if (ti->isBranchLikeType() )
1028 if (s=="") s="unnamed";
1029 return QString("branch (%1)").arg(s);
1031 /* FIXME-2 move floatimage to TreeModel first
1032 if (type==TreeItem::Image)
1033 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1035 return QString("Unknown type has no name!");
1038 void VymModel::redo()
1040 // Can we undo at all?
1041 if (redosAvail<1) return;
1043 bool blockSaveStateOrg=blockSaveState;
1044 blockSaveState=true;
1048 if (undosAvail<stepsTotal) undosAvail++;
1050 if (curStep>stepsTotal) curStep=1;
1051 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1052 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1053 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1054 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1055 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1056 QString version=undoSet.readEntry ("/history/version");
1058 /* TODO Maybe check for version, if we save the history
1059 if (!checkVersion(version))
1060 QMessageBox::warning(0,tr("Warning"),
1061 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1064 // Find out current undo directory
1065 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1069 cout << "VymModel::redo() begin\n";
1070 cout << " undosAvail="<<undosAvail<<endl;
1071 cout << " redosAvail="<<redosAvail<<endl;
1072 cout << " curStep="<<curStep<<endl;
1073 cout << " ---------------------------"<<endl;
1074 cout << " comment="<<comment.toStdString()<<endl;
1075 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1076 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1077 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1078 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1079 cout << " ---------------------------"<<endl<<endl;
1082 // select object before redo
1083 if (!redoSelection.isEmpty())
1084 select (redoSelection);
1087 parseAtom (redoCommand);
1090 blockSaveState=blockSaveStateOrg;
1092 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1093 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1094 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1095 undoSet.writeSettings(histPath);
1097 mainWindow->updateHistory (undoSet);
1100 /* TODO remove testing
1101 cout << "ME::redo() end\n";
1102 cout << " undosAvail="<<undosAvail<<endl;
1103 cout << " redosAvail="<<redosAvail<<endl;
1104 cout << " curStep="<<curStep<<endl;
1105 cout << " ---------------------------"<<endl<<endl;
1111 bool VymModel::isRedoAvailable()
1113 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1119 void VymModel::undo()
1121 // Can we undo at all?
1122 if (undosAvail<1) return;
1124 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1126 bool blockSaveStateOrg=blockSaveState;
1127 blockSaveState=true;
1129 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1130 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1131 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1132 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1133 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1134 QString version=undoSet.readEntry ("/history/version");
1136 /* TODO Maybe check for version, if we save the history
1137 if (!checkVersion(version))
1138 QMessageBox::warning(0,tr("Warning"),
1139 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1142 // Find out current undo directory
1143 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1145 // select object before undo
1146 if (!undoSelection.isEmpty())
1147 select (undoSelection);
1151 cout << "VymModel::undo() begin\n";
1152 cout << " undosAvail="<<undosAvail<<endl;
1153 cout << " redosAvail="<<redosAvail<<endl;
1154 cout << " curStep="<<curStep<<endl;
1155 cout << " ---------------------------"<<endl;
1156 cout << " comment="<<comment.toStdString()<<endl;
1157 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1158 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1159 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1160 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1161 cout << " ---------------------------"<<endl<<endl;
1163 parseAtom (undoCommand);
1168 if (curStep<1) curStep=stepsTotal;
1172 blockSaveState=blockSaveStateOrg;
1173 /* TODO remove testing
1174 cout << "VymModel::undo() end\n";
1175 cout << " undosAvail="<<undosAvail<<endl;
1176 cout << " redosAvail="<<redosAvail<<endl;
1177 cout << " curStep="<<curStep<<endl;
1178 cout << " ---------------------------"<<endl<<endl;
1181 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1182 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1183 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1184 undoSet.writeSettings(histPath);
1186 mainWindow->updateHistory (undoSet);
1189 ensureSelectionVisible();
1192 bool VymModel::isUndoAvailable()
1194 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1200 void VymModel::gotoHistoryStep (int i)
1202 // Restore variables
1203 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1204 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1206 if (i<0) i=undosAvail+redosAvail;
1208 // Clicking above current step makes us undo things
1211 for (int j=0; j<undosAvail-i; j++) undo();
1214 // Clicking below current step makes us redo things
1216 for (int j=undosAvail; j<i; j++)
1218 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1222 // And ignore clicking the current row ;-)
1226 QString VymModel::getHistoryPath()
1228 QString histName(QString("history-%1").arg(curStep));
1229 return (tmpMapDir+"/"+histName);
1232 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1234 sendData(redoCom); //FIXME-3 testing
1239 if (blockSaveState) return;
1241 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1243 // Find out current undo directory
1244 if (undosAvail<stepsTotal) undosAvail++;
1246 if (curStep>stepsTotal) curStep=1;
1248 QString backupXML="";
1249 QString histDir=getHistoryPath();
1250 QString bakMapPath=histDir+"/map.xml";
1252 // Create histDir if not available
1255 makeSubDirs (histDir);
1257 // Save depending on how much needs to be saved
1259 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1261 QString undoCommand="";
1262 if (savemode==UndoCommand)
1264 undoCommand=undoCom;
1266 else if (savemode==PartOfMap )
1268 undoCommand=undoCom;
1269 undoCommand.replace ("PATH",bakMapPath);
1273 if (!backupXML.isEmpty())
1274 // Write XML Data to disk
1275 saveStringToDisk (bakMapPath,backupXML);
1277 // We would have to save all actions in a tree, to keep track of
1278 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1281 // Write the current state to disk
1282 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1283 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1284 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1285 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1286 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1287 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1288 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1289 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1290 undoSet.setEntry (QString("/history/version"),vymVersion);
1291 undoSet.writeSettings(histPath);
1295 // TODO remove after testing
1296 //cout << " into="<< histPath.toStdString()<<endl;
1297 cout << " stepsTotal="<<stepsTotal<<
1298 ", undosAvail="<<undosAvail<<
1299 ", redosAvail="<<redosAvail<<
1300 ", curStep="<<curStep<<endl;
1301 cout << " ---------------------------"<<endl;
1302 cout << " comment="<<comment.toStdString()<<endl;
1303 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1304 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1305 cout << " redoCom="<<redoCom.toStdString()<<endl;
1306 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1307 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1308 cout << " ---------------------------"<<endl;
1311 mainWindow->updateHistory (undoSet);
1317 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1319 // save the selected part of the map, Undo will replace part of map
1320 QString undoSelection="";
1322 undoSelection=getSelectString(undoSel);
1324 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1325 QString redoSelection="";
1327 redoSelection=getSelectString(undoSel);
1329 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1332 saveState (PartOfMap,
1333 undoSelection, "addMapReplace (\"PATH\")",
1339 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1343 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1346 QString undoSelection=getSelectString (redoSel->parent() );
1347 QString redoSelection=getSelectString(redoSel);
1348 if (redoSel->getType()==TreeItem::Branch)
1350 // save the selected branch of the map, Undo will insert part of map
1351 saveState (PartOfMap,
1352 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1353 redoSelection, "delete ()",
1360 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1362 // "Normal" savestate: save commands, selections and comment
1363 // so just save commands for undo and redo
1364 // and use current selection
1366 QString redoSelection="";
1367 if (redoSel) redoSelection=getSelectString(redoSel);
1368 QString undoSelection="";
1369 if (undoSel) undoSelection=getSelectString(undoSel);
1371 saveState (UndoCommand,
1378 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1380 // "Normal" savestate: save commands, selections and comment
1381 // so just save commands for undo and redo
1382 // and use current selection
1383 saveState (UndoCommand,
1390 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1392 // "Normal" savestate applied to model (no selection needed):
1393 // save commands and comment
1394 saveState (UndoCommand,
1402 QGraphicsScene* VymModel::getScene ()
1407 TreeItem* VymModel::findBySelectString(QString s)
1409 if (s.isEmpty() ) return NULL;
1411 // Old maps don't have multiple mapcenters and don't save full path
1412 if (s.left(2) !="mc")
1415 QStringList parts=s.split (",");
1418 TreeItem *ti=rootItem;
1420 while (!parts.isEmpty() )
1422 typ=parts.first().left(2);
1423 n=parts.first().right(parts.first().length() - 3).toInt();
1424 parts.removeFirst();
1425 if (typ=="mc" || typ=="bo")
1426 ti=ti->getBranchNum (n);
1430 ti=ti->getImageNum (n);
1436 TreeItem* VymModel::findID (const QString &s)
1439 for (int i=0; i<rootItem->branchCount(); i++)
1441 ti=rootItem->getBranchNum(i)->findID (s);
1447 //////////////////////////////////////////////
1449 //////////////////////////////////////////////
1450 void VymModel::setVersion (const QString &s)
1455 void VymModel::setAuthor (const QString &s)
1458 QString ("setMapAuthor (\"%1\")").arg(author),
1459 QString ("setMapAuthor (\"%1\")").arg(s),
1460 QString ("Set author of map to \"%1\"").arg(s)
1465 QString VymModel::getAuthor()
1470 void VymModel::setComment (const QString &s)
1473 QString ("setMapComment (\"%1\")").arg(comment),
1474 QString ("setMapComment (\"%1\")").arg(s),
1475 QString ("Set comment of map")
1480 QString VymModel::getComment ()
1485 QString VymModel::getDate ()
1487 return QDate::currentDate().toString ("yyyy-MM-dd");
1490 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1493 BranchItem *cur=NULL;
1494 BranchItem *prev=NULL;
1505 void VymModel::setHeading(const QString &s)
1507 BranchItem *selbi=getSelectedBranchItem();
1512 "setHeading (\""+selbi->getHeading()+"\")",
1514 "setHeading (\""+s+"\")",
1515 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1516 selbi->setHeading(s );
1517 QModelIndex ix2=index (selbi);
1518 emit (dataChanged ( ix2,ix2));
1519 /* FIXME-3 testing only
1523 // selection.update(); //FIXME-4
1524 ensureSelectionVisible();
1528 BranchItem* VymModel::findText (QString s, bool cs)
1531 QTextDocument::FindFlags flags=0;
1532 if (cs) flags=QTextDocument::FindCaseSensitively;
1535 { // Nothing found or new find process
1537 // nothing found, start again
1541 next (findCurrent,findPrevious,d);
1543 bool searching=true;
1544 bool foundNote=false;
1545 while (searching && !EOFind)
1549 // Searching in Note
1550 if (findCurrent->getNote().contains(s,cs))
1552 select (findCurrent);
1554 if (getSelectedBranch()!=itFind)
1557 ensureSelectionVisible();
1560 if (textEditor->findText(s,flags))
1566 // Searching in Heading
1567 if (searching && findCurrent->getHeading().contains (s,cs) )
1569 select(findCurrent);
1575 if (!next(findCurrent,findPrevious,d) )
1578 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1581 return getSelectedBranchItem();
1586 void VymModel::findReset()
1587 { // Necessary if text to find changes during a find process
1593 void VymModel::setScene (QGraphicsScene *s)
1595 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1596 //init(); // Here we have a mapScene set,
1597 // which is (still) needed to create MapCenters
1600 void VymModel::setURL(const QString &url) //FIXME-2
1603 BranchObj *bo=getSelectedBranch();
1606 QString oldurl=bo->getURL();
1610 QString ("setURL (\"%1\")").arg(oldurl),
1612 QString ("setURL (\"%1\")").arg(url),
1613 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1618 ensureSelectionVisible();
1623 QString VymModel::getURL() //FIXME-2
1626 BranchObj *bo=getSelectedBranch();
1628 return bo->getURL();
1634 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1636 return QStringList();
1639 BranchObj *bo=getSelectedBranch();
1645 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1653 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1655 FloatImageObj *fio=selection.getFloatImage();
1658 TreeItem *dst=findBySelectString (dstString);
1659 if (dst && dst->isBranchLikeType() )
1661 TreeItem *dstPar=dst->parent();
1662 QString parString=getSelectString(dstPar);
1663 QString fioPreSelectString=getSelectString(fio);
1664 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1665 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1667 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1668 fio=((BranchObj*)dst)->getLastFloatImage();
1673 getSelectString(fio),
1674 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1676 QString ("linkTo (\"%1\")").arg(dstString),
1677 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1683 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1686 BranchObj *bo=getSelectedBranch();
1689 QString s=bo->getFrameTypeName();
1690 bo->setFrameType (t);
1691 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1692 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1699 void VymModel::setFrameType(const QString &s) //FIXME-2
1702 BranchObj *bo=getSelectedBranch();
1705 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1706 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1707 bo->setFrameType (s);
1714 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1717 BranchObj *bo=getSelectedBranch();
1720 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1721 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1722 bo->setFramePenColor (c);
1727 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1730 BranchObj *bo=getSelectedBranch();
1733 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1734 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1735 bo->setFrameBrushColor (c);
1739 void VymModel::setFramePadding (const int &i) //FIXME-2
1742 BranchObj *bo=getSelectedBranch();
1745 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1746 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1747 bo->setFramePadding (i);
1754 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1757 BranchObj *bo=getSelectedBranch();
1760 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1761 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1762 bo->setFrameBorderWidth (i);
1769 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1772 BranchObj *bo=getSelectedBranch();
1775 QString u= b ? "false" : "true";
1776 QString r=!b ? "false" : "true";
1780 QString("setIncludeImagesVertically (%1)").arg(u),
1782 QString("setIncludeImagesVertically (%1)").arg(r),
1783 QString("Include images vertically in %1").arg(getObjectName(bo))
1785 bo->setIncludeImagesVer(b);
1790 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1793 BranchObj *bo=getSelectedBranch();
1796 QString u= b ? "false" : "true";
1797 QString r=!b ? "false" : "true";
1801 QString("setIncludeImagesHorizontally (%1)").arg(u),
1803 QString("setIncludeImagesHorizontally (%1)").arg(r),
1804 QString("Include images horizontally in %1").arg(getObjectName(bo))
1806 bo->setIncludeImagesHor(b);
1812 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1815 LinkableMapObj *sel=getSelectedLMO();
1817 (selectionType() == TreeItem::Branch ||
1818 selectionType() == TreeItem::MapCenter ||
1819 selectionType() == TreeItem::Image ))
1821 QString u= b ? "false" : "true";
1822 QString r=!b ? "false" : "true";
1826 QString("setHideLinkUnselected (%1)").arg(u),
1828 QString("setHideLinkUnselected (%1)").arg(r),
1829 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1831 sel->setHideLinkUnselected(b);
1836 void VymModel::setHideExport(bool b)
1838 BranchItem *bi=getSelectedBranchItem();
1841 bi->setHideInExport (b);
1842 QString u= b ? "false" : "true";
1843 QString r=!b ? "false" : "true";
1847 QString ("setHideExport (%1)").arg(u),
1849 QString ("setHideExport (%1)").arg(r),
1850 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1854 // selection.update();
1855 // FIXME-3 VM needed? scene()->update();
1859 void VymModel::toggleHideExport()
1861 BranchItem *selbi=getSelectedBranchItem();
1863 setHideExport ( !selbi->hideInExport() );
1867 void VymModel::copy() //FIXME-2
1870 LinkableMapObj *sel=getSelectedLMO();
1872 (selectionType() == TreeItem::Branch ||
1873 selectionType() == TreeItem::MapCenter ||
1874 selectionType() == TreeItem::Image ))
1876 if (redosAvail == 0)
1879 QString s=getSelectString(sel);
1880 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1881 curClipboard=curStep;
1884 // Copy also to global clipboard, because we are at last step in history
1885 QString bakMapName(QString("history-%1").arg(curStep));
1886 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1887 copyDir (bakMapDir,clipboardDir );
1889 clipboardEmpty=false;
1896 void VymModel::pasteNoSave(const int &n) //FIXME-2
1899 bool old=blockSaveState;
1900 blockSaveState=true;
1901 bool zippedOrg=zipped;
1902 if (redosAvail > 0 || n!=0)
1904 // Use the "historical" buffer
1905 QString bakMapName(QString("history-%1").arg(n));
1906 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1907 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1909 // Use the global buffer
1910 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1916 void VymModel::paste() //FIXME-2
1919 BranchObj *sel=getSelectedBranch();
1922 saveStateChangingPart(
1925 QString ("paste (%1)").arg(curClipboard),
1926 QString("Paste to %1").arg( getObjectName(sel))
1934 void VymModel::cut() //FIXME-2
1937 LinkableMapObj *sel=getSelectedLMO();
1938 if ( sel && (selectionType() == TreeItem::Branch ||
1939 selectionType()==TreeItem::MapCenter ||
1940 selectionType()==TreeItem::Image))
1943 /* No savestate! savestate is called in cutNoSave
1944 saveStateChangingPart(
1948 QString("Cut %1").arg(getObjectName(sel ))
1958 void VymModel::moveBranchUp() //FIXME-2
1961 BranchObj* bo=getSelectedBranch();
1965 if (!bo->canMoveBranchUp()) return;
1966 par=(BranchObj*)(bo->getParObj());
1967 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1968 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1970 //FIXME-3 VM needed? scene()->update();
1972 ensureSelectionVisible();
1977 void VymModel::moveBranchDown() //FIXME-2
1980 BranchObj* bo=getSelectedBranch();
1984 if (!bo->canMoveBranchDown()) return;
1985 par=(BranchObj*)(bo->getParObj());
1986 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1987 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1989 //FIXME-3 VM needed? scene()->update();
1991 ensureSelectionVisible();
1996 void VymModel::sortChildren() // FIXME-2 not implemented yet
1999 BranchObj* bo=getSelectedBranch();
2002 if(treeItem->branchCount()>1)
2004 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
2007 ensureSelectionVisible();
2013 MapCenterItem* VymModel::createMapCenter()
2015 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
2020 BranchItem* VymModel::createBranch()
2022 return addNewBranchInt (-2);
2025 TreeItem* VymModel::createImage() //FIXME-2
2028 BranchObj *bo=getSelectedBranch();
2031 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
2034 QList<QVariant> cData;
2035 cData << "VM:createImage" << "undef"<<"undef";
2036 TreeItem *parti=bo->getTreeItem();
2037 TreeItem *ti=new TreeItem (cData,parti);
2038 ti->setLMO (newfio);
2039 ti->setType (TreeItem::Image);
2040 parti->appendChild (ti);
2044 newfio->setTreeItem (ti);
2045 select (newfio); // FIXME-2 VM really needed here?
2053 MapCenterItem* VymModel::addMapCenter ()
2055 MapCenterItem *mci=addMapCenter (contextPos);
2056 //FIXME-3 selection.select (mco);
2058 ensureSelectionVisible();
2063 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2064 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2069 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2073 QModelIndex parix=index(rootItem);
2075 int n=rootItem->branchCount();
2077 emit (layoutAboutToBeChanged() );
2078 beginInsertRows (parix,n,n+1);
2080 QList<QVariant> cData;
2081 cData << "VM:addMapCenter" << "undef"<<"undef";
2082 MapCenterItem *mci=new MapCenterItem (cData);
2083 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2084 rootItem->appendChild (mci);
2087 emit (newChildObject (parix));
2088 emit (layoutChanged() );
2091 BranchObj *newbo=mci->createMapObj(mapScene);
2095 if (!mci->getHeading().isEmpty() )
2097 newbo->updateHeading();
2098 newbo->setColor (headingColor);
2102 //newbo->updateLink(); //FIXME-3
2105 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2106 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2107 mci->setLMO (mapCenter);
2108 mapCenter->updateHeading();
2109 mapCenter->move (absPos);
2110 mapCenter->setVisibility (true);
2111 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2116 BranchItem* VymModel::addNewBranchInt(int num)
2118 // Depending on pos:
2119 // -3 insert in children of parent above selection
2120 // -2 add branch to selection
2121 // -1 insert in children of parent below selection
2122 // 0..n insert in children of parent at pos
2123 BranchObj *newbo=NULL;
2124 BranchObj *bo=getSelectedBranchObj(); //FIXME-2
2125 BranchItem *bi=getSelectedBranchItem();
2131 QList<QVariant> cData;
2132 cData << "new" << "undef"<<"undef";
2134 BranchItem *parbi=bi;
2135 QModelIndex parix=index(parbi);
2136 int n=parbi->childCount();
2138 emit (layoutAboutToBeChanged() );
2139 beginInsertRows (parix,n,n+1); //FIXME-1 check if n is correct: should be index below _last_ branch...
2140 bi=new BranchItem (cData);
2141 bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2143 parbi->appendChild (bi);
2145 emit (newChildObject (parix));
2146 emit (layoutChanged() );
2148 // save scroll state. If scrolled, automatically select
2149 // new branch in order to tmp unscroll parent...
2150 newbo=bi->createMapObj(mapScene);
2156 bo=(BranchObj*)bo->getParObj();
2157 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2163 bo=(BranchObj*)bo->getParObj();
2164 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2171 BranchItem* VymModel::addNewBranch(int pos)
2173 // Different meaning than num in addNewBranchInt!
2177 BranchItem *newbi=NULL;
2178 BranchItem *selbi=getSelectedBranchItem();
2182 // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2184 newbi=addNewBranchInt (pos-2);
2192 QString ("addBranch (%1)").arg(pos),
2193 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2196 // selection.update(); FIXME-3
2197 latestAddedItem=newbi;
2198 // In Network mode, the client needs to know where the new branch is,
2199 // so we have to pass on this information via saveState.
2200 // TODO: Get rid of this positioning workaround
2201 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2202 sendData ("selectLatestAdded ()");
2203 sendData (QString("move %1").arg(ps));
2212 BranchItem* VymModel::addNewBranchBefore() //FIXME-2
2215 BranchObj *newbo=NULL;
2216 BranchObj *bo = getSelectedBranch();
2217 if (bo && selectionType()==TreeItem::Branch)
2218 // We accept no MapCenterObj here, so we _have_ a parent
2220 QPointF p=bo->getRelPos();
2223 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2225 // add below selection
2226 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2230 newbo->move2RelPos (p);
2232 // Move selection to new branch
2233 bo->linkTo (newbo,-1);
2235 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2236 QString ("Add branch before %1").arg(getObjectName(bo)));
2239 // selection.update(); FIXME-3
2242 latestSelectionString=selection.getSelectString();
2248 BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2252 emit (layoutAboutToBeChanged() );
2253 BranchItem *branchpi=(BranchItem*)branch->parent();
2254 // Remove at current position
2255 int n=branch->childNum();
2256 beginRemoveRows (index(branchpi),n,n);
2257 branchpi->removeChild (n);
2260 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2262 // Append as last branch to dst
2263 if (dst->branchCount()==0)
2266 n=dst->getFirstBranch()->childNumber();
2267 beginInsertRows (index(dst),n+pos,n+pos);
2268 dst->insertBranch (pos,branch);
2271 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2272 emit (layoutChanged() );
2277 void VymModel::deleteSelection()
2279 BranchItem *selbi=getSelectedBranchItem();
2283 TreeItem *pi=selbi->parent();
2284 QModelIndex parentIndex=index(pi);
2286 if (selbi->isBranchLikeType() )
2289 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2291 emit (layoutAboutToBeChanged() );
2293 int n=selbi->childNum();
2294 beginRemoveRows (parentIndex,n,n);
2295 removeRows (n,1,parentIndex);
2298 ensureSelectionVisible();
2301 emit (layoutChanged() );
2304 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2309 BranchObj* par=(BranchObj*)fio->getParObj();
2310 saveStateChangingPart(
2314 QString("Delete %1").arg(getObjectName(fio))
2317 par->removeFloatImage(fio);
2320 ensureSelectionVisible();
2326 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2330 BranchObj *bo=getSelectedBranch();
2334 par=(BranchObj*)(bo->getParObj());
2336 // Don't use this on mapcenter
2339 // Check if we have childs at all to keep
2340 if (bo->getTreeItem()->branchCount()==0)
2346 QPointF p=bo->getRelPos();
2347 saveStateChangingPart(
2350 "deleteKeepChildren ()",
2351 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2354 QString sel=getSelectString(bo);
2356 par->removeBranchHere(bo);
2359 getSelectedBranch()->move2RelPos (p);
2364 void VymModel::deleteChildren() //FIXME-2 VM still missing
2368 BranchObj *bo=getSelectedBranch();
2371 saveStateChangingPart(
2374 "deleteChildren ()",
2375 QString( "Remove children of branch %1").arg(getObjectName(bo))
2377 bo->removeChildren();
2383 bool VymModel::scrollBranch(BranchItem *bi)
2387 if (bi->isScrolled()) return false;
2388 if (bi->branchCount()==0) return false;
2389 if (bi->depth()==0) return false;
2393 /* FIXME-3 no savestate yet
2396 QString ("%1 ()").arg(u),
2398 QString ("%1 ()").arg(r),
2399 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2403 //selection.update();
2404 // FIXME-3 VM needed? scene()->update();
2410 bool VymModel::unscrollBranch(BranchItem *bi)
2414 if (bi->isScrolled()) return false;
2415 if (bi->branchCount()==0) return false;
2416 if (bi->depth()==0) return false;
2421 /* FIXME-3 no savestate yet
2424 QString ("%1 ()").arg(u),
2426 QString ("%1 ()").arg(r),
2427 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2431 // selection.update();
2432 // FIXME-3 VM needed? scene()->update();
2438 void VymModel::toggleScroll()
2440 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2441 if (bi && bi->getType()==TreeItem::Branch )
2443 if (bi->isScrolled())
2444 unscrollBranch (bi);
2450 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2454 BranchObj *bo=getSelectedBranch();
2460 if (bo->isScrolled()) unscrollBranch (bo);
2467 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2470 BranchObj *bo=getSelectedBranch();
2473 FloatImageObj *fio=bo->addFloatImage();
2475 fio->setOriginalFilename("No original filename (image added by dropevent)");
2476 QString s=getSelectString(bo);
2477 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2478 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2480 // FIXME-3 VM needed? scene()->update();
2486 void VymModel::colorBranch (QColor c) //FIXME-2
2489 BranchObj *bo=getSelectedBranch();
2494 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2496 QString ("colorBranch (\"%1\")").arg(c.name()),
2497 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2499 bo->setColor(c); // color branch
2504 void VymModel::colorSubtree (QColor c) //FIXME-2
2507 BranchObj *bo=getSelectedBranch();
2510 saveStateChangingPart(
2513 QString ("colorSubtree (\"%1\")").arg(c.name()),
2514 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2516 bo->setColorSubtree (c); // color links, color children
2521 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2524 BranchObj *bo=getSelectedBranch();
2525 if (bo) return bo->getColor();
2527 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2534 void VymModel::editURL() //FIXME-2
2537 BranchObj *bo=getSelectedBranch();
2541 QString text = QInputDialog::getText(
2542 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2543 bo->getURL(), &ok, NULL);
2545 // user entered something and pressed OK
2551 void VymModel::editLocalURL() //FIXME-2
2554 BranchObj *bo=getSelectedBranch();
2557 QStringList filters;
2558 filters <<"All files (*)";
2559 filters << tr("Text","Filedialog") + " (*.txt)";
2560 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2561 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2562 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2563 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2564 fd->setFilters (filters);
2565 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2566 fd->setDirectory (lastFileDir);
2567 if (! bo->getVymLink().isEmpty() )
2568 fd->selectFile( bo->getURL() );
2571 if ( fd->exec() == QDialog::Accepted )
2573 lastFileDir=QDir (fd->directory().path());
2574 setURL (fd->selectedFile() );
2581 void VymModel::editHeading2URL() //FIXME-2
2584 BranchObj *bo=getSelectedBranch();
2586 setURL (bo->getHeading());
2590 void VymModel::editBugzilla2URL() //FIXME-2
2593 BranchObj *bo=getSelectedBranch();
2596 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2602 void VymModel::editFATE2URL() //FIXME-2
2605 BranchObj *bo=getSelectedBranch();
2608 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2611 "setURL (\""+bo->getURL()+"\")",
2613 "setURL (\""+url+"\")",
2614 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2622 void VymModel::editVymLink()
2624 BranchItem *bi=getSelectedBranchItem();
2627 QStringList filters;
2628 filters <<"VYM map (*.vym)";
2629 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2630 fd->setFilters (filters);
2631 fd->setCaption(vymName+" - " +tr("Link to another map"));
2632 fd->setDirectory (lastFileDir);
2633 if (! bi->getVymLink().isEmpty() )
2634 fd->selectFile( bi->getVymLink() );
2638 if ( fd->exec() == QDialog::Accepted )
2640 lastFileDir=QDir (fd->directory().path());
2643 "setVymLink (\""+bi->getVymLink()+"\")",
2645 "setVymLink (\""+fd->selectedFile()+"\")",
2646 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2648 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2653 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2655 // Internal function, no saveState needed
2656 BranchItem *bi=getSelectedBranchItem();
2659 bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO
2662 //selection.update();
2663 ensureSelectionVisible();
2667 void VymModel::deleteVymLink()
2669 BranchItem *bi=getSelectedBranchItem();
2674 "setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO
2677 "setVymLink (\"\")",
2678 QString("Unset vymlink of %1").arg(getObjectName(bi))
2680 bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO
2683 // FIXME-3 VM needed? scene()->update();
2687 QString VymModel::getVymLink()
2689 BranchItem *bi=getSelectedBranchItem();
2691 return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here...
2697 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2699 return QStringList();
2702 BranchObj *bo=getSelectedBranch();
2708 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2717 void VymModel::followXLink(int i) // FIXME-2
2721 BranchObj *bo=getSelectedBranch();
2724 bo=bo->XLinkTargetAt(i);
2727 selection.select(bo);
2728 ensureSelectionVisible();
2734 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2738 BranchObj *bo=getSelectedBranch();
2741 XLinkObj *xlo=bo->XLinkAt(i);
2744 EditXLinkDialog dia;
2746 dia.setSelection(bo);
2747 if (dia.exec() == QDialog::Accepted)
2749 if (dia.useSettingsGlobal() )
2751 setMapDefXLinkColor (xlo->getColor() );
2752 setMapDefXLinkWidth (xlo->getWidth() );
2754 if (dia.deleteXLink())
2755 bo->deleteXLinkAt(i);
2766 //////////////////////////////////////////////
2768 //////////////////////////////////////////////
2770 void VymModel::parseAtom(const QString &atom)
2772 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2773 TreeItem* selti=getSelectedItem();
2774 BranchItem *selbi=getSelectedBranchItem();
2780 // Split string s into command and parameters
2781 parser.parseAtom (atom);
2782 QString com=parser.getCommand();
2784 // External commands
2785 /////////////////////////////////////////////////////////////////////
2786 if (com=="addBranch")
2790 parser.setError (Aborted,"Nothing selected");
2791 } else if (! selbi )
2793 parser.setError (Aborted,"Type of selection is not a branch");
2798 if (parser.checkParCount(pl))
2800 if (parser.parCount()==0)
2804 n=parser.parInt (ok,0);
2805 if (ok ) addNewBranch (n);
2809 /////////////////////////////////////////////////////////////////////
2810 } else if (com=="addBranchBefore")
2814 parser.setError (Aborted,"Nothing selected");
2815 } else if (! selbi )
2817 parser.setError (Aborted,"Type of selection is not a branch");
2820 if (parser.parCount()==0)
2822 addNewBranchBefore ();
2825 /////////////////////////////////////////////////////////////////////
2826 } else if (com==QString("addMapCenter"))
2828 if (parser.checkParCount(2))
2830 x=parser.parDouble (ok,0);
2833 y=parser.parDouble (ok,1);
2834 if (ok) addMapCenter (QPointF(x,y));
2837 /////////////////////////////////////////////////////////////////////
2838 } else if (com==QString("addMapReplace"))
2842 parser.setError (Aborted,"Nothing selected");
2843 } else if (! selbi )
2845 parser.setError (Aborted,"Type of selection is not a branch");
2846 } else if (parser.checkParCount(1))
2848 //s=parser.parString (ok,0); // selection
2849 t=parser.parString (ok,0); // path to map
2850 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2851 addMapReplaceInt(getSelectString(selbi),t);
2853 /////////////////////////////////////////////////////////////////////
2854 } else if (com==QString("addMapInsert"))
2858 parser.setError (Aborted,"Nothing selected");
2859 } else if (! selbi )
2861 parser.setError (Aborted,"Type of selection is not a branch");
2864 if (parser.checkParCount(2))
2866 t=parser.parString (ok,0); // path to map
2867 n=parser.parInt(ok,1); // position
2868 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2869 addMapInsertInt(t,n);
2872 /////////////////////////////////////////////////////////////////////
2873 } else /*if (com=="clearFlags") // FIXME-2
2877 parser.setError (Aborted,"Nothing selected");
2878 } else if (! selbi )
2880 parser.setError (Aborted,"Type of selection is not a branch");
2881 } else if (parser.checkParCount(0))
2883 selb->clearStandardFlags();
2884 selb->updateFlagsToolbar();
2886 /////////////////////////////////////////////////////////////////////
2887 } else */ if (com=="colorBranch")
2891 parser.setError (Aborted,"Nothing selected");
2892 } else if (! selbi )
2894 parser.setError (Aborted,"Type of selection is not a branch");
2895 } else if (parser.checkParCount(1))
2897 QColor c=parser.parColor (ok,0);
2898 if (ok) colorBranch (c);
2900 /////////////////////////////////////////////////////////////////////
2901 } else if (com=="colorSubtree")
2905 parser.setError (Aborted,"Nothing selected");
2906 } else if (! selbi )
2908 parser.setError (Aborted,"Type of selection is not a branch");
2909 } else if (parser.checkParCount(1))
2911 QColor c=parser.parColor (ok,0);
2912 if (ok) colorSubtree (c);
2914 /////////////////////////////////////////////////////////////////////
2915 } else if (com=="copy")
2919 parser.setError (Aborted,"Nothing selected");
2920 } else if (! selbi )
2922 parser.setError (Aborted,"Type of selection is not a branch");
2923 } else if (parser.checkParCount(0))
2925 //FIXME-1 missing action for copy
2927 /////////////////////////////////////////////////////////////////////
2928 } else if (com=="cut")
2932 parser.setError (Aborted,"Nothing selected");
2933 } else if ( selectionType()!=TreeItem::Branch &&
2934 selectionType()!=TreeItem::MapCenter &&
2935 selectionType()!=TreeItem::Image )
2937 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2938 } else if (parser.checkParCount(0))
2942 /////////////////////////////////////////////////////////////////////
2943 } else if (com=="delete")
2947 parser.setError (Aborted,"Nothing selected");
2949 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2951 parser.setError (Aborted,"Type of selection is wrong.");
2954 else if (parser.checkParCount(0))
2958 /////////////////////////////////////////////////////////////////////
2959 } else if (com=="deleteKeepChildren")
2963 parser.setError (Aborted,"Nothing selected");
2964 } else if (! selbi )
2966 parser.setError (Aborted,"Type of selection is not a branch");
2967 } else if (parser.checkParCount(0))
2969 deleteKeepChildren();
2971 /////////////////////////////////////////////////////////////////////
2972 } else if (com=="deleteChildren")
2976 parser.setError (Aborted,"Nothing selected");
2979 parser.setError (Aborted,"Type of selection is not a branch");
2980 } else if (parser.checkParCount(0))
2984 /////////////////////////////////////////////////////////////////////
2985 } else if (com=="exportASCII")
2989 if (parser.parCount()>=1)
2990 // Hey, we even have a filename
2991 fname=parser.parString(ok,0);
2994 parser.setError (Aborted,"Could not read filename");
2997 exportASCII (fname,false);
2999 /////////////////////////////////////////////////////////////////////
3000 } else if (com=="exportImage")
3004 if (parser.parCount()>=2)
3005 // Hey, we even have a filename
3006 fname=parser.parString(ok,0);
3009 parser.setError (Aborted,"Could not read filename");
3012 QString format="PNG";
3013 if (parser.parCount()>=2)
3015 format=parser.parString(ok,1);
3017 exportImage (fname,false,format);
3019 /////////////////////////////////////////////////////////////////////
3020 } else if (com=="exportXHTML")
3024 if (parser.parCount()>=2)
3025 // Hey, we even have a filename
3026 fname=parser.parString(ok,1);
3029 parser.setError (Aborted,"Could not read filename");
3032 exportXHTML (fname,false);
3034 /////////////////////////////////////////////////////////////////////
3035 } else if (com=="exportXML")
3039 if (parser.parCount()>=2)
3040 // Hey, we even have a filename
3041 fname=parser.parString(ok,1);
3044 parser.setError (Aborted,"Could not read filename");
3047 exportXML (fname,false);
3049 /////////////////////////////////////////////////////////////////////
3050 } else if (com=="importDir")
3054 parser.setError (Aborted,"Nothing selected");
3055 } else if (! selbi )
3057 parser.setError (Aborted,"Type of selection is not a branch");
3058 } else if (parser.checkParCount(1))
3060 s=parser.parString(ok,0);
3061 if (ok) importDirInt(s);
3063 /////////////////////////////////////////////////////////////////////
3064 } else /* FIXME-2 if (com=="linkTo")
3068 parser.setError (Aborted,"Nothing selected");
3071 if (parser.checkParCount(4))
3073 // 0 selectstring of parent
3074 // 1 num in parent (for branches)
3075 // 2,3 x,y of mainbranch or mapcenter
3076 s=parser.parString(ok,0);
3077 LinkableMapObj *dst=findObjBySelect (s);
3080 if (typeid(*dst) == typeid(BranchObj) )
3082 // Get number in parent
3083 n=parser.parInt (ok,1);
3086 selb->linkTo ((BranchObj*)(dst),n);
3089 } else if (typeid(*dst) == typeid(MapCenterObj) )
3091 selb->linkTo ((BranchObj*)(dst),-1);
3092 // Get coordinates of mainbranch
3093 x=parser.parDouble(ok,2);
3096 y=parser.parDouble(ok,3);
3106 } else if ( selectionType() == TreeItem::Image)
3108 if (parser.checkParCount(1))
3110 // 0 selectstring of parent
3111 s=parser.parString(ok,0);
3112 LinkableMapObj *dst=findObjBySelect (s);
3115 if (typeid(*dst) == typeid(BranchObj) ||
3116 typeid(*dst) == typeid(MapCenterObj))
3117 linkFloatImageTo (getSelectString(dst));
3119 parser.setError (Aborted,"Destination is not a branch");
3122 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3123 /////////////////////////////////////////////////////////////////////
3124 } else */ if (com=="loadImage")
3128 parser.setError (Aborted,"Nothing selected");
3129 } else if (! selbi )
3131 parser.setError (Aborted,"Type of selection is not a branch");
3132 } else if (parser.checkParCount(1))
3134 s=parser.parString(ok,0);
3135 if (ok) loadFloatImageInt (s);
3137 /////////////////////////////////////////////////////////////////////
3138 } else if (com=="moveBranchUp")
3142 parser.setError (Aborted,"Nothing selected");
3143 } else if (! selbi )
3145 parser.setError (Aborted,"Type of selection is not a branch");
3146 } else if (parser.checkParCount(0))
3150 /////////////////////////////////////////////////////////////////////
3151 } else if (com=="moveBranchDown")
3155 parser.setError (Aborted,"Nothing selected");
3156 } else if (! selbi )
3158 parser.setError (Aborted,"Type of selection is not a branch");
3159 } else if (parser.checkParCount(0))
3163 /////////////////////////////////////////////////////////////////////
3164 } else if (com=="move")
3168 parser.setError (Aborted,"Nothing selected");
3169 } else if ( selectionType()!=TreeItem::Branch &&
3170 selectionType()!=TreeItem::MapCenter &&
3171 selectionType()!=TreeItem::Image )
3173 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3174 } else if (parser.checkParCount(2))
3176 x=parser.parDouble (ok,0);
3179 y=parser.parDouble (ok,1);
3183 /////////////////////////////////////////////////////////////////////
3184 } else if (com=="moveRel")
3188 parser.setError (Aborted,"Nothing selected");
3189 } else if ( selectionType()!=TreeItem::Branch &&
3190 selectionType()!=TreeItem::MapCenter &&
3191 selectionType()!=TreeItem::Image )
3193 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3194 } else if (parser.checkParCount(2))
3196 x=parser.parDouble (ok,0);
3199 y=parser.parDouble (ok,1);
3200 if (ok) moveRel (x,y);
3203 /////////////////////////////////////////////////////////////////////
3204 } else if (com=="nop")
3206 /////////////////////////////////////////////////////////////////////
3207 } else if (com=="paste")
3211 parser.setError (Aborted,"Nothing selected");
3212 } else if (! selbi )
3214 parser.setError (Aborted,"Type of selection is not a branch");
3215 } else if (parser.checkParCount(1))
3217 n=parser.parInt (ok,0);
3218 if (ok) pasteNoSave(n);
3220 /////////////////////////////////////////////////////////////////////
3221 } else if (com=="qa")
3225 parser.setError (Aborted,"Nothing selected");
3226 } else if (! selbi )
3228 parser.setError (Aborted,"Type of selection is not a branch");
3229 } else if (parser.checkParCount(4))
3232 c=parser.parString (ok,0);
3235 parser.setError (Aborted,"No comment given");
3238 s=parser.parString (ok,1);
3241 parser.setError (Aborted,"First parameter is not a string");
3244 t=parser.parString (ok,2);
3247 parser.setError (Aborted,"Condition is not a string");
3250 u=parser.parString (ok,3);
3253 parser.setError (Aborted,"Third parameter is not a string");
3258 parser.setError (Aborted,"Unknown type: "+s);
3263 parser.setError (Aborted,"Unknown operator: "+t);
3268 parser.setError (Aborted,"Type of selection is not a branch");
3271 if (selbi->getHeading() == u)
3273 cout << "PASSED: " << qPrintable (c) << endl;
3276 cout << "FAILED: " << qPrintable (c) << endl;
3286 /////////////////////////////////////////////////////////////////////
3287 } else if (com=="saveImage")
3289 FloatImageObj *fio=selection.getFloatImage();
3292 parser.setError (Aborted,"Type of selection is not an image");
3293 } else if (parser.checkParCount(2))
3295 s=parser.parString(ok,0);
3298 t=parser.parString(ok,1);
3299 if (ok) saveFloatImageInt (fio,t,s);
3302 /////////////////////////////////////////////////////////////////////
3303 } else if (com=="scroll")
3307 parser.setError (Aborted,"Nothing selected");
3308 } else if (! selbi )
3310 parser.setError (Aborted,"Type of selection is not a branch");
3311 } else if (parser.checkParCount(0))
3313 if (!scrollBranch (selbi))
3314 parser.setError (Aborted,"Could not scroll branch");
3316 /////////////////////////////////////////////////////////////////////
3317 } else if (com=="select")
3319 if (parser.checkParCount(1))
3321 s=parser.parString(ok,0);
3324 /////////////////////////////////////////////////////////////////////
3325 } else if (com=="selectLastBranch")
3329 parser.setError (Aborted,"Nothing selected");
3330 } else if (! selbi )
3332 parser.setError (Aborted,"Type of selection is not a branch");
3333 } else if (parser.checkParCount(0))
3335 BranchItem *bi=selbi->getLastBranch();
3337 parser.setError (Aborted,"Could not select last branch");
3338 select (bi); // FIXME-3 was selectInt
3341 /////////////////////////////////////////////////////////////////////
3342 } else /* FIXME-2 if (com=="selectLastImage")
3346 parser.setError (Aborted,"Nothing selected");
3347 } else if (! selbi )
3349 parser.setError (Aborted,"Type of selection is not a branch");
3350 } else if (parser.checkParCount(0))
3352 FloatImageObj *fio=selb->getLastFloatImage();
3354 parser.setError (Aborted,"Could not select last image");
3355 select (fio); // FIXME-3 was selectInt
3358 /////////////////////////////////////////////////////////////////////
3359 } else */ if (com=="selectLatestAdded")
3361 if (!latestAddedItem)
3363 parser.setError (Aborted,"No latest added object");
3366 if (!select (latestAddedItem))
3367 parser.setError (Aborted,"Could not select latest added object ");
3369 /////////////////////////////////////////////////////////////////////
3370 } else if (com=="setFrameType")
3372 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3374 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3376 else if (parser.checkParCount(1))
3378 s=parser.parString(ok,0);
3379 if (ok) setFrameType (s);
3381 /////////////////////////////////////////////////////////////////////
3382 } else if (com=="setFramePenColor")
3384 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3386 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3388 else if (parser.checkParCount(1))
3390 QColor c=parser.parColor(ok,0);
3391 if (ok) setFramePenColor (c);
3393 /////////////////////////////////////////////////////////////////////
3394 } else if (com=="setFrameBrushColor")
3396 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3398 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3400 else if (parser.checkParCount(1))
3402 QColor c=parser.parColor(ok,0);
3403 if (ok) setFrameBrushColor (c);
3405 /////////////////////////////////////////////////////////////////////
3406 } else if (com=="setFramePadding")
3408 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3410 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3412 else if (parser.checkParCount(1))
3414 n=parser.parInt(ok,0);
3415 if (ok) setFramePadding(n);
3417 /////////////////////////////////////////////////////////////////////
3418 } else if (com=="setFrameBorderWidth")
3420 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3422 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3424 else if (parser.checkParCount(1))
3426 n=parser.parInt(ok,0);
3427 if (ok) setFrameBorderWidth (n);
3429 /////////////////////////////////////////////////////////////////////
3430 } else if (com=="setMapAuthor")
3432 if (parser.checkParCount(1))
3434 s=parser.parString(ok,0);
3435 if (ok) setAuthor (s);
3437 /////////////////////////////////////////////////////////////////////
3438 } else if (com=="setMapComment")
3440 if (parser.checkParCount(1))
3442 s=parser.parString(ok,0);
3443 if (ok) setComment(s);
3445 /////////////////////////////////////////////////////////////////////
3446 } else if (com=="setMapBackgroundColor")
3450 parser.setError (Aborted,"Nothing selected");
3451 } else if (! selbi )
3453 parser.setError (Aborted,"Type of selection is not a branch");
3454 } else if (parser.checkParCount(1))
3456 QColor c=parser.parColor (ok,0);
3457 if (ok) setMapBackgroundColor (c);
3459 /////////////////////////////////////////////////////////////////////
3460 } else if (com=="setMapDefLinkColor")
3464 parser.setError (Aborted,"Nothing selected");
3465 } else if (! selbi )
3467 parser.setError (Aborted,"Type of selection is not a branch");
3468 } else if (parser.checkParCount(1))
3470 QColor c=parser.parColor (ok,0);
3471 if (ok) setMapDefLinkColor (c);
3473 /////////////////////////////////////////////////////////////////////
3474 } else if (com=="setMapLinkStyle")
3476 if (parser.checkParCount(1))
3478 s=parser.parString (ok,0);
3479 if (ok) setMapLinkStyle(s);
3481 /////////////////////////////////////////////////////////////////////
3482 } else if (com=="setHeading")
3486 parser.setError (Aborted,"Nothing selected");
3487 } else if (! selbi )
3489 parser.setError (Aborted,"Type of selection is not a branch");
3490 } else if (parser.checkParCount(1))
3492 s=parser.parString (ok,0);
3496 /////////////////////////////////////////////////////////////////////
3497 } else if (com=="setHideExport")
3501 parser.setError (Aborted,"Nothing selected");
3502 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3504 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3505 } else if (parser.checkParCount(1))
3507 b=parser.parBool(ok,0);
3508 if (ok) setHideExport (b);
3510 /////////////////////////////////////////////////////////////////////
3511 } else if (com=="setIncludeImagesHorizontally")
3515 parser.setError (Aborted,"Nothing selected");
3518 parser.setError (Aborted,"Type of selection is not a branch");
3519 } else if (parser.checkParCount(1))
3521 b=parser.parBool(ok,0);
3522 if (ok) setIncludeImagesHor(b);
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="setIncludeImagesVertically")
3529 parser.setError (Aborted,"Nothing selected");
3532 parser.setError (Aborted,"Type of selection is not a branch");
3533 } else if (parser.checkParCount(1))
3535 b=parser.parBool(ok,0);
3536 if (ok) setIncludeImagesVer(b);
3538 /////////////////////////////////////////////////////////////////////
3539 } else if (com=="setHideLinkUnselected")
3543 parser.setError (Aborted,"Nothing selected");
3544 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3546 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3547 } else if (parser.checkParCount(1))
3549 b=parser.parBool(ok,0);
3550 if (ok) setHideLinkUnselected(b);
3552 /////////////////////////////////////////////////////////////////////
3553 } else if (com=="setSelectionColor")
3555 if (parser.checkParCount(1))
3557 QColor c=parser.parColor (ok,0);
3558 if (ok) setSelectionColorInt (c);
3560 /////////////////////////////////////////////////////////////////////
3561 } else if (com=="setURL")
3565 parser.setError (Aborted,"Nothing selected");
3566 } else if (! selbi )
3568 parser.setError (Aborted,"Type of selection is not a branch");
3569 } else if (parser.checkParCount(1))
3571 s=parser.parString (ok,0);
3574 /////////////////////////////////////////////////////////////////////
3575 } else if (com=="setVymLink")
3579 parser.setError (Aborted,"Nothing selected");
3580 } else if (! selbi )
3582 parser.setError (Aborted,"Type of selection is not a branch");
3583 } else if (parser.checkParCount(1))
3585 s=parser.parString (ok,0);
3586 if (ok) setVymLink(s);
3589 /////////////////////////////////////////////////////////////////////
3590 else /* FIXME-2 if (com=="setFlag")
3594 parser.setError (Aborted,"Nothing selected");
3595 } else if (! selbi )
3597 parser.setError (Aborted,"Type of selection is not a branch");
3598 } else if (parser.checkParCount(1))
3600 s=parser.parString(ok,0);
3603 selb->activateStandardFlag(s);
3604 selb->updateFlagsToolbar();
3607 /////////////////////////////////////////////////////////////////////
3608 } else */ /* FIXME-2 if (com=="setFrameType")
3612 parser.setError (Aborted,"Nothing selected");
3615 parser.setError (Aborted,"Type of selection is not a branch");
3616 } else if (parser.checkParCount(1))
3618 s=parser.parString(ok,0);
3622 /////////////////////////////////////////////////////////////////////
3623 } else*/ if (com=="sortChildren")
3627 parser.setError (Aborted,"Nothing selected");
3628 } else if (! selbi )
3630 parser.setError (Aborted,"Type of selection is not a branch");
3631 } else if (parser.checkParCount(0))
3635 /////////////////////////////////////////////////////////////////////
3636 } else /* FIXME-2 if (com=="toggleFlag")
3640 parser.setError (Aborted,"Nothing selected");
3641 } else if (! selbi )
3643 parser.setError (Aborted,"Type of selection is not a branch");
3644 } else if (parser.checkParCount(1))
3646 s=parser.parString(ok,0);
3649 selbi->toggleStandardFlag(s);
3650 selb->updateFlagsToolbar();
3653 /////////////////////////////////////////////////////////////////////
3654 } else */ if (com=="unscroll")
3658 parser.setError (Aborted,"Nothing selected");
3659 } else if (! selbi )
3661 parser.setError (Aborted,"Type of selection is not a branch");
3662 } else if (parser.checkParCount(0))
3664 if (!unscrollBranch (selbi))
3665 parser.setError (Aborted,"Could not unscroll branch");
3667 /////////////////////////////////////////////////////////////////////
3668 } else if (com=="unscrollChildren")
3672 parser.setError (Aborted,"Nothing selected");
3673 } else if (! selbi )
3675 parser.setError (Aborted,"Type of selection is not a branch");
3676 } else if (parser.checkParCount(0))
3678 unscrollChildren ();
3680 /////////////////////////////////////////////////////////////////////
3681 } else /* FIXME-2 if (com=="unsetFlag")
3683 if (selection.isEmpty() )
3685 parser.setError (Aborted,"Nothing selected");
3686 } else if (! selbi )
3688 parser.setError (Aborted,"Type of selection is not a branch");
3689 } else if (parser.checkParCount(1))
3691 s=parser.parString(ok,0);
3694 selb->deactivateStandardFlag(s);
3695 selb->updateFlagsToolbar();
3699 parser.setError (Aborted,"Unknown command");
3702 if (parser.errorLevel()==NoError)
3704 // setChanged(); FIXME-2 should not be called e.g. for export?!
3709 // TODO Error handling
3710 qWarning("VymModel::parseAtom: Error!");
3711 qWarning(parser.errorMessage());
3715 void VymModel::runScript (QString script)
3717 parser.setScript (script);
3719 while (parser.next() )
3720 parseAtom(parser.getAtom());
3723 void VymModel::setExportMode (bool b)
3725 // should be called before and after exports
3726 // depending on the settings
3727 if (b && settings.value("/export/useHideExport","true")=="true")
3728 setHideTmpMode (TreeItem::HideExport);
3730 setHideTmpMode (TreeItem::HideNone);
3733 void VymModel::exportImage(QString fname, bool askName, QString format)
3737 fname=getMapName()+".png";
3744 QFileDialog *fd=new QFileDialog (NULL);
3745 fd->setCaption (tr("Export map as image"));
3746 fd->setDirectory (lastImageDir);
3747 fd->setFileMode(QFileDialog::AnyFile);
3748 fd->setFilters (imageIO.getFilters() );
3751 fl=fd->selectedFiles();
3753 format=imageIO.getType(fd->selectedFilter());
3757 setExportMode (true);
3758 QPixmap pix (getPixmap());
3759 pix.save(fname, format);
3760 setExportMode (false);
3764 void VymModel::exportXML(QString dir, bool askForName)
3768 dir=browseDirectory(NULL,tr("Export XML to directory"));
3769 if (dir =="" && !reallyWriteDirectory(dir) )
3773 // Hide stuff during export, if settings want this
3774 setExportMode (true);
3776 // Create subdirectories
3779 // write to directory
3780 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3783 file.setName ( dir + "/"+mapName+".xml");
3784 if ( !file.open( QIODevice::WriteOnly ) )
3786 // This should neverever happen
3787 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3791 // Write it finally, and write in UTF8, no matter what
3792 QTextStream ts( &file );
3793 ts.setEncoding (QTextStream::UnicodeUTF8);
3797 // Now write image, too
3798 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3800 setExportMode (false);
3803 void VymModel::exportASCII(QString fname,bool askName)
3808 ex.setFile (mapName+".txt");
3814 //ex.addFilter ("TXT (*.txt)");
3815 ex.setDir(lastImageDir);
3816 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3821 setExportMode(true);
3823 setExportMode(false);
3827 void VymModel::exportXHTML (const QString &dir, bool askForName)
3829 ExportXHTMLDialog dia(NULL);
3830 dia.setFilePath (filePath );
3831 dia.setMapName (mapName );
3833 if (dir!="") dia.setDir (dir);
3839 if (dia.exec()!=QDialog::Accepted)
3843 QDir d (dia.getDir());
3844 // Check, if warnings should be used before overwriting
3845 // the output directory
3846 if (d.exists() && d.count()>0)
3849 warn.showCancelButton (true);
3850 warn.setText(QString(
3851 "The directory %1 is not empty.\n"
3852 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3853 warn.setCaption("Warning: Directory not empty");
3854 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3856 if (warn.exec()!=QDialog::Accepted) ok=false;
3863 exportXML (dia.getDir(),false );
3864 dia.doExport(mapName );
3865 //if (dia.hasChanged()) setChanged();
3869 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3874 if (ex.setConfigFile(cf))
3876 setExportMode (true);
3877 ex.exportPresentation();
3878 setExportMode (false);
3885 //////////////////////////////////////////////
3887 //////////////////////////////////////////////
3889 void VymModel::registerEditor(QWidget *me)
3891 mapEditor=(MapEditor*)me;
3894 void VymModel::unregisterEditor(QWidget *)
3899 void VymModel::setContextPos(QPointF p)
3904 void VymModel::unsetContextPos()
3906 contextPos=QPointF();
3909 void VymModel::updateNoteFlag()
3912 cout << "VM::updateNoteFlag()\n";
3913 /* FIXME-1 modify note flag
3914 BranchObj *bo=getSelectedBranch();
3917 bo->updateNoteFlag();
3918 mainWindow->updateActions();
3923 void VymModel::updateRelPositions() //FIXME-2 VM should have no need to updateRelPos
3925 //cout << "VM::updateRelPos...\n";
3926 for (int i=0; i<rootItem->branchCount(); i++)
3927 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3930 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3932 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3933 if (blockReposition) return;
3935 for (int i=0;i<rootItem->branchCount(); i++)
3936 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3939 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3942 // Creating (arbitrary) shapes
3945 QRectF rb=bo->getBBox();
3946 if (bo->getDepth()==0)
3948 // Just take BBox of this mapCenter
3949 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3953 // Take union of BBox and TotalBBox
3955 QRectF ra=bo->getTotalBBox();
3956 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3959 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3962 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3964 p <<ra.bottomRight()
3966 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3969 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3974 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3978 // Move all branches and MapCenters away from lmo
3979 // to avoid collisions
3985 BranchObj *boA=(BranchObj*)lmo;
3987 for (int i=0; i<rootItem->branchCount(); i++)
3989 boB=rootItem->getBranchNum(i);
3992 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3995 <<" ("<<qPrintable(boA->getHeading() )<<")"
3996 <<" with ("<< qPrintable (boB->getHeading() )
3999 <<" minT="<<r.minTranslation<<endl<<endl;
4004 QPixmap VymModel::getPixmap()
4006 QRectF mapRect=getTotalBBox();
4007 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4010 pp.setRenderHints(mapEditor->renderHints());
4012 // Don't print the visualisation of selection
4013 selection.unselect();
4015 mapScene->render ( &pp,
4016 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4017 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4019 // Restore selection
4020 selection.reselect();
4026 void VymModel::setMapLinkStyle (const QString & s)
4031 case LinkableMapObj::Line :
4034 case LinkableMapObj::Parabel:
4035 snow="StyleParabel";
4037 case LinkableMapObj::PolyLine:
4038 snow="StylePolyLine";
4040 case LinkableMapObj::PolyParabel:
4041 snow="StylePolyParabel";
4044 snow="UndefinedStyle";
4049 QString("setMapLinkStyle (\"%1\")").arg(s),
4050 QString("setMapLinkStyle (\"%1\")").arg(snow),
4051 QString("Set map link style (\"%1\")").arg(s)
4055 linkstyle=LinkableMapObj::Line;
4056 else if (s=="StyleParabel")
4057 linkstyle=LinkableMapObj::Parabel;
4058 else if (s=="StylePolyLine")
4059 linkstyle=LinkableMapObj::PolyLine;
4060 else if (s=="StylePolyParabel")
4061 linkstyle=LinkableMapObj::PolyParabel;
4063 linkstyle=LinkableMapObj::UndefinedStyle;
4065 BranchItem *cur=NULL;
4066 BranchItem *prev=NULL;
4072 bo=(BranchObj*)(cur->getLMO() );
4073 bo->setLinkStyle(bo->getDefLinkStyle());
4074 cur=next(cur,prev,d);
4079 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4084 void VymModel::setMapDefLinkColor(QColor col)
4086 if ( !col.isValid() ) return;
4088 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4089 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4090 QString("Set map link color to %1").arg(col.name())
4094 BranchItem *cur=NULL;
4095 BranchItem *prev=NULL;
4098 cur=next(cur,prev,d);
4101 bo=(BranchObj*)(cur->getLMO() );
4108 void VymModel::setMapLinkColorHintInt()
4110 // called from setMapLinkColorHint(lch) or at end of parse
4111 BranchItem *cur=NULL;
4112 BranchItem *prev=NULL;
4115 cur=next(cur,prev,d);
4118 bo=(BranchObj*)(cur->getLMO() );
4120 cur=next(cur,prev,d);
4124 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4127 setMapLinkColorHintInt();
4130 void VymModel::toggleMapLinkColorHint()
4132 if (linkcolorhint==LinkableMapObj::HeadingColor)
4133 linkcolorhint=LinkableMapObj::DefaultColor;
4135 linkcolorhint=LinkableMapObj::HeadingColor;
4136 BranchItem *cur=NULL;
4137 BranchItem *prev=NULL;
4140 cur=next(cur,prev,d);
4143 bo=(BranchObj*)(cur->getLMO() );
4149 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4151 Q3FileDialog *fd=new Q3FileDialog( NULL);
4152 fd->setMode (Q3FileDialog::ExistingFile);
4153 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4154 ImagePreview *p =new ImagePreview (fd);
4155 fd->setContentsPreviewEnabled( TRUE );
4156 fd->setContentsPreview( p, p );
4157 fd->setPreviewMode( Q3FileDialog::Contents );
4158 fd->setCaption(vymName+" - " +tr("Load background image"));
4159 fd->setDir (lastImageDir);
4162 if ( fd->exec() == QDialog::Accepted )
4164 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4165 lastImageDir=QDir (fd->dirPath());
4166 setMapBackgroundImage (fd->selectedFile());
4170 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4172 QColor oldcol=mapScene->backgroundBrush().color();
4176 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4178 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4179 QString("Set background color of map to %1").arg(col.name()));
4182 brush.setTextureImage (QPixmap (fn));
4183 mapScene->setBackgroundBrush(brush);
4186 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4188 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4189 if ( !col.isValid() ) return;
4190 setMapBackgroundColor( col );
4194 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4196 QColor oldcol=mapScene->backgroundBrush().color();
4198 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4199 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4200 QString("Set background color of map to %1").arg(col.name()));
4201 mapScene->setBackgroundBrush(col);
4204 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4206 return mapScene->backgroundBrush().color();
4210 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4212 return linkcolorhint;
4215 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4217 return defLinkColor;
4220 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4225 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4227 return defXLinkColor;
4230 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4235 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4237 return defXLinkWidth;
4240 void VymModel::move(const double &x, const double &y) // FIXME-3
4244 BranchObj *bo = getSelectedBranch();
4246 (selectionType()==TreeItem::Branch ||
4247 selectionType()==TreeItem::MapCenter ||
4248 selectionType()==TreeItem::Image
4251 QPointF ap(bo->getAbsPos());
4255 QString ps=qpointfToString(ap);
4256 QString s=getSelectString();
4259 s, "move "+qpointfToString(to),
4260 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4269 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4273 BranchObj *bo = getSelectedBranch();
4275 (selectionType()==TreeItem::Branch ||
4276 selectionType()==TreeItem::MapCenter ||
4277 selectionType()==TreeItem::Image
4281 QPointF rp(bo->getRelPos());
4285 QString ps=qpointfToString (bo->getRelPos());
4286 QString s=getSelectString(bo);
4289 s, "moveRel "+qpointfToString(to),
4290 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4291 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4301 void VymModel::animate()
4303 animationTimer->stop();
4306 while (i<animObjList.size() )
4308 bo=(BranchObj*)animObjList.at(i);
4313 animObjList.removeAt(i);
4320 QItemSelection sel=selModel->selection();
4321 emit (selectionChanged(sel,sel));
4324 if (!animObjList.isEmpty()) animationTimer->start();
4328 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4330 if (bo && bo->getTreeItem()->depth()>0)
4333 ap.setStart (start);
4335 ap.setTicks (animationTicks);
4336 ap.setAnimated (true);
4337 bo->setAnimation (ap);
4338 animObjList.append( bo );
4339 animationTimer->setSingleShot (true);
4340 animationTimer->start(animationInterval);
4344 void VymModel::stopAnimation (MapObj *mo)
4346 int i=animObjList.indexOf(mo);
4348 animObjList.removeAt (i);
4351 void VymModel::sendSelection()
4353 if (netstate!=Server) return;
4354 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4357 void VymModel::newServer()
4361 tcpServer = new QTcpServer(this);
4362 if (!tcpServer->listen(QHostAddress::Any,port)) {
4363 QMessageBox::critical(NULL, "vym server",
4364 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4365 //FIXME-3 needed? we are no widget any longer... close();
4368 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4370 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4373 void VymModel::connectToServer()
4376 server="salam.suse.de";
4378 clientSocket = new QTcpSocket (this);
4379 clientSocket->abort();
4380 clientSocket->connectToHost(server ,port);
4381 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4382 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4383 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4385 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4390 void VymModel::newClient()
4392 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4393 connect(newClient, SIGNAL(disconnected()),
4394 newClient, SLOT(deleteLater()));
4396 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4398 clientList.append (newClient);
4402 void VymModel::sendData(const QString &s)
4404 if (clientList.size()==0) return;
4406 // Create bytearray to send
4408 QDataStream out(&block, QIODevice::WriteOnly);
4409 out.setVersion(QDataStream::Qt_4_0);
4411 // Reserve some space for blocksize
4414 // Write sendCounter
4415 out << sendCounter++;
4420 // Go back and write blocksize so far
4421 out.device()->seek(0);
4422 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4426 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4428 for (int i=0; i<clientList.size(); ++i)
4430 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4431 clientList.at(i)->write (block);
4435 void VymModel::readData ()
4437 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4440 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4444 QDataStream in(clientSocket);
4445 in.setVersion(QDataStream::Qt_4_0);
4453 cout << " t="<<qPrintable (t)<<endl;
4459 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4461 switch (socketError) {
4462 case QAbstractSocket::RemoteHostClosedError:
4464 case QAbstractSocket::HostNotFoundError:
4465 QMessageBox::information(NULL, vymName +" Network client",
4466 "The host was not found. Please check the "
4467 "host name and port settings.");
4469 case QAbstractSocket::ConnectionRefusedError:
4470 QMessageBox::information(NULL, vymName + " Network client",
4471 "The connection was refused by the peer. "
4472 "Make sure the fortune server is running, "
4473 "and check that the host name and port "
4474 "settings are correct.");
4477 QMessageBox::information(NULL, vymName + " Network client",
4478 QString("The following error occurred: %1.")
4479 .arg(clientSocket->errorString()));
4486 void VymModel::selectMapSelectionColor()
4488 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4489 setSelectionColor (col);
4492 void VymModel::setSelectionColorInt (QColor col)
4494 if ( !col.isValid() ) return;
4496 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4497 QString("setSelectionColor (%1)").arg(col.name()),
4498 QString("Set color of selection box to %1").arg(col.name())
4501 mapEditor->setSelectionColor (col);
4505 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4507 cout << "VymModel::changeSelection (";
4508 if (!newsel.indexes().isEmpty() )
4509 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4511 if (!oldsel.indexes().isEmpty() )
4512 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4517 void VymModel::updateSelection(const QItemSelection &newsel)
4519 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4520 ensureSelectionVisible();
4524 void VymModel::updateSelection()
4526 QItemSelection newsel=selModel->selection();
4527 updateSelection (newsel);
4530 void VymModel::setSelectionColor(QColor col)
4532 if ( !col.isValid() ) return;
4534 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4535 QString("setSelectionColor (%1)").arg(col.name()),
4536 QString("Set color of selection box to %1").arg(col.name())
4538 setSelectionColorInt (col);
4541 QColor VymModel::getSelectionColor()
4543 return mapEditor->getSelectionColor();
4546 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4549 for (int i=0;i<rootItem->childCount();i++)
4550 rootItem->child(i)->setHideTmp (mode);
4552 // FIXME-3 needed? scene()->update();
4556 QRectF VymModel::getTotalBBox() //FIXME-2
4560 for (int i=0;i<rootItem->branchCount(); i++)
4561 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4566 //////////////////////////////////////////////
4567 // Selection related
4568 //////////////////////////////////////////////
4570 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4575 QItemSelectionModel* VymModel::getSelectionModel()
4580 void VymModel::setSelectionBlocked (bool b)
4585 selection.unblock();
4588 bool VymModel::isSelectionBlocked()
4590 return selection.isBlocked();
4593 bool VymModel::select ()
4595 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4597 TreeItem *item = getItem (index);
4598 return select (item->getLMO() );
4601 bool VymModel::select (const QString &s)
4603 TreeItem *ti=findBySelectString(s);
4613 bool VymModel::select (LinkableMapObj *lmo)
4615 QItemSelection oldsel=selModel->selection();
4618 return select (lmo->getTreeItem() );
4623 bool VymModel::select (TreeItem *ti)
4627 QModelIndex ix=index(ti);
4628 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4629 ti->setLastSelectedBranch();
4635 void VymModel::unselect()
4637 selModel->clearSelection();
4640 void VymModel::reselect()
4642 selection.reselect();
4645 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4647 LinkableMapObj *lmo=getSelectedLMO();
4648 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4651 void VymModel::emitNoteHasChanged (TreeItem *ti)
4653 QModelIndex ix=index(ti);
4654 emit (noteHasChanged (ix) );
4657 void VymModel::emitDataHasChanged (TreeItem *ti)
4659 QModelIndex ix=index(ti);
4660 emit (dataHasChanged (ix) );
4664 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4667 if (selection.select(lmo))
4669 //selection.update();
4670 sendSelection (); // FIXME-4 VM use signal
4674 void VymModel::selectInt (TreeItem *ti)
4676 if (selection.select(lmo))
4678 //selection.update();
4679 sendSelection (); // FIXME-4 VM use signal
4684 void VymModel::selectNextBranchInt()
4686 BranchItem *bi=getSelectedBranchItem();
4689 TreeItem *pi=bi->parent();
4693 if (i<pi->branchCount() )
4695 // select previous branch with same parent
4697 select (pi->getBranchNum(i));
4705 void VymModel::selectPrevBranchInt()
4708 BranchItem *bi=getSelectedBranchItem();
4711 BranchItem *pi=(BranchItem*)bi->parent();
4717 // select previous branch with same parent
4718 bi=pi->getBranchNum(i-1);
4723 while (bi->branchCount() >0)
4724 bi=bi->getLastBranch();
4727 // Try to select last branch in parent pi2 previous to own parent pi
4729 TreeItem *pi2=pi->parent();
4740 void VymModel::selectAboveBranchInt()
4742 BranchItem *bi=getSelectedBranchItem();
4745 BranchItem *newbi=NULL;
4746 BranchItem *pi=(BranchItem*)bi->parent();
4750 // goto previous branch with same parent
4751 newbi=pi->getBranchNum(i-1);
4752 while (newbi->branchCount() >0 )
4753 newbi=newbi->getLastBranch();
4757 if (newbi==rootItem)
4758 // already at top branch (resp. mapcenter)
4764 void VymModel::selectBelowBranchInt()
4766 BranchItem *bi=getSelectedBranchItem();
4769 BranchItem *newbi=NULL;
4771 if (bi->branchCount() >0)
4772 newbi=bi->getFirstBranch();
4779 pi=(BranchItem*)bi->parent();
4781 if (pi->branchCount()-1 > i)
4783 newbi=(BranchItem*)pi->getBranchNum(i+1);
4788 // look for siblings of myself
4789 // or parent, or parent of parent...
4800 void VymModel::selectUpperBranch()
4802 if (selection.isBlocked() ) return;
4804 BranchItem *bi=getSelectedBranchItem();
4805 if (bi && bi->isBranchLikeType())
4806 selectAboveBranchInt();
4809 void VymModel::selectLowerBranch()
4811 if (selection.isBlocked() ) return;
4813 BranchItem *bi=getSelectedBranchItem();
4814 if (bi && bi->isBranchLikeType())
4815 selectBelowBranchInt();
4819 void VymModel::selectLeftBranch()
4821 if (selection.isBlocked() ) return;
4823 QItemSelection oldsel=selModel->selection();
4826 BranchItem *selbi=getSelectedBranchItem();
4827 TreeItem::Type type=selbi->getType();
4830 if (type == TreeItem::MapCenter)
4832 QModelIndex ix=index(selbi);
4833 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4836 par=(BranchItem*)selbi->parent();
4837 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4840 if (type == TreeItem::Branch ||
4841 type == TreeItem::Image)
4843 QModelIndex ix=index (selbi->parent());
4844 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4849 if (type == TreeItem::Branch )
4851 cout << "VM::selLeft\n";
4852 selectLastSelectedBranch();
4860 void VymModel::selectRightBranch()
4862 if (selection.isBlocked() ) return;
4864 QItemSelection oldsel=selModel->selection();
4867 BranchItem *selbi=getSelectedBranchItem();
4868 TreeItem::Type type=selbi->getType();
4871 if (type==TreeItem::MapCenter)
4873 QModelIndex ix=index(selbi);
4874 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4877 par=(BranchItem*)selbi->parent();
4878 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4881 if ( type== TreeItem::Branch )
4883 selectLastSelectedBranch();
4889 if (type == TreeItem::Branch ||
4890 type == TreeItem::Image)
4892 cout << "VM::selRight\n";
4893 QModelIndex ix=index(selbi->parent());
4894 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4901 void VymModel::selectFirstBranch()
4903 TreeItem *ti=getSelectedBranchItem();
4906 TreeItem *par=ti->parent();
4908 TreeItem *ti2=par->getFirstBranch();
4912 ensureSelectionVisible();
4918 void VymModel::selectLastBranch()
4920 TreeItem *ti=getSelectedBranchItem();
4923 TreeItem *par=ti->parent();
4925 TreeItem *ti2=par->getLastBranch();
4929 ensureSelectionVisible();
4935 void VymModel::selectLastSelectedBranch()
4937 TreeItem *ti=getSelectedBranchItem();
4940 ti=ti->getLastSelectedBranch();
4941 if (ti) select (ti);
4945 void VymModel::selectParent()
4947 TreeItem *ti=getSelectedItem();
4955 ensureSelectionVisible();
4960 TreeItem::Type VymModel::selectionType()
4962 QModelIndexList list=selModel->selectedIndexes();
4963 if (list.isEmpty()) return TreeItem::Undefined;
4964 TreeItem *ti = getItem (list.first() );
4965 return ti->getType();
4969 LinkableMapObj* VymModel::getSelectedLMO()
4971 QModelIndexList list=selModel->selectedIndexes();
4972 if (!list.isEmpty() )
4974 TreeItem *ti = getItem (list.first() );
4975 TreeItem::Type type=ti->getType();
4976 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4978 return ti->getLMO();
4984 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4986 TreeItem *ti = getSelectedBranchItem();
4988 return (BranchObj*)ti->getLMO();
4993 BranchItem* VymModel::getSelectedBranchItem()
4995 QModelIndexList list=selModel->selectedIndexes();
4996 if (!list.isEmpty() )
4998 TreeItem *ti = getItem (list.first() );
4999 TreeItem::Type type=ti->getType();
5000 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5001 return (BranchItem*)ti;
5006 TreeItem* VymModel::getSelectedItem()
5008 QModelIndexList list=selModel->selectedIndexes();
5009 if (!list.isEmpty() )
5010 return getItem (list.first() );
5015 QModelIndex VymModel::getSelectedIndex()
5017 QModelIndexList list=selModel->selectedIndexes();
5018 if (list.isEmpty() )
5019 return QModelIndex();
5021 return list.first();
5024 FloatImageObj* VymModel::getSelectedFloatImage()
5026 return selection.getFloatImage();
5029 QString VymModel::getSelectString ()
5031 LinkableMapObj *lmo=getSelectedLMO();
5033 return getSelectString(lmo);
5038 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5040 if (!lmo) return QString();
5041 return getSelectString (lmo->getTreeItem() );
5044 QString VymModel::getSelectString (TreeItem *ti)
5048 if (ti->getType() == TreeItem::Branch ||
5049 ti->getType() == TreeItem::MapCenter)
5051 TreeItem *par=ti->parent();
5054 if (ti->depth() ==1)
5055 // Mainbranch, return
5056 s= "bo:" + QString("%1").arg(ti->num() );
5058 // Branch, call myself recursively
5059 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5063 int i=rootItem->num(ti);
5064 if (i>=0) s=QString("mc:%1").arg(i);