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 cout << "VM::saveToDir 0 " <<saveSel<<endl;
242 // Build xml recursivly
243 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
244 // Save all mapcenters as complete map, if saveSel not set
245 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
248 if (saveSel->getType()==TreeItem::Branch)
250 s+=saveSel->saveToDir(tmpdir,prefix,offset);
251 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
253 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
256 cout << "VM::saveToDir 1 \n";
257 // Save local settings
258 s+=settings.getDataXML (destPath);
260 cout << "VM::saveToDir 2 \n";
262 if (getSelectedItem() && !saveSel )
263 s+=xml.valueElement("select",getSelectString());
266 s+=xml.endElement("vymmap");
268 // FIXME-2 if (writeflags) standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
272 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
276 for (int i=0; i<rootItem->branchCount(); i++)
277 s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
281 void VymModel::setFilePath(QString fpath, QString destname)
283 if (fpath.isEmpty() || fpath=="")
290 filePath=fpath; // becomes absolute path
291 fileName=fpath; // gets stripped of path
292 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
294 // If fpath is not an absolute path, complete it
295 filePath=QDir(fpath).absPath();
296 fileDir=filePath.left (1+filePath.findRev ("/"));
298 // Set short name, too. Search from behind:
299 int i=fileName.findRev("/");
300 if (i>=0) fileName=fileName.remove (0,i+1);
302 // Forget the .vym (or .xml) for name of map
303 mapName=fileName.left(fileName.findRev(".",-1,true) );
307 void VymModel::setFilePath(QString fpath)
309 setFilePath (fpath,fpath);
312 QString VymModel::getFilePath()
317 QString VymModel::getFileName()
322 QString VymModel::getMapName()
327 QString VymModel::getDestPath()
332 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
334 ErrorCode err=success;
336 parseBaseHandler *handler;
340 case VymMap: handler=new parseVYMHandler; break;
341 case FreemindMap : handler=new parseFreemindHandler; break;
343 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
344 "Unknown FileType in VymModel::load()");
348 bool zipped_org=zipped;
352 selModel->clearSelection();
353 // FIXME-2 VM not needed??? model->setMapEditor(this);
354 // (map state is set later at end of load...)
357 BranchItem *bi=getSelectedBranchItem();
358 if (!bi) return aborted;
359 if (lmode==ImportAdd)
360 saveStateChangingPart(
363 QString("addMapInsert (%1)").arg(fname),
364 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
366 saveStateChangingPart(
369 QString("addMapReplace(%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
374 // Create temporary directory for packing
376 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
379 QMessageBox::critical( 0, tr( "Critical Load Error" ),
380 tr("Couldn't create temporary directory before load\n"));
385 err=unzipDir (tmpZipDir,fname);
395 // Look for mapname.xml
396 xmlfile= fname.left(fname.findRev(".",-1,true));
397 xmlfile=xmlfile.section( '/', -1 );
398 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
399 if (!mfile.exists() )
401 // mapname.xml does not exist, well,
402 // maybe someone renamed the mapname.vym file...
403 // Try to find any .xml in the toplevel
404 // directory of the .vym file
405 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
406 if (flist.count()==1)
408 // Only one entry, take this one
409 xmlfile=tmpZipDir + "/"+flist.first();
412 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
413 *it=tmpZipDir + "/" + *it;
414 // TODO Multiple entries, load all (but only the first one into this ME)
415 //mainWindow->fileLoadFromTmp (flist);
416 //returnCode=1; // Silently forget this attempt to load
417 qWarning ("MainWindow::load (fn) multimap found...");
420 if (flist.isEmpty() )
422 QMessageBox::critical( 0, tr( "Critical Load Error" ),
423 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
426 } //file doesn't exist
428 xmlfile=mfile.name();
431 QFile file( xmlfile);
433 // I am paranoid: file should exist anyway
434 // according to check in mainwindow.
437 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
438 tr(QString("Couldn't open map %1").arg(file.name())));
442 bool blockSaveStateOrg=blockSaveState;
443 blockReposition=true;
445 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
446 QXmlInputSource source( file);
447 QXmlSimpleReader reader;
448 reader.setContentHandler( handler );
449 reader.setErrorHandler( handler );
450 handler->setModel ( this);
453 // We need to set the tmpDir in order to load files with rel. path
458 tmpdir=fname.left(fname.findRev("/",-1));
459 handler->setTmpDir (tmpdir);
460 handler->setInputFile (file.name());
461 handler->setLoadMode (lmode);
462 bool ok = reader.parse( source );
463 blockReposition=false;
464 blockSaveState=blockSaveStateOrg;
465 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
469 reposition(); // FIXME-2 VM reposition the view instead...
476 autosaveTimer->stop();
479 // Reset timestamp to check for later updates of file
480 fileChangedTime=QFileInfo (destPath).lastModified();
483 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
484 tr( handler->errorProtocol() ) );
486 // Still return "success": the map maybe at least
487 // partially read by the parser
492 removeDir (QDir(tmpZipDir));
494 // Restore original zip state
501 ErrorCode VymModel::save (const SaveMode &savemode)
505 QString safeFilePath;
507 ErrorCode err=success;
511 mapFileName=mapName+".xml";
513 // use name given by user, even if he chooses .doc
514 mapFileName=fileName;
516 // Look, if we should zip the data:
519 QMessageBox mb( vymName,
520 tr("The map %1\ndid not use the compressed "
521 "vym file format.\nWriting it uncompressed will also write images \n"
522 "and flags and thus may overwrite files in the "
523 "given directory\n\nDo you want to write the map").arg(filePath),
524 QMessageBox::Warning,
525 QMessageBox::Yes | QMessageBox::Default,
527 QMessageBox::Cancel | QMessageBox::Escape);
528 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
529 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
530 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
533 case QMessageBox::Yes:
534 // save compressed (default file format)
537 case QMessageBox::No:
541 case QMessageBox::Cancel:
548 // First backup existing file, we
549 // don't want to add to old zip archives
553 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
555 QString backupFileName(destPath + "~");
556 QFile backupFile(backupFileName);
557 if (backupFile.exists() && !backupFile.remove())
559 QMessageBox::warning(0, tr("Save Error"),
560 tr("%1\ncould not be removed before saving").arg(backupFileName));
562 else if (!f.rename(backupFileName))
564 QMessageBox::warning(0, tr("Save Error"),
565 tr("%1\ncould not be renamed before saving").arg(destPath));
572 // Create temporary directory for packing
574 tmpZipDir=makeTmpDir (ok,"vym-zip");
577 QMessageBox::critical( 0, tr( "Critical Load Error" ),
578 tr("Couldn't create temporary directory before save\n"));
582 safeFilePath=filePath;
583 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
586 // Create mapName and fileDir
587 makeSubDirs (fileDir);
590 if (savemode==CompleteMap || selection.isEmpty())
593 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
596 autosaveTimer->stop();
601 if (selectionType()==TreeItem::Image)
604 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
605 // TODO take care of multiselections
608 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
611 qWarning ("ME::saveStringToDisk failed!");
617 if (err==success) err=zipDir (tmpZipDir,destPath);
620 removeDir (QDir(tmpZipDir));
622 // Restore original filepath outside of tmp zip dir
623 setFilePath (safeFilePath);
627 fileChangedTime=QFileInfo (destPath).lastModified();
631 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
633 QString pathDir=path.left(path.findRev("/"));
639 // We need to parse saved XML data
640 parseVYMHandler handler;
641 QXmlInputSource source( file);
642 QXmlSimpleReader reader;
643 reader.setContentHandler( &handler );
644 reader.setErrorHandler( &handler );
645 handler.setModel ( this);
646 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
647 if (undoSel.isEmpty())
651 handler.setLoadMode (NewMap);
655 handler.setLoadMode (ImportReplace);
657 blockReposition=true;
658 bool ok = reader.parse( source );
659 blockReposition=false;
662 // This should never ever happen
663 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
664 handler.errorProtocol());
667 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
670 void VymModel::addMapInsertInt (const QString &path, int pos)
672 /* FIXME-2 addMapInsertInt not ported yet
673 BranchObj *sel=getSelectedBranch();
676 QString pathDir=path.left(path.findRev("/"));
682 // We need to parse saved XML data
683 parseVYMHandler handler;
684 QXmlInputSource source( file);
685 QXmlSimpleReader reader;
686 reader.setContentHandler( &handler );
687 reader.setErrorHandler( &handler );
688 handler.setModel (this);
689 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
690 handler.setLoadMode (ImportAdd);
691 blockReposition=true;
692 bool ok = reader.parse( source );
693 blockReposition=false;
696 // This should never ever happen
697 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
698 handler.errorProtocol());
700 if (sel->getDepth()>0)
701 sel->getLastBranch()->linkTo (sel,pos);
703 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
708 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
710 TreeItem *fi=createImage();
713 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
721 void VymModel::loadFloatImage () // FIXME-2
724 BranchObj *bo=getSelectedBranch();
728 Q3FileDialog *fd=new Q3FileDialog( NULL);
729 fd->setMode (Q3FileDialog::ExistingFiles);
730 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
731 ImagePreview *p =new ImagePreview (fd);
732 fd->setContentsPreviewEnabled( TRUE );
733 fd->setContentsPreview( p, p );
734 fd->setPreviewMode( Q3FileDialog::Contents );
735 fd->setCaption(vymName+" - " +tr("Load image"));
736 fd->setDir (lastImageDir);
739 if ( fd->exec() == QDialog::Accepted )
741 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
742 lastImageDir=QDir (fd->dirPath());
745 for (int j=0; j<fd->selectedFiles().count(); j++)
747 s=fd->selectedFiles().at(j);
748 fio=loadFloatImageInt (s);
751 (LinkableMapObj*)fio,
754 QString ("loadImage (%1)").arg(s ),
755 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
758 // TODO loadFIO error handling
759 qWarning ("Failed to load "+s);
768 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
773 void VymModel::saveFloatImage ()
775 FloatImageObj *fio=selection.getFloatImage();
778 QFileDialog *fd=new QFileDialog( NULL);
779 fd->setFilters (imageIO.getFilters());
780 fd->setCaption(vymName+" - " +tr("Save image"));
781 fd->setFileMode( QFileDialog::AnyFile );
782 fd->setDirectory (lastImageDir);
783 // fd->setSelection (fio->getOriginalFilename());
787 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
789 fn=fd->selectedFiles().at(0);
790 if (QFile (fn).exists() )
792 QMessageBox mb( vymName,
793 tr("The file %1 exists already.\n"
794 "Do you want to overwrite it?").arg(fn),
795 QMessageBox::Warning,
796 QMessageBox::Yes | QMessageBox::Default,
797 QMessageBox::Cancel | QMessageBox::Escape,
798 QMessageBox::NoButton );
800 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
801 mb.setButtonText( QMessageBox::No, tr("Cancel"));
804 case QMessageBox::Yes:
807 case QMessageBox::Cancel:
814 saveFloatImageInt (fio,fd->selectedFilter(),fn );
821 void VymModel::importDirInt(BranchObj *dst, QDir d)
823 /* FIXME-2 importDirInt not ported yet
824 BranchObj *bo=getSelectedBranch();
827 // Traverse directories
828 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
829 QFileInfoList list = d.entryInfoList();
832 for (int i = 0; i < list.size(); ++i)
835 if (fi.fileName() != "." && fi.fileName() != ".." )
838 bo=dst->getLastBranch();
839 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
840 bi->setHeading (fi.fileName() ); // FIXME-3 check this
841 bo->setColor (QColor("blue"));
843 if ( !d.cd(fi.fileName()) )
844 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
847 // Recursively add subdirs
854 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
855 list = d.entryInfoList();
857 for (int i = 0; i < list.size(); ++i)
861 bo=dst->getLastBranch();
862 bo->setHeading (fi.fileName() );
863 bo->setColor (QColor("black"));
864 if (fi.fileName().right(4) == ".vym" )
865 bo->setVymLink (fi.filePath());
871 void VymModel::importDirInt (const QString &s) // FIXME-2
874 BranchObj *bo=getSelectedBranch();
877 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
885 void VymModel::importDir() //FIXME-2
888 BranchObj *bo=getSelectedBranch();
892 filters <<"VYM map (*.vym)";
893 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
894 fd->setMode (QFileDialog::DirectoryOnly);
895 fd->setFilters (filters);
896 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
900 if ( fd->exec() == QDialog::Accepted )
902 importDirInt (fd->selectedFile() );
904 //FIXME-3 VM needed? scene()->update();
911 void VymModel::autosave()
916 cout << "VymModel::autosave rejected due to missing filePath\n";
919 QDateTime now=QDateTime().currentDateTime();
921 // Disable autosave, while we have gone back in history
922 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
923 if (redosAvail>0) return;
925 // Also disable autosave for new map without filename
926 if (filePath.isEmpty()) return;
929 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
931 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
932 mainWindow->fileSave (this);
935 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
940 void VymModel::fileChanged()
942 // Check if file on disk has changed meanwhile
943 if (!filePath.isEmpty())
945 QDateTime tmod=QFileInfo (filePath).lastModified();
946 if (tmod>fileChangedTime)
948 // FIXME-2 VM switch to current mapeditor and finish lineedits...
949 QMessageBox mb( vymName,
950 tr("The file of the map on disk has changed:\n\n"
951 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
952 QMessageBox::Question,
954 QMessageBox::Cancel | QMessageBox::Default,
955 QMessageBox::NoButton );
957 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
958 mb.setButtonText( QMessageBox::No, tr("Ignore"));
961 case QMessageBox::Yes:
963 load (filePath,NewMap,fileType);
964 case QMessageBox::Cancel:
965 fileChangedTime=tmod; // allow autosave to overwrite newer file!
971 bool VymModel::isDefault()
976 void VymModel::makeDefault()
982 bool VymModel::hasChanged()
987 void VymModel::setChanged()
990 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
994 latestAddedItem=NULL;
998 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
1001 if (!lmo) return QString("Error: NULL has no name!");
1003 if ((typeid(*lmo) == typeid(BranchObj) ||
1004 typeid(*lmo) == typeid(MapCenterObj)))
1007 s=lmo->getTreeItem()->getHeading();
1008 if (s=="") s="unnamed";
1009 return QString("branch (%1)").arg(s);
1011 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1012 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1013 return QString("Unknown type has no name!");
1017 QString VymModel::getObjectName (const TreeItem *ti)
1020 if (!ti) return QString("Error: NULL has no name!");
1022 if (ti->isBranchLikeType() )
1025 if (s=="") s="unnamed";
1026 return QString("branch (%1)").arg(s);
1028 /* FIXME-2 move floatimage to TreeModel first
1029 if (type==TreeItem::Image)
1030 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1032 return QString("Unknown type has no name!");
1035 void VymModel::redo()
1037 // Can we undo at all?
1038 if (redosAvail<1) return;
1040 bool blockSaveStateOrg=blockSaveState;
1041 blockSaveState=true;
1045 if (undosAvail<stepsTotal) undosAvail++;
1047 if (curStep>stepsTotal) curStep=1;
1048 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1049 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1050 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1051 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1052 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1053 QString version=undoSet.readEntry ("/history/version");
1055 /* TODO Maybe check for version, if we save the history
1056 if (!checkVersion(version))
1057 QMessageBox::warning(0,tr("Warning"),
1058 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1061 // Find out current undo directory
1062 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1066 cout << "VymModel::redo() begin\n";
1067 cout << " undosAvail="<<undosAvail<<endl;
1068 cout << " redosAvail="<<redosAvail<<endl;
1069 cout << " curStep="<<curStep<<endl;
1070 cout << " ---------------------------"<<endl;
1071 cout << " comment="<<comment.toStdString()<<endl;
1072 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1073 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1074 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1075 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1076 cout << " ---------------------------"<<endl<<endl;
1079 // select object before redo
1080 if (!redoSelection.isEmpty())
1081 select (redoSelection);
1084 parseAtom (redoCommand);
1087 blockSaveState=blockSaveStateOrg;
1089 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1090 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1091 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1092 undoSet.writeSettings(histPath);
1094 mainWindow->updateHistory (undoSet);
1097 /* TODO remove testing
1098 cout << "ME::redo() end\n";
1099 cout << " undosAvail="<<undosAvail<<endl;
1100 cout << " redosAvail="<<redosAvail<<endl;
1101 cout << " curStep="<<curStep<<endl;
1102 cout << " ---------------------------"<<endl<<endl;
1108 bool VymModel::isRedoAvailable()
1110 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1116 void VymModel::undo()
1118 // Can we undo at all?
1119 if (undosAvail<1) return;
1121 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1123 bool blockSaveStateOrg=blockSaveState;
1124 blockSaveState=true;
1126 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1127 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1128 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1129 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1130 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1131 QString version=undoSet.readEntry ("/history/version");
1133 /* TODO Maybe check for version, if we save the history
1134 if (!checkVersion(version))
1135 QMessageBox::warning(0,tr("Warning"),
1136 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1139 // Find out current undo directory
1140 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1142 // select object before undo
1143 if (!undoSelection.isEmpty())
1144 select (undoSelection);
1148 cout << "VymModel::undo() begin\n";
1149 cout << " undosAvail="<<undosAvail<<endl;
1150 cout << " redosAvail="<<redosAvail<<endl;
1151 cout << " curStep="<<curStep<<endl;
1152 cout << " ---------------------------"<<endl;
1153 cout << " comment="<<comment.toStdString()<<endl;
1154 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1155 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1156 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1157 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1158 cout << " ---------------------------"<<endl<<endl;
1160 parseAtom (undoCommand);
1165 if (curStep<1) curStep=stepsTotal;
1169 blockSaveState=blockSaveStateOrg;
1170 /* TODO remove testing
1171 cout << "VymModel::undo() end\n";
1172 cout << " undosAvail="<<undosAvail<<endl;
1173 cout << " redosAvail="<<redosAvail<<endl;
1174 cout << " curStep="<<curStep<<endl;
1175 cout << " ---------------------------"<<endl<<endl;
1178 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1179 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1180 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1181 undoSet.writeSettings(histPath);
1183 mainWindow->updateHistory (undoSet);
1186 emitShowSelection();
1189 bool VymModel::isUndoAvailable()
1191 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1197 void VymModel::gotoHistoryStep (int i)
1199 // Restore variables
1200 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1201 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1203 if (i<0) i=undosAvail+redosAvail;
1205 // Clicking above current step makes us undo things
1208 for (int j=0; j<undosAvail-i; j++) undo();
1211 // Clicking below current step makes us redo things
1213 for (int j=undosAvail; j<i; j++)
1215 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1219 // And ignore clicking the current row ;-)
1223 QString VymModel::getHistoryPath()
1225 QString histName(QString("history-%1").arg(curStep));
1226 return (tmpMapDir+"/"+histName);
1229 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1231 sendData(redoCom); //FIXME-3 testing
1236 if (blockSaveState) return;
1238 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1240 // Find out current undo directory
1241 if (undosAvail<stepsTotal) undosAvail++;
1243 if (curStep>stepsTotal) curStep=1;
1245 QString backupXML="";
1246 QString histDir=getHistoryPath();
1247 QString bakMapPath=histDir+"/map.xml";
1249 // Create histDir if not available
1252 makeSubDirs (histDir);
1254 // Save depending on how much needs to be saved
1256 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1258 QString undoCommand="";
1259 if (savemode==UndoCommand)
1261 undoCommand=undoCom;
1263 else if (savemode==PartOfMap )
1265 undoCommand=undoCom;
1266 undoCommand.replace ("PATH",bakMapPath);
1270 if (!backupXML.isEmpty())
1271 // Write XML Data to disk
1272 saveStringToDisk (bakMapPath,backupXML);
1274 // We would have to save all actions in a tree, to keep track of
1275 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1278 // Write the current state to disk
1279 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1280 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1281 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1282 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1283 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1284 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1285 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1286 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1287 undoSet.setEntry (QString("/history/version"),vymVersion);
1288 undoSet.writeSettings(histPath);
1292 // TODO remove after testing
1293 //cout << " into="<< histPath.toStdString()<<endl;
1294 cout << " stepsTotal="<<stepsTotal<<
1295 ", undosAvail="<<undosAvail<<
1296 ", redosAvail="<<redosAvail<<
1297 ", curStep="<<curStep<<endl;
1298 cout << " ---------------------------"<<endl;
1299 cout << " comment="<<comment.toStdString()<<endl;
1300 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1301 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1302 cout << " redoCom="<<redoCom.toStdString()<<endl;
1303 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1304 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1305 cout << " ---------------------------"<<endl;
1308 mainWindow->updateHistory (undoSet);
1314 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1316 // save the selected part of the map, Undo will replace part of map
1317 QString undoSelection="";
1319 undoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1322 QString redoSelection="";
1324 redoSelection=getSelectString(undoSel);
1326 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1329 saveState (PartOfMap,
1330 undoSelection, "addMapReplace (\"PATH\")",
1336 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1340 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1343 QString undoSelection=getSelectString (redoSel->parent() );
1344 QString redoSelection=getSelectString(redoSel);
1345 if (redoSel->getType()==TreeItem::Branch)
1347 // save the selected branch of the map, Undo will insert part of map
1348 saveState (PartOfMap,
1349 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1350 redoSelection, "delete ()",
1357 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1359 // "Normal" savestate: save commands, selections and comment
1360 // so just save commands for undo and redo
1361 // and use current selection
1363 QString redoSelection="";
1364 if (redoSel) redoSelection=getSelectString(redoSel);
1365 QString undoSelection="";
1366 if (undoSel) undoSelection=getSelectString(undoSel);
1368 saveState (UndoCommand,
1375 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1377 // "Normal" savestate: save commands, selections and comment
1378 // so just save commands for undo and redo
1379 // and use current selection
1380 saveState (UndoCommand,
1387 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1389 // "Normal" savestate applied to model (no selection needed):
1390 // save commands and comment
1391 saveState (UndoCommand,
1399 QGraphicsScene* VymModel::getScene ()
1404 TreeItem* VymModel::findBySelectString(QString s)
1406 if (s.isEmpty() ) return NULL;
1408 // Old maps don't have multiple mapcenters and don't save full path
1409 if (s.left(2) !="mc")
1412 QStringList parts=s.split (",");
1415 TreeItem *ti=rootItem;
1417 while (!parts.isEmpty() )
1419 typ=parts.first().left(2);
1420 n=parts.first().right(parts.first().length() - 3).toInt();
1421 parts.removeFirst();
1422 if (typ=="mc" || typ=="bo")
1423 ti=ti->getBranchNum (n);
1427 ti=ti->getImageNum (n);
1433 TreeItem* VymModel::findID (const QString &s)
1436 for (int i=0; i<rootItem->branchCount(); i++)
1438 ti=rootItem->getBranchNum(i)->findID (s);
1444 //////////////////////////////////////////////
1446 //////////////////////////////////////////////
1447 void VymModel::setVersion (const QString &s)
1452 void VymModel::setAuthor (const QString &s)
1455 QString ("setMapAuthor (\"%1\")").arg(author),
1456 QString ("setMapAuthor (\"%1\")").arg(s),
1457 QString ("Set author of map to \"%1\"").arg(s)
1462 QString VymModel::getAuthor()
1467 void VymModel::setComment (const QString &s)
1470 QString ("setMapComment (\"%1\")").arg(comment),
1471 QString ("setMapComment (\"%1\")").arg(s),
1472 QString ("Set comment of map")
1477 QString VymModel::getComment ()
1482 QString VymModel::getDate ()
1484 return QDate::currentDate().toString ("yyyy-MM-dd");
1487 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1490 BranchItem *cur=NULL;
1491 BranchItem *prev=NULL;
1502 void VymModel::setHeading(const QString &s)
1504 BranchItem *selbi=getSelectedBranchItem();
1509 "setHeading (\""+selbi->getHeading()+"\")",
1511 "setHeading (\""+s+"\")",
1512 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1513 selbi->setHeading(s );
1514 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1517 // selection.update(); //FIXME-4
1522 BranchItem* VymModel::findText (QString s, bool cs)
1525 QTextDocument::FindFlags flags=0;
1526 if (cs) flags=QTextDocument::FindCaseSensitively;
1529 { // Nothing found or new find process
1531 // nothing found, start again
1535 next (findCurrent,findPrevious,d);
1537 bool searching=true;
1538 bool foundNote=false;
1539 while (searching && !EOFind)
1543 // Searching in Note
1544 if (findCurrent->getNote().contains(s,cs))
1546 select (findCurrent);
1548 if (getSelectedBranch()!=itFind)
1551 emitShowSelection();
1554 if (textEditor->findText(s,flags))
1560 // Searching in Heading
1561 if (searching && findCurrent->getHeading().contains (s,cs) )
1563 select(findCurrent);
1569 if (!next(findCurrent,findPrevious,d) )
1572 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1575 return getSelectedBranchItem();
1580 void VymModel::findReset()
1581 { // Necessary if text to find changes during a find process
1587 void VymModel::setScene (QGraphicsScene *s)
1589 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1590 //init(); // Here we have a mapScene set,
1591 // which is (still) needed to create MapCenters
1594 void VymModel::setURL(const QString &url)
1596 TreeItem *selti=getSelectedItem();
1599 QString oldurl=selti->getURL();
1600 selti->setURL (url);
1603 QString ("setURL (\"%1\")").arg(oldurl),
1605 QString ("setURL (\"%1\")").arg(url),
1606 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1609 emitDataHasChanged (selti);
1610 emitShowSelection();
1614 QString VymModel::getURL()
1616 TreeItem *selti=getSelectedItem();
1618 return selti->getURL();
1623 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1625 return QStringList();
1628 BranchObj *bo=getSelectedBranch();
1634 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1642 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
1644 FloatImageObj *fio=selection.getFloatImage();
1647 TreeItem *dst=findBySelectString (dstString);
1648 if (dst && dst->isBranchLikeType() )
1650 TreeItem *dstPar=dst->parent();
1651 QString parString=getSelectString(dstPar);
1652 QString fioPreSelectString=getSelectString(fio);
1653 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1654 // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
1656 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1657 fio=((BranchObj*)dst)->getLastFloatImage();
1662 getSelectString(fio),
1663 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1665 QString ("linkTo (\"%1\")").arg(dstString),
1666 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1672 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1675 BranchObj *bo=getSelectedBranch();
1678 QString s=bo->getFrameTypeName();
1679 bo->setFrameType (t);
1680 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1681 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1688 void VymModel::setFrameType(const QString &s) //FIXME-2
1691 BranchObj *bo=getSelectedBranch();
1694 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1695 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1696 bo->setFrameType (s);
1703 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1706 BranchObj *bo=getSelectedBranch();
1709 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1710 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1711 bo->setFramePenColor (c);
1716 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1719 BranchObj *bo=getSelectedBranch();
1722 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1723 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1724 bo->setFrameBrushColor (c);
1728 void VymModel::setFramePadding (const int &i) //FIXME-2
1731 BranchObj *bo=getSelectedBranch();
1734 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1735 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1736 bo->setFramePadding (i);
1743 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1746 BranchObj *bo=getSelectedBranch();
1749 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1750 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1751 bo->setFrameBorderWidth (i);
1758 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1761 BranchObj *bo=getSelectedBranch();
1764 QString u= b ? "false" : "true";
1765 QString r=!b ? "false" : "true";
1769 QString("setIncludeImagesVertically (%1)").arg(u),
1771 QString("setIncludeImagesVertically (%1)").arg(r),
1772 QString("Include images vertically in %1").arg(getObjectName(bo))
1774 bo->setIncludeImagesVer(b);
1779 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1782 BranchObj *bo=getSelectedBranch();
1785 QString u= b ? "false" : "true";
1786 QString r=!b ? "false" : "true";
1790 QString("setIncludeImagesHorizontally (%1)").arg(u),
1792 QString("setIncludeImagesHorizontally (%1)").arg(r),
1793 QString("Include images horizontally in %1").arg(getObjectName(bo))
1795 bo->setIncludeImagesHor(b);
1801 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1804 LinkableMapObj *sel=getSelectedLMO();
1806 (selectionType() == TreeItem::Branch ||
1807 selectionType() == TreeItem::MapCenter ||
1808 selectionType() == TreeItem::Image ))
1810 QString u= b ? "false" : "true";
1811 QString r=!b ? "false" : "true";
1815 QString("setHideLinkUnselected (%1)").arg(u),
1817 QString("setHideLinkUnselected (%1)").arg(r),
1818 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1820 sel->setHideLinkUnselected(b);
1825 void VymModel::setHideExport(bool b)
1827 BranchItem *bi=getSelectedBranchItem();
1830 bi->setHideInExport (b);
1831 QString u= b ? "false" : "true";
1832 QString r=!b ? "false" : "true";
1836 QString ("setHideExport (%1)").arg(u),
1838 QString ("setHideExport (%1)").arg(r),
1839 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1843 // selection.update();
1844 // FIXME-3 VM needed? scene()->update();
1848 void VymModel::toggleHideExport()
1850 BranchItem *selbi=getSelectedBranchItem();
1852 setHideExport ( !selbi->hideInExport() );
1856 void VymModel::copy()
1858 TreeItem *selti=getSelectedItem();
1860 (selti->getType() == TreeItem::Branch ||
1861 selti->getType() == TreeItem::MapCenter ||
1862 selti->getType() == TreeItem::Image ))
1864 if (redosAvail == 0)
1867 QString s=getSelectString(selti);
1868 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1869 curClipboard=curStep;
1872 // Copy also to global clipboard, because we are at last step in history
1873 QString bakMapName(QString("history-%1").arg(curStep));
1874 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1875 copyDir (bakMapDir,clipboardDir );
1877 clipboardEmpty=false;
1883 void VymModel::pasteNoSave(const int &n)
1885 bool old=blockSaveState;
1886 blockSaveState=true;
1887 bool zippedOrg=zipped;
1888 if (redosAvail > 0 || n!=0)
1890 // Use the "historical" buffer
1891 QString bakMapName(QString("history-%1").arg(n));
1892 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1893 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1895 // Use the global buffer
1896 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1901 void VymModel::paste()
1903 BranchItem *selbi=getSelectedBranchItem();
1906 saveStateChangingPart(
1909 QString ("paste (%1)").arg(curClipboard),
1910 QString("Paste to %1").arg( getObjectName(selbi))
1917 void VymModel::cut()
1919 TreeItem *selti=getSelectedItem();
1920 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1928 void VymModel::moveUp()
1930 BranchItem *selbi=getSelectedBranchItem();
1933 if (!selbi->canMoveUp()) return;
1934 QString oldsel=getSelectString();
1935 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1937 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1941 void VymModel::moveDown()
1943 BranchItem *selbi=getSelectedBranchItem();
1946 if (!selbi->canMoveDown()) return;
1947 QString oldsel=getSelectString();
1948 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1950 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1954 void VymModel::sortChildren() // FIXME-2 not implemented yet
1957 BranchObj* bo=getSelectedBranch();
1960 if(treeItem->branchCount()>1)
1962 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1965 emitShowSelection();
1971 MapCenterItem* VymModel::createMapCenter()
1973 MapCenterItem *mci=addMapCenter (QPointF (0,0) );
1978 BranchItem* VymModel::createBranch()
1980 return addNewBranchInt (-2);
1983 TreeItem* VymModel::createImage() //FIXME-2
1986 BranchObj *bo=getSelectedBranch();
1989 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1992 QList<QVariant> cData;
1993 cData << "VM:createImage" << "undef"<<"undef";
1994 TreeItem *parti=bo->getTreeItem();
1995 TreeItem *ti=new TreeItem (cData,parti);
1996 ti->setLMO (newfio);
1997 ti->setType (TreeItem::Image);
1998 parti->appendChild (ti);
2002 newfio->setTreeItem (ti);
2003 select (newfio); // FIXME-2 VM really needed here?
2011 MapCenterItem* VymModel::addMapCenter ()
2013 MapCenterItem *mci=addMapCenter (contextPos);
2014 //FIXME-3 selection.select (mco);
2016 emitShowSelection();
2021 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2022 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2027 MapCenterItem* VymModel::addMapCenter(QPointF absPos)
2031 QModelIndex parix=index(rootItem);
2033 int n=rootItem->branchCount();
2035 emit (layoutAboutToBeChanged() );
2036 beginInsertRows (parix,n,n+1);
2038 QList<QVariant> cData;
2039 cData << "VM:addMapCenter" << "undef"<<"undef";
2040 MapCenterItem *mci=new MapCenterItem (cData);
2041 mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2042 rootItem->appendChild (mci);
2045 emit (layoutChanged() );
2048 BranchObj *newbo=mci->createMapObj(mapScene);
2052 if (!mci->getHeading().isEmpty() )
2054 newbo->updateHeading();
2055 newbo->setColor (headingColor);
2059 //newbo->updateLink(); //FIXME-3
2062 //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2063 mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
2064 mci->setLMO (mapCenter);
2065 mapCenter->updateHeading();
2066 mapCenter->move (absPos);
2067 mapCenter->setVisibility (true);
2068 //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2073 BranchItem* VymModel::addNewBranchInt(int num)
2075 // Depending on pos:
2076 // -3 insert in children of parent above selection
2077 // -2 add branch to selection
2078 // -1 insert in children of parent below selection
2079 // 0..n insert in children of parent at pos
2080 BranchItem *selbi=getSelectedBranchItem();
2084 QList<QVariant> cData;
2085 cData << "new" << "undef"<<"undef";
2090 BranchItem *newbi=new BranchItem (cData);
2091 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2093 emit (layoutAboutToBeChanged() );
2099 n=parbi->childCount();
2100 beginInsertRows (parix,n,n+1);
2101 parbi->appendChild (newbi);
2105 // insert below selection
2106 parbi=(BranchItem*)selbi->parent();
2108 n=selbi->childNumber()+1;
2109 beginInsertRows (parix,n,n);
2110 parbi->insertBranch(n,newbi);
2114 // insert above selection
2115 parbi=(BranchItem*)selbi->parent();
2117 n=selbi->childNumber();
2118 beginInsertRows (parix,n,n);
2119 parbi->insertBranch(n,newbi);
2122 emit (layoutChanged() );
2124 // save scroll state. If scrolled, automatically select
2125 // new branch in order to tmp unscroll parent...
2126 newbi->createMapObj(mapScene);
2133 BranchItem* VymModel::addNewBranch(int pos)
2135 // Different meaning than num in addNewBranchInt!
2139 BranchItem *newbi=NULL;
2140 BranchItem *selbi=getSelectedBranchItem();
2144 // FIXME-3 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2146 newbi=addNewBranchInt (pos-2);
2154 QString ("addBranch (%1)").arg(pos),
2155 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2158 // selection.update(); FIXME-3
2159 latestAddedItem=newbi;
2160 // In Network mode, the client needs to know where the new branch is,
2161 // so we have to pass on this information via saveState.
2162 // TODO: Get rid of this positioning workaround
2163 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2164 sendData ("selectLatestAdded ()");
2165 sendData (QString("move %1").arg(ps));
2174 BranchItem* VymModel::addNewBranchBefore() //FIXME-2
2177 BranchObj *newbo=NULL;
2178 BranchObj *bo = getSelectedBranch();
2179 if (bo && selectionType()==TreeItem::Branch)
2180 // We accept no MapCenterObj here, so we _have_ a parent
2182 QPointF p=bo->getRelPos();
2185 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2187 // add below selection
2188 newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
2192 newbo->move2RelPos (p);
2194 // Move selection to new branch
2195 bo->linkTo (newbo,-1);
2197 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2198 QString ("Add branch before %1").arg(getObjectName(bo)));
2201 // selection.update(); FIXME-3
2204 latestSelectionString=selection.getSelectString();
2210 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2214 cout << "VM::relinkBranch "<<branch->getHeadingStd()<<" to "<<dst->getHeadingStd()<<" at "<<pos<<endl;
2215 emit (layoutAboutToBeChanged() );
2216 BranchItem *branchpi=(BranchItem*)branch->parent();
2217 // Remove at current position
2218 int n=branch->childNum();
2219 beginRemoveRows (index(branchpi),n,n);
2220 branchpi->removeChild (n);
2223 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2225 // Append as last branch to dst
2226 if (dst->branchCount()==0)
2229 n=dst->getFirstBranch()->childNumber();
2230 beginInsertRows (index(dst),n+pos,n+pos);
2231 dst->insertBranch (pos,branch);
2234 branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
2235 emit (layoutChanged() );
2236 reposition(); // both for moveUp/Down and relinking
2243 void VymModel::deleteSelection()
2245 BranchItem *selbi=getSelectedBranchItem();
2249 TreeItem *pi=selbi->parent();
2250 QModelIndex parentIndex=index(pi);
2252 if (selbi->isBranchLikeType() )
2255 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2257 emit (layoutAboutToBeChanged() );
2259 int n=selbi->childNum();
2260 beginRemoveRows (parentIndex,n,n);
2261 removeRows (n,1,parentIndex);
2264 emitShowSelection();
2267 emit (layoutChanged() );
2270 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2275 BranchObj* par=(BranchObj*)fio->getParObj();
2276 saveStateChangingPart(
2280 QString("Delete %1").arg(getObjectName(fio))
2283 par->removeFloatImage(fio);
2286 emitShowSelection();
2292 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2296 BranchObj *bo=getSelectedBranch();
2300 par=(BranchObj*)(bo->getParObj());
2302 // Don't use this on mapcenter
2305 // Check if we have childs at all to keep
2306 if (bo->getTreeItem()->branchCount()==0)
2312 QPointF p=bo->getRelPos();
2313 saveStateChangingPart(
2316 "deleteKeepChildren ()",
2317 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2320 QString sel=getSelectString(bo);
2322 par->removeBranchHere(bo);
2325 getSelectedBranch()->move2RelPos (p);
2330 void VymModel::deleteChildren() //FIXME-2 VM still missing
2334 BranchObj *bo=getSelectedBranch();
2337 saveStateChangingPart(
2340 "deleteChildren ()",
2341 QString( "Remove children of branch %1").arg(getObjectName(bo))
2343 bo->removeChildren();
2349 bool VymModel::scrollBranch(BranchItem *bi)
2353 if (bi->isScrolled()) return false;
2354 if (bi->branchCount()==0) return false;
2355 if (bi->depth()==0) return false;
2356 if (bi->toggleScroll())
2363 QString ("%1 ()").arg(u),
2365 QString ("%1 ()").arg(r),
2366 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2368 emitDataHasChanged(bi);
2370 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2377 bool VymModel::unscrollBranch(BranchItem *bi)
2381 if (!bi->isScrolled()) return false;
2382 if (bi->branchCount()==0) return false;
2383 if (bi->depth()==0) return false;
2390 QString ("%1 ()").arg(u),
2392 QString ("%1 ()").arg(r),
2393 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2396 emitDataHasChanged(bi);
2399 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2405 void VymModel::toggleScroll()
2407 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2408 if (bi && bi->isBranchLikeType() )
2410 if (bi->isScrolled())
2411 unscrollBranch (bi);
2415 // saveState is called in above functions
2418 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2422 BranchObj *bo=getSelectedBranch();
2428 if (bo->isScrolled()) unscrollBranch (bo);
2435 void VymModel::emitExpandAll()
2437 emit (expandAll() );
2440 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2442 BranchItem *bi=getSelectedBranchItem();
2446 if (bi->isActiveStandardFlag(name))
2458 QString("%1 (\"%2\")").arg(u).arg(name),
2460 QString("%1 (\"%2\")").arg(r).arg(name),
2461 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2462 bi->toggleStandardFlag (name, master);
2468 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2471 BranchObj *bo=getSelectedBranch();
2474 FloatImageObj *fio=bo->addFloatImage();
2476 fio->setOriginalFilename("No original filename (image added by dropevent)");
2477 QString s=getSelectString(bo);
2478 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2479 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2481 // FIXME-3 VM needed? scene()->update();
2487 void VymModel::colorBranch (QColor c) //FIXME-2
2490 BranchObj *bo=getSelectedBranch();
2495 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2497 QString ("colorBranch (\"%1\")").arg(c.name()),
2498 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2500 bo->setColor(c); // color branch
2505 void VymModel::colorSubtree (QColor c) //FIXME-2
2508 BranchObj *bo=getSelectedBranch();
2511 saveStateChangingPart(
2514 QString ("colorSubtree (\"%1\")").arg(c.name()),
2515 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2517 bo->setColorSubtree (c); // color links, color children
2522 QColor VymModel::getCurrentHeadingColor() //FIXME-2
2525 BranchObj *bo=getSelectedBranch();
2526 if (bo) return bo->getColor();
2528 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2535 void VymModel::editURL()
2537 TreeItem *selti=getSelectedItem();
2541 QString text = QInputDialog::getText(
2542 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2543 selti->getURL(), &ok, NULL);
2545 // user entered something and pressed OK
2550 void VymModel::editLocalURL()
2552 TreeItem *selti=getSelectedItem();
2555 QStringList filters;
2556 filters <<"All files (*)";
2557 filters << tr("Text","Filedialog") + " (*.txt)";
2558 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2559 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2560 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2561 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2562 fd->setFilters (filters);
2563 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2564 fd->setDirectory (lastFileDir);
2565 if (! selti->getVymLink().isEmpty() )
2566 fd->selectFile( selti->getURL() );
2569 if ( fd->exec() == QDialog::Accepted )
2571 lastFileDir=QDir (fd->directory().path());
2572 setURL (fd->selectedFile() );
2578 void VymModel::editHeading2URL()
2580 TreeItem *selti=getSelectedItem();
2582 setURL (selti->getHeading());
2585 void VymModel::editBugzilla2URL()
2587 TreeItem *selti=getSelectedItem();
2590 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2595 void VymModel::editFATE2URL()
2597 TreeItem *selti=getSelectedItem();
2600 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2603 "setURL (\""+selti->getURL()+"\")",
2605 "setURL (\""+url+"\")",
2606 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2608 selti->setURL (url);
2609 // FIXME-4 updateActions();
2613 void VymModel::editVymLink()
2615 BranchItem *bi=getSelectedBranchItem();
2618 QStringList filters;
2619 filters <<"VYM map (*.vym)";
2620 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2621 fd->setFilters (filters);
2622 fd->setCaption(vymName+" - " +tr("Link to another map"));
2623 fd->setDirectory (lastFileDir);
2624 if (! bi->getVymLink().isEmpty() )
2625 fd->selectFile( bi->getVymLink() );
2629 if ( fd->exec() == QDialog::Accepted )
2631 lastFileDir=QDir (fd->directory().path());
2634 "setVymLink (\""+bi->getVymLink()+"\")",
2636 "setVymLink (\""+fd->selectedFile()+"\")",
2637 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2639 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2644 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2646 // Internal function, no saveState needed
2647 BranchItem *bi=getSelectedBranchItem();
2653 //selection.update();
2654 emitShowSelection();
2658 void VymModel::deleteVymLink()
2660 BranchItem *bi=getSelectedBranchItem();
2665 "setVymLink (\""+bi->getVymLink()+"\")",
2667 "setVymLink (\"\")",
2668 QString("Unset vymlink of %1").arg(getObjectName(bi))
2670 bi->setVymLink ("" );
2676 QString VymModel::getVymLink()
2678 BranchItem *bi=getSelectedBranchItem();
2680 return bi->getVymLink();
2686 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2688 return QStringList();
2691 BranchObj *bo=getSelectedBranch();
2697 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2706 void VymModel::followXLink(int i) // FIXME-2
2710 BranchObj *bo=getSelectedBranch();
2713 bo=bo->XLinkTargetAt(i);
2716 selection.select(bo);
2717 emitShowSelection();
2723 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2727 BranchObj *bo=getSelectedBranch();
2730 XLinkObj *xlo=bo->XLinkAt(i);
2733 EditXLinkDialog dia;
2735 dia.setSelection(bo);
2736 if (dia.exec() == QDialog::Accepted)
2738 if (dia.useSettingsGlobal() )
2740 setMapDefXLinkColor (xlo->getColor() );
2741 setMapDefXLinkWidth (xlo->getWidth() );
2743 if (dia.deleteXLink())
2744 bo->deleteXLinkAt(i);
2755 //////////////////////////////////////////////
2757 //////////////////////////////////////////////
2759 void VymModel::parseAtom(const QString &atom)
2761 //BranchObj *selb=getSelectedBranch(); // FIXME-4
2762 TreeItem* selti=getSelectedItem();
2763 BranchItem *selbi=getSelectedBranchItem();
2769 // Split string s into command and parameters
2770 parser.parseAtom (atom);
2771 QString com=parser.getCommand();
2773 // External commands
2774 /////////////////////////////////////////////////////////////////////
2775 if (com=="addBranch")
2779 parser.setError (Aborted,"Nothing selected");
2780 } else if (! selbi )
2782 parser.setError (Aborted,"Type of selection is not a branch");
2787 if (parser.checkParCount(pl))
2789 if (parser.parCount()==0)
2793 n=parser.parInt (ok,0);
2794 if (ok ) addNewBranch (n);
2798 /////////////////////////////////////////////////////////////////////
2799 } else if (com=="addBranchBefore")
2803 parser.setError (Aborted,"Nothing selected");
2804 } else if (! selbi )
2806 parser.setError (Aborted,"Type of selection is not a branch");
2809 if (parser.parCount()==0)
2811 addNewBranchBefore ();
2814 /////////////////////////////////////////////////////////////////////
2815 } else if (com==QString("addMapCenter"))
2817 if (parser.checkParCount(2))
2819 x=parser.parDouble (ok,0);
2822 y=parser.parDouble (ok,1);
2823 if (ok) addMapCenter (QPointF(x,y));
2826 /////////////////////////////////////////////////////////////////////
2827 } else if (com==QString("addMapReplace"))
2831 parser.setError (Aborted,"Nothing selected");
2832 } else if (! selbi )
2834 parser.setError (Aborted,"Type of selection is not a branch");
2835 } else if (parser.checkParCount(1))
2837 //s=parser.parString (ok,0); // selection
2838 t=parser.parString (ok,0); // path to map
2839 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2840 addMapReplaceInt(getSelectString(selbi),t);
2842 /////////////////////////////////////////////////////////////////////
2843 } else if (com==QString("addMapInsert"))
2847 parser.setError (Aborted,"Nothing selected");
2848 } else if (! selbi )
2850 parser.setError (Aborted,"Type of selection is not a branch");
2853 if (parser.checkParCount(2))
2855 t=parser.parString (ok,0); // path to map
2856 n=parser.parInt(ok,1); // position
2857 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2858 addMapInsertInt(t,n);
2861 /////////////////////////////////////////////////////////////////////
2862 } else if (com=="clearFlags")
2866 parser.setError (Aborted,"Nothing selected");
2867 } else if (! selbi )
2869 parser.setError (Aborted,"Type of selection is not a branch");
2870 } else if (parser.checkParCount(0))
2872 selbi->deactivateAllStandardFlags();
2874 /////////////////////////////////////////////////////////////////////
2875 } else if (com=="colorBranch")
2879 parser.setError (Aborted,"Nothing selected");
2880 } else if (! selbi )
2882 parser.setError (Aborted,"Type of selection is not a branch");
2883 } else if (parser.checkParCount(1))
2885 QColor c=parser.parColor (ok,0);
2886 if (ok) colorBranch (c);
2888 /////////////////////////////////////////////////////////////////////
2889 } else if (com=="colorSubtree")
2893 parser.setError (Aborted,"Nothing selected");
2894 } else if (! selbi )
2896 parser.setError (Aborted,"Type of selection is not a branch");
2897 } else if (parser.checkParCount(1))
2899 QColor c=parser.parColor (ok,0);
2900 if (ok) colorSubtree (c);
2902 /////////////////////////////////////////////////////////////////////
2903 } else if (com=="copy")
2907 parser.setError (Aborted,"Nothing selected");
2908 } else if (! selbi )
2910 parser.setError (Aborted,"Type of selection is not a branch");
2911 } else if (parser.checkParCount(0))
2913 //FIXME-1 missing action for copy
2915 /////////////////////////////////////////////////////////////////////
2916 } else if (com=="cut")
2920 parser.setError (Aborted,"Nothing selected");
2921 } else if ( selectionType()!=TreeItem::Branch &&
2922 selectionType()!=TreeItem::MapCenter &&
2923 selectionType()!=TreeItem::Image )
2925 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2926 } else if (parser.checkParCount(0))
2930 /////////////////////////////////////////////////////////////////////
2931 } else if (com=="delete")
2935 parser.setError (Aborted,"Nothing selected");
2937 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2939 parser.setError (Aborted,"Type of selection is wrong.");
2942 else if (parser.checkParCount(0))
2946 /////////////////////////////////////////////////////////////////////
2947 } else if (com=="deleteKeepChildren")
2951 parser.setError (Aborted,"Nothing selected");
2952 } else if (! selbi )
2954 parser.setError (Aborted,"Type of selection is not a branch");
2955 } else if (parser.checkParCount(0))
2957 deleteKeepChildren();
2959 /////////////////////////////////////////////////////////////////////
2960 } else if (com=="deleteChildren")
2964 parser.setError (Aborted,"Nothing selected");
2967 parser.setError (Aborted,"Type of selection is not a branch");
2968 } else if (parser.checkParCount(0))
2972 /////////////////////////////////////////////////////////////////////
2973 } else if (com=="exportASCII")
2977 if (parser.parCount()>=1)
2978 // Hey, we even have a filename
2979 fname=parser.parString(ok,0);
2982 parser.setError (Aborted,"Could not read filename");
2985 exportASCII (fname,false);
2987 /////////////////////////////////////////////////////////////////////
2988 } else if (com=="exportImage")
2992 if (parser.parCount()>=2)
2993 // Hey, we even have a filename
2994 fname=parser.parString(ok,0);
2997 parser.setError (Aborted,"Could not read filename");
3000 QString format="PNG";
3001 if (parser.parCount()>=2)
3003 format=parser.parString(ok,1);
3005 exportImage (fname,false,format);
3007 /////////////////////////////////////////////////////////////////////
3008 } else if (com=="exportXHTML")
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 exportXHTML (fname,false);
3022 /////////////////////////////////////////////////////////////////////
3023 } else if (com=="exportXML")
3027 if (parser.parCount()>=2)
3028 // Hey, we even have a filename
3029 fname=parser.parString(ok,1);
3032 parser.setError (Aborted,"Could not read filename");
3035 exportXML (fname,false);
3037 /////////////////////////////////////////////////////////////////////
3038 } else if (com=="importDir")
3042 parser.setError (Aborted,"Nothing selected");
3043 } else if (! selbi )
3045 parser.setError (Aborted,"Type of selection is not a branch");
3046 } else if (parser.checkParCount(1))
3048 s=parser.parString(ok,0);
3049 if (ok) importDirInt(s);
3051 /////////////////////////////////////////////////////////////////////
3052 } else /* FIXME-2 if (com=="linkTo")
3056 parser.setError (Aborted,"Nothing selected");
3059 if (parser.checkParCount(4))
3061 // 0 selectstring of parent
3062 // 1 num in parent (for branches)
3063 // 2,3 x,y of mainbranch or mapcenter
3064 s=parser.parString(ok,0);
3065 LinkableMapObj *dst=findObjBySelect (s);
3068 if (typeid(*dst) == typeid(BranchObj) )
3070 // Get number in parent
3071 n=parser.parInt (ok,1);
3074 selb->linkTo ((BranchObj*)(dst),n);
3077 } else if (typeid(*dst) == typeid(MapCenterObj) )
3079 selb->linkTo ((BranchObj*)(dst),-1);
3080 // Get coordinates of mainbranch
3081 x=parser.parDouble(ok,2);
3084 y=parser.parDouble(ok,3);
3094 } else if ( selectionType() == TreeItem::Image)
3096 if (parser.checkParCount(1))
3098 // 0 selectstring of parent
3099 s=parser.parString(ok,0);
3100 LinkableMapObj *dst=findObjBySelect (s);
3103 if (typeid(*dst) == typeid(BranchObj) ||
3104 typeid(*dst) == typeid(MapCenterObj))
3105 linkFloatImageTo (getSelectString(dst));
3107 parser.setError (Aborted,"Destination is not a branch");
3110 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3111 /////////////////////////////////////////////////////////////////////
3112 } else */ if (com=="loadImage")
3116 parser.setError (Aborted,"Nothing selected");
3117 } else if (! selbi )
3119 parser.setError (Aborted,"Type of selection is not a branch");
3120 } else if (parser.checkParCount(1))
3122 s=parser.parString(ok,0);
3123 if (ok) loadFloatImageInt (s);
3125 /////////////////////////////////////////////////////////////////////
3126 } else if (com=="moveUp")
3130 parser.setError (Aborted,"Nothing selected");
3131 } else if (! selbi )
3133 parser.setError (Aborted,"Type of selection is not a branch");
3134 } else if (parser.checkParCount(0))
3138 /////////////////////////////////////////////////////////////////////
3139 } else if (com=="moveDown")
3143 parser.setError (Aborted,"Nothing selected");
3144 } else if (! selbi )
3146 parser.setError (Aborted,"Type of selection is not a branch");
3147 } else if (parser.checkParCount(0))
3151 /////////////////////////////////////////////////////////////////////
3152 } else if (com=="move")
3156 parser.setError (Aborted,"Nothing selected");
3157 } else if ( selectionType()!=TreeItem::Branch &&
3158 selectionType()!=TreeItem::MapCenter &&
3159 selectionType()!=TreeItem::Image )
3161 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3162 } else if (parser.checkParCount(2))
3164 x=parser.parDouble (ok,0);
3167 y=parser.parDouble (ok,1);
3171 /////////////////////////////////////////////////////////////////////
3172 } else if (com=="moveRel")
3176 parser.setError (Aborted,"Nothing selected");
3177 } else if ( selectionType()!=TreeItem::Branch &&
3178 selectionType()!=TreeItem::MapCenter &&
3179 selectionType()!=TreeItem::Image )
3181 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3182 } else if (parser.checkParCount(2))
3184 x=parser.parDouble (ok,0);
3187 y=parser.parDouble (ok,1);
3188 if (ok) moveRel (x,y);
3191 /////////////////////////////////////////////////////////////////////
3192 } else if (com=="nop")
3194 /////////////////////////////////////////////////////////////////////
3195 } else if (com=="paste")
3199 parser.setError (Aborted,"Nothing selected");
3200 } else if (! selbi )
3202 parser.setError (Aborted,"Type of selection is not a branch");
3203 } else if (parser.checkParCount(1))
3205 n=parser.parInt (ok,0);
3206 if (ok) pasteNoSave(n);
3208 /////////////////////////////////////////////////////////////////////
3209 } else if (com=="qa")
3213 parser.setError (Aborted,"Nothing selected");
3214 } else if (! selbi )
3216 parser.setError (Aborted,"Type of selection is not a branch");
3217 } else if (parser.checkParCount(4))
3220 c=parser.parString (ok,0);
3223 parser.setError (Aborted,"No comment given");
3226 s=parser.parString (ok,1);
3229 parser.setError (Aborted,"First parameter is not a string");
3232 t=parser.parString (ok,2);
3235 parser.setError (Aborted,"Condition is not a string");
3238 u=parser.parString (ok,3);
3241 parser.setError (Aborted,"Third parameter is not a string");
3246 parser.setError (Aborted,"Unknown type: "+s);
3251 parser.setError (Aborted,"Unknown operator: "+t);
3256 parser.setError (Aborted,"Type of selection is not a branch");
3259 if (selbi->getHeading() == u)
3261 cout << "PASSED: " << qPrintable (c) << endl;
3264 cout << "FAILED: " << qPrintable (c) << endl;
3274 /////////////////////////////////////////////////////////////////////
3275 } else if (com=="saveImage")
3277 FloatImageObj *fio=selection.getFloatImage();
3280 parser.setError (Aborted,"Type of selection is not an image");
3281 } else if (parser.checkParCount(2))
3283 s=parser.parString(ok,0);
3286 t=parser.parString(ok,1);
3287 if (ok) saveFloatImageInt (fio,t,s);
3290 /////////////////////////////////////////////////////////////////////
3291 } else if (com=="scroll")
3295 parser.setError (Aborted,"Nothing selected");
3296 } else if (! selbi )
3298 parser.setError (Aborted,"Type of selection is not a branch");
3299 } else if (parser.checkParCount(0))
3301 if (!scrollBranch (selbi))
3302 parser.setError (Aborted,"Could not scroll branch");
3304 /////////////////////////////////////////////////////////////////////
3305 } else if (com=="select")
3307 if (parser.checkParCount(1))
3309 s=parser.parString(ok,0);
3312 /////////////////////////////////////////////////////////////////////
3313 } else if (com=="selectLastBranch")
3317 parser.setError (Aborted,"Nothing selected");
3318 } else if (! selbi )
3320 parser.setError (Aborted,"Type of selection is not a branch");
3321 } else if (parser.checkParCount(0))
3323 BranchItem *bi=selbi->getLastBranch();
3325 parser.setError (Aborted,"Could not select last branch");
3326 select (bi); // FIXME-3 was selectInt
3329 /////////////////////////////////////////////////////////////////////
3330 } else /* FIXME-2 if (com=="selectLastImage")
3334 parser.setError (Aborted,"Nothing selected");
3335 } else if (! selbi )
3337 parser.setError (Aborted,"Type of selection is not a branch");
3338 } else if (parser.checkParCount(0))
3340 FloatImageObj *fio=selb->getLastFloatImage();
3342 parser.setError (Aborted,"Could not select last image");
3343 select (fio); // FIXME-3 was selectInt
3346 /////////////////////////////////////////////////////////////////////
3347 } else */ if (com=="selectLatestAdded")
3349 if (!latestAddedItem)
3351 parser.setError (Aborted,"No latest added object");
3354 if (!select (latestAddedItem))
3355 parser.setError (Aborted,"Could not select latest added object ");
3357 /////////////////////////////////////////////////////////////////////
3358 } else if (com=="setFrameType")
3360 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3362 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3364 else if (parser.checkParCount(1))
3366 s=parser.parString(ok,0);
3367 if (ok) setFrameType (s);
3369 /////////////////////////////////////////////////////////////////////
3370 } else if (com=="setFramePenColor")
3372 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3374 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3376 else if (parser.checkParCount(1))
3378 QColor c=parser.parColor(ok,0);
3379 if (ok) setFramePenColor (c);
3381 /////////////////////////////////////////////////////////////////////
3382 } else if (com=="setFrameBrushColor")
3384 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3386 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3388 else if (parser.checkParCount(1))
3390 QColor c=parser.parColor(ok,0);
3391 if (ok) setFrameBrushColor (c);
3393 /////////////////////////////////////////////////////////////////////
3394 } else if (com=="setFramePadding")
3396 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3398 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3400 else if (parser.checkParCount(1))
3402 n=parser.parInt(ok,0);
3403 if (ok) setFramePadding(n);
3405 /////////////////////////////////////////////////////////////////////
3406 } else if (com=="setFrameBorderWidth")
3408 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3410 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3412 else if (parser.checkParCount(1))
3414 n=parser.parInt(ok,0);
3415 if (ok) setFrameBorderWidth (n);
3417 /////////////////////////////////////////////////////////////////////
3418 } else if (com=="setMapAuthor")
3420 if (parser.checkParCount(1))
3422 s=parser.parString(ok,0);
3423 if (ok) setAuthor (s);
3425 /////////////////////////////////////////////////////////////////////
3426 } else if (com=="setMapComment")
3428 if (parser.checkParCount(1))
3430 s=parser.parString(ok,0);
3431 if (ok) setComment(s);
3433 /////////////////////////////////////////////////////////////////////
3434 } else if (com=="setMapBackgroundColor")
3438 parser.setError (Aborted,"Nothing selected");
3439 } else if (! selbi )
3441 parser.setError (Aborted,"Type of selection is not a branch");
3442 } else if (parser.checkParCount(1))
3444 QColor c=parser.parColor (ok,0);
3445 if (ok) setMapBackgroundColor (c);
3447 /////////////////////////////////////////////////////////////////////
3448 } else if (com=="setMapDefLinkColor")
3452 parser.setError (Aborted,"Nothing selected");
3453 } else if (! selbi )
3455 parser.setError (Aborted,"Type of selection is not a branch");
3456 } else if (parser.checkParCount(1))
3458 QColor c=parser.parColor (ok,0);
3459 if (ok) setMapDefLinkColor (c);
3461 /////////////////////////////////////////////////////////////////////
3462 } else if (com=="setMapLinkStyle")
3464 if (parser.checkParCount(1))
3466 s=parser.parString (ok,0);
3467 if (ok) setMapLinkStyle(s);
3469 /////////////////////////////////////////////////////////////////////
3470 } else if (com=="setHeading")
3474 parser.setError (Aborted,"Nothing selected");
3475 } else if (! selbi )
3477 parser.setError (Aborted,"Type of selection is not a branch");
3478 } else if (parser.checkParCount(1))
3480 s=parser.parString (ok,0);
3484 /////////////////////////////////////////////////////////////////////
3485 } else if (com=="setHideExport")
3489 parser.setError (Aborted,"Nothing selected");
3490 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3492 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3493 } else if (parser.checkParCount(1))
3495 b=parser.parBool(ok,0);
3496 if (ok) setHideExport (b);
3498 /////////////////////////////////////////////////////////////////////
3499 } else if (com=="setIncludeImagesHorizontally")
3503 parser.setError (Aborted,"Nothing selected");
3506 parser.setError (Aborted,"Type of selection is not a branch");
3507 } else if (parser.checkParCount(1))
3509 b=parser.parBool(ok,0);
3510 if (ok) setIncludeImagesHor(b);
3512 /////////////////////////////////////////////////////////////////////
3513 } else if (com=="setIncludeImagesVertically")
3517 parser.setError (Aborted,"Nothing selected");
3520 parser.setError (Aborted,"Type of selection is not a branch");
3521 } else if (parser.checkParCount(1))
3523 b=parser.parBool(ok,0);
3524 if (ok) setIncludeImagesVer(b);
3526 /////////////////////////////////////////////////////////////////////
3527 } else if (com=="setHideLinkUnselected")
3531 parser.setError (Aborted,"Nothing selected");
3532 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3534 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3535 } else if (parser.checkParCount(1))
3537 b=parser.parBool(ok,0);
3538 if (ok) setHideLinkUnselected(b);
3540 /////////////////////////////////////////////////////////////////////
3541 } else if (com=="setSelectionColor")
3543 if (parser.checkParCount(1))
3545 QColor c=parser.parColor (ok,0);
3546 if (ok) setSelectionColorInt (c);
3548 /////////////////////////////////////////////////////////////////////
3549 } else if (com=="setURL")
3553 parser.setError (Aborted,"Nothing selected");
3554 } else if (! selbi )
3556 parser.setError (Aborted,"Type of selection is not a branch");
3557 } else if (parser.checkParCount(1))
3559 s=parser.parString (ok,0);
3562 /////////////////////////////////////////////////////////////////////
3563 } else if (com=="setVymLink")
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);
3574 if (ok) setVymLink(s);
3577 /////////////////////////////////////////////////////////////////////
3578 else if (com=="setFlag")
3582 parser.setError (Aborted,"Nothing selected");
3583 } else if (! selbi )
3585 parser.setError (Aborted,"Type of selection is not a branch");
3586 } else if (parser.checkParCount(1))
3588 s=parser.parString(ok,0);
3590 selbi->activateStandardFlag(s);
3592 /////////////////////////////////////////////////////////////////////
3593 } else /* FIXME-2 if (com=="setFrameType")
3597 parser.setError (Aborted,"Nothing selected");
3600 parser.setError (Aborted,"Type of selection is not a branch");
3601 } else if (parser.checkParCount(1))
3603 s=parser.parString(ok,0);
3607 /////////////////////////////////////////////////////////////////////
3608 } else*/ if (com=="sortChildren")
3612 parser.setError (Aborted,"Nothing selected");
3613 } else if (! selbi )
3615 parser.setError (Aborted,"Type of selection is not a branch");
3616 } else if (parser.checkParCount(0))
3620 /////////////////////////////////////////////////////////////////////
3621 } else if (com=="toggleFlag")
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(1))
3631 s=parser.parString(ok,0);
3633 selbi->toggleStandardFlag(s);
3635 /////////////////////////////////////////////////////////////////////
3636 } else if (com=="unscroll")
3640 parser.setError (Aborted,"Nothing selected");
3641 } else if (! selbi )
3643 parser.setError (Aborted,"Type of selection is not a branch");
3644 } else if (parser.checkParCount(0))
3646 if (!unscrollBranch (selbi))
3647 parser.setError (Aborted,"Could not unscroll branch");
3649 /////////////////////////////////////////////////////////////////////
3650 } else if (com=="unscrollChildren")
3654 parser.setError (Aborted,"Nothing selected");
3655 } else if (! selbi )
3657 parser.setError (Aborted,"Type of selection is not a branch");
3658 } else if (parser.checkParCount(0))
3660 unscrollChildren ();
3662 /////////////////////////////////////////////////////////////////////
3663 } else if (com=="unsetFlag")
3667 parser.setError (Aborted,"Nothing selected");
3668 } else if (! selbi )
3670 parser.setError (Aborted,"Type of selection is not a branch");
3671 } else if (parser.checkParCount(1))
3673 s=parser.parString(ok,0);
3675 selbi->deactivateStandardFlag(s);
3678 parser.setError (Aborted,"Unknown command");
3681 if (parser.errorLevel()==NoError)
3683 // setChanged(); FIXME-2 should not be called e.g. for export?!
3688 // TODO Error handling
3689 qWarning("VymModel::parseAtom: Error!");
3690 qWarning(parser.errorMessage());
3694 void VymModel::runScript (QString script)
3696 parser.setScript (script);
3698 while (parser.next() )
3699 parseAtom(parser.getAtom());
3702 void VymModel::setExportMode (bool b)
3704 // should be called before and after exports
3705 // depending on the settings
3706 if (b && settings.value("/export/useHideExport","true")=="true")
3707 setHideTmpMode (TreeItem::HideExport);
3709 setHideTmpMode (TreeItem::HideNone);
3712 void VymModel::exportImage(QString fname, bool askName, QString format)
3716 fname=getMapName()+".png";
3723 QFileDialog *fd=new QFileDialog (NULL);
3724 fd->setCaption (tr("Export map as image"));
3725 fd->setDirectory (lastImageDir);
3726 fd->setFileMode(QFileDialog::AnyFile);
3727 fd->setFilters (imageIO.getFilters() );
3730 fl=fd->selectedFiles();
3732 format=imageIO.getType(fd->selectedFilter());
3736 setExportMode (true);
3737 QPixmap pix (getPixmap());
3738 pix.save(fname, format);
3739 setExportMode (false);
3743 void VymModel::exportXML(QString dir, bool askForName)
3747 dir=browseDirectory(NULL,tr("Export XML to directory"));
3748 if (dir =="" && !reallyWriteDirectory(dir) )
3752 // Hide stuff during export, if settings want this
3753 setExportMode (true);
3755 // Create subdirectories
3758 // write to directory
3759 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3762 file.setName ( dir + "/"+mapName+".xml");
3763 if ( !file.open( QIODevice::WriteOnly ) )
3765 // This should neverever happen
3766 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3770 // Write it finally, and write in UTF8, no matter what
3771 QTextStream ts( &file );
3772 ts.setEncoding (QTextStream::UnicodeUTF8);
3776 // Now write image, too
3777 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3779 setExportMode (false);
3782 void VymModel::exportASCII(QString fname,bool askName)
3787 ex.setFile (mapName+".txt");
3793 //ex.addFilter ("TXT (*.txt)");
3794 ex.setDir(lastImageDir);
3795 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3800 setExportMode(true);
3802 setExportMode(false);
3806 void VymModel::exportXHTML (const QString &dir, bool askForName)
3808 ExportXHTMLDialog dia(NULL);
3809 dia.setFilePath (filePath );
3810 dia.setMapName (mapName );
3812 if (dir!="") dia.setDir (dir);
3818 if (dia.exec()!=QDialog::Accepted)
3822 QDir d (dia.getDir());
3823 // Check, if warnings should be used before overwriting
3824 // the output directory
3825 if (d.exists() && d.count()>0)
3828 warn.showCancelButton (true);
3829 warn.setText(QString(
3830 "The directory %1 is not empty.\n"
3831 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3832 warn.setCaption("Warning: Directory not empty");
3833 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3835 if (warn.exec()!=QDialog::Accepted) ok=false;
3842 exportXML (dia.getDir(),false );
3843 dia.doExport(mapName );
3844 //if (dia.hasChanged()) setChanged();
3848 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3853 if (ex.setConfigFile(cf))
3855 setExportMode (true);
3856 ex.exportPresentation();
3857 setExportMode (false);
3864 //////////////////////////////////////////////
3866 //////////////////////////////////////////////
3868 void VymModel::registerEditor(QWidget *me)
3870 mapEditor=(MapEditor*)me;
3873 void VymModel::unregisterEditor(QWidget *)
3878 void VymModel::setContextPos(QPointF p)
3883 void VymModel::unsetContextPos()
3885 contextPos=QPointF();
3888 void VymModel::updateNoteFlag()
3891 TreeItem *selti=getSelectedItem();
3894 if (textEditor->isEmpty())
3897 selti->setNote (textEditor->getText());
3898 emitDataHasChanged(selti);
3904 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3906 //cout << "VM::updateRelPos...\n";
3907 for (int i=0; i<rootItem->branchCount(); i++)
3908 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3911 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3913 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3914 if (blockReposition) return;
3916 for (int i=0;i<rootItem->branchCount(); i++)
3917 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3920 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3923 // Creating (arbitrary) shapes
3926 QRectF rb=bo->getBBox();
3927 if (bo->getDepth()==0)
3929 // Just take BBox of this mapCenter
3930 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3934 // Take union of BBox and TotalBBox
3936 QRectF ra=bo->getTotalBBox();
3937 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3940 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3943 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3945 p <<ra.bottomRight()
3947 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3950 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3955 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3959 // Move all branches and MapCenters away from lmo
3960 // to avoid collisions
3966 BranchObj *boA=(BranchObj*)lmo;
3968 for (int i=0; i<rootItem->branchCount(); i++)
3970 boB=rootItem->getBranchNum(i);
3973 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3976 <<" ("<<qPrintable(boA->getHeading() )<<")"
3977 <<" with ("<< qPrintable (boB->getHeading() )
3980 <<" minT="<<r.minTranslation<<endl<<endl;
3985 QPixmap VymModel::getPixmap()
3987 QRectF mapRect=getTotalBBox();
3988 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3991 pp.setRenderHints(mapEditor->renderHints());
3993 // Don't print the visualisation of selection
3994 selection.unselect();
3996 mapScene->render ( &pp,
3997 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3998 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4000 // Restore selection
4001 selection.reselect();
4007 void VymModel::setMapLinkStyle (const QString & s)
4012 case LinkableMapObj::Line :
4015 case LinkableMapObj::Parabel:
4016 snow="StyleParabel";
4018 case LinkableMapObj::PolyLine:
4019 snow="StylePolyLine";
4021 case LinkableMapObj::PolyParabel:
4022 snow="StylePolyParabel";
4025 snow="UndefinedStyle";
4030 QString("setMapLinkStyle (\"%1\")").arg(s),
4031 QString("setMapLinkStyle (\"%1\")").arg(snow),
4032 QString("Set map link style (\"%1\")").arg(s)
4036 linkstyle=LinkableMapObj::Line;
4037 else if (s=="StyleParabel")
4038 linkstyle=LinkableMapObj::Parabel;
4039 else if (s=="StylePolyLine")
4040 linkstyle=LinkableMapObj::PolyLine;
4041 else if (s=="StylePolyParabel")
4042 linkstyle=LinkableMapObj::PolyParabel;
4044 linkstyle=LinkableMapObj::UndefinedStyle;
4046 BranchItem *cur=NULL;
4047 BranchItem *prev=NULL;
4053 bo=(BranchObj*)(cur->getLMO() );
4054 bo->setLinkStyle(bo->getDefLinkStyle());
4055 cur=next(cur,prev,d);
4060 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4065 void VymModel::setMapDefLinkColor(QColor col)
4067 if ( !col.isValid() ) return;
4069 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4070 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4071 QString("Set map link color to %1").arg(col.name())
4075 BranchItem *cur=NULL;
4076 BranchItem *prev=NULL;
4079 cur=next(cur,prev,d);
4082 bo=(BranchObj*)(cur->getLMO() );
4089 void VymModel::setMapLinkColorHintInt()
4091 // called from setMapLinkColorHint(lch) or at end of parse
4092 BranchItem *cur=NULL;
4093 BranchItem *prev=NULL;
4096 cur=next(cur,prev,d);
4099 bo=(BranchObj*)(cur->getLMO() );
4101 cur=next(cur,prev,d);
4105 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4108 setMapLinkColorHintInt();
4111 void VymModel::toggleMapLinkColorHint()
4113 if (linkcolorhint==LinkableMapObj::HeadingColor)
4114 linkcolorhint=LinkableMapObj::DefaultColor;
4116 linkcolorhint=LinkableMapObj::HeadingColor;
4117 BranchItem *cur=NULL;
4118 BranchItem *prev=NULL;
4121 cur=next(cur,prev,d);
4124 bo=(BranchObj*)(cur->getLMO() );
4130 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4132 Q3FileDialog *fd=new Q3FileDialog( NULL);
4133 fd->setMode (Q3FileDialog::ExistingFile);
4134 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4135 ImagePreview *p =new ImagePreview (fd);
4136 fd->setContentsPreviewEnabled( TRUE );
4137 fd->setContentsPreview( p, p );
4138 fd->setPreviewMode( Q3FileDialog::Contents );
4139 fd->setCaption(vymName+" - " +tr("Load background image"));
4140 fd->setDir (lastImageDir);
4143 if ( fd->exec() == QDialog::Accepted )
4145 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4146 lastImageDir=QDir (fd->dirPath());
4147 setMapBackgroundImage (fd->selectedFile());
4151 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4153 QColor oldcol=mapScene->backgroundBrush().color();
4157 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4159 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4160 QString("Set background color of map to %1").arg(col.name()));
4163 brush.setTextureImage (QPixmap (fn));
4164 mapScene->setBackgroundBrush(brush);
4167 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4169 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4170 if ( !col.isValid() ) return;
4171 setMapBackgroundColor( col );
4175 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4177 QColor oldcol=mapScene->backgroundBrush().color();
4179 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4180 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4181 QString("Set background color of map to %1").arg(col.name()));
4182 mapScene->setBackgroundBrush(col);
4185 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4187 return mapScene->backgroundBrush().color();
4191 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4193 return linkcolorhint;
4196 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4198 return defLinkColor;
4201 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4206 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4208 return defXLinkColor;
4211 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4216 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4218 return defXLinkWidth;
4221 void VymModel::move(const double &x, const double &y) // FIXME-3
4225 BranchObj *bo = getSelectedBranch();
4227 (selectionType()==TreeItem::Branch ||
4228 selectionType()==TreeItem::MapCenter ||
4229 selectionType()==TreeItem::Image
4232 QPointF ap(bo->getAbsPos());
4236 QString ps=qpointfToString(ap);
4237 QString s=getSelectString();
4240 s, "move "+qpointfToString(to),
4241 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4250 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4254 BranchObj *bo = getSelectedBranch();
4256 (selectionType()==TreeItem::Branch ||
4257 selectionType()==TreeItem::MapCenter ||
4258 selectionType()==TreeItem::Image
4262 QPointF rp(bo->getRelPos());
4266 QString ps=qpointfToString (bo->getRelPos());
4267 QString s=getSelectString(bo);
4270 s, "moveRel "+qpointfToString(to),
4271 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4272 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4282 void VymModel::animate()
4284 animationTimer->stop();
4287 while (i<animObjList.size() )
4289 bo=(BranchObj*)animObjList.at(i);
4294 animObjList.removeAt(i);
4301 QItemSelection sel=selModel->selection();
4302 emit (selectionChanged(sel,sel));
4305 if (!animObjList.isEmpty()) animationTimer->start();
4309 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4311 if (bo && bo->getTreeItem()->depth()>0)
4314 ap.setStart (start);
4316 ap.setTicks (animationTicks);
4317 ap.setAnimated (true);
4318 bo->setAnimation (ap);
4319 animObjList.append( bo );
4320 animationTimer->setSingleShot (true);
4321 animationTimer->start(animationInterval);
4325 void VymModel::stopAnimation (MapObj *mo)
4327 int i=animObjList.indexOf(mo);
4329 animObjList.removeAt (i);
4332 void VymModel::sendSelection()
4334 if (netstate!=Server) return;
4335 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4338 void VymModel::newServer()
4342 tcpServer = new QTcpServer(this);
4343 if (!tcpServer->listen(QHostAddress::Any,port)) {
4344 QMessageBox::critical(NULL, "vym server",
4345 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4346 //FIXME-3 needed? we are no widget any longer... close();
4349 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4351 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4354 void VymModel::connectToServer()
4357 server="salam.suse.de";
4359 clientSocket = new QTcpSocket (this);
4360 clientSocket->abort();
4361 clientSocket->connectToHost(server ,port);
4362 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4363 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4364 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4366 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4371 void VymModel::newClient()
4373 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4374 connect(newClient, SIGNAL(disconnected()),
4375 newClient, SLOT(deleteLater()));
4377 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4379 clientList.append (newClient);
4383 void VymModel::sendData(const QString &s)
4385 if (clientList.size()==0) return;
4387 // Create bytearray to send
4389 QDataStream out(&block, QIODevice::WriteOnly);
4390 out.setVersion(QDataStream::Qt_4_0);
4392 // Reserve some space for blocksize
4395 // Write sendCounter
4396 out << sendCounter++;
4401 // Go back and write blocksize so far
4402 out.device()->seek(0);
4403 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4407 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4409 for (int i=0; i<clientList.size(); ++i)
4411 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4412 clientList.at(i)->write (block);
4416 void VymModel::readData ()
4418 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4421 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4425 QDataStream in(clientSocket);
4426 in.setVersion(QDataStream::Qt_4_0);
4434 cout << " t="<<qPrintable (t)<<endl;
4440 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4442 switch (socketError) {
4443 case QAbstractSocket::RemoteHostClosedError:
4445 case QAbstractSocket::HostNotFoundError:
4446 QMessageBox::information(NULL, vymName +" Network client",
4447 "The host was not found. Please check the "
4448 "host name and port settings.");
4450 case QAbstractSocket::ConnectionRefusedError:
4451 QMessageBox::information(NULL, vymName + " Network client",
4452 "The connection was refused by the peer. "
4453 "Make sure the fortune server is running, "
4454 "and check that the host name and port "
4455 "settings are correct.");
4458 QMessageBox::information(NULL, vymName + " Network client",
4459 QString("The following error occurred: %1.")
4460 .arg(clientSocket->errorString()));
4467 void VymModel::selectMapSelectionColor()
4469 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4470 setSelectionColor (col);
4473 void VymModel::setSelectionColorInt (QColor col)
4475 if ( !col.isValid() ) return;
4477 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4478 QString("setSelectionColor (%1)").arg(col.name()),
4479 QString("Set color of selection box to %1").arg(col.name())
4482 mapEditor->setSelectionColor (col);
4486 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4488 cout << "VymModel::changeSelection (";
4489 if (!newsel.indexes().isEmpty() )
4490 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4492 if (!oldsel.indexes().isEmpty() )
4493 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4498 void VymModel::updateSelection(const QItemSelection &newsel)
4500 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4501 emitShowSelection();
4505 void VymModel::updateSelection()
4507 QItemSelection newsel=selModel->selection();
4508 updateSelection (newsel);
4511 void VymModel::setSelectionColor(QColor col)
4513 if ( !col.isValid() ) return;
4515 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4516 QString("setSelectionColor (%1)").arg(col.name()),
4517 QString("Set color of selection box to %1").arg(col.name())
4519 setSelectionColorInt (col);
4522 QColor VymModel::getSelectionColor()
4524 return mapEditor->getSelectionColor();
4527 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4530 for (int i=0;i<rootItem->childCount();i++)
4531 rootItem->child(i)->setHideTmp (mode);
4533 // FIXME-3 needed? scene()->update();
4537 QRectF VymModel::getTotalBBox() //FIXME-2
4541 for (int i=0;i<rootItem->branchCount(); i++)
4542 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4547 //////////////////////////////////////////////
4548 // Selection related
4549 //////////////////////////////////////////////
4551 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4556 QItemSelectionModel* VymModel::getSelectionModel()
4561 void VymModel::setSelectionBlocked (bool b)
4566 selection.unblock();
4569 bool VymModel::isSelectionBlocked()
4571 return selection.isBlocked();
4574 bool VymModel::select ()
4576 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4578 TreeItem *item = getItem (index);
4579 return select (item->getLMO() );
4582 bool VymModel::select (const QString &s)
4584 TreeItem *ti=findBySelectString(s);
4594 bool VymModel::select (LinkableMapObj *lmo)
4596 QItemSelection oldsel=selModel->selection();
4599 return select (lmo->getTreeItem() );
4604 bool VymModel::select (TreeItem *ti)
4608 QModelIndex ix=index(ti);
4609 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4610 ti->setLastSelectedBranch();
4616 void VymModel::unselect()
4618 selModel->clearSelection();
4621 void VymModel::reselect()
4623 selection.reselect();
4626 void VymModel::emitShowSelection()
4628 if (!blockReposition)
4629 emit (showSelection() );
4632 void VymModel::emitNoteHasChanged (TreeItem *ti)
4634 QModelIndex ix=index(ti);
4635 emit (noteHasChanged (ix) );
4638 void VymModel::emitDataHasChanged (TreeItem *ti)
4640 QModelIndex ix=index(ti);
4641 emit (dataChanged (ix,ix) );
4645 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4648 if (selection.select(lmo))
4650 //selection.update();
4651 sendSelection (); // FIXME-4 VM use signal
4655 void VymModel::selectInt (TreeItem *ti)
4657 if (selection.select(lmo))
4659 //selection.update();
4660 sendSelection (); // FIXME-4 VM use signal
4665 void VymModel::selectNextBranchInt()
4667 BranchItem *bi=getSelectedBranchItem();
4670 TreeItem *pi=bi->parent();
4674 if (i<pi->branchCount() )
4676 // select previous branch with same parent
4678 select (pi->getBranchNum(i));
4686 void VymModel::selectPrevBranchInt()
4689 BranchItem *bi=getSelectedBranchItem();
4692 BranchItem *pi=(BranchItem*)bi->parent();
4698 // select previous branch with same parent
4699 bi=pi->getBranchNum(i-1);
4704 while (bi->branchCount() >0)
4705 bi=bi->getLastBranch();
4708 // Try to select last branch in parent pi2 previous to own parent pi
4710 TreeItem *pi2=pi->parent();
4721 void VymModel::selectAboveBranchInt()
4723 BranchItem *bi=getSelectedBranchItem();
4726 BranchItem *newbi=NULL;
4727 BranchItem *pi=(BranchItem*)bi->parent();
4731 // goto previous branch with same parent
4732 newbi=pi->getBranchNum(i-1);
4733 while (newbi->branchCount() >0 )
4734 newbi=newbi->getLastBranch();
4738 if (newbi==rootItem)
4739 // already at top branch (resp. mapcenter)
4745 void VymModel::selectBelowBranchInt()
4747 BranchItem *bi=getSelectedBranchItem();
4750 BranchItem *newbi=NULL;
4752 if (bi->branchCount() >0)
4753 newbi=bi->getFirstBranch();
4760 pi=(BranchItem*)bi->parent();
4762 if (pi->branchCount()-1 > i)
4764 newbi=(BranchItem*)pi->getBranchNum(i+1);
4769 // look for siblings of myself
4770 // or parent, or parent of parent...
4781 void VymModel::selectUpperBranch()
4783 if (selection.isBlocked() ) return;
4785 BranchItem *bi=getSelectedBranchItem();
4786 if (bi && bi->isBranchLikeType())
4787 selectAboveBranchInt();
4790 void VymModel::selectLowerBranch()
4792 if (selection.isBlocked() ) return;
4794 BranchItem *bi=getSelectedBranchItem();
4795 if (bi && bi->isBranchLikeType())
4796 selectBelowBranchInt();
4800 void VymModel::selectLeftBranch()
4802 if (selection.isBlocked() ) return;
4804 QItemSelection oldsel=selModel->selection();
4807 BranchItem *selbi=getSelectedBranchItem();
4808 TreeItem::Type type=selbi->getType();
4811 if (type == TreeItem::MapCenter)
4813 QModelIndex ix=index(selbi);
4814 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4817 par=(BranchItem*)selbi->parent();
4818 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4821 if (type == TreeItem::Branch ||
4822 type == TreeItem::Image)
4824 QModelIndex ix=index (selbi->parent());
4825 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4830 if (type == TreeItem::Branch )
4832 selectLastSelectedBranch();
4840 void VymModel::selectRightBranch()
4842 if (selection.isBlocked() ) return;
4844 QItemSelection oldsel=selModel->selection();
4847 BranchItem *selbi=getSelectedBranchItem();
4848 TreeItem::Type type=selbi->getType();
4851 if (type==TreeItem::MapCenter)
4853 QModelIndex ix=index(selbi);
4854 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4857 par=(BranchItem*)selbi->parent();
4858 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4861 if ( type== TreeItem::Branch )
4863 selectLastSelectedBranch();
4869 if (type == TreeItem::Branch ||
4870 type == TreeItem::Image)
4872 QModelIndex ix=index(selbi->parent());
4873 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4880 void VymModel::selectFirstBranch()
4882 TreeItem *ti=getSelectedBranchItem();
4885 TreeItem *par=ti->parent();
4887 TreeItem *ti2=par->getFirstBranch();
4891 emitShowSelection();
4897 void VymModel::selectLastBranch()
4899 TreeItem *ti=getSelectedBranchItem();
4902 TreeItem *par=ti->parent();
4904 TreeItem *ti2=par->getLastBranch();
4908 emitShowSelection();
4914 void VymModel::selectLastSelectedBranch()
4916 TreeItem *ti=getSelectedBranchItem();
4919 ti=ti->getLastSelectedBranch();
4920 if (ti) select (ti);
4924 void VymModel::selectParent()
4926 TreeItem *ti=getSelectedItem();
4934 emitShowSelection();
4939 TreeItem::Type VymModel::selectionType()
4941 QModelIndexList list=selModel->selectedIndexes();
4942 if (list.isEmpty()) return TreeItem::Undefined;
4943 TreeItem *ti = getItem (list.first() );
4944 return ti->getType();
4948 LinkableMapObj* VymModel::getSelectedLMO()
4950 QModelIndexList list=selModel->selectedIndexes();
4951 if (!list.isEmpty() )
4953 TreeItem *ti = getItem (list.first() );
4954 TreeItem::Type type=ti->getType();
4955 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4957 return ti->getLMO();
4963 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4965 TreeItem *ti = getSelectedBranchItem();
4967 return (BranchObj*)ti->getLMO();
4972 BranchItem* VymModel::getSelectedBranchItem()
4974 QModelIndexList list=selModel->selectedIndexes();
4975 if (!list.isEmpty() )
4977 TreeItem *ti = getItem (list.first() );
4978 TreeItem::Type type=ti->getType();
4979 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4980 return (BranchItem*)ti;
4985 TreeItem* VymModel::getSelectedItem()
4987 QModelIndexList list=selModel->selectedIndexes();
4988 if (!list.isEmpty() )
4989 return getItem (list.first() );
4994 QModelIndex VymModel::getSelectedIndex()
4996 QModelIndexList list=selModel->selectedIndexes();
4997 if (list.isEmpty() )
4998 return QModelIndex();
5000 return list.first();
5003 FloatImageObj* VymModel::getSelectedFloatImage()
5005 return selection.getFloatImage();
5008 QString VymModel::getSelectString ()
5010 LinkableMapObj *lmo=getSelectedLMO();
5012 return getSelectString(lmo);
5017 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5019 if (!lmo) return QString();
5020 return getSelectString (lmo->getTreeItem() );
5023 QString VymModel::getSelectString (TreeItem *ti)
5027 if (ti->getType() == TreeItem::Branch ||
5028 ti->getType() == TreeItem::MapCenter)
5030 TreeItem *par=ti->parent();
5033 if (ti->depth() ==1)
5034 // Mainbranch, return
5035 s= "bo:" + QString("%1").arg(ti->num() );
5037 // Branch, call myself recursively
5038 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5042 int i=rootItem->num(ti);
5043 if (i>=0) s=QString("mc:%1").arg(i);