1 #include <QApplication>
7 #include "branchitem.h"
8 #include "mapcenteritem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
15 #include "mapcenterobj.h"
18 #include "selection.h"
21 #include "warningdialog.h"
22 #include "xml-freemind.h"
28 extern Main *mainWindow;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
34 extern QString clipboardDir;
35 extern QString clipboardFile;
36 extern bool clipboardEmpty;
38 extern ImageIO imageIO;
40 extern QString vymName;
41 extern QString vymVersion;
42 extern QDir vymBaseDir;
44 extern QDir lastImageDir;
45 extern QDir lastFileDir;
47 extern FlagRowObj *standardFlagsDefault;
49 extern Settings settings;
53 int VymModel::mapNum=0; // make instance
57 // cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 // cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
71 void VymModel::clear()
73 selModel->clearSelection();
76 while (!mapCenters.isEmpty()) // FIXME-2 VM needs to be in treemodel only...
77 delete mapCenters.takeFirst();
79 QModelIndex ri=index(rootItem);
80 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
83 void VymModel::init ()
85 // We should have at least one map center to start with
86 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
91 // Also no scene yet (should not be needed anyway) FIXME-3 VM
104 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
105 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
106 mainWindow->updateHistory (undoSet);
109 makeTmpDirectories();
114 fileName=tr("unnamed");
116 blockReposition=false;
117 blockSaveState=false;
119 autosaveTimer=new QTimer (this);
120 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
122 fileChangedTimer=new QTimer (this);
123 fileChangedTimer->start(3000);
124 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
136 animationUse=settings.readBoolEntry("/animation/use",false);
137 animationTicks=settings.readNumEntry("/animation/ticks",10);
138 animationInterval=settings.readNumEntry("/animation/interval",50);
140 animationTimer=new QTimer (this);
141 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
144 defLinkColor=QColor (0,0,255);
145 defXLinkColor=QColor (180,180,180);
146 linkcolorhint=LinkableMapObj::DefaultColor;
147 linkstyle=LinkableMapObj::PolyParabel;
149 defXLinkColor=QColor (230,230,230);
151 hidemode=TreeItem::HideNone;
157 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
161 void VymModel::makeTmpDirectories()
163 // Create unique temporary directories
164 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
165 histPath = tmpMapDir+"/history";
171 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
176 bool VymModel::isRepositionBlocked()
178 return blockReposition;
181 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
183 cout << "VymModel::updateActions \n";
184 // Tell mainwindow to update states of actions
185 mainWindow->updateActions();
190 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
192 // tmpdir temporary directory to which data will be written
193 // prefix mapname, which will be appended to images etc.
194 // writeflags Only write flags for "real" save of map, not undo
195 // offset offset of bbox of whole map in scene.
196 // Needed for XML export
205 case LinkableMapObj::Line:
208 case LinkableMapObj::Parabel:
211 case LinkableMapObj::PolyLine:
215 ls="StylePolyParabel";
219 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
221 if (linkcolorhint==LinkableMapObj::HeadingColor)
222 colhint=xml.attribut("linkColorHint","HeadingColor");
224 QString mapAttr=xml.attribut("version",vymVersion);
226 mapAttr+= xml.attribut("author",author) +
227 xml.attribut("comment",comment) +
228 xml.attribut("date",getDate()) +
229 xml.attribut("branchCount", QString().number(branchCount())) +
230 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
231 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
232 xml.attribut("linkStyle", ls ) +
233 xml.attribut("linkColor", defLinkColor.name() ) +
234 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
235 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
237 s+=xml.beginElement("vymmap",mapAttr);
240 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
241 standardFlagsDefault->resetUsedCounter();
243 // Reset the counters before saving
244 // TODO constr. of FIO creates lots of objects, better do this in some other way...
245 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
247 // Build xml recursivly
248 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
249 // Save all mapcenters as complete map, if saveSel not set
250 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
253 if ( typeid(*saveSel) == typeid(BranchObj) )
255 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
256 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
258 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
261 // Save local settings
262 s+=settings.getDataXML (destPath);
265 if (!selection.isEmpty() && !saveSel )
266 s+=xml.valueElement("select",selection.getSelectString());
269 s+=xml.endElement("vymmap");
272 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
276 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
280 for (int i=0; i<mapCenters.count(); i++)
281 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
285 void VymModel::setFilePath(QString fpath, QString destname)
287 if (fpath.isEmpty() || fpath=="")
294 filePath=fpath; // becomes absolute path
295 fileName=fpath; // gets stripped of path
296 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
298 // If fpath is not an absolute path, complete it
299 filePath=QDir(fpath).absPath();
300 fileDir=filePath.left (1+filePath.findRev ("/"));
302 // Set short name, too. Search from behind:
303 int i=fileName.findRev("/");
304 if (i>=0) fileName=fileName.remove (0,i+1);
306 // Forget the .vym (or .xml) for name of map
307 mapName=fileName.left(fileName.findRev(".",-1,true) );
311 void VymModel::setFilePath(QString fpath)
313 setFilePath (fpath,fpath);
316 QString VymModel::getFilePath()
321 QString VymModel::getFileName()
326 QString VymModel::getMapName()
331 QString VymModel::getDestPath()
336 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
338 ErrorCode err=success;
340 parseBaseHandler *handler;
344 case VymMap: handler=new parseVYMHandler; break;
345 case FreemindMap : handler=new parseFreemindHandler; break;
347 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
348 "Unknown FileType in VymModel::load()");
352 bool zipped_org=zipped;
356 selModel->clearSelection();
357 // FIXME-2 VM not needed??? model->setMapEditor(this);
358 // (map state is set later at end of load...)
361 BranchItem *bi=getSelectedBranchItem();
362 if (!bi) return aborted;
363 if (lmode==ImportAdd)
364 saveStateChangingPart(
367 QString("addMapInsert (%1)").arg(fname),
368 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
370 saveStateChangingPart(
373 QString("addMapReplace(%1)").arg(fname),
374 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
378 // Create temporary directory for packing
380 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
383 QMessageBox::critical( 0, tr( "Critical Load Error" ),
384 tr("Couldn't create temporary directory before load\n"));
389 err=unzipDir (tmpZipDir,fname);
399 // Look for mapname.xml
400 xmlfile= fname.left(fname.findRev(".",-1,true));
401 xmlfile=xmlfile.section( '/', -1 );
402 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
403 if (!mfile.exists() )
405 // mapname.xml does not exist, well,
406 // maybe someone renamed the mapname.vym file...
407 // Try to find any .xml in the toplevel
408 // directory of the .vym file
409 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
410 if (flist.count()==1)
412 // Only one entry, take this one
413 xmlfile=tmpZipDir + "/"+flist.first();
416 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
417 *it=tmpZipDir + "/" + *it;
418 // TODO Multiple entries, load all (but only the first one into this ME)
419 //mainWindow->fileLoadFromTmp (flist);
420 //returnCode=1; // Silently forget this attempt to load
421 qWarning ("MainWindow::load (fn) multimap found...");
424 if (flist.isEmpty() )
426 QMessageBox::critical( 0, tr( "Critical Load Error" ),
427 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
430 } //file doesn't exist
432 xmlfile=mfile.name();
435 QFile file( xmlfile);
437 // I am paranoid: file should exist anyway
438 // according to check in mainwindow.
441 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
442 tr(QString("Couldn't open map %1").arg(file.name())));
446 bool blockSaveStateOrg=blockSaveState;
447 blockReposition=true;
449 QXmlInputSource source( file);
450 QXmlSimpleReader reader;
451 reader.setContentHandler( handler );
452 reader.setErrorHandler( handler );
453 handler->setModel ( this);
456 // We need to set the tmpDir in order to load files with rel. path
461 tmpdir=fname.left(fname.findRev("/",-1));
462 handler->setTmpDir (tmpdir);
463 handler->setInputFile (file.name());
464 handler->setLoadMode (lmode);
465 bool ok = reader.parse( source );
466 blockReposition=false;
467 blockSaveState=blockSaveStateOrg;
471 reposition(); // FIXME-2 VM reposition the view instead...
478 autosaveTimer->stop();
481 // Reset timestamp to check for later updates of file
482 fileChangedTime=QFileInfo (destPath).lastModified();
485 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
486 tr( handler->errorProtocol() ) );
488 // Still return "success": the map maybe at least
489 // partially read by the parser
494 removeDir (QDir(tmpZipDir));
496 // Restore original zip state
503 ErrorCode VymModel::save (const SaveMode &savemode)
507 QString safeFilePath;
509 ErrorCode err=success;
513 mapFileName=mapName+".xml";
515 // use name given by user, even if he chooses .doc
516 mapFileName=fileName;
518 // Look, if we should zip the data:
521 QMessageBox mb( vymName,
522 tr("The map %1\ndid not use the compressed "
523 "vym file format.\nWriting it uncompressed will also write images \n"
524 "and flags and thus may overwrite files in the "
525 "given directory\n\nDo you want to write the map").arg(filePath),
526 QMessageBox::Warning,
527 QMessageBox::Yes | QMessageBox::Default,
529 QMessageBox::Cancel | QMessageBox::Escape);
530 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
531 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
532 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
535 case QMessageBox::Yes:
536 // save compressed (default file format)
539 case QMessageBox::No:
543 case QMessageBox::Cancel:
550 // First backup existing file, we
551 // don't want to add to old zip archives
555 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
557 QString backupFileName(destPath + "~");
558 QFile backupFile(backupFileName);
559 if (backupFile.exists() && !backupFile.remove())
561 QMessageBox::warning(0, tr("Save Error"),
562 tr("%1\ncould not be removed before saving").arg(backupFileName));
564 else if (!f.rename(backupFileName))
566 QMessageBox::warning(0, tr("Save Error"),
567 tr("%1\ncould not be renamed before saving").arg(destPath));
574 // Create temporary directory for packing
576 tmpZipDir=makeTmpDir (ok,"vym-zip");
579 QMessageBox::critical( 0, tr( "Critical Load Error" ),
580 tr("Couldn't create temporary directory before save\n"));
584 safeFilePath=filePath;
585 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
588 // Create mapName and fileDir
589 makeSubDirs (fileDir);
592 if (savemode==CompleteMap || selection.isEmpty())
595 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
598 autosaveTimer->stop();
603 if (selectionType()==TreeItem::Image)
606 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
607 // TODO take care of multiselections
610 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
613 qWarning ("ME::saveStringToDisk failed!");
619 if (err==success) err=zipDir (tmpZipDir,destPath);
622 removeDir (QDir(tmpZipDir));
624 // Restore original filepath outside of tmp zip dir
625 setFilePath (safeFilePath);
629 fileChangedTime=QFileInfo (destPath).lastModified();
633 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
635 QString pathDir=path.left(path.findRev("/"));
641 // We need to parse saved XML data
642 parseVYMHandler handler;
643 QXmlInputSource source( file);
644 QXmlSimpleReader reader;
645 reader.setContentHandler( &handler );
646 reader.setErrorHandler( &handler );
647 handler.setModel ( this);
648 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
649 if (undoSel.isEmpty())
653 handler.setLoadMode (NewMap);
657 handler.setLoadMode (ImportReplace);
659 blockReposition=true;
660 bool ok = reader.parse( source );
661 blockReposition=false;
664 // This should never ever happen
665 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
666 handler.errorProtocol());
669 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
672 void VymModel::addMapInsertInt (const QString &path, int pos)
674 /* FIXME-2 addMapInsertInt not ported yet
675 BranchObj *sel=getSelectedBranch();
678 QString pathDir=path.left(path.findRev("/"));
684 // We need to parse saved XML data
685 parseVYMHandler handler;
686 QXmlInputSource source( file);
687 QXmlSimpleReader reader;
688 reader.setContentHandler( &handler );
689 reader.setErrorHandler( &handler );
690 handler.setModel (this);
691 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
692 handler.setLoadMode (ImportAdd);
693 blockReposition=true;
694 bool ok = reader.parse( source );
695 blockReposition=false;
698 // This should never ever happen
699 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
700 handler.errorProtocol());
702 if (sel->getDepth()>0)
703 sel->getLastBranch()->linkTo (sel,pos);
705 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
710 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
712 TreeItem *fi=createImage();
715 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
723 void VymModel::loadFloatImage () // FIXME-2
726 BranchObj *bo=getSelectedBranch();
730 Q3FileDialog *fd=new Q3FileDialog( NULL);
731 fd->setMode (Q3FileDialog::ExistingFiles);
732 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
733 ImagePreview *p =new ImagePreview (fd);
734 fd->setContentsPreviewEnabled( TRUE );
735 fd->setContentsPreview( p, p );
736 fd->setPreviewMode( Q3FileDialog::Contents );
737 fd->setCaption(vymName+" - " +tr("Load image"));
738 fd->setDir (lastImageDir);
741 if ( fd->exec() == QDialog::Accepted )
743 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
744 lastImageDir=QDir (fd->dirPath());
747 for (int j=0; j<fd->selectedFiles().count(); j++)
749 s=fd->selectedFiles().at(j);
750 fio=loadFloatImageInt (s);
753 (LinkableMapObj*)fio,
756 QString ("loadImage (%1)").arg(s ),
757 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
760 // TODO loadFIO error handling
761 qWarning ("Failed to load "+s);
770 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
775 void VymModel::saveFloatImage ()
777 FloatImageObj *fio=selection.getFloatImage();
780 QFileDialog *fd=new QFileDialog( NULL);
781 fd->setFilters (imageIO.getFilters());
782 fd->setCaption(vymName+" - " +tr("Save image"));
783 fd->setFileMode( QFileDialog::AnyFile );
784 fd->setDirectory (lastImageDir);
785 // fd->setSelection (fio->getOriginalFilename());
789 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
791 fn=fd->selectedFiles().at(0);
792 if (QFile (fn).exists() )
794 QMessageBox mb( vymName,
795 tr("The file %1 exists already.\n"
796 "Do you want to overwrite it?").arg(fn),
797 QMessageBox::Warning,
798 QMessageBox::Yes | QMessageBox::Default,
799 QMessageBox::Cancel | QMessageBox::Escape,
800 QMessageBox::NoButton );
802 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
803 mb.setButtonText( QMessageBox::No, tr("Cancel"));
806 case QMessageBox::Yes:
809 case QMessageBox::Cancel:
816 saveFloatImageInt (fio,fd->selectedFilter(),fn );
823 void VymModel::importDirInt(BranchObj *dst, QDir d)
825 /* FIXME-2 importDirInt not ported yet
826 BranchObj *bo=getSelectedBranch();
829 // Traverse directories
830 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
831 QFileInfoList list = d.entryInfoList();
834 for (int i = 0; i < list.size(); ++i)
837 if (fi.fileName() != "." && fi.fileName() != ".." )
840 bo=dst->getLastBranch();
841 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
842 bi->setHeading (fi.fileName() ); // FIXME-3 check this
843 bo->setColor (QColor("blue"));
845 if ( !d.cd(fi.fileName()) )
846 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
849 // Recursively add subdirs
856 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
857 list = d.entryInfoList();
859 for (int i = 0; i < list.size(); ++i)
863 bo=dst->getLastBranch();
864 bo->setHeading (fi.fileName() );
865 bo->setColor (QColor("black"));
866 if (fi.fileName().right(4) == ".vym" )
867 bo->setVymLink (fi.filePath());
873 void VymModel::importDirInt (const QString &s) // FIXME-2
876 BranchObj *bo=getSelectedBranch();
879 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
887 void VymModel::importDir() //FIXME-2
890 BranchObj *bo=getSelectedBranch();
894 filters <<"VYM map (*.vym)";
895 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
896 fd->setMode (QFileDialog::DirectoryOnly);
897 fd->setFilters (filters);
898 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
902 if ( fd->exec() == QDialog::Accepted )
904 importDirInt (fd->selectedFile() );
906 //FIXME-3 VM needed? scene()->update();
913 void VymModel::autosave()
918 cout << "VymModel::autosave rejected due to missing filePath\n";
921 QDateTime now=QDateTime().currentDateTime();
923 // Disable autosave, while we have gone back in history
924 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
925 if (redosAvail>0) return;
927 // Also disable autosave for new map without filename
928 if (filePath.isEmpty()) return;
931 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
933 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
934 mainWindow->fileSave (this);
937 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
942 void VymModel::fileChanged()
944 // Check if file on disk has changed meanwhile
945 if (!filePath.isEmpty())
947 QDateTime tmod=QFileInfo (filePath).lastModified();
948 if (tmod>fileChangedTime)
950 // FIXME-2 VM switch to current mapeditor and finish lineedits...
951 QMessageBox mb( vymName,
952 tr("The file of the map on disk has changed:\n\n"
953 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
954 QMessageBox::Question,
956 QMessageBox::Cancel | QMessageBox::Default,
957 QMessageBox::NoButton );
959 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
960 mb.setButtonText( QMessageBox::No, tr("Ignore"));
963 case QMessageBox::Yes:
965 load (filePath,NewMap,fileType);
966 case QMessageBox::Cancel:
967 fileChangedTime=tmod; // allow autosave to overwrite newer file!
973 bool VymModel::isDefault()
978 void VymModel::makeDefault()
984 bool VymModel::hasChanged()
989 void VymModel::setChanged()
991 cout << "VM::setChanged()\n";
994 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
995 cout <<" timer started with "<<settings.value("/mainwindow/autosave/ms/",300000).toInt()<<endl;
1003 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1006 if (!lmo) return QString("Error: NULL has no name!");
1008 if ((typeid(*lmo) == typeid(BranchObj) ||
1009 typeid(*lmo) == typeid(MapCenterObj)))
1012 s=lmo->getTreeItem()->getHeading();
1013 if (s=="") s="unnamed";
1014 return QString("branch (%1)").arg(s);
1016 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1017 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1018 return QString("Unknown type has no name!");
1022 QString VymModel::getObjectName (const TreeItem *ti)
1025 if (!ti) return QString("Error: NULL has no name!");
1027 if (ti->isBranchLikeType() )
1030 if (s=="") s="unnamed";
1031 return QString("branch (%1)").arg(s);
1033 /* FIXME-2 move floatimage to TreeModel first
1034 if (type==TreeItem::Image)
1035 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1037 return QString("Unknown type has no name!");
1040 void VymModel::redo()
1042 // Can we undo at all?
1043 if (redosAvail<1) return;
1045 bool blockSaveStateOrg=blockSaveState;
1046 blockSaveState=true;
1050 if (undosAvail<stepsTotal) undosAvail++;
1052 if (curStep>stepsTotal) curStep=1;
1053 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1054 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1055 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1056 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1057 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1058 QString version=undoSet.readEntry ("/history/version");
1060 /* TODO Maybe check for version, if we save the history
1061 if (!checkVersion(version))
1062 QMessageBox::warning(0,tr("Warning"),
1063 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1066 // Find out current undo directory
1067 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1071 cout << "VymModel::redo() begin\n";
1072 cout << " undosAvail="<<undosAvail<<endl;
1073 cout << " redosAvail="<<redosAvail<<endl;
1074 cout << " curStep="<<curStep<<endl;
1075 cout << " ---------------------------"<<endl;
1076 cout << " comment="<<comment.toStdString()<<endl;
1077 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1078 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1079 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1080 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1081 cout << " ---------------------------"<<endl<<endl;
1084 // select object before redo
1085 if (!redoSelection.isEmpty())
1086 select (redoSelection);
1089 parseAtom (redoCommand);
1092 blockSaveState=blockSaveStateOrg;
1094 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1095 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1096 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1097 undoSet.writeSettings(histPath);
1099 mainWindow->updateHistory (undoSet);
1102 /* TODO remove testing
1103 cout << "ME::redo() end\n";
1104 cout << " undosAvail="<<undosAvail<<endl;
1105 cout << " redosAvail="<<redosAvail<<endl;
1106 cout << " curStep="<<curStep<<endl;
1107 cout << " ---------------------------"<<endl<<endl;
1113 bool VymModel::isRedoAvailable()
1115 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1121 void VymModel::undo()
1123 // Can we undo at all?
1124 if (undosAvail<1) return;
1126 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1128 bool blockSaveStateOrg=blockSaveState;
1129 blockSaveState=true;
1131 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1132 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1133 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1134 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1135 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1136 QString version=undoSet.readEntry ("/history/version");
1138 /* TODO Maybe check for version, if we save the history
1139 if (!checkVersion(version))
1140 QMessageBox::warning(0,tr("Warning"),
1141 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1144 // Find out current undo directory
1145 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1147 // select object before undo
1148 if (!undoSelection.isEmpty())
1149 select (undoSelection);
1153 cout << "VymModel::undo() begin\n";
1154 cout << " undosAvail="<<undosAvail<<endl;
1155 cout << " redosAvail="<<redosAvail<<endl;
1156 cout << " curStep="<<curStep<<endl;
1157 cout << " ---------------------------"<<endl;
1158 cout << " comment="<<comment.toStdString()<<endl;
1159 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1160 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1161 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1162 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1163 cout << " ---------------------------"<<endl<<endl;
1165 parseAtom (undoCommand);
1170 if (curStep<1) curStep=stepsTotal;
1174 blockSaveState=blockSaveStateOrg;
1175 /* TODO remove testing
1176 cout << "VymModel::undo() end\n";
1177 cout << " undosAvail="<<undosAvail<<endl;
1178 cout << " redosAvail="<<redosAvail<<endl;
1179 cout << " curStep="<<curStep<<endl;
1180 cout << " ---------------------------"<<endl<<endl;
1183 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1184 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1185 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1186 undoSet.writeSettings(histPath);
1188 mainWindow->updateHistory (undoSet);
1191 ensureSelectionVisible();
1194 bool VymModel::isUndoAvailable()
1196 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1202 void VymModel::gotoHistoryStep (int i)
1204 // Restore variables
1205 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1206 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1208 if (i<0) i=undosAvail+redosAvail;
1210 // Clicking above current step makes us undo things
1213 for (int j=0; j<undosAvail-i; j++) undo();
1216 // Clicking below current step makes us redo things
1218 for (int j=undosAvail; j<i; j++)
1220 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1224 // And ignore clicking the current row ;-)
1228 QString VymModel::getHistoryPath()
1230 QString histName(QString("history-%1").arg(curStep));
1231 return (tmpMapDir+"/"+histName);
1234 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1236 sendData(redoCom); //FIXME-3 testing
1241 if (blockSaveState) return;
1243 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1245 // Find out current undo directory
1246 if (undosAvail<stepsTotal) undosAvail++;
1248 if (curStep>stepsTotal) curStep=1;
1250 QString backupXML="";
1251 QString histDir=getHistoryPath();
1252 QString bakMapPath=histDir+"/map.xml";
1254 // Create histDir if not available
1257 makeSubDirs (histDir);
1259 // Save depending on how much needs to be saved
1261 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1263 QString undoCommand="";
1264 if (savemode==UndoCommand)
1266 undoCommand=undoCom;
1268 else if (savemode==PartOfMap )
1270 undoCommand=undoCom;
1271 undoCommand.replace ("PATH",bakMapPath);
1274 if (!backupXML.isEmpty())
1275 // Write XML Data to disk
1276 saveStringToDisk (bakMapPath,backupXML);
1278 // We would have to save all actions in a tree, to keep track of
1279 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1282 // Write the current state to disk
1283 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1284 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1285 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1286 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1287 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1288 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1289 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1290 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1291 undoSet.setEntry (QString("/history/version"),vymVersion);
1292 undoSet.writeSettings(histPath);
1296 // TODO remove after testing
1297 //cout << " into="<< histPath.toStdString()<<endl;
1298 cout << " stepsTotal="<<stepsTotal<<
1299 ", undosAvail="<<undosAvail<<
1300 ", redosAvail="<<redosAvail<<
1301 ", curStep="<<curStep<<endl;
1302 cout << " ---------------------------"<<endl;
1303 cout << " comment="<<comment.toStdString()<<endl;
1304 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1305 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1306 cout << " redoCom="<<redoCom.toStdString()<<endl;
1307 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1308 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1309 cout << " ---------------------------"<<endl;
1312 mainWindow->updateHistory (undoSet);
1318 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1320 // save the selected part of the map, Undo will replace part of map
1321 QString undoSelection="";
1323 undoSelection=getSelectString(undoSel);
1325 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1326 QString redoSelection="";
1328 redoSelection=getSelectString(undoSel);
1330 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1333 saveState (PartOfMap,
1334 undoSelection, "addMapReplace (\"PATH\")",
1340 void VymModel::saveStateRemovingPart(TreeItem*redoSel, const QString &comment)
1344 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1347 QString undoSelection=getSelectString (redoSel->parent() );
1348 QString redoSelection=getSelectString(redoSel);
1349 if (redoSel->getType()==TreeItem::Branch)
1351 // save the selected branch of the map, Undo will insert part of map
1352 saveState (PartOfMap,
1353 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1354 redoSelection, "delete ()",
1361 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1363 // "Normal" savestate: save commands, selections and comment
1364 // so just save commands for undo and redo
1365 // and use current selection
1367 QString redoSelection="";
1368 if (redoSel) redoSelection=getSelectString(redoSel);
1369 QString undoSelection="";
1370 if (undoSel) undoSelection=getSelectString(undoSel);
1372 saveState (UndoCommand,
1379 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1381 // "Normal" savestate: save commands, selections and comment
1382 // so just save commands for undo and redo
1383 // and use current selection
1384 saveState (UndoCommand,
1391 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1393 // "Normal" savestate applied to model (no selection needed):
1394 // save commands and comment
1395 saveState (UndoCommand,
1403 QGraphicsScene* VymModel::getScene ()
1408 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1410 LinkableMapObj *lmo;
1412 for (int i=0;i<mapCenters.count(); i++)
1414 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1415 if (lmo) return lmo;
1420 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1422 LinkableMapObj *lmo;
1428 part=s.section(",",0,0);
1430 num=part.right(part.length() - 3);
1431 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1432 return mapCenters.at(num.toInt() );
1435 for (int i=0; i<mapCenters.count(); i++)
1437 lmo=mapCenters.at(i)->findObjBySelect(s);
1438 if (lmo) return lmo;
1443 LinkableMapObj* VymModel::findID (const QString &s)
1445 LinkableMapObj *lmo;
1446 for (int i=0; i<mapCenters.count(); i++)
1448 lmo=mapCenters.at(i)->findID (s);
1449 if (lmo) return lmo;
1454 //////////////////////////////////////////////
1456 //////////////////////////////////////////////
1457 void VymModel::setVersion (const QString &s)
1462 void VymModel::setAuthor (const QString &s)
1465 QString ("setMapAuthor (\"%1\")").arg(author),
1466 QString ("setMapAuthor (\"%1\")").arg(s),
1467 QString ("Set author of map to \"%1\"").arg(s)
1473 QString VymModel::getAuthor()
1478 void VymModel::setComment (const QString &s)
1481 QString ("setMapComment (\"%1\")").arg(comment),
1482 QString ("setMapComment (\"%1\")").arg(s),
1483 QString ("Set comment of map")
1489 QString VymModel::getComment ()
1494 QString VymModel::getDate ()
1496 return QDate::currentDate().toString ("yyyy-MM-dd");
1499 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1502 BranchItem *cur=NULL;
1503 BranchItem *prev=NULL;
1515 void VymModel::setHeading(const QString &s)
1517 BranchItem *selbi=getSelectedBranchItem();
1522 "setHeading (\""+selbi->getHeading()+"\")",
1524 "setHeading (\""+s+"\")",
1525 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1526 selbi->setHeading(s );
1527 QModelIndex ix2=index (selbi);
1528 emit (dataChanged ( ix2,ix2));
1529 /* FIXME-3 testing only
1533 // selection.update(); //FIXME-4
1534 ensureSelectionVisible();
1538 BranchItem* VymModel::findText (QString s, bool cs)
1541 QTextDocument::FindFlags flags=0;
1542 if (cs) flags=QTextDocument::FindCaseSensitively;
1545 { // Nothing found or new find process
1547 // nothing found, start again
1551 next (findCurrent,findPrevious,d);
1553 bool searching=true;
1554 bool foundNote=false;
1555 while (searching && !EOFind)
1559 // Searching in Note
1560 if (findCurrent->getNote().contains(s,cs))
1562 select (findCurrent);
1564 if (getSelectedBranch()!=itFind)
1567 ensureSelectionVisible();
1570 if (textEditor->findText(s,flags))
1576 // Searching in Heading
1577 if (searching && findCurrent->getHeading().contains (s,cs) )
1579 select(findCurrent);
1585 if (!next(findCurrent,findPrevious,d) )
1588 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1591 return getSelectedBranchItem();
1596 void VymModel::findReset()
1597 { // Necessary if text to find changes during a find process
1605 void VymModel::setScene (QGraphicsScene *s)
1607 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1608 //init(); // Here we have a mapScene set,
1609 // which is (still) needed to create MapCenters
1612 void VymModel::setURL(const QString &url) //FIXME-2
1615 BranchObj *bo=getSelectedBranch();
1618 QString oldurl=bo->getURL();
1622 QString ("setURL (\"%1\")").arg(oldurl),
1624 QString ("setURL (\"%1\")").arg(url),
1625 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1630 ensureSelectionVisible();
1635 QString VymModel::getURL() //FIXME-2
1638 BranchObj *bo=getSelectedBranch();
1640 return bo->getURL();
1646 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1648 return QStringList();
1651 BranchObj *bo=getSelectedBranch();
1657 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1665 void VymModel::linkFloatImageTo(const QString &dstString)
1667 FloatImageObj *fio=selection.getFloatImage();
1670 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1671 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1672 typeid(*dst)==typeid (MapCenterObj)))
1674 LinkableMapObj *dstPar=dst->getParObj();
1675 QString parString=getSelectString(dstPar);
1676 QString fioPreSelectString=getSelectString(fio);
1677 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1678 ((BranchObj*)dst)->addFloatImage (fio);
1679 selection.unselect();
1680 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1681 fio=((BranchObj*)dst)->getLastFloatImage();
1684 selection.select(fio);
1686 getSelectString(fio),
1687 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1689 QString ("linkTo (\"%1\")").arg(dstString),
1690 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1696 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1699 BranchObj *bo=getSelectedBranch();
1702 QString s=bo->getFrameTypeName();
1703 bo->setFrameType (t);
1704 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1705 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1712 void VymModel::setFrameType(const QString &s) //FIXME-2
1715 BranchObj *bo=getSelectedBranch();
1718 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1719 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1720 bo->setFrameType (s);
1727 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1730 BranchObj *bo=getSelectedBranch();
1733 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1734 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1735 bo->setFramePenColor (c);
1740 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1743 BranchObj *bo=getSelectedBranch();
1746 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1747 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1748 bo->setFrameBrushColor (c);
1752 void VymModel::setFramePadding (const int &i) //FIXME-2
1755 BranchObj *bo=getSelectedBranch();
1758 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1759 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1760 bo->setFramePadding (i);
1767 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1770 BranchObj *bo=getSelectedBranch();
1773 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1774 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1775 bo->setFrameBorderWidth (i);
1782 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1785 BranchObj *bo=getSelectedBranch();
1788 QString u= b ? "false" : "true";
1789 QString r=!b ? "false" : "true";
1793 QString("setIncludeImagesVertically (%1)").arg(u),
1795 QString("setIncludeImagesVertically (%1)").arg(r),
1796 QString("Include images vertically in %1").arg(getObjectName(bo))
1798 bo->setIncludeImagesVer(b);
1803 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1806 BranchObj *bo=getSelectedBranch();
1809 QString u= b ? "false" : "true";
1810 QString r=!b ? "false" : "true";
1814 QString("setIncludeImagesHorizontally (%1)").arg(u),
1816 QString("setIncludeImagesHorizontally (%1)").arg(r),
1817 QString("Include images horizontally in %1").arg(getObjectName(bo))
1819 bo->setIncludeImagesHor(b);
1825 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1828 LinkableMapObj *sel=getSelectedLMO();
1830 (selectionType() == TreeItem::Branch ||
1831 selectionType() == TreeItem::MapCenter ||
1832 selectionType() == TreeItem::Image ))
1834 QString u= b ? "false" : "true";
1835 QString r=!b ? "false" : "true";
1839 QString("setHideLinkUnselected (%1)").arg(u),
1841 QString("setHideLinkUnselected (%1)").arg(r),
1842 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1844 sel->setHideLinkUnselected(b);
1849 void VymModel::setHideExport(bool b)
1851 BranchItem *bi=getSelectedBranchItem();
1854 bi->setHideInExport (b);
1855 QString u= b ? "false" : "true";
1856 QString r=!b ? "false" : "true";
1860 QString ("setHideExport (%1)").arg(u),
1862 QString ("setHideExport (%1)").arg(r),
1863 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1867 // selection.update();
1868 // FIXME-3 VM needed? scene()->update();
1872 void VymModel::toggleHideExport()
1874 BranchItem *selbi=getSelectedBranchItem();
1876 setHideExport ( !selbi->hideInExport() );
1880 void VymModel::copy() //FIXME-2
1883 LinkableMapObj *sel=getSelectedLMO();
1885 (selectionType() == TreeItem::Branch ||
1886 selectionType() == TreeItem::MapCenter ||
1887 selectionType() == TreeItem::Image ))
1889 if (redosAvail == 0)
1892 QString s=getSelectString(sel);
1893 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1894 curClipboard=curStep;
1897 // Copy also to global clipboard, because we are at last step in history
1898 QString bakMapName(QString("history-%1").arg(curStep));
1899 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1900 copyDir (bakMapDir,clipboardDir );
1902 clipboardEmpty=false;
1909 void VymModel::pasteNoSave(const int &n) //FIXME-2
1912 bool old=blockSaveState;
1913 blockSaveState=true;
1914 bool zippedOrg=zipped;
1915 if (redosAvail > 0 || n!=0)
1917 // Use the "historical" buffer
1918 QString bakMapName(QString("history-%1").arg(n));
1919 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1920 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1922 // Use the global buffer
1923 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1929 void VymModel::paste() //FIXME-2
1932 BranchObj *sel=getSelectedBranch();
1935 saveStateChangingPart(
1938 QString ("paste (%1)").arg(curClipboard),
1939 QString("Paste to %1").arg( getObjectName(sel))
1947 void VymModel::cut() //FIXME-2
1950 LinkableMapObj *sel=getSelectedLMO();
1951 if ( sel && (selectionType() == TreeItem::Branch ||
1952 selectionType()==TreeItem::MapCenter ||
1953 selectionType()==TreeItem::Image))
1956 /* No savestate! savestate is called in cutNoSave
1957 saveStateChangingPart(
1961 QString("Cut %1").arg(getObjectName(sel ))
1971 void VymModel::moveBranchUp() //FIXME-2
1974 BranchObj* bo=getSelectedBranch();
1978 if (!bo->canMoveBranchUp()) return;
1979 par=(BranchObj*)(bo->getParObj());
1980 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1981 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1983 //FIXME-3 VM needed? scene()->update();
1985 ensureSelectionVisible();
1990 void VymModel::moveBranchDown() //FIXME-2
1993 BranchObj* bo=getSelectedBranch();
1997 if (!bo->canMoveBranchDown()) return;
1998 par=(BranchObj*)(bo->getParObj());
1999 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
2000 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
2002 //FIXME-3 VM needed? scene()->update();
2004 ensureSelectionVisible();
2009 void VymModel::sortChildren() // FIXME-2 not implemented yet
2012 BranchObj* bo=getSelectedBranch();
2015 if(treeItem->branchCount()>1)
2017 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
2020 ensureSelectionVisible();
2026 MapCenterItem* VymModel::createMapCenter()
2028 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
2033 BranchItem* VymModel::createBranch() // FIXME-2 switcht addNewBrancInt to BranchItem...
2035 BranchObj* bo=addNewBranchInt (-2);
2036 return (BranchItem*)bo->getTreeItem();
2039 TreeItem* VymModel::createImage() //FIXME-2
2042 BranchObj *bo=getSelectedBranch();
2045 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
2048 QList<QVariant> cData;
2049 cData << "VM:createImage" << "undef"<<"undef";
2050 TreeItem *parti=bo->getTreeItem();
2051 TreeItem *ti=new TreeItem (cData,parti);
2052 ti->setLMO (newfio);
2053 ti->setType (TreeItem::Image);
2054 parti->appendChild (ti);
2058 newfio->setTreeItem (ti);
2059 select (newfio); // FIXME-2 VM really needed here?
2067 MapCenterItem* VymModel::addMapCenter ()
2069 MapCenterItem *mci=addMapCenter (contextPos); //FIXME-2 get rid of MCO here
2070 //FIXME-3 selection.select (mco);
2072 ensureSelectionVisible();
2077 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2078 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2083 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2087 QModelIndex parix=index(rootItem);
2089 int n=rootItem->branchCount();
2091 emit (layoutAboutToBeChanged() );
2092 beginInsertRows (parix,n,n+1);
2094 QList<QVariant> cData;
2095 cData << "VM:addMapCenter" << "undef"<<"undef";
2096 MapCenterItem *mci=new MapCenterItem (cData,rootItem);
2097 cout << "VM::addMapCenter mci="<<mci<<endl;
2098 mci->setType (TreeItem::MapCenter);
2099 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2100 rootItem->appendChild (mci);
2103 emit (newChildObject (parix));
2104 emit (layoutChanged() );
2107 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
2108 mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2109 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2110 mci->setLMO (mapCenter);
2111 mapCenter->updateHeading();
2112 mapCenter->move (absPos);
2113 mapCenter->setVisibility (true);
2114 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2115 mapCenters.append(mapCenter); //FIXME-1 get rid of mapCenters...
2118 qWarning ("MW::insertRow a");
2119 if (!insertRow(0, parix))
2121 std::cout << " war nix...\n";
2123 qWarning ("MW::insertRow b");
2129 MapCenterItem* VymModel::removeMapCenter(MapCenterItem* mci) //FIXME-2
2132 int i=mapCenters.indexOf (mco);
2135 mapCenters.removeAt (i);
2137 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2143 MapCenterObj* VymModel::getLastMapCenter()
2145 if (mapCenters.size()>0)
2146 return mapCenters.last();
2153 BranchObj* VymModel::addNewBranchInt(int num)
2155 // Depending on pos:
2156 // -3 insert in children of parent above selection
2157 // -2 add branch to selection
2158 // -1 insert in children of parent below selection
2159 // 0..n insert in children of parent at pos
2160 BranchObj *newbo=NULL;
2161 BranchObj *bo=getSelectedBranchObj(); //FIXME-2
2162 BranchItem *bi=getSelectedBranchItem();
2168 QList<QVariant> cData;
2169 cData << "new" << "undef"<<"undef";
2171 BranchItem *parbi=bi;
2172 QModelIndex parix=index(parbi);
2173 int n=parbi->branchCount();
2175 emit (layoutAboutToBeChanged() );
2176 beginInsertRows (parix,n,n+1);
2177 bi=new BranchItem (cData,parbi);
2178 bi->setType (TreeItem::Branch);
2179 bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2181 parbi->appendChild (bi);
2183 emit (newChildObject (parix));
2184 emit (layoutChanged() );
2186 // save scroll state. If scrolled, automatically select
2187 // new branch in order to tmp unscroll parent...
2188 newbo=bo->addBranch();
2193 newbo->setTreeItem (bi);
2200 bo=(BranchObj*)bo->getParObj();
2201 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2205 bo=(BranchObj*)bo->getParObj();
2206 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2212 BranchObj* VymModel::addNewBranch(int pos)
2214 // Different meaning than num in addNewBranchInt!
2218 BranchObj *bo = getSelectedBranchObj(); //FIXME-2
2219 BranchObj *newbo=NULL;
2223 // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2225 newbo=addNewBranchInt (pos-2);
2230 newbo->getTreeItem(),
2233 QString ("addBranch (%1)").arg(pos),
2234 QString ("Add new branch to %1").arg(getObjectName(bo)));
2237 // selection.update(); FIXME-3
2238 latestSelectionString=getSelectString(newbo);
2239 // In Network mode, the client needs to know where the new branch is,
2240 // so we have to pass on this information via saveState.
2241 // TODO: Get rid of this positioning workaround
2242 QString ps=qpointfToString (newbo->getAbsPos());
2243 sendData ("selectLatestAdded ()");
2244 sendData (QString("move %1").arg(ps));
2252 BranchObj* VymModel::addNewBranchBefore() //FIXME-2
2255 BranchObj *newbo=NULL;
2256 BranchObj *bo = getSelectedBranch();
2257 if (bo && selectionType()==TreeItem::Branch)
2258 // We accept no MapCenterObj here, so we _have_ a parent
2260 QPointF p=bo->getRelPos();
2263 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2265 // add below selection
2266 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2270 newbo->move2RelPos (p);
2272 // Move selection to new branch
2273 bo->linkTo (newbo,-1);
2275 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2276 QString ("Add branch before %1").arg(getObjectName(bo)));
2279 // selection.update(); FIXME-3
2282 latestSelectionString=selection.getSelectString();
2288 void VymModel::deleteSelection()
2290 BranchObj *bo = getSelectedBranchObj(); // FIXME-2 VM should not be necessary
2291 BranchItem *selbi=getSelectedBranchItem();
2295 QModelIndex ix=index (selbi);
2296 if (!ix.isValid() ) return;
2298 QModelIndex parentIndex=parent(ix);
2300 if (!parentIndex.isValid())
2302 cout << "VM::delete no valid parent ix\n";
2308 if (selbi->getType()==TreeItem::MapCenter)
2310 // BranchObj* par=(BranchObj*)(bo->getParObj());
2311 //selection.unselect();
2312 // FIXME-1 VM Note: does saveStateRemovingPart work for MCO? (No parent!)
2313 //saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2314 emit (layoutAboutToBeChanged() );
2316 parentIndex=parent(index(selbi));
2317 cout << "VM::delete selbi="<<selbi<<" row="<<ix.row()<<" parIndex.valid="<<parentIndex.isValid()<<endl;
2319 beginRemoveRows (parentIndex,n,n);
2320 removeRows (n,1,parentIndex);
2321 MapCenterItem *mci=removeMapCenter (selbi);
2326 ensureSelectionVisible();
2330 emit (layoutChanged() );
2332 if (selbi->getType()==TreeItem::Branch)
2334 if (selbi->isBranchLikeType() )
2337 BranchObj* par=(BranchObj*)bo->getParObj();
2339 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(bo)));
2341 emit (layoutAboutToBeChanged() );
2343 cout << "VM::delete selbi="<<selbi<<" row="<<ix.row()<<endl;
2344 parentIndex=parent(index(selbi));
2346 beginRemoveRows (parentIndex,n,n);
2347 removeRows (n,1,parentIndex);
2349 par->removeBranch(bo); // remove from BranchObj lists...
2351 ensureSelectionVisible();
2354 emit (layoutChanged() );
2357 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2362 BranchObj* par=(BranchObj*)fio->getParObj();
2363 saveStateChangingPart(
2367 QString("Delete %1").arg(getObjectName(fio))
2370 par->removeFloatImage(fio);
2373 ensureSelectionVisible();
2379 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2383 BranchObj *bo=getSelectedBranch();
2387 par=(BranchObj*)(bo->getParObj());
2389 // Don't use this on mapcenter
2392 // Check if we have childs at all to keep
2393 if (bo->getTreeItem()->branchCount()==0)
2399 QPointF p=bo->getRelPos();
2400 saveStateChangingPart(
2403 "deleteKeepChildren ()",
2404 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2407 QString sel=getSelectString(bo);
2409 par->removeBranchHere(bo);
2412 getSelectedBranch()->move2RelPos (p);
2417 void VymModel::deleteChildren() //FIXME-2 VM still missing
2421 BranchObj *bo=getSelectedBranch();
2424 saveStateChangingPart(
2427 "deleteChildren ()",
2428 QString( "Remove children of branch %1").arg(getObjectName(bo))
2430 bo->removeChildren();
2436 bool VymModel::scrollBranch(BranchItem *bi)
2440 if (bi->isScrolled()) return false;
2441 if (bi->branchCount()==0) return false;
2442 if (bi->depth()==0) return false;
2446 /* FIXME-3 no savestate yet
2449 QString ("%1 ()").arg(u),
2451 QString ("%1 ()").arg(r),
2452 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2456 //selection.update();
2457 // FIXME-3 VM needed? scene()->update();
2463 bool VymModel::unscrollBranch(BranchItem *bi)
2467 if (bi->isScrolled()) return false;
2468 if (bi->branchCount()==0) return false;
2469 if (bi->depth()==0) return false;
2474 /* FIXME-3 no savestate yet
2477 QString ("%1 ()").arg(u),
2479 QString ("%1 ()").arg(r),
2480 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2484 // selection.update();
2485 // FIXME-3 VM needed? scene()->update();
2491 void VymModel::toggleScroll()
2493 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2494 if (bi && bi->getType()==TreeItem::Branch )
2496 if (bi->isScrolled())
2497 unscrollBranch (bi);
2503 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2507 BranchObj *bo=getSelectedBranch();
2513 if (bo->isScrolled()) unscrollBranch (bo);
2520 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2523 BranchObj *bo=getSelectedBranch();
2526 FloatImageObj *fio=bo->addFloatImage();
2528 fio->setOriginalFilename("No original filename (image added by dropevent)");
2529 QString s=getSelectString(bo);
2530 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2531 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2533 // FIXME-3 VM needed? scene()->update();
2539 void VymModel::colorBranch (QColor c) //FIXME-2
2542 BranchObj *bo=getSelectedBranch();
2547 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2549 QString ("colorBranch (\"%1\")").arg(c.name()),
2550 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2552 bo->setColor(c); // color branch
2557 void VymModel::colorSubtree (QColor c) //FIXME-2
2560 BranchObj *bo=getSelectedBranch();
2563 saveStateChangingPart(
2566 QString ("colorSubtree (\"%1\")").arg(c.name()),
2567 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2569 bo->setColorSubtree (c); // color links, color children
2574 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2577 BranchObj *bo=getSelectedBranch();
2578 if (bo) return bo->getColor();
2580 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2587 void VymModel::editURL() //FIXME-2
2590 BranchObj *bo=getSelectedBranch();
2594 QString text = QInputDialog::getText(
2595 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2596 bo->getURL(), &ok, NULL);
2598 // user entered something and pressed OK
2604 void VymModel::editLocalURL() //FIXME-2
2607 BranchObj *bo=getSelectedBranch();
2610 QStringList filters;
2611 filters <<"All files (*)";
2612 filters << tr("Text","Filedialog") + " (*.txt)";
2613 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2614 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2615 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2616 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2617 fd->setFilters (filters);
2618 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2619 fd->setDirectory (lastFileDir);
2620 if (! bo->getVymLink().isEmpty() )
2621 fd->selectFile( bo->getURL() );
2624 if ( fd->exec() == QDialog::Accepted )
2626 lastFileDir=QDir (fd->directory().path());
2627 setURL (fd->selectedFile() );
2634 void VymModel::editHeading2URL() //FIXME-2
2637 BranchObj *bo=getSelectedBranch();
2639 setURL (bo->getHeading());
2643 void VymModel::editBugzilla2URL() //FIXME-2
2646 BranchObj *bo=getSelectedBranch();
2649 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2655 void VymModel::editFATE2URL() //FIXME-2
2658 BranchObj *bo=getSelectedBranch();
2661 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2664 "setURL (\""+bo->getURL()+"\")",
2666 "setURL (\""+url+"\")",
2667 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2675 void VymModel::editVymLink()
2677 BranchItem *bi=getSelectedBranchItem();
2680 QStringList filters;
2681 filters <<"VYM map (*.vym)";
2682 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2683 fd->setFilters (filters);
2684 fd->setCaption(vymName+" - " +tr("Link to another map"));
2685 fd->setDirectory (lastFileDir);
2686 if (! bi->getVymLink().isEmpty() )
2687 fd->selectFile( bi->getVymLink() );
2691 if ( fd->exec() == QDialog::Accepted )
2693 lastFileDir=QDir (fd->directory().path());
2696 "setVymLink (\""+bi->getVymLink()+"\")",
2698 "setVymLink (\""+fd->selectedFile()+"\")",
2699 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2701 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2706 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2708 // Internal function, no saveState needed
2709 BranchItem *bi=getSelectedBranchItem();
2712 bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO
2715 //selection.update();
2716 ensureSelectionVisible();
2720 void VymModel::deleteVymLink()
2722 BranchItem *bi=getSelectedBranchItem();
2727 "setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO
2730 "setVymLink (\"\")",
2731 QString("Unset vymlink of %1").arg(getObjectName(bi))
2733 bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO
2736 // FIXME-3 VM needed? scene()->update();
2740 QString VymModel::getVymLink()
2742 BranchItem *bi=getSelectedBranchItem();
2744 return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here...
2750 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2752 return QStringList();
2755 BranchObj *bo=getSelectedBranch();
2761 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2770 void VymModel::followXLink(int i) // FIXME-2
2774 BranchObj *bo=getSelectedBranch();
2777 bo=bo->XLinkTargetAt(i);
2780 selection.select(bo);
2781 ensureSelectionVisible();
2787 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2791 BranchObj *bo=getSelectedBranch();
2794 XLinkObj *xlo=bo->XLinkAt(i);
2797 EditXLinkDialog dia;
2799 dia.setSelection(bo);
2800 if (dia.exec() == QDialog::Accepted)
2802 if (dia.useSettingsGlobal() )
2804 setMapDefXLinkColor (xlo->getColor() );
2805 setMapDefXLinkWidth (xlo->getWidth() );
2807 if (dia.deleteXLink())
2808 bo->deleteXLinkAt(i);
2819 //////////////////////////////////////////////
2821 //////////////////////////////////////////////
2823 void VymModel::parseAtom(const QString &atom)
2825 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2826 TreeItem* selti=getSelectedItem();
2827 BranchItem *selbi=getSelectedBranchItem();
2833 // Split string s into command and parameters
2834 parser.parseAtom (atom);
2835 QString com=parser.getCommand();
2837 // External commands
2838 /////////////////////////////////////////////////////////////////////
2839 if (com=="addBranch")
2843 parser.setError (Aborted,"Nothing selected");
2844 } else if (! selbi )
2846 parser.setError (Aborted,"Type of selection is not a branch");
2851 if (parser.checkParCount(pl))
2853 if (parser.parCount()==0)
2857 n=parser.parInt (ok,0);
2858 if (ok ) addNewBranch (n);
2862 /////////////////////////////////////////////////////////////////////
2863 } else if (com=="addBranchBefore")
2867 parser.setError (Aborted,"Nothing selected");
2868 } else if (! selbi )
2870 parser.setError (Aborted,"Type of selection is not a branch");
2873 if (parser.parCount()==0)
2875 addNewBranchBefore ();
2878 /////////////////////////////////////////////////////////////////////
2879 } else if (com==QString("addMapCenter"))
2881 if (parser.checkParCount(2))
2883 x=parser.parDouble (ok,0);
2886 y=parser.parDouble (ok,1);
2887 if (ok) addMapCenter (QPointF(x,y));
2890 /////////////////////////////////////////////////////////////////////
2891 } else if (com==QString("addMapReplace"))
2895 parser.setError (Aborted,"Nothing selected");
2896 } else if (! selbi )
2898 parser.setError (Aborted,"Type of selection is not a branch");
2899 } else if (parser.checkParCount(1))
2901 //s=parser.parString (ok,0); // selection
2902 t=parser.parString (ok,0); // path to map
2903 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2904 addMapReplaceInt(getSelectString(selbi),t);
2906 /////////////////////////////////////////////////////////////////////
2907 } else if (com==QString("addMapInsert"))
2911 parser.setError (Aborted,"Nothing selected");
2912 } else if (! selbi )
2914 parser.setError (Aborted,"Type of selection is not a branch");
2917 if (parser.checkParCount(2))
2919 t=parser.parString (ok,0); // path to map
2920 n=parser.parInt(ok,1); // position
2921 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2922 addMapInsertInt(t,n);
2925 /////////////////////////////////////////////////////////////////////
2926 } else /*if (com=="clearFlags") // FIXME-2
2930 parser.setError (Aborted,"Nothing selected");
2931 } else if (! selbi )
2933 parser.setError (Aborted,"Type of selection is not a branch");
2934 } else if (parser.checkParCount(0))
2936 selb->clearStandardFlags();
2937 selb->updateFlagsToolbar();
2939 /////////////////////////////////////////////////////////////////////
2940 } else */ if (com=="colorBranch")
2944 parser.setError (Aborted,"Nothing selected");
2945 } else if (! selbi )
2947 parser.setError (Aborted,"Type of selection is not a branch");
2948 } else if (parser.checkParCount(1))
2950 QColor c=parser.parColor (ok,0);
2951 if (ok) colorBranch (c);
2953 /////////////////////////////////////////////////////////////////////
2954 } else if (com=="colorSubtree")
2958 parser.setError (Aborted,"Nothing selected");
2959 } else if (! selbi )
2961 parser.setError (Aborted,"Type of selection is not a branch");
2962 } else if (parser.checkParCount(1))
2964 QColor c=parser.parColor (ok,0);
2965 if (ok) colorSubtree (c);
2967 /////////////////////////////////////////////////////////////////////
2968 } else if (com=="copy")
2972 parser.setError (Aborted,"Nothing selected");
2973 } else if (! selbi )
2975 parser.setError (Aborted,"Type of selection is not a branch");
2976 } else if (parser.checkParCount(0))
2978 //FIXME-1 missing action for copy
2980 /////////////////////////////////////////////////////////////////////
2981 } else if (com=="cut")
2985 parser.setError (Aborted,"Nothing selected");
2986 } else if ( selectionType()!=TreeItem::Branch &&
2987 selectionType()!=TreeItem::MapCenter &&
2988 selectionType()!=TreeItem::Image )
2990 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2991 } else if (parser.checkParCount(0))
2995 /////////////////////////////////////////////////////////////////////
2996 } else if (com=="delete")
3000 parser.setError (Aborted,"Nothing selected");
3002 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3004 parser.setError (Aborted,"Type of selection is wrong.");
3007 else if (parser.checkParCount(0))
3011 /////////////////////////////////////////////////////////////////////
3012 } else if (com=="deleteKeepChildren")
3016 parser.setError (Aborted,"Nothing selected");
3017 } else if (! selbi )
3019 parser.setError (Aborted,"Type of selection is not a branch");
3020 } else if (parser.checkParCount(0))
3022 deleteKeepChildren();
3024 /////////////////////////////////////////////////////////////////////
3025 } else if (com=="deleteChildren")
3029 parser.setError (Aborted,"Nothing selected");
3032 parser.setError (Aborted,"Type of selection is not a branch");
3033 } else if (parser.checkParCount(0))
3037 /////////////////////////////////////////////////////////////////////
3038 } else if (com=="exportASCII")
3042 if (parser.parCount()>=1)
3043 // Hey, we even have a filename
3044 fname=parser.parString(ok,0);
3047 parser.setError (Aborted,"Could not read filename");
3050 exportASCII (fname,false);
3052 /////////////////////////////////////////////////////////////////////
3053 } else if (com=="exportImage")
3057 if (parser.parCount()>=2)
3058 // Hey, we even have a filename
3059 fname=parser.parString(ok,0);
3062 parser.setError (Aborted,"Could not read filename");
3065 QString format="PNG";
3066 if (parser.parCount()>=2)
3068 format=parser.parString(ok,1);
3070 exportImage (fname,false,format);
3072 /////////////////////////////////////////////////////////////////////
3073 } else if (com=="exportXHTML")
3077 if (parser.parCount()>=2)
3078 // Hey, we even have a filename
3079 fname=parser.parString(ok,1);
3082 parser.setError (Aborted,"Could not read filename");
3085 exportXHTML (fname,false);
3087 /////////////////////////////////////////////////////////////////////
3088 } else if (com=="exportXML")
3092 if (parser.parCount()>=2)
3093 // Hey, we even have a filename
3094 fname=parser.parString(ok,1);
3097 parser.setError (Aborted,"Could not read filename");
3100 exportXML (fname,false);
3102 /////////////////////////////////////////////////////////////////////
3103 } else if (com=="importDir")
3107 parser.setError (Aborted,"Nothing selected");
3108 } else if (! selbi )
3110 parser.setError (Aborted,"Type of selection is not a branch");
3111 } else if (parser.checkParCount(1))
3113 s=parser.parString(ok,0);
3114 if (ok) importDirInt(s);
3116 /////////////////////////////////////////////////////////////////////
3117 } else /* FIXME-2 if (com=="linkTo")
3121 parser.setError (Aborted,"Nothing selected");
3124 if (parser.checkParCount(4))
3126 // 0 selectstring of parent
3127 // 1 num in parent (for branches)
3128 // 2,3 x,y of mainbranch or mapcenter
3129 s=parser.parString(ok,0);
3130 LinkableMapObj *dst=findObjBySelect (s);
3133 if (typeid(*dst) == typeid(BranchObj) )
3135 // Get number in parent
3136 n=parser.parInt (ok,1);
3139 selb->linkTo ((BranchObj*)(dst),n);
3142 } else if (typeid(*dst) == typeid(MapCenterObj) )
3144 selb->linkTo ((BranchObj*)(dst),-1);
3145 // Get coordinates of mainbranch
3146 x=parser.parDouble(ok,2);
3149 y=parser.parDouble(ok,3);
3159 } else if ( selectionType() == TreeItem::Image)
3161 if (parser.checkParCount(1))
3163 // 0 selectstring of parent
3164 s=parser.parString(ok,0);
3165 LinkableMapObj *dst=findObjBySelect (s);
3168 if (typeid(*dst) == typeid(BranchObj) ||
3169 typeid(*dst) == typeid(MapCenterObj))
3170 linkFloatImageTo (getSelectString(dst));
3172 parser.setError (Aborted,"Destination is not a branch");
3175 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3176 /////////////////////////////////////////////////////////////////////
3177 } else */ if (com=="loadImage")
3181 parser.setError (Aborted,"Nothing selected");
3182 } else if (! selbi )
3184 parser.setError (Aborted,"Type of selection is not a branch");
3185 } else if (parser.checkParCount(1))
3187 s=parser.parString(ok,0);
3188 if (ok) loadFloatImageInt (s);
3190 /////////////////////////////////////////////////////////////////////
3191 } else if (com=="moveBranchUp")
3195 parser.setError (Aborted,"Nothing selected");
3196 } else if (! selbi )
3198 parser.setError (Aborted,"Type of selection is not a branch");
3199 } else if (parser.checkParCount(0))
3203 /////////////////////////////////////////////////////////////////////
3204 } else if (com=="moveBranchDown")
3208 parser.setError (Aborted,"Nothing selected");
3209 } else if (! selbi )
3211 parser.setError (Aborted,"Type of selection is not a branch");
3212 } else if (parser.checkParCount(0))
3216 /////////////////////////////////////////////////////////////////////
3217 } else if (com=="move")
3221 parser.setError (Aborted,"Nothing selected");
3222 } else if ( selectionType()!=TreeItem::Branch &&
3223 selectionType()!=TreeItem::MapCenter &&
3224 selectionType()!=TreeItem::Image )
3226 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3227 } else if (parser.checkParCount(2))
3229 x=parser.parDouble (ok,0);
3232 y=parser.parDouble (ok,1);
3236 /////////////////////////////////////////////////////////////////////
3237 } else if (com=="moveRel")
3241 parser.setError (Aborted,"Nothing selected");
3242 } else if ( selectionType()!=TreeItem::Branch &&
3243 selectionType()!=TreeItem::MapCenter &&
3244 selectionType()!=TreeItem::Image )
3246 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3247 } else if (parser.checkParCount(2))
3249 x=parser.parDouble (ok,0);
3252 y=parser.parDouble (ok,1);
3253 if (ok) moveRel (x,y);
3256 /////////////////////////////////////////////////////////////////////
3257 } else if (com=="nop")
3259 /////////////////////////////////////////////////////////////////////
3260 } else if (com=="paste")
3264 parser.setError (Aborted,"Nothing selected");
3265 } else if (! selbi )
3267 parser.setError (Aborted,"Type of selection is not a branch");
3268 } else if (parser.checkParCount(1))
3270 n=parser.parInt (ok,0);
3271 if (ok) pasteNoSave(n);
3273 /////////////////////////////////////////////////////////////////////
3274 } else if (com=="qa")
3278 parser.setError (Aborted,"Nothing selected");
3279 } else if (! selbi )
3281 parser.setError (Aborted,"Type of selection is not a branch");
3282 } else if (parser.checkParCount(4))
3285 c=parser.parString (ok,0);
3288 parser.setError (Aborted,"No comment given");
3291 s=parser.parString (ok,1);
3294 parser.setError (Aborted,"First parameter is not a string");
3297 t=parser.parString (ok,2);
3300 parser.setError (Aborted,"Condition is not a string");
3303 u=parser.parString (ok,3);
3306 parser.setError (Aborted,"Third parameter is not a string");
3311 parser.setError (Aborted,"Unknown type: "+s);
3316 parser.setError (Aborted,"Unknown operator: "+t);
3321 parser.setError (Aborted,"Type of selection is not a branch");
3324 if (selbi->getHeading() == u)
3326 cout << "PASSED: " << qPrintable (c) << endl;
3329 cout << "FAILED: " << qPrintable (c) << endl;
3339 /////////////////////////////////////////////////////////////////////
3340 } else if (com=="saveImage")
3342 FloatImageObj *fio=selection.getFloatImage();
3345 parser.setError (Aborted,"Type of selection is not an image");
3346 } else if (parser.checkParCount(2))
3348 s=parser.parString(ok,0);
3351 t=parser.parString(ok,1);
3352 if (ok) saveFloatImageInt (fio,t,s);
3355 /////////////////////////////////////////////////////////////////////
3356 } else if (com=="scroll")
3360 parser.setError (Aborted,"Nothing selected");
3361 } else if (! selbi )
3363 parser.setError (Aborted,"Type of selection is not a branch");
3364 } else if (parser.checkParCount(0))
3366 if (!scrollBranch (selbi))
3367 parser.setError (Aborted,"Could not scroll branch");
3369 /////////////////////////////////////////////////////////////////////
3370 } else if (com=="select")
3372 if (parser.checkParCount(1))
3374 s=parser.parString(ok,0);
3377 /////////////////////////////////////////////////////////////////////
3378 } else if (com=="selectLastBranch")
3382 parser.setError (Aborted,"Nothing selected");
3383 } else if (! selbi )
3385 parser.setError (Aborted,"Type of selection is not a branch");
3386 } else if (parser.checkParCount(0))
3388 BranchItem *bi=selbi->getLastBranch();
3390 parser.setError (Aborted,"Could not select last branch");
3391 select (bi); // FIXME-3 was selectInt
3394 /////////////////////////////////////////////////////////////////////
3395 } else /* FIXME-2 if (com=="selectLastImage")
3399 parser.setError (Aborted,"Nothing selected");
3400 } else if (! selbi )
3402 parser.setError (Aborted,"Type of selection is not a branch");
3403 } else if (parser.checkParCount(0))
3405 FloatImageObj *fio=selb->getLastFloatImage();
3407 parser.setError (Aborted,"Could not select last image");
3408 select (fio); // FIXME-3 was selectInt
3411 /////////////////////////////////////////////////////////////////////
3412 } else */ if (com=="selectLatestAdded")
3414 if (latestSelectionString.isEmpty() )
3416 parser.setError (Aborted,"No latest added object");
3419 if (!select (latestSelectionString))
3420 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3422 /////////////////////////////////////////////////////////////////////
3423 } else if (com=="setFrameType")
3425 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3427 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3429 else if (parser.checkParCount(1))
3431 s=parser.parString(ok,0);
3432 if (ok) setFrameType (s);
3434 /////////////////////////////////////////////////////////////////////
3435 } else if (com=="setFramePenColor")
3437 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3439 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3441 else if (parser.checkParCount(1))
3443 QColor c=parser.parColor(ok,0);
3444 if (ok) setFramePenColor (c);
3446 /////////////////////////////////////////////////////////////////////
3447 } else if (com=="setFrameBrushColor")
3449 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3451 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3453 else if (parser.checkParCount(1))
3455 QColor c=parser.parColor(ok,0);
3456 if (ok) setFrameBrushColor (c);
3458 /////////////////////////////////////////////////////////////////////
3459 } else if (com=="setFramePadding")
3461 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3463 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3465 else if (parser.checkParCount(1))
3467 n=parser.parInt(ok,0);
3468 if (ok) setFramePadding(n);
3470 /////////////////////////////////////////////////////////////////////
3471 } else if (com=="setFrameBorderWidth")
3473 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3475 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3477 else if (parser.checkParCount(1))
3479 n=parser.parInt(ok,0);
3480 if (ok) setFrameBorderWidth (n);
3482 /////////////////////////////////////////////////////////////////////
3483 } else if (com=="setMapAuthor")
3485 if (parser.checkParCount(1))
3487 s=parser.parString(ok,0);
3488 if (ok) setAuthor (s);
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="setMapComment")
3493 if (parser.checkParCount(1))
3495 s=parser.parString(ok,0);
3496 if (ok) setComment(s);
3498 /////////////////////////////////////////////////////////////////////
3499 } else if (com=="setMapBackgroundColor")
3503 parser.setError (Aborted,"Nothing selected");
3504 } else if (! selbi )
3506 parser.setError (Aborted,"Type of selection is not a branch");
3507 } else if (parser.checkParCount(1))
3509 QColor c=parser.parColor (ok,0);
3510 if (ok) setMapBackgroundColor (c);
3512 /////////////////////////////////////////////////////////////////////
3513 } else if (com=="setMapDefLinkColor")
3517 parser.setError (Aborted,"Nothing selected");
3518 } else if (! selbi )
3520 parser.setError (Aborted,"Type of selection is not a branch");
3521 } else if (parser.checkParCount(1))
3523 QColor c=parser.parColor (ok,0);
3524 if (ok) setMapDefLinkColor (c);
3526 /////////////////////////////////////////////////////////////////////
3527 } else if (com=="setMapLinkStyle")
3529 if (parser.checkParCount(1))
3531 s=parser.parString (ok,0);
3532 if (ok) setMapLinkStyle(s);
3534 /////////////////////////////////////////////////////////////////////
3535 } else if (com=="setHeading")
3539 parser.setError (Aborted,"Nothing selected");
3540 } else if (! selbi )
3542 parser.setError (Aborted,"Type of selection is not a branch");
3543 } else if (parser.checkParCount(1))
3545 s=parser.parString (ok,0);
3549 /////////////////////////////////////////////////////////////////////
3550 } else if (com=="setHideExport")
3554 parser.setError (Aborted,"Nothing selected");
3555 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3557 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3558 } else if (parser.checkParCount(1))
3560 b=parser.parBool(ok,0);
3561 if (ok) setHideExport (b);
3563 /////////////////////////////////////////////////////////////////////
3564 } else if (com=="setIncludeImagesHorizontally")
3568 parser.setError (Aborted,"Nothing selected");
3571 parser.setError (Aborted,"Type of selection is not a branch");
3572 } else if (parser.checkParCount(1))
3574 b=parser.parBool(ok,0);
3575 if (ok) setIncludeImagesHor(b);
3577 /////////////////////////////////////////////////////////////////////
3578 } else if (com=="setIncludeImagesVertically")
3582 parser.setError (Aborted,"Nothing selected");
3585 parser.setError (Aborted,"Type of selection is not a branch");
3586 } else if (parser.checkParCount(1))
3588 b=parser.parBool(ok,0);
3589 if (ok) setIncludeImagesVer(b);
3591 /////////////////////////////////////////////////////////////////////
3592 } else if (com=="setHideLinkUnselected")
3596 parser.setError (Aborted,"Nothing selected");
3597 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3599 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3600 } else if (parser.checkParCount(1))
3602 b=parser.parBool(ok,0);
3603 if (ok) setHideLinkUnselected(b);
3605 /////////////////////////////////////////////////////////////////////
3606 } else if (com=="setSelectionColor")
3608 if (parser.checkParCount(1))
3610 QColor c=parser.parColor (ok,0);
3611 if (ok) setSelectionColorInt (c);
3613 /////////////////////////////////////////////////////////////////////
3614 } else if (com=="setURL")
3618 parser.setError (Aborted,"Nothing selected");
3619 } else if (! selbi )
3621 parser.setError (Aborted,"Type of selection is not a branch");
3622 } else if (parser.checkParCount(1))
3624 s=parser.parString (ok,0);
3627 /////////////////////////////////////////////////////////////////////
3628 } else if (com=="setVymLink")
3632 parser.setError (Aborted,"Nothing selected");
3633 } else if (! selbi )
3635 parser.setError (Aborted,"Type of selection is not a branch");
3636 } else if (parser.checkParCount(1))
3638 s=parser.parString (ok,0);
3639 if (ok) setVymLink(s);
3642 /////////////////////////////////////////////////////////////////////
3643 else /* FIXME-2 if (com=="setFlag")
3647 parser.setError (Aborted,"Nothing selected");
3648 } else if (! selbi )
3650 parser.setError (Aborted,"Type of selection is not a branch");
3651 } else if (parser.checkParCount(1))
3653 s=parser.parString(ok,0);
3656 selb->activateStandardFlag(s);
3657 selb->updateFlagsToolbar();
3660 /////////////////////////////////////////////////////////////////////
3661 } else */ /* FIXME-2 if (com=="setFrameType")
3665 parser.setError (Aborted,"Nothing selected");
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(1))
3671 s=parser.parString(ok,0);
3675 /////////////////////////////////////////////////////////////////////
3676 } else*/ if (com=="sortChildren")
3680 parser.setError (Aborted,"Nothing selected");
3681 } else if (! selbi )
3683 parser.setError (Aborted,"Type of selection is not a branch");
3684 } else if (parser.checkParCount(0))
3688 /////////////////////////////////////////////////////////////////////
3689 } else /* FIXME-2 if (com=="toggleFlag")
3693 parser.setError (Aborted,"Nothing selected");
3694 } else if (! selbi )
3696 parser.setError (Aborted,"Type of selection is not a branch");
3697 } else if (parser.checkParCount(1))
3699 s=parser.parString(ok,0);
3702 selbi->toggleStandardFlag(s);
3703 selb->updateFlagsToolbar();
3706 /////////////////////////////////////////////////////////////////////
3707 } else */ if (com=="unscroll")
3711 parser.setError (Aborted,"Nothing selected");
3712 } else if (! selbi )
3714 parser.setError (Aborted,"Type of selection is not a branch");
3715 } else if (parser.checkParCount(0))
3717 if (!unscrollBranch (selbi))
3718 parser.setError (Aborted,"Could not unscroll branch");
3720 /////////////////////////////////////////////////////////////////////
3721 } else if (com=="unscrollChildren")
3725 parser.setError (Aborted,"Nothing selected");
3726 } else if (! selbi )
3728 parser.setError (Aborted,"Type of selection is not a branch");
3729 } else if (parser.checkParCount(0))
3731 unscrollChildren ();
3733 /////////////////////////////////////////////////////////////////////
3734 } else /* FIXME-2 if (com=="unsetFlag")
3736 if (selection.isEmpty() )
3738 parser.setError (Aborted,"Nothing selected");
3739 } else if (! selbi )
3741 parser.setError (Aborted,"Type of selection is not a branch");
3742 } else if (parser.checkParCount(1))
3744 s=parser.parString(ok,0);
3747 selb->deactivateStandardFlag(s);
3748 selb->updateFlagsToolbar();
3752 parser.setError (Aborted,"Unknown command");
3755 if (parser.errorLevel()==NoError)
3757 // setChanged(); FIXME-2 should not be called e.g. for export?!
3762 // TODO Error handling
3763 qWarning("VymModel::parseAtom: Error!");
3764 qWarning(parser.errorMessage());
3768 void VymModel::runScript (QString script)
3770 parser.setScript (script);
3772 while (parser.next() )
3773 parseAtom(parser.getAtom());
3776 void VymModel::setExportMode (bool b)
3778 // should be called before and after exports
3779 // depending on the settings
3780 if (b && settings.value("/export/useHideExport","true")=="true")
3781 setHideTmpMode (TreeItem::HideExport);
3783 setHideTmpMode (TreeItem::HideNone);
3786 void VymModel::exportImage(QString fname, bool askName, QString format)
3790 fname=getMapName()+".png";
3797 QFileDialog *fd=new QFileDialog (NULL);
3798 fd->setCaption (tr("Export map as image"));
3799 fd->setDirectory (lastImageDir);
3800 fd->setFileMode(QFileDialog::AnyFile);
3801 fd->setFilters (imageIO.getFilters() );
3804 fl=fd->selectedFiles();
3806 format=imageIO.getType(fd->selectedFilter());
3810 setExportMode (true);
3811 QPixmap pix (getPixmap());
3812 pix.save(fname, format);
3813 setExportMode (false);
3817 void VymModel::exportXML(QString dir, bool askForName)
3821 dir=browseDirectory(NULL,tr("Export XML to directory"));
3822 if (dir =="" && !reallyWriteDirectory(dir) )
3826 // Hide stuff during export, if settings want this
3827 setExportMode (true);
3829 // Create subdirectories
3832 // write to directory
3833 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3836 file.setName ( dir + "/"+mapName+".xml");
3837 if ( !file.open( QIODevice::WriteOnly ) )
3839 // This should neverever happen
3840 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3844 // Write it finally, and write in UTF8, no matter what
3845 QTextStream ts( &file );
3846 ts.setEncoding (QTextStream::UnicodeUTF8);
3850 // Now write image, too
3851 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3853 setExportMode (false);
3856 void VymModel::exportASCII(QString fname,bool askName)
3861 ex.setFile (mapName+".txt");
3867 //ex.addFilter ("TXT (*.txt)");
3868 ex.setDir(lastImageDir);
3869 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3874 setExportMode(true);
3876 setExportMode(false);
3880 void VymModel::exportXHTML (const QString &dir, bool askForName)
3882 ExportXHTMLDialog dia(NULL);
3883 dia.setFilePath (filePath );
3884 dia.setMapName (mapName );
3886 if (dir!="") dia.setDir (dir);
3892 if (dia.exec()!=QDialog::Accepted)
3896 QDir d (dia.getDir());
3897 // Check, if warnings should be used before overwriting
3898 // the output directory
3899 if (d.exists() && d.count()>0)
3902 warn.showCancelButton (true);
3903 warn.setText(QString(
3904 "The directory %1 is not empty.\n"
3905 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3906 warn.setCaption("Warning: Directory not empty");
3907 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3909 if (warn.exec()!=QDialog::Accepted) ok=false;
3916 exportXML (dia.getDir(),false );
3917 dia.doExport(mapName );
3918 //if (dia.hasChanged()) setChanged();
3922 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3927 if (ex.setConfigFile(cf))
3929 setExportMode (true);
3930 ex.exportPresentation();
3931 setExportMode (false);
3938 //////////////////////////////////////////////
3940 //////////////////////////////////////////////
3942 void VymModel::registerEditor(QWidget *me)
3944 mapEditor=(MapEditor*)me;
3945 for (int i=0; i<mapCenters.count(); i++)
3946 mapCenters.at(i)->setMapEditor(mapEditor);
3949 void VymModel::unregisterEditor(QWidget *)
3954 void VymModel::setContextPos(QPointF p)
3959 void VymModel::unsetContextPos()
3961 contextPos=QPointF();
3964 void VymModel::updateNoteFlag()
3967 cout << "VM::updateNoteFlag()\n";
3968 /* FIXME-1 modify note flag
3969 BranchObj *bo=getSelectedBranch();
3972 bo->updateNoteFlag();
3973 mainWindow->updateActions();
3978 void VymModel::updateRelPositions()
3980 for (int i=0; i<mapCenters.count(); i++)
3981 mapCenters.at(i)->updateRelPositions();
3984 void VymModel::reposition() //FIXME-2 get rid of mapCenters...
3986 for (int i=0;i<mapCenters.count(); i++)
3987 mapCenters.at(i)->reposition(); // for positioning heading
3990 QPolygonF VymModel::shape(BranchObj *bo)
3992 // Creating (arbitrary) shapes
3995 QRectF rb=bo->getBBox();
3996 if (bo->getDepth()==0)
3998 // Just take BBox of this mapCenter
3999 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
4003 // Take union of BBox and TotalBBox
4005 QRectF ra=bo->getTotalBBox();
4006 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4009 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
4012 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
4014 p <<ra.bottomRight()
4016 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4019 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4024 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4028 // Move all branches and MapCenters away from lmo
4029 // to avoid collisions
4034 BranchObj *boA=(BranchObj*)lmo;
4036 for (int i=0; i<mapCenters.count(); i++)
4038 boB=mapCenters.at(i);
4041 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4045 <<" ("<<qPrintable(boA->getHeading() )<<")"
4046 <<" with ("<< qPrintable (boB->getHeading() )
4049 <<" minT="<<r.minTranslation<<endl<<endl;
4054 QPixmap VymModel::getPixmap()
4056 QRectF mapRect=getTotalBBox();
4057 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4060 pp.setRenderHints(mapEditor->renderHints());
4062 // Don't print the visualisation of selection
4063 selection.unselect();
4065 mapScene->render ( &pp,
4066 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4067 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4069 // Restore selection
4070 selection.reselect();
4076 void VymModel::setMapLinkStyle (const QString & s)
4081 case LinkableMapObj::Line :
4084 case LinkableMapObj::Parabel:
4085 snow="StyleParabel";
4087 case LinkableMapObj::PolyLine:
4088 snow="StylePolyLine";
4090 case LinkableMapObj::PolyParabel:
4091 snow="StylePolyParabel";
4094 snow="UndefinedStyle";
4099 QString("setMapLinkStyle (\"%1\")").arg(s),
4100 QString("setMapLinkStyle (\"%1\")").arg(snow),
4101 QString("Set map link style (\"%1\")").arg(s)
4105 linkstyle=LinkableMapObj::Line;
4106 else if (s=="StyleParabel")
4107 linkstyle=LinkableMapObj::Parabel;
4108 else if (s=="StylePolyLine")
4109 linkstyle=LinkableMapObj::PolyLine;
4110 else if (s=="StylePolyParabel")
4111 linkstyle=LinkableMapObj::PolyParabel;
4113 linkstyle=LinkableMapObj::UndefinedStyle;
4115 BranchItem *cur=NULL;
4116 BranchItem *prev=NULL;
4122 bo=(BranchObj*)(cur->getLMO() );
4123 bo->setLinkStyle(bo->getDefLinkStyle());
4124 cur=next(cur,prev,d);
4129 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4134 void VymModel::setMapDefLinkColor(QColor col)
4136 if ( !col.isValid() ) return;
4138 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4139 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4140 QString("Set map link color to %1").arg(col.name())
4144 BranchItem *cur=NULL;
4145 BranchItem *prev=NULL;
4148 cur=next(cur,prev,d);
4151 bo=(BranchObj*)(cur->getLMO() );
4158 void VymModel::setMapLinkColorHintInt()
4160 // called from setMapLinkColorHint(lch) or at end of parse
4161 BranchItem *cur=NULL;
4162 BranchItem *prev=NULL;
4165 cur=next(cur,prev,d);
4168 bo=(BranchObj*)(cur->getLMO() );
4170 cur=next(cur,prev,d);
4174 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4177 setMapLinkColorHintInt();
4180 void VymModel::toggleMapLinkColorHint()
4182 if (linkcolorhint==LinkableMapObj::HeadingColor)
4183 linkcolorhint=LinkableMapObj::DefaultColor;
4185 linkcolorhint=LinkableMapObj::HeadingColor;
4186 BranchItem *cur=NULL;
4187 BranchItem *prev=NULL;
4190 cur=next(cur,prev,d);
4193 bo=(BranchObj*)(cur->getLMO() );
4199 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4201 Q3FileDialog *fd=new Q3FileDialog( NULL);
4202 fd->setMode (Q3FileDialog::ExistingFile);
4203 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4204 ImagePreview *p =new ImagePreview (fd);
4205 fd->setContentsPreviewEnabled( TRUE );
4206 fd->setContentsPreview( p, p );
4207 fd->setPreviewMode( Q3FileDialog::Contents );
4208 fd->setCaption(vymName+" - " +tr("Load background image"));
4209 fd->setDir (lastImageDir);
4212 if ( fd->exec() == QDialog::Accepted )
4214 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4215 lastImageDir=QDir (fd->dirPath());
4216 setMapBackgroundImage (fd->selectedFile());
4220 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4222 QColor oldcol=mapScene->backgroundBrush().color();
4226 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4228 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4229 QString("Set background color of map to %1").arg(col.name()));
4232 brush.setTextureImage (QPixmap (fn));
4233 mapScene->setBackgroundBrush(brush);
4236 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4238 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4239 if ( !col.isValid() ) return;
4240 setMapBackgroundColor( col );
4244 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4246 QColor oldcol=mapScene->backgroundBrush().color();
4248 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4249 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4250 QString("Set background color of map to %1").arg(col.name()));
4251 mapScene->setBackgroundBrush(col);
4254 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4256 return mapScene->backgroundBrush().color();
4260 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4262 return linkcolorhint;
4265 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4267 return defLinkColor;
4270 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4275 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4277 return defXLinkColor;
4280 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4285 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4287 return defXLinkWidth;
4290 void VymModel::move(const double &x, const double &y) // FIXME-3
4294 BranchObj *bo = getSelectedBranch();
4296 (selectionType()==TreeItem::Branch ||
4297 selectionType()==TreeItem::MapCenter ||
4298 selectionType()==TreeItem::Image
4301 QPointF ap(bo->getAbsPos());
4305 QString ps=qpointfToString(ap);
4306 QString s=getSelectString();
4309 s, "move "+qpointfToString(to),
4310 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4319 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4323 BranchObj *bo = getSelectedBranch();
4325 (selectionType()==TreeItem::Branch ||
4326 selectionType()==TreeItem::MapCenter ||
4327 selectionType()==TreeItem::Image
4331 QPointF rp(bo->getRelPos());
4335 QString ps=qpointfToString (bo->getRelPos());
4336 QString s=getSelectString(bo);
4339 s, "moveRel "+qpointfToString(to),
4340 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4341 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4351 void VymModel::animate()
4353 animationTimer->stop();
4356 while (i<animObjList.size() )
4358 bo=(BranchObj*)animObjList.at(i);
4363 animObjList.removeAt(i);
4370 QItemSelection sel=selModel->selection();
4371 emit (selectionChanged(sel,sel));
4374 if (!animObjList.isEmpty()) animationTimer->start();
4378 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4380 if (bo && bo->getDepth()>0)
4383 ap.setStart (start);
4385 ap.setTicks (animationTicks);
4386 ap.setAnimated (true);
4387 bo->setAnimation (ap);
4388 animObjList.append( bo );
4389 animationTimer->setSingleShot (true);
4390 animationTimer->start(animationInterval);
4394 void VymModel::stopAnimation (MapObj *mo)
4396 int i=animObjList.indexOf(mo);
4398 animObjList.removeAt (i);
4401 void VymModel::sendSelection()
4403 if (netstate!=Server) return;
4404 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4407 void VymModel::newServer()
4411 tcpServer = new QTcpServer(this);
4412 if (!tcpServer->listen(QHostAddress::Any,port)) {
4413 QMessageBox::critical(NULL, "vym server",
4414 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4415 //FIXME-3 needed? we are no widget any longer... close();
4418 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4420 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4423 void VymModel::connectToServer()
4426 server="salam.suse.de";
4428 clientSocket = new QTcpSocket (this);
4429 clientSocket->abort();
4430 clientSocket->connectToHost(server ,port);
4431 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4432 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4433 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4435 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4440 void VymModel::newClient()
4442 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4443 connect(newClient, SIGNAL(disconnected()),
4444 newClient, SLOT(deleteLater()));
4446 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4448 clientList.append (newClient);
4452 void VymModel::sendData(const QString &s)
4454 if (clientList.size()==0) return;
4456 // Create bytearray to send
4458 QDataStream out(&block, QIODevice::WriteOnly);
4459 out.setVersion(QDataStream::Qt_4_0);
4461 // Reserve some space for blocksize
4464 // Write sendCounter
4465 out << sendCounter++;
4470 // Go back and write blocksize so far
4471 out.device()->seek(0);
4472 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4476 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4478 for (int i=0; i<clientList.size(); ++i)
4480 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4481 clientList.at(i)->write (block);
4485 void VymModel::readData ()
4487 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4490 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4494 QDataStream in(clientSocket);
4495 in.setVersion(QDataStream::Qt_4_0);
4503 cout << " t="<<qPrintable (t)<<endl;
4509 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4511 switch (socketError) {
4512 case QAbstractSocket::RemoteHostClosedError:
4514 case QAbstractSocket::HostNotFoundError:
4515 QMessageBox::information(NULL, vymName +" Network client",
4516 "The host was not found. Please check the "
4517 "host name and port settings.");
4519 case QAbstractSocket::ConnectionRefusedError:
4520 QMessageBox::information(NULL, vymName + " Network client",
4521 "The connection was refused by the peer. "
4522 "Make sure the fortune server is running, "
4523 "and check that the host name and port "
4524 "settings are correct.");
4527 QMessageBox::information(NULL, vymName + " Network client",
4528 QString("The following error occurred: %1.")
4529 .arg(clientSocket->errorString()));
4536 void VymModel::selectMapSelectionColor()
4538 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4539 setSelectionColor (col);
4542 void VymModel::setSelectionColorInt (QColor col)
4544 if ( !col.isValid() ) return;
4546 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4547 QString("setSelectionColor (%1)").arg(col.name()),
4548 QString("Set color of selection box to %1").arg(col.name())
4551 mapEditor->setSelectionColor (col);
4555 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4557 cout << "VymModel::changeSelection (";
4558 if (!newsel.indexes().isEmpty() )
4559 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4561 if (!oldsel.indexes().isEmpty() )
4562 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4567 void VymModel::updateSelection(const QItemSelection &newsel)
4569 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4570 ensureSelectionVisible();
4574 void VymModel::updateSelection()
4576 QItemSelection newsel=selModel->selection();
4577 updateSelection (newsel);
4580 void VymModel::setSelectionColor(QColor col)
4582 if ( !col.isValid() ) return;
4584 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4585 QString("setSelectionColor (%1)").arg(col.name()),
4586 QString("Set color of selection box to %1").arg(col.name())
4588 setSelectionColorInt (col);
4591 QColor VymModel::getSelectionColor()
4593 return mapEditor->getSelectionColor();
4596 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4599 for (int i=0;i<rootItem->childCount();i++)
4600 rootItem->child(i)->setHideTmp (mode);
4602 // FIXME-3 needed? scene()->update();
4606 QRectF VymModel::getTotalBBox()
4609 for (int i=0;i<mapCenters.count(); i++)
4610 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4614 //////////////////////////////////////////////
4615 // Selection related
4616 //////////////////////////////////////////////
4618 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4623 QItemSelectionModel* VymModel::getSelectionModel()
4628 void VymModel::setSelectionBlocked (bool b)
4633 selection.unblock();
4636 bool VymModel::isSelectionBlocked()
4638 return selection.isBlocked();
4641 bool VymModel::select ()
4643 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4645 TreeItem *item = getItem (index);
4646 return select (item->getLMO() );
4649 bool VymModel::select (const QString &s)
4651 LinkableMapObj *lmo=findObjBySelect(s);
4653 // Finally select the found object
4663 bool VymModel::select (LinkableMapObj *lmo)
4665 QItemSelection oldsel=selModel->selection();
4668 return select (lmo->getTreeItem() );
4673 bool VymModel::select (TreeItem *ti)
4677 QModelIndex ix=index(ti);
4678 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4679 ti->setLastSelectedBranch();
4680 //updateSelection(oldsel); //FIXME-3 needed?
4686 void VymModel::unselect()
4688 selModel->clearSelection();
4691 void VymModel::reselect()
4693 selection.reselect();
4696 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4698 LinkableMapObj *lmo=getSelectedLMO();
4699 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4702 void VymModel::emitNoteHasChanged (TreeItem *ti)
4704 QModelIndex ix=index(ti);
4705 emit (noteHasChanged (ix) );
4708 void VymModel::emitDataHasChanged (TreeItem *ti)
4710 QModelIndex ix=index(ti);
4711 emit (dataHasChanged (ix) );
4715 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4718 if (selection.select(lmo))
4720 //selection.update();
4721 sendSelection (); // FIXME-4 VM use signal
4725 void VymModel::selectInt (TreeItem *ti)
4727 if (selection.select(lmo))
4729 //selection.update();
4730 sendSelection (); // FIXME-4 VM use signal
4735 void VymModel::selectNextBranchInt()
4737 // Increase number of branch
4738 BranchItem *selbi=getSelectedBranchItem();
4741 QString s=getSelectString();
4747 part=s.section(",",-1);
4749 num=part.right(part.length() - 3);
4751 s=s.left (s.length() -num.length());
4754 num=QString ("%1").arg(num.toUInt()+1);
4758 // Try to select this one
4759 if (select (s)) return;
4761 // We have no direct successor,
4762 // try to increase the parental number in order to
4763 // find a successor with same depth
4765 int d=getSelectedBranchItem()->depth();
4770 while (!found && d>0)
4772 s=s.section (",",0,d-1);
4773 // replace substring of current depth in s with "1"
4774 part=s.section(",",-1);
4776 num=part.right(part.length() - 3);
4780 // increase number of parent
4781 num=QString ("%1").arg(num.toUInt()+1);
4782 s=s.section (",",0,d-2) + ","+ typ+num;
4785 // Special case, look at orientation
4786 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) // FIXME-3 check access to LMO
4787 num=QString ("%1").arg(num.toUInt()+1);
4789 num=QString ("%1").arg(num.toUInt()-1);
4794 // pad to oldDepth, select the first branch for each depth
4795 for (i=d;i<oldDepth;i++)
4800 if ( getSelectedItem()->branchCount()>0)
4808 // try to select the freshly built string
4816 void VymModel::selectPrevBranchInt()
4818 // Decrease number of branch
4819 if (selectionType()==TreeItem::Branch)
4821 QString s=getSelectString();
4827 part=s.section(",",-1);
4829 num=part.right(part.length() - 3);
4831 s=s.left (s.length() -num.length());
4833 int n=num.toInt()-1;
4836 num=QString ("%1").arg(n);
4839 // Try to select this one
4840 if (n>=0 && select (s)) return;
4842 // We have no direct precessor,
4843 // try to decrease the parental number in order to
4844 // find a precessor with same depth
4846 int d=getSelectedBranchItem()->depth();
4851 while (!found && d>0)
4853 s=s.section (",",0,d-1);
4854 // replace substring of current depth in s with "1"
4855 part=s.section(",",-1);
4857 num=part.right(part.length() - 3);
4861 // decrease number of parent
4862 num=QString ("%1").arg(num.toInt()-1);
4863 s=s.section (",",0,d-2) + ","+ typ+num;
4866 // Special case, look at orientation
4867 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) // FIXME-3 check access to LMO
4868 num=QString ("%1").arg(num.toInt()-1);
4870 num=QString ("%1").arg(num.toInt()+1);
4875 // pad to oldDepth, select the last branch for each depth
4876 for (i=d;i<oldDepth;i++)
4880 if ( getSelectedItem()->branchCount()>0)
4881 s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 );
4888 // try to select the freshly built string
4896 void VymModel::selectUpperBranch()
4898 if (selection.isBlocked() ) return;
4900 BranchItem *bi=getSelectedBranchItem();
4901 if (bi && bi->getType()==TreeItem::Branch)
4903 if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4904 selectPrevBranchInt();
4907 selectNextBranchInt();
4909 selectPrevBranchInt();
4913 void VymModel::selectLowerBranch()
4915 if (selection.isBlocked() ) return;
4917 BranchItem *bi=getSelectedBranchItem();
4918 if (bi && bi->getType()==TreeItem::Branch)
4920 if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4921 selectNextBranchInt();
4924 selectPrevBranchInt();
4926 selectNextBranchInt();
4931 void VymModel::selectLeftBranch()
4933 if (selection.isBlocked() ) return;
4935 QItemSelection oldsel=selModel->selection();
4938 BranchItem *selbi=getSelectedBranchItem();
4939 TreeItem::Type type=selbi->getType();
4942 if (type == TreeItem::MapCenter)
4944 QModelIndex ix=index(selbi);
4945 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4948 par=(BranchItem*)selbi->parent();
4949 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4952 if (type == TreeItem::Branch ||
4953 type == TreeItem::Image)
4955 QModelIndex ix=index (selbi->parent());
4956 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4961 if (type == TreeItem::Branch )
4963 selectLastSelectedBranch();
4968 updateSelection (oldsel);
4972 void VymModel::selectRightBranch()
4974 if (selection.isBlocked() ) return;
4976 QItemSelection oldsel=selModel->selection();
4979 BranchItem *selbi=getSelectedBranchItem();
4980 TreeItem::Type type=selbi->getType();
4983 if (type==TreeItem::MapCenter)
4985 QModelIndex ix=index(selbi);
4986 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4989 par=(BranchItem*)selbi->parent();
4990 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4993 if ( type== TreeItem::Branch )
4995 selectLastSelectedBranch();
5001 if (type == TreeItem::Branch ||
5002 type == TreeItem::Image)
5004 QModelIndex ix=index(selbi->parent());
5005 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
5009 updateSelection (oldsel);
5013 void VymModel::selectFirstBranch()
5015 TreeItem *ti=getSelectedBranchItem();
5018 TreeItem *par=ti->parent();
5020 TreeItem *ti2=par->getFirstBranch();
5024 ensureSelectionVisible();
5030 void VymModel::selectLastBranch()
5032 TreeItem *ti=getSelectedBranchItem();
5035 TreeItem *par=ti->parent();
5037 TreeItem *ti2=par->getLastBranch();
5041 ensureSelectionVisible();
5047 void VymModel::selectLastSelectedBranch()
5049 TreeItem *ti=getSelectedBranchItem();
5052 ti=ti->getLastSelectedBranch();
5053 if (ti) select (ti);
5057 void VymModel::selectParent()
5059 TreeItem *ti=getSelectedItem();
5067 ensureSelectionVisible();
5072 TreeItem::Type VymModel::selectionType()
5074 QModelIndexList list=selModel->selectedIndexes();
5075 if (list.isEmpty()) return TreeItem::Undefined;
5076 TreeItem *ti = getItem (list.first() );
5077 return ti->getType();
5081 LinkableMapObj* VymModel::getSelectedLMO()
5083 QModelIndexList list=selModel->selectedIndexes();
5084 if (!list.isEmpty() )
5086 TreeItem *ti = getItem (list.first() );
5087 TreeItem::Type type=ti->getType();
5088 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5090 return ti->getLMO();
5096 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5098 TreeItem *ti = getSelectedBranchItem();
5100 return (BranchObj*)ti->getLMO();
5105 BranchItem* VymModel::getSelectedBranchItem()
5107 QModelIndexList list=selModel->selectedIndexes();
5108 if (!list.isEmpty() )
5110 TreeItem *ti = getItem (list.first() );
5111 TreeItem::Type type=ti->getType();
5112 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5113 return (BranchItem*)ti;
5118 MapCenterItem* VymModel::getSelectedMapCenterItem()
5120 QModelIndexList list=selModel->selectedIndexes();
5121 if (!list.isEmpty() )
5123 TreeItem *ti = getItem (list.first() );
5124 TreeItem::Type type=ti->getType();
5125 if (ti->getType()==TreeItem::MapCenter)
5126 return (MapCenterItem*)ti;
5131 TreeItem* VymModel::getSelectedItem()
5133 QModelIndexList list=selModel->selectedIndexes();
5134 if (!list.isEmpty() )
5135 return getItem (list.first() );
5140 QModelIndex VymModel::getSelectedIndex()
5142 QModelIndexList list=selModel->selectedIndexes();
5143 if (list.isEmpty() )
5144 return QModelIndex();
5146 return list.first();
5149 FloatImageObj* VymModel::getSelectedFloatImage()
5151 return selection.getFloatImage();
5154 QString VymModel::getSelectString ()
5156 LinkableMapObj *lmo=getSelectedLMO();
5158 return getSelectString(lmo);
5163 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5165 if (!lmo) return QString();
5166 return getSelectString (lmo->getTreeItem() );
5169 QString VymModel::getSelectString (TreeItem *ti)
5173 if (ti->getType() == TreeItem::Branch ||
5174 ti->getType() == TreeItem::MapCenter)
5176 TreeItem *par=ti->parent();
5179 if (ti->depth() ==1)
5180 // Mainbranch, return
5181 s= "bo:" + QString("%1").arg(ti->num() );
5183 // Branch, call myself recursively
5184 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5188 int i=rootItem->num(ti);
5189 if (i>=0) s=QString("mc:%1").arg(i);