1 #include <QApplication>
7 #include "branchitem.h"
8 #include "mapcenteritem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
15 #include "mapcenterobj.h"
18 #include "selection.h"
21 #include "warningdialog.h"
22 #include "xml-freemind.h"
28 extern Main *mainWindow;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
34 extern QString clipboardDir;
35 extern QString clipboardFile;
36 extern bool clipboardEmpty;
38 extern ImageIO imageIO;
40 extern QString vymName;
41 extern QString vymVersion;
42 extern QDir vymBaseDir;
44 extern QDir lastImageDir;
45 extern QDir lastFileDir;
47 extern FlagRowObj *standardFlagsDefault;
49 extern Settings settings;
53 int VymModel::mapNum=0; // make instance
57 // cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 // cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
71 void VymModel::clear()
73 selModel->clearSelection();
75 //QModelIndex ri=index(rootItem);
76 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
79 void VymModel::init ()
81 // We should have at least one map center to start with
82 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
87 // Also no scene yet (should not be needed anyway) FIXME-3 VM
100 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
101 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
102 mainWindow->updateHistory (undoSet);
105 makeTmpDirectories();
110 fileName=tr("unnamed");
112 blockReposition=false;
113 blockSaveState=false;
115 autosaveTimer=new QTimer (this);
116 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
118 fileChangedTimer=new QTimer (this);
119 fileChangedTimer->start(3000);
120 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
132 animationUse=settings.readBoolEntry("/animation/use",false);
133 animationTicks=settings.readNumEntry("/animation/ticks",10);
134 animationInterval=settings.readNumEntry("/animation/interval",50);
136 animationTimer=new QTimer (this);
137 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
140 defLinkColor=QColor (0,0,255);
141 defXLinkColor=QColor (180,180,180);
142 linkcolorhint=LinkableMapObj::DefaultColor;
143 linkstyle=LinkableMapObj::PolyParabel;
145 defXLinkColor=QColor (230,230,230);
147 hidemode=TreeItem::HideNone;
153 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
157 void VymModel::makeTmpDirectories()
159 // Create unique temporary directories
160 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
161 histPath = tmpMapDir+"/history";
167 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
172 bool VymModel::isRepositionBlocked()
174 return blockReposition;
177 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
179 cout << "VymModel::updateActions \n";
180 // Tell mainwindow to update states of actions
181 mainWindow->updateActions();
186 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
188 // tmpdir temporary directory to which data will be written
189 // prefix mapname, which will be appended to images etc.
190 // writeflags Only write flags for "real" save of map, not undo
191 // offset offset of bbox of whole map in scene.
192 // Needed for XML export
201 case LinkableMapObj::Line:
204 case LinkableMapObj::Parabel:
207 case LinkableMapObj::PolyLine:
211 ls="StylePolyParabel";
215 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
217 if (linkcolorhint==LinkableMapObj::HeadingColor)
218 colhint=xml.attribut("linkColorHint","HeadingColor");
220 QString mapAttr=xml.attribut("version",vymVersion);
222 mapAttr+= xml.attribut("author",author) +
223 xml.attribut("comment",comment) +
224 xml.attribut("date",getDate()) +
225 xml.attribut("branchCount", QString().number(branchCount())) +
226 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
227 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
228 xml.attribut("linkStyle", ls ) +
229 xml.attribut("linkColor", defLinkColor.name() ) +
230 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
231 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
233 s+=xml.beginElement("vymmap",mapAttr);
236 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
237 standardFlagsDefault->resetUsedCounter();
239 // Reset the counters before saving
240 // TODO constr. of FIO creates lots of objects, better do this in some other way...
241 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
243 // Build xml recursivly
244 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
245 // Save all mapcenters as complete map, if saveSel not set
246 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
249 if ( typeid(*saveSel) == typeid(BranchObj) )
251 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
252 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
254 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
257 // Save local settings
258 s+=settings.getDataXML (destPath);
261 if (!selection.isEmpty() && !saveSel )
262 s+=xml.valueElement("select",selection.getSelectString());
265 s+=xml.endElement("vymmap");
268 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
272 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
276 for (int i=0; i<rootItem->branchCount(); i++) // FIXME-0 remove mapCenters
277 s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
281 void VymModel::setFilePath(QString fpath, QString destname)
283 if (fpath.isEmpty() || fpath=="")
290 filePath=fpath; // becomes absolute path
291 fileName=fpath; // gets stripped of path
292 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
294 // If fpath is not an absolute path, complete it
295 filePath=QDir(fpath).absPath();
296 fileDir=filePath.left (1+filePath.findRev ("/"));
298 // Set short name, too. Search from behind:
299 int i=fileName.findRev("/");
300 if (i>=0) fileName=fileName.remove (0,i+1);
302 // Forget the .vym (or .xml) for name of map
303 mapName=fileName.left(fileName.findRev(".",-1,true) );
307 void VymModel::setFilePath(QString fpath)
309 setFilePath (fpath,fpath);
312 QString VymModel::getFilePath()
317 QString VymModel::getFileName()
322 QString VymModel::getMapName()
327 QString VymModel::getDestPath()
332 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
334 ErrorCode err=success;
336 parseBaseHandler *handler;
340 case VymMap: handler=new parseVYMHandler; break;
341 case FreemindMap : handler=new parseFreemindHandler; break;
343 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
344 "Unknown FileType in VymModel::load()");
348 bool zipped_org=zipped;
352 selModel->clearSelection();
353 // FIXME-2 VM not needed??? model->setMapEditor(this);
354 // (map state is set later at end of load...)
357 BranchItem *bi=getSelectedBranchItem();
358 if (!bi) return aborted;
359 if (lmode==ImportAdd)
360 saveStateChangingPart(
363 QString("addMapInsert (%1)").arg(fname),
364 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
366 saveStateChangingPart(
369 QString("addMapReplace(%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
374 // Create temporary directory for packing
376 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
379 QMessageBox::critical( 0, tr( "Critical Load Error" ),
380 tr("Couldn't create temporary directory before load\n"));
385 err=unzipDir (tmpZipDir,fname);
395 // Look for mapname.xml
396 xmlfile= fname.left(fname.findRev(".",-1,true));
397 xmlfile=xmlfile.section( '/', -1 );
398 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
399 if (!mfile.exists() )
401 // mapname.xml does not exist, well,
402 // maybe someone renamed the mapname.vym file...
403 // Try to find any .xml in the toplevel
404 // directory of the .vym file
405 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
406 if (flist.count()==1)
408 // Only one entry, take this one
409 xmlfile=tmpZipDir + "/"+flist.first();
412 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
413 *it=tmpZipDir + "/" + *it;
414 // TODO Multiple entries, load all (but only the first one into this ME)
415 //mainWindow->fileLoadFromTmp (flist);
416 //returnCode=1; // Silently forget this attempt to load
417 qWarning ("MainWindow::load (fn) multimap found...");
420 if (flist.isEmpty() )
422 QMessageBox::critical( 0, tr( "Critical Load Error" ),
423 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
426 } //file doesn't exist
428 xmlfile=mfile.name();
431 QFile file( xmlfile);
433 // I am paranoid: file should exist anyway
434 // according to check in mainwindow.
437 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
438 tr(QString("Couldn't open map %1").arg(file.name())));
442 bool blockSaveStateOrg=blockSaveState;
443 blockReposition=true;
445 QXmlInputSource source( file);
446 QXmlSimpleReader reader;
447 reader.setContentHandler( handler );
448 reader.setErrorHandler( handler );
449 handler->setModel ( this);
452 // We need to set the tmpDir in order to load files with rel. path
457 tmpdir=fname.left(fname.findRev("/",-1));
458 handler->setTmpDir (tmpdir);
459 handler->setInputFile (file.name());
460 handler->setLoadMode (lmode);
461 bool ok = reader.parse( source );
462 blockReposition=false;
463 blockSaveState=blockSaveStateOrg;
467 reposition(); // FIXME-2 VM reposition the view instead...
474 autosaveTimer->stop();
477 // Reset timestamp to check for later updates of file
478 fileChangedTime=QFileInfo (destPath).lastModified();
481 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
482 tr( handler->errorProtocol() ) );
484 // Still return "success": the map maybe at least
485 // partially read by the parser
490 removeDir (QDir(tmpZipDir));
492 // Restore original zip state
499 ErrorCode VymModel::save (const SaveMode &savemode)
503 QString safeFilePath;
505 ErrorCode err=success;
509 mapFileName=mapName+".xml";
511 // use name given by user, even if he chooses .doc
512 mapFileName=fileName;
514 // Look, if we should zip the data:
517 QMessageBox mb( vymName,
518 tr("The map %1\ndid not use the compressed "
519 "vym file format.\nWriting it uncompressed will also write images \n"
520 "and flags and thus may overwrite files in the "
521 "given directory\n\nDo you want to write the map").arg(filePath),
522 QMessageBox::Warning,
523 QMessageBox::Yes | QMessageBox::Default,
525 QMessageBox::Cancel | QMessageBox::Escape);
526 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
527 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
528 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
531 case QMessageBox::Yes:
532 // save compressed (default file format)
535 case QMessageBox::No:
539 case QMessageBox::Cancel:
546 // First backup existing file, we
547 // don't want to add to old zip archives
551 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
553 QString backupFileName(destPath + "~");
554 QFile backupFile(backupFileName);
555 if (backupFile.exists() && !backupFile.remove())
557 QMessageBox::warning(0, tr("Save Error"),
558 tr("%1\ncould not be removed before saving").arg(backupFileName));
560 else if (!f.rename(backupFileName))
562 QMessageBox::warning(0, tr("Save Error"),
563 tr("%1\ncould not be renamed before saving").arg(destPath));
570 // Create temporary directory for packing
572 tmpZipDir=makeTmpDir (ok,"vym-zip");
575 QMessageBox::critical( 0, tr( "Critical Load Error" ),
576 tr("Couldn't create temporary directory before save\n"));
580 safeFilePath=filePath;
581 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
584 // Create mapName and fileDir
585 makeSubDirs (fileDir);
588 if (savemode==CompleteMap || selection.isEmpty())
591 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
594 autosaveTimer->stop();
599 if (selectionType()==TreeItem::Image)
602 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
603 // TODO take care of multiselections
606 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
609 qWarning ("ME::saveStringToDisk failed!");
615 if (err==success) err=zipDir (tmpZipDir,destPath);
618 removeDir (QDir(tmpZipDir));
620 // Restore original filepath outside of tmp zip dir
621 setFilePath (safeFilePath);
625 fileChangedTime=QFileInfo (destPath).lastModified();
629 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
631 QString pathDir=path.left(path.findRev("/"));
637 // We need to parse saved XML data
638 parseVYMHandler handler;
639 QXmlInputSource source( file);
640 QXmlSimpleReader reader;
641 reader.setContentHandler( &handler );
642 reader.setErrorHandler( &handler );
643 handler.setModel ( this);
644 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
645 if (undoSel.isEmpty())
649 handler.setLoadMode (NewMap);
653 handler.setLoadMode (ImportReplace);
655 blockReposition=true;
656 bool ok = reader.parse( source );
657 blockReposition=false;
660 // This should never ever happen
661 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
662 handler.errorProtocol());
665 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
668 void VymModel::addMapInsertInt (const QString &path, int pos)
670 /* FIXME-2 addMapInsertInt not ported yet
671 BranchObj *sel=getSelectedBranch();
674 QString pathDir=path.left(path.findRev("/"));
680 // We need to parse saved XML data
681 parseVYMHandler handler;
682 QXmlInputSource source( file);
683 QXmlSimpleReader reader;
684 reader.setContentHandler( &handler );
685 reader.setErrorHandler( &handler );
686 handler.setModel (this);
687 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
688 handler.setLoadMode (ImportAdd);
689 blockReposition=true;
690 bool ok = reader.parse( source );
691 blockReposition=false;
694 // This should never ever happen
695 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
696 handler.errorProtocol());
698 if (sel->getDepth()>0)
699 sel->getLastBranch()->linkTo (sel,pos);
701 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
706 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
708 TreeItem *fi=createImage();
711 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
719 void VymModel::loadFloatImage () // FIXME-2
722 BranchObj *bo=getSelectedBranch();
726 Q3FileDialog *fd=new Q3FileDialog( NULL);
727 fd->setMode (Q3FileDialog::ExistingFiles);
728 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
729 ImagePreview *p =new ImagePreview (fd);
730 fd->setContentsPreviewEnabled( TRUE );
731 fd->setContentsPreview( p, p );
732 fd->setPreviewMode( Q3FileDialog::Contents );
733 fd->setCaption(vymName+" - " +tr("Load image"));
734 fd->setDir (lastImageDir);
737 if ( fd->exec() == QDialog::Accepted )
739 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
740 lastImageDir=QDir (fd->dirPath());
743 for (int j=0; j<fd->selectedFiles().count(); j++)
745 s=fd->selectedFiles().at(j);
746 fio=loadFloatImageInt (s);
749 (LinkableMapObj*)fio,
752 QString ("loadImage (%1)").arg(s ),
753 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
756 // TODO loadFIO error handling
757 qWarning ("Failed to load "+s);
766 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
771 void VymModel::saveFloatImage ()
773 FloatImageObj *fio=selection.getFloatImage();
776 QFileDialog *fd=new QFileDialog( NULL);
777 fd->setFilters (imageIO.getFilters());
778 fd->setCaption(vymName+" - " +tr("Save image"));
779 fd->setFileMode( QFileDialog::AnyFile );
780 fd->setDirectory (lastImageDir);
781 // fd->setSelection (fio->getOriginalFilename());
785 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
787 fn=fd->selectedFiles().at(0);
788 if (QFile (fn).exists() )
790 QMessageBox mb( vymName,
791 tr("The file %1 exists already.\n"
792 "Do you want to overwrite it?").arg(fn),
793 QMessageBox::Warning,
794 QMessageBox::Yes | QMessageBox::Default,
795 QMessageBox::Cancel | QMessageBox::Escape,
796 QMessageBox::NoButton );
798 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
799 mb.setButtonText( QMessageBox::No, tr("Cancel"));
802 case QMessageBox::Yes:
805 case QMessageBox::Cancel:
812 saveFloatImageInt (fio,fd->selectedFilter(),fn );
819 void VymModel::importDirInt(BranchObj *dst, QDir d)
821 /* FIXME-2 importDirInt not ported yet
822 BranchObj *bo=getSelectedBranch();
825 // Traverse directories
826 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
827 QFileInfoList list = d.entryInfoList();
830 for (int i = 0; i < list.size(); ++i)
833 if (fi.fileName() != "." && fi.fileName() != ".." )
836 bo=dst->getLastBranch();
837 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
838 bi->setHeading (fi.fileName() ); // FIXME-3 check this
839 bo->setColor (QColor("blue"));
841 if ( !d.cd(fi.fileName()) )
842 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
845 // Recursively add subdirs
852 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
853 list = d.entryInfoList();
855 for (int i = 0; i < list.size(); ++i)
859 bo=dst->getLastBranch();
860 bo->setHeading (fi.fileName() );
861 bo->setColor (QColor("black"));
862 if (fi.fileName().right(4) == ".vym" )
863 bo->setVymLink (fi.filePath());
869 void VymModel::importDirInt (const QString &s) // FIXME-2
872 BranchObj *bo=getSelectedBranch();
875 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
883 void VymModel::importDir() //FIXME-2
886 BranchObj *bo=getSelectedBranch();
890 filters <<"VYM map (*.vym)";
891 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
892 fd->setMode (QFileDialog::DirectoryOnly);
893 fd->setFilters (filters);
894 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
898 if ( fd->exec() == QDialog::Accepted )
900 importDirInt (fd->selectedFile() );
902 //FIXME-3 VM needed? scene()->update();
909 void VymModel::autosave()
914 cout << "VymModel::autosave rejected due to missing filePath\n";
917 QDateTime now=QDateTime().currentDateTime();
919 // Disable autosave, while we have gone back in history
920 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
921 if (redosAvail>0) return;
923 // Also disable autosave for new map without filename
924 if (filePath.isEmpty()) return;
927 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
929 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
930 mainWindow->fileSave (this);
933 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
938 void VymModel::fileChanged()
940 // Check if file on disk has changed meanwhile
941 if (!filePath.isEmpty())
943 QDateTime tmod=QFileInfo (filePath).lastModified();
944 if (tmod>fileChangedTime)
946 // FIXME-2 VM switch to current mapeditor and finish lineedits...
947 QMessageBox mb( vymName,
948 tr("The file of the map on disk has changed:\n\n"
949 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
950 QMessageBox::Question,
952 QMessageBox::Cancel | QMessageBox::Default,
953 QMessageBox::NoButton );
955 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
956 mb.setButtonText( QMessageBox::No, tr("Ignore"));
959 case QMessageBox::Yes:
961 load (filePath,NewMap,fileType);
962 case QMessageBox::Cancel:
963 fileChangedTime=tmod; // allow autosave to overwrite newer file!
969 bool VymModel::isDefault()
974 void VymModel::makeDefault()
980 bool VymModel::hasChanged()
985 void VymModel::setChanged()
987 cout << "VM::setChanged()\n";
990 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
991 cout <<" timer started with "<<settings.value("/mainwindow/autosave/ms/",300000).toInt()<<endl;
999 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1002 if (!lmo) return QString("Error: NULL has no name!");
1004 if ((typeid(*lmo) == typeid(BranchObj) ||
1005 typeid(*lmo) == typeid(MapCenterObj)))
1008 s=lmo->getTreeItem()->getHeading();
1009 if (s=="") s="unnamed";
1010 return QString("branch (%1)").arg(s);
1012 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1013 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1014 return QString("Unknown type has no name!");
1018 QString VymModel::getObjectName (const TreeItem *ti)
1021 if (!ti) return QString("Error: NULL has no name!");
1023 if (ti->isBranchLikeType() )
1026 if (s=="") s="unnamed";
1027 return QString("branch (%1)").arg(s);
1029 /* FIXME-2 move floatimage to TreeModel first
1030 if (type==TreeItem::Image)
1031 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1033 return QString("Unknown type has no name!");
1036 void VymModel::redo()
1038 // Can we undo at all?
1039 if (redosAvail<1) return;
1041 bool blockSaveStateOrg=blockSaveState;
1042 blockSaveState=true;
1046 if (undosAvail<stepsTotal) undosAvail++;
1048 if (curStep>stepsTotal) curStep=1;
1049 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1050 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1051 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1052 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1053 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1054 QString version=undoSet.readEntry ("/history/version");
1056 /* TODO Maybe check for version, if we save the history
1057 if (!checkVersion(version))
1058 QMessageBox::warning(0,tr("Warning"),
1059 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1062 // Find out current undo directory
1063 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1067 cout << "VymModel::redo() begin\n";
1068 cout << " undosAvail="<<undosAvail<<endl;
1069 cout << " redosAvail="<<redosAvail<<endl;
1070 cout << " curStep="<<curStep<<endl;
1071 cout << " ---------------------------"<<endl;
1072 cout << " comment="<<comment.toStdString()<<endl;
1073 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1074 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1075 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1076 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1077 cout << " ---------------------------"<<endl<<endl;
1080 // select object before redo
1081 if (!redoSelection.isEmpty())
1082 select (redoSelection);
1085 parseAtom (redoCommand);
1088 blockSaveState=blockSaveStateOrg;
1090 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1091 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1092 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1093 undoSet.writeSettings(histPath);
1095 mainWindow->updateHistory (undoSet);
1098 /* TODO remove testing
1099 cout << "ME::redo() end\n";
1100 cout << " undosAvail="<<undosAvail<<endl;
1101 cout << " redosAvail="<<redosAvail<<endl;
1102 cout << " curStep="<<curStep<<endl;
1103 cout << " ---------------------------"<<endl<<endl;
1109 bool VymModel::isRedoAvailable()
1111 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1117 void VymModel::undo()
1119 // Can we undo at all?
1120 if (undosAvail<1) return;
1122 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1124 bool blockSaveStateOrg=blockSaveState;
1125 blockSaveState=true;
1127 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1128 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1129 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1130 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1131 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1132 QString version=undoSet.readEntry ("/history/version");
1134 /* TODO Maybe check for version, if we save the history
1135 if (!checkVersion(version))
1136 QMessageBox::warning(0,tr("Warning"),
1137 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1140 // Find out current undo directory
1141 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1143 // select object before undo
1144 if (!undoSelection.isEmpty())
1145 select (undoSelection);
1149 cout << "VymModel::undo() begin\n";
1150 cout << " undosAvail="<<undosAvail<<endl;
1151 cout << " redosAvail="<<redosAvail<<endl;
1152 cout << " curStep="<<curStep<<endl;
1153 cout << " ---------------------------"<<endl;
1154 cout << " comment="<<comment.toStdString()<<endl;
1155 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1156 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1157 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1158 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1159 cout << " ---------------------------"<<endl<<endl;
1161 parseAtom (undoCommand);
1166 if (curStep<1) curStep=stepsTotal;
1170 blockSaveState=blockSaveStateOrg;
1171 /* TODO remove testing
1172 cout << "VymModel::undo() end\n";
1173 cout << " undosAvail="<<undosAvail<<endl;
1174 cout << " redosAvail="<<redosAvail<<endl;
1175 cout << " curStep="<<curStep<<endl;
1176 cout << " ---------------------------"<<endl<<endl;
1179 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1180 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1181 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1182 undoSet.writeSettings(histPath);
1184 mainWindow->updateHistory (undoSet);
1187 ensureSelectionVisible();
1190 bool VymModel::isUndoAvailable()
1192 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1198 void VymModel::gotoHistoryStep (int i)
1200 // Restore variables
1201 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1202 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1204 if (i<0) i=undosAvail+redosAvail;
1206 // Clicking above current step makes us undo things
1209 for (int j=0; j<undosAvail-i; j++) undo();
1212 // Clicking below current step makes us redo things
1214 for (int j=undosAvail; j<i; j++)
1216 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1220 // And ignore clicking the current row ;-)
1224 QString VymModel::getHistoryPath()
1226 QString histName(QString("history-%1").arg(curStep));
1227 return (tmpMapDir+"/"+histName);
1230 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1232 sendData(redoCom); //FIXME-3 testing
1237 if (blockSaveState) return;
1239 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1241 // Find out current undo directory
1242 if (undosAvail<stepsTotal) undosAvail++;
1244 if (curStep>stepsTotal) curStep=1;
1246 QString backupXML="";
1247 QString histDir=getHistoryPath();
1248 QString bakMapPath=histDir+"/map.xml";
1250 // Create histDir if not available
1253 makeSubDirs (histDir);
1255 // Save depending on how much needs to be saved
1257 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1259 QString undoCommand="";
1260 if (savemode==UndoCommand)
1262 undoCommand=undoCom;
1264 else if (savemode==PartOfMap )
1266 undoCommand=undoCom;
1267 undoCommand.replace ("PATH",bakMapPath);
1270 if (!backupXML.isEmpty())
1271 // Write XML Data to disk
1272 saveStringToDisk (bakMapPath,backupXML);
1274 // We would have to save all actions in a tree, to keep track of
1275 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1278 // Write the current state to disk
1279 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1280 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1281 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1282 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1283 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1284 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1285 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1286 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1287 undoSet.setEntry (QString("/history/version"),vymVersion);
1288 undoSet.writeSettings(histPath);
1292 // TODO remove after testing
1293 //cout << " into="<< histPath.toStdString()<<endl;
1294 cout << " stepsTotal="<<stepsTotal<<
1295 ", undosAvail="<<undosAvail<<
1296 ", redosAvail="<<redosAvail<<
1297 ", curStep="<<curStep<<endl;
1298 cout << " ---------------------------"<<endl;
1299 cout << " comment="<<comment.toStdString()<<endl;
1300 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1301 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1302 cout << " redoCom="<<redoCom.toStdString()<<endl;
1303 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1304 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1305 cout << " ---------------------------"<<endl;
1308 mainWindow->updateHistory (undoSet);
1314 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1316 // save the selected part of the map, Undo will replace part of map
1317 QString undoSelection="";
1319 undoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1322 QString redoSelection="";
1324 redoSelection=getSelectString(undoSel);
1326 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1329 saveState (PartOfMap,
1330 undoSelection, "addMapReplace (\"PATH\")",
1336 void VymModel::saveStateRemovingPart(TreeItem*redoSel, const QString &comment)
1340 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1343 QString undoSelection=getSelectString (redoSel->parent() );
1344 QString redoSelection=getSelectString(redoSel);
1345 if (redoSel->getType()==TreeItem::Branch)
1347 // save the selected branch of the map, Undo will insert part of map
1348 saveState (PartOfMap,
1349 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1350 redoSelection, "delete ()",
1357 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1359 // "Normal" savestate: save commands, selections and comment
1360 // so just save commands for undo and redo
1361 // and use current selection
1363 QString redoSelection="";
1364 if (redoSel) redoSelection=getSelectString(redoSel);
1365 QString undoSelection="";
1366 if (undoSel) undoSelection=getSelectString(undoSel);
1368 saveState (UndoCommand,
1375 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1377 // "Normal" savestate: save commands, selections and comment
1378 // so just save commands for undo and redo
1379 // and use current selection
1380 saveState (UndoCommand,
1387 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1389 // "Normal" savestate applied to model (no selection needed):
1390 // save commands and comment
1391 saveState (UndoCommand,
1399 QGraphicsScene* VymModel::getScene ()
1404 TreeItem* VymModel::findBySelectString(const QString &s)
1411 part=s.section(",",0,0);
1413 num=part.right(part.length() - 3);
1414 if (typ=="mc" && num.toInt()>=0 && num.toInt() <rootItem->branchCount() )
1415 return rootItem->getBranchNum (num.toInt() );
1419 for (int i=0; i<rootItem->branchCount(); i++)
1421 ti=rootItem->getBranchNum(i)->findBySelectString(s);
1427 TreeItem* VymModel::findID (const QString &s)
1430 for (int i=0; i<rootItem->branchCount(); i++)
1432 ti=rootItem->getBranchNum(i)->findID (s);
1438 //////////////////////////////////////////////
1440 //////////////////////////////////////////////
1441 void VymModel::setVersion (const QString &s)
1446 void VymModel::setAuthor (const QString &s)
1449 QString ("setMapAuthor (\"%1\")").arg(author),
1450 QString ("setMapAuthor (\"%1\")").arg(s),
1451 QString ("Set author of map to \"%1\"").arg(s)
1456 QString VymModel::getAuthor()
1461 void VymModel::setComment (const QString &s)
1464 QString ("setMapComment (\"%1\")").arg(comment),
1465 QString ("setMapComment (\"%1\")").arg(s),
1466 QString ("Set comment of map")
1471 QString VymModel::getComment ()
1476 QString VymModel::getDate ()
1478 return QDate::currentDate().toString ("yyyy-MM-dd");
1481 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1484 BranchItem *cur=NULL;
1485 BranchItem *prev=NULL;
1496 void VymModel::setHeading(const QString &s)
1498 BranchItem *selbi=getSelectedBranchItem();
1503 "setHeading (\""+selbi->getHeading()+"\")",
1505 "setHeading (\""+s+"\")",
1506 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1507 selbi->setHeading(s );
1508 QModelIndex ix2=index (selbi);
1509 emit (dataChanged ( ix2,ix2));
1510 /* FIXME-3 testing only
1514 // selection.update(); //FIXME-4
1515 ensureSelectionVisible();
1519 BranchItem* VymModel::findText (QString s, bool cs)
1522 QTextDocument::FindFlags flags=0;
1523 if (cs) flags=QTextDocument::FindCaseSensitively;
1526 { // Nothing found or new find process
1528 // nothing found, start again
1532 next (findCurrent,findPrevious,d);
1534 bool searching=true;
1535 bool foundNote=false;
1536 while (searching && !EOFind)
1540 // Searching in Note
1541 if (findCurrent->getNote().contains(s,cs))
1543 select (findCurrent);
1545 if (getSelectedBranch()!=itFind)
1548 ensureSelectionVisible();
1551 if (textEditor->findText(s,flags))
1557 // Searching in Heading
1558 if (searching && findCurrent->getHeading().contains (s,cs) )
1560 select(findCurrent);
1566 if (!next(findCurrent,findPrevious,d) )
1569 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1572 return getSelectedBranchItem();
1577 void VymModel::findReset()
1578 { // Necessary if text to find changes during a find process
1584 void VymModel::setScene (QGraphicsScene *s)
1586 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1587 //init(); // Here we have a mapScene set,
1588 // which is (still) needed to create MapCenters
1591 void VymModel::setURL(const QString &url) //FIXME-2
1594 BranchObj *bo=getSelectedBranch();
1597 QString oldurl=bo->getURL();
1601 QString ("setURL (\"%1\")").arg(oldurl),
1603 QString ("setURL (\"%1\")").arg(url),
1604 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1609 ensureSelectionVisible();
1614 QString VymModel::getURL() //FIXME-2
1617 BranchObj *bo=getSelectedBranch();
1619 return bo->getURL();
1625 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1627 return QStringList();
1630 BranchObj *bo=getSelectedBranch();
1636 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1644 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1646 FloatImageObj *fio=selection.getFloatImage();
1649 TreeItem *dst=findBySelectString (dstString);
1650 if (dst && dst->isBranchLikeType() )
1652 TreeItem *dstPar=dst->parent();
1653 QString parString=getSelectString(dstPar);
1654 QString fioPreSelectString=getSelectString(fio);
1655 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1656 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1658 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1659 fio=((BranchObj*)dst)->getLastFloatImage();
1664 getSelectString(fio),
1665 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1667 QString ("linkTo (\"%1\")").arg(dstString),
1668 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1674 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1677 BranchObj *bo=getSelectedBranch();
1680 QString s=bo->getFrameTypeName();
1681 bo->setFrameType (t);
1682 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1683 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1690 void VymModel::setFrameType(const QString &s) //FIXME-2
1693 BranchObj *bo=getSelectedBranch();
1696 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1697 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1698 bo->setFrameType (s);
1705 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1708 BranchObj *bo=getSelectedBranch();
1711 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1712 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1713 bo->setFramePenColor (c);
1718 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1721 BranchObj *bo=getSelectedBranch();
1724 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1725 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1726 bo->setFrameBrushColor (c);
1730 void VymModel::setFramePadding (const int &i) //FIXME-2
1733 BranchObj *bo=getSelectedBranch();
1736 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1737 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1738 bo->setFramePadding (i);
1745 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1748 BranchObj *bo=getSelectedBranch();
1751 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1752 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1753 bo->setFrameBorderWidth (i);
1760 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1763 BranchObj *bo=getSelectedBranch();
1766 QString u= b ? "false" : "true";
1767 QString r=!b ? "false" : "true";
1771 QString("setIncludeImagesVertically (%1)").arg(u),
1773 QString("setIncludeImagesVertically (%1)").arg(r),
1774 QString("Include images vertically in %1").arg(getObjectName(bo))
1776 bo->setIncludeImagesVer(b);
1781 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1784 BranchObj *bo=getSelectedBranch();
1787 QString u= b ? "false" : "true";
1788 QString r=!b ? "false" : "true";
1792 QString("setIncludeImagesHorizontally (%1)").arg(u),
1794 QString("setIncludeImagesHorizontally (%1)").arg(r),
1795 QString("Include images horizontally in %1").arg(getObjectName(bo))
1797 bo->setIncludeImagesHor(b);
1803 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1806 LinkableMapObj *sel=getSelectedLMO();
1808 (selectionType() == TreeItem::Branch ||
1809 selectionType() == TreeItem::MapCenter ||
1810 selectionType() == TreeItem::Image ))
1812 QString u= b ? "false" : "true";
1813 QString r=!b ? "false" : "true";
1817 QString("setHideLinkUnselected (%1)").arg(u),
1819 QString("setHideLinkUnselected (%1)").arg(r),
1820 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1822 sel->setHideLinkUnselected(b);
1827 void VymModel::setHideExport(bool b)
1829 BranchItem *bi=getSelectedBranchItem();
1832 bi->setHideInExport (b);
1833 QString u= b ? "false" : "true";
1834 QString r=!b ? "false" : "true";
1838 QString ("setHideExport (%1)").arg(u),
1840 QString ("setHideExport (%1)").arg(r),
1841 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1845 // selection.update();
1846 // FIXME-3 VM needed? scene()->update();
1850 void VymModel::toggleHideExport()
1852 BranchItem *selbi=getSelectedBranchItem();
1854 setHideExport ( !selbi->hideInExport() );
1858 void VymModel::copy() //FIXME-2
1861 LinkableMapObj *sel=getSelectedLMO();
1863 (selectionType() == TreeItem::Branch ||
1864 selectionType() == TreeItem::MapCenter ||
1865 selectionType() == TreeItem::Image ))
1867 if (redosAvail == 0)
1870 QString s=getSelectString(sel);
1871 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1872 curClipboard=curStep;
1875 // Copy also to global clipboard, because we are at last step in history
1876 QString bakMapName(QString("history-%1").arg(curStep));
1877 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1878 copyDir (bakMapDir,clipboardDir );
1880 clipboardEmpty=false;
1887 void VymModel::pasteNoSave(const int &n) //FIXME-2
1890 bool old=blockSaveState;
1891 blockSaveState=true;
1892 bool zippedOrg=zipped;
1893 if (redosAvail > 0 || n!=0)
1895 // Use the "historical" buffer
1896 QString bakMapName(QString("history-%1").arg(n));
1897 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1898 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1900 // Use the global buffer
1901 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1907 void VymModel::paste() //FIXME-2
1910 BranchObj *sel=getSelectedBranch();
1913 saveStateChangingPart(
1916 QString ("paste (%1)").arg(curClipboard),
1917 QString("Paste to %1").arg( getObjectName(sel))
1925 void VymModel::cut() //FIXME-2
1928 LinkableMapObj *sel=getSelectedLMO();
1929 if ( sel && (selectionType() == TreeItem::Branch ||
1930 selectionType()==TreeItem::MapCenter ||
1931 selectionType()==TreeItem::Image))
1934 /* No savestate! savestate is called in cutNoSave
1935 saveStateChangingPart(
1939 QString("Cut %1").arg(getObjectName(sel ))
1949 void VymModel::moveBranchUp() //FIXME-2
1952 BranchObj* bo=getSelectedBranch();
1956 if (!bo->canMoveBranchUp()) return;
1957 par=(BranchObj*)(bo->getParObj());
1958 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1959 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1961 //FIXME-3 VM needed? scene()->update();
1963 ensureSelectionVisible();
1968 void VymModel::moveBranchDown() //FIXME-2
1971 BranchObj* bo=getSelectedBranch();
1975 if (!bo->canMoveBranchDown()) return;
1976 par=(BranchObj*)(bo->getParObj());
1977 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1978 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1980 //FIXME-3 VM needed? scene()->update();
1982 ensureSelectionVisible();
1987 void VymModel::sortChildren() // FIXME-2 not implemented yet
1990 BranchObj* bo=getSelectedBranch();
1993 if(treeItem->branchCount()>1)
1995 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1998 ensureSelectionVisible();
2004 MapCenterItem* VymModel::createMapCenter()
2006 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
2011 BranchItem* VymModel::createBranch()
2013 return addNewBranchInt (-2);
2016 TreeItem* VymModel::createImage() //FIXME-2
2019 BranchObj *bo=getSelectedBranch();
2022 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
2025 QList<QVariant> cData;
2026 cData << "VM:createImage" << "undef"<<"undef";
2027 TreeItem *parti=bo->getTreeItem();
2028 TreeItem *ti=new TreeItem (cData,parti);
2029 ti->setLMO (newfio);
2030 ti->setType (TreeItem::Image);
2031 parti->appendChild (ti);
2035 newfio->setTreeItem (ti);
2036 select (newfio); // FIXME-2 VM really needed here?
2044 MapCenterItem* VymModel::addMapCenter ()
2046 MapCenterItem *mci=addMapCenter (contextPos); //FIXME-2 get rid of MCO here
2047 //FIXME-3 selection.select (mco);
2049 ensureSelectionVisible();
2054 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2055 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2060 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2064 QModelIndex parix=index(rootItem);
2066 int n=rootItem->branchCount();
2068 emit (layoutAboutToBeChanged() );
2069 beginInsertRows (parix,n,n+1);
2071 QList<QVariant> cData;
2072 cData << "VM:addMapCenter" << "undef"<<"undef";
2073 MapCenterItem *mci=new MapCenterItem (cData,rootItem);
2074 cout << "VM::addMapCenter mci="<<mci<<endl;
2075 mci->setType (TreeItem::MapCenter);
2076 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2077 rootItem->appendChild (mci);
2080 emit (newChildObject (parix));
2081 emit (layoutChanged() );
2084 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
2085 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2086 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2087 mci->setLMO (mapCenter);
2088 mapCenter->updateHeading();
2089 mapCenter->move (absPos);
2090 mapCenter->setVisibility (true);
2091 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2094 qWarning ("MW::insertRow a");
2095 if (!insertRow(0, parix))
2097 std::cout << " war nix...\n";
2099 qWarning ("MW::insertRow b");
2105 MapCenterItem* VymModel::removeMapCenter(MapCenterItem* mci) //FIXME-2
2108 int i=mapCenters.indexOf (mco);
2111 mapCenters.removeAt (i);
2113 if (i>0) return rootItem->getBranchNum(i-1); // Return previous MCO
2119 MapCenterObj* VymModel::getLastMapCenter() // FIXME-3 still needed?
2121 return (MapCenterObj*)rootItem->getLastBranch();
2125 BranchItem* VymModel::addNewBranchInt(int num)
2127 // Depending on pos:
2128 // -3 insert in children of parent above selection
2129 // -2 add branch to selection
2130 // -1 insert in children of parent below selection
2131 // 0..n insert in children of parent at pos
2132 BranchObj *newbo=NULL;
2133 BranchObj *bo=getSelectedBranchObj(); //FIXME-2
2134 BranchItem *bi=getSelectedBranchItem();
2140 QList<QVariant> cData;
2141 cData << "new" << "undef"<<"undef";
2143 BranchItem *parbi=bi;
2144 QModelIndex parix=index(parbi);
2145 int n=parbi->branchCount();
2147 emit (layoutAboutToBeChanged() );
2148 beginInsertRows (parix,n,n+1);
2149 bi=new BranchItem (cData,parbi);
2150 bi->setType (TreeItem::Branch);
2151 bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2153 parbi->appendChild (bi);
2155 emit (newChildObject (parix));
2156 emit (layoutChanged() );
2158 // save scroll state. If scrolled, automatically select
2159 // new branch in order to tmp unscroll parent...
2160 newbo=bi->createMapObj(mapScene);
2162 newbo=bo->addBranch();
2167 newbo->setTreeItem (bi);
2177 bo=(BranchObj*)bo->getParObj();
2178 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2184 bo=(BranchObj*)bo->getParObj();
2185 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2192 BranchItem* VymModel::addNewBranch(int pos)
2194 // Different meaning than num in addNewBranchInt!
2198 BranchItem *newbi=NULL;
2199 BranchItem *selbi=getSelectedBranchItem();
2203 // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2205 newbi=addNewBranchInt (pos-2);
2213 QString ("addBranch (%1)").arg(pos),
2214 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2217 // selection.update(); FIXME-3
2218 latestSelectionString=getSelectString(newbi);
2219 // In Network mode, the client needs to know where the new branch is,
2220 // so we have to pass on this information via saveState.
2221 // TODO: Get rid of this positioning workaround
2222 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2223 sendData ("selectLatestAdded ()");
2224 sendData (QString("move %1").arg(ps));
2233 BranchItem* VymModel::addNewBranchBefore() //FIXME-2
2236 BranchObj *newbo=NULL;
2237 BranchObj *bo = getSelectedBranch();
2238 if (bo && selectionType()==TreeItem::Branch)
2239 // We accept no MapCenterObj here, so we _have_ a parent
2241 QPointF p=bo->getRelPos();
2244 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2246 // add below selection
2247 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2251 newbo->move2RelPos (p);
2253 // Move selection to new branch
2254 bo->linkTo (newbo,-1);
2256 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2257 QString ("Add branch before %1").arg(getObjectName(bo)));
2260 // selection.update(); FIXME-3
2263 latestSelectionString=selection.getSelectString();
2269 BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2271 cout << "VM::relinkBranch "<<branch->getHeadingStd()<<" to "<<dst->getHeadingStd()<<" at pos="<<pos<<endl;
2274 BranchItem *branchpi=(BranchItem*)branch->parent();
2275 BranchItem *dstpi=(BranchItem*)dst->parent();
2278 // Append as last branch to dst
2279 branchpi->removeChild (branch->childNum() );
2280 dst->appendChild (branch);
2285 void VymModel::deleteSelection()
2287 BranchObj *bo = getSelectedBranchObj(); // FIXME-2 VM should not be necessary
2288 BranchItem *selbi=getSelectedBranchItem();
2292 QModelIndex ix=index (selbi);
2293 if (!ix.isValid() ) return;
2295 QModelIndex parentIndex=parent(ix);
2297 if (!parentIndex.isValid())
2299 cout << "VM::delete no valid parent ix\n";
2305 if (selbi->getType()==TreeItem::MapCenter)
2307 // BranchObj* par=(BranchObj*)(bo->getParObj());
2308 //selection.unselect();
2309 // FIXME-1 VM Note: does saveStateRemovingPart work for MCO? (No parent!)
2310 //saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2311 emit (layoutAboutToBeChanged() );
2313 parentIndex=parent(index(selbi));
2314 cout << "VM::delete selbi="<<selbi<<" row="<<ix.row()<<" parIndex.valid="<<parentIndex.isValid()<<endl;
2316 beginRemoveRows (parentIndex,n,n);
2317 removeRows (n,1,parentIndex);
2318 MapCenterItem *mci=removeMapCenter (selbi);
2323 ensureSelectionVisible();
2327 emit (layoutChanged() );
2329 if (selbi->getType()==TreeItem::Branch)
2331 if (selbi->isBranchLikeType() )
2334 BranchObj* par=(BranchObj*)bo->getParObj();
2336 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(bo)));
2338 emit (layoutAboutToBeChanged() );
2340 cout << "VM::delete selbi="<<selbi<<" row="<<ix.row()<<endl;
2341 parentIndex=parent(index(selbi));
2343 beginRemoveRows (parentIndex,n,n);
2344 removeRows (n,1,parentIndex);
2346 // delete (selbi->getLMO() ); // FIXME-0 selbi is removed implicetely, destructor is called. from there BO is deleted, but somhow still segfaulting :-(
2348 ensureSelectionVisible();
2351 emit (layoutChanged() );
2354 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2359 BranchObj* par=(BranchObj*)fio->getParObj();
2360 saveStateChangingPart(
2364 QString("Delete %1").arg(getObjectName(fio))
2367 par->removeFloatImage(fio);
2370 ensureSelectionVisible();
2376 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2380 BranchObj *bo=getSelectedBranch();
2384 par=(BranchObj*)(bo->getParObj());
2386 // Don't use this on mapcenter
2389 // Check if we have childs at all to keep
2390 if (bo->getTreeItem()->branchCount()==0)
2396 QPointF p=bo->getRelPos();
2397 saveStateChangingPart(
2400 "deleteKeepChildren ()",
2401 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2404 QString sel=getSelectString(bo);
2406 par->removeBranchHere(bo);
2409 getSelectedBranch()->move2RelPos (p);
2414 void VymModel::deleteChildren() //FIXME-2 VM still missing
2418 BranchObj *bo=getSelectedBranch();
2421 saveStateChangingPart(
2424 "deleteChildren ()",
2425 QString( "Remove children of branch %1").arg(getObjectName(bo))
2427 bo->removeChildren();
2433 bool VymModel::scrollBranch(BranchItem *bi)
2437 if (bi->isScrolled()) return false;
2438 if (bi->branchCount()==0) return false;
2439 if (bi->depth()==0) return false;
2443 /* FIXME-3 no savestate yet
2446 QString ("%1 ()").arg(u),
2448 QString ("%1 ()").arg(r),
2449 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2453 //selection.update();
2454 // FIXME-3 VM needed? scene()->update();
2460 bool VymModel::unscrollBranch(BranchItem *bi)
2464 if (bi->isScrolled()) return false;
2465 if (bi->branchCount()==0) return false;
2466 if (bi->depth()==0) return false;
2471 /* FIXME-3 no savestate yet
2474 QString ("%1 ()").arg(u),
2476 QString ("%1 ()").arg(r),
2477 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2481 // selection.update();
2482 // FIXME-3 VM needed? scene()->update();
2488 void VymModel::toggleScroll()
2490 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2491 if (bi && bi->getType()==TreeItem::Branch )
2493 if (bi->isScrolled())
2494 unscrollBranch (bi);
2500 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2504 BranchObj *bo=getSelectedBranch();
2510 if (bo->isScrolled()) unscrollBranch (bo);
2517 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2520 BranchObj *bo=getSelectedBranch();
2523 FloatImageObj *fio=bo->addFloatImage();
2525 fio->setOriginalFilename("No original filename (image added by dropevent)");
2526 QString s=getSelectString(bo);
2527 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2528 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2530 // FIXME-3 VM needed? scene()->update();
2536 void VymModel::colorBranch (QColor c) //FIXME-2
2539 BranchObj *bo=getSelectedBranch();
2544 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2546 QString ("colorBranch (\"%1\")").arg(c.name()),
2547 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2549 bo->setColor(c); // color branch
2554 void VymModel::colorSubtree (QColor c) //FIXME-2
2557 BranchObj *bo=getSelectedBranch();
2560 saveStateChangingPart(
2563 QString ("colorSubtree (\"%1\")").arg(c.name()),
2564 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2566 bo->setColorSubtree (c); // color links, color children
2571 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2574 BranchObj *bo=getSelectedBranch();
2575 if (bo) return bo->getColor();
2577 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2584 void VymModel::editURL() //FIXME-2
2587 BranchObj *bo=getSelectedBranch();
2591 QString text = QInputDialog::getText(
2592 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2593 bo->getURL(), &ok, NULL);
2595 // user entered something and pressed OK
2601 void VymModel::editLocalURL() //FIXME-2
2604 BranchObj *bo=getSelectedBranch();
2607 QStringList filters;
2608 filters <<"All files (*)";
2609 filters << tr("Text","Filedialog") + " (*.txt)";
2610 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2611 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2612 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2613 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2614 fd->setFilters (filters);
2615 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2616 fd->setDirectory (lastFileDir);
2617 if (! bo->getVymLink().isEmpty() )
2618 fd->selectFile( bo->getURL() );
2621 if ( fd->exec() == QDialog::Accepted )
2623 lastFileDir=QDir (fd->directory().path());
2624 setURL (fd->selectedFile() );
2631 void VymModel::editHeading2URL() //FIXME-2
2634 BranchObj *bo=getSelectedBranch();
2636 setURL (bo->getHeading());
2640 void VymModel::editBugzilla2URL() //FIXME-2
2643 BranchObj *bo=getSelectedBranch();
2646 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2652 void VymModel::editFATE2URL() //FIXME-2
2655 BranchObj *bo=getSelectedBranch();
2658 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2661 "setURL (\""+bo->getURL()+"\")",
2663 "setURL (\""+url+"\")",
2664 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2672 void VymModel::editVymLink()
2674 BranchItem *bi=getSelectedBranchItem();
2677 QStringList filters;
2678 filters <<"VYM map (*.vym)";
2679 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2680 fd->setFilters (filters);
2681 fd->setCaption(vymName+" - " +tr("Link to another map"));
2682 fd->setDirectory (lastFileDir);
2683 if (! bi->getVymLink().isEmpty() )
2684 fd->selectFile( bi->getVymLink() );
2688 if ( fd->exec() == QDialog::Accepted )
2690 lastFileDir=QDir (fd->directory().path());
2693 "setVymLink (\""+bi->getVymLink()+"\")",
2695 "setVymLink (\""+fd->selectedFile()+"\")",
2696 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2698 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2703 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2705 // Internal function, no saveState needed
2706 BranchItem *bi=getSelectedBranchItem();
2709 bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO
2712 //selection.update();
2713 ensureSelectionVisible();
2717 void VymModel::deleteVymLink()
2719 BranchItem *bi=getSelectedBranchItem();
2724 "setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO
2727 "setVymLink (\"\")",
2728 QString("Unset vymlink of %1").arg(getObjectName(bi))
2730 bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO
2733 // FIXME-3 VM needed? scene()->update();
2737 QString VymModel::getVymLink()
2739 BranchItem *bi=getSelectedBranchItem();
2741 return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here...
2747 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2749 return QStringList();
2752 BranchObj *bo=getSelectedBranch();
2758 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2767 void VymModel::followXLink(int i) // FIXME-2
2771 BranchObj *bo=getSelectedBranch();
2774 bo=bo->XLinkTargetAt(i);
2777 selection.select(bo);
2778 ensureSelectionVisible();
2784 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2788 BranchObj *bo=getSelectedBranch();
2791 XLinkObj *xlo=bo->XLinkAt(i);
2794 EditXLinkDialog dia;
2796 dia.setSelection(bo);
2797 if (dia.exec() == QDialog::Accepted)
2799 if (dia.useSettingsGlobal() )
2801 setMapDefXLinkColor (xlo->getColor() );
2802 setMapDefXLinkWidth (xlo->getWidth() );
2804 if (dia.deleteXLink())
2805 bo->deleteXLinkAt(i);
2816 //////////////////////////////////////////////
2818 //////////////////////////////////////////////
2820 void VymModel::parseAtom(const QString &atom)
2822 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2823 TreeItem* selti=getSelectedItem();
2824 BranchItem *selbi=getSelectedBranchItem();
2830 // Split string s into command and parameters
2831 parser.parseAtom (atom);
2832 QString com=parser.getCommand();
2834 // External commands
2835 /////////////////////////////////////////////////////////////////////
2836 if (com=="addBranch")
2840 parser.setError (Aborted,"Nothing selected");
2841 } else if (! selbi )
2843 parser.setError (Aborted,"Type of selection is not a branch");
2848 if (parser.checkParCount(pl))
2850 if (parser.parCount()==0)
2854 n=parser.parInt (ok,0);
2855 if (ok ) addNewBranch (n);
2859 /////////////////////////////////////////////////////////////////////
2860 } else if (com=="addBranchBefore")
2864 parser.setError (Aborted,"Nothing selected");
2865 } else if (! selbi )
2867 parser.setError (Aborted,"Type of selection is not a branch");
2870 if (parser.parCount()==0)
2872 addNewBranchBefore ();
2875 /////////////////////////////////////////////////////////////////////
2876 } else if (com==QString("addMapCenter"))
2878 if (parser.checkParCount(2))
2880 x=parser.parDouble (ok,0);
2883 y=parser.parDouble (ok,1);
2884 if (ok) addMapCenter (QPointF(x,y));
2887 /////////////////////////////////////////////////////////////////////
2888 } else if (com==QString("addMapReplace"))
2892 parser.setError (Aborted,"Nothing selected");
2893 } else if (! selbi )
2895 parser.setError (Aborted,"Type of selection is not a branch");
2896 } else if (parser.checkParCount(1))
2898 //s=parser.parString (ok,0); // selection
2899 t=parser.parString (ok,0); // path to map
2900 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2901 addMapReplaceInt(getSelectString(selbi),t);
2903 /////////////////////////////////////////////////////////////////////
2904 } else if (com==QString("addMapInsert"))
2908 parser.setError (Aborted,"Nothing selected");
2909 } else if (! selbi )
2911 parser.setError (Aborted,"Type of selection is not a branch");
2914 if (parser.checkParCount(2))
2916 t=parser.parString (ok,0); // path to map
2917 n=parser.parInt(ok,1); // position
2918 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2919 addMapInsertInt(t,n);
2922 /////////////////////////////////////////////////////////////////////
2923 } else /*if (com=="clearFlags") // FIXME-2
2927 parser.setError (Aborted,"Nothing selected");
2928 } else if (! selbi )
2930 parser.setError (Aborted,"Type of selection is not a branch");
2931 } else if (parser.checkParCount(0))
2933 selb->clearStandardFlags();
2934 selb->updateFlagsToolbar();
2936 /////////////////////////////////////////////////////////////////////
2937 } else */ if (com=="colorBranch")
2941 parser.setError (Aborted,"Nothing selected");
2942 } else if (! selbi )
2944 parser.setError (Aborted,"Type of selection is not a branch");
2945 } else if (parser.checkParCount(1))
2947 QColor c=parser.parColor (ok,0);
2948 if (ok) colorBranch (c);
2950 /////////////////////////////////////////////////////////////////////
2951 } else if (com=="colorSubtree")
2955 parser.setError (Aborted,"Nothing selected");
2956 } else if (! selbi )
2958 parser.setError (Aborted,"Type of selection is not a branch");
2959 } else if (parser.checkParCount(1))
2961 QColor c=parser.parColor (ok,0);
2962 if (ok) colorSubtree (c);
2964 /////////////////////////////////////////////////////////////////////
2965 } else if (com=="copy")
2969 parser.setError (Aborted,"Nothing selected");
2970 } else if (! selbi )
2972 parser.setError (Aborted,"Type of selection is not a branch");
2973 } else if (parser.checkParCount(0))
2975 //FIXME-1 missing action for copy
2977 /////////////////////////////////////////////////////////////////////
2978 } else if (com=="cut")
2982 parser.setError (Aborted,"Nothing selected");
2983 } else if ( selectionType()!=TreeItem::Branch &&
2984 selectionType()!=TreeItem::MapCenter &&
2985 selectionType()!=TreeItem::Image )
2987 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2988 } else if (parser.checkParCount(0))
2992 /////////////////////////////////////////////////////////////////////
2993 } else if (com=="delete")
2997 parser.setError (Aborted,"Nothing selected");
2999 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3001 parser.setError (Aborted,"Type of selection is wrong.");
3004 else if (parser.checkParCount(0))
3008 /////////////////////////////////////////////////////////////////////
3009 } else if (com=="deleteKeepChildren")
3013 parser.setError (Aborted,"Nothing selected");
3014 } else if (! selbi )
3016 parser.setError (Aborted,"Type of selection is not a branch");
3017 } else if (parser.checkParCount(0))
3019 deleteKeepChildren();
3021 /////////////////////////////////////////////////////////////////////
3022 } else if (com=="deleteChildren")
3026 parser.setError (Aborted,"Nothing selected");
3029 parser.setError (Aborted,"Type of selection is not a branch");
3030 } else if (parser.checkParCount(0))
3034 /////////////////////////////////////////////////////////////////////
3035 } else if (com=="exportASCII")
3039 if (parser.parCount()>=1)
3040 // Hey, we even have a filename
3041 fname=parser.parString(ok,0);
3044 parser.setError (Aborted,"Could not read filename");
3047 exportASCII (fname,false);
3049 /////////////////////////////////////////////////////////////////////
3050 } else if (com=="exportImage")
3054 if (parser.parCount()>=2)
3055 // Hey, we even have a filename
3056 fname=parser.parString(ok,0);
3059 parser.setError (Aborted,"Could not read filename");
3062 QString format="PNG";
3063 if (parser.parCount()>=2)
3065 format=parser.parString(ok,1);
3067 exportImage (fname,false,format);
3069 /////////////////////////////////////////////////////////////////////
3070 } else if (com=="exportXHTML")
3074 if (parser.parCount()>=2)
3075 // Hey, we even have a filename
3076 fname=parser.parString(ok,1);
3079 parser.setError (Aborted,"Could not read filename");
3082 exportXHTML (fname,false);
3084 /////////////////////////////////////////////////////////////////////
3085 } else if (com=="exportXML")
3089 if (parser.parCount()>=2)
3090 // Hey, we even have a filename
3091 fname=parser.parString(ok,1);
3094 parser.setError (Aborted,"Could not read filename");
3097 exportXML (fname,false);
3099 /////////////////////////////////////////////////////////////////////
3100 } else if (com=="importDir")
3104 parser.setError (Aborted,"Nothing selected");
3105 } else if (! selbi )
3107 parser.setError (Aborted,"Type of selection is not a branch");
3108 } else if (parser.checkParCount(1))
3110 s=parser.parString(ok,0);
3111 if (ok) importDirInt(s);
3113 /////////////////////////////////////////////////////////////////////
3114 } else /* FIXME-2 if (com=="linkTo")
3118 parser.setError (Aborted,"Nothing selected");
3121 if (parser.checkParCount(4))
3123 // 0 selectstring of parent
3124 // 1 num in parent (for branches)
3125 // 2,3 x,y of mainbranch or mapcenter
3126 s=parser.parString(ok,0);
3127 LinkableMapObj *dst=findObjBySelect (s);
3130 if (typeid(*dst) == typeid(BranchObj) )
3132 // Get number in parent
3133 n=parser.parInt (ok,1);
3136 selb->linkTo ((BranchObj*)(dst),n);
3139 } else if (typeid(*dst) == typeid(MapCenterObj) )
3141 selb->linkTo ((BranchObj*)(dst),-1);
3142 // Get coordinates of mainbranch
3143 x=parser.parDouble(ok,2);
3146 y=parser.parDouble(ok,3);
3156 } else if ( selectionType() == TreeItem::Image)
3158 if (parser.checkParCount(1))
3160 // 0 selectstring of parent
3161 s=parser.parString(ok,0);
3162 LinkableMapObj *dst=findObjBySelect (s);
3165 if (typeid(*dst) == typeid(BranchObj) ||
3166 typeid(*dst) == typeid(MapCenterObj))
3167 linkFloatImageTo (getSelectString(dst));
3169 parser.setError (Aborted,"Destination is not a branch");
3172 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3173 /////////////////////////////////////////////////////////////////////
3174 } else */ if (com=="loadImage")
3178 parser.setError (Aborted,"Nothing selected");
3179 } else if (! selbi )
3181 parser.setError (Aborted,"Type of selection is not a branch");
3182 } else if (parser.checkParCount(1))
3184 s=parser.parString(ok,0);
3185 if (ok) loadFloatImageInt (s);
3187 /////////////////////////////////////////////////////////////////////
3188 } else if (com=="moveBranchUp")
3192 parser.setError (Aborted,"Nothing selected");
3193 } else if (! selbi )
3195 parser.setError (Aborted,"Type of selection is not a branch");
3196 } else if (parser.checkParCount(0))
3200 /////////////////////////////////////////////////////////////////////
3201 } else if (com=="moveBranchDown")
3205 parser.setError (Aborted,"Nothing selected");
3206 } else if (! selbi )
3208 parser.setError (Aborted,"Type of selection is not a branch");
3209 } else if (parser.checkParCount(0))
3213 /////////////////////////////////////////////////////////////////////
3214 } else if (com=="move")
3218 parser.setError (Aborted,"Nothing selected");
3219 } else if ( selectionType()!=TreeItem::Branch &&
3220 selectionType()!=TreeItem::MapCenter &&
3221 selectionType()!=TreeItem::Image )
3223 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3224 } else if (parser.checkParCount(2))
3226 x=parser.parDouble (ok,0);
3229 y=parser.parDouble (ok,1);
3233 /////////////////////////////////////////////////////////////////////
3234 } else if (com=="moveRel")
3238 parser.setError (Aborted,"Nothing selected");
3239 } else if ( selectionType()!=TreeItem::Branch &&
3240 selectionType()!=TreeItem::MapCenter &&
3241 selectionType()!=TreeItem::Image )
3243 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3244 } else if (parser.checkParCount(2))
3246 x=parser.parDouble (ok,0);
3249 y=parser.parDouble (ok,1);
3250 if (ok) moveRel (x,y);
3253 /////////////////////////////////////////////////////////////////////
3254 } else if (com=="nop")
3256 /////////////////////////////////////////////////////////////////////
3257 } else if (com=="paste")
3261 parser.setError (Aborted,"Nothing selected");
3262 } else if (! selbi )
3264 parser.setError (Aborted,"Type of selection is not a branch");
3265 } else if (parser.checkParCount(1))
3267 n=parser.parInt (ok,0);
3268 if (ok) pasteNoSave(n);
3270 /////////////////////////////////////////////////////////////////////
3271 } else if (com=="qa")
3275 parser.setError (Aborted,"Nothing selected");
3276 } else if (! selbi )
3278 parser.setError (Aborted,"Type of selection is not a branch");
3279 } else if (parser.checkParCount(4))
3282 c=parser.parString (ok,0);
3285 parser.setError (Aborted,"No comment given");
3288 s=parser.parString (ok,1);
3291 parser.setError (Aborted,"First parameter is not a string");
3294 t=parser.parString (ok,2);
3297 parser.setError (Aborted,"Condition is not a string");
3300 u=parser.parString (ok,3);
3303 parser.setError (Aborted,"Third parameter is not a string");
3308 parser.setError (Aborted,"Unknown type: "+s);
3313 parser.setError (Aborted,"Unknown operator: "+t);
3318 parser.setError (Aborted,"Type of selection is not a branch");
3321 if (selbi->getHeading() == u)
3323 cout << "PASSED: " << qPrintable (c) << endl;
3326 cout << "FAILED: " << qPrintable (c) << endl;
3336 /////////////////////////////////////////////////////////////////////
3337 } else if (com=="saveImage")
3339 FloatImageObj *fio=selection.getFloatImage();
3342 parser.setError (Aborted,"Type of selection is not an image");
3343 } else if (parser.checkParCount(2))
3345 s=parser.parString(ok,0);
3348 t=parser.parString(ok,1);
3349 if (ok) saveFloatImageInt (fio,t,s);
3352 /////////////////////////////////////////////////////////////////////
3353 } else if (com=="scroll")
3357 parser.setError (Aborted,"Nothing selected");
3358 } else if (! selbi )
3360 parser.setError (Aborted,"Type of selection is not a branch");
3361 } else if (parser.checkParCount(0))
3363 if (!scrollBranch (selbi))
3364 parser.setError (Aborted,"Could not scroll branch");
3366 /////////////////////////////////////////////////////////////////////
3367 } else if (com=="select")
3369 if (parser.checkParCount(1))
3371 s=parser.parString(ok,0);
3374 /////////////////////////////////////////////////////////////////////
3375 } else if (com=="selectLastBranch")
3379 parser.setError (Aborted,"Nothing selected");
3380 } else if (! selbi )
3382 parser.setError (Aborted,"Type of selection is not a branch");
3383 } else if (parser.checkParCount(0))
3385 BranchItem *bi=selbi->getLastBranch();
3387 parser.setError (Aborted,"Could not select last branch");
3388 select (bi); // FIXME-3 was selectInt
3391 /////////////////////////////////////////////////////////////////////
3392 } else /* FIXME-2 if (com=="selectLastImage")
3396 parser.setError (Aborted,"Nothing selected");
3397 } else if (! selbi )
3399 parser.setError (Aborted,"Type of selection is not a branch");
3400 } else if (parser.checkParCount(0))
3402 FloatImageObj *fio=selb->getLastFloatImage();
3404 parser.setError (Aborted,"Could not select last image");
3405 select (fio); // FIXME-3 was selectInt
3408 /////////////////////////////////////////////////////////////////////
3409 } else */ if (com=="selectLatestAdded")
3411 if (latestSelectionString.isEmpty() )
3413 parser.setError (Aborted,"No latest added object");
3416 if (!select (latestSelectionString))
3417 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3419 /////////////////////////////////////////////////////////////////////
3420 } else if (com=="setFrameType")
3422 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3424 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3426 else if (parser.checkParCount(1))
3428 s=parser.parString(ok,0);
3429 if (ok) setFrameType (s);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="setFramePenColor")
3434 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3436 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3438 else if (parser.checkParCount(1))
3440 QColor c=parser.parColor(ok,0);
3441 if (ok) setFramePenColor (c);
3443 /////////////////////////////////////////////////////////////////////
3444 } else if (com=="setFrameBrushColor")
3446 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3448 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3450 else if (parser.checkParCount(1))
3452 QColor c=parser.parColor(ok,0);
3453 if (ok) setFrameBrushColor (c);
3455 /////////////////////////////////////////////////////////////////////
3456 } else if (com=="setFramePadding")
3458 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3460 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3462 else if (parser.checkParCount(1))
3464 n=parser.parInt(ok,0);
3465 if (ok) setFramePadding(n);
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="setFrameBorderWidth")
3470 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3472 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3474 else if (parser.checkParCount(1))
3476 n=parser.parInt(ok,0);
3477 if (ok) setFrameBorderWidth (n);
3479 /////////////////////////////////////////////////////////////////////
3480 } else if (com=="setMapAuthor")
3482 if (parser.checkParCount(1))
3484 s=parser.parString(ok,0);
3485 if (ok) setAuthor (s);
3487 /////////////////////////////////////////////////////////////////////
3488 } else if (com=="setMapComment")
3490 if (parser.checkParCount(1))
3492 s=parser.parString(ok,0);
3493 if (ok) setComment(s);
3495 /////////////////////////////////////////////////////////////////////
3496 } else if (com=="setMapBackgroundColor")
3500 parser.setError (Aborted,"Nothing selected");
3501 } else if (! selbi )
3503 parser.setError (Aborted,"Type of selection is not a branch");
3504 } else if (parser.checkParCount(1))
3506 QColor c=parser.parColor (ok,0);
3507 if (ok) setMapBackgroundColor (c);
3509 /////////////////////////////////////////////////////////////////////
3510 } else if (com=="setMapDefLinkColor")
3514 parser.setError (Aborted,"Nothing selected");
3515 } else if (! selbi )
3517 parser.setError (Aborted,"Type of selection is not a branch");
3518 } else if (parser.checkParCount(1))
3520 QColor c=parser.parColor (ok,0);
3521 if (ok) setMapDefLinkColor (c);
3523 /////////////////////////////////////////////////////////////////////
3524 } else if (com=="setMapLinkStyle")
3526 if (parser.checkParCount(1))
3528 s=parser.parString (ok,0);
3529 if (ok) setMapLinkStyle(s);
3531 /////////////////////////////////////////////////////////////////////
3532 } else if (com=="setHeading")
3536 parser.setError (Aborted,"Nothing selected");
3537 } else if (! selbi )
3539 parser.setError (Aborted,"Type of selection is not a branch");
3540 } else if (parser.checkParCount(1))
3542 s=parser.parString (ok,0);
3546 /////////////////////////////////////////////////////////////////////
3547 } else if (com=="setHideExport")
3551 parser.setError (Aborted,"Nothing selected");
3552 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3554 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3555 } else if (parser.checkParCount(1))
3557 b=parser.parBool(ok,0);
3558 if (ok) setHideExport (b);
3560 /////////////////////////////////////////////////////////////////////
3561 } else if (com=="setIncludeImagesHorizontally")
3565 parser.setError (Aborted,"Nothing selected");
3568 parser.setError (Aborted,"Type of selection is not a branch");
3569 } else if (parser.checkParCount(1))
3571 b=parser.parBool(ok,0);
3572 if (ok) setIncludeImagesHor(b);
3574 /////////////////////////////////////////////////////////////////////
3575 } else if (com=="setIncludeImagesVertically")
3579 parser.setError (Aborted,"Nothing selected");
3582 parser.setError (Aborted,"Type of selection is not a branch");
3583 } else if (parser.checkParCount(1))
3585 b=parser.parBool(ok,0);
3586 if (ok) setIncludeImagesVer(b);
3588 /////////////////////////////////////////////////////////////////////
3589 } else if (com=="setHideLinkUnselected")
3593 parser.setError (Aborted,"Nothing selected");
3594 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3596 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3597 } else if (parser.checkParCount(1))
3599 b=parser.parBool(ok,0);
3600 if (ok) setHideLinkUnselected(b);
3602 /////////////////////////////////////////////////////////////////////
3603 } else if (com=="setSelectionColor")
3605 if (parser.checkParCount(1))
3607 QColor c=parser.parColor (ok,0);
3608 if (ok) setSelectionColorInt (c);
3610 /////////////////////////////////////////////////////////////////////
3611 } else if (com=="setURL")
3615 parser.setError (Aborted,"Nothing selected");
3616 } else if (! selbi )
3618 parser.setError (Aborted,"Type of selection is not a branch");
3619 } else if (parser.checkParCount(1))
3621 s=parser.parString (ok,0);
3624 /////////////////////////////////////////////////////////////////////
3625 } else if (com=="setVymLink")
3629 parser.setError (Aborted,"Nothing selected");
3630 } else if (! selbi )
3632 parser.setError (Aborted,"Type of selection is not a branch");
3633 } else if (parser.checkParCount(1))
3635 s=parser.parString (ok,0);
3636 if (ok) setVymLink(s);
3639 /////////////////////////////////////////////////////////////////////
3640 else /* FIXME-2 if (com=="setFlag")
3644 parser.setError (Aborted,"Nothing selected");
3645 } else if (! selbi )
3647 parser.setError (Aborted,"Type of selection is not a branch");
3648 } else if (parser.checkParCount(1))
3650 s=parser.parString(ok,0);
3653 selb->activateStandardFlag(s);
3654 selb->updateFlagsToolbar();
3657 /////////////////////////////////////////////////////////////////////
3658 } else */ /* FIXME-2 if (com=="setFrameType")
3662 parser.setError (Aborted,"Nothing selected");
3665 parser.setError (Aborted,"Type of selection is not a branch");
3666 } else if (parser.checkParCount(1))
3668 s=parser.parString(ok,0);
3672 /////////////////////////////////////////////////////////////////////
3673 } else*/ if (com=="sortChildren")
3677 parser.setError (Aborted,"Nothing selected");
3678 } else if (! selbi )
3680 parser.setError (Aborted,"Type of selection is not a branch");
3681 } else if (parser.checkParCount(0))
3685 /////////////////////////////////////////////////////////////////////
3686 } else /* FIXME-2 if (com=="toggleFlag")
3690 parser.setError (Aborted,"Nothing selected");
3691 } else if (! selbi )
3693 parser.setError (Aborted,"Type of selection is not a branch");
3694 } else if (parser.checkParCount(1))
3696 s=parser.parString(ok,0);
3699 selbi->toggleStandardFlag(s);
3700 selb->updateFlagsToolbar();
3703 /////////////////////////////////////////////////////////////////////
3704 } else */ if (com=="unscroll")
3708 parser.setError (Aborted,"Nothing selected");
3709 } else if (! selbi )
3711 parser.setError (Aborted,"Type of selection is not a branch");
3712 } else if (parser.checkParCount(0))
3714 if (!unscrollBranch (selbi))
3715 parser.setError (Aborted,"Could not unscroll branch");
3717 /////////////////////////////////////////////////////////////////////
3718 } else if (com=="unscrollChildren")
3722 parser.setError (Aborted,"Nothing selected");
3723 } else if (! selbi )
3725 parser.setError (Aborted,"Type of selection is not a branch");
3726 } else if (parser.checkParCount(0))
3728 unscrollChildren ();
3730 /////////////////////////////////////////////////////////////////////
3731 } else /* FIXME-2 if (com=="unsetFlag")
3733 if (selection.isEmpty() )
3735 parser.setError (Aborted,"Nothing selected");
3736 } else if (! selbi )
3738 parser.setError (Aborted,"Type of selection is not a branch");
3739 } else if (parser.checkParCount(1))
3741 s=parser.parString(ok,0);
3744 selb->deactivateStandardFlag(s);
3745 selb->updateFlagsToolbar();
3749 parser.setError (Aborted,"Unknown command");
3752 if (parser.errorLevel()==NoError)
3754 // setChanged(); FIXME-2 should not be called e.g. for export?!
3759 // TODO Error handling
3760 qWarning("VymModel::parseAtom: Error!");
3761 qWarning(parser.errorMessage());
3765 void VymModel::runScript (QString script)
3767 parser.setScript (script);
3769 while (parser.next() )
3770 parseAtom(parser.getAtom());
3773 void VymModel::setExportMode (bool b)
3775 // should be called before and after exports
3776 // depending on the settings
3777 if (b && settings.value("/export/useHideExport","true")=="true")
3778 setHideTmpMode (TreeItem::HideExport);
3780 setHideTmpMode (TreeItem::HideNone);
3783 void VymModel::exportImage(QString fname, bool askName, QString format)
3787 fname=getMapName()+".png";
3794 QFileDialog *fd=new QFileDialog (NULL);
3795 fd->setCaption (tr("Export map as image"));
3796 fd->setDirectory (lastImageDir);
3797 fd->setFileMode(QFileDialog::AnyFile);
3798 fd->setFilters (imageIO.getFilters() );
3801 fl=fd->selectedFiles();
3803 format=imageIO.getType(fd->selectedFilter());
3807 setExportMode (true);
3808 QPixmap pix (getPixmap());
3809 pix.save(fname, format);
3810 setExportMode (false);
3814 void VymModel::exportXML(QString dir, bool askForName)
3818 dir=browseDirectory(NULL,tr("Export XML to directory"));
3819 if (dir =="" && !reallyWriteDirectory(dir) )
3823 // Hide stuff during export, if settings want this
3824 setExportMode (true);
3826 // Create subdirectories
3829 // write to directory
3830 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3833 file.setName ( dir + "/"+mapName+".xml");
3834 if ( !file.open( QIODevice::WriteOnly ) )
3836 // This should neverever happen
3837 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3841 // Write it finally, and write in UTF8, no matter what
3842 QTextStream ts( &file );
3843 ts.setEncoding (QTextStream::UnicodeUTF8);
3847 // Now write image, too
3848 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3850 setExportMode (false);
3853 void VymModel::exportASCII(QString fname,bool askName)
3858 ex.setFile (mapName+".txt");
3864 //ex.addFilter ("TXT (*.txt)");
3865 ex.setDir(lastImageDir);
3866 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3871 setExportMode(true);
3873 setExportMode(false);
3877 void VymModel::exportXHTML (const QString &dir, bool askForName)
3879 ExportXHTMLDialog dia(NULL);
3880 dia.setFilePath (filePath );
3881 dia.setMapName (mapName );
3883 if (dir!="") dia.setDir (dir);
3889 if (dia.exec()!=QDialog::Accepted)
3893 QDir d (dia.getDir());
3894 // Check, if warnings should be used before overwriting
3895 // the output directory
3896 if (d.exists() && d.count()>0)
3899 warn.showCancelButton (true);
3900 warn.setText(QString(
3901 "The directory %1 is not empty.\n"
3902 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3903 warn.setCaption("Warning: Directory not empty");
3904 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3906 if (warn.exec()!=QDialog::Accepted) ok=false;
3913 exportXML (dia.getDir(),false );
3914 dia.doExport(mapName );
3915 //if (dia.hasChanged()) setChanged();
3919 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3924 if (ex.setConfigFile(cf))
3926 setExportMode (true);
3927 ex.exportPresentation();
3928 setExportMode (false);
3935 //////////////////////////////////////////////
3937 //////////////////////////////////////////////
3939 void VymModel::registerEditor(QWidget *me)
3941 mapEditor=(MapEditor*)me;
3943 for (int i=0; i<rootItem->branchCount(); i++)
3944 rootItem->getBranchNum(i)->setMapEditor(mapEditor);
3948 void VymModel::unregisterEditor(QWidget *)
3953 void VymModel::setContextPos(QPointF p)
3958 void VymModel::unsetContextPos()
3960 contextPos=QPointF();
3963 void VymModel::updateNoteFlag()
3966 cout << "VM::updateNoteFlag()\n";
3967 /* FIXME-1 modify note flag
3968 BranchObj *bo=getSelectedBranch();
3971 bo->updateNoteFlag();
3972 mainWindow->updateActions();
3977 void VymModel::updateRelPositions() //FIXME-2 VM should have no need to updateRelPos
3979 cout << "VM::updateRelPos...\n";
3980 for (int i=0; i<rootItem->branchCount(); i++)
3981 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3984 void VymModel::reposition() //FIXME-2 VM should have no need to reposition, this is done in views???
3986 cout << "VM::reposition ...\n";
3987 for (int i=0;i<rootItem->branchCount(); i++)
3988 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3991 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3994 // Creating (arbitrary) shapes
3997 QRectF rb=bo->getBBox();
3998 if (bo->getDepth()==0)
4000 // Just take BBox of this mapCenter
4001 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
4005 // Take union of BBox and TotalBBox
4007 QRectF ra=bo->getTotalBBox();
4008 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4011 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
4014 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
4016 p <<ra.bottomRight()
4018 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4021 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4026 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4030 // Move all branches and MapCenters away from lmo
4031 // to avoid collisions
4037 BranchObj *boA=(BranchObj*)lmo;
4039 for (int i=0; i<rootItem->branchCount(); i++)
4041 boB=rootItem->getBranchNum(i);
4044 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4047 <<" ("<<qPrintable(boA->getHeading() )<<")"
4048 <<" with ("<< qPrintable (boB->getHeading() )
4051 <<" minT="<<r.minTranslation<<endl<<endl;
4056 QPixmap VymModel::getPixmap()
4058 QRectF mapRect=getTotalBBox();
4059 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4062 pp.setRenderHints(mapEditor->renderHints());
4064 // Don't print the visualisation of selection
4065 selection.unselect();
4067 mapScene->render ( &pp,
4068 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4069 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4071 // Restore selection
4072 selection.reselect();
4078 void VymModel::setMapLinkStyle (const QString & s)
4083 case LinkableMapObj::Line :
4086 case LinkableMapObj::Parabel:
4087 snow="StyleParabel";
4089 case LinkableMapObj::PolyLine:
4090 snow="StylePolyLine";
4092 case LinkableMapObj::PolyParabel:
4093 snow="StylePolyParabel";
4096 snow="UndefinedStyle";
4101 QString("setMapLinkStyle (\"%1\")").arg(s),
4102 QString("setMapLinkStyle (\"%1\")").arg(snow),
4103 QString("Set map link style (\"%1\")").arg(s)
4107 linkstyle=LinkableMapObj::Line;
4108 else if (s=="StyleParabel")
4109 linkstyle=LinkableMapObj::Parabel;
4110 else if (s=="StylePolyLine")
4111 linkstyle=LinkableMapObj::PolyLine;
4112 else if (s=="StylePolyParabel")
4113 linkstyle=LinkableMapObj::PolyParabel;
4115 linkstyle=LinkableMapObj::UndefinedStyle;
4117 BranchItem *cur=NULL;
4118 BranchItem *prev=NULL;
4124 bo=(BranchObj*)(cur->getLMO() );
4125 bo->setLinkStyle(bo->getDefLinkStyle());
4126 cur=next(cur,prev,d);
4131 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4136 void VymModel::setMapDefLinkColor(QColor col)
4138 if ( !col.isValid() ) return;
4140 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4141 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4142 QString("Set map link color to %1").arg(col.name())
4146 BranchItem *cur=NULL;
4147 BranchItem *prev=NULL;
4150 cur=next(cur,prev,d);
4153 bo=(BranchObj*)(cur->getLMO() );
4160 void VymModel::setMapLinkColorHintInt()
4162 // called from setMapLinkColorHint(lch) or at end of parse
4163 BranchItem *cur=NULL;
4164 BranchItem *prev=NULL;
4167 cur=next(cur,prev,d);
4170 bo=(BranchObj*)(cur->getLMO() );
4172 cur=next(cur,prev,d);
4176 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4179 setMapLinkColorHintInt();
4182 void VymModel::toggleMapLinkColorHint()
4184 if (linkcolorhint==LinkableMapObj::HeadingColor)
4185 linkcolorhint=LinkableMapObj::DefaultColor;
4187 linkcolorhint=LinkableMapObj::HeadingColor;
4188 BranchItem *cur=NULL;
4189 BranchItem *prev=NULL;
4192 cur=next(cur,prev,d);
4195 bo=(BranchObj*)(cur->getLMO() );
4201 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4203 Q3FileDialog *fd=new Q3FileDialog( NULL);
4204 fd->setMode (Q3FileDialog::ExistingFile);
4205 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4206 ImagePreview *p =new ImagePreview (fd);
4207 fd->setContentsPreviewEnabled( TRUE );
4208 fd->setContentsPreview( p, p );
4209 fd->setPreviewMode( Q3FileDialog::Contents );
4210 fd->setCaption(vymName+" - " +tr("Load background image"));
4211 fd->setDir (lastImageDir);
4214 if ( fd->exec() == QDialog::Accepted )
4216 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4217 lastImageDir=QDir (fd->dirPath());
4218 setMapBackgroundImage (fd->selectedFile());
4222 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4224 QColor oldcol=mapScene->backgroundBrush().color();
4228 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4230 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4231 QString("Set background color of map to %1").arg(col.name()));
4234 brush.setTextureImage (QPixmap (fn));
4235 mapScene->setBackgroundBrush(brush);
4238 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4240 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4241 if ( !col.isValid() ) return;
4242 setMapBackgroundColor( col );
4246 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4248 QColor oldcol=mapScene->backgroundBrush().color();
4250 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4251 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4252 QString("Set background color of map to %1").arg(col.name()));
4253 mapScene->setBackgroundBrush(col);
4256 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4258 return mapScene->backgroundBrush().color();
4262 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4264 return linkcolorhint;
4267 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4269 return defLinkColor;
4272 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4277 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4279 return defXLinkColor;
4282 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4287 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4289 return defXLinkWidth;
4292 void VymModel::move(const double &x, const double &y) // FIXME-3
4296 BranchObj *bo = getSelectedBranch();
4298 (selectionType()==TreeItem::Branch ||
4299 selectionType()==TreeItem::MapCenter ||
4300 selectionType()==TreeItem::Image
4303 QPointF ap(bo->getAbsPos());
4307 QString ps=qpointfToString(ap);
4308 QString s=getSelectString();
4311 s, "move "+qpointfToString(to),
4312 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4321 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4325 BranchObj *bo = getSelectedBranch();
4327 (selectionType()==TreeItem::Branch ||
4328 selectionType()==TreeItem::MapCenter ||
4329 selectionType()==TreeItem::Image
4333 QPointF rp(bo->getRelPos());
4337 QString ps=qpointfToString (bo->getRelPos());
4338 QString s=getSelectString(bo);
4341 s, "moveRel "+qpointfToString(to),
4342 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4343 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4353 void VymModel::animate()
4355 animationTimer->stop();
4358 while (i<animObjList.size() )
4360 bo=(BranchObj*)animObjList.at(i);
4365 animObjList.removeAt(i);
4372 QItemSelection sel=selModel->selection();
4373 emit (selectionChanged(sel,sel));
4376 if (!animObjList.isEmpty()) animationTimer->start();
4380 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4382 if (bo && bo->getTreeItem()->depth()>0)
4385 ap.setStart (start);
4387 ap.setTicks (animationTicks);
4388 ap.setAnimated (true);
4389 bo->setAnimation (ap);
4390 animObjList.append( bo );
4391 animationTimer->setSingleShot (true);
4392 animationTimer->start(animationInterval);
4396 void VymModel::stopAnimation (MapObj *mo)
4398 int i=animObjList.indexOf(mo);
4400 animObjList.removeAt (i);
4403 void VymModel::sendSelection()
4405 if (netstate!=Server) return;
4406 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4409 void VymModel::newServer()
4413 tcpServer = new QTcpServer(this);
4414 if (!tcpServer->listen(QHostAddress::Any,port)) {
4415 QMessageBox::critical(NULL, "vym server",
4416 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4417 //FIXME-3 needed? we are no widget any longer... close();
4420 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4422 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4425 void VymModel::connectToServer()
4428 server="salam.suse.de";
4430 clientSocket = new QTcpSocket (this);
4431 clientSocket->abort();
4432 clientSocket->connectToHost(server ,port);
4433 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4434 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4435 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4437 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4442 void VymModel::newClient()
4444 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4445 connect(newClient, SIGNAL(disconnected()),
4446 newClient, SLOT(deleteLater()));
4448 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4450 clientList.append (newClient);
4454 void VymModel::sendData(const QString &s)
4456 if (clientList.size()==0) return;
4458 // Create bytearray to send
4460 QDataStream out(&block, QIODevice::WriteOnly);
4461 out.setVersion(QDataStream::Qt_4_0);
4463 // Reserve some space for blocksize
4466 // Write sendCounter
4467 out << sendCounter++;
4472 // Go back and write blocksize so far
4473 out.device()->seek(0);
4474 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4478 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4480 for (int i=0; i<clientList.size(); ++i)
4482 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4483 clientList.at(i)->write (block);
4487 void VymModel::readData ()
4489 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4492 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4496 QDataStream in(clientSocket);
4497 in.setVersion(QDataStream::Qt_4_0);
4505 cout << " t="<<qPrintable (t)<<endl;
4511 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4513 switch (socketError) {
4514 case QAbstractSocket::RemoteHostClosedError:
4516 case QAbstractSocket::HostNotFoundError:
4517 QMessageBox::information(NULL, vymName +" Network client",
4518 "The host was not found. Please check the "
4519 "host name and port settings.");
4521 case QAbstractSocket::ConnectionRefusedError:
4522 QMessageBox::information(NULL, vymName + " Network client",
4523 "The connection was refused by the peer. "
4524 "Make sure the fortune server is running, "
4525 "and check that the host name and port "
4526 "settings are correct.");
4529 QMessageBox::information(NULL, vymName + " Network client",
4530 QString("The following error occurred: %1.")
4531 .arg(clientSocket->errorString()));
4538 void VymModel::selectMapSelectionColor()
4540 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4541 setSelectionColor (col);
4544 void VymModel::setSelectionColorInt (QColor col)
4546 if ( !col.isValid() ) return;
4548 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4549 QString("setSelectionColor (%1)").arg(col.name()),
4550 QString("Set color of selection box to %1").arg(col.name())
4553 mapEditor->setSelectionColor (col);
4557 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4559 cout << "VymModel::changeSelection (";
4560 if (!newsel.indexes().isEmpty() )
4561 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4563 if (!oldsel.indexes().isEmpty() )
4564 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4569 void VymModel::updateSelection(const QItemSelection &newsel)
4571 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4572 ensureSelectionVisible();
4576 void VymModel::updateSelection()
4578 QItemSelection newsel=selModel->selection();
4579 updateSelection (newsel);
4582 void VymModel::setSelectionColor(QColor col)
4584 if ( !col.isValid() ) return;
4586 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4587 QString("setSelectionColor (%1)").arg(col.name()),
4588 QString("Set color of selection box to %1").arg(col.name())
4590 setSelectionColorInt (col);
4593 QColor VymModel::getSelectionColor()
4595 return mapEditor->getSelectionColor();
4598 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4601 for (int i=0;i<rootItem->childCount();i++)
4602 rootItem->child(i)->setHideTmp (mode);
4604 // FIXME-3 needed? scene()->update();
4608 QRectF VymModel::getTotalBBox() //FIXME-2
4612 for (int i=0;i<rootItem->branchCount(); i++)
4613 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4618 //////////////////////////////////////////////
4619 // Selection related
4620 //////////////////////////////////////////////
4622 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4627 QItemSelectionModel* VymModel::getSelectionModel()
4632 void VymModel::setSelectionBlocked (bool b)
4637 selection.unblock();
4640 bool VymModel::isSelectionBlocked()
4642 return selection.isBlocked();
4645 bool VymModel::select ()
4647 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4649 TreeItem *item = getItem (index);
4650 return select (item->getLMO() );
4653 bool VymModel::select (const QString &s)
4655 TreeItem *ti=findBySelectString(s);
4665 bool VymModel::select (LinkableMapObj *lmo)
4667 QItemSelection oldsel=selModel->selection();
4670 return select (lmo->getTreeItem() );
4675 bool VymModel::select (TreeItem *ti)
4679 QModelIndex ix=index(ti);
4680 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4681 ti->setLastSelectedBranch();
4687 void VymModel::unselect()
4689 selModel->clearSelection();
4692 void VymModel::reselect()
4694 selection.reselect();
4697 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4699 LinkableMapObj *lmo=getSelectedLMO();
4700 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4703 void VymModel::emitNoteHasChanged (TreeItem *ti)
4705 QModelIndex ix=index(ti);
4706 emit (noteHasChanged (ix) );
4709 void VymModel::emitDataHasChanged (TreeItem *ti)
4711 QModelIndex ix=index(ti);
4712 emit (dataHasChanged (ix) );
4716 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4719 if (selection.select(lmo))
4721 //selection.update();
4722 sendSelection (); // FIXME-4 VM use signal
4726 void VymModel::selectInt (TreeItem *ti)
4728 if (selection.select(lmo))
4730 //selection.update();
4731 sendSelection (); // FIXME-4 VM use signal
4736 void VymModel::selectNextBranchInt()
4738 BranchItem *bi=getSelectedBranchItem();
4741 TreeItem *pi=bi->parent();
4745 if (i<pi->branchCount() )
4747 // select previous branch with same parent
4749 select (pi->getBranchNum(i));
4757 void VymModel::selectPrevBranchInt()
4760 BranchItem *bi=getSelectedBranchItem();
4763 BranchItem *pi=(BranchItem*)bi->parent();
4769 // select previous branch with same parent
4770 bi=pi->getBranchNum(i-1);
4775 while (bi->branchCount() >0)
4776 bi=bi->getLastBranch();
4779 // Try to select last branch in parent pi2 previous to own parent pi
4781 TreeItem *pi2=pi->parent();
4792 void VymModel::selectAboveBranchInt()
4794 BranchItem *bi=getSelectedBranchItem();
4797 BranchItem *newbi=NULL;
4798 BranchItem *pi=(BranchItem*)bi->parent();
4802 // goto previous branch with same parent
4803 newbi=pi->getBranchNum(i-1);
4804 while (newbi->branchCount() >0 )
4805 newbi=newbi->getLastBranch();
4809 if (newbi==rootItem)
4810 // already at top branch (resp. mapcenter)
4816 void VymModel::selectBelowBranchInt()
4818 BranchItem *bi=getSelectedBranchItem();
4821 BranchItem *newbi=NULL;
4823 if (bi->branchCount() >0)
4824 newbi=bi->getFirstBranch();
4831 pi=(BranchItem*)bi->parent();
4833 if (pi->branchCount()-1 > i)
4835 newbi=(BranchItem*)pi->getBranchNum(i+1);
4840 // look for siblings of myself
4841 // or parent, or parent of parent...
4852 void VymModel::selectUpperBranch()
4854 if (selection.isBlocked() ) return;
4856 BranchItem *bi=getSelectedBranchItem();
4857 if (bi && bi->isBranchLikeType())
4858 selectAboveBranchInt();
4861 void VymModel::selectLowerBranch()
4863 if (selection.isBlocked() ) return;
4865 BranchItem *bi=getSelectedBranchItem();
4866 if (bi && bi->isBranchLikeType())
4867 selectBelowBranchInt();
4871 void VymModel::selectLeftBranch()
4873 if (selection.isBlocked() ) return;
4875 QItemSelection oldsel=selModel->selection();
4878 BranchItem *selbi=getSelectedBranchItem();
4879 TreeItem::Type type=selbi->getType();
4882 if (type == TreeItem::MapCenter)
4884 QModelIndex ix=index(selbi);
4885 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4888 par=(BranchItem*)selbi->parent();
4889 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4892 if (type == TreeItem::Branch ||
4893 type == TreeItem::Image)
4895 QModelIndex ix=index (selbi->parent());
4896 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4901 if (type == TreeItem::Branch )
4903 cout << "VM::selLeft\n";
4904 selectLastSelectedBranch();
4912 void VymModel::selectRightBranch()
4914 if (selection.isBlocked() ) return;
4916 QItemSelection oldsel=selModel->selection();
4919 BranchItem *selbi=getSelectedBranchItem();
4920 TreeItem::Type type=selbi->getType();
4923 if (type==TreeItem::MapCenter)
4925 QModelIndex ix=index(selbi);
4926 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4929 par=(BranchItem*)selbi->parent();
4930 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4933 if ( type== TreeItem::Branch )
4935 selectLastSelectedBranch();
4941 if (type == TreeItem::Branch ||
4942 type == TreeItem::Image)
4944 cout << "VM::selRight\n";
4945 QModelIndex ix=index(selbi->parent());
4946 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4953 void VymModel::selectFirstBranch()
4955 TreeItem *ti=getSelectedBranchItem();
4958 TreeItem *par=ti->parent();
4960 TreeItem *ti2=par->getFirstBranch();
4964 ensureSelectionVisible();
4970 void VymModel::selectLastBranch()
4972 TreeItem *ti=getSelectedBranchItem();
4975 TreeItem *par=ti->parent();
4977 TreeItem *ti2=par->getLastBranch();
4981 ensureSelectionVisible();
4987 void VymModel::selectLastSelectedBranch()
4989 TreeItem *ti=getSelectedBranchItem();
4992 ti=ti->getLastSelectedBranch();
4993 if (ti) select (ti);
4997 void VymModel::selectParent()
4999 TreeItem *ti=getSelectedItem();
5007 ensureSelectionVisible();
5012 TreeItem::Type VymModel::selectionType()
5014 QModelIndexList list=selModel->selectedIndexes();
5015 if (list.isEmpty()) return TreeItem::Undefined;
5016 TreeItem *ti = getItem (list.first() );
5017 return ti->getType();
5021 LinkableMapObj* VymModel::getSelectedLMO()
5023 QModelIndexList list=selModel->selectedIndexes();
5024 if (!list.isEmpty() )
5026 TreeItem *ti = getItem (list.first() );
5027 TreeItem::Type type=ti->getType();
5028 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5030 return ti->getLMO();
5036 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5038 TreeItem *ti = getSelectedBranchItem();
5040 return (BranchObj*)ti->getLMO();
5045 BranchItem* VymModel::getSelectedBranchItem()
5047 QModelIndexList list=selModel->selectedIndexes();
5048 if (!list.isEmpty() )
5050 TreeItem *ti = getItem (list.first() );
5051 TreeItem::Type type=ti->getType();
5052 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5053 return (BranchItem*)ti;
5058 MapCenterItem* VymModel::getSelectedMapCenterItem()
5060 QModelIndexList list=selModel->selectedIndexes();
5061 if (!list.isEmpty() )
5063 TreeItem *ti = getItem (list.first() );
5064 TreeItem::Type type=ti->getType();
5065 if (ti->getType()==TreeItem::MapCenter)
5066 return (MapCenterItem*)ti;
5071 TreeItem* VymModel::getSelectedItem()
5073 QModelIndexList list=selModel->selectedIndexes();
5074 if (!list.isEmpty() )
5075 return getItem (list.first() );
5080 QModelIndex VymModel::getSelectedIndex()
5082 QModelIndexList list=selModel->selectedIndexes();
5083 if (list.isEmpty() )
5084 return QModelIndex();
5086 return list.first();
5089 FloatImageObj* VymModel::getSelectedFloatImage()
5091 return selection.getFloatImage();
5094 QString VymModel::getSelectString ()
5096 LinkableMapObj *lmo=getSelectedLMO();
5098 return getSelectString(lmo);
5103 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5105 if (!lmo) return QString();
5106 return getSelectString (lmo->getTreeItem() );
5109 QString VymModel::getSelectString (TreeItem *ti)
5113 if (ti->getType() == TreeItem::Branch ||
5114 ti->getType() == TreeItem::MapCenter)
5116 TreeItem *par=ti->parent();
5119 if (ti->depth() ==1)
5120 // Mainbranch, return
5121 s= "bo:" + QString("%1").arg(ti->num() );
5123 // Branch, call myself recursively
5124 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5128 int i=rootItem->num(ti);
5129 if (i>=0) s=QString("mc:%1").arg(i);