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 Settings settings;
51 int VymModel::mapNum=0; // make instance
55 // cout << "Const VymModel\n";
57 rootItem->setModel (this);
63 // cout << "Destr VymModel\n";
64 autosaveTimer->stop();
65 fileChangedTimer->stop();
69 void VymModel::clear()
71 selModel->clearSelection();
73 //QModelIndex ri=index(rootItem);
74 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
77 void VymModel::init ()
79 // We should have at least one map center to start with
80 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
85 // Also no scene yet (should not be needed anyway) FIXME-3 VM
98 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
99 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
100 mainWindow->updateHistory (undoSet);
103 makeTmpDirectories();
108 fileName=tr("unnamed");
110 blockReposition=false;
111 blockSaveState=false;
113 autosaveTimer=new QTimer (this);
114 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
116 fileChangedTimer=new QTimer (this);
117 fileChangedTimer->start(3000);
118 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
130 animationUse=settings.readBoolEntry("/animation/use",false);
131 animationTicks=settings.readNumEntry("/animation/ticks",10);
132 animationInterval=settings.readNumEntry("/animation/interval",50);
134 animationTimer=new QTimer (this);
135 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
138 defLinkColor=QColor (0,0,255);
139 defXLinkColor=QColor (180,180,180);
140 linkcolorhint=LinkableMapObj::DefaultColor;
141 linkstyle=LinkableMapObj::PolyParabel;
143 defXLinkColor=QColor (230,230,230);
145 hidemode=TreeItem::HideNone;
151 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
155 void VymModel::makeTmpDirectories()
157 // Create unique temporary directories
158 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
159 histPath = tmpMapDir+"/history";
165 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
170 bool VymModel::isRepositionBlocked()
172 return blockReposition;
175 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
177 //cout << "VM::updateActions \n";
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
199 case LinkableMapObj::Line:
202 case LinkableMapObj::Parabel:
205 case LinkableMapObj::PolyLine:
209 ls="StylePolyParabel";
213 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
215 if (linkcolorhint==LinkableMapObj::HeadingColor)
216 colhint=xml.attribut("linkColorHint","HeadingColor");
218 QString mapAttr=xml.attribut("version",vymVersion);
220 mapAttr+= xml.attribut("author",author) +
221 xml.attribut("comment",comment) +
222 xml.attribut("date",getDate()) +
223 xml.attribut("branchCount", QString().number(branchCount())) +
224 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
226 xml.attribut("linkStyle", ls ) +
227 xml.attribut("linkColor", defLinkColor.name() ) +
228 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
229 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
231 s+=xml.beginElement("vymmap",mapAttr);
234 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
235 //FIXME-2 not used any longer: standardFlagsDefault->resetUsedCounter();
237 // Reset the counters before saving
238 // TODO constr. of FIO creates lots of objects, better do this in some other way...
239 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
241 // Build xml recursivly
242 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
243 // Save all mapcenters as complete map, if saveSel not set
244 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
247 if (saveSel->getType()==TreeItem::Branch)
249 s+=saveSel->saveToDir(tmpdir,prefix,offset);
250 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
252 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
255 cout << "VM::saveToDir 1 \n";
256 // Save local settings
257 s+=settings.getDataXML (destPath);
259 cout << "VM::saveToDir 2 \n";
261 if (getSelectedItem() && !saveSel )
262 s+=xml.valueElement("select",getSelectString());
265 s+=xml.endElement("vymmap");
267 // FIXME-2 if (writeflags) standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
271 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
275 for (int i=0; i<rootItem->branchCount(); i++)
276 s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
280 void VymModel::setFilePath(QString fpath, QString destname)
282 if (fpath.isEmpty() || fpath=="")
289 filePath=fpath; // becomes absolute path
290 fileName=fpath; // gets stripped of path
291 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
293 // If fpath is not an absolute path, complete it
294 filePath=QDir(fpath).absPath();
295 fileDir=filePath.left (1+filePath.findRev ("/"));
297 // Set short name, too. Search from behind:
298 int i=fileName.findRev("/");
299 if (i>=0) fileName=fileName.remove (0,i+1);
301 // Forget the .vym (or .xml) for name of map
302 mapName=fileName.left(fileName.findRev(".",-1,true) );
306 void VymModel::setFilePath(QString fpath)
308 setFilePath (fpath,fpath);
311 QString VymModel::getFilePath()
316 QString VymModel::getFileName()
321 QString VymModel::getMapName()
326 QString VymModel::getDestPath()
331 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
333 ErrorCode err=success;
335 parseBaseHandler *handler;
339 case VymMap: handler=new parseVYMHandler; break;
340 case FreemindMap : handler=new parseFreemindHandler; break;
342 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
343 "Unknown FileType in VymModel::load()");
347 bool zipped_org=zipped;
351 selModel->clearSelection();
352 // FIXME-2 VM not needed??? model->setMapEditor(this);
353 // (map state is set later at end of load...)
356 BranchItem *bi=getSelectedBranchItem();
357 if (!bi) return aborted;
358 if (lmode==ImportAdd)
359 saveStateChangingPart(
362 QString("addMapInsert (%1)").arg(fname),
363 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
365 saveStateChangingPart(
368 QString("addMapReplace(%1)").arg(fname),
369 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
373 // Create temporary directory for packing
375 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
378 QMessageBox::critical( 0, tr( "Critical Load Error" ),
379 tr("Couldn't create temporary directory before load\n"));
384 err=unzipDir (tmpZipDir,fname);
394 // Look for mapname.xml
395 xmlfile= fname.left(fname.findRev(".",-1,true));
396 xmlfile=xmlfile.section( '/', -1 );
397 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
398 if (!mfile.exists() )
400 // mapname.xml does not exist, well,
401 // maybe someone renamed the mapname.vym file...
402 // Try to find any .xml in the toplevel
403 // directory of the .vym file
404 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
405 if (flist.count()==1)
407 // Only one entry, take this one
408 xmlfile=tmpZipDir + "/"+flist.first();
411 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
412 *it=tmpZipDir + "/" + *it;
413 // TODO Multiple entries, load all (but only the first one into this ME)
414 //mainWindow->fileLoadFromTmp (flist);
415 //returnCode=1; // Silently forget this attempt to load
416 qWarning ("MainWindow::load (fn) multimap found...");
419 if (flist.isEmpty() )
421 QMessageBox::critical( 0, tr( "Critical Load Error" ),
422 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
425 } //file doesn't exist
427 xmlfile=mfile.name();
430 QFile file( xmlfile);
432 // I am paranoid: file should exist anyway
433 // according to check in mainwindow.
436 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
437 tr(QString("Couldn't open map %1").arg(file.name())));
441 bool blockSaveStateOrg=blockSaveState;
442 blockReposition=true;
444 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
445 QXmlInputSource source( file);
446 QXmlSimpleReader reader;
447 reader.setContentHandler( handler );
448 reader.setErrorHandler( handler );
449 handler->setModel ( this);
452 // We need to set the tmpDir in order to load files with rel. path
457 tmpdir=fname.left(fname.findRev("/",-1));
458 handler->setTmpDir (tmpdir);
459 handler->setInputFile (file.name());
460 handler->setLoadMode (lmode);
461 bool ok = reader.parse( source );
462 blockReposition=false;
463 blockSaveState=blockSaveStateOrg;
464 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
468 reposition(); // FIXME-2 VM reposition the view instead...
475 autosaveTimer->stop();
478 // Reset timestamp to check for later updates of file
479 fileChangedTime=QFileInfo (destPath).lastModified();
482 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
483 tr( handler->errorProtocol() ) );
485 // Still return "success": the map maybe at least
486 // partially read by the parser
491 removeDir (QDir(tmpZipDir));
493 // Restore original zip state
500 ErrorCode VymModel::save (const SaveMode &savemode)
504 QString safeFilePath;
506 ErrorCode err=success;
510 mapFileName=mapName+".xml";
512 // use name given by user, even if he chooses .doc
513 mapFileName=fileName;
515 // Look, if we should zip the data:
518 QMessageBox mb( vymName,
519 tr("The map %1\ndid not use the compressed "
520 "vym file format.\nWriting it uncompressed will also write images \n"
521 "and flags and thus may overwrite files in the "
522 "given directory\n\nDo you want to write the map").arg(filePath),
523 QMessageBox::Warning,
524 QMessageBox::Yes | QMessageBox::Default,
526 QMessageBox::Cancel | QMessageBox::Escape);
527 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
528 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
529 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
532 case QMessageBox::Yes:
533 // save compressed (default file format)
536 case QMessageBox::No:
540 case QMessageBox::Cancel:
547 // First backup existing file, we
548 // don't want to add to old zip archives
552 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
554 QString backupFileName(destPath + "~");
555 QFile backupFile(backupFileName);
556 if (backupFile.exists() && !backupFile.remove())
558 QMessageBox::warning(0, tr("Save Error"),
559 tr("%1\ncould not be removed before saving").arg(backupFileName));
561 else if (!f.rename(backupFileName))
563 QMessageBox::warning(0, tr("Save Error"),
564 tr("%1\ncould not be renamed before saving").arg(destPath));
571 // Create temporary directory for packing
573 tmpZipDir=makeTmpDir (ok,"vym-zip");
576 QMessageBox::critical( 0, tr( "Critical Load Error" ),
577 tr("Couldn't create temporary directory before save\n"));
581 safeFilePath=filePath;
582 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
585 // Create mapName and fileDir
586 makeSubDirs (fileDir);
589 if (savemode==CompleteMap || selection.isEmpty())
592 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
595 autosaveTimer->stop();
600 if (selectionType()==TreeItem::Image)
603 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
604 // TODO take care of multiselections
607 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
610 qWarning ("ME::saveStringToDisk failed!");
616 if (err==success) err=zipDir (tmpZipDir,destPath);
619 removeDir (QDir(tmpZipDir));
621 // Restore original filepath outside of tmp zip dir
622 setFilePath (safeFilePath);
626 fileChangedTime=QFileInfo (destPath).lastModified();
630 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
632 QString pathDir=path.left(path.findRev("/"));
638 // We need to parse saved XML data
639 parseVYMHandler handler;
640 QXmlInputSource source( file);
641 QXmlSimpleReader reader;
642 reader.setContentHandler( &handler );
643 reader.setErrorHandler( &handler );
644 handler.setModel ( this);
645 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
646 if (undoSel.isEmpty())
650 handler.setLoadMode (NewMap);
654 handler.setLoadMode (ImportReplace);
656 blockReposition=true;
657 bool ok = reader.parse( source );
658 blockReposition=false;
661 // This should never ever happen
662 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
663 handler.errorProtocol());
666 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
669 void VymModel::addMapInsertInt (const QString &path, int pos)
671 /* FIXME-2 addMapInsertInt not ported yet
672 BranchObj *sel=getSelectedBranch();
675 QString pathDir=path.left(path.findRev("/"));
681 // We need to parse saved XML data
682 parseVYMHandler handler;
683 QXmlInputSource source( file);
684 QXmlSimpleReader reader;
685 reader.setContentHandler( &handler );
686 reader.setErrorHandler( &handler );
687 handler.setModel (this);
688 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
689 handler.setLoadMode (ImportAdd);
690 blockReposition=true;
691 bool ok = reader.parse( source );
692 blockReposition=false;
695 // This should never ever happen
696 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
697 handler.errorProtocol());
699 if (sel->getDepth()>0)
700 sel->getLastBranch()->linkTo (sel,pos);
702 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
707 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
709 TreeItem *fi=createImage();
712 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
720 void VymModel::loadFloatImage () // FIXME-2
723 BranchObj *bo=getSelectedBranch();
727 Q3FileDialog *fd=new Q3FileDialog( NULL);
728 fd->setMode (Q3FileDialog::ExistingFiles);
729 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
730 ImagePreview *p =new ImagePreview (fd);
731 fd->setContentsPreviewEnabled( TRUE );
732 fd->setContentsPreview( p, p );
733 fd->setPreviewMode( Q3FileDialog::Contents );
734 fd->setCaption(vymName+" - " +tr("Load image"));
735 fd->setDir (lastImageDir);
738 if ( fd->exec() == QDialog::Accepted )
740 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
741 lastImageDir=QDir (fd->dirPath());
744 for (int j=0; j<fd->selectedFiles().count(); j++)
746 s=fd->selectedFiles().at(j);
747 fio=loadFloatImageInt (s);
750 (LinkableMapObj*)fio,
753 QString ("loadImage (%1)").arg(s ),
754 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
757 // TODO loadFIO error handling
758 qWarning ("Failed to load "+s);
767 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
772 void VymModel::saveFloatImage ()
774 FloatImageObj *fio=selection.getFloatImage();
777 QFileDialog *fd=new QFileDialog( NULL);
778 fd->setFilters (imageIO.getFilters());
779 fd->setCaption(vymName+" - " +tr("Save image"));
780 fd->setFileMode( QFileDialog::AnyFile );
781 fd->setDirectory (lastImageDir);
782 // fd->setSelection (fio->getOriginalFilename());
786 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
788 fn=fd->selectedFiles().at(0);
789 if (QFile (fn).exists() )
791 QMessageBox mb( vymName,
792 tr("The file %1 exists already.\n"
793 "Do you want to overwrite it?").arg(fn),
794 QMessageBox::Warning,
795 QMessageBox::Yes | QMessageBox::Default,
796 QMessageBox::Cancel | QMessageBox::Escape,
797 QMessageBox::NoButton );
799 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
800 mb.setButtonText( QMessageBox::No, tr("Cancel"));
803 case QMessageBox::Yes:
806 case QMessageBox::Cancel:
813 saveFloatImageInt (fio,fd->selectedFilter(),fn );
820 void VymModel::importDirInt(BranchObj *dst, QDir d)
822 /* FIXME-2 importDirInt not ported yet
823 BranchObj *bo=getSelectedBranch();
826 // Traverse directories
827 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
828 QFileInfoList list = d.entryInfoList();
831 for (int i = 0; i < list.size(); ++i)
834 if (fi.fileName() != "." && fi.fileName() != ".." )
837 bo=dst->getLastBranch();
838 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
839 bi->setHeading (fi.fileName() ); // FIXME-3 check this
840 bo->setColor (QColor("blue"));
842 if ( !d.cd(fi.fileName()) )
843 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
846 // Recursively add subdirs
853 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
854 list = d.entryInfoList();
856 for (int i = 0; i < list.size(); ++i)
860 bo=dst->getLastBranch();
861 bo->setHeading (fi.fileName() );
862 bo->setColor (QColor("black"));
863 if (fi.fileName().right(4) == ".vym" )
864 bo->setVymLink (fi.filePath());
870 void VymModel::importDirInt (const QString &s) // FIXME-2
873 BranchObj *bo=getSelectedBranch();
876 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
884 void VymModel::importDir() //FIXME-2
887 BranchObj *bo=getSelectedBranch();
891 filters <<"VYM map (*.vym)";
892 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
893 fd->setMode (QFileDialog::DirectoryOnly);
894 fd->setFilters (filters);
895 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
899 if ( fd->exec() == QDialog::Accepted )
901 importDirInt (fd->selectedFile() );
903 //FIXME-3 VM needed? scene()->update();
910 void VymModel::autosave()
915 cout << "VymModel::autosave rejected due to missing filePath\n";
918 QDateTime now=QDateTime().currentDateTime();
920 // Disable autosave, while we have gone back in history
921 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
922 if (redosAvail>0) return;
924 // Also disable autosave for new map without filename
925 if (filePath.isEmpty()) return;
928 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
930 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
931 mainWindow->fileSave (this);
934 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
939 void VymModel::fileChanged()
941 // Check if file on disk has changed meanwhile
942 if (!filePath.isEmpty())
944 QDateTime tmod=QFileInfo (filePath).lastModified();
945 if (tmod>fileChangedTime)
947 // FIXME-2 VM switch to current mapeditor and finish lineedits...
948 QMessageBox mb( vymName,
949 tr("The file of the map on disk has changed:\n\n"
950 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
951 QMessageBox::Question,
953 QMessageBox::Cancel | QMessageBox::Default,
954 QMessageBox::NoButton );
956 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
957 mb.setButtonText( QMessageBox::No, tr("Ignore"));
960 case QMessageBox::Yes:
962 load (filePath,NewMap,fileType);
963 case QMessageBox::Cancel:
964 fileChangedTime=tmod; // allow autosave to overwrite newer file!
970 bool VymModel::isDefault()
975 void VymModel::makeDefault()
981 bool VymModel::hasChanged()
986 void VymModel::setChanged()
989 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
993 latestAddedItem=NULL;
997 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1000 if (!lmo) return QString("Error: NULL has no name!");
1002 if ((typeid(*lmo) == typeid(BranchObj) ||
1003 typeid(*lmo) == typeid(MapCenterObj)))
1006 s=lmo->getTreeItem()->getHeading();
1007 if (s=="") s="unnamed";
1008 return QString("branch (%1)").arg(s);
1010 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1011 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1012 return QString("Unknown type has no name!");
1016 QString VymModel::getObjectName (const TreeItem *ti)
1019 if (!ti) return QString("Error: NULL has no name!");
1021 if (ti->isBranchLikeType() )
1024 if (s=="") s="unnamed";
1025 return QString("branch (%1)").arg(s);
1027 /* FIXME-2 move floatimage to TreeModel first
1028 if (type==TreeItem::Image)
1029 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1031 return QString("Unknown type has no name!");
1034 void VymModel::redo()
1036 // Can we undo at all?
1037 if (redosAvail<1) return;
1039 bool blockSaveStateOrg=blockSaveState;
1040 blockSaveState=true;
1044 if (undosAvail<stepsTotal) undosAvail++;
1046 if (curStep>stepsTotal) curStep=1;
1047 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1048 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1049 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1050 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1051 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1052 QString version=undoSet.readEntry ("/history/version");
1054 /* TODO Maybe check for version, if we save the history
1055 if (!checkVersion(version))
1056 QMessageBox::warning(0,tr("Warning"),
1057 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1060 // Find out current undo directory
1061 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1065 cout << "VymModel::redo() begin\n";
1066 cout << " undosAvail="<<undosAvail<<endl;
1067 cout << " redosAvail="<<redosAvail<<endl;
1068 cout << " curStep="<<curStep<<endl;
1069 cout << " ---------------------------"<<endl;
1070 cout << " comment="<<comment.toStdString()<<endl;
1071 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1072 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1073 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1074 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1075 cout << " ---------------------------"<<endl<<endl;
1078 // select object before redo
1079 if (!redoSelection.isEmpty())
1080 select (redoSelection);
1083 parseAtom (redoCommand);
1086 blockSaveState=blockSaveStateOrg;
1088 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1089 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1090 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1091 undoSet.writeSettings(histPath);
1093 mainWindow->updateHistory (undoSet);
1096 /* TODO remove testing
1097 cout << "ME::redo() end\n";
1098 cout << " undosAvail="<<undosAvail<<endl;
1099 cout << " redosAvail="<<redosAvail<<endl;
1100 cout << " curStep="<<curStep<<endl;
1101 cout << " ---------------------------"<<endl<<endl;
1107 bool VymModel::isRedoAvailable()
1109 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1115 void VymModel::undo()
1117 // Can we undo at all?
1118 if (undosAvail<1) return;
1120 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1122 bool blockSaveStateOrg=blockSaveState;
1123 blockSaveState=true;
1125 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1126 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1127 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1128 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1129 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1130 QString version=undoSet.readEntry ("/history/version");
1132 /* TODO Maybe check for version, if we save the history
1133 if (!checkVersion(version))
1134 QMessageBox::warning(0,tr("Warning"),
1135 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1138 // Find out current undo directory
1139 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1141 // select object before undo
1142 if (!undoSelection.isEmpty())
1143 select (undoSelection);
1147 cout << "VymModel::undo() begin\n";
1148 cout << " undosAvail="<<undosAvail<<endl;
1149 cout << " redosAvail="<<redosAvail<<endl;
1150 cout << " curStep="<<curStep<<endl;
1151 cout << " ---------------------------"<<endl;
1152 cout << " comment="<<comment.toStdString()<<endl;
1153 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1154 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1155 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1156 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1157 cout << " ---------------------------"<<endl<<endl;
1159 parseAtom (undoCommand);
1164 if (curStep<1) curStep=stepsTotal;
1168 blockSaveState=blockSaveStateOrg;
1169 /* TODO remove testing
1170 cout << "VymModel::undo() end\n";
1171 cout << " undosAvail="<<undosAvail<<endl;
1172 cout << " redosAvail="<<redosAvail<<endl;
1173 cout << " curStep="<<curStep<<endl;
1174 cout << " ---------------------------"<<endl<<endl;
1177 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1178 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1179 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1180 undoSet.writeSettings(histPath);
1182 mainWindow->updateHistory (undoSet);
1185 emitShowSelection();
1188 bool VymModel::isUndoAvailable()
1190 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1196 void VymModel::gotoHistoryStep (int i)
1198 // Restore variables
1199 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1200 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1202 if (i<0) i=undosAvail+redosAvail;
1204 // Clicking above current step makes us undo things
1207 for (int j=0; j<undosAvail-i; j++) undo();
1210 // Clicking below current step makes us redo things
1212 for (int j=undosAvail; j<i; j++)
1214 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1218 // And ignore clicking the current row ;-)
1222 QString VymModel::getHistoryPath()
1224 QString histName(QString("history-%1").arg(curStep));
1225 return (tmpMapDir+"/"+histName);
1228 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1230 sendData(redoCom); //FIXME-3 testing
1235 if (blockSaveState) return;
1237 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1239 // Find out current undo directory
1240 if (undosAvail<stepsTotal) undosAvail++;
1242 if (curStep>stepsTotal) curStep=1;
1244 QString backupXML="";
1245 QString histDir=getHistoryPath();
1246 QString bakMapPath=histDir+"/map.xml";
1248 // Create histDir if not available
1251 makeSubDirs (histDir);
1253 // Save depending on how much needs to be saved
1255 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1257 QString undoCommand="";
1258 if (savemode==UndoCommand)
1260 undoCommand=undoCom;
1262 else if (savemode==PartOfMap )
1264 undoCommand=undoCom;
1265 undoCommand.replace ("PATH",bakMapPath);
1269 if (!backupXML.isEmpty())
1270 // Write XML Data to disk
1271 saveStringToDisk (bakMapPath,backupXML);
1273 // We would have to save all actions in a tree, to keep track of
1274 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1277 // Write the current state to disk
1278 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1279 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1280 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1281 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1282 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1283 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1284 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1285 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1286 undoSet.setEntry (QString("/history/version"),vymVersion);
1287 undoSet.writeSettings(histPath);
1291 // TODO remove after testing
1292 //cout << " into="<< histPath.toStdString()<<endl;
1293 cout << " stepsTotal="<<stepsTotal<<
1294 ", undosAvail="<<undosAvail<<
1295 ", redosAvail="<<redosAvail<<
1296 ", curStep="<<curStep<<endl;
1297 cout << " ---------------------------"<<endl;
1298 cout << " comment="<<comment.toStdString()<<endl;
1299 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1300 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1301 cout << " redoCom="<<redoCom.toStdString()<<endl;
1302 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1303 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1304 cout << " ---------------------------"<<endl;
1307 mainWindow->updateHistory (undoSet);
1313 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1315 // save the selected part of the map, Undo will replace part of map
1316 QString undoSelection="";
1318 undoSelection=getSelectString(undoSel);
1320 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1321 QString redoSelection="";
1323 redoSelection=getSelectString(undoSel);
1325 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1328 saveState (PartOfMap,
1329 undoSelection, "addMapReplace (\"PATH\")",
1335 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1339 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1342 QString undoSelection=getSelectString (redoSel->parent() );
1343 QString redoSelection=getSelectString(redoSel);
1344 if (redoSel->getType()==TreeItem::Branch)
1346 // save the selected branch of the map, Undo will insert part of map
1347 saveState (PartOfMap,
1348 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1349 redoSelection, "delete ()",
1356 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1358 // "Normal" savestate: save commands, selections and comment
1359 // so just save commands for undo and redo
1360 // and use current selection
1362 QString redoSelection="";
1363 if (redoSel) redoSelection=getSelectString(redoSel);
1364 QString undoSelection="";
1365 if (undoSel) undoSelection=getSelectString(undoSel);
1367 saveState (UndoCommand,
1374 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1376 // "Normal" savestate: save commands, selections and comment
1377 // so just save commands for undo and redo
1378 // and use current selection
1379 saveState (UndoCommand,
1386 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1388 // "Normal" savestate applied to model (no selection needed):
1389 // save commands and comment
1390 saveState (UndoCommand,
1398 QGraphicsScene* VymModel::getScene ()
1403 TreeItem* VymModel::findBySelectString(QString s)
1405 if (s.isEmpty() ) return NULL;
1407 // Old maps don't have multiple mapcenters and don't save full path
1408 if (s.left(2) !="mc")
1411 QStringList parts=s.split (",");
1414 TreeItem *ti=rootItem;
1416 while (!parts.isEmpty() )
1418 typ=parts.first().left(2);
1419 n=parts.first().right(parts.first().length() - 3).toInt();
1420 parts.removeFirst();
1421 if (typ=="mc" || typ=="bo")
1422 ti=ti->getBranchNum (n);
1426 ti=ti->getImageNum (n);
1432 TreeItem* VymModel::findID (const QString &s)
1435 for (int i=0; i<rootItem->branchCount(); i++)
1437 ti=rootItem->getBranchNum(i)->findID (s);
1443 //////////////////////////////////////////////
1445 //////////////////////////////////////////////
1446 void VymModel::setVersion (const QString &s)
1451 void VymModel::setAuthor (const QString &s)
1454 QString ("setMapAuthor (\"%1\")").arg(author),
1455 QString ("setMapAuthor (\"%1\")").arg(s),
1456 QString ("Set author of map to \"%1\"").arg(s)
1461 QString VymModel::getAuthor()
1466 void VymModel::setComment (const QString &s)
1469 QString ("setMapComment (\"%1\")").arg(comment),
1470 QString ("setMapComment (\"%1\")").arg(s),
1471 QString ("Set comment of map")
1476 QString VymModel::getComment ()
1481 QString VymModel::getDate ()
1483 return QDate::currentDate().toString ("yyyy-MM-dd");
1486 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1489 BranchItem *cur=NULL;
1490 BranchItem *prev=NULL;
1501 void VymModel::setHeading(const QString &s)
1503 BranchItem *selbi=getSelectedBranchItem();
1508 "setHeading (\""+selbi->getHeading()+"\")",
1510 "setHeading (\""+s+"\")",
1511 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1512 selbi->setHeading(s );
1513 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1516 // selection.update(); //FIXME-4
1521 BranchItem* VymModel::findText (QString s, bool cs)
1524 QTextDocument::FindFlags flags=0;
1525 if (cs) flags=QTextDocument::FindCaseSensitively;
1528 { // Nothing found or new find process
1530 // nothing found, start again
1534 next (findCurrent,findPrevious,d);
1536 bool searching=true;
1537 bool foundNote=false;
1538 while (searching && !EOFind)
1542 // Searching in Note
1543 if (findCurrent->getNote().contains(s,cs))
1545 select (findCurrent);
1547 if (getSelectedBranch()!=itFind)
1550 emitShowSelection();
1553 if (textEditor->findText(s,flags))
1559 // Searching in Heading
1560 if (searching && findCurrent->getHeading().contains (s,cs) )
1562 select(findCurrent);
1568 if (!next(findCurrent,findPrevious,d) )
1571 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1574 return getSelectedBranchItem();
1579 void VymModel::findReset()
1580 { // Necessary if text to find changes during a find process
1586 void VymModel::setScene (QGraphicsScene *s)
1588 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1589 //init(); // Here we have a mapScene set,
1590 // which is (still) needed to create MapCenters
1593 void VymModel::setURL(const QString &url)
1595 TreeItem *selti=getSelectedItem();
1598 QString oldurl=selti->getURL();
1599 selti->setURL (url);
1602 QString ("setURL (\"%1\")").arg(oldurl),
1604 QString ("setURL (\"%1\")").arg(url),
1605 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1608 emitDataHasChanged (selti);
1609 emitShowSelection();
1613 QString VymModel::getURL()
1615 TreeItem *selti=getSelectedItem();
1617 return selti->getURL();
1622 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1624 return QStringList();
1627 BranchObj *bo=getSelectedBranch();
1633 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1641 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1643 FloatImageObj *fio=selection.getFloatImage();
1646 TreeItem *dst=findBySelectString (dstString);
1647 if (dst && dst->isBranchLikeType() )
1649 TreeItem *dstPar=dst->parent();
1650 QString parString=getSelectString(dstPar);
1651 QString fioPreSelectString=getSelectString(fio);
1652 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1653 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1655 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1656 fio=((BranchObj*)dst)->getLastFloatImage();
1661 getSelectString(fio),
1662 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1664 QString ("linkTo (\"%1\")").arg(dstString),
1665 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1671 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1674 BranchObj *bo=getSelectedBranch();
1677 QString s=bo->getFrameTypeName();
1678 bo->setFrameType (t);
1679 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1680 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1687 void VymModel::setFrameType(const QString &s) //FIXME-2
1690 BranchObj *bo=getSelectedBranch();
1693 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1694 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1695 bo->setFrameType (s);
1702 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1705 BranchObj *bo=getSelectedBranch();
1708 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1709 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1710 bo->setFramePenColor (c);
1715 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1718 BranchObj *bo=getSelectedBranch();
1721 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1722 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1723 bo->setFrameBrushColor (c);
1727 void VymModel::setFramePadding (const int &i) //FIXME-2
1730 BranchObj *bo=getSelectedBranch();
1733 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1734 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1735 bo->setFramePadding (i);
1742 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1745 BranchObj *bo=getSelectedBranch();
1748 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1749 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1750 bo->setFrameBorderWidth (i);
1757 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1760 BranchObj *bo=getSelectedBranch();
1763 QString u= b ? "false" : "true";
1764 QString r=!b ? "false" : "true";
1768 QString("setIncludeImagesVertically (%1)").arg(u),
1770 QString("setIncludeImagesVertically (%1)").arg(r),
1771 QString("Include images vertically in %1").arg(getObjectName(bo))
1773 bo->setIncludeImagesVer(b);
1778 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1781 BranchObj *bo=getSelectedBranch();
1784 QString u= b ? "false" : "true";
1785 QString r=!b ? "false" : "true";
1789 QString("setIncludeImagesHorizontally (%1)").arg(u),
1791 QString("setIncludeImagesHorizontally (%1)").arg(r),
1792 QString("Include images horizontally in %1").arg(getObjectName(bo))
1794 bo->setIncludeImagesHor(b);
1800 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1803 LinkableMapObj *sel=getSelectedLMO();
1805 (selectionType() == TreeItem::Branch ||
1806 selectionType() == TreeItem::MapCenter ||
1807 selectionType() == TreeItem::Image ))
1809 QString u= b ? "false" : "true";
1810 QString r=!b ? "false" : "true";
1814 QString("setHideLinkUnselected (%1)").arg(u),
1816 QString("setHideLinkUnselected (%1)").arg(r),
1817 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1819 sel->setHideLinkUnselected(b);
1824 void VymModel::setHideExport(bool b)
1826 BranchItem *bi=getSelectedBranchItem();
1829 bi->setHideInExport (b);
1830 QString u= b ? "false" : "true";
1831 QString r=!b ? "false" : "true";
1835 QString ("setHideExport (%1)").arg(u),
1837 QString ("setHideExport (%1)").arg(r),
1838 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1842 // selection.update();
1843 // FIXME-3 VM needed? scene()->update();
1847 void VymModel::toggleHideExport()
1849 BranchItem *selbi=getSelectedBranchItem();
1851 setHideExport ( !selbi->hideInExport() );
1855 void VymModel::copy()
1857 TreeItem *selti=getSelectedItem();
1859 (selti->getType() == TreeItem::Branch ||
1860 selti->getType() == TreeItem::MapCenter ||
1861 selti->getType() == TreeItem::Image ))
1863 if (redosAvail == 0)
1866 QString s=getSelectString(selti);
1867 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1868 curClipboard=curStep;
1871 // Copy also to global clipboard, because we are at last step in history
1872 QString bakMapName(QString("history-%1").arg(curStep));
1873 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1874 copyDir (bakMapDir,clipboardDir );
1876 clipboardEmpty=false;
1882 void VymModel::pasteNoSave(const int &n)
1884 bool old=blockSaveState;
1885 blockSaveState=true;
1886 bool zippedOrg=zipped;
1887 if (redosAvail > 0 || n!=0)
1889 // Use the "historical" buffer
1890 QString bakMapName(QString("history-%1").arg(n));
1891 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1892 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1894 // Use the global buffer
1895 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1900 void VymModel::paste()
1902 BranchItem *selbi=getSelectedBranchItem();
1905 saveStateChangingPart(
1908 QString ("paste (%1)").arg(curClipboard),
1909 QString("Paste to %1").arg( getObjectName(selbi))
1916 void VymModel::cut()
1918 TreeItem *selti=getSelectedItem();
1919 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1927 void VymModel::moveUp()
1929 BranchItem *selbi=getSelectedBranchItem();
1932 if (!selbi->canMoveUp()) return;
1933 QString oldsel=getSelectString();
1934 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1936 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1940 void VymModel::moveDown()
1942 BranchItem *selbi=getSelectedBranchItem();
1945 if (!selbi->canMoveDown()) return;
1946 QString oldsel=getSelectString();
1947 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1949 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1953 void VymModel::sortChildren() // FIXME-2 not implemented yet
1956 BranchObj* bo=getSelectedBranch();
1959 if(treeItem->branchCount()>1)
1961 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1964 emitShowSelection();
1970 MapCenterItem* VymModel::createMapCenter()
1972 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
1977 BranchItem* VymModel::createBranch()
1979 return addNewBranchInt (-2);
1982 TreeItem* VymModel::createImage() //FIXME-2
1985 BranchObj *bo=getSelectedBranch();
1988 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1991 QList<QVariant> cData;
1992 cData << "VM:createImage" << "undef"<<"undef";
1993 TreeItem *parti=bo->getTreeItem();
1994 TreeItem *ti=new TreeItem (cData,parti);
1995 ti->setLMO (newfio);
1996 ti->setType (TreeItem::Image);
1997 parti->appendChild (ti);
2001 newfio->setTreeItem (ti);
2002 select (newfio); // FIXME-2 VM really needed here?
2010 MapCenterItem* VymModel::addMapCenter ()
2012 MapCenterItem *mci=addMapCenter (contextPos);
2013 //FIXME-3 selection.select (mco);
2015 emitShowSelection();
2020 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2021 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2026 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2030 QModelIndex parix=index(rootItem);
2032 int n=rootItem->branchCount();
2034 emit (layoutAboutToBeChanged() );
2035 beginInsertRows (parix,n,n+1);
2037 QList<QVariant> cData;
2038 cData << "VM:addMapCenter" << "undef"<<"undef";
2039 MapCenterItem *mci=new MapCenterItem (cData);
2040 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2041 rootItem->appendChild (mci);
2044 emit (layoutChanged() );
2047 BranchObj *newbo=mci->createMapObj(mapScene);
2051 if (!mci->getHeading().isEmpty() )
2053 newbo->updateHeading();
2054 newbo->setColor (headingColor);
2058 //newbo->updateLink(); //FIXME-3
2061 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2062 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2063 mci->setLMO (mapCenter);
2064 mapCenter->updateHeading();
2065 mapCenter->move (absPos);
2066 mapCenter->setVisibility (true);
2067 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2072 BranchItem* VymModel::addNewBranchInt(int num)
2074 // Depending on pos:
2075 // -3 insert in children of parent above selection
2076 // -2 add branch to selection
2077 // -1 insert in children of parent below selection
2078 // 0..n insert in children of parent at pos
2079 BranchItem *selbi=getSelectedBranchItem();
2083 QList<QVariant> cData;
2084 cData << "new" << "undef"<<"undef";
2089 BranchItem *newbi=new BranchItem (cData);
2090 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2092 emit (layoutAboutToBeChanged() );
2098 n=parbi->childCount();
2099 beginInsertRows (parix,n,n+1);
2100 parbi->appendChild (newbi);
2104 // insert below selection
2105 parbi=(BranchItem*)selbi->parent();
2107 n=selbi->childNumber()+1;
2108 beginInsertRows (parix,n,n);
2109 parbi->insertBranch(n,newbi);
2113 // insert above selection
2114 parbi=(BranchItem*)selbi->parent();
2116 n=selbi->childNumber();
2117 beginInsertRows (parix,n,n);
2118 parbi->insertBranch(n,newbi);
2121 emit (layoutChanged() );
2123 // save scroll state. If scrolled, automatically select
2124 // new branch in order to tmp unscroll parent...
2125 newbi->createMapObj(mapScene);
2132 BranchItem* VymModel::addNewBranch(int pos)
2134 // Different meaning than num in addNewBranchInt!
2138 BranchItem *newbi=NULL;
2139 BranchItem *selbi=getSelectedBranchItem();
2143 // FIXME-3 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2145 newbi=addNewBranchInt (pos-2);
2153 QString ("addBranch (%1)").arg(pos),
2154 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2157 // selection.update(); FIXME-3
2158 latestAddedItem=newbi;
2159 // In Network mode, the client needs to know where the new branch is,
2160 // so we have to pass on this information via saveState.
2161 // TODO: Get rid of this positioning workaround
2162 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2163 sendData ("selectLatestAdded ()");
2164 sendData (QString("move %1").arg(ps));
2173 BranchItem* VymModel::addNewBranchBefore() //FIXME-2
2176 BranchObj *newbo=NULL;
2177 BranchObj *bo = getSelectedBranch();
2178 if (bo && selectionType()==TreeItem::Branch)
2179 // We accept no MapCenterObj here, so we _have_ a parent
2181 QPointF p=bo->getRelPos();
2184 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2186 // add below selection
2187 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2191 newbo->move2RelPos (p);
2193 // Move selection to new branch
2194 bo->linkTo (newbo,-1);
2196 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2197 QString ("Add branch before %1").arg(getObjectName(bo)));
2200 // selection.update(); FIXME-3
2203 latestSelectionString=selection.getSelectString();
2209 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2213 emit (layoutAboutToBeChanged() );
2214 BranchItem *branchpi=(BranchItem*)branch->parent();
2215 // Remove at current position
2216 int n=branch->childNum();
2217 beginRemoveRows (index(branchpi),n,n);
2218 branchpi->removeChild (n);
2221 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2223 // Append as last branch to dst
2224 if (dst->branchCount()==0)
2227 n=dst->getFirstBranch()->childNumber();
2228 beginInsertRows (index(dst),n+pos,n+pos);
2229 dst->insertBranch (pos,branch);
2232 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2233 emit (layoutChanged() );
2234 reposition(); // both for moveUp/Down and relinking
2241 void VymModel::deleteSelection()
2243 BranchItem *selbi=getSelectedBranchItem();
2247 TreeItem *pi=selbi->parent();
2248 QModelIndex parentIndex=index(pi);
2250 if (selbi->isBranchLikeType() )
2253 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2255 emit (layoutAboutToBeChanged() );
2257 int n=selbi->childNum();
2258 beginRemoveRows (parentIndex,n,n);
2259 removeRows (n,1,parentIndex);
2262 emitShowSelection();
2265 emit (layoutChanged() );
2268 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2273 BranchObj* par=(BranchObj*)fio->getParObj();
2274 saveStateChangingPart(
2278 QString("Delete %1").arg(getObjectName(fio))
2281 par->removeFloatImage(fio);
2284 emitShowSelection();
2290 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2294 BranchObj *bo=getSelectedBranch();
2298 par=(BranchObj*)(bo->getParObj());
2300 // Don't use this on mapcenter
2303 // Check if we have childs at all to keep
2304 if (bo->getTreeItem()->branchCount()==0)
2310 QPointF p=bo->getRelPos();
2311 saveStateChangingPart(
2314 "deleteKeepChildren ()",
2315 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2318 QString sel=getSelectString(bo);
2320 par->removeBranchHere(bo);
2323 getSelectedBranch()->move2RelPos (p);
2328 void VymModel::deleteChildren() //FIXME-2 VM still missing
2332 BranchObj *bo=getSelectedBranch();
2335 saveStateChangingPart(
2338 "deleteChildren ()",
2339 QString( "Remove children of branch %1").arg(getObjectName(bo))
2341 bo->removeChildren();
2347 bool VymModel::scrollBranch(BranchItem *bi)
2351 if (bi->isScrolled()) return false;
2352 if (bi->branchCount()==0) return false;
2353 if (bi->depth()==0) return false;
2354 if (bi->toggleScroll())
2361 QString ("%1 ()").arg(u),
2363 QString ("%1 ()").arg(r),
2364 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2366 emitDataHasChanged(bi);
2368 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2375 bool VymModel::unscrollBranch(BranchItem *bi)
2379 if (!bi->isScrolled()) return false;
2380 if (bi->branchCount()==0) return false;
2381 if (bi->depth()==0) return false;
2388 QString ("%1 ()").arg(u),
2390 QString ("%1 ()").arg(r),
2391 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2394 emitDataHasChanged(bi);
2397 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2403 void VymModel::toggleScroll()
2405 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2406 if (bi && bi->isBranchLikeType() )
2408 if (bi->isScrolled())
2409 unscrollBranch (bi);
2413 // saveState is called in above functions
2416 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2420 BranchObj *bo=getSelectedBranch();
2426 if (bo->isScrolled()) unscrollBranch (bo);
2433 void VymModel::emitExpandAll()
2435 emit (expandAll() );
2438 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2440 BranchItem *bi=getSelectedBranchItem();
2444 if (bi->isActiveStandardFlag(name))
2456 QString("%1 (\"%2\")").arg(u).arg(name),
2458 QString("%1 (\"%2\")").arg(r).arg(name),
2459 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2460 bi->toggleStandardFlag (name, master);
2466 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2469 BranchObj *bo=getSelectedBranch();
2472 FloatImageObj *fio=bo->addFloatImage();
2474 fio->setOriginalFilename("No original filename (image added by dropevent)");
2475 QString s=getSelectString(bo);
2476 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2477 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2479 // FIXME-3 VM needed? scene()->update();
2485 void VymModel::colorBranch (QColor c) //FIXME-2
2488 BranchObj *bo=getSelectedBranch();
2493 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2495 QString ("colorBranch (\"%1\")").arg(c.name()),
2496 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2498 bo->setColor(c); // color branch
2503 void VymModel::colorSubtree (QColor c) //FIXME-2
2506 BranchObj *bo=getSelectedBranch();
2509 saveStateChangingPart(
2512 QString ("colorSubtree (\"%1\")").arg(c.name()),
2513 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2515 bo->setColorSubtree (c); // color links, color children
2520 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2523 BranchObj *bo=getSelectedBranch();
2524 if (bo) return bo->getColor();
2526 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2533 void VymModel::editURL()
2535 TreeItem *selti=getSelectedItem();
2539 QString text = QInputDialog::getText(
2540 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2541 selti->getURL(), &ok, NULL);
2543 // user entered something and pressed OK
2548 void VymModel::editLocalURL()
2550 TreeItem *selti=getSelectedItem();
2553 QStringList filters;
2554 filters <<"All files (*)";
2555 filters << tr("Text","Filedialog") + " (*.txt)";
2556 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2557 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2558 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2559 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2560 fd->setFilters (filters);
2561 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2562 fd->setDirectory (lastFileDir);
2563 if (! selti->getVymLink().isEmpty() )
2564 fd->selectFile( selti->getURL() );
2567 if ( fd->exec() == QDialog::Accepted )
2569 lastFileDir=QDir (fd->directory().path());
2570 setURL (fd->selectedFile() );
2576 void VymModel::editHeading2URL()
2578 TreeItem *selti=getSelectedItem();
2580 setURL (selti->getHeading());
2583 void VymModel::editBugzilla2URL()
2585 TreeItem *selti=getSelectedItem();
2588 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2593 void VymModel::editFATE2URL()
2595 TreeItem *selti=getSelectedItem();
2598 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2601 "setURL (\""+selti->getURL()+"\")",
2603 "setURL (\""+url+"\")",
2604 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2606 selti->setURL (url);
2607 // FIXME-4 updateActions();
2611 void VymModel::editVymLink()
2613 BranchItem *bi=getSelectedBranchItem();
2616 QStringList filters;
2617 filters <<"VYM map (*.vym)";
2618 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2619 fd->setFilters (filters);
2620 fd->setCaption(vymName+" - " +tr("Link to another map"));
2621 fd->setDirectory (lastFileDir);
2622 if (! bi->getVymLink().isEmpty() )
2623 fd->selectFile( bi->getVymLink() );
2627 if ( fd->exec() == QDialog::Accepted )
2629 lastFileDir=QDir (fd->directory().path());
2632 "setVymLink (\""+bi->getVymLink()+"\")",
2634 "setVymLink (\""+fd->selectedFile()+"\")",
2635 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2637 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2642 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2644 // Internal function, no saveState needed
2645 BranchItem *bi=getSelectedBranchItem();
2651 //selection.update();
2652 emitShowSelection();
2656 void VymModel::deleteVymLink()
2658 BranchItem *bi=getSelectedBranchItem();
2663 "setVymLink (\""+bi->getVymLink()+"\")",
2665 "setVymLink (\"\")",
2666 QString("Unset vymlink of %1").arg(getObjectName(bi))
2668 bi->setVymLink ("" );
2674 QString VymModel::getVymLink()
2676 BranchItem *bi=getSelectedBranchItem();
2678 return bi->getVymLink();
2684 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2686 return QStringList();
2689 BranchObj *bo=getSelectedBranch();
2695 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2704 void VymModel::followXLink(int i) // FIXME-2
2708 BranchObj *bo=getSelectedBranch();
2711 bo=bo->XLinkTargetAt(i);
2714 selection.select(bo);
2715 emitShowSelection();
2721 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2725 BranchObj *bo=getSelectedBranch();
2728 XLinkObj *xlo=bo->XLinkAt(i);
2731 EditXLinkDialog dia;
2733 dia.setSelection(bo);
2734 if (dia.exec() == QDialog::Accepted)
2736 if (dia.useSettingsGlobal() )
2738 setMapDefXLinkColor (xlo->getColor() );
2739 setMapDefXLinkWidth (xlo->getWidth() );
2741 if (dia.deleteXLink())
2742 bo->deleteXLinkAt(i);
2753 //////////////////////////////////////////////
2755 //////////////////////////////////////////////
2757 void VymModel::parseAtom(const QString &atom)
2759 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2760 TreeItem* selti=getSelectedItem();
2761 BranchItem *selbi=getSelectedBranchItem();
2767 // Split string s into command and parameters
2768 parser.parseAtom (atom);
2769 QString com=parser.getCommand();
2771 // External commands
2772 /////////////////////////////////////////////////////////////////////
2773 if (com=="addBranch")
2777 parser.setError (Aborted,"Nothing selected");
2778 } else if (! selbi )
2780 parser.setError (Aborted,"Type of selection is not a branch");
2785 if (parser.checkParCount(pl))
2787 if (parser.parCount()==0)
2791 n=parser.parInt (ok,0);
2792 if (ok ) addNewBranch (n);
2796 /////////////////////////////////////////////////////////////////////
2797 } else if (com=="addBranchBefore")
2801 parser.setError (Aborted,"Nothing selected");
2802 } else if (! selbi )
2804 parser.setError (Aborted,"Type of selection is not a branch");
2807 if (parser.parCount()==0)
2809 addNewBranchBefore ();
2812 /////////////////////////////////////////////////////////////////////
2813 } else if (com==QString("addMapCenter"))
2815 if (parser.checkParCount(2))
2817 x=parser.parDouble (ok,0);
2820 y=parser.parDouble (ok,1);
2821 if (ok) addMapCenter (QPointF(x,y));
2824 /////////////////////////////////////////////////////////////////////
2825 } else if (com==QString("addMapReplace"))
2829 parser.setError (Aborted,"Nothing selected");
2830 } else if (! selbi )
2832 parser.setError (Aborted,"Type of selection is not a branch");
2833 } else if (parser.checkParCount(1))
2835 //s=parser.parString (ok,0); // selection
2836 t=parser.parString (ok,0); // path to map
2837 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2838 addMapReplaceInt(getSelectString(selbi),t);
2840 /////////////////////////////////////////////////////////////////////
2841 } else if (com==QString("addMapInsert"))
2845 parser.setError (Aborted,"Nothing selected");
2846 } else if (! selbi )
2848 parser.setError (Aborted,"Type of selection is not a branch");
2851 if (parser.checkParCount(2))
2853 t=parser.parString (ok,0); // path to map
2854 n=parser.parInt(ok,1); // position
2855 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2856 addMapInsertInt(t,n);
2859 /////////////////////////////////////////////////////////////////////
2860 } else if (com=="clearFlags")
2864 parser.setError (Aborted,"Nothing selected");
2865 } else if (! selbi )
2867 parser.setError (Aborted,"Type of selection is not a branch");
2868 } else if (parser.checkParCount(0))
2870 selbi->deactivateAllStandardFlags();
2872 /////////////////////////////////////////////////////////////////////
2873 } else if (com=="colorBranch")
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(1))
2883 QColor c=parser.parColor (ok,0);
2884 if (ok) colorBranch (c);
2886 /////////////////////////////////////////////////////////////////////
2887 } else if (com=="colorSubtree")
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) colorSubtree (c);
2900 /////////////////////////////////////////////////////////////////////
2901 } else if (com=="copy")
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(0))
2911 //FIXME-1 missing action for copy
2913 /////////////////////////////////////////////////////////////////////
2914 } else if (com=="cut")
2918 parser.setError (Aborted,"Nothing selected");
2919 } else if ( selectionType()!=TreeItem::Branch &&
2920 selectionType()!=TreeItem::MapCenter &&
2921 selectionType()!=TreeItem::Image )
2923 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2924 } else if (parser.checkParCount(0))
2928 /////////////////////////////////////////////////////////////////////
2929 } else if (com=="delete")
2933 parser.setError (Aborted,"Nothing selected");
2935 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2937 parser.setError (Aborted,"Type of selection is wrong.");
2940 else if (parser.checkParCount(0))
2944 /////////////////////////////////////////////////////////////////////
2945 } else if (com=="deleteKeepChildren")
2949 parser.setError (Aborted,"Nothing selected");
2950 } else if (! selbi )
2952 parser.setError (Aborted,"Type of selection is not a branch");
2953 } else if (parser.checkParCount(0))
2955 deleteKeepChildren();
2957 /////////////////////////////////////////////////////////////////////
2958 } else if (com=="deleteChildren")
2962 parser.setError (Aborted,"Nothing selected");
2965 parser.setError (Aborted,"Type of selection is not a branch");
2966 } else if (parser.checkParCount(0))
2970 /////////////////////////////////////////////////////////////////////
2971 } else if (com=="exportASCII")
2975 if (parser.parCount()>=1)
2976 // Hey, we even have a filename
2977 fname=parser.parString(ok,0);
2980 parser.setError (Aborted,"Could not read filename");
2983 exportASCII (fname,false);
2985 /////////////////////////////////////////////////////////////////////
2986 } else if (com=="exportImage")
2990 if (parser.parCount()>=2)
2991 // Hey, we even have a filename
2992 fname=parser.parString(ok,0);
2995 parser.setError (Aborted,"Could not read filename");
2998 QString format="PNG";
2999 if (parser.parCount()>=2)
3001 format=parser.parString(ok,1);
3003 exportImage (fname,false,format);
3005 /////////////////////////////////////////////////////////////////////
3006 } else if (com=="exportXHTML")
3010 if (parser.parCount()>=2)
3011 // Hey, we even have a filename
3012 fname=parser.parString(ok,1);
3015 parser.setError (Aborted,"Could not read filename");
3018 exportXHTML (fname,false);
3020 /////////////////////////////////////////////////////////////////////
3021 } else if (com=="exportXML")
3025 if (parser.parCount()>=2)
3026 // Hey, we even have a filename
3027 fname=parser.parString(ok,1);
3030 parser.setError (Aborted,"Could not read filename");
3033 exportXML (fname,false);
3035 /////////////////////////////////////////////////////////////////////
3036 } else if (com=="importDir")
3040 parser.setError (Aborted,"Nothing selected");
3041 } else if (! selbi )
3043 parser.setError (Aborted,"Type of selection is not a branch");
3044 } else if (parser.checkParCount(1))
3046 s=parser.parString(ok,0);
3047 if (ok) importDirInt(s);
3049 /////////////////////////////////////////////////////////////////////
3050 } else /* FIXME-2 if (com=="linkTo")
3054 parser.setError (Aborted,"Nothing selected");
3057 if (parser.checkParCount(4))
3059 // 0 selectstring of parent
3060 // 1 num in parent (for branches)
3061 // 2,3 x,y of mainbranch or mapcenter
3062 s=parser.parString(ok,0);
3063 LinkableMapObj *dst=findObjBySelect (s);
3066 if (typeid(*dst) == typeid(BranchObj) )
3068 // Get number in parent
3069 n=parser.parInt (ok,1);
3072 selb->linkTo ((BranchObj*)(dst),n);
3075 } else if (typeid(*dst) == typeid(MapCenterObj) )
3077 selb->linkTo ((BranchObj*)(dst),-1);
3078 // Get coordinates of mainbranch
3079 x=parser.parDouble(ok,2);
3082 y=parser.parDouble(ok,3);
3092 } else if ( selectionType() == TreeItem::Image)
3094 if (parser.checkParCount(1))
3096 // 0 selectstring of parent
3097 s=parser.parString(ok,0);
3098 LinkableMapObj *dst=findObjBySelect (s);
3101 if (typeid(*dst) == typeid(BranchObj) ||
3102 typeid(*dst) == typeid(MapCenterObj))
3103 linkFloatImageTo (getSelectString(dst));
3105 parser.setError (Aborted,"Destination is not a branch");
3108 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3109 /////////////////////////////////////////////////////////////////////
3110 } else */ if (com=="loadImage")
3114 parser.setError (Aborted,"Nothing selected");
3115 } else if (! selbi )
3117 parser.setError (Aborted,"Type of selection is not a branch");
3118 } else if (parser.checkParCount(1))
3120 s=parser.parString(ok,0);
3121 if (ok) loadFloatImageInt (s);
3123 /////////////////////////////////////////////////////////////////////
3124 } else if (com=="moveUp")
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(0))
3136 /////////////////////////////////////////////////////////////////////
3137 } else if (com=="moveDown")
3141 parser.setError (Aborted,"Nothing selected");
3142 } else if (! selbi )
3144 parser.setError (Aborted,"Type of selection is not a branch");
3145 } else if (parser.checkParCount(0))
3149 /////////////////////////////////////////////////////////////////////
3150 } else if (com=="move")
3154 parser.setError (Aborted,"Nothing selected");
3155 } else if ( selectionType()!=TreeItem::Branch &&
3156 selectionType()!=TreeItem::MapCenter &&
3157 selectionType()!=TreeItem::Image )
3159 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3160 } else if (parser.checkParCount(2))
3162 x=parser.parDouble (ok,0);
3165 y=parser.parDouble (ok,1);
3169 /////////////////////////////////////////////////////////////////////
3170 } else if (com=="moveRel")
3174 parser.setError (Aborted,"Nothing selected");
3175 } else if ( selectionType()!=TreeItem::Branch &&
3176 selectionType()!=TreeItem::MapCenter &&
3177 selectionType()!=TreeItem::Image )
3179 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3180 } else if (parser.checkParCount(2))
3182 x=parser.parDouble (ok,0);
3185 y=parser.parDouble (ok,1);
3186 if (ok) moveRel (x,y);
3189 /////////////////////////////////////////////////////////////////////
3190 } else if (com=="nop")
3192 /////////////////////////////////////////////////////////////////////
3193 } else if (com=="paste")
3197 parser.setError (Aborted,"Nothing selected");
3198 } else if (! selbi )
3200 parser.setError (Aborted,"Type of selection is not a branch");
3201 } else if (parser.checkParCount(1))
3203 n=parser.parInt (ok,0);
3204 if (ok) pasteNoSave(n);
3206 /////////////////////////////////////////////////////////////////////
3207 } else if (com=="qa")
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(4))
3218 c=parser.parString (ok,0);
3221 parser.setError (Aborted,"No comment given");
3224 s=parser.parString (ok,1);
3227 parser.setError (Aborted,"First parameter is not a string");
3230 t=parser.parString (ok,2);
3233 parser.setError (Aborted,"Condition is not a string");
3236 u=parser.parString (ok,3);
3239 parser.setError (Aborted,"Third parameter is not a string");
3244 parser.setError (Aborted,"Unknown type: "+s);
3249 parser.setError (Aborted,"Unknown operator: "+t);
3254 parser.setError (Aborted,"Type of selection is not a branch");
3257 if (selbi->getHeading() == u)
3259 cout << "PASSED: " << qPrintable (c) << endl;
3262 cout << "FAILED: " << qPrintable (c) << endl;
3272 /////////////////////////////////////////////////////////////////////
3273 } else if (com=="saveImage")
3275 FloatImageObj *fio=selection.getFloatImage();
3278 parser.setError (Aborted,"Type of selection is not an image");
3279 } else if (parser.checkParCount(2))
3281 s=parser.parString(ok,0);
3284 t=parser.parString(ok,1);
3285 if (ok) saveFloatImageInt (fio,t,s);
3288 /////////////////////////////////////////////////////////////////////
3289 } else if (com=="scroll")
3293 parser.setError (Aborted,"Nothing selected");
3294 } else if (! selbi )
3296 parser.setError (Aborted,"Type of selection is not a branch");
3297 } else if (parser.checkParCount(0))
3299 if (!scrollBranch (selbi))
3300 parser.setError (Aborted,"Could not scroll branch");
3302 /////////////////////////////////////////////////////////////////////
3303 } else if (com=="select")
3305 if (parser.checkParCount(1))
3307 s=parser.parString(ok,0);
3310 /////////////////////////////////////////////////////////////////////
3311 } else if (com=="selectLastBranch")
3315 parser.setError (Aborted,"Nothing selected");
3316 } else if (! selbi )
3318 parser.setError (Aborted,"Type of selection is not a branch");
3319 } else if (parser.checkParCount(0))
3321 BranchItem *bi=selbi->getLastBranch();
3323 parser.setError (Aborted,"Could not select last branch");
3324 select (bi); // FIXME-3 was selectInt
3327 /////////////////////////////////////////////////////////////////////
3328 } else /* FIXME-2 if (com=="selectLastImage")
3332 parser.setError (Aborted,"Nothing selected");
3333 } else if (! selbi )
3335 parser.setError (Aborted,"Type of selection is not a branch");
3336 } else if (parser.checkParCount(0))
3338 FloatImageObj *fio=selb->getLastFloatImage();
3340 parser.setError (Aborted,"Could not select last image");
3341 select (fio); // FIXME-3 was selectInt
3344 /////////////////////////////////////////////////////////////////////
3345 } else */ if (com=="selectLatestAdded")
3347 if (!latestAddedItem)
3349 parser.setError (Aborted,"No latest added object");
3352 if (!select (latestAddedItem))
3353 parser.setError (Aborted,"Could not select latest added object ");
3355 /////////////////////////////////////////////////////////////////////
3356 } else if (com=="setFrameType")
3358 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3360 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3362 else if (parser.checkParCount(1))
3364 s=parser.parString(ok,0);
3365 if (ok) setFrameType (s);
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="setFramePenColor")
3370 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3372 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3374 else if (parser.checkParCount(1))
3376 QColor c=parser.parColor(ok,0);
3377 if (ok) setFramePenColor (c);
3379 /////////////////////////////////////////////////////////////////////
3380 } else if (com=="setFrameBrushColor")
3382 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3384 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3386 else if (parser.checkParCount(1))
3388 QColor c=parser.parColor(ok,0);
3389 if (ok) setFrameBrushColor (c);
3391 /////////////////////////////////////////////////////////////////////
3392 } else if (com=="setFramePadding")
3394 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3396 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3398 else if (parser.checkParCount(1))
3400 n=parser.parInt(ok,0);
3401 if (ok) setFramePadding(n);
3403 /////////////////////////////////////////////////////////////////////
3404 } else if (com=="setFrameBorderWidth")
3406 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3408 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3410 else if (parser.checkParCount(1))
3412 n=parser.parInt(ok,0);
3413 if (ok) setFrameBorderWidth (n);
3415 /////////////////////////////////////////////////////////////////////
3416 } else if (com=="setMapAuthor")
3418 if (parser.checkParCount(1))
3420 s=parser.parString(ok,0);
3421 if (ok) setAuthor (s);
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="setMapComment")
3426 if (parser.checkParCount(1))
3428 s=parser.parString(ok,0);
3429 if (ok) setComment(s);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="setMapBackgroundColor")
3436 parser.setError (Aborted,"Nothing selected");
3437 } else if (! selbi )
3439 parser.setError (Aborted,"Type of selection is not a branch");
3440 } else if (parser.checkParCount(1))
3442 QColor c=parser.parColor (ok,0);
3443 if (ok) setMapBackgroundColor (c);
3445 /////////////////////////////////////////////////////////////////////
3446 } else if (com=="setMapDefLinkColor")
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) setMapDefLinkColor (c);
3459 /////////////////////////////////////////////////////////////////////
3460 } else if (com=="setMapLinkStyle")
3462 if (parser.checkParCount(1))
3464 s=parser.parString (ok,0);
3465 if (ok) setMapLinkStyle(s);
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="setHeading")
3472 parser.setError (Aborted,"Nothing selected");
3473 } else if (! selbi )
3475 parser.setError (Aborted,"Type of selection is not a branch");
3476 } else if (parser.checkParCount(1))
3478 s=parser.parString (ok,0);
3482 /////////////////////////////////////////////////////////////////////
3483 } else if (com=="setHideExport")
3487 parser.setError (Aborted,"Nothing selected");
3488 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3490 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3491 } else if (parser.checkParCount(1))
3493 b=parser.parBool(ok,0);
3494 if (ok) setHideExport (b);
3496 /////////////////////////////////////////////////////////////////////
3497 } else if (com=="setIncludeImagesHorizontally")
3501 parser.setError (Aborted,"Nothing selected");
3504 parser.setError (Aborted,"Type of selection is not a branch");
3505 } else if (parser.checkParCount(1))
3507 b=parser.parBool(ok,0);
3508 if (ok) setIncludeImagesHor(b);
3510 /////////////////////////////////////////////////////////////////////
3511 } else if (com=="setIncludeImagesVertically")
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) setIncludeImagesVer(b);
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="setHideLinkUnselected")
3529 parser.setError (Aborted,"Nothing selected");
3530 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3532 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3533 } else if (parser.checkParCount(1))
3535 b=parser.parBool(ok,0);
3536 if (ok) setHideLinkUnselected(b);
3538 /////////////////////////////////////////////////////////////////////
3539 } else if (com=="setSelectionColor")
3541 if (parser.checkParCount(1))
3543 QColor c=parser.parColor (ok,0);
3544 if (ok) setSelectionColorInt (c);
3546 /////////////////////////////////////////////////////////////////////
3547 } else if (com=="setURL")
3551 parser.setError (Aborted,"Nothing selected");
3552 } else if (! selbi )
3554 parser.setError (Aborted,"Type of selection is not a branch");
3555 } else if (parser.checkParCount(1))
3557 s=parser.parString (ok,0);
3560 /////////////////////////////////////////////////////////////////////
3561 } else if (com=="setVymLink")
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);
3572 if (ok) setVymLink(s);
3575 /////////////////////////////////////////////////////////////////////
3576 else if (com=="setFlag")
3580 parser.setError (Aborted,"Nothing selected");
3581 } else if (! selbi )
3583 parser.setError (Aborted,"Type of selection is not a branch");
3584 } else if (parser.checkParCount(1))
3586 s=parser.parString(ok,0);
3588 selbi->activateStandardFlag(s);
3590 /////////////////////////////////////////////////////////////////////
3591 } else /* FIXME-2 if (com=="setFrameType")
3595 parser.setError (Aborted,"Nothing selected");
3598 parser.setError (Aborted,"Type of selection is not a branch");
3599 } else if (parser.checkParCount(1))
3601 s=parser.parString(ok,0);
3605 /////////////////////////////////////////////////////////////////////
3606 } else*/ if (com=="sortChildren")
3610 parser.setError (Aborted,"Nothing selected");
3611 } else if (! selbi )
3613 parser.setError (Aborted,"Type of selection is not a branch");
3614 } else if (parser.checkParCount(0))
3618 /////////////////////////////////////////////////////////////////////
3619 } else if (com=="toggleFlag")
3623 parser.setError (Aborted,"Nothing selected");
3624 } else if (! selbi )
3626 parser.setError (Aborted,"Type of selection is not a branch");
3627 } else if (parser.checkParCount(1))
3629 s=parser.parString(ok,0);
3631 selbi->toggleStandardFlag(s);
3633 /////////////////////////////////////////////////////////////////////
3634 } else if (com=="unscroll")
3638 parser.setError (Aborted,"Nothing selected");
3639 } else if (! selbi )
3641 parser.setError (Aborted,"Type of selection is not a branch");
3642 } else if (parser.checkParCount(0))
3644 if (!unscrollBranch (selbi))
3645 parser.setError (Aborted,"Could not unscroll branch");
3647 /////////////////////////////////////////////////////////////////////
3648 } else if (com=="unscrollChildren")
3652 parser.setError (Aborted,"Nothing selected");
3653 } else if (! selbi )
3655 parser.setError (Aborted,"Type of selection is not a branch");
3656 } else if (parser.checkParCount(0))
3658 unscrollChildren ();
3660 /////////////////////////////////////////////////////////////////////
3661 } else if (com=="unsetFlag")
3665 parser.setError (Aborted,"Nothing selected");
3666 } else if (! selbi )
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(1))
3671 s=parser.parString(ok,0);
3673 selbi->deactivateStandardFlag(s);
3676 parser.setError (Aborted,"Unknown command");
3679 if (parser.errorLevel()==NoError)
3681 // setChanged(); FIXME-2 should not be called e.g. for export?!
3686 // TODO Error handling
3687 qWarning("VymModel::parseAtom: Error!");
3688 qWarning(parser.errorMessage());
3692 void VymModel::runScript (QString script)
3694 parser.setScript (script);
3696 while (parser.next() )
3697 parseAtom(parser.getAtom());
3700 void VymModel::setExportMode (bool b)
3702 // should be called before and after exports
3703 // depending on the settings
3704 if (b && settings.value("/export/useHideExport","true")=="true")
3705 setHideTmpMode (TreeItem::HideExport);
3707 setHideTmpMode (TreeItem::HideNone);
3710 void VymModel::exportImage(QString fname, bool askName, QString format)
3714 fname=getMapName()+".png";
3721 QFileDialog *fd=new QFileDialog (NULL);
3722 fd->setCaption (tr("Export map as image"));
3723 fd->setDirectory (lastImageDir);
3724 fd->setFileMode(QFileDialog::AnyFile);
3725 fd->setFilters (imageIO.getFilters() );
3728 fl=fd->selectedFiles();
3730 format=imageIO.getType(fd->selectedFilter());
3734 setExportMode (true);
3735 QPixmap pix (getPixmap());
3736 pix.save(fname, format);
3737 setExportMode (false);
3741 void VymModel::exportXML(QString dir, bool askForName)
3745 dir=browseDirectory(NULL,tr("Export XML to directory"));
3746 if (dir =="" && !reallyWriteDirectory(dir) )
3750 // Hide stuff during export, if settings want this
3751 setExportMode (true);
3753 // Create subdirectories
3756 // write to directory
3757 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3760 file.setName ( dir + "/"+mapName+".xml");
3761 if ( !file.open( QIODevice::WriteOnly ) )
3763 // This should neverever happen
3764 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3768 // Write it finally, and write in UTF8, no matter what
3769 QTextStream ts( &file );
3770 ts.setEncoding (QTextStream::UnicodeUTF8);
3774 // Now write image, too
3775 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3777 setExportMode (false);
3780 void VymModel::exportASCII(QString fname,bool askName)
3785 ex.setFile (mapName+".txt");
3791 //ex.addFilter ("TXT (*.txt)");
3792 ex.setDir(lastImageDir);
3793 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3798 setExportMode(true);
3800 setExportMode(false);
3804 void VymModel::exportXHTML (const QString &dir, bool askForName)
3806 ExportXHTMLDialog dia(NULL);
3807 dia.setFilePath (filePath );
3808 dia.setMapName (mapName );
3810 if (dir!="") dia.setDir (dir);
3816 if (dia.exec()!=QDialog::Accepted)
3820 QDir d (dia.getDir());
3821 // Check, if warnings should be used before overwriting
3822 // the output directory
3823 if (d.exists() && d.count()>0)
3826 warn.showCancelButton (true);
3827 warn.setText(QString(
3828 "The directory %1 is not empty.\n"
3829 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3830 warn.setCaption("Warning: Directory not empty");
3831 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3833 if (warn.exec()!=QDialog::Accepted) ok=false;
3840 exportXML (dia.getDir(),false );
3841 dia.doExport(mapName );
3842 //if (dia.hasChanged()) setChanged();
3846 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3851 if (ex.setConfigFile(cf))
3853 setExportMode (true);
3854 ex.exportPresentation();
3855 setExportMode (false);
3862 //////////////////////////////////////////////
3864 //////////////////////////////////////////////
3866 void VymModel::registerEditor(QWidget *me)
3868 mapEditor=(MapEditor*)me;
3871 void VymModel::unregisterEditor(QWidget *)
3876 void VymModel::setContextPos(QPointF p)
3881 void VymModel::unsetContextPos()
3883 contextPos=QPointF();
3886 void VymModel::updateNoteFlag()
3889 TreeItem *selti=getSelectedItem();
3892 if (textEditor->isEmpty())
3895 selti->setNote (textEditor->getText());
3896 emitDataHasChanged(selti);
3902 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3904 //cout << "VM::updateRelPos...\n";
3905 for (int i=0; i<rootItem->branchCount(); i++)
3906 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3909 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3911 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3912 if (blockReposition) return;
3914 for (int i=0;i<rootItem->branchCount(); i++)
3915 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3918 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3921 // Creating (arbitrary) shapes
3924 QRectF rb=bo->getBBox();
3925 if (bo->getDepth()==0)
3927 // Just take BBox of this mapCenter
3928 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3932 // Take union of BBox and TotalBBox
3934 QRectF ra=bo->getTotalBBox();
3935 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3938 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3941 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3943 p <<ra.bottomRight()
3945 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3948 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3953 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3957 // Move all branches and MapCenters away from lmo
3958 // to avoid collisions
3964 BranchObj *boA=(BranchObj*)lmo;
3966 for (int i=0; i<rootItem->branchCount(); i++)
3968 boB=rootItem->getBranchNum(i);
3971 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3974 <<" ("<<qPrintable(boA->getHeading() )<<")"
3975 <<" with ("<< qPrintable (boB->getHeading() )
3978 <<" minT="<<r.minTranslation<<endl<<endl;
3983 QPixmap VymModel::getPixmap()
3985 QRectF mapRect=getTotalBBox();
3986 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3989 pp.setRenderHints(mapEditor->renderHints());
3991 // Don't print the visualisation of selection
3992 selection.unselect();
3994 mapScene->render ( &pp,
3995 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3996 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3998 // Restore selection
3999 selection.reselect();
4005 void VymModel::setMapLinkStyle (const QString & s)
4010 case LinkableMapObj::Line :
4013 case LinkableMapObj::Parabel:
4014 snow="StyleParabel";
4016 case LinkableMapObj::PolyLine:
4017 snow="StylePolyLine";
4019 case LinkableMapObj::PolyParabel:
4020 snow="StylePolyParabel";
4023 snow="UndefinedStyle";
4028 QString("setMapLinkStyle (\"%1\")").arg(s),
4029 QString("setMapLinkStyle (\"%1\")").arg(snow),
4030 QString("Set map link style (\"%1\")").arg(s)
4034 linkstyle=LinkableMapObj::Line;
4035 else if (s=="StyleParabel")
4036 linkstyle=LinkableMapObj::Parabel;
4037 else if (s=="StylePolyLine")
4038 linkstyle=LinkableMapObj::PolyLine;
4039 else if (s=="StylePolyParabel")
4040 linkstyle=LinkableMapObj::PolyParabel;
4042 linkstyle=LinkableMapObj::UndefinedStyle;
4044 BranchItem *cur=NULL;
4045 BranchItem *prev=NULL;
4051 bo=(BranchObj*)(cur->getLMO() );
4052 bo->setLinkStyle(bo->getDefLinkStyle());
4053 cur=next(cur,prev,d);
4058 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4063 void VymModel::setMapDefLinkColor(QColor col)
4065 if ( !col.isValid() ) return;
4067 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4068 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4069 QString("Set map link color to %1").arg(col.name())
4073 BranchItem *cur=NULL;
4074 BranchItem *prev=NULL;
4077 cur=next(cur,prev,d);
4080 bo=(BranchObj*)(cur->getLMO() );
4087 void VymModel::setMapLinkColorHintInt()
4089 // called from setMapLinkColorHint(lch) or at end of parse
4090 BranchItem *cur=NULL;
4091 BranchItem *prev=NULL;
4094 cur=next(cur,prev,d);
4097 bo=(BranchObj*)(cur->getLMO() );
4099 cur=next(cur,prev,d);
4103 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4106 setMapLinkColorHintInt();
4109 void VymModel::toggleMapLinkColorHint()
4111 if (linkcolorhint==LinkableMapObj::HeadingColor)
4112 linkcolorhint=LinkableMapObj::DefaultColor;
4114 linkcolorhint=LinkableMapObj::HeadingColor;
4115 BranchItem *cur=NULL;
4116 BranchItem *prev=NULL;
4119 cur=next(cur,prev,d);
4122 bo=(BranchObj*)(cur->getLMO() );
4128 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4130 Q3FileDialog *fd=new Q3FileDialog( NULL);
4131 fd->setMode (Q3FileDialog::ExistingFile);
4132 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4133 ImagePreview *p =new ImagePreview (fd);
4134 fd->setContentsPreviewEnabled( TRUE );
4135 fd->setContentsPreview( p, p );
4136 fd->setPreviewMode( Q3FileDialog::Contents );
4137 fd->setCaption(vymName+" - " +tr("Load background image"));
4138 fd->setDir (lastImageDir);
4141 if ( fd->exec() == QDialog::Accepted )
4143 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4144 lastImageDir=QDir (fd->dirPath());
4145 setMapBackgroundImage (fd->selectedFile());
4149 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4151 QColor oldcol=mapScene->backgroundBrush().color();
4155 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4157 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4158 QString("Set background color of map to %1").arg(col.name()));
4161 brush.setTextureImage (QPixmap (fn));
4162 mapScene->setBackgroundBrush(brush);
4165 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4167 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4168 if ( !col.isValid() ) return;
4169 setMapBackgroundColor( col );
4173 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4175 QColor oldcol=mapScene->backgroundBrush().color();
4177 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4178 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4179 QString("Set background color of map to %1").arg(col.name()));
4180 mapScene->setBackgroundBrush(col);
4183 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4185 return mapScene->backgroundBrush().color();
4189 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4191 return linkcolorhint;
4194 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4196 return defLinkColor;
4199 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4204 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4206 return defXLinkColor;
4209 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4214 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4216 return defXLinkWidth;
4219 void VymModel::move(const double &x, const double &y) // FIXME-3
4223 BranchObj *bo = getSelectedBranch();
4225 (selectionType()==TreeItem::Branch ||
4226 selectionType()==TreeItem::MapCenter ||
4227 selectionType()==TreeItem::Image
4230 QPointF ap(bo->getAbsPos());
4234 QString ps=qpointfToString(ap);
4235 QString s=getSelectString();
4238 s, "move "+qpointfToString(to),
4239 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4248 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4252 BranchObj *bo = getSelectedBranch();
4254 (selectionType()==TreeItem::Branch ||
4255 selectionType()==TreeItem::MapCenter ||
4256 selectionType()==TreeItem::Image
4260 QPointF rp(bo->getRelPos());
4264 QString ps=qpointfToString (bo->getRelPos());
4265 QString s=getSelectString(bo);
4268 s, "moveRel "+qpointfToString(to),
4269 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4270 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4280 void VymModel::animate()
4282 animationTimer->stop();
4285 while (i<animObjList.size() )
4287 bo=(BranchObj*)animObjList.at(i);
4292 animObjList.removeAt(i);
4299 QItemSelection sel=selModel->selection();
4300 emit (selectionChanged(sel,sel));
4303 if (!animObjList.isEmpty()) animationTimer->start();
4307 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4309 if (bo && bo->getTreeItem()->depth()>0)
4312 ap.setStart (start);
4314 ap.setTicks (animationTicks);
4315 ap.setAnimated (true);
4316 bo->setAnimation (ap);
4317 animObjList.append( bo );
4318 animationTimer->setSingleShot (true);
4319 animationTimer->start(animationInterval);
4323 void VymModel::stopAnimation (MapObj *mo)
4325 int i=animObjList.indexOf(mo);
4327 animObjList.removeAt (i);
4330 void VymModel::sendSelection()
4332 if (netstate!=Server) return;
4333 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4336 void VymModel::newServer()
4340 tcpServer = new QTcpServer(this);
4341 if (!tcpServer->listen(QHostAddress::Any,port)) {
4342 QMessageBox::critical(NULL, "vym server",
4343 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4344 //FIXME-3 needed? we are no widget any longer... close();
4347 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4349 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4352 void VymModel::connectToServer()
4355 server="salam.suse.de";
4357 clientSocket = new QTcpSocket (this);
4358 clientSocket->abort();
4359 clientSocket->connectToHost(server ,port);
4360 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4361 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4362 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4364 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4369 void VymModel::newClient()
4371 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4372 connect(newClient, SIGNAL(disconnected()),
4373 newClient, SLOT(deleteLater()));
4375 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4377 clientList.append (newClient);
4381 void VymModel::sendData(const QString &s)
4383 if (clientList.size()==0) return;
4385 // Create bytearray to send
4387 QDataStream out(&block, QIODevice::WriteOnly);
4388 out.setVersion(QDataStream::Qt_4_0);
4390 // Reserve some space for blocksize
4393 // Write sendCounter
4394 out << sendCounter++;
4399 // Go back and write blocksize so far
4400 out.device()->seek(0);
4401 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4405 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4407 for (int i=0; i<clientList.size(); ++i)
4409 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4410 clientList.at(i)->write (block);
4414 void VymModel::readData ()
4416 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4419 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4423 QDataStream in(clientSocket);
4424 in.setVersion(QDataStream::Qt_4_0);
4432 cout << " t="<<qPrintable (t)<<endl;
4438 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4440 switch (socketError) {
4441 case QAbstractSocket::RemoteHostClosedError:
4443 case QAbstractSocket::HostNotFoundError:
4444 QMessageBox::information(NULL, vymName +" Network client",
4445 "The host was not found. Please check the "
4446 "host name and port settings.");
4448 case QAbstractSocket::ConnectionRefusedError:
4449 QMessageBox::information(NULL, vymName + " Network client",
4450 "The connection was refused by the peer. "
4451 "Make sure the fortune server is running, "
4452 "and check that the host name and port "
4453 "settings are correct.");
4456 QMessageBox::information(NULL, vymName + " Network client",
4457 QString("The following error occurred: %1.")
4458 .arg(clientSocket->errorString()));
4465 void VymModel::selectMapSelectionColor()
4467 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4468 setSelectionColor (col);
4471 void VymModel::setSelectionColorInt (QColor col)
4473 if ( !col.isValid() ) return;
4475 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4476 QString("setSelectionColor (%1)").arg(col.name()),
4477 QString("Set color of selection box to %1").arg(col.name())
4480 mapEditor->setSelectionColor (col);
4484 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4486 cout << "VymModel::changeSelection (";
4487 if (!newsel.indexes().isEmpty() )
4488 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4490 if (!oldsel.indexes().isEmpty() )
4491 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4496 void VymModel::updateSelection(const QItemSelection &newsel)
4498 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4499 emitShowSelection();
4503 void VymModel::updateSelection()
4505 QItemSelection newsel=selModel->selection();
4506 updateSelection (newsel);
4509 void VymModel::setSelectionColor(QColor col)
4511 if ( !col.isValid() ) return;
4513 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4514 QString("setSelectionColor (%1)").arg(col.name()),
4515 QString("Set color of selection box to %1").arg(col.name())
4517 setSelectionColorInt (col);
4520 QColor VymModel::getSelectionColor()
4522 return mapEditor->getSelectionColor();
4525 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4528 for (int i=0;i<rootItem->childCount();i++)
4529 rootItem->child(i)->setHideTmp (mode);
4531 // FIXME-3 needed? scene()->update();
4535 QRectF VymModel::getTotalBBox() //FIXME-2
4539 for (int i=0;i<rootItem->branchCount(); i++)
4540 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4545 //////////////////////////////////////////////
4546 // Selection related
4547 //////////////////////////////////////////////
4549 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4554 QItemSelectionModel* VymModel::getSelectionModel()
4559 void VymModel::setSelectionBlocked (bool b)
4564 selection.unblock();
4567 bool VymModel::isSelectionBlocked()
4569 return selection.isBlocked();
4572 bool VymModel::select ()
4574 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4576 TreeItem *item = getItem (index);
4577 return select (item->getLMO() );
4580 bool VymModel::select (const QString &s)
4582 TreeItem *ti=findBySelectString(s);
4592 bool VymModel::select (LinkableMapObj *lmo)
4594 QItemSelection oldsel=selModel->selection();
4597 return select (lmo->getTreeItem() );
4602 bool VymModel::select (TreeItem *ti)
4604 if (ti) return select (index(ti));
4608 bool VymModel::select (const QModelIndex &index)
4610 if (index.isValid() )
4612 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4613 getSelectedItem()->setLastSelectedBranch();
4619 void VymModel::unselect()
4621 selModel->clearSelection();
4624 void VymModel::reselect()
4626 selection.reselect();
4629 void VymModel::emitShowSelection()
4631 if (!blockReposition)
4632 emit (showSelection() );
4635 void VymModel::emitNoteHasChanged (TreeItem *ti)
4637 QModelIndex ix=index(ti);
4638 emit (noteHasChanged (ix) );
4641 void VymModel::emitDataHasChanged (TreeItem *ti)
4643 QModelIndex ix=index(ti);
4644 emit (dataChanged (ix,ix) );
4648 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4651 if (selection.select(lmo))
4653 //selection.update();
4654 sendSelection (); // FIXME-4 VM use signal
4658 void VymModel::selectInt (TreeItem *ti)
4660 if (selection.select(lmo))
4662 //selection.update();
4663 sendSelection (); // FIXME-4 VM use signal
4668 void VymModel::selectNextBranchInt()
4670 BranchItem *bi=getSelectedBranchItem();
4673 TreeItem *pi=bi->parent();
4677 if (i<pi->branchCount() )
4679 // select previous branch with same parent
4681 select (pi->getBranchNum(i));
4689 void VymModel::selectPrevBranchInt()
4692 BranchItem *bi=getSelectedBranchItem();
4695 BranchItem *pi=(BranchItem*)bi->parent();
4701 // select previous branch with same parent
4702 bi=pi->getBranchNum(i-1);
4707 while (bi->branchCount() >0)
4708 bi=bi->getLastBranch();
4711 // Try to select last branch in parent pi2 previous to own parent pi
4713 TreeItem *pi2=pi->parent();
4724 void VymModel::selectAboveBranchInt()
4726 BranchItem *bi=getSelectedBranchItem();
4729 BranchItem *newbi=NULL;
4730 BranchItem *pi=(BranchItem*)bi->parent();
4734 // goto previous branch with same parent
4735 newbi=pi->getBranchNum(i-1);
4736 while (newbi->branchCount() >0 )
4737 newbi=newbi->getLastBranch();
4741 if (newbi==rootItem)
4742 // already at top branch (resp. mapcenter)
4748 void VymModel::selectBelowBranchInt()
4750 BranchItem *bi=getSelectedBranchItem();
4753 BranchItem *newbi=NULL;
4755 if (bi->branchCount() >0)
4756 newbi=bi->getFirstBranch();
4763 pi=(BranchItem*)bi->parent();
4765 if (pi->branchCount()-1 > i)
4767 newbi=(BranchItem*)pi->getBranchNum(i+1);
4772 // look for siblings of myself
4773 // or parent, or parent of parent...
4784 void VymModel::selectUpperBranch()
4786 if (selection.isBlocked() ) return;
4788 BranchItem *bi=getSelectedBranchItem();
4789 if (bi && bi->isBranchLikeType())
4790 selectAboveBranchInt();
4793 void VymModel::selectLowerBranch()
4795 if (selection.isBlocked() ) return;
4797 BranchItem *bi=getSelectedBranchItem();
4798 if (bi && bi->isBranchLikeType())
4799 selectBelowBranchInt();
4803 void VymModel::selectLeftBranch()
4805 if (selection.isBlocked() ) return;
4807 QItemSelection oldsel=selModel->selection();
4810 BranchItem *selbi=getSelectedBranchItem();
4811 TreeItem::Type type=selbi->getType();
4814 if (type == TreeItem::MapCenter)
4816 QModelIndex ix=index(selbi);
4817 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4820 par=(BranchItem*)selbi->parent();
4821 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4824 if (type == TreeItem::Branch ||
4825 type == TreeItem::Image)
4827 QModelIndex ix=index (selbi->parent());
4828 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4833 if (type == TreeItem::Branch )
4835 selectLastSelectedBranch();
4843 void VymModel::selectRightBranch()
4845 if (selection.isBlocked() ) return;
4847 QItemSelection oldsel=selModel->selection();
4850 BranchItem *selbi=getSelectedBranchItem();
4851 TreeItem::Type type=selbi->getType();
4854 if (type==TreeItem::MapCenter)
4856 QModelIndex ix=index(selbi);
4857 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4860 par=(BranchItem*)selbi->parent();
4861 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4864 if ( type== TreeItem::Branch )
4866 selectLastSelectedBranch();
4872 if (type == TreeItem::Branch ||
4873 type == TreeItem::Image)
4875 QModelIndex ix=index(selbi->parent());
4876 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4883 void VymModel::selectFirstBranch()
4885 TreeItem *ti=getSelectedBranchItem();
4888 TreeItem *par=ti->parent();
4890 TreeItem *ti2=par->getFirstBranch();
4894 emitShowSelection();
4900 void VymModel::selectLastBranch()
4902 TreeItem *ti=getSelectedBranchItem();
4905 TreeItem *par=ti->parent();
4907 TreeItem *ti2=par->getLastBranch();
4911 emitShowSelection();
4917 void VymModel::selectLastSelectedBranch()
4919 TreeItem *ti=getSelectedBranchItem();
4922 ti=ti->getLastSelectedBranch();
4923 if (ti) select (ti);
4927 void VymModel::selectParent()
4929 TreeItem *ti=getSelectedItem();
4937 emitShowSelection();
4942 TreeItem::Type VymModel::selectionType()
4944 QModelIndexList list=selModel->selectedIndexes();
4945 if (list.isEmpty()) return TreeItem::Undefined;
4946 TreeItem *ti = getItem (list.first() );
4947 return ti->getType();
4951 LinkableMapObj* VymModel::getSelectedLMO()
4953 QModelIndexList list=selModel->selectedIndexes();
4954 if (!list.isEmpty() )
4956 TreeItem *ti = getItem (list.first() );
4957 TreeItem::Type type=ti->getType();
4958 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4960 return ti->getLMO();
4966 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4968 TreeItem *ti = getSelectedBranchItem();
4970 return (BranchObj*)ti->getLMO();
4975 BranchItem* VymModel::getSelectedBranchItem()
4977 QModelIndexList list=selModel->selectedIndexes();
4978 if (!list.isEmpty() )
4980 TreeItem *ti = getItem (list.first() );
4981 TreeItem::Type type=ti->getType();
4982 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4983 return (BranchItem*)ti;
4988 TreeItem* VymModel::getSelectedItem()
4990 QModelIndexList list=selModel->selectedIndexes();
4991 if (!list.isEmpty() )
4992 return getItem (list.first() );
4997 QModelIndex VymModel::getSelectedIndex()
4999 QModelIndexList list=selModel->selectedIndexes();
5000 if (list.isEmpty() )
5001 return QModelIndex();
5003 return list.first();
5006 FloatImageObj* VymModel::getSelectedFloatImage()
5008 return selection.getFloatImage();
5011 QString VymModel::getSelectString ()
5013 LinkableMapObj *lmo=getSelectedLMO();
5015 return getSelectString(lmo);
5020 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5022 if (!lmo) return QString();
5023 return getSelectString (lmo->getTreeItem() );
5026 QString VymModel::getSelectString (TreeItem *ti)
5030 if (ti->getType() == TreeItem::Branch ||
5031 ti->getType() == TreeItem::MapCenter)
5033 TreeItem *par=ti->parent();
5036 if (ti->depth() ==1)
5037 // Mainbranch, return
5038 s= "bo:" + QString("%1").arg(ti->num() );
5040 // Branch, call myself recursively
5041 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5045 int i=rootItem->num(ti);
5046 if (i>=0) s=QString("mc:%1").arg(i);