1 #include <QApplication>
7 #include "branchitem.h"
8 #include "mapcenteritem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
15 #include "mapcenterobj.h"
18 #include "selection.h"
21 #include "warningdialog.h"
22 #include "xml-freemind.h"
28 extern Main *mainWindow;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
34 extern QString clipboardDir;
35 extern QString clipboardFile;
36 extern bool clipboardEmpty;
38 extern ImageIO imageIO;
40 extern QString vymName;
41 extern QString vymVersion;
42 extern QDir vymBaseDir;
44 extern QDir lastImageDir;
45 extern QDir lastFileDir;
47 extern Settings settings;
51 int VymModel::mapNum=0; // make instance
55 // cout << "Const VymModel\n";
57 rootItem->setModel (this);
63 // cout << "Destr VymModel\n";
64 autosaveTimer->stop();
65 fileChangedTimer->stop();
69 void VymModel::clear()
71 selModel->clearSelection();
73 //QModelIndex ri=index(rootItem);
74 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
77 void VymModel::init ()
79 // We should have at least one map center to start with
80 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
85 // Also no scene yet (should not be needed anyway) FIXME-3 VM
98 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
99 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
100 mainWindow->updateHistory (undoSet);
103 makeTmpDirectories();
108 fileName=tr("unnamed");
110 blockReposition=false;
111 blockSaveState=false;
113 autosaveTimer=new QTimer (this);
114 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
116 fileChangedTimer=new QTimer (this);
117 fileChangedTimer->start(3000);
118 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
130 animationUse=settings.readBoolEntry("/animation/use",false);
131 animationTicks=settings.readNumEntry("/animation/ticks",10);
132 animationInterval=settings.readNumEntry("/animation/interval",50);
134 animationTimer=new QTimer (this);
135 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
138 defLinkColor=QColor (0,0,255);
139 defXLinkColor=QColor (180,180,180);
140 linkcolorhint=LinkableMapObj::DefaultColor;
141 linkstyle=LinkableMapObj::PolyParabel;
143 defXLinkColor=QColor (230,230,230);
145 hidemode=TreeItem::HideNone;
151 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
155 void VymModel::makeTmpDirectories()
157 // Create unique temporary directories
158 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
159 histPath = tmpMapDir+"/history";
165 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
170 bool VymModel::isRepositionBlocked()
172 return blockReposition;
175 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
177 //cout << "VM::updateActions \n";
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
199 case LinkableMapObj::Line:
202 case LinkableMapObj::Parabel:
205 case LinkableMapObj::PolyLine:
209 ls="StylePolyParabel";
213 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
215 if (linkcolorhint==LinkableMapObj::HeadingColor)
216 colhint=xml.attribut("linkColorHint","HeadingColor");
218 QString mapAttr=xml.attribut("version",vymVersion);
220 mapAttr+= xml.attribut("author",author) +
221 xml.attribut("comment",comment) +
222 xml.attribut("date",getDate()) +
223 xml.attribut("branchCount", QString().number(branchCount())) +
224 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
226 xml.attribut("linkStyle", ls ) +
227 xml.attribut("linkColor", defLinkColor.name() ) +
228 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
229 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
231 s+=xml.beginElement("vymmap",mapAttr);
234 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
235 //FIXME-2 not used any longer: standardFlagsDefault->resetUsedCounter();
237 // Reset the counters before saving
238 // TODO constr. of FIO creates lots of objects, better do this in some other way...
239 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
241 // Build xml recursivly
242 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
243 // Save all mapcenters as complete map, if saveSel not set
244 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
247 if (saveSel->getType()==TreeItem::Branch)
249 s+=saveSel->saveToDir(tmpdir,prefix,offset);
250 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
252 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
255 // Save local settings
256 s+=settings.getDataXML (destPath);
259 if (getSelectedItem() && !saveSel )
260 s+=xml.valueElement("select",getSelectString());
263 s+=xml.endElement("vymmap");
265 // FIXME-2 if (writeflags) standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
269 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
273 for (int i=0; i<rootItem->branchCount(); i++)
274 s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
278 void VymModel::setFilePath(QString fpath, QString destname)
280 if (fpath.isEmpty() || fpath=="")
287 filePath=fpath; // becomes absolute path
288 fileName=fpath; // gets stripped of path
289 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
291 // If fpath is not an absolute path, complete it
292 filePath=QDir(fpath).absPath();
293 fileDir=filePath.left (1+filePath.findRev ("/"));
295 // Set short name, too. Search from behind:
296 int i=fileName.findRev("/");
297 if (i>=0) fileName=fileName.remove (0,i+1);
299 // Forget the .vym (or .xml) for name of map
300 mapName=fileName.left(fileName.findRev(".",-1,true) );
304 void VymModel::setFilePath(QString fpath)
306 setFilePath (fpath,fpath);
309 QString VymModel::getFilePath()
314 QString VymModel::getFileName()
319 QString VymModel::getMapName()
324 QString VymModel::getDestPath()
329 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
331 ErrorCode err=success;
333 parseBaseHandler *handler;
337 case VymMap: handler=new parseVYMHandler; break;
338 case FreemindMap : handler=new parseFreemindHandler; break;
340 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
341 "Unknown FileType in VymModel::load()");
345 bool zipped_org=zipped;
349 selModel->clearSelection();
350 // FIXME-2 VM not needed??? model->setMapEditor(this);
351 // (map state is set later at end of load...)
354 BranchItem *bi=getSelectedBranchItem();
355 if (!bi) return aborted;
356 if (lmode==ImportAdd)
357 saveStateChangingPart(
360 QString("addMapInsert (%1)").arg(fname),
361 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
363 saveStateChangingPart(
366 QString("addMapReplace(%1)").arg(fname),
367 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
371 // Create temporary directory for packing
373 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
376 QMessageBox::critical( 0, tr( "Critical Load Error" ),
377 tr("Couldn't create temporary directory before load\n"));
382 err=unzipDir (tmpZipDir,fname);
392 // Look for mapname.xml
393 xmlfile= fname.left(fname.findRev(".",-1,true));
394 xmlfile=xmlfile.section( '/', -1 );
395 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
396 if (!mfile.exists() )
398 // mapname.xml does not exist, well,
399 // maybe someone renamed the mapname.vym file...
400 // Try to find any .xml in the toplevel
401 // directory of the .vym file
402 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
403 if (flist.count()==1)
405 // Only one entry, take this one
406 xmlfile=tmpZipDir + "/"+flist.first();
409 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
410 *it=tmpZipDir + "/" + *it;
411 // TODO Multiple entries, load all (but only the first one into this ME)
412 //mainWindow->fileLoadFromTmp (flist);
413 //returnCode=1; // Silently forget this attempt to load
414 qWarning ("MainWindow::load (fn) multimap found...");
417 if (flist.isEmpty() )
419 QMessageBox::critical( 0, tr( "Critical Load Error" ),
420 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
423 } //file doesn't exist
425 xmlfile=mfile.name();
428 QFile file( xmlfile);
430 // I am paranoid: file should exist anyway
431 // according to check in mainwindow.
434 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
435 tr(QString("Couldn't open map %1").arg(file.name())));
439 bool blockSaveStateOrg=blockSaveState;
440 blockReposition=true;
442 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
443 QXmlInputSource source( file);
444 QXmlSimpleReader reader;
445 reader.setContentHandler( handler );
446 reader.setErrorHandler( handler );
447 handler->setModel ( this);
450 // We need to set the tmpDir in order to load files with rel. path
455 tmpdir=fname.left(fname.findRev("/",-1));
456 handler->setTmpDir (tmpdir);
457 handler->setInputFile (file.name());
458 handler->setLoadMode (lmode);
459 bool ok = reader.parse( source );
460 blockReposition=false;
461 blockSaveState=blockSaveStateOrg;
462 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
466 reposition(); // FIXME-2 VM reposition the view instead...
473 autosaveTimer->stop();
476 // Reset timestamp to check for later updates of file
477 fileChangedTime=QFileInfo (destPath).lastModified();
480 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
481 tr( handler->errorProtocol() ) );
483 // Still return "success": the map maybe at least
484 // partially read by the parser
489 removeDir (QDir(tmpZipDir));
491 // Restore original zip state
498 ErrorCode VymModel::save (const SaveMode &savemode)
502 QString safeFilePath;
504 ErrorCode err=success;
508 mapFileName=mapName+".xml";
510 // use name given by user, even if he chooses .doc
511 mapFileName=fileName;
513 // Look, if we should zip the data:
516 QMessageBox mb( vymName,
517 tr("The map %1\ndid not use the compressed "
518 "vym file format.\nWriting it uncompressed will also write images \n"
519 "and flags and thus may overwrite files in the "
520 "given directory\n\nDo you want to write the map").arg(filePath),
521 QMessageBox::Warning,
522 QMessageBox::Yes | QMessageBox::Default,
524 QMessageBox::Cancel | QMessageBox::Escape);
525 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
526 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
527 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
530 case QMessageBox::Yes:
531 // save compressed (default file format)
534 case QMessageBox::No:
538 case QMessageBox::Cancel:
545 // First backup existing file, we
546 // don't want to add to old zip archives
550 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
552 QString backupFileName(destPath + "~");
553 QFile backupFile(backupFileName);
554 if (backupFile.exists() && !backupFile.remove())
556 QMessageBox::warning(0, tr("Save Error"),
557 tr("%1\ncould not be removed before saving").arg(backupFileName));
559 else if (!f.rename(backupFileName))
561 QMessageBox::warning(0, tr("Save Error"),
562 tr("%1\ncould not be renamed before saving").arg(destPath));
569 // Create temporary directory for packing
571 tmpZipDir=makeTmpDir (ok,"vym-zip");
574 QMessageBox::critical( 0, tr( "Critical Load Error" ),
575 tr("Couldn't create temporary directory before save\n"));
579 safeFilePath=filePath;
580 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
583 // Create mapName and fileDir
584 makeSubDirs (fileDir);
587 if (savemode==CompleteMap || selection.isEmpty())
590 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
593 autosaveTimer->stop();
598 if (selectionType()==TreeItem::Image)
601 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
602 // TODO take care of multiselections
605 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
608 qWarning ("ME::saveStringToDisk failed!");
614 if (err==success) err=zipDir (tmpZipDir,destPath);
617 removeDir (QDir(tmpZipDir));
619 // Restore original filepath outside of tmp zip dir
620 setFilePath (safeFilePath);
624 fileChangedTime=QFileInfo (destPath).lastModified();
628 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
630 QString pathDir=path.left(path.findRev("/"));
636 // We need to parse saved XML data
637 parseVYMHandler handler;
638 QXmlInputSource source( file);
639 QXmlSimpleReader reader;
640 reader.setContentHandler( &handler );
641 reader.setErrorHandler( &handler );
642 handler.setModel ( this);
643 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
644 if (undoSel.isEmpty())
648 handler.setLoadMode (NewMap);
652 handler.setLoadMode (ImportReplace);
654 blockReposition=true;
655 bool ok = reader.parse( source );
656 blockReposition=false;
659 // This should never ever happen
660 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
661 handler.errorProtocol());
664 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
667 void VymModel::addMapInsertInt (const QString &path, int pos)
669 /* FIXME-2 addMapInsertInt not ported yet
670 BranchObj *sel=getSelectedBranch();
673 QString pathDir=path.left(path.findRev("/"));
679 // We need to parse saved XML data
680 parseVYMHandler handler;
681 QXmlInputSource source( file);
682 QXmlSimpleReader reader;
683 reader.setContentHandler( &handler );
684 reader.setErrorHandler( &handler );
685 handler.setModel (this);
686 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
687 handler.setLoadMode (ImportAdd);
688 blockReposition=true;
689 bool ok = reader.parse( source );
690 blockReposition=false;
693 // This should never ever happen
694 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
695 handler.errorProtocol());
697 if (sel->getDepth()>0)
698 sel->getLastBranch()->linkTo (sel,pos);
700 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
705 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
707 TreeItem *fi=createImage();
710 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
718 void VymModel::loadFloatImage () // FIXME-2
721 BranchObj *bo=getSelectedBranch();
725 Q3FileDialog *fd=new Q3FileDialog( NULL);
726 fd->setMode (Q3FileDialog::ExistingFiles);
727 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
728 ImagePreview *p =new ImagePreview (fd);
729 fd->setContentsPreviewEnabled( TRUE );
730 fd->setContentsPreview( p, p );
731 fd->setPreviewMode( Q3FileDialog::Contents );
732 fd->setCaption(vymName+" - " +tr("Load image"));
733 fd->setDir (lastImageDir);
736 if ( fd->exec() == QDialog::Accepted )
738 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
739 lastImageDir=QDir (fd->dirPath());
742 for (int j=0; j<fd->selectedFiles().count(); j++)
744 s=fd->selectedFiles().at(j);
745 fio=loadFloatImageInt (s);
748 (LinkableMapObj*)fio,
751 QString ("loadImage (%1)").arg(s ),
752 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
755 // TODO loadFIO error handling
756 qWarning ("Failed to load "+s);
765 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
770 void VymModel::saveFloatImage ()
772 FloatImageObj *fio=selection.getFloatImage();
775 QFileDialog *fd=new QFileDialog( NULL);
776 fd->setFilters (imageIO.getFilters());
777 fd->setCaption(vymName+" - " +tr("Save image"));
778 fd->setFileMode( QFileDialog::AnyFile );
779 fd->setDirectory (lastImageDir);
780 // fd->setSelection (fio->getOriginalFilename());
784 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
786 fn=fd->selectedFiles().at(0);
787 if (QFile (fn).exists() )
789 QMessageBox mb( vymName,
790 tr("The file %1 exists already.\n"
791 "Do you want to overwrite it?").arg(fn),
792 QMessageBox::Warning,
793 QMessageBox::Yes | QMessageBox::Default,
794 QMessageBox::Cancel | QMessageBox::Escape,
795 QMessageBox::NoButton );
797 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
798 mb.setButtonText( QMessageBox::No, tr("Cancel"));
801 case QMessageBox::Yes:
804 case QMessageBox::Cancel:
811 saveFloatImageInt (fio,fd->selectedFilter(),fn );
818 void VymModel::importDirInt(BranchObj *dst, QDir d)
820 /* FIXME-2 importDirInt not ported yet
821 BranchObj *bo=getSelectedBranch();
824 // Traverse directories
825 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
826 QFileInfoList list = d.entryInfoList();
829 for (int i = 0; i < list.size(); ++i)
832 if (fi.fileName() != "." && fi.fileName() != ".." )
835 bo=dst->getLastBranch();
836 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
837 bi->setHeading (fi.fileName() ); // FIXME-3 check this
838 bo->setColor (QColor("blue"));
840 if ( !d.cd(fi.fileName()) )
841 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
844 // Recursively add subdirs
851 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
852 list = d.entryInfoList();
854 for (int i = 0; i < list.size(); ++i)
858 bo=dst->getLastBranch();
859 bo->setHeading (fi.fileName() );
860 bo->setColor (QColor("black"));
861 if (fi.fileName().right(4) == ".vym" )
862 bo->setVymLink (fi.filePath());
868 void VymModel::importDirInt (const QString &s) // FIXME-2
871 BranchObj *bo=getSelectedBranch();
874 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
882 void VymModel::importDir() //FIXME-2
885 BranchObj *bo=getSelectedBranch();
889 filters <<"VYM map (*.vym)";
890 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
891 fd->setMode (QFileDialog::DirectoryOnly);
892 fd->setFilters (filters);
893 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
897 if ( fd->exec() == QDialog::Accepted )
899 importDirInt (fd->selectedFile() );
901 //FIXME-3 VM needed? scene()->update();
908 void VymModel::autosave()
913 cout << "VymModel::autosave rejected due to missing filePath\n";
916 QDateTime now=QDateTime().currentDateTime();
918 // Disable autosave, while we have gone back in history
919 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
920 if (redosAvail>0) return;
922 // Also disable autosave for new map without filename
923 if (filePath.isEmpty()) return;
926 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
928 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
929 mainWindow->fileSave (this);
932 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
937 void VymModel::fileChanged()
939 // Check if file on disk has changed meanwhile
940 if (!filePath.isEmpty())
942 QDateTime tmod=QFileInfo (filePath).lastModified();
943 if (tmod>fileChangedTime)
945 // FIXME-2 VM switch to current mapeditor and finish lineedits...
946 QMessageBox mb( vymName,
947 tr("The file of the map on disk has changed:\n\n"
948 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
949 QMessageBox::Question,
951 QMessageBox::Cancel | QMessageBox::Default,
952 QMessageBox::NoButton );
954 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
955 mb.setButtonText( QMessageBox::No, tr("Ignore"));
958 case QMessageBox::Yes:
960 load (filePath,NewMap,fileType);
961 case QMessageBox::Cancel:
962 fileChangedTime=tmod; // allow autosave to overwrite newer file!
968 bool VymModel::isDefault()
973 void VymModel::makeDefault()
979 bool VymModel::hasChanged()
984 void VymModel::setChanged()
987 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
991 latestAddedItem=NULL;
995 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
998 if (!lmo) return QString("Error: NULL has no name!");
1000 if ((typeid(*lmo) == typeid(BranchObj) ||
1001 typeid(*lmo) == typeid(MapCenterObj)))
1004 s=lmo->getTreeItem()->getHeading();
1005 if (s=="") s="unnamed";
1006 return QString("branch (%1)").arg(s);
1008 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1009 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1010 return QString("Unknown type has no name!");
1014 QString VymModel::getObjectName (const TreeItem *ti)
1017 if (!ti) return QString("Error: NULL has no name!");
1019 if (ti->isBranchLikeType() )
1022 if (s=="") s="unnamed";
1023 return QString("branch (%1)").arg(s);
1025 /* FIXME-2 move floatimage to TreeModel first
1026 if (type==TreeItem::Image)
1027 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1029 return QString("Unknown type has no name!");
1032 void VymModel::redo()
1034 // Can we undo at all?
1035 if (redosAvail<1) return;
1037 bool blockSaveStateOrg=blockSaveState;
1038 blockSaveState=true;
1042 if (undosAvail<stepsTotal) undosAvail++;
1044 if (curStep>stepsTotal) curStep=1;
1045 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1046 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1047 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1048 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1049 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1050 QString version=undoSet.readEntry ("/history/version");
1052 /* TODO Maybe check for version, if we save the history
1053 if (!checkVersion(version))
1054 QMessageBox::warning(0,tr("Warning"),
1055 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1058 // Find out current undo directory
1059 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1063 cout << "VymModel::redo() begin\n";
1064 cout << " undosAvail="<<undosAvail<<endl;
1065 cout << " redosAvail="<<redosAvail<<endl;
1066 cout << " curStep="<<curStep<<endl;
1067 cout << " ---------------------------"<<endl;
1068 cout << " comment="<<comment.toStdString()<<endl;
1069 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1070 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1071 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1072 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1073 cout << " ---------------------------"<<endl<<endl;
1076 // select object before redo
1077 if (!redoSelection.isEmpty())
1078 select (redoSelection);
1081 parseAtom (redoCommand);
1084 blockSaveState=blockSaveStateOrg;
1086 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1087 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1088 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1089 undoSet.writeSettings(histPath);
1091 mainWindow->updateHistory (undoSet);
1094 /* TODO remove testing
1095 cout << "ME::redo() end\n";
1096 cout << " undosAvail="<<undosAvail<<endl;
1097 cout << " redosAvail="<<redosAvail<<endl;
1098 cout << " curStep="<<curStep<<endl;
1099 cout << " ---------------------------"<<endl<<endl;
1105 bool VymModel::isRedoAvailable()
1107 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1113 void VymModel::undo()
1115 // Can we undo at all?
1116 if (undosAvail<1) return;
1118 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1120 bool blockSaveStateOrg=blockSaveState;
1121 blockSaveState=true;
1123 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1124 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1125 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1126 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1127 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1128 QString version=undoSet.readEntry ("/history/version");
1130 /* TODO Maybe check for version, if we save the history
1131 if (!checkVersion(version))
1132 QMessageBox::warning(0,tr("Warning"),
1133 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1136 // Find out current undo directory
1137 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1139 // select object before undo
1140 if (!undoSelection.isEmpty())
1141 select (undoSelection);
1145 cout << "VymModel::undo() begin\n";
1146 cout << " undosAvail="<<undosAvail<<endl;
1147 cout << " redosAvail="<<redosAvail<<endl;
1148 cout << " curStep="<<curStep<<endl;
1149 cout << " ---------------------------"<<endl;
1150 cout << " comment="<<comment.toStdString()<<endl;
1151 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1152 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1153 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1154 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1155 cout << " ---------------------------"<<endl<<endl;
1157 parseAtom (undoCommand);
1162 if (curStep<1) curStep=stepsTotal;
1166 blockSaveState=blockSaveStateOrg;
1167 /* TODO remove testing
1168 cout << "VymModel::undo() end\n";
1169 cout << " undosAvail="<<undosAvail<<endl;
1170 cout << " redosAvail="<<redosAvail<<endl;
1171 cout << " curStep="<<curStep<<endl;
1172 cout << " ---------------------------"<<endl<<endl;
1175 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1176 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1177 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1178 undoSet.writeSettings(histPath);
1180 mainWindow->updateHistory (undoSet);
1183 emitShowSelection();
1186 bool VymModel::isUndoAvailable()
1188 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1194 void VymModel::gotoHistoryStep (int i)
1196 // Restore variables
1197 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1198 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1200 if (i<0) i=undosAvail+redosAvail;
1202 // Clicking above current step makes us undo things
1205 for (int j=0; j<undosAvail-i; j++) undo();
1208 // Clicking below current step makes us redo things
1210 for (int j=undosAvail; j<i; j++)
1212 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1216 // And ignore clicking the current row ;-)
1220 QString VymModel::getHistoryPath()
1222 QString histName(QString("history-%1").arg(curStep));
1223 return (tmpMapDir+"/"+histName);
1226 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1228 sendData(redoCom); //FIXME-3 testing
1233 if (blockSaveState) return;
1235 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1237 // Find out current undo directory
1238 if (undosAvail<stepsTotal) undosAvail++;
1240 if (curStep>stepsTotal) curStep=1;
1242 QString backupXML="";
1243 QString histDir=getHistoryPath();
1244 QString bakMapPath=histDir+"/map.xml";
1246 // Create histDir if not available
1249 makeSubDirs (histDir);
1251 // Save depending on how much needs to be saved
1253 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1255 QString undoCommand="";
1256 if (savemode==UndoCommand)
1258 undoCommand=undoCom;
1260 else if (savemode==PartOfMap )
1262 undoCommand=undoCom;
1263 undoCommand.replace ("PATH",bakMapPath);
1267 if (!backupXML.isEmpty())
1268 // Write XML Data to disk
1269 saveStringToDisk (bakMapPath,backupXML);
1271 // We would have to save all actions in a tree, to keep track of
1272 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1275 // Write the current state to disk
1276 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1277 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1278 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1279 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1280 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1282 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1283 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1284 undoSet.setEntry (QString("/history/version"),vymVersion);
1285 undoSet.writeSettings(histPath);
1289 // TODO remove after testing
1290 //cout << " into="<< histPath.toStdString()<<endl;
1291 cout << " stepsTotal="<<stepsTotal<<
1292 ", undosAvail="<<undosAvail<<
1293 ", redosAvail="<<redosAvail<<
1294 ", curStep="<<curStep<<endl;
1295 cout << " ---------------------------"<<endl;
1296 cout << " comment="<<comment.toStdString()<<endl;
1297 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1298 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1299 cout << " redoCom="<<redoCom.toStdString()<<endl;
1300 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1301 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1302 cout << " ---------------------------"<<endl;
1305 mainWindow->updateHistory (undoSet);
1311 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1313 // save the selected part of the map, Undo will replace part of map
1314 QString undoSelection="";
1316 undoSelection=getSelectString(undoSel);
1318 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1319 QString redoSelection="";
1321 redoSelection=getSelectString(undoSel);
1323 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1326 saveState (PartOfMap,
1327 undoSelection, "addMapReplace (\"PATH\")",
1333 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1337 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1340 QString undoSelection=getSelectString (redoSel->parent() );
1341 QString redoSelection=getSelectString(redoSel);
1342 if (redoSel->getType()==TreeItem::Branch)
1344 // save the selected branch of the map, Undo will insert part of map
1345 saveState (PartOfMap,
1346 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1347 redoSelection, "delete ()",
1354 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1356 // "Normal" savestate: save commands, selections and comment
1357 // so just save commands for undo and redo
1358 // and use current selection
1360 QString redoSelection="";
1361 if (redoSel) redoSelection=getSelectString(redoSel);
1362 QString undoSelection="";
1363 if (undoSel) undoSelection=getSelectString(undoSel);
1365 saveState (UndoCommand,
1372 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1374 // "Normal" savestate: save commands, selections and comment
1375 // so just save commands for undo and redo
1376 // and use current selection
1377 saveState (UndoCommand,
1384 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1386 // "Normal" savestate applied to model (no selection needed):
1387 // save commands and comment
1388 saveState (UndoCommand,
1396 QGraphicsScene* VymModel::getScene ()
1401 TreeItem* VymModel::findBySelectString(QString s)
1403 if (s.isEmpty() ) return NULL;
1405 // Old maps don't have multiple mapcenters and don't save full path
1406 if (s.left(2) !="mc")
1409 QStringList parts=s.split (",");
1412 TreeItem *ti=rootItem;
1414 while (!parts.isEmpty() )
1416 typ=parts.first().left(2);
1417 n=parts.first().right(parts.first().length() - 3).toInt();
1418 parts.removeFirst();
1419 if (typ=="mc" || typ=="bo")
1420 ti=ti->getBranchNum (n);
1424 ti=ti->getImageNum (n);
1430 TreeItem* VymModel::findID (const QString &s)
1433 for (int i=0; i<rootItem->branchCount(); i++)
1435 ti=rootItem->getBranchNum(i)->findID (s);
1441 //////////////////////////////////////////////
1443 //////////////////////////////////////////////
1444 void VymModel::setVersion (const QString &s)
1449 void VymModel::setAuthor (const QString &s)
1452 QString ("setMapAuthor (\"%1\")").arg(author),
1453 QString ("setMapAuthor (\"%1\")").arg(s),
1454 QString ("Set author of map to \"%1\"").arg(s)
1459 QString VymModel::getAuthor()
1464 void VymModel::setComment (const QString &s)
1467 QString ("setMapComment (\"%1\")").arg(comment),
1468 QString ("setMapComment (\"%1\")").arg(s),
1469 QString ("Set comment of map")
1474 QString VymModel::getComment ()
1479 QString VymModel::getDate ()
1481 return QDate::currentDate().toString ("yyyy-MM-dd");
1484 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1487 BranchItem *cur=NULL;
1488 BranchItem *prev=NULL;
1499 void VymModel::setHeading(const QString &s)
1501 BranchItem *selbi=getSelectedBranchItem();
1506 "setHeading (\""+selbi->getHeading()+"\")",
1508 "setHeading (\""+s+"\")",
1509 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1510 selbi->setHeading(s );
1511 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1514 // selection.update(); //FIXME-4
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 emitShowSelection();
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)
1593 TreeItem *selti=getSelectedItem();
1596 QString oldurl=selti->getURL();
1597 selti->setURL (url);
1600 QString ("setURL (\"%1\")").arg(oldurl),
1602 QString ("setURL (\"%1\")").arg(url),
1603 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1606 emitDataHasChanged (selti);
1607 emitShowSelection();
1611 QString VymModel::getURL()
1613 TreeItem *selti=getSelectedItem();
1615 return selti->getURL();
1620 QStringList VymModel::getURLs()
1623 BranchItem *cur=getSelectedBranchItem();
1624 BranchItem *prev=NULL;
1629 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1630 cur=next (cur,prev,d);
1635 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1637 FloatImageObj *fio=selection.getFloatImage();
1640 TreeItem *dst=findBySelectString (dstString);
1641 if (dst && dst->isBranchLikeType() )
1643 TreeItem *dstPar=dst->parent();
1644 QString parString=getSelectString(dstPar);
1645 QString fioPreSelectString=getSelectString(fio);
1646 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1647 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1649 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1650 fio=((BranchObj*)dst)->getLastFloatImage();
1655 getSelectString(fio),
1656 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1658 QString ("linkTo (\"%1\")").arg(dstString),
1659 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1665 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1668 BranchObj *bo=getSelectedBranch();
1671 QString s=bo->getFrameTypeName();
1672 bo->setFrameType (t);
1673 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1674 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1681 void VymModel::setFrameType(const QString &s) //FIXME-2
1684 BranchObj *bo=getSelectedBranch();
1687 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1688 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1689 bo->setFrameType (s);
1696 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1699 BranchObj *bo=getSelectedBranch();
1702 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1703 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1704 bo->setFramePenColor (c);
1709 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1712 BranchObj *bo=getSelectedBranch();
1715 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1716 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1717 bo->setFrameBrushColor (c);
1721 void VymModel::setFramePadding (const int &i) //FIXME-2
1724 BranchObj *bo=getSelectedBranch();
1727 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1728 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1729 bo->setFramePadding (i);
1736 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1739 BranchObj *bo=getSelectedBranch();
1742 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1743 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1744 bo->setFrameBorderWidth (i);
1751 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1754 BranchObj *bo=getSelectedBranch();
1757 QString u= b ? "false" : "true";
1758 QString r=!b ? "false" : "true";
1762 QString("setIncludeImagesVertically (%1)").arg(u),
1764 QString("setIncludeImagesVertically (%1)").arg(r),
1765 QString("Include images vertically in %1").arg(getObjectName(bo))
1767 bo->setIncludeImagesVer(b);
1772 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1775 BranchObj *bo=getSelectedBranch();
1778 QString u= b ? "false" : "true";
1779 QString r=!b ? "false" : "true";
1783 QString("setIncludeImagesHorizontally (%1)").arg(u),
1785 QString("setIncludeImagesHorizontally (%1)").arg(r),
1786 QString("Include images horizontally in %1").arg(getObjectName(bo))
1788 bo->setIncludeImagesHor(b);
1794 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1797 LinkableMapObj *sel=getSelectedLMO();
1799 (selectionType() == TreeItem::Branch ||
1800 selectionType() == TreeItem::MapCenter ||
1801 selectionType() == TreeItem::Image ))
1803 QString u= b ? "false" : "true";
1804 QString r=!b ? "false" : "true";
1808 QString("setHideLinkUnselected (%1)").arg(u),
1810 QString("setHideLinkUnselected (%1)").arg(r),
1811 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1813 sel->setHideLinkUnselected(b);
1818 void VymModel::setHideExport(bool b)
1820 BranchItem *bi=getSelectedBranchItem();
1823 bi->setHideInExport (b);
1824 QString u= b ? "false" : "true";
1825 QString r=!b ? "false" : "true";
1829 QString ("setHideExport (%1)").arg(u),
1831 QString ("setHideExport (%1)").arg(r),
1832 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1836 // selection.update();
1837 // FIXME-3 VM needed? scene()->update();
1841 void VymModel::toggleHideExport()
1843 BranchItem *selbi=getSelectedBranchItem();
1845 setHideExport ( !selbi->hideInExport() );
1849 void VymModel::copy()
1851 TreeItem *selti=getSelectedItem();
1853 (selti->getType() == TreeItem::Branch ||
1854 selti->getType() == TreeItem::MapCenter ||
1855 selti->getType() == TreeItem::Image ))
1857 if (redosAvail == 0)
1860 QString s=getSelectString(selti);
1861 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1862 curClipboard=curStep;
1865 // Copy also to global clipboard, because we are at last step in history
1866 QString bakMapName(QString("history-%1").arg(curStep));
1867 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1868 copyDir (bakMapDir,clipboardDir );
1870 clipboardEmpty=false;
1876 void VymModel::pasteNoSave(const int &n)
1878 bool old=blockSaveState;
1879 blockSaveState=true;
1880 bool zippedOrg=zipped;
1881 if (redosAvail > 0 || n!=0)
1883 // Use the "historical" buffer
1884 QString bakMapName(QString("history-%1").arg(n));
1885 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1886 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1888 // Use the global buffer
1889 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1894 void VymModel::paste()
1896 BranchItem *selbi=getSelectedBranchItem();
1899 saveStateChangingPart(
1902 QString ("paste (%1)").arg(curClipboard),
1903 QString("Paste to %1").arg( getObjectName(selbi))
1910 void VymModel::cut()
1912 TreeItem *selti=getSelectedItem();
1913 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1921 void VymModel::moveUp()
1923 BranchItem *selbi=getSelectedBranchItem();
1926 if (!selbi->canMoveUp()) return;
1927 QString oldsel=getSelectString();
1928 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1930 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1934 void VymModel::moveDown()
1936 BranchItem *selbi=getSelectedBranchItem();
1939 if (!selbi->canMoveDown()) return;
1940 QString oldsel=getSelectString();
1941 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1943 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1947 void VymModel::sortChildren() // FIXME-2 not implemented yet
1950 BranchObj* bo=getSelectedBranch();
1953 if(treeItem->branchCount()>1)
1955 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1958 emitShowSelection();
1964 MapCenterItem* VymModel::createMapCenter()
1966 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
1971 BranchItem* VymModel::createBranch()
1973 BranchItem *selbi=getSelectedBranchItem();
1975 return addNewBranchInt (selbi,-2);
1980 TreeItem* VymModel::createImage() //FIXME-2
1983 BranchObj *bo=getSelectedBranch();
1986 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1989 QList<QVariant> cData;
1990 cData << "VM:createImage" << "undef"<<"undef";
1991 TreeItem *parti=bo->getTreeItem();
1992 TreeItem *ti=new TreeItem (cData,parti);
1993 ti->setLMO (newfio);
1994 ti->setType (TreeItem::Image);
1995 parti->appendChild (ti);
1999 newfio->setTreeItem (ti);
2000 select (newfio); // FIXME-2 VM really needed here?
2008 MapCenterItem* VymModel::addMapCenter ()
2010 MapCenterItem *mci=addMapCenter (contextPos);
2011 //FIXME-3 selection.select (mco);
2013 emitShowSelection();
2018 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2019 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2024 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2028 QModelIndex parix=index(rootItem);
2030 int n=rootItem->branchCount();
2032 emit (layoutAboutToBeChanged() );
2033 beginInsertRows (parix,n,n+1);
2035 QList<QVariant> cData;
2036 cData << "VM:addMapCenter" << "undef"<<"undef";
2037 MapCenterItem *mci=new MapCenterItem (cData);
2038 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2039 rootItem->appendChild (mci);
2042 emit (layoutChanged() );
2045 BranchObj *newbo=mci->createMapObj(mapScene);
2049 if (!mci->getHeading().isEmpty() )
2051 newbo->updateHeading();
2052 newbo->setColor (headingColor);
2056 //newbo->updateLink(); //FIXME-3
2059 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2060 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2061 mci->setLMO (mapCenter);
2062 mapCenter->updateHeading();
2063 mapCenter->move (absPos);
2064 mapCenter->setVisibility (true);
2065 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2070 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) //FIXME-4 simplify...
2072 // Depending on pos:
2073 // -3 insert in children of parent above selection
2074 // -2 add branch to selection
2075 // -1 insert in children of parent below selection
2076 // 0..n insert in children of parent at pos
2079 QList<QVariant> cData;
2080 cData << "new" << "undef"<<"undef";
2085 BranchItem *newbi=new BranchItem (cData);
2086 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2088 emit (layoutAboutToBeChanged() );
2094 n=parbi->childCount();
2095 beginInsertRows (parix,n,n+1);
2096 parbi->appendChild (newbi);
2100 // insert below selection
2101 parbi=(BranchItem*)dst->parent();
2103 n=dst->childNumber()+1;
2104 beginInsertRows (parix,n,n);
2105 parbi->insertBranch(n,newbi);
2109 // insert above selection
2110 parbi=(BranchItem*)dst->parent();
2112 n=dst->childNumber();
2113 beginInsertRows (parix,n,n);
2114 parbi->insertBranch(n,newbi);
2117 emit (layoutChanged() );
2119 // save scroll state. If scrolled, automatically select
2120 // new branch in order to tmp unscroll parent...
2121 newbi->createMapObj(mapScene);
2126 BranchItem* VymModel::addNewBranch(int pos)
2128 // Different meaning than num in addNewBranchInt!
2132 BranchItem *newbi=NULL;
2133 BranchItem *selbi=getSelectedBranchItem();
2137 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2140 newbi=addNewBranchInt (selbi,pos-2);
2148 QString ("addBranch (%1)").arg(pos),
2149 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2152 // selection.update(); FIXME-3
2153 latestAddedItem=newbi;
2154 // In Network mode, the client needs to know where the new branch is,
2155 // so we have to pass on this information via saveState.
2156 // TODO: Get rid of this positioning workaround
2157 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2158 sendData ("selectLatestAdded ()");
2159 sendData (QString("move %1").arg(ps));
2168 BranchItem* VymModel::addNewBranchBefore() //FIXME-0
2170 BranchItem *newbi=NULL;
2171 BranchItem *selbi=getSelectedBranchItem();
2172 if (selbi && selbi->getType()==TreeItem::Branch)
2173 // We accept no MapCenter here, so we _have_ a parent
2175 //QPointF p=bo->getRelPos();
2178 // add below selection
2179 newbi=addNewBranchInt (selbi,-1);
2183 //newbi->move2RelPos (p);
2185 // Move selection to new branch
2186 relinkBranch (selbi,newbi,0);
2188 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2189 QString ("Add branch before %1").arg(getObjectName(selbi)));
2191 // FIXME-3 needed? reposition();
2192 // selection.update(); FIXME-3
2195 //FIXME-3 needed? latestSelectionString=selection.getSelectString();
2199 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2203 emit (layoutAboutToBeChanged() );
2204 BranchItem *branchpi=(BranchItem*)branch->parent();
2205 // Remove at current position
2206 int n=branch->childNum();
2207 beginRemoveRows (index(branchpi),n,n);
2208 branchpi->removeChild (n);
2211 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2213 // Append as last branch to dst
2214 if (dst->branchCount()==0)
2217 n=dst->getFirstBranch()->childNumber();
2218 beginInsertRows (index(dst),n+pos,n+pos);
2219 dst->insertBranch (pos,branch);
2222 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2223 emit (layoutChanged() );
2224 reposition(); // both for moveUp/Down and relinking
2231 void VymModel::deleteSelection()
2233 BranchItem *selbi=getSelectedBranchItem();
2237 TreeItem *pi=selbi->parent();
2238 QModelIndex parentIndex=index(pi);
2240 if (selbi->isBranchLikeType() )
2243 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2245 emit (layoutAboutToBeChanged() );
2247 int n=selbi->childNum();
2248 beginRemoveRows (parentIndex,n,n);
2249 removeRows (n,1,parentIndex);
2252 emitShowSelection();
2255 emit (layoutChanged() );
2258 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2263 BranchObj* par=(BranchObj*)fio->getParObj();
2264 saveStateChangingPart(
2268 QString("Delete %1").arg(getObjectName(fio))
2271 par->removeFloatImage(fio);
2274 emitShowSelection();
2280 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2284 BranchObj *bo=getSelectedBranch();
2288 par=(BranchObj*)(bo->getParObj());
2290 // Don't use this on mapcenter
2293 // Check if we have childs at all to keep
2294 if (bo->getTreeItem()->branchCount()==0)
2300 QPointF p=bo->getRelPos();
2301 saveStateChangingPart(
2304 "deleteKeepChildren ()",
2305 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2308 QString sel=getSelectString(bo);
2310 par->removeBranchHere(bo);
2313 getSelectedBranch()->move2RelPos (p);
2318 void VymModel::deleteChildren() //FIXME-2 VM still missing
2322 BranchObj *bo=getSelectedBranch();
2325 saveStateChangingPart(
2328 "deleteChildren ()",
2329 QString( "Remove children of branch %1").arg(getObjectName(bo))
2331 bo->removeChildren();
2337 bool VymModel::scrollBranch(BranchItem *bi)
2341 if (bi->isScrolled()) return false;
2342 if (bi->branchCount()==0) return false;
2343 if (bi->depth()==0) return false;
2344 if (bi->toggleScroll())
2351 QString ("%1 ()").arg(u),
2353 QString ("%1 ()").arg(r),
2354 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2356 emitDataHasChanged(bi);
2358 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2365 bool VymModel::unscrollBranch(BranchItem *bi)
2369 if (!bi->isScrolled()) return false;
2370 if (bi->branchCount()==0) return false;
2371 if (bi->depth()==0) return false;
2378 QString ("%1 ()").arg(u),
2380 QString ("%1 ()").arg(r),
2381 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2384 emitDataHasChanged(bi);
2387 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2393 void VymModel::toggleScroll()
2395 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2396 if (bi && bi->isBranchLikeType() )
2398 if (bi->isScrolled())
2399 unscrollBranch (bi);
2403 // saveState is called in above functions
2406 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2410 BranchObj *bo=getSelectedBranch();
2416 if (bo->isScrolled()) unscrollBranch (bo);
2423 void VymModel::emitExpandAll()
2425 emit (expandAll() );
2428 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2430 BranchItem *bi=getSelectedBranchItem();
2434 if (bi->isActiveStandardFlag(name))
2446 QString("%1 (\"%2\")").arg(u).arg(name),
2448 QString("%1 (\"%2\")").arg(r).arg(name),
2449 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2450 bi->toggleStandardFlag (name, master);
2456 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2459 BranchObj *bo=getSelectedBranch();
2462 FloatImageObj *fio=bo->addFloatImage();
2464 fio->setOriginalFilename("No original filename (image added by dropevent)");
2465 QString s=getSelectString(bo);
2466 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2467 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2469 // FIXME-3 VM needed? scene()->update();
2475 void VymModel::colorBranch (QColor c) //FIXME-2
2478 BranchObj *bo=getSelectedBranch();
2483 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2485 QString ("colorBranch (\"%1\")").arg(c.name()),
2486 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2488 bo->setColor(c); // color branch
2493 void VymModel::colorSubtree (QColor c) //FIXME-2
2496 BranchObj *bo=getSelectedBranch();
2499 saveStateChangingPart(
2502 QString ("colorSubtree (\"%1\")").arg(c.name()),
2503 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2505 bo->setColorSubtree (c); // color links, color children
2510 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2513 BranchObj *bo=getSelectedBranch();
2514 if (bo) return bo->getColor();
2516 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2523 void VymModel::editURL()
2525 TreeItem *selti=getSelectedItem();
2529 QString text = QInputDialog::getText(
2530 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2531 selti->getURL(), &ok, NULL);
2533 // user entered something and pressed OK
2538 void VymModel::editLocalURL()
2540 TreeItem *selti=getSelectedItem();
2543 QStringList filters;
2544 filters <<"All files (*)";
2545 filters << tr("Text","Filedialog") + " (*.txt)";
2546 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2547 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2548 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2549 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2550 fd->setFilters (filters);
2551 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2552 fd->setDirectory (lastFileDir);
2553 if (! selti->getVymLink().isEmpty() )
2554 fd->selectFile( selti->getURL() );
2557 if ( fd->exec() == QDialog::Accepted )
2559 lastFileDir=QDir (fd->directory().path());
2560 setURL (fd->selectedFile() );
2566 void VymModel::editHeading2URL()
2568 TreeItem *selti=getSelectedItem();
2570 setURL (selti->getHeading());
2573 void VymModel::editBugzilla2URL()
2575 TreeItem *selti=getSelectedItem();
2578 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2583 void VymModel::editFATE2URL()
2585 TreeItem *selti=getSelectedItem();
2588 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2591 "setURL (\""+selti->getURL()+"\")",
2593 "setURL (\""+url+"\")",
2594 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2596 selti->setURL (url);
2597 // FIXME-4 updateActions();
2601 void VymModel::editVymLink()
2603 BranchItem *bi=getSelectedBranchItem();
2606 QStringList filters;
2607 filters <<"VYM map (*.vym)";
2608 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2609 fd->setFilters (filters);
2610 fd->setCaption(vymName+" - " +tr("Link to another map"));
2611 fd->setDirectory (lastFileDir);
2612 if (! bi->getVymLink().isEmpty() )
2613 fd->selectFile( bi->getVymLink() );
2617 if ( fd->exec() == QDialog::Accepted )
2619 lastFileDir=QDir (fd->directory().path());
2622 "setVymLink (\""+bi->getVymLink()+"\")",
2624 "setVymLink (\""+fd->selectedFile()+"\")",
2625 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2627 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2632 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2634 // Internal function, no saveState needed
2635 BranchItem *bi=getSelectedBranchItem();
2641 //selection.update();
2642 emitShowSelection();
2646 void VymModel::deleteVymLink()
2648 BranchItem *bi=getSelectedBranchItem();
2653 "setVymLink (\""+bi->getVymLink()+"\")",
2655 "setVymLink (\"\")",
2656 QString("Unset vymlink of %1").arg(getObjectName(bi))
2658 bi->setVymLink ("" );
2664 QString VymModel::getVymLink()
2666 BranchItem *bi=getSelectedBranchItem();
2668 return bi->getVymLink();
2674 QStringList VymModel::getVymLinks()
2677 BranchItem *cur=getSelectedBranchItem();
2678 BranchItem *prev=NULL;
2683 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2684 cur=next (cur,prev,d);
2690 void VymModel::followXLink(int i) // FIXME-2
2694 BranchObj *bo=getSelectedBranch();
2697 bo=bo->XLinkTargetAt(i);
2700 selection.select(bo);
2701 emitShowSelection();
2707 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2711 BranchObj *bo=getSelectedBranch();
2714 XLinkObj *xlo=bo->XLinkAt(i);
2717 EditXLinkDialog dia;
2719 dia.setSelection(bo);
2720 if (dia.exec() == QDialog::Accepted)
2722 if (dia.useSettingsGlobal() )
2724 setMapDefXLinkColor (xlo->getColor() );
2725 setMapDefXLinkWidth (xlo->getWidth() );
2727 if (dia.deleteXLink())
2728 bo->deleteXLinkAt(i);
2739 //////////////////////////////////////////////
2741 //////////////////////////////////////////////
2743 void VymModel::parseAtom(const QString &atom)
2745 TreeItem* selti=getSelectedItem();
2746 BranchItem *selbi=getSelectedBranchItem();
2752 // Split string s into command and parameters
2753 parser.parseAtom (atom);
2754 QString com=parser.getCommand();
2756 // External commands
2757 /////////////////////////////////////////////////////////////////////
2758 if (com=="addBranch")
2762 parser.setError (Aborted,"Nothing selected");
2763 } else if (! selbi )
2765 parser.setError (Aborted,"Type of selection is not a branch");
2770 if (parser.checkParCount(pl))
2772 if (parser.parCount()==0)
2776 n=parser.parInt (ok,0);
2777 if (ok ) addNewBranch (n);
2781 /////////////////////////////////////////////////////////////////////
2782 } else if (com=="addBranchBefore")
2786 parser.setError (Aborted,"Nothing selected");
2787 } else if (! selbi )
2789 parser.setError (Aborted,"Type of selection is not a branch");
2792 if (parser.parCount()==0)
2794 addNewBranchBefore ();
2797 /////////////////////////////////////////////////////////////////////
2798 } else if (com==QString("addMapCenter"))
2800 if (parser.checkParCount(2))
2802 x=parser.parDouble (ok,0);
2805 y=parser.parDouble (ok,1);
2806 if (ok) addMapCenter (QPointF(x,y));
2809 /////////////////////////////////////////////////////////////////////
2810 } else if (com==QString("addMapReplace"))
2814 parser.setError (Aborted,"Nothing selected");
2815 } else if (! selbi )
2817 parser.setError (Aborted,"Type of selection is not a branch");
2818 } else if (parser.checkParCount(1))
2820 //s=parser.parString (ok,0); // selection
2821 t=parser.parString (ok,0); // path to map
2822 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2823 addMapReplaceInt(getSelectString(selbi),t);
2825 /////////////////////////////////////////////////////////////////////
2826 } else if (com==QString("addMapInsert"))
2830 parser.setError (Aborted,"Nothing selected");
2831 } else if (! selbi )
2833 parser.setError (Aborted,"Type of selection is not a branch");
2836 if (parser.checkParCount(2))
2838 t=parser.parString (ok,0); // path to map
2839 n=parser.parInt(ok,1); // position
2840 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2841 addMapInsertInt(t,n);
2844 /////////////////////////////////////////////////////////////////////
2845 } else if (com=="clearFlags")
2849 parser.setError (Aborted,"Nothing selected");
2850 } else if (! selbi )
2852 parser.setError (Aborted,"Type of selection is not a branch");
2853 } else if (parser.checkParCount(0))
2855 selbi->deactivateAllStandardFlags();
2857 /////////////////////////////////////////////////////////////////////
2858 } else if (com=="colorBranch")
2862 parser.setError (Aborted,"Nothing selected");
2863 } else if (! selbi )
2865 parser.setError (Aborted,"Type of selection is not a branch");
2866 } else if (parser.checkParCount(1))
2868 QColor c=parser.parColor (ok,0);
2869 if (ok) colorBranch (c);
2871 /////////////////////////////////////////////////////////////////////
2872 } else if (com=="colorSubtree")
2876 parser.setError (Aborted,"Nothing selected");
2877 } else if (! selbi )
2879 parser.setError (Aborted,"Type of selection is not a branch");
2880 } else if (parser.checkParCount(1))
2882 QColor c=parser.parColor (ok,0);
2883 if (ok) colorSubtree (c);
2885 /////////////////////////////////////////////////////////////////////
2886 } else if (com=="copy")
2890 parser.setError (Aborted,"Nothing selected");
2891 } else if ( selectionType()!=TreeItem::Branch &&
2892 selectionType()!=TreeItem::MapCenter &&
2893 selectionType()!=TreeItem::Image )
2895 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2896 } else if (parser.checkParCount(0))
2900 /////////////////////////////////////////////////////////////////////
2901 } else if (com=="cut")
2905 parser.setError (Aborted,"Nothing selected");
2906 } else if ( selectionType()!=TreeItem::Branch &&
2907 selectionType()!=TreeItem::MapCenter &&
2908 selectionType()!=TreeItem::Image )
2910 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2911 } else if (parser.checkParCount(0))
2915 /////////////////////////////////////////////////////////////////////
2916 } else if (com=="delete")
2920 parser.setError (Aborted,"Nothing selected");
2922 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2924 parser.setError (Aborted,"Type of selection is wrong.");
2927 else if (parser.checkParCount(0))
2931 /////////////////////////////////////////////////////////////////////
2932 } else if (com=="deleteKeepChildren")
2936 parser.setError (Aborted,"Nothing selected");
2937 } else if (! selbi )
2939 parser.setError (Aborted,"Type of selection is not a branch");
2940 } else if (parser.checkParCount(0))
2942 deleteKeepChildren();
2944 /////////////////////////////////////////////////////////////////////
2945 } else if (com=="deleteChildren")
2949 parser.setError (Aborted,"Nothing selected");
2952 parser.setError (Aborted,"Type of selection is not a branch");
2953 } else if (parser.checkParCount(0))
2957 /////////////////////////////////////////////////////////////////////
2958 } else if (com=="exportASCII")
2962 if (parser.parCount()>=1)
2963 // Hey, we even have a filename
2964 fname=parser.parString(ok,0);
2967 parser.setError (Aborted,"Could not read filename");
2970 exportASCII (fname,false);
2972 /////////////////////////////////////////////////////////////////////
2973 } else if (com=="exportImage")
2977 if (parser.parCount()>=2)
2978 // Hey, we even have a filename
2979 fname=parser.parString(ok,0);
2982 parser.setError (Aborted,"Could not read filename");
2985 QString format="PNG";
2986 if (parser.parCount()>=2)
2988 format=parser.parString(ok,1);
2990 exportImage (fname,false,format);
2992 /////////////////////////////////////////////////////////////////////
2993 } else if (com=="exportXHTML")
2997 if (parser.parCount()>=2)
2998 // Hey, we even have a filename
2999 fname=parser.parString(ok,1);
3002 parser.setError (Aborted,"Could not read filename");
3005 exportXHTML (fname,false);
3007 /////////////////////////////////////////////////////////////////////
3008 } else if (com=="exportXML")
3012 if (parser.parCount()>=2)
3013 // Hey, we even have a filename
3014 fname=parser.parString(ok,1);
3017 parser.setError (Aborted,"Could not read filename");
3020 exportXML (fname,false);
3022 /////////////////////////////////////////////////////////////////////
3023 } else if (com=="importDir")
3027 parser.setError (Aborted,"Nothing selected");
3028 } else if (! selbi )
3030 parser.setError (Aborted,"Type of selection is not a branch");
3031 } else if (parser.checkParCount(1))
3033 s=parser.parString(ok,0);
3034 if (ok) importDirInt(s);
3036 /////////////////////////////////////////////////////////////////////
3037 } else /* FIXME-2 if (com=="linkTo")
3041 parser.setError (Aborted,"Nothing selected");
3044 if (parser.checkParCount(4))
3046 // 0 selectstring of parent
3047 // 1 num in parent (for branches)
3048 // 2,3 x,y of mainbranch or mapcenter
3049 s=parser.parString(ok,0);
3050 LinkableMapObj *dst=findObjBySelect (s);
3053 if (typeid(*dst) == typeid(BranchObj) )
3055 // Get number in parent
3056 n=parser.parInt (ok,1);
3059 selb->linkTo ((BranchObj*)(dst),n);
3062 } else if (typeid(*dst) == typeid(MapCenterObj) )
3064 selb->linkTo ((BranchObj*)(dst),-1);
3065 // Get coordinates of mainbranch
3066 x=parser.parDouble(ok,2);
3069 y=parser.parDouble(ok,3);
3079 } else if ( selectionType() == TreeItem::Image)
3081 if (parser.checkParCount(1))
3083 // 0 selectstring of parent
3084 s=parser.parString(ok,0);
3085 LinkableMapObj *dst=findObjBySelect (s);
3088 if (typeid(*dst) == typeid(BranchObj) ||
3089 typeid(*dst) == typeid(MapCenterObj))
3090 linkFloatImageTo (getSelectString(dst));
3092 parser.setError (Aborted,"Destination is not a branch");
3095 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3096 /////////////////////////////////////////////////////////////////////
3097 } else */ if (com=="loadImage")
3101 parser.setError (Aborted,"Nothing selected");
3102 } else if (! selbi )
3104 parser.setError (Aborted,"Type of selection is not a branch");
3105 } else if (parser.checkParCount(1))
3107 s=parser.parString(ok,0);
3108 if (ok) loadFloatImageInt (s);
3110 /////////////////////////////////////////////////////////////////////
3111 } else if (com=="moveUp")
3115 parser.setError (Aborted,"Nothing selected");
3116 } else if (! selbi )
3118 parser.setError (Aborted,"Type of selection is not a branch");
3119 } else if (parser.checkParCount(0))
3123 /////////////////////////////////////////////////////////////////////
3124 } else if (com=="moveDown")
3128 parser.setError (Aborted,"Nothing selected");
3129 } else if (! selbi )
3131 parser.setError (Aborted,"Type of selection is not a branch");
3132 } else if (parser.checkParCount(0))
3136 /////////////////////////////////////////////////////////////////////
3137 } else if (com=="move")
3141 parser.setError (Aborted,"Nothing selected");
3142 } else if ( selectionType()!=TreeItem::Branch &&
3143 selectionType()!=TreeItem::MapCenter &&
3144 selectionType()!=TreeItem::Image )
3146 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3147 } else if (parser.checkParCount(2))
3149 x=parser.parDouble (ok,0);
3152 y=parser.parDouble (ok,1);
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="moveRel")
3161 parser.setError (Aborted,"Nothing selected");
3162 } else if ( selectionType()!=TreeItem::Branch &&
3163 selectionType()!=TreeItem::MapCenter &&
3164 selectionType()!=TreeItem::Image )
3166 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3167 } else if (parser.checkParCount(2))
3169 x=parser.parDouble (ok,0);
3172 y=parser.parDouble (ok,1);
3173 if (ok) moveRel (x,y);
3176 /////////////////////////////////////////////////////////////////////
3177 } else if (com=="nop")
3179 /////////////////////////////////////////////////////////////////////
3180 } else if (com=="paste")
3184 parser.setError (Aborted,"Nothing selected");
3185 } else if (! selbi )
3187 parser.setError (Aborted,"Type of selection is not a branch");
3188 } else if (parser.checkParCount(1))
3190 n=parser.parInt (ok,0);
3191 if (ok) pasteNoSave(n);
3193 /////////////////////////////////////////////////////////////////////
3194 } else if (com=="qa")
3198 parser.setError (Aborted,"Nothing selected");
3199 } else if (! selbi )
3201 parser.setError (Aborted,"Type of selection is not a branch");
3202 } else if (parser.checkParCount(4))
3205 c=parser.parString (ok,0);
3208 parser.setError (Aborted,"No comment given");
3211 s=parser.parString (ok,1);
3214 parser.setError (Aborted,"First parameter is not a string");
3217 t=parser.parString (ok,2);
3220 parser.setError (Aborted,"Condition is not a string");
3223 u=parser.parString (ok,3);
3226 parser.setError (Aborted,"Third parameter is not a string");
3231 parser.setError (Aborted,"Unknown type: "+s);
3236 parser.setError (Aborted,"Unknown operator: "+t);
3241 parser.setError (Aborted,"Type of selection is not a branch");
3244 if (selbi->getHeading() == u)
3246 cout << "PASSED: " << qPrintable (c) << endl;
3249 cout << "FAILED: " << qPrintable (c) << endl;
3259 /////////////////////////////////////////////////////////////////////
3260 } else if (com=="saveImage")
3262 FloatImageObj *fio=selection.getFloatImage();
3265 parser.setError (Aborted,"Type of selection is not an image");
3266 } else if (parser.checkParCount(2))
3268 s=parser.parString(ok,0);
3271 t=parser.parString(ok,1);
3272 if (ok) saveFloatImageInt (fio,t,s);
3275 /////////////////////////////////////////////////////////////////////
3276 } else if (com=="scroll")
3280 parser.setError (Aborted,"Nothing selected");
3281 } else if (! selbi )
3283 parser.setError (Aborted,"Type of selection is not a branch");
3284 } else if (parser.checkParCount(0))
3286 if (!scrollBranch (selbi))
3287 parser.setError (Aborted,"Could not scroll branch");
3289 /////////////////////////////////////////////////////////////////////
3290 } else if (com=="select")
3292 if (parser.checkParCount(1))
3294 s=parser.parString(ok,0);
3297 /////////////////////////////////////////////////////////////////////
3298 } else if (com=="selectLastBranch")
3302 parser.setError (Aborted,"Nothing selected");
3303 } else if (! selbi )
3305 parser.setError (Aborted,"Type of selection is not a branch");
3306 } else if (parser.checkParCount(0))
3308 BranchItem *bi=selbi->getLastBranch();
3310 parser.setError (Aborted,"Could not select last branch");
3311 select (bi); // FIXME-3 was selectInt
3314 /////////////////////////////////////////////////////////////////////
3315 } else /* FIXME-2 if (com=="selectLastImage")
3319 parser.setError (Aborted,"Nothing selected");
3320 } else if (! selbi )
3322 parser.setError (Aborted,"Type of selection is not a branch");
3323 } else if (parser.checkParCount(0))
3325 FloatImageObj *fio=selb->getLastFloatImage();
3327 parser.setError (Aborted,"Could not select last image");
3328 select (fio); // FIXME-3 was selectInt
3331 /////////////////////////////////////////////////////////////////////
3332 } else */ if (com=="selectLatestAdded")
3334 if (!latestAddedItem)
3336 parser.setError (Aborted,"No latest added object");
3339 if (!select (latestAddedItem))
3340 parser.setError (Aborted,"Could not select latest added object ");
3342 /////////////////////////////////////////////////////////////////////
3343 } else if (com=="setFrameType")
3345 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3347 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3349 else if (parser.checkParCount(1))
3351 s=parser.parString(ok,0);
3352 if (ok) setFrameType (s);
3354 /////////////////////////////////////////////////////////////////////
3355 } else if (com=="setFramePenColor")
3357 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3359 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3361 else if (parser.checkParCount(1))
3363 QColor c=parser.parColor(ok,0);
3364 if (ok) setFramePenColor (c);
3366 /////////////////////////////////////////////////////////////////////
3367 } else if (com=="setFrameBrushColor")
3369 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3371 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3373 else if (parser.checkParCount(1))
3375 QColor c=parser.parColor(ok,0);
3376 if (ok) setFrameBrushColor (c);
3378 /////////////////////////////////////////////////////////////////////
3379 } else if (com=="setFramePadding")
3381 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3383 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3385 else if (parser.checkParCount(1))
3387 n=parser.parInt(ok,0);
3388 if (ok) setFramePadding(n);
3390 /////////////////////////////////////////////////////////////////////
3391 } else if (com=="setFrameBorderWidth")
3393 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3395 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3397 else if (parser.checkParCount(1))
3399 n=parser.parInt(ok,0);
3400 if (ok) setFrameBorderWidth (n);
3402 /////////////////////////////////////////////////////////////////////
3403 } else if (com=="setMapAuthor")
3405 if (parser.checkParCount(1))
3407 s=parser.parString(ok,0);
3408 if (ok) setAuthor (s);
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="setMapComment")
3413 if (parser.checkParCount(1))
3415 s=parser.parString(ok,0);
3416 if (ok) setComment(s);
3418 /////////////////////////////////////////////////////////////////////
3419 } else if (com=="setMapBackgroundColor")
3423 parser.setError (Aborted,"Nothing selected");
3424 } else if (! selbi )
3426 parser.setError (Aborted,"Type of selection is not a branch");
3427 } else if (parser.checkParCount(1))
3429 QColor c=parser.parColor (ok,0);
3430 if (ok) setMapBackgroundColor (c);
3432 /////////////////////////////////////////////////////////////////////
3433 } else if (com=="setMapDefLinkColor")
3437 parser.setError (Aborted,"Nothing selected");
3438 } else if (! selbi )
3440 parser.setError (Aborted,"Type of selection is not a branch");
3441 } else if (parser.checkParCount(1))
3443 QColor c=parser.parColor (ok,0);
3444 if (ok) setMapDefLinkColor (c);
3446 /////////////////////////////////////////////////////////////////////
3447 } else if (com=="setMapLinkStyle")
3449 if (parser.checkParCount(1))
3451 s=parser.parString (ok,0);
3452 if (ok) setMapLinkStyle(s);
3454 /////////////////////////////////////////////////////////////////////
3455 } else if (com=="setHeading")
3459 parser.setError (Aborted,"Nothing selected");
3460 } else if (! selbi )
3462 parser.setError (Aborted,"Type of selection is not a branch");
3463 } else if (parser.checkParCount(1))
3465 s=parser.parString (ok,0);
3469 /////////////////////////////////////////////////////////////////////
3470 } else if (com=="setHideExport")
3474 parser.setError (Aborted,"Nothing selected");
3475 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3477 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3478 } else if (parser.checkParCount(1))
3480 b=parser.parBool(ok,0);
3481 if (ok) setHideExport (b);
3483 /////////////////////////////////////////////////////////////////////
3484 } else if (com=="setIncludeImagesHorizontally")
3488 parser.setError (Aborted,"Nothing selected");
3491 parser.setError (Aborted,"Type of selection is not a branch");
3492 } else if (parser.checkParCount(1))
3494 b=parser.parBool(ok,0);
3495 if (ok) setIncludeImagesHor(b);
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="setIncludeImagesVertically")
3502 parser.setError (Aborted,"Nothing selected");
3505 parser.setError (Aborted,"Type of selection is not a branch");
3506 } else if (parser.checkParCount(1))
3508 b=parser.parBool(ok,0);
3509 if (ok) setIncludeImagesVer(b);
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="setHideLinkUnselected")
3516 parser.setError (Aborted,"Nothing selected");
3517 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3519 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3520 } else if (parser.checkParCount(1))
3522 b=parser.parBool(ok,0);
3523 if (ok) setHideLinkUnselected(b);
3525 /////////////////////////////////////////////////////////////////////
3526 } else if (com=="setSelectionColor")
3528 if (parser.checkParCount(1))
3530 QColor c=parser.parColor (ok,0);
3531 if (ok) setSelectionColorInt (c);
3533 /////////////////////////////////////////////////////////////////////
3534 } else if (com=="setURL")
3538 parser.setError (Aborted,"Nothing selected");
3539 } else if (! selbi )
3541 parser.setError (Aborted,"Type of selection is not a branch");
3542 } else if (parser.checkParCount(1))
3544 s=parser.parString (ok,0);
3547 /////////////////////////////////////////////////////////////////////
3548 } else if (com=="setVymLink")
3552 parser.setError (Aborted,"Nothing selected");
3553 } else if (! selbi )
3555 parser.setError (Aborted,"Type of selection is not a branch");
3556 } else if (parser.checkParCount(1))
3558 s=parser.parString (ok,0);
3559 if (ok) setVymLink(s);
3562 /////////////////////////////////////////////////////////////////////
3563 else if (com=="setFlag")
3567 parser.setError (Aborted,"Nothing selected");
3568 } else if (! selbi )
3570 parser.setError (Aborted,"Type of selection is not a branch");
3571 } else if (parser.checkParCount(1))
3573 s=parser.parString(ok,0);
3575 selbi->activateStandardFlag(s);
3577 /////////////////////////////////////////////////////////////////////
3578 } else /* FIXME-2 if (com=="setFrameType")
3582 parser.setError (Aborted,"Nothing selected");
3585 parser.setError (Aborted,"Type of selection is not a branch");
3586 } else if (parser.checkParCount(1))
3588 s=parser.parString(ok,0);
3592 /////////////////////////////////////////////////////////////////////
3593 } else*/ if (com=="sortChildren")
3597 parser.setError (Aborted,"Nothing selected");
3598 } else if (! selbi )
3600 parser.setError (Aborted,"Type of selection is not a branch");
3601 } else if (parser.checkParCount(0))
3605 /////////////////////////////////////////////////////////////////////
3606 } else if (com=="toggleFlag")
3610 parser.setError (Aborted,"Nothing selected");
3611 } else if (! selbi )
3613 parser.setError (Aborted,"Type of selection is not a branch");
3614 } else if (parser.checkParCount(1))
3616 s=parser.parString(ok,0);
3618 selbi->toggleStandardFlag(s);
3620 /////////////////////////////////////////////////////////////////////
3621 } else if (com=="unscroll")
3625 parser.setError (Aborted,"Nothing selected");
3626 } else if (! selbi )
3628 parser.setError (Aborted,"Type of selection is not a branch");
3629 } else if (parser.checkParCount(0))
3631 if (!unscrollBranch (selbi))
3632 parser.setError (Aborted,"Could not unscroll branch");
3634 /////////////////////////////////////////////////////////////////////
3635 } else if (com=="unscrollChildren")
3639 parser.setError (Aborted,"Nothing selected");
3640 } else if (! selbi )
3642 parser.setError (Aborted,"Type of selection is not a branch");
3643 } else if (parser.checkParCount(0))
3645 unscrollChildren ();
3647 /////////////////////////////////////////////////////////////////////
3648 } else if (com=="unsetFlag")
3652 parser.setError (Aborted,"Nothing selected");
3653 } else if (! selbi )
3655 parser.setError (Aborted,"Type of selection is not a branch");
3656 } else if (parser.checkParCount(1))
3658 s=parser.parString(ok,0);
3660 selbi->deactivateStandardFlag(s);
3663 parser.setError (Aborted,"Unknown command");
3666 if (parser.errorLevel()==NoError)
3668 // setChanged(); FIXME-2 should not be called e.g. for export?!
3673 // TODO Error handling
3674 qWarning("VymModel::parseAtom: Error!");
3675 qWarning(parser.errorMessage());
3679 void VymModel::runScript (QString script)
3681 parser.setScript (script);
3683 while (parser.next() )
3684 parseAtom(parser.getAtom());
3687 void VymModel::setExportMode (bool b)
3689 // should be called before and after exports
3690 // depending on the settings
3691 if (b && settings.value("/export/useHideExport","true")=="true")
3692 setHideTmpMode (TreeItem::HideExport);
3694 setHideTmpMode (TreeItem::HideNone);
3697 void VymModel::exportImage(QString fname, bool askName, QString format)
3701 fname=getMapName()+".png";
3708 QFileDialog *fd=new QFileDialog (NULL);
3709 fd->setCaption (tr("Export map as image"));
3710 fd->setDirectory (lastImageDir);
3711 fd->setFileMode(QFileDialog::AnyFile);
3712 fd->setFilters (imageIO.getFilters() );
3715 fl=fd->selectedFiles();
3717 format=imageIO.getType(fd->selectedFilter());
3721 setExportMode (true);
3722 QPixmap pix (getPixmap());
3723 pix.save(fname, format);
3724 setExportMode (false);
3728 void VymModel::exportXML(QString dir, bool askForName)
3732 dir=browseDirectory(NULL,tr("Export XML to directory"));
3733 if (dir =="" && !reallyWriteDirectory(dir) )
3737 // Hide stuff during export, if settings want this
3738 setExportMode (true);
3740 // Create subdirectories
3743 // write to directory
3744 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3747 file.setName ( dir + "/"+mapName+".xml");
3748 if ( !file.open( QIODevice::WriteOnly ) )
3750 // This should neverever happen
3751 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3755 // Write it finally, and write in UTF8, no matter what
3756 QTextStream ts( &file );
3757 ts.setEncoding (QTextStream::UnicodeUTF8);
3761 // Now write image, too
3762 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3764 setExportMode (false);
3767 void VymModel::exportASCII(QString fname,bool askName)
3772 ex.setFile (mapName+".txt");
3778 //ex.addFilter ("TXT (*.txt)");
3779 ex.setDir(lastImageDir);
3780 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3785 setExportMode(true);
3787 setExportMode(false);
3791 void VymModel::exportXHTML (const QString &dir, bool askForName)
3793 ExportXHTMLDialog dia(NULL);
3794 dia.setFilePath (filePath );
3795 dia.setMapName (mapName );
3797 if (dir!="") dia.setDir (dir);
3803 if (dia.exec()!=QDialog::Accepted)
3807 QDir d (dia.getDir());
3808 // Check, if warnings should be used before overwriting
3809 // the output directory
3810 if (d.exists() && d.count()>0)
3813 warn.showCancelButton (true);
3814 warn.setText(QString(
3815 "The directory %1 is not empty.\n"
3816 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3817 warn.setCaption("Warning: Directory not empty");
3818 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3820 if (warn.exec()!=QDialog::Accepted) ok=false;
3827 exportXML (dia.getDir(),false );
3828 dia.doExport(mapName );
3829 //if (dia.hasChanged()) setChanged();
3833 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3838 if (ex.setConfigFile(cf))
3840 setExportMode (true);
3841 ex.exportPresentation();
3842 setExportMode (false);
3849 //////////////////////////////////////////////
3851 //////////////////////////////////////////////
3853 void VymModel::registerEditor(QWidget *me)
3855 mapEditor=(MapEditor*)me;
3858 void VymModel::unregisterEditor(QWidget *)
3863 void VymModel::setContextPos(QPointF p)
3868 void VymModel::unsetContextPos()
3870 contextPos=QPointF();
3873 void VymModel::updateNoteFlag()
3876 TreeItem *selti=getSelectedItem();
3879 if (textEditor->isEmpty())
3882 selti->setNote (textEditor->getText());
3883 emitDataHasChanged(selti);
3889 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3891 //cout << "VM::updateRelPos...\n";
3892 for (int i=0; i<rootItem->branchCount(); i++)
3893 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3896 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3898 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3899 if (blockReposition) return;
3901 for (int i=0;i<rootItem->branchCount(); i++)
3902 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3905 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3908 // Creating (arbitrary) shapes
3911 QRectF rb=bo->getBBox();
3912 if (bo->getDepth()==0)
3914 // Just take BBox of this mapCenter
3915 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3919 // Take union of BBox and TotalBBox
3921 QRectF ra=bo->getTotalBBox();
3922 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3925 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3928 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3930 p <<ra.bottomRight()
3932 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3935 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3940 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3944 // Move all branches and MapCenters away from lmo
3945 // to avoid collisions
3951 BranchObj *boA=(BranchObj*)lmo;
3953 for (int i=0; i<rootItem->branchCount(); i++)
3955 boB=rootItem->getBranchNum(i);
3958 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3961 <<" ("<<qPrintable(boA->getHeading() )<<")"
3962 <<" with ("<< qPrintable (boB->getHeading() )
3965 <<" minT="<<r.minTranslation<<endl<<endl;
3970 QPixmap VymModel::getPixmap()
3972 QRectF mapRect=getTotalBBox();
3973 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3976 pp.setRenderHints(mapEditor->renderHints());
3978 // Don't print the visualisation of selection
3979 selection.unselect();
3981 mapScene->render ( &pp,
3982 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3983 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3985 // Restore selection
3986 selection.reselect();
3992 void VymModel::setMapLinkStyle (const QString & s)
3997 case LinkableMapObj::Line :
4000 case LinkableMapObj::Parabel:
4001 snow="StyleParabel";
4003 case LinkableMapObj::PolyLine:
4004 snow="StylePolyLine";
4006 case LinkableMapObj::PolyParabel:
4007 snow="StylePolyParabel";
4010 snow="UndefinedStyle";
4015 QString("setMapLinkStyle (\"%1\")").arg(s),
4016 QString("setMapLinkStyle (\"%1\")").arg(snow),
4017 QString("Set map link style (\"%1\")").arg(s)
4021 linkstyle=LinkableMapObj::Line;
4022 else if (s=="StyleParabel")
4023 linkstyle=LinkableMapObj::Parabel;
4024 else if (s=="StylePolyLine")
4025 linkstyle=LinkableMapObj::PolyLine;
4026 else if (s=="StylePolyParabel")
4027 linkstyle=LinkableMapObj::PolyParabel;
4029 linkstyle=LinkableMapObj::UndefinedStyle;
4031 BranchItem *cur=NULL;
4032 BranchItem *prev=NULL;
4038 bo=(BranchObj*)(cur->getLMO() );
4039 bo->setLinkStyle(bo->getDefLinkStyle());
4040 cur=next(cur,prev,d);
4045 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4050 void VymModel::setMapDefLinkColor(QColor col)
4052 if ( !col.isValid() ) return;
4054 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4055 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4056 QString("Set map link color to %1").arg(col.name())
4060 BranchItem *cur=NULL;
4061 BranchItem *prev=NULL;
4064 cur=next(cur,prev,d);
4067 bo=(BranchObj*)(cur->getLMO() );
4074 void VymModel::setMapLinkColorHintInt()
4076 // called from setMapLinkColorHint(lch) or at end of parse
4077 BranchItem *cur=NULL;
4078 BranchItem *prev=NULL;
4081 cur=next(cur,prev,d);
4084 bo=(BranchObj*)(cur->getLMO() );
4086 cur=next(cur,prev,d);
4090 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4093 setMapLinkColorHintInt();
4096 void VymModel::toggleMapLinkColorHint()
4098 if (linkcolorhint==LinkableMapObj::HeadingColor)
4099 linkcolorhint=LinkableMapObj::DefaultColor;
4101 linkcolorhint=LinkableMapObj::HeadingColor;
4102 BranchItem *cur=NULL;
4103 BranchItem *prev=NULL;
4106 cur=next(cur,prev,d);
4109 bo=(BranchObj*)(cur->getLMO() );
4115 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4117 Q3FileDialog *fd=new Q3FileDialog( NULL);
4118 fd->setMode (Q3FileDialog::ExistingFile);
4119 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4120 ImagePreview *p =new ImagePreview (fd);
4121 fd->setContentsPreviewEnabled( TRUE );
4122 fd->setContentsPreview( p, p );
4123 fd->setPreviewMode( Q3FileDialog::Contents );
4124 fd->setCaption(vymName+" - " +tr("Load background image"));
4125 fd->setDir (lastImageDir);
4128 if ( fd->exec() == QDialog::Accepted )
4130 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4131 lastImageDir=QDir (fd->dirPath());
4132 setMapBackgroundImage (fd->selectedFile());
4136 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4138 QColor oldcol=mapScene->backgroundBrush().color();
4142 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4144 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4145 QString("Set background color of map to %1").arg(col.name()));
4148 brush.setTextureImage (QPixmap (fn));
4149 mapScene->setBackgroundBrush(brush);
4152 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4154 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4155 if ( !col.isValid() ) return;
4156 setMapBackgroundColor( col );
4160 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4162 QColor oldcol=mapScene->backgroundBrush().color();
4164 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4165 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4166 QString("Set background color of map to %1").arg(col.name()));
4167 mapScene->setBackgroundBrush(col);
4170 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4172 return mapScene->backgroundBrush().color();
4176 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4178 return linkcolorhint;
4181 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4183 return defLinkColor;
4186 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4191 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4193 return defXLinkColor;
4196 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4201 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4203 return defXLinkWidth;
4206 void VymModel::move(const double &x, const double &y) // FIXME-3
4210 BranchObj *bo = getSelectedBranch();
4212 (selectionType()==TreeItem::Branch ||
4213 selectionType()==TreeItem::MapCenter ||
4214 selectionType()==TreeItem::Image
4217 QPointF ap(bo->getAbsPos());
4221 QString ps=qpointfToString(ap);
4222 QString s=getSelectString();
4225 s, "move "+qpointfToString(to),
4226 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4235 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4239 BranchObj *bo = getSelectedBranch();
4241 (selectionType()==TreeItem::Branch ||
4242 selectionType()==TreeItem::MapCenter ||
4243 selectionType()==TreeItem::Image
4247 QPointF rp(bo->getRelPos());
4251 QString ps=qpointfToString (bo->getRelPos());
4252 QString s=getSelectString(bo);
4255 s, "moveRel "+qpointfToString(to),
4256 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4257 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4267 void VymModel::animate()
4269 animationTimer->stop();
4272 while (i<animObjList.size() )
4274 bo=(BranchObj*)animObjList.at(i);
4279 animObjList.removeAt(i);
4286 QItemSelection sel=selModel->selection();
4287 emit (selectionChanged(sel,sel));
4290 if (!animObjList.isEmpty()) animationTimer->start();
4294 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4296 if (bo && bo->getTreeItem()->depth()>0)
4299 ap.setStart (start);
4301 ap.setTicks (animationTicks);
4302 ap.setAnimated (true);
4303 bo->setAnimation (ap);
4304 animObjList.append( bo );
4305 animationTimer->setSingleShot (true);
4306 animationTimer->start(animationInterval);
4310 void VymModel::stopAnimation (MapObj *mo)
4312 int i=animObjList.indexOf(mo);
4314 animObjList.removeAt (i);
4317 void VymModel::sendSelection()
4319 if (netstate!=Server) return;
4320 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4323 void VymModel::newServer()
4327 tcpServer = new QTcpServer(this);
4328 if (!tcpServer->listen(QHostAddress::Any,port)) {
4329 QMessageBox::critical(NULL, "vym server",
4330 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4331 //FIXME-3 needed? we are no widget any longer... close();
4334 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4336 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4339 void VymModel::connectToServer()
4342 server="salam.suse.de";
4344 clientSocket = new QTcpSocket (this);
4345 clientSocket->abort();
4346 clientSocket->connectToHost(server ,port);
4347 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4348 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4349 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4351 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4356 void VymModel::newClient()
4358 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4359 connect(newClient, SIGNAL(disconnected()),
4360 newClient, SLOT(deleteLater()));
4362 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4364 clientList.append (newClient);
4368 void VymModel::sendData(const QString &s)
4370 if (clientList.size()==0) return;
4372 // Create bytearray to send
4374 QDataStream out(&block, QIODevice::WriteOnly);
4375 out.setVersion(QDataStream::Qt_4_0);
4377 // Reserve some space for blocksize
4380 // Write sendCounter
4381 out << sendCounter++;
4386 // Go back and write blocksize so far
4387 out.device()->seek(0);
4388 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4392 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4394 for (int i=0; i<clientList.size(); ++i)
4396 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4397 clientList.at(i)->write (block);
4401 void VymModel::readData ()
4403 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4406 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4410 QDataStream in(clientSocket);
4411 in.setVersion(QDataStream::Qt_4_0);
4419 cout << " t="<<qPrintable (t)<<endl;
4425 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4427 switch (socketError) {
4428 case QAbstractSocket::RemoteHostClosedError:
4430 case QAbstractSocket::HostNotFoundError:
4431 QMessageBox::information(NULL, vymName +" Network client",
4432 "The host was not found. Please check the "
4433 "host name and port settings.");
4435 case QAbstractSocket::ConnectionRefusedError:
4436 QMessageBox::information(NULL, vymName + " Network client",
4437 "The connection was refused by the peer. "
4438 "Make sure the fortune server is running, "
4439 "and check that the host name and port "
4440 "settings are correct.");
4443 QMessageBox::information(NULL, vymName + " Network client",
4444 QString("The following error occurred: %1.")
4445 .arg(clientSocket->errorString()));
4452 void VymModel::selectMapSelectionColor()
4454 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4455 setSelectionColor (col);
4458 void VymModel::setSelectionColorInt (QColor col)
4460 if ( !col.isValid() ) return;
4462 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4463 QString("setSelectionColor (%1)").arg(col.name()),
4464 QString("Set color of selection box to %1").arg(col.name())
4467 mapEditor->setSelectionColor (col);
4471 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4473 cout << "VymModel::changeSelection (";
4474 if (!newsel.indexes().isEmpty() )
4475 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4477 if (!oldsel.indexes().isEmpty() )
4478 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4483 void VymModel::updateSelection(const QItemSelection &newsel)
4485 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4486 emitShowSelection();
4490 void VymModel::updateSelection()
4492 QItemSelection newsel=selModel->selection();
4493 updateSelection (newsel);
4496 void VymModel::setSelectionColor(QColor col)
4498 if ( !col.isValid() ) return;
4500 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4501 QString("setSelectionColor (%1)").arg(col.name()),
4502 QString("Set color of selection box to %1").arg(col.name())
4504 setSelectionColorInt (col);
4507 QColor VymModel::getSelectionColor()
4509 return mapEditor->getSelectionColor();
4512 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4515 for (int i=0;i<rootItem->childCount();i++)
4516 rootItem->child(i)->setHideTmp (mode);
4518 // FIXME-3 needed? scene()->update();
4522 QRectF VymModel::getTotalBBox() //FIXME-2
4526 for (int i=0;i<rootItem->branchCount(); i++)
4527 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4532 //////////////////////////////////////////////
4533 // Selection related
4534 //////////////////////////////////////////////
4536 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4541 QItemSelectionModel* VymModel::getSelectionModel()
4546 void VymModel::setSelectionBlocked (bool b)
4551 selection.unblock();
4554 bool VymModel::isSelectionBlocked()
4556 return selection.isBlocked();
4559 bool VymModel::select ()
4561 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4563 TreeItem *item = getItem (index);
4564 return select (item->getLMO() );
4567 bool VymModel::select (const QString &s)
4569 TreeItem *ti=findBySelectString(s);
4579 bool VymModel::select (LinkableMapObj *lmo)
4581 QItemSelection oldsel=selModel->selection();
4584 return select (lmo->getTreeItem() );
4589 bool VymModel::select (TreeItem *ti)
4591 if (ti) return select (index(ti));
4595 bool VymModel::select (const QModelIndex &index)
4597 if (index.isValid() )
4599 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4600 getSelectedItem()->setLastSelectedBranch();
4606 void VymModel::unselect()
4608 selModel->clearSelection();
4611 void VymModel::reselect()
4613 selection.reselect();
4616 void VymModel::emitShowSelection()
4618 if (!blockReposition)
4619 emit (showSelection() );
4622 void VymModel::emitNoteHasChanged (TreeItem *ti)
4624 QModelIndex ix=index(ti);
4625 emit (noteHasChanged (ix) );
4628 void VymModel::emitDataHasChanged (TreeItem *ti)
4630 QModelIndex ix=index(ti);
4631 emit (dataChanged (ix,ix) );
4635 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4638 if (selection.select(lmo))
4640 //selection.update();
4641 sendSelection (); // FIXME-4 VM use signal
4645 void VymModel::selectInt (TreeItem *ti)
4647 if (selection.select(lmo))
4649 //selection.update();
4650 sendSelection (); // FIXME-4 VM use signal
4655 void VymModel::selectNextBranchInt()
4657 BranchItem *bi=getSelectedBranchItem();
4660 TreeItem *pi=bi->parent();
4664 if (i<pi->branchCount() )
4666 // select previous branch with same parent
4668 select (pi->getBranchNum(i));
4676 void VymModel::selectPrevBranchInt()
4679 BranchItem *bi=getSelectedBranchItem();
4682 BranchItem *pi=(BranchItem*)bi->parent();
4688 // select previous branch with same parent
4689 bi=pi->getBranchNum(i-1);
4694 while (bi->branchCount() >0)
4695 bi=bi->getLastBranch();
4698 // Try to select last branch in parent pi2 previous to own parent pi
4700 TreeItem *pi2=pi->parent();
4711 void VymModel::selectAboveBranchInt()
4713 BranchItem *bi=getSelectedBranchItem();
4716 BranchItem *newbi=NULL;
4717 BranchItem *pi=(BranchItem*)bi->parent();
4721 // goto previous branch with same parent
4722 newbi=pi->getBranchNum(i-1);
4723 while (newbi->branchCount() >0 )
4724 newbi=newbi->getLastBranch();
4728 if (newbi==rootItem)
4729 // already at top branch (resp. mapcenter)
4735 void VymModel::selectBelowBranchInt()
4737 BranchItem *bi=getSelectedBranchItem();
4740 BranchItem *newbi=NULL;
4742 if (bi->branchCount() >0)
4743 newbi=bi->getFirstBranch();
4750 pi=(BranchItem*)bi->parent();
4752 if (pi->branchCount()-1 > i)
4754 newbi=(BranchItem*)pi->getBranchNum(i+1);
4759 // look for siblings of myself
4760 // or parent, or parent of parent...
4771 void VymModel::selectUpperBranch()
4773 if (selection.isBlocked() ) return;
4775 BranchItem *bi=getSelectedBranchItem();
4776 if (bi && bi->isBranchLikeType())
4777 selectAboveBranchInt();
4780 void VymModel::selectLowerBranch()
4782 if (selection.isBlocked() ) return;
4784 BranchItem *bi=getSelectedBranchItem();
4785 if (bi && bi->isBranchLikeType())
4786 selectBelowBranchInt();
4790 void VymModel::selectLeftBranch()
4792 if (selection.isBlocked() ) return;
4794 QItemSelection oldsel=selModel->selection();
4797 BranchItem *selbi=getSelectedBranchItem();
4798 TreeItem::Type type=selbi->getType();
4801 if (type == TreeItem::MapCenter)
4803 QModelIndex ix=index(selbi);
4804 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4807 par=(BranchItem*)selbi->parent();
4808 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4811 if (type == TreeItem::Branch ||
4812 type == TreeItem::Image)
4814 QModelIndex ix=index (selbi->parent());
4815 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4820 if (type == TreeItem::Branch )
4822 selectLastSelectedBranch();
4830 void VymModel::selectRightBranch()
4832 if (selection.isBlocked() ) return;
4834 QItemSelection oldsel=selModel->selection();
4837 BranchItem *selbi=getSelectedBranchItem();
4838 TreeItem::Type type=selbi->getType();
4841 if (type==TreeItem::MapCenter)
4843 QModelIndex ix=index(selbi);
4844 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4847 par=(BranchItem*)selbi->parent();
4848 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4851 if ( type== TreeItem::Branch )
4853 selectLastSelectedBranch();
4859 if (type == TreeItem::Branch ||
4860 type == TreeItem::Image)
4862 QModelIndex ix=index(selbi->parent());
4863 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4870 void VymModel::selectFirstBranch()
4872 TreeItem *ti=getSelectedBranchItem();
4875 TreeItem *par=ti->parent();
4877 TreeItem *ti2=par->getFirstBranch();
4881 emitShowSelection();
4887 void VymModel::selectLastBranch()
4889 TreeItem *ti=getSelectedBranchItem();
4892 TreeItem *par=ti->parent();
4894 TreeItem *ti2=par->getLastBranch();
4898 emitShowSelection();
4904 void VymModel::selectLastSelectedBranch()
4906 TreeItem *ti=getSelectedBranchItem();
4909 ti=ti->getLastSelectedBranch();
4910 if (ti) select (ti);
4914 void VymModel::selectParent()
4916 TreeItem *ti=getSelectedItem();
4924 emitShowSelection();
4929 TreeItem::Type VymModel::selectionType()
4931 QModelIndexList list=selModel->selectedIndexes();
4932 if (list.isEmpty()) return TreeItem::Undefined;
4933 TreeItem *ti = getItem (list.first() );
4934 return ti->getType();
4938 LinkableMapObj* VymModel::getSelectedLMO()
4940 QModelIndexList list=selModel->selectedIndexes();
4941 if (!list.isEmpty() )
4943 TreeItem *ti = getItem (list.first() );
4944 TreeItem::Type type=ti->getType();
4945 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4947 return ti->getLMO();
4953 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4955 TreeItem *ti = getSelectedBranchItem();
4957 return (BranchObj*)ti->getLMO();
4962 BranchItem* VymModel::getSelectedBranchItem()
4964 QModelIndexList list=selModel->selectedIndexes();
4965 if (!list.isEmpty() )
4967 TreeItem *ti = getItem (list.first() );
4968 TreeItem::Type type=ti->getType();
4969 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4970 return (BranchItem*)ti;
4975 TreeItem* VymModel::getSelectedItem()
4977 QModelIndexList list=selModel->selectedIndexes();
4978 if (!list.isEmpty() )
4979 return getItem (list.first() );
4984 QModelIndex VymModel::getSelectedIndex()
4986 QModelIndexList list=selModel->selectedIndexes();
4987 if (list.isEmpty() )
4988 return QModelIndex();
4990 return list.first();
4993 FloatImageObj* VymModel::getSelectedFloatImage()
4995 return selection.getFloatImage();
4998 QString VymModel::getSelectString ()
5000 LinkableMapObj *lmo=getSelectedLMO();
5002 return getSelectString(lmo);
5007 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5009 if (!lmo) return QString();
5010 return getSelectString (lmo->getTreeItem() );
5013 QString VymModel::getSelectString (TreeItem *ti)
5017 if (ti->getType() == TreeItem::Branch ||
5018 ti->getType() == TreeItem::MapCenter)
5020 TreeItem *par=ti->parent();
5023 if (ti->depth() ==1)
5024 // Mainbranch, return
5025 s= "bo:" + QString("%1").arg(ti->num() );
5027 // Branch, call myself recursively
5028 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5032 int i=rootItem->num(ti);
5033 if (i>=0) s=QString("mc:%1").arg(i);