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;
33 extern FlagRow *standardFlagsMaster;
35 extern QString clipboardDir;
36 extern QString clipboardFile;
37 extern bool clipboardEmpty;
39 extern ImageIO imageIO;
41 extern QString vymName;
42 extern QString vymVersion;
43 extern QDir vymBaseDir;
45 extern QDir lastImageDir;
46 extern QDir lastFileDir;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 // cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 selModel->clearSelection();
74 //QModelIndex ri=index(rootItem);
75 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
78 void VymModel::init ()
80 // We should have at least one map center to start with
81 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
86 // Also no scene yet (should not be needed anyway) FIXME-3 VM
99 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
100 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
101 mainWindow->updateHistory (undoSet);
104 makeTmpDirectories();
109 fileName=tr("unnamed");
111 blockReposition=false;
112 blockSaveState=false;
114 autosaveTimer=new QTimer (this);
115 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
117 fileChangedTimer=new QTimer (this);
118 fileChangedTimer->start(3000);
119 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
131 animationUse=settings.readBoolEntry("/animation/use",false);
132 animationTicks=settings.readNumEntry("/animation/ticks",10);
133 animationInterval=settings.readNumEntry("/animation/interval",50);
135 animationTimer=new QTimer (this);
136 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
139 defLinkColor=QColor (0,0,255);
140 defXLinkColor=QColor (180,180,180);
141 linkcolorhint=LinkableMapObj::DefaultColor;
142 linkstyle=LinkableMapObj::PolyParabel;
144 defXLinkColor=QColor (230,230,230);
146 hidemode=TreeItem::HideNone;
152 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
156 void VymModel::makeTmpDirectories()
158 // Create unique temporary directories
159 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
160 histPath = tmpMapDir+"/history";
166 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
171 bool VymModel::isRepositionBlocked()
173 return blockReposition;
176 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
178 //cout << "VM::updateActions \n";
179 // Tell mainwindow to update states of actions
180 mainWindow->updateActions();
185 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
187 // tmpdir temporary directory to which data will be written
188 // prefix mapname, which will be appended to images etc.
189 // writeflags Only write flags for "real" save of map, not undo
190 // offset offset of bbox of whole map in scene.
191 // Needed for XML export
200 case LinkableMapObj::Line:
203 case LinkableMapObj::Parabel:
206 case LinkableMapObj::PolyLine:
210 ls="StylePolyParabel";
214 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
216 if (linkcolorhint==LinkableMapObj::HeadingColor)
217 colhint=xml.attribut("linkColorHint","HeadingColor");
219 QString mapAttr=xml.attribut("version",vymVersion);
221 mapAttr+= xml.attribut("author",author) +
222 xml.attribut("comment",comment) +
223 xml.attribut("date",getDate()) +
224 xml.attribut("branchCount", QString().number(branchCount())) +
225 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
226 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
227 xml.attribut("linkStyle", ls ) +
228 xml.attribut("linkColor", defLinkColor.name() ) +
229 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
230 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
232 s+=xml.beginElement("vymmap",mapAttr);
235 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
236 standardFlagsMaster->resetUsedCounter();
238 // Reset the counters before saving
239 // TODO constr. of FIO creates lots of objects, better do this in some other way...
240 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
242 // Build xml recursivly
243 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
244 // Save all mapcenters as complete map, if saveSel not set
245 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
248 if (saveSel->getType()==TreeItem::Branch)
250 s+=saveSel->saveToDir(tmpdir,prefix,offset);
251 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
253 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
256 // Save local settings
257 s+=settings.getDataXML (destPath);
260 if (getSelectedItem() && !saveSel )
261 s+=xml.valueElement("select",getSelectString());
264 s+=xml.endElement("vymmap");
266 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
270 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
274 for (int i=0; i<rootItem->branchCount(); i++)
275 s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
279 void VymModel::setFilePath(QString fpath, QString destname)
281 if (fpath.isEmpty() || fpath=="")
288 filePath=fpath; // becomes absolute path
289 fileName=fpath; // gets stripped of path
290 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
292 // If fpath is not an absolute path, complete it
293 filePath=QDir(fpath).absPath();
294 fileDir=filePath.left (1+filePath.findRev ("/"));
296 // Set short name, too. Search from behind:
297 int i=fileName.findRev("/");
298 if (i>=0) fileName=fileName.remove (0,i+1);
300 // Forget the .vym (or .xml) for name of map
301 mapName=fileName.left(fileName.findRev(".",-1,true) );
305 void VymModel::setFilePath(QString fpath)
307 setFilePath (fpath,fpath);
310 QString VymModel::getFilePath()
315 QString VymModel::getFileName()
320 QString VymModel::getMapName()
325 QString VymModel::getDestPath()
330 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
332 ErrorCode err=success;
334 parseBaseHandler *handler;
338 case VymMap: handler=new parseVYMHandler; break;
339 case FreemindMap : handler=new parseFreemindHandler; break;
341 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
342 "Unknown FileType in VymModel::load()");
346 bool zipped_org=zipped;
350 selModel->clearSelection();
351 // FIXME-2 VM not needed??? model->setMapEditor(this);
352 // (map state is set later at end of load...)
355 BranchItem *bi=getSelectedBranchItem();
356 if (!bi) return aborted;
357 if (lmode==ImportAdd)
358 saveStateChangingPart(
361 QString("addMapInsert (%1)").arg(fname),
362 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
364 saveStateChangingPart(
367 QString("addMapReplace(%1)").arg(fname),
368 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 // Create temporary directory for packing
374 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
377 QMessageBox::critical( 0, tr( "Critical Load Error" ),
378 tr("Couldn't create temporary directory before load\n"));
383 err=unzipDir (tmpZipDir,fname);
393 // Look for mapname.xml
394 xmlfile= fname.left(fname.findRev(".",-1,true));
395 xmlfile=xmlfile.section( '/', -1 );
396 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
397 if (!mfile.exists() )
399 // mapname.xml does not exist, well,
400 // maybe someone renamed the mapname.vym file...
401 // Try to find any .xml in the toplevel
402 // directory of the .vym file
403 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
404 if (flist.count()==1)
406 // Only one entry, take this one
407 xmlfile=tmpZipDir + "/"+flist.first();
410 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
411 *it=tmpZipDir + "/" + *it;
412 // TODO Multiple entries, load all (but only the first one into this ME)
413 //mainWindow->fileLoadFromTmp (flist);
414 //returnCode=1; // Silently forget this attempt to load
415 qWarning ("MainWindow::load (fn) multimap found...");
418 if (flist.isEmpty() )
420 QMessageBox::critical( 0, tr( "Critical Load Error" ),
421 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
424 } //file doesn't exist
426 xmlfile=mfile.name();
429 QFile file( xmlfile);
431 // I am paranoid: file should exist anyway
432 // according to check in mainwindow.
435 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
436 tr(QString("Couldn't open map %1").arg(file.name())));
440 bool blockSaveStateOrg=blockSaveState;
441 blockReposition=true;
443 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
444 QXmlInputSource source( file);
445 QXmlSimpleReader reader;
446 reader.setContentHandler( handler );
447 reader.setErrorHandler( handler );
448 handler->setModel ( this);
451 // We need to set the tmpDir in order to load files with rel. path
456 tmpdir=fname.left(fname.findRev("/",-1));
457 handler->setTmpDir (tmpdir);
458 handler->setInputFile (file.name());
459 handler->setLoadMode (lmode);
460 bool ok = reader.parse( source );
461 blockReposition=false;
462 blockSaveState=blockSaveStateOrg;
463 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
467 reposition(); // FIXME-2 VM reposition the view instead...
474 autosaveTimer->stop();
477 // Reset timestamp to check for later updates of file
478 fileChangedTime=QFileInfo (destPath).lastModified();
481 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
482 tr( handler->errorProtocol() ) );
484 // Still return "success": the map maybe at least
485 // partially read by the parser
490 removeDir (QDir(tmpZipDir));
492 // Restore original zip state
499 ErrorCode VymModel::save (const SaveMode &savemode)
503 QString safeFilePath;
505 ErrorCode err=success;
509 mapFileName=mapName+".xml";
511 // use name given by user, even if he chooses .doc
512 mapFileName=fileName;
514 // Look, if we should zip the data:
517 QMessageBox mb( vymName,
518 tr("The map %1\ndid not use the compressed "
519 "vym file format.\nWriting it uncompressed will also write images \n"
520 "and flags and thus may overwrite files in the "
521 "given directory\n\nDo you want to write the map").arg(filePath),
522 QMessageBox::Warning,
523 QMessageBox::Yes | QMessageBox::Default,
525 QMessageBox::Cancel | QMessageBox::Escape);
526 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
527 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
528 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
531 case QMessageBox::Yes:
532 // save compressed (default file format)
535 case QMessageBox::No:
539 case QMessageBox::Cancel:
546 // First backup existing file, we
547 // don't want to add to old zip archives
551 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
553 QString backupFileName(destPath + "~");
554 QFile backupFile(backupFileName);
555 if (backupFile.exists() && !backupFile.remove())
557 QMessageBox::warning(0, tr("Save Error"),
558 tr("%1\ncould not be removed before saving").arg(backupFileName));
560 else if (!f.rename(backupFileName))
562 QMessageBox::warning(0, tr("Save Error"),
563 tr("%1\ncould not be renamed before saving").arg(destPath));
570 // Create temporary directory for packing
572 tmpZipDir=makeTmpDir (ok,"vym-zip");
575 QMessageBox::critical( 0, tr( "Critical Load Error" ),
576 tr("Couldn't create temporary directory before save\n"));
580 safeFilePath=filePath;
581 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
584 // Create mapName and fileDir
585 makeSubDirs (fileDir);
588 if (savemode==CompleteMap || selection.isEmpty())
591 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
594 autosaveTimer->stop();
599 if (selectionType()==TreeItem::Image)
602 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
603 // TODO take care of multiselections
606 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
609 qWarning ("ME::saveStringToDisk failed!");
615 if (err==success) err=zipDir (tmpZipDir,destPath);
618 removeDir (QDir(tmpZipDir));
620 // Restore original filepath outside of tmp zip dir
621 setFilePath (safeFilePath);
625 fileChangedTime=QFileInfo (destPath).lastModified();
629 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
631 QString pathDir=path.left(path.findRev("/"));
637 // We need to parse saved XML data
638 parseVYMHandler handler;
639 QXmlInputSource source( file);
640 QXmlSimpleReader reader;
641 reader.setContentHandler( &handler );
642 reader.setErrorHandler( &handler );
643 handler.setModel ( this);
644 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
645 if (undoSel.isEmpty())
649 handler.setLoadMode (NewMap);
653 handler.setLoadMode (ImportReplace);
655 blockReposition=true;
656 bool ok = reader.parse( source );
657 blockReposition=false;
660 // This should never ever happen
661 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
662 handler.errorProtocol());
665 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
668 void VymModel::addMapInsertInt (const QString &path, int pos)
670 /* FIXME-2 addMapInsertInt not ported yet
671 BranchObj *sel=getSelectedBranch();
674 QString pathDir=path.left(path.findRev("/"));
680 // We need to parse saved XML data
681 parseVYMHandler handler;
682 QXmlInputSource source( file);
683 QXmlSimpleReader reader;
684 reader.setContentHandler( &handler );
685 reader.setErrorHandler( &handler );
686 handler.setModel (this);
687 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
688 handler.setLoadMode (ImportAdd);
689 blockReposition=true;
690 bool ok = reader.parse( source );
691 blockReposition=false;
694 // This should never ever happen
695 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
696 handler.errorProtocol());
698 if (sel->getDepth()>0)
699 sel->getLastBranch()->linkTo (sel,pos);
701 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
706 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
708 TreeItem *fi=createImage();
711 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
719 void VymModel::loadFloatImage () // FIXME-2
722 BranchObj *bo=getSelectedBranch();
726 Q3FileDialog *fd=new Q3FileDialog( NULL);
727 fd->setMode (Q3FileDialog::ExistingFiles);
728 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
729 ImagePreview *p =new ImagePreview (fd);
730 fd->setContentsPreviewEnabled( TRUE );
731 fd->setContentsPreview( p, p );
732 fd->setPreviewMode( Q3FileDialog::Contents );
733 fd->setCaption(vymName+" - " +tr("Load image"));
734 fd->setDir (lastImageDir);
737 if ( fd->exec() == QDialog::Accepted )
739 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
740 lastImageDir=QDir (fd->dirPath());
743 for (int j=0; j<fd->selectedFiles().count(); j++)
745 s=fd->selectedFiles().at(j);
746 fio=loadFloatImageInt (s);
749 (LinkableMapObj*)fio,
752 QString ("loadImage (%1)").arg(s ),
753 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
756 // TODO loadFIO error handling
757 qWarning ("Failed to load "+s);
766 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
771 void VymModel::saveFloatImage ()
773 FloatImageObj *fio=selection.getFloatImage();
776 QFileDialog *fd=new QFileDialog( NULL);
777 fd->setFilters (imageIO.getFilters());
778 fd->setCaption(vymName+" - " +tr("Save image"));
779 fd->setFileMode( QFileDialog::AnyFile );
780 fd->setDirectory (lastImageDir);
781 // fd->setSelection (fio->getOriginalFilename());
785 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
787 fn=fd->selectedFiles().at(0);
788 if (QFile (fn).exists() )
790 QMessageBox mb( vymName,
791 tr("The file %1 exists already.\n"
792 "Do you want to overwrite it?").arg(fn),
793 QMessageBox::Warning,
794 QMessageBox::Yes | QMessageBox::Default,
795 QMessageBox::Cancel | QMessageBox::Escape,
796 QMessageBox::NoButton );
798 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
799 mb.setButtonText( QMessageBox::No, tr("Cancel"));
802 case QMessageBox::Yes:
805 case QMessageBox::Cancel:
812 saveFloatImageInt (fio,fd->selectedFilter(),fn );
819 void VymModel::importDirInt(BranchObj *dst, QDir d)
821 /* FIXME-2 importDirInt not ported yet
822 BranchObj *bo=getSelectedBranch();
825 // Traverse directories
826 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
827 QFileInfoList list = d.entryInfoList();
830 for (int i = 0; i < list.size(); ++i)
833 if (fi.fileName() != "." && fi.fileName() != ".." )
836 bo=dst->getLastBranch();
837 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
838 bi->setHeading (fi.fileName() ); // FIXME-3 check this
839 bo->setColor (QColor("blue"));
841 if ( !d.cd(fi.fileName()) )
842 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
845 // Recursively add subdirs
852 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
853 list = d.entryInfoList();
855 for (int i = 0; i < list.size(); ++i)
859 bo=dst->getLastBranch();
860 bo->setHeading (fi.fileName() );
861 bo->setColor (QColor("black"));
862 if (fi.fileName().right(4) == ".vym" )
863 bo->setVymLink (fi.filePath());
869 void VymModel::importDirInt (const QString &s) // FIXME-2
872 BranchObj *bo=getSelectedBranch();
875 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
883 void VymModel::importDir() //FIXME-2
886 BranchObj *bo=getSelectedBranch();
890 filters <<"VYM map (*.vym)";
891 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
892 fd->setMode (QFileDialog::DirectoryOnly);
893 fd->setFilters (filters);
894 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
898 if ( fd->exec() == QDialog::Accepted )
900 importDirInt (fd->selectedFile() );
902 //FIXME-3 VM needed? scene()->update();
909 void VymModel::autosave()
914 cout << "VymModel::autosave rejected due to missing filePath\n";
917 QDateTime now=QDateTime().currentDateTime();
919 // Disable autosave, while we have gone back in history
920 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
921 if (redosAvail>0) return;
923 // Also disable autosave for new map without filename
924 if (filePath.isEmpty()) return;
927 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
929 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
930 mainWindow->fileSave (this);
933 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
938 void VymModel::fileChanged()
940 // Check if file on disk has changed meanwhile
941 if (!filePath.isEmpty())
943 QDateTime tmod=QFileInfo (filePath).lastModified();
944 if (tmod>fileChangedTime)
946 // FIXME-2 VM switch to current mapeditor and finish lineedits...
947 QMessageBox mb( vymName,
948 tr("The file of the map on disk has changed:\n\n"
949 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
950 QMessageBox::Question,
952 QMessageBox::Cancel | QMessageBox::Default,
953 QMessageBox::NoButton );
955 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
956 mb.setButtonText( QMessageBox::No, tr("Ignore"));
959 case QMessageBox::Yes:
961 load (filePath,NewMap,fileType);
962 case QMessageBox::Cancel:
963 fileChangedTime=tmod; // allow autosave to overwrite newer file!
969 bool VymModel::isDefault()
974 void VymModel::makeDefault()
980 bool VymModel::hasChanged()
985 void VymModel::setChanged()
988 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
992 latestAddedItem=NULL;
996 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
999 if (!lmo) return QString("Error: NULL has no name!");
1001 if ((typeid(*lmo) == typeid(BranchObj) ||
1002 typeid(*lmo) == typeid(MapCenterObj)))
1005 s=lmo->getTreeItem()->getHeading();
1006 if (s=="") s="unnamed";
1007 return QString("branch (%1)").arg(s);
1009 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1010 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1011 return QString("Unknown type has no name!");
1015 QString VymModel::getObjectName (const TreeItem *ti)
1018 if (!ti) return QString("Error: NULL has no name!");
1020 if (ti->isBranchLikeType() )
1023 if (s=="") s="unnamed";
1024 return QString("branch (%1)").arg(s);
1026 /* FIXME-2 move floatimage to TreeModel first
1027 if (type==TreeItem::Image)
1028 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1030 return QString("Unknown type has no name!");
1033 void VymModel::redo()
1035 // Can we undo at all?
1036 if (redosAvail<1) return;
1038 bool blockSaveStateOrg=blockSaveState;
1039 blockSaveState=true;
1043 if (undosAvail<stepsTotal) undosAvail++;
1045 if (curStep>stepsTotal) curStep=1;
1046 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1047 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1048 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1049 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1050 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1051 QString version=undoSet.readEntry ("/history/version");
1053 /* TODO Maybe check for version, if we save the history
1054 if (!checkVersion(version))
1055 QMessageBox::warning(0,tr("Warning"),
1056 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1059 // Find out current undo directory
1060 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1064 cout << "VymModel::redo() begin\n";
1065 cout << " undosAvail="<<undosAvail<<endl;
1066 cout << " redosAvail="<<redosAvail<<endl;
1067 cout << " curStep="<<curStep<<endl;
1068 cout << " ---------------------------"<<endl;
1069 cout << " comment="<<comment.toStdString()<<endl;
1070 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1071 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1072 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1073 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1074 cout << " ---------------------------"<<endl<<endl;
1077 // select object before redo
1078 if (!redoSelection.isEmpty())
1079 select (redoSelection);
1082 parseAtom (redoCommand);
1085 blockSaveState=blockSaveStateOrg;
1087 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1088 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1089 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1090 undoSet.writeSettings(histPath);
1092 mainWindow->updateHistory (undoSet);
1095 /* TODO remove testing
1096 cout << "ME::redo() end\n";
1097 cout << " undosAvail="<<undosAvail<<endl;
1098 cout << " redosAvail="<<redosAvail<<endl;
1099 cout << " curStep="<<curStep<<endl;
1100 cout << " ---------------------------"<<endl<<endl;
1106 bool VymModel::isRedoAvailable()
1108 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1114 void VymModel::undo()
1116 // Can we undo at all?
1117 if (undosAvail<1) return;
1119 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1121 bool blockSaveStateOrg=blockSaveState;
1122 blockSaveState=true;
1124 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1125 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1126 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1127 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1128 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1129 QString version=undoSet.readEntry ("/history/version");
1131 /* TODO Maybe check for version, if we save the history
1132 if (!checkVersion(version))
1133 QMessageBox::warning(0,tr("Warning"),
1134 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1137 // Find out current undo directory
1138 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1140 // select object before undo
1141 if (!undoSelection.isEmpty())
1142 select (undoSelection);
1146 cout << "VymModel::undo() begin\n";
1147 cout << " undosAvail="<<undosAvail<<endl;
1148 cout << " redosAvail="<<redosAvail<<endl;
1149 cout << " curStep="<<curStep<<endl;
1150 cout << " ---------------------------"<<endl;
1151 cout << " comment="<<comment.toStdString()<<endl;
1152 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1153 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1154 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1155 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1156 cout << " ---------------------------"<<endl<<endl;
1158 parseAtom (undoCommand);
1163 if (curStep<1) curStep=stepsTotal;
1167 blockSaveState=blockSaveStateOrg;
1168 /* TODO remove testing
1169 cout << "VymModel::undo() end\n";
1170 cout << " undosAvail="<<undosAvail<<endl;
1171 cout << " redosAvail="<<redosAvail<<endl;
1172 cout << " curStep="<<curStep<<endl;
1173 cout << " ---------------------------"<<endl<<endl;
1176 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1177 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1178 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1179 undoSet.writeSettings(histPath);
1181 mainWindow->updateHistory (undoSet);
1184 emitShowSelection();
1187 bool VymModel::isUndoAvailable()
1189 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1195 void VymModel::gotoHistoryStep (int i)
1197 // Restore variables
1198 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1199 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1201 if (i<0) i=undosAvail+redosAvail;
1203 // Clicking above current step makes us undo things
1206 for (int j=0; j<undosAvail-i; j++) undo();
1209 // Clicking below current step makes us redo things
1211 for (int j=undosAvail; j<i; j++)
1213 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1217 // And ignore clicking the current row ;-)
1221 QString VymModel::getHistoryPath()
1223 QString histName(QString("history-%1").arg(curStep));
1224 return (tmpMapDir+"/"+histName);
1227 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1229 sendData(redoCom); //FIXME-3 testing
1234 if (blockSaveState) return;
1236 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1238 // Find out current undo directory
1239 if (undosAvail<stepsTotal) undosAvail++;
1241 if (curStep>stepsTotal) curStep=1;
1243 QString backupXML="";
1244 QString histDir=getHistoryPath();
1245 QString bakMapPath=histDir+"/map.xml";
1247 // Create histDir if not available
1250 makeSubDirs (histDir);
1252 // Save depending on how much needs to be saved
1254 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1256 QString undoCommand="";
1257 if (savemode==UndoCommand)
1259 undoCommand=undoCom;
1261 else if (savemode==PartOfMap )
1263 undoCommand=undoCom;
1264 undoCommand.replace ("PATH",bakMapPath);
1268 if (!backupXML.isEmpty())
1269 // Write XML Data to disk
1270 saveStringToDisk (bakMapPath,backupXML);
1272 // We would have to save all actions in a tree, to keep track of
1273 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1276 // Write the current state to disk
1277 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1278 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1279 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1280 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1281 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1282 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1283 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1284 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1285 undoSet.setEntry (QString("/history/version"),vymVersion);
1286 undoSet.writeSettings(histPath);
1290 // TODO remove after testing
1291 //cout << " into="<< histPath.toStdString()<<endl;
1292 cout << " stepsTotal="<<stepsTotal<<
1293 ", undosAvail="<<undosAvail<<
1294 ", redosAvail="<<redosAvail<<
1295 ", curStep="<<curStep<<endl;
1296 cout << " ---------------------------"<<endl;
1297 cout << " comment="<<comment.toStdString()<<endl;
1298 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1299 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1300 cout << " redoCom="<<redoCom.toStdString()<<endl;
1301 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1302 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1303 cout << " ---------------------------"<<endl;
1306 mainWindow->updateHistory (undoSet);
1312 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1314 // save the selected part of the map, Undo will replace part of map
1315 QString undoSelection="";
1317 undoSelection=getSelectString(undoSel);
1319 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1320 QString redoSelection="";
1322 redoSelection=getSelectString(undoSel);
1324 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1327 saveState (PartOfMap,
1328 undoSelection, "addMapReplace (\"PATH\")",
1334 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1338 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1341 QString undoSelection=getSelectString (redoSel->parent() );
1342 QString redoSelection=getSelectString(redoSel);
1343 if (redoSel->getType()==TreeItem::Branch)
1345 // save the selected branch of the map, Undo will insert part of map
1346 saveState (PartOfMap,
1347 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1348 redoSelection, "delete ()",
1355 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1357 // "Normal" savestate: save commands, selections and comment
1358 // so just save commands for undo and redo
1359 // and use current selection
1361 QString redoSelection="";
1362 if (redoSel) redoSelection=getSelectString(redoSel);
1363 QString undoSelection="";
1364 if (undoSel) undoSelection=getSelectString(undoSel);
1366 saveState (UndoCommand,
1373 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1375 // "Normal" savestate: save commands, selections and comment
1376 // so just save commands for undo and redo
1377 // and use current selection
1378 saveState (UndoCommand,
1385 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1387 // "Normal" savestate applied to model (no selection needed):
1388 // save commands and comment
1389 saveState (UndoCommand,
1397 QGraphicsScene* VymModel::getScene ()
1402 TreeItem* VymModel::findBySelectString(QString s)
1404 if (s.isEmpty() ) return NULL;
1406 // Old maps don't have multiple mapcenters and don't save full path
1407 if (s.left(2) !="mc")
1410 QStringList parts=s.split (",");
1413 TreeItem *ti=rootItem;
1415 while (!parts.isEmpty() )
1417 typ=parts.first().left(2);
1418 n=parts.first().right(parts.first().length() - 3).toInt();
1419 parts.removeFirst();
1420 if (typ=="mc" || typ=="bo")
1421 ti=ti->getBranchNum (n);
1425 ti=ti->getImageNum (n);
1431 TreeItem* VymModel::findID (const QString &s)
1434 for (int i=0; i<rootItem->branchCount(); i++)
1436 ti=rootItem->getBranchNum(i)->findID (s);
1442 //////////////////////////////////////////////
1444 //////////////////////////////////////////////
1445 void VymModel::setVersion (const QString &s)
1450 void VymModel::setAuthor (const QString &s)
1453 QString ("setMapAuthor (\"%1\")").arg(author),
1454 QString ("setMapAuthor (\"%1\")").arg(s),
1455 QString ("Set author of map to \"%1\"").arg(s)
1460 QString VymModel::getAuthor()
1465 void VymModel::setComment (const QString &s)
1468 QString ("setMapComment (\"%1\")").arg(comment),
1469 QString ("setMapComment (\"%1\")").arg(s),
1470 QString ("Set comment of map")
1475 QString VymModel::getComment ()
1480 QString VymModel::getDate ()
1482 return QDate::currentDate().toString ("yyyy-MM-dd");
1485 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1488 BranchItem *cur=NULL;
1489 BranchItem *prev=NULL;
1500 void VymModel::setHeading(const QString &s)
1502 BranchItem *selbi=getSelectedBranchItem();
1507 "setHeading (\""+selbi->getHeading()+"\")",
1509 "setHeading (\""+s+"\")",
1510 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1511 selbi->setHeading(s );
1512 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1515 // selection.update(); //FIXME-4
1520 BranchItem* VymModel::findText (QString s, bool cs)
1523 QTextDocument::FindFlags flags=0;
1524 if (cs) flags=QTextDocument::FindCaseSensitively;
1527 { // Nothing found or new find process
1529 // nothing found, start again
1533 next (findCurrent,findPrevious,d);
1535 bool searching=true;
1536 bool foundNote=false;
1537 while (searching && !EOFind)
1541 // Searching in Note
1542 if (findCurrent->getNote().contains(s,cs))
1544 select (findCurrent);
1546 if (getSelectedBranch()!=itFind)
1549 emitShowSelection();
1552 if (textEditor->findText(s,flags))
1558 // Searching in Heading
1559 if (searching && findCurrent->getHeading().contains (s,cs) )
1561 select(findCurrent);
1567 if (!next(findCurrent,findPrevious,d) )
1570 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1573 return getSelectedBranchItem();
1578 void VymModel::findReset()
1579 { // Necessary if text to find changes during a find process
1585 void VymModel::setScene (QGraphicsScene *s)
1587 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1588 //init(); // Here we have a mapScene set,
1589 // which is (still) needed to create MapCenters
1592 void VymModel::setURL(const QString &url)
1594 TreeItem *selti=getSelectedItem();
1597 QString oldurl=selti->getURL();
1598 selti->setURL (url);
1601 QString ("setURL (\"%1\")").arg(oldurl),
1603 QString ("setURL (\"%1\")").arg(url),
1604 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1607 emitDataHasChanged (selti);
1608 emitShowSelection();
1612 QString VymModel::getURL()
1614 TreeItem *selti=getSelectedItem();
1616 return selti->getURL();
1621 QStringList VymModel::getURLs()
1624 BranchItem *cur=getSelectedBranchItem();
1625 BranchItem *prev=NULL;
1630 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1631 cur=next (cur,prev,d);
1636 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1638 FloatImageObj *fio=selection.getFloatImage();
1641 TreeItem *dst=findBySelectString (dstString);
1642 if (dst && dst->isBranchLikeType() )
1644 TreeItem *dstPar=dst->parent();
1645 QString parString=getSelectString(dstPar);
1646 QString fioPreSelectString=getSelectString(fio);
1647 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1648 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1650 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1651 fio=((BranchObj*)dst)->getLastFloatImage();
1656 getSelectString(fio),
1657 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1659 QString ("linkTo (\"%1\")").arg(dstString),
1660 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1666 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1669 BranchObj *bo=getSelectedBranch();
1672 QString s=bo->getFrameTypeName();
1673 bo->setFrameType (t);
1674 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1675 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1682 void VymModel::setFrameType(const QString &s) //FIXME-2
1685 BranchObj *bo=getSelectedBranch();
1688 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1689 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1690 bo->setFrameType (s);
1697 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1700 BranchObj *bo=getSelectedBranch();
1703 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1704 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1705 bo->setFramePenColor (c);
1710 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1713 BranchObj *bo=getSelectedBranch();
1716 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1717 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1718 bo->setFrameBrushColor (c);
1722 void VymModel::setFramePadding (const int &i) //FIXME-2
1725 BranchObj *bo=getSelectedBranch();
1728 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1729 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1730 bo->setFramePadding (i);
1737 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1740 BranchObj *bo=getSelectedBranch();
1743 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1744 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1745 bo->setFrameBorderWidth (i);
1752 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1755 BranchObj *bo=getSelectedBranch();
1758 QString u= b ? "false" : "true";
1759 QString r=!b ? "false" : "true";
1763 QString("setIncludeImagesVertically (%1)").arg(u),
1765 QString("setIncludeImagesVertically (%1)").arg(r),
1766 QString("Include images vertically in %1").arg(getObjectName(bo))
1768 bo->setIncludeImagesVer(b);
1773 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1776 BranchObj *bo=getSelectedBranch();
1779 QString u= b ? "false" : "true";
1780 QString r=!b ? "false" : "true";
1784 QString("setIncludeImagesHorizontally (%1)").arg(u),
1786 QString("setIncludeImagesHorizontally (%1)").arg(r),
1787 QString("Include images horizontally in %1").arg(getObjectName(bo))
1789 bo->setIncludeImagesHor(b);
1795 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1798 LinkableMapObj *sel=getSelectedLMO();
1800 (selectionType() == TreeItem::Branch ||
1801 selectionType() == TreeItem::MapCenter ||
1802 selectionType() == TreeItem::Image ))
1804 QString u= b ? "false" : "true";
1805 QString r=!b ? "false" : "true";
1809 QString("setHideLinkUnselected (%1)").arg(u),
1811 QString("setHideLinkUnselected (%1)").arg(r),
1812 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1814 sel->setHideLinkUnselected(b);
1819 void VymModel::setHideExport(bool b)
1821 BranchItem *bi=getSelectedBranchItem();
1824 bi->setHideInExport (b);
1825 QString u= b ? "false" : "true";
1826 QString r=!b ? "false" : "true";
1830 QString ("setHideExport (%1)").arg(u),
1832 QString ("setHideExport (%1)").arg(r),
1833 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1837 // selection.update();
1838 // FIXME-3 VM needed? scene()->update();
1842 void VymModel::toggleHideExport()
1844 BranchItem *selbi=getSelectedBranchItem();
1846 setHideExport ( !selbi->hideInExport() );
1850 void VymModel::copy()
1852 TreeItem *selti=getSelectedItem();
1854 (selti->getType() == TreeItem::Branch ||
1855 selti->getType() == TreeItem::MapCenter ||
1856 selti->getType() == TreeItem::Image ))
1858 if (redosAvail == 0)
1861 QString s=getSelectString(selti);
1862 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1863 curClipboard=curStep;
1866 // Copy also to global clipboard, because we are at last step in history
1867 QString bakMapName(QString("history-%1").arg(curStep));
1868 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1869 copyDir (bakMapDir,clipboardDir );
1871 clipboardEmpty=false;
1877 void VymModel::pasteNoSave(const int &n)
1879 bool old=blockSaveState;
1880 blockSaveState=true;
1881 bool zippedOrg=zipped;
1882 if (redosAvail > 0 || n!=0)
1884 // Use the "historical" buffer
1885 QString bakMapName(QString("history-%1").arg(n));
1886 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1887 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1889 // Use the global buffer
1890 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1895 void VymModel::paste()
1897 BranchItem *selbi=getSelectedBranchItem();
1900 saveStateChangingPart(
1903 QString ("paste (%1)").arg(curClipboard),
1904 QString("Paste to %1").arg( getObjectName(selbi))
1911 void VymModel::cut()
1913 TreeItem *selti=getSelectedItem();
1914 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1922 void VymModel::moveUp()
1924 BranchItem *selbi=getSelectedBranchItem();
1927 if (!selbi->canMoveUp()) return;
1928 QString oldsel=getSelectString();
1929 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1931 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1935 void VymModel::moveDown()
1937 BranchItem *selbi=getSelectedBranchItem();
1940 if (!selbi->canMoveDown()) return;
1941 QString oldsel=getSelectString();
1942 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1944 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1948 void VymModel::sortChildren() // FIXME-2 not implemented yet
1951 BranchObj* bo=getSelectedBranch();
1954 if(treeItem->branchCount()>1)
1956 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1959 emitShowSelection();
1965 MapCenterItem* VymModel::createMapCenter()
1967 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
1972 BranchItem* VymModel::createBranch()
1974 BranchItem *selbi=getSelectedBranchItem();
1976 return addNewBranchInt (selbi,-2);
1981 TreeItem* VymModel::createImage() //FIXME-2
1984 BranchObj *bo=getSelectedBranch();
1987 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1990 QList<QVariant> cData;
1991 cData << "VM:createImage" << "undef"<<"undef";
1992 TreeItem *parti=bo->getTreeItem();
1993 TreeItem *ti=new TreeItem (cData,parti);
1994 ti->setLMO (newfio);
1995 ti->setType (TreeItem::Image);
1996 parti->appendChild (ti);
2000 newfio->setTreeItem (ti);
2001 select (newfio); // FIXME-2 VM really needed here?
2009 MapCenterItem* VymModel::addMapCenter ()
2011 MapCenterItem *mci=addMapCenter (contextPos);
2013 emitShowSelection();
2018 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2019 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2024 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2028 QModelIndex parix=index(rootItem);
2030 int n=rootItem->branchCount();
2032 emit (layoutAboutToBeChanged() );
2033 beginInsertRows (parix,n,n+1);
2035 QList<QVariant> cData;
2036 cData << "VM:addMapCenter" << "undef"<<"undef";
2037 MapCenterItem *mci=new MapCenterItem (cData);
2038 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2039 rootItem->appendChild (mci);
2042 emit (layoutChanged() );
2045 BranchObj *newbo=mci->createMapObj(mapScene);
2050 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) //FIXME-4 simplify...
2052 // Depending on pos:
2053 // -3 insert in children of parent above selection
2054 // -2 add branch to selection
2055 // -1 insert in children of parent below selection
2056 // 0..n insert in children of parent at pos
2059 QList<QVariant> cData;
2060 cData << "new" << "undef"<<"undef";
2065 BranchItem *newbi=new BranchItem (cData);
2066 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2068 emit (layoutAboutToBeChanged() );
2074 n=parbi->childCount();
2075 beginInsertRows (parix,n,n+1);
2076 parbi->appendChild (newbi);
2078 }else if (num==-1 || num==-3)
2080 // insert below selection
2081 parbi=(BranchItem*)dst->parent();
2083 n=dst->childNumber()+ (3+num)/2; //-1 |-> 1;-3 |-> 0
2084 beginInsertRows (parix,n,n);
2085 parbi->insertBranch(n,newbi);
2088 emit (layoutChanged() );
2090 // save scroll state. If scrolled, automatically select
2091 // new branch in order to tmp unscroll parent...
2092 newbi->createMapObj(mapScene);
2098 BranchItem* VymModel::addNewBranch(int pos)
2100 // Different meaning than num in addNewBranchInt!
2104 BranchItem *newbi=NULL;
2105 BranchItem *selbi=getSelectedBranchItem();
2109 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2112 newbi=addNewBranchInt (selbi,pos-2);
2120 QString ("addBranch (%1)").arg(pos),
2121 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2124 // selection.update(); FIXME-3
2125 latestAddedItem=newbi;
2126 // In Network mode, the client needs to know where the new branch is,
2127 // so we have to pass on this information via saveState.
2128 // TODO: Get rid of this positioning workaround
2129 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2130 sendData ("selectLatestAdded ()");
2131 sendData (QString("move %1").arg(ps));
2140 BranchItem* VymModel::addNewBranchBefore()
2142 BranchItem *newbi=NULL;
2143 BranchItem *selbi=getSelectedBranchItem();
2144 if (selbi && selbi->getType()==TreeItem::Branch)
2145 // We accept no MapCenter here, so we _have_ a parent
2147 //QPointF p=bo->getRelPos();
2150 // add below selection
2151 newbi=addNewBranchInt (selbi,-1);
2155 //newbi->move2RelPos (p);
2157 // Move selection to new branch
2158 relinkBranch (selbi,newbi,0);
2160 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2161 QString ("Add branch before %1").arg(getObjectName(selbi)));
2163 // FIXME-3 needed? reposition();
2164 // selection.update(); FIXME-3
2167 //FIXME-3 needed? latestSelectionString=selection.getSelectString();
2171 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2175 emit (layoutAboutToBeChanged() );
2176 BranchItem *branchpi=(BranchItem*)branch->parent();
2177 // Remove at current position
2178 int n=branch->childNum();
2179 beginRemoveRows (index(branchpi),n,n);
2180 branchpi->removeChild (n);
2183 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2185 // Append as last branch to dst
2186 if (dst->branchCount()==0)
2189 n=dst->getFirstBranch()->childNumber();
2190 beginInsertRows (index(dst),n+pos,n+pos);
2191 dst->insertBranch (pos,branch);
2194 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2195 emit (layoutChanged() );
2196 reposition(); // both for moveUp/Down and relinking
2203 void VymModel::deleteSelection()
2205 BranchItem *selbi=getSelectedBranchItem();
2209 TreeItem *pi=selbi->parent();
2210 QModelIndex parentIndex=index(pi);
2212 if (selbi->isBranchLikeType() )
2215 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2217 emit (layoutAboutToBeChanged() );
2219 int n=selbi->childNum();
2220 beginRemoveRows (parentIndex,n,n);
2221 removeRows (n,1,parentIndex);
2224 emitShowSelection();
2227 emit (layoutChanged() );
2230 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2235 BranchObj* par=(BranchObj*)fio->getParObj();
2236 saveStateChangingPart(
2240 QString("Delete %1").arg(getObjectName(fio))
2243 par->removeFloatImage(fio);
2246 emitShowSelection();
2252 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2256 BranchObj *bo=getSelectedBranch();
2260 par=(BranchObj*)(bo->getParObj());
2262 // Don't use this on mapcenter
2265 // Check if we have childs at all to keep
2266 if (bo->getTreeItem()->branchCount()==0)
2272 QPointF p=bo->getRelPos();
2273 saveStateChangingPart(
2276 "deleteKeepChildren ()",
2277 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2280 QString sel=getSelectString(bo);
2282 par->removeBranchHere(bo);
2285 getSelectedBranch()->move2RelPos (p);
2290 void VymModel::deleteChildren()
2293 BranchItem *selbi=getSelectedBranchItem();
2296 saveStateChangingPart(
2299 "deleteChildren ()",
2300 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2302 emit (layoutAboutToBeChanged() );
2304 QModelIndex ix=index (selbi);
2305 int n=selbi->branchCount()-1;
2306 beginRemoveRows (ix,0,n);
2307 removeRows (0,n+1,ix);
2309 emit (layoutChanged() );
2314 bool VymModel::scrollBranch(BranchItem *bi)
2318 if (bi->isScrolled()) return false;
2319 if (bi->branchCount()==0) return false;
2320 if (bi->depth()==0) return false;
2321 if (bi->toggleScroll())
2328 QString ("%1 ()").arg(u),
2330 QString ("%1 ()").arg(r),
2331 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2333 emitDataHasChanged(bi);
2335 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2342 bool VymModel::unscrollBranch(BranchItem *bi)
2346 if (!bi->isScrolled()) return false;
2347 if (bi->branchCount()==0) return false;
2348 if (bi->depth()==0) return false;
2355 QString ("%1 ()").arg(u),
2357 QString ("%1 ()").arg(r),
2358 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2361 emitDataHasChanged(bi);
2364 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2370 void VymModel::toggleScroll()
2372 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2373 if (bi && bi->isBranchLikeType() )
2375 if (bi->isScrolled())
2376 unscrollBranch (bi);
2380 // saveState is called in above functions
2383 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2387 BranchObj *bo=getSelectedBranch();
2393 if (bo->isScrolled()) unscrollBranch (bo);
2400 void VymModel::emitExpandAll()
2402 emit (expandAll() );
2405 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2407 BranchItem *bi=getSelectedBranchItem();
2411 if (bi->isActiveStandardFlag(name))
2423 QString("%1 (\"%2\")").arg(u).arg(name),
2425 QString("%1 (\"%2\")").arg(r).arg(name),
2426 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2427 bi->toggleStandardFlag (name, master);
2433 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2436 BranchObj *bo=getSelectedBranch();
2439 FloatImageObj *fio=bo->addFloatImage();
2441 fio->setOriginalFilename("No original filename (image added by dropevent)");
2442 QString s=getSelectString(bo);
2443 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2444 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2446 // FIXME-3 VM needed? scene()->update();
2452 void VymModel::colorBranch (QColor c) //FIXME-2
2455 BranchObj *bo=getSelectedBranch();
2460 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2462 QString ("colorBranch (\"%1\")").arg(c.name()),
2463 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2465 bo->setColor(c); // color branch
2470 void VymModel::colorSubtree (QColor c) //FIXME-2
2473 BranchObj *bo=getSelectedBranch();
2476 saveStateChangingPart(
2479 QString ("colorSubtree (\"%1\")").arg(c.name()),
2480 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2482 bo->setColorSubtree (c); // color links, color children
2487 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2490 BranchObj *bo=getSelectedBranch();
2491 if (bo) return bo->getColor();
2493 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2500 void VymModel::editURL()
2502 TreeItem *selti=getSelectedItem();
2506 QString text = QInputDialog::getText(
2507 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2508 selti->getURL(), &ok, NULL);
2510 // user entered something and pressed OK
2515 void VymModel::editLocalURL()
2517 TreeItem *selti=getSelectedItem();
2520 QStringList filters;
2521 filters <<"All files (*)";
2522 filters << tr("Text","Filedialog") + " (*.txt)";
2523 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2524 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2525 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2526 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2527 fd->setFilters (filters);
2528 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2529 fd->setDirectory (lastFileDir);
2530 if (! selti->getVymLink().isEmpty() )
2531 fd->selectFile( selti->getURL() );
2534 if ( fd->exec() == QDialog::Accepted )
2536 lastFileDir=QDir (fd->directory().path());
2537 setURL (fd->selectedFile() );
2543 void VymModel::editHeading2URL()
2545 TreeItem *selti=getSelectedItem();
2547 setURL (selti->getHeading());
2550 void VymModel::editBugzilla2URL()
2552 TreeItem *selti=getSelectedItem();
2555 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2560 void VymModel::editFATE2URL()
2562 TreeItem *selti=getSelectedItem();
2565 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2568 "setURL (\""+selti->getURL()+"\")",
2570 "setURL (\""+url+"\")",
2571 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2573 selti->setURL (url);
2574 // FIXME-4 updateActions();
2578 void VymModel::editVymLink()
2580 BranchItem *bi=getSelectedBranchItem();
2583 QStringList filters;
2584 filters <<"VYM map (*.vym)";
2585 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2586 fd->setFilters (filters);
2587 fd->setCaption(vymName+" - " +tr("Link to another map"));
2588 fd->setDirectory (lastFileDir);
2589 if (! bi->getVymLink().isEmpty() )
2590 fd->selectFile( bi->getVymLink() );
2594 if ( fd->exec() == QDialog::Accepted )
2596 lastFileDir=QDir (fd->directory().path());
2599 "setVymLink (\""+bi->getVymLink()+"\")",
2601 "setVymLink (\""+fd->selectedFile()+"\")",
2602 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2604 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2609 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2611 // Internal function, no saveState needed
2612 BranchItem *bi=getSelectedBranchItem();
2618 //selection.update();
2619 emitShowSelection();
2623 void VymModel::deleteVymLink()
2625 BranchItem *bi=getSelectedBranchItem();
2630 "setVymLink (\""+bi->getVymLink()+"\")",
2632 "setVymLink (\"\")",
2633 QString("Unset vymlink of %1").arg(getObjectName(bi))
2635 bi->setVymLink ("" );
2641 QString VymModel::getVymLink()
2643 BranchItem *bi=getSelectedBranchItem();
2645 return bi->getVymLink();
2651 QStringList VymModel::getVymLinks()
2654 BranchItem *cur=getSelectedBranchItem();
2655 BranchItem *prev=NULL;
2660 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2661 cur=next (cur,prev,d);
2667 void VymModel::followXLink(int i) // FIXME-2
2671 BranchObj *bo=getSelectedBranch();
2674 bo=bo->XLinkTargetAt(i);
2677 selection.select(bo);
2678 emitShowSelection();
2684 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2688 BranchObj *bo=getSelectedBranch();
2691 XLinkObj *xlo=bo->XLinkAt(i);
2694 EditXLinkDialog dia;
2696 dia.setSelection(bo);
2697 if (dia.exec() == QDialog::Accepted)
2699 if (dia.useSettingsGlobal() )
2701 setMapDefXLinkColor (xlo->getColor() );
2702 setMapDefXLinkWidth (xlo->getWidth() );
2704 if (dia.deleteXLink())
2705 bo->deleteXLinkAt(i);
2716 //////////////////////////////////////////////
2718 //////////////////////////////////////////////
2720 void VymModel::parseAtom(const QString &atom)
2722 TreeItem* selti=getSelectedItem();
2723 BranchItem *selbi=getSelectedBranchItem();
2729 // Split string s into command and parameters
2730 parser.parseAtom (atom);
2731 QString com=parser.getCommand();
2733 // External commands
2734 /////////////////////////////////////////////////////////////////////
2735 if (com=="addBranch")
2739 parser.setError (Aborted,"Nothing selected");
2740 } else if (! selbi )
2742 parser.setError (Aborted,"Type of selection is not a branch");
2747 if (parser.checkParCount(pl))
2749 if (parser.parCount()==0)
2753 n=parser.parInt (ok,0);
2754 if (ok ) addNewBranch (n);
2758 /////////////////////////////////////////////////////////////////////
2759 } else if (com=="addBranchBefore")
2763 parser.setError (Aborted,"Nothing selected");
2764 } else if (! selbi )
2766 parser.setError (Aborted,"Type of selection is not a branch");
2769 if (parser.parCount()==0)
2771 addNewBranchBefore ();
2774 /////////////////////////////////////////////////////////////////////
2775 } else if (com==QString("addMapCenter"))
2777 if (parser.checkParCount(2))
2779 x=parser.parDouble (ok,0);
2782 y=parser.parDouble (ok,1);
2783 if (ok) addMapCenter (QPointF(x,y));
2786 /////////////////////////////////////////////////////////////////////
2787 } else if (com==QString("addMapReplace"))
2791 parser.setError (Aborted,"Nothing selected");
2792 } else if (! selbi )
2794 parser.setError (Aborted,"Type of selection is not a branch");
2795 } else if (parser.checkParCount(1))
2797 //s=parser.parString (ok,0); // selection
2798 t=parser.parString (ok,0); // path to map
2799 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2800 addMapReplaceInt(getSelectString(selbi),t);
2802 /////////////////////////////////////////////////////////////////////
2803 } else if (com==QString("addMapInsert"))
2807 parser.setError (Aborted,"Nothing selected");
2808 } else if (! selbi )
2810 parser.setError (Aborted,"Type of selection is not a branch");
2813 if (parser.checkParCount(2))
2815 t=parser.parString (ok,0); // path to map
2816 n=parser.parInt(ok,1); // position
2817 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2818 addMapInsertInt(t,n);
2821 /////////////////////////////////////////////////////////////////////
2822 } else if (com=="clearFlags")
2826 parser.setError (Aborted,"Nothing selected");
2827 } else if (! selbi )
2829 parser.setError (Aborted,"Type of selection is not a branch");
2830 } else if (parser.checkParCount(0))
2832 selbi->deactivateAllStandardFlags();
2834 /////////////////////////////////////////////////////////////////////
2835 } else if (com=="colorBranch")
2839 parser.setError (Aborted,"Nothing selected");
2840 } else if (! selbi )
2842 parser.setError (Aborted,"Type of selection is not a branch");
2843 } else if (parser.checkParCount(1))
2845 QColor c=parser.parColor (ok,0);
2846 if (ok) colorBranch (c);
2848 /////////////////////////////////////////////////////////////////////
2849 } else if (com=="colorSubtree")
2853 parser.setError (Aborted,"Nothing selected");
2854 } else if (! selbi )
2856 parser.setError (Aborted,"Type of selection is not a branch");
2857 } else if (parser.checkParCount(1))
2859 QColor c=parser.parColor (ok,0);
2860 if (ok) colorSubtree (c);
2862 /////////////////////////////////////////////////////////////////////
2863 } else if (com=="copy")
2867 parser.setError (Aborted,"Nothing selected");
2868 } else if ( selectionType()!=TreeItem::Branch &&
2869 selectionType()!=TreeItem::MapCenter &&
2870 selectionType()!=TreeItem::Image )
2872 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2873 } else if (parser.checkParCount(0))
2877 /////////////////////////////////////////////////////////////////////
2878 } else if (com=="cut")
2882 parser.setError (Aborted,"Nothing selected");
2883 } else if ( selectionType()!=TreeItem::Branch &&
2884 selectionType()!=TreeItem::MapCenter &&
2885 selectionType()!=TreeItem::Image )
2887 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2888 } else if (parser.checkParCount(0))
2892 /////////////////////////////////////////////////////////////////////
2893 } else if (com=="delete")
2897 parser.setError (Aborted,"Nothing selected");
2899 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2901 parser.setError (Aborted,"Type of selection is wrong.");
2904 else if (parser.checkParCount(0))
2908 /////////////////////////////////////////////////////////////////////
2909 } else if (com=="deleteKeepChildren")
2913 parser.setError (Aborted,"Nothing selected");
2914 } else if (! selbi )
2916 parser.setError (Aborted,"Type of selection is not a branch");
2917 } else if (parser.checkParCount(0))
2919 deleteKeepChildren();
2921 /////////////////////////////////////////////////////////////////////
2922 } else if (com=="deleteChildren")
2926 parser.setError (Aborted,"Nothing selected");
2929 parser.setError (Aborted,"Type of selection is not a branch");
2930 } else if (parser.checkParCount(0))
2934 /////////////////////////////////////////////////////////////////////
2935 } else if (com=="exportASCII")
2939 if (parser.parCount()>=1)
2940 // Hey, we even have a filename
2941 fname=parser.parString(ok,0);
2944 parser.setError (Aborted,"Could not read filename");
2947 exportASCII (fname,false);
2949 /////////////////////////////////////////////////////////////////////
2950 } else if (com=="exportImage")
2954 if (parser.parCount()>=2)
2955 // Hey, we even have a filename
2956 fname=parser.parString(ok,0);
2959 parser.setError (Aborted,"Could not read filename");
2962 QString format="PNG";
2963 if (parser.parCount()>=2)
2965 format=parser.parString(ok,1);
2967 exportImage (fname,false,format);
2969 /////////////////////////////////////////////////////////////////////
2970 } else if (com=="exportXHTML")
2974 if (parser.parCount()>=2)
2975 // Hey, we even have a filename
2976 fname=parser.parString(ok,1);
2979 parser.setError (Aborted,"Could not read filename");
2982 exportXHTML (fname,false);
2984 /////////////////////////////////////////////////////////////////////
2985 } else if (com=="exportXML")
2989 if (parser.parCount()>=2)
2990 // Hey, we even have a filename
2991 fname=parser.parString(ok,1);
2994 parser.setError (Aborted,"Could not read filename");
2997 exportXML (fname,false);
2999 /////////////////////////////////////////////////////////////////////
3000 } else if (com=="importDir")
3004 parser.setError (Aborted,"Nothing selected");
3005 } else if (! selbi )
3007 parser.setError (Aborted,"Type of selection is not a branch");
3008 } else if (parser.checkParCount(1))
3010 s=parser.parString(ok,0);
3011 if (ok) importDirInt(s);
3013 /////////////////////////////////////////////////////////////////////
3014 } else /* FIXME-2 if (com=="linkTo")
3018 parser.setError (Aborted,"Nothing selected");
3021 if (parser.checkParCount(4))
3023 // 0 selectstring of parent
3024 // 1 num in parent (for branches)
3025 // 2,3 x,y of mainbranch or mapcenter
3026 s=parser.parString(ok,0);
3027 LinkableMapObj *dst=findObjBySelect (s);
3030 if (typeid(*dst) == typeid(BranchObj) )
3032 // Get number in parent
3033 n=parser.parInt (ok,1);
3036 selb->linkTo ((BranchObj*)(dst),n);
3039 } else if (typeid(*dst) == typeid(MapCenterObj) )
3041 selb->linkTo ((BranchObj*)(dst),-1);
3042 // Get coordinates of mainbranch
3043 x=parser.parDouble(ok,2);
3046 y=parser.parDouble(ok,3);
3056 } else if ( selectionType() == TreeItem::Image)
3058 if (parser.checkParCount(1))
3060 // 0 selectstring of parent
3061 s=parser.parString(ok,0);
3062 LinkableMapObj *dst=findObjBySelect (s);
3065 if (typeid(*dst) == typeid(BranchObj) ||
3066 typeid(*dst) == typeid(MapCenterObj))
3067 linkFloatImageTo (getSelectString(dst));
3069 parser.setError (Aborted,"Destination is not a branch");
3072 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3073 /////////////////////////////////////////////////////////////////////
3074 } else */ if (com=="loadImage")
3078 parser.setError (Aborted,"Nothing selected");
3079 } else if (! selbi )
3081 parser.setError (Aborted,"Type of selection is not a branch");
3082 } else if (parser.checkParCount(1))
3084 s=parser.parString(ok,0);
3085 if (ok) loadFloatImageInt (s);
3087 /////////////////////////////////////////////////////////////////////
3088 } else if (com=="moveUp")
3092 parser.setError (Aborted,"Nothing selected");
3093 } else if (! selbi )
3095 parser.setError (Aborted,"Type of selection is not a branch");
3096 } else if (parser.checkParCount(0))
3100 /////////////////////////////////////////////////////////////////////
3101 } else if (com=="moveDown")
3105 parser.setError (Aborted,"Nothing selected");
3106 } else if (! selbi )
3108 parser.setError (Aborted,"Type of selection is not a branch");
3109 } else if (parser.checkParCount(0))
3113 /////////////////////////////////////////////////////////////////////
3114 } else if (com=="move")
3118 parser.setError (Aborted,"Nothing selected");
3119 } else if ( selectionType()!=TreeItem::Branch &&
3120 selectionType()!=TreeItem::MapCenter &&
3121 selectionType()!=TreeItem::Image )
3123 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3124 } else if (parser.checkParCount(2))
3126 x=parser.parDouble (ok,0);
3129 y=parser.parDouble (ok,1);
3133 /////////////////////////////////////////////////////////////////////
3134 } else if (com=="moveRel")
3138 parser.setError (Aborted,"Nothing selected");
3139 } else if ( selectionType()!=TreeItem::Branch &&
3140 selectionType()!=TreeItem::MapCenter &&
3141 selectionType()!=TreeItem::Image )
3143 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3144 } else if (parser.checkParCount(2))
3146 x=parser.parDouble (ok,0);
3149 y=parser.parDouble (ok,1);
3150 if (ok) moveRel (x,y);
3153 /////////////////////////////////////////////////////////////////////
3154 } else if (com=="nop")
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="paste")
3161 parser.setError (Aborted,"Nothing selected");
3162 } else if (! selbi )
3164 parser.setError (Aborted,"Type of selection is not a branch");
3165 } else if (parser.checkParCount(1))
3167 n=parser.parInt (ok,0);
3168 if (ok) pasteNoSave(n);
3170 /////////////////////////////////////////////////////////////////////
3171 } else if (com=="qa")
3175 parser.setError (Aborted,"Nothing selected");
3176 } else if (! selbi )
3178 parser.setError (Aborted,"Type of selection is not a branch");
3179 } else if (parser.checkParCount(4))
3182 c=parser.parString (ok,0);
3185 parser.setError (Aborted,"No comment given");
3188 s=parser.parString (ok,1);
3191 parser.setError (Aborted,"First parameter is not a string");
3194 t=parser.parString (ok,2);
3197 parser.setError (Aborted,"Condition is not a string");
3200 u=parser.parString (ok,3);
3203 parser.setError (Aborted,"Third parameter is not a string");
3208 parser.setError (Aborted,"Unknown type: "+s);
3213 parser.setError (Aborted,"Unknown operator: "+t);
3218 parser.setError (Aborted,"Type of selection is not a branch");
3221 if (selbi->getHeading() == u)
3223 cout << "PASSED: " << qPrintable (c) << endl;
3226 cout << "FAILED: " << qPrintable (c) << endl;
3236 /////////////////////////////////////////////////////////////////////
3237 } else if (com=="saveImage")
3239 FloatImageObj *fio=selection.getFloatImage();
3242 parser.setError (Aborted,"Type of selection is not an image");
3243 } else if (parser.checkParCount(2))
3245 s=parser.parString(ok,0);
3248 t=parser.parString(ok,1);
3249 if (ok) saveFloatImageInt (fio,t,s);
3252 /////////////////////////////////////////////////////////////////////
3253 } else if (com=="scroll")
3257 parser.setError (Aborted,"Nothing selected");
3258 } else if (! selbi )
3260 parser.setError (Aborted,"Type of selection is not a branch");
3261 } else if (parser.checkParCount(0))
3263 if (!scrollBranch (selbi))
3264 parser.setError (Aborted,"Could not scroll branch");
3266 /////////////////////////////////////////////////////////////////////
3267 } else if (com=="select")
3269 if (parser.checkParCount(1))
3271 s=parser.parString(ok,0);
3274 /////////////////////////////////////////////////////////////////////
3275 } else if (com=="selectLastBranch")
3279 parser.setError (Aborted,"Nothing selected");
3280 } else if (! selbi )
3282 parser.setError (Aborted,"Type of selection is not a branch");
3283 } else if (parser.checkParCount(0))
3285 BranchItem *bi=selbi->getLastBranch();
3287 parser.setError (Aborted,"Could not select last branch");
3288 select (bi); // FIXME-3 was selectInt
3291 /////////////////////////////////////////////////////////////////////
3292 } else /* FIXME-2 if (com=="selectLastImage")
3296 parser.setError (Aborted,"Nothing selected");
3297 } else if (! selbi )
3299 parser.setError (Aborted,"Type of selection is not a branch");
3300 } else if (parser.checkParCount(0))
3302 FloatImageObj *fio=selb->getLastFloatImage();
3304 parser.setError (Aborted,"Could not select last image");
3305 select (fio); // FIXME-3 was selectInt
3308 /////////////////////////////////////////////////////////////////////
3309 } else */ if (com=="selectLatestAdded")
3311 if (!latestAddedItem)
3313 parser.setError (Aborted,"No latest added object");
3316 if (!select (latestAddedItem))
3317 parser.setError (Aborted,"Could not select latest added object ");
3319 /////////////////////////////////////////////////////////////////////
3320 } else if (com=="setFrameType")
3322 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3324 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3326 else if (parser.checkParCount(1))
3328 s=parser.parString(ok,0);
3329 if (ok) setFrameType (s);
3331 /////////////////////////////////////////////////////////////////////
3332 } else if (com=="setFramePenColor")
3334 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3336 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3338 else if (parser.checkParCount(1))
3340 QColor c=parser.parColor(ok,0);
3341 if (ok) setFramePenColor (c);
3343 /////////////////////////////////////////////////////////////////////
3344 } else if (com=="setFrameBrushColor")
3346 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3348 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3350 else if (parser.checkParCount(1))
3352 QColor c=parser.parColor(ok,0);
3353 if (ok) setFrameBrushColor (c);
3355 /////////////////////////////////////////////////////////////////////
3356 } else if (com=="setFramePadding")
3358 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3360 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3362 else if (parser.checkParCount(1))
3364 n=parser.parInt(ok,0);
3365 if (ok) setFramePadding(n);
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="setFrameBorderWidth")
3370 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3372 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3374 else if (parser.checkParCount(1))
3376 n=parser.parInt(ok,0);
3377 if (ok) setFrameBorderWidth (n);
3379 /////////////////////////////////////////////////////////////////////
3380 } else if (com=="setMapAuthor")
3382 if (parser.checkParCount(1))
3384 s=parser.parString(ok,0);
3385 if (ok) setAuthor (s);
3387 /////////////////////////////////////////////////////////////////////
3388 } else if (com=="setMapComment")
3390 if (parser.checkParCount(1))
3392 s=parser.parString(ok,0);
3393 if (ok) setComment(s);
3395 /////////////////////////////////////////////////////////////////////
3396 } else if (com=="setMapBackgroundColor")
3400 parser.setError (Aborted,"Nothing selected");
3401 } else if (! selbi )
3403 parser.setError (Aborted,"Type of selection is not a branch");
3404 } else if (parser.checkParCount(1))
3406 QColor c=parser.parColor (ok,0);
3407 if (ok) setMapBackgroundColor (c);
3409 /////////////////////////////////////////////////////////////////////
3410 } else if (com=="setMapDefLinkColor")
3414 parser.setError (Aborted,"Nothing selected");
3415 } else if (! selbi )
3417 parser.setError (Aborted,"Type of selection is not a branch");
3418 } else if (parser.checkParCount(1))
3420 QColor c=parser.parColor (ok,0);
3421 if (ok) setMapDefLinkColor (c);
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="setMapLinkStyle")
3426 if (parser.checkParCount(1))
3428 s=parser.parString (ok,0);
3429 if (ok) setMapLinkStyle(s);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="setHeading")
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 s=parser.parString (ok,0);
3446 /////////////////////////////////////////////////////////////////////
3447 } else if (com=="setHideExport")
3451 parser.setError (Aborted,"Nothing selected");
3452 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3454 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3455 } else if (parser.checkParCount(1))
3457 b=parser.parBool(ok,0);
3458 if (ok) setHideExport (b);
3460 /////////////////////////////////////////////////////////////////////
3461 } else if (com=="setIncludeImagesHorizontally")
3465 parser.setError (Aborted,"Nothing selected");
3468 parser.setError (Aborted,"Type of selection is not a branch");
3469 } else if (parser.checkParCount(1))
3471 b=parser.parBool(ok,0);
3472 if (ok) setIncludeImagesHor(b);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="setIncludeImagesVertically")
3479 parser.setError (Aborted,"Nothing selected");
3482 parser.setError (Aborted,"Type of selection is not a branch");
3483 } else if (parser.checkParCount(1))
3485 b=parser.parBool(ok,0);
3486 if (ok) setIncludeImagesVer(b);
3488 /////////////////////////////////////////////////////////////////////
3489 } else if (com=="setHideLinkUnselected")
3493 parser.setError (Aborted,"Nothing selected");
3494 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3496 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3497 } else if (parser.checkParCount(1))
3499 b=parser.parBool(ok,0);
3500 if (ok) setHideLinkUnselected(b);
3502 /////////////////////////////////////////////////////////////////////
3503 } else if (com=="setSelectionColor")
3505 if (parser.checkParCount(1))
3507 QColor c=parser.parColor (ok,0);
3508 if (ok) setSelectionColorInt (c);
3510 /////////////////////////////////////////////////////////////////////
3511 } else if (com=="setURL")
3515 parser.setError (Aborted,"Nothing selected");
3516 } else if (! selbi )
3518 parser.setError (Aborted,"Type of selection is not a branch");
3519 } else if (parser.checkParCount(1))
3521 s=parser.parString (ok,0);
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="setVymLink")
3529 parser.setError (Aborted,"Nothing selected");
3530 } else if (! selbi )
3532 parser.setError (Aborted,"Type of selection is not a branch");
3533 } else if (parser.checkParCount(1))
3535 s=parser.parString (ok,0);
3536 if (ok) setVymLink(s);
3539 /////////////////////////////////////////////////////////////////////
3540 else if (com=="setFlag")
3544 parser.setError (Aborted,"Nothing selected");
3545 } else if (! selbi )
3547 parser.setError (Aborted,"Type of selection is not a branch");
3548 } else if (parser.checkParCount(1))
3550 s=parser.parString(ok,0);
3552 selbi->activateStandardFlag(s);
3554 /////////////////////////////////////////////////////////////////////
3555 } else /* FIXME-2 if (com=="setFrameType")
3559 parser.setError (Aborted,"Nothing selected");
3562 parser.setError (Aborted,"Type of selection is not a branch");
3563 } else if (parser.checkParCount(1))
3565 s=parser.parString(ok,0);
3569 /////////////////////////////////////////////////////////////////////
3570 } else*/ if (com=="sortChildren")
3574 parser.setError (Aborted,"Nothing selected");
3575 } else if (! selbi )
3577 parser.setError (Aborted,"Type of selection is not a branch");
3578 } else if (parser.checkParCount(0))
3582 /////////////////////////////////////////////////////////////////////
3583 } else if (com=="toggleFlag")
3587 parser.setError (Aborted,"Nothing selected");
3588 } else if (! selbi )
3590 parser.setError (Aborted,"Type of selection is not a branch");
3591 } else if (parser.checkParCount(1))
3593 s=parser.parString(ok,0);
3595 selbi->toggleStandardFlag(s);
3597 /////////////////////////////////////////////////////////////////////
3598 } else if (com=="unscroll")
3602 parser.setError (Aborted,"Nothing selected");
3603 } else if (! selbi )
3605 parser.setError (Aborted,"Type of selection is not a branch");
3606 } else if (parser.checkParCount(0))
3608 if (!unscrollBranch (selbi))
3609 parser.setError (Aborted,"Could not unscroll branch");
3611 /////////////////////////////////////////////////////////////////////
3612 } else if (com=="unscrollChildren")
3616 parser.setError (Aborted,"Nothing selected");
3617 } else if (! selbi )
3619 parser.setError (Aborted,"Type of selection is not a branch");
3620 } else if (parser.checkParCount(0))
3622 unscrollChildren ();
3624 /////////////////////////////////////////////////////////////////////
3625 } else if (com=="unsetFlag")
3629 parser.setError (Aborted,"Nothing selected");
3630 } else if (! selbi )
3632 parser.setError (Aborted,"Type of selection is not a branch");
3633 } else if (parser.checkParCount(1))
3635 s=parser.parString(ok,0);
3637 selbi->deactivateStandardFlag(s);
3640 parser.setError (Aborted,"Unknown command");
3643 if (parser.errorLevel()==NoError)
3645 // setChanged(); FIXME-2 should not be called e.g. for export?!
3650 // TODO Error handling
3651 qWarning("VymModel::parseAtom: Error!");
3652 qWarning(parser.errorMessage());
3656 void VymModel::runScript (QString script)
3658 parser.setScript (script);
3660 while (parser.next() )
3661 parseAtom(parser.getAtom());
3664 void VymModel::setExportMode (bool b)
3666 // should be called before and after exports
3667 // depending on the settings
3668 if (b && settings.value("/export/useHideExport","true")=="true")
3669 setHideTmpMode (TreeItem::HideExport);
3671 setHideTmpMode (TreeItem::HideNone);
3674 void VymModel::exportImage(QString fname, bool askName, QString format)
3678 fname=getMapName()+".png";
3685 QFileDialog *fd=new QFileDialog (NULL);
3686 fd->setCaption (tr("Export map as image"));
3687 fd->setDirectory (lastImageDir);
3688 fd->setFileMode(QFileDialog::AnyFile);
3689 fd->setFilters (imageIO.getFilters() );
3692 fl=fd->selectedFiles();
3694 format=imageIO.getType(fd->selectedFilter());
3698 setExportMode (true);
3699 QPixmap pix (getPixmap());
3700 pix.save(fname, format);
3701 setExportMode (false);
3705 void VymModel::exportXML(QString dir, bool askForName)
3709 dir=browseDirectory(NULL,tr("Export XML to directory"));
3710 if (dir =="" && !reallyWriteDirectory(dir) )
3714 // Hide stuff during export, if settings want this
3715 setExportMode (true);
3717 // Create subdirectories
3720 // write to directory
3721 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3724 file.setName ( dir + "/"+mapName+".xml");
3725 if ( !file.open( QIODevice::WriteOnly ) )
3727 // This should neverever happen
3728 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3732 // Write it finally, and write in UTF8, no matter what
3733 QTextStream ts( &file );
3734 ts.setEncoding (QTextStream::UnicodeUTF8);
3738 // Now write image, too
3739 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3741 setExportMode (false);
3744 void VymModel::exportASCII(QString fname,bool askName)
3749 ex.setFile (mapName+".txt");
3755 //ex.addFilter ("TXT (*.txt)");
3756 ex.setDir(lastImageDir);
3757 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3762 setExportMode(true);
3764 setExportMode(false);
3768 void VymModel::exportXHTML (const QString &dir, bool askForName)
3770 ExportXHTMLDialog dia(NULL);
3771 dia.setFilePath (filePath );
3772 dia.setMapName (mapName );
3774 if (dir!="") dia.setDir (dir);
3780 if (dia.exec()!=QDialog::Accepted)
3784 QDir d (dia.getDir());
3785 // Check, if warnings should be used before overwriting
3786 // the output directory
3787 if (d.exists() && d.count()>0)
3790 warn.showCancelButton (true);
3791 warn.setText(QString(
3792 "The directory %1 is not empty.\n"
3793 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3794 warn.setCaption("Warning: Directory not empty");
3795 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3797 if (warn.exec()!=QDialog::Accepted) ok=false;
3804 exportXML (dia.getDir(),false );
3805 dia.doExport(mapName );
3806 //if (dia.hasChanged()) setChanged();
3810 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3815 if (ex.setConfigFile(cf))
3817 setExportMode (true);
3818 ex.exportPresentation();
3819 setExportMode (false);
3826 //////////////////////////////////////////////
3828 //////////////////////////////////////////////
3830 void VymModel::registerEditor(QWidget *me)
3832 mapEditor=(MapEditor*)me;
3835 void VymModel::unregisterEditor(QWidget *)
3840 void VymModel::setContextPos(QPointF p)
3845 void VymModel::unsetContextPos()
3847 contextPos=QPointF();
3850 void VymModel::updateNoteFlag()
3853 TreeItem *selti=getSelectedItem();
3856 if (textEditor->isEmpty())
3859 selti->setNote (textEditor->getText());
3860 emitDataHasChanged(selti);
3866 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3868 //cout << "VM::updateRelPos...\n";
3869 for (int i=0; i<rootItem->branchCount(); i++)
3870 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3873 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3875 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3876 if (blockReposition) return;
3878 for (int i=0;i<rootItem->branchCount(); i++)
3879 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3882 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3885 // Creating (arbitrary) shapes
3888 QRectF rb=bo->getBBox();
3889 if (bo->getDepth()==0)
3891 // Just take BBox of this mapCenter
3892 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3896 // Take union of BBox and TotalBBox
3898 QRectF ra=bo->getTotalBBox();
3899 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3902 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3905 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3907 p <<ra.bottomRight()
3909 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3912 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3917 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3921 // Move all branches and MapCenters away from lmo
3922 // to avoid collisions
3928 BranchObj *boA=(BranchObj*)lmo;
3930 for (int i=0; i<rootItem->branchCount(); i++)
3932 boB=rootItem->getBranchNum(i);
3935 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3938 <<" ("<<qPrintable(boA->getHeading() )<<")"
3939 <<" with ("<< qPrintable (boB->getHeading() )
3942 <<" minT="<<r.minTranslation<<endl<<endl;
3947 QPixmap VymModel::getPixmap()
3949 QRectF mapRect=getTotalBBox();
3950 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3953 pp.setRenderHints(mapEditor->renderHints());
3955 // Don't print the visualisation of selection
3956 selection.unselect();
3958 mapScene->render ( &pp,
3959 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3960 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3962 // Restore selection
3963 selection.reselect();
3969 void VymModel::setMapLinkStyle (const QString & s)
3974 case LinkableMapObj::Line :
3977 case LinkableMapObj::Parabel:
3978 snow="StyleParabel";
3980 case LinkableMapObj::PolyLine:
3981 snow="StylePolyLine";
3983 case LinkableMapObj::PolyParabel:
3984 snow="StylePolyParabel";
3987 snow="UndefinedStyle";
3992 QString("setMapLinkStyle (\"%1\")").arg(s),
3993 QString("setMapLinkStyle (\"%1\")").arg(snow),
3994 QString("Set map link style (\"%1\")").arg(s)
3998 linkstyle=LinkableMapObj::Line;
3999 else if (s=="StyleParabel")
4000 linkstyle=LinkableMapObj::Parabel;
4001 else if (s=="StylePolyLine")
4002 linkstyle=LinkableMapObj::PolyLine;
4003 else if (s=="StylePolyParabel")
4004 linkstyle=LinkableMapObj::PolyParabel;
4006 linkstyle=LinkableMapObj::UndefinedStyle;
4008 BranchItem *cur=NULL;
4009 BranchItem *prev=NULL;
4015 bo=(BranchObj*)(cur->getLMO() );
4016 bo->setLinkStyle(bo->getDefLinkStyle());
4017 cur=next(cur,prev,d);
4022 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4027 void VymModel::setMapDefLinkColor(QColor col)
4029 if ( !col.isValid() ) return;
4031 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4032 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4033 QString("Set map link color to %1").arg(col.name())
4037 BranchItem *cur=NULL;
4038 BranchItem *prev=NULL;
4041 cur=next(cur,prev,d);
4044 bo=(BranchObj*)(cur->getLMO() );
4051 void VymModel::setMapLinkColorHintInt()
4053 // called from setMapLinkColorHint(lch) or at end of parse
4054 BranchItem *cur=NULL;
4055 BranchItem *prev=NULL;
4058 cur=next(cur,prev,d);
4061 bo=(BranchObj*)(cur->getLMO() );
4063 cur=next(cur,prev,d);
4067 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4070 setMapLinkColorHintInt();
4073 void VymModel::toggleMapLinkColorHint()
4075 if (linkcolorhint==LinkableMapObj::HeadingColor)
4076 linkcolorhint=LinkableMapObj::DefaultColor;
4078 linkcolorhint=LinkableMapObj::HeadingColor;
4079 BranchItem *cur=NULL;
4080 BranchItem *prev=NULL;
4083 cur=next(cur,prev,d);
4086 bo=(BranchObj*)(cur->getLMO() );
4092 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4094 Q3FileDialog *fd=new Q3FileDialog( NULL);
4095 fd->setMode (Q3FileDialog::ExistingFile);
4096 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4097 ImagePreview *p =new ImagePreview (fd);
4098 fd->setContentsPreviewEnabled( TRUE );
4099 fd->setContentsPreview( p, p );
4100 fd->setPreviewMode( Q3FileDialog::Contents );
4101 fd->setCaption(vymName+" - " +tr("Load background image"));
4102 fd->setDir (lastImageDir);
4105 if ( fd->exec() == QDialog::Accepted )
4107 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4108 lastImageDir=QDir (fd->dirPath());
4109 setMapBackgroundImage (fd->selectedFile());
4113 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4115 QColor oldcol=mapScene->backgroundBrush().color();
4119 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4121 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4122 QString("Set background color of map to %1").arg(col.name()));
4125 brush.setTextureImage (QPixmap (fn));
4126 mapScene->setBackgroundBrush(brush);
4129 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4131 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4132 if ( !col.isValid() ) return;
4133 setMapBackgroundColor( col );
4137 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4139 QColor oldcol=mapScene->backgroundBrush().color();
4141 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4142 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4143 QString("Set background color of map to %1").arg(col.name()));
4144 mapScene->setBackgroundBrush(col);
4147 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4149 return mapScene->backgroundBrush().color();
4153 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4155 return linkcolorhint;
4158 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4160 return defLinkColor;
4163 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4168 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4170 return defXLinkColor;
4173 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4178 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4180 return defXLinkWidth;
4183 void VymModel::move(const double &x, const double &y) // FIXME-3
4187 BranchObj *bo = getSelectedBranch();
4189 (selectionType()==TreeItem::Branch ||
4190 selectionType()==TreeItem::MapCenter ||
4191 selectionType()==TreeItem::Image
4194 QPointF ap(bo->getAbsPos());
4198 QString ps=qpointfToString(ap);
4199 QString s=getSelectString();
4202 s, "move "+qpointfToString(to),
4203 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4212 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4216 BranchObj *bo = getSelectedBranch();
4218 (selectionType()==TreeItem::Branch ||
4219 selectionType()==TreeItem::MapCenter ||
4220 selectionType()==TreeItem::Image
4224 QPointF rp(bo->getRelPos());
4228 QString ps=qpointfToString (bo->getRelPos());
4229 QString s=getSelectString(bo);
4232 s, "moveRel "+qpointfToString(to),
4233 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4234 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4244 void VymModel::animate()
4246 animationTimer->stop();
4249 while (i<animObjList.size() )
4251 bo=(BranchObj*)animObjList.at(i);
4256 animObjList.removeAt(i);
4263 QItemSelection sel=selModel->selection();
4264 emit (selectionChanged(sel,sel));
4267 if (!animObjList.isEmpty()) animationTimer->start();
4271 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4273 if (bo && bo->getTreeItem()->depth()>0)
4276 ap.setStart (start);
4278 ap.setTicks (animationTicks);
4279 ap.setAnimated (true);
4280 bo->setAnimation (ap);
4281 animObjList.append( bo );
4282 animationTimer->setSingleShot (true);
4283 animationTimer->start(animationInterval);
4287 void VymModel::stopAnimation (MapObj *mo)
4289 int i=animObjList.indexOf(mo);
4291 animObjList.removeAt (i);
4294 void VymModel::sendSelection()
4296 if (netstate!=Server) return;
4297 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4300 void VymModel::newServer()
4304 tcpServer = new QTcpServer(this);
4305 if (!tcpServer->listen(QHostAddress::Any,port)) {
4306 QMessageBox::critical(NULL, "vym server",
4307 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4308 //FIXME-3 needed? we are no widget any longer... close();
4311 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4313 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4316 void VymModel::connectToServer()
4319 server="salam.suse.de";
4321 clientSocket = new QTcpSocket (this);
4322 clientSocket->abort();
4323 clientSocket->connectToHost(server ,port);
4324 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4325 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4326 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4328 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4333 void VymModel::newClient()
4335 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4336 connect(newClient, SIGNAL(disconnected()),
4337 newClient, SLOT(deleteLater()));
4339 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4341 clientList.append (newClient);
4345 void VymModel::sendData(const QString &s)
4347 if (clientList.size()==0) return;
4349 // Create bytearray to send
4351 QDataStream out(&block, QIODevice::WriteOnly);
4352 out.setVersion(QDataStream::Qt_4_0);
4354 // Reserve some space for blocksize
4357 // Write sendCounter
4358 out << sendCounter++;
4363 // Go back and write blocksize so far
4364 out.device()->seek(0);
4365 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4369 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4371 for (int i=0; i<clientList.size(); ++i)
4373 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4374 clientList.at(i)->write (block);
4378 void VymModel::readData ()
4380 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4383 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4387 QDataStream in(clientSocket);
4388 in.setVersion(QDataStream::Qt_4_0);
4396 cout << " t="<<qPrintable (t)<<endl;
4402 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4404 switch (socketError) {
4405 case QAbstractSocket::RemoteHostClosedError:
4407 case QAbstractSocket::HostNotFoundError:
4408 QMessageBox::information(NULL, vymName +" Network client",
4409 "The host was not found. Please check the "
4410 "host name and port settings.");
4412 case QAbstractSocket::ConnectionRefusedError:
4413 QMessageBox::information(NULL, vymName + " Network client",
4414 "The connection was refused by the peer. "
4415 "Make sure the fortune server is running, "
4416 "and check that the host name and port "
4417 "settings are correct.");
4420 QMessageBox::information(NULL, vymName + " Network client",
4421 QString("The following error occurred: %1.")
4422 .arg(clientSocket->errorString()));
4429 void VymModel::selectMapSelectionColor()
4431 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4432 setSelectionColor (col);
4435 void VymModel::setSelectionColorInt (QColor col)
4437 if ( !col.isValid() ) return;
4439 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4440 QString("setSelectionColor (%1)").arg(col.name()),
4441 QString("Set color of selection box to %1").arg(col.name())
4444 mapEditor->setSelectionColor (col);
4448 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4450 cout << "VymModel::changeSelection (";
4451 if (!newsel.indexes().isEmpty() )
4452 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4454 if (!oldsel.indexes().isEmpty() )
4455 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4460 void VymModel::updateSelection(const QItemSelection &newsel)
4462 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4463 emitShowSelection();
4467 void VymModel::updateSelection()
4469 QItemSelection newsel=selModel->selection();
4470 updateSelection (newsel);
4473 void VymModel::setSelectionColor(QColor col)
4475 if ( !col.isValid() ) return;
4477 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4478 QString("setSelectionColor (%1)").arg(col.name()),
4479 QString("Set color of selection box to %1").arg(col.name())
4481 setSelectionColorInt (col);
4484 QColor VymModel::getSelectionColor()
4486 return mapEditor->getSelectionColor();
4489 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4492 for (int i=0;i<rootItem->childCount();i++)
4493 rootItem->child(i)->setHideTmp (mode);
4495 // FIXME-3 needed? scene()->update();
4499 QRectF VymModel::getTotalBBox() //FIXME-2
4503 for (int i=0;i<rootItem->branchCount(); i++)
4504 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4509 //////////////////////////////////////////////
4510 // Selection related
4511 //////////////////////////////////////////////
4513 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4518 QItemSelectionModel* VymModel::getSelectionModel()
4523 void VymModel::setSelectionBlocked (bool b)
4528 selection.unblock();
4531 bool VymModel::isSelectionBlocked()
4533 return selection.isBlocked();
4536 bool VymModel::select ()
4538 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4540 TreeItem *item = getItem (index);
4541 return select (item->getLMO() );
4544 bool VymModel::select (const QString &s)
4546 TreeItem *ti=findBySelectString(s);
4556 bool VymModel::select (LinkableMapObj *lmo)
4558 QItemSelection oldsel=selModel->selection();
4561 return select (lmo->getTreeItem() );
4566 bool VymModel::select (TreeItem *ti)
4568 if (ti) return select (index(ti));
4572 bool VymModel::select (const QModelIndex &index)
4574 if (index.isValid() )
4576 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4577 getSelectedItem()->setLastSelectedBranch();
4583 void VymModel::unselect()
4585 selModel->clearSelection();
4588 void VymModel::reselect()
4590 selection.reselect();
4593 void VymModel::emitShowSelection()
4595 if (!blockReposition)
4596 emit (showSelection() );
4599 void VymModel::emitNoteHasChanged (TreeItem *ti)
4601 QModelIndex ix=index(ti);
4602 emit (noteHasChanged (ix) );
4605 void VymModel::emitDataHasChanged (TreeItem *ti)
4607 QModelIndex ix=index(ti);
4608 emit (dataChanged (ix,ix) );
4612 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4615 if (selection.select(lmo))
4617 //selection.update();
4618 sendSelection (); // FIXME-4 VM use signal
4622 void VymModel::selectInt (TreeItem *ti)
4624 if (selection.select(lmo))
4626 //selection.update();
4627 sendSelection (); // FIXME-4 VM use signal
4632 void VymModel::selectNextBranchInt()
4634 BranchItem *bi=getSelectedBranchItem();
4637 TreeItem *pi=bi->parent();
4641 if (i<pi->branchCount() )
4643 // select previous branch with same parent
4645 select (pi->getBranchNum(i));
4653 void VymModel::selectPrevBranchInt()
4656 BranchItem *bi=getSelectedBranchItem();
4659 BranchItem *pi=(BranchItem*)bi->parent();
4665 // select previous branch with same parent
4666 bi=pi->getBranchNum(i-1);
4671 while (bi->branchCount() >0)
4672 bi=bi->getLastBranch();
4675 // Try to select last branch in parent pi2 previous to own parent pi
4677 TreeItem *pi2=pi->parent();
4688 void VymModel::selectAboveBranchInt()
4690 BranchItem *bi=getSelectedBranchItem();
4693 BranchItem *newbi=NULL;
4694 BranchItem *pi=(BranchItem*)bi->parent();
4698 // goto previous branch with same parent
4699 newbi=pi->getBranchNum(i-1);
4700 while (newbi->branchCount() >0 )
4701 newbi=newbi->getLastBranch();
4705 if (newbi==rootItem)
4706 // already at top branch (resp. mapcenter)
4712 void VymModel::selectBelowBranchInt()
4714 BranchItem *bi=getSelectedBranchItem();
4717 BranchItem *newbi=NULL;
4719 if (bi->branchCount() >0)
4720 newbi=bi->getFirstBranch();
4727 pi=(BranchItem*)bi->parent();
4729 if (pi->branchCount()-1 > i)
4731 newbi=(BranchItem*)pi->getBranchNum(i+1);
4736 // look for siblings of myself
4737 // or parent, or parent of parent...
4748 void VymModel::selectUpperBranch()
4750 if (selection.isBlocked() ) return;
4752 BranchItem *bi=getSelectedBranchItem();
4753 if (bi && bi->isBranchLikeType())
4754 selectAboveBranchInt();
4757 void VymModel::selectLowerBranch()
4759 if (selection.isBlocked() ) return;
4761 BranchItem *bi=getSelectedBranchItem();
4762 if (bi && bi->isBranchLikeType())
4763 selectBelowBranchInt();
4767 void VymModel::selectLeftBranch()
4769 if (selection.isBlocked() ) return;
4771 QItemSelection oldsel=selModel->selection();
4774 BranchItem *selbi=getSelectedBranchItem();
4775 TreeItem::Type type=selbi->getType();
4778 if (type == TreeItem::MapCenter)
4780 QModelIndex ix=index(selbi);
4781 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4784 par=(BranchItem*)selbi->parent();
4785 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4788 if (type == TreeItem::Branch ||
4789 type == TreeItem::Image)
4791 QModelIndex ix=index (selbi->parent());
4792 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4797 if (type == TreeItem::Branch )
4799 selectLastSelectedBranch();
4807 void VymModel::selectRightBranch()
4809 if (selection.isBlocked() ) return;
4811 QItemSelection oldsel=selModel->selection();
4814 BranchItem *selbi=getSelectedBranchItem();
4815 TreeItem::Type type=selbi->getType();
4818 if (type==TreeItem::MapCenter)
4820 QModelIndex ix=index(selbi);
4821 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4824 par=(BranchItem*)selbi->parent();
4825 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4828 if ( type== TreeItem::Branch )
4830 selectLastSelectedBranch();
4836 if (type == TreeItem::Branch ||
4837 type == TreeItem::Image)
4839 QModelIndex ix=index(selbi->parent());
4840 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4847 void VymModel::selectFirstBranch()
4849 TreeItem *ti=getSelectedBranchItem();
4852 TreeItem *par=ti->parent();
4854 TreeItem *ti2=par->getFirstBranch();
4858 emitShowSelection();
4864 void VymModel::selectLastBranch()
4866 TreeItem *ti=getSelectedBranchItem();
4869 TreeItem *par=ti->parent();
4871 TreeItem *ti2=par->getLastBranch();
4875 emitShowSelection();
4881 void VymModel::selectLastSelectedBranch()
4883 TreeItem *ti=getSelectedBranchItem();
4886 ti=ti->getLastSelectedBranch();
4887 if (ti) select (ti);
4891 void VymModel::selectParent()
4893 TreeItem *ti=getSelectedItem();
4901 emitShowSelection();
4906 TreeItem::Type VymModel::selectionType()
4908 QModelIndexList list=selModel->selectedIndexes();
4909 if (list.isEmpty()) return TreeItem::Undefined;
4910 TreeItem *ti = getItem (list.first() );
4911 return ti->getType();
4915 LinkableMapObj* VymModel::getSelectedLMO()
4917 QModelIndexList list=selModel->selectedIndexes();
4918 if (!list.isEmpty() )
4920 TreeItem *ti = getItem (list.first() );
4921 TreeItem::Type type=ti->getType();
4922 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4924 return ti->getLMO();
4930 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4932 TreeItem *ti = getSelectedBranchItem();
4934 return (BranchObj*)ti->getLMO();
4939 BranchItem* VymModel::getSelectedBranchItem()
4941 QModelIndexList list=selModel->selectedIndexes();
4942 if (!list.isEmpty() )
4944 TreeItem *ti = getItem (list.first() );
4945 TreeItem::Type type=ti->getType();
4946 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4947 return (BranchItem*)ti;
4952 TreeItem* VymModel::getSelectedItem()
4954 QModelIndexList list=selModel->selectedIndexes();
4955 if (!list.isEmpty() )
4956 return getItem (list.first() );
4961 QModelIndex VymModel::getSelectedIndex()
4963 QModelIndexList list=selModel->selectedIndexes();
4964 if (list.isEmpty() )
4965 return QModelIndex();
4967 return list.first();
4970 FloatImageObj* VymModel::getSelectedFloatImage()
4972 return selection.getFloatImage();
4975 QString VymModel::getSelectString ()
4977 LinkableMapObj *lmo=getSelectedLMO();
4979 return getSelectString(lmo);
4984 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
4986 if (!lmo) return QString();
4987 return getSelectString (lmo->getTreeItem() );
4990 QString VymModel::getSelectString (TreeItem *ti)
4994 if (ti->getType() == TreeItem::Branch ||
4995 ti->getType() == TreeItem::MapCenter)
4997 TreeItem *par=ti->parent();
5000 if (ti->depth() ==1)
5001 // Mainbranch, return
5002 s= "bo:" + QString("%1").arg(ti->num() );
5004 // Branch, call myself recursively
5005 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5009 int i=rootItem->num(ti);
5010 if (i>=0) s=QString("mc:%1").arg(i);