1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
18 #include "warningdialog.h"
19 #include "xml-freemind.h"
25 extern Main *mainWindow;
26 extern QDBusConnection dbusConnection;
28 extern Settings settings;
29 extern QString tmpVymDir;
31 extern TextEditor *textEditor;
32 extern FlagRow *standardFlagsMaster;
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-3 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()));
123 selectionBlocked=false;
130 // animations // FIXME-3 switch to new animation system
131 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
132 animationTicks=settings.readNumEntry("/animation/ticks",10);
133 animationInterval=settings.readNumEntry("/animation/interval",50);
135 animationTimer=new QTimer (this);
136 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
139 defLinkColor=QColor (0,0,255);
140 defXLinkColor=QColor (180,180,180);
141 linkcolorhint=LinkableMapObj::DefaultColor;
142 linkstyle=LinkableMapObj::PolyParabel;
144 defXLinkColor=QColor (230,230,230);
146 hidemode=TreeItem::HideNone;
152 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
155 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
156 //adaptor->setModel (this);
157 //connection.registerObject("/Car", car);
158 dbusConnection.registerService("org.insilmaril.VymModel");
159 dbusConnection.sessionBus().registerObject ("/Object1",this);
162 void VymModel::makeTmpDirectories()
164 // Create unique temporary directories
165 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
166 histPath = tmpMapDir+"/history";
172 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
177 bool VymModel::isRepositionBlocked()
179 return blockReposition;
182 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
184 //cout << "VM::updateActions \n";
185 // Tell mainwindow to update states of actions
186 mainWindow->updateActions();
191 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
193 // tmpdir temporary directory to which data will be written
194 // prefix mapname, which will be appended to images etc.
195 // writeflags Only write flags for "real" save of map, not undo
196 // offset offset of bbox of whole map in scene.
197 // Needed for XML export
206 case LinkableMapObj::Line:
209 case LinkableMapObj::Parabel:
212 case LinkableMapObj::PolyLine:
216 ls="StylePolyParabel";
220 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
222 if (linkcolorhint==LinkableMapObj::HeadingColor)
223 colhint=xml.attribut("linkColorHint","HeadingColor");
225 QString mapAttr=xml.attribut("version",vymVersion);
227 mapAttr+= xml.attribut("author",author) +
228 xml.attribut("comment",comment) +
229 xml.attribut("date",getDate()) +
230 xml.attribut("branchCount", QString().number(branchCount())) +
231 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
232 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
233 xml.attribut("linkStyle", ls ) +
234 xml.attribut("linkColor", defLinkColor.name() ) +
235 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
236 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
238 s+=xml.beginElement("vymmap",mapAttr);
241 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
242 standardFlagsMaster->resetUsedCounter();
244 // Build xml recursivly
246 // Save all mapcenters as complete map, if saveSel not set
247 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
250 switch (saveSel->getType())
252 case TreeItem::Branch:
254 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
256 case TreeItem::MapCenter:
258 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
260 case TreeItem::Image:
262 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
264 default://FIXME-4 other types shouldn't be safed...
269 // Save local settings
270 s+=settings.getDataXML (destPath);
273 if (getSelectedItem() && !saveSel )
274 s+=xml.valueElement("select",getSelectString());
277 s+=xml.endElement("vymmap");
279 //cout << s.toStdString() << endl;
281 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
285 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
289 for (int i=0; i<rootItem->branchCount(); i++)
290 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
294 void VymModel::setFilePath(QString fpath, QString destname)
296 if (fpath.isEmpty() || fpath=="")
303 filePath=fpath; // becomes absolute path
304 fileName=fpath; // gets stripped of path
305 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
307 // If fpath is not an absolute path, complete it
308 filePath=QDir(fpath).absPath();
309 fileDir=filePath.left (1+filePath.findRev ("/"));
311 // Set short name, too. Search from behind:
312 int i=fileName.findRev("/");
313 if (i>=0) fileName=fileName.remove (0,i+1);
315 // Forget the .vym (or .xml) for name of map
316 mapName=fileName.left(fileName.findRev(".",-1,true) );
320 void VymModel::setFilePath(QString fpath)
322 setFilePath (fpath,fpath);
325 QString VymModel::getFilePath()
330 QString VymModel::getFileName()
335 QString VymModel::getMapName()
340 QString VymModel::getDestPath()
345 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
347 ErrorCode err=success;
349 parseBaseHandler *handler;
353 case VymMap: handler=new parseVYMHandler; break;
354 case FreemindMap : handler=new parseFreemindHandler; break;
356 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
357 "Unknown FileType in VymModel::load()");
361 bool zipped_org=zipped;
365 selModel->clearSelection();
366 // FIXME-2 VM not needed??? model->setMapEditor(this);
367 // (map state is set later at end of load...)
370 BranchItem *bi=getSelectedBranch();
371 if (!bi) return aborted;
372 if (lmode==ImportAdd)
373 saveStateChangingPart(
376 QString("addMapInsert (%1)").arg(fname),
377 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
379 saveStateChangingPart(
382 QString("addMapReplace(%1)").arg(fname),
383 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
387 // Create temporary directory for packing
389 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
392 QMessageBox::critical( 0, tr( "Critical Load Error" ),
393 tr("Couldn't create temporary directory before load\n"));
398 err=unzipDir (tmpZipDir,fname);
408 // Look for mapname.xml
409 xmlfile= fname.left(fname.findRev(".",-1,true));
410 xmlfile=xmlfile.section( '/', -1 );
411 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
412 if (!mfile.exists() )
414 // mapname.xml does not exist, well,
415 // maybe someone renamed the mapname.vym file...
416 // Try to find any .xml in the toplevel
417 // directory of the .vym file
418 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
419 if (flist.count()==1)
421 // Only one entry, take this one
422 xmlfile=tmpZipDir + "/"+flist.first();
425 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
426 *it=tmpZipDir + "/" + *it;
427 // TODO Multiple entries, load all (but only the first one into this ME)
428 //mainWindow->fileLoadFromTmp (flist);
429 //returnCode=1; // Silently forget this attempt to load
430 qWarning ("MainWindow::load (fn) multimap found...");
433 if (flist.isEmpty() )
435 QMessageBox::critical( 0, tr( "Critical Load Error" ),
436 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
439 } //file doesn't exist
441 xmlfile=mfile.name();
444 QFile file( xmlfile);
446 // I am paranoid: file should exist anyway
447 // according to check in mainwindow.
450 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
451 tr(QString("Couldn't open map %1").arg(file.name())));
455 bool blockSaveStateOrg=blockSaveState;
456 blockReposition=true;
458 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
459 QXmlInputSource source( file);
460 QXmlSimpleReader reader;
461 reader.setContentHandler( handler );
462 reader.setErrorHandler( handler );
463 handler->setModel ( this);
466 // We need to set the tmpDir in order to load files with rel. path
471 tmpdir=fname.left(fname.findRev("/",-1));
472 handler->setTmpDir (tmpdir);
473 handler->setInputFile (file.name());
474 handler->setLoadMode (lmode);
475 bool ok = reader.parse( source );
476 blockReposition=false;
477 blockSaveState=blockSaveStateOrg;
478 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
482 reposition(); // FIXME-2 VM reposition the view instead...
483 emitSelectionChanged();
489 autosaveTimer->stop();
492 // Reset timestamp to check for later updates of file
493 fileChangedTime=QFileInfo (destPath).lastModified();
496 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
497 tr( handler->errorProtocol() ) );
499 // Still return "success": the map maybe at least
500 // partially read by the parser
505 removeDir (QDir(tmpZipDir));
507 // Restore original zip state
514 ErrorCode VymModel::save (const SaveMode &savemode)
518 QString safeFilePath;
520 ErrorCode err=success;
524 mapFileName=mapName+".xml";
526 // use name given by user, even if he chooses .doc
527 mapFileName=fileName;
529 // Look, if we should zip the data:
532 QMessageBox mb( vymName,
533 tr("The map %1\ndid not use the compressed "
534 "vym file format.\nWriting it uncompressed will also write images \n"
535 "and flags and thus may overwrite files in the "
536 "given directory\n\nDo you want to write the map").arg(filePath),
537 QMessageBox::Warning,
538 QMessageBox::Yes | QMessageBox::Default,
540 QMessageBox::Cancel | QMessageBox::Escape);
541 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
542 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
543 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
546 case QMessageBox::Yes:
547 // save compressed (default file format)
550 case QMessageBox::No:
554 case QMessageBox::Cancel:
561 // First backup existing file, we
562 // don't want to add to old zip archives
566 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
568 QString backupFileName(destPath + "~");
569 QFile backupFile(backupFileName);
570 if (backupFile.exists() && !backupFile.remove())
572 QMessageBox::warning(0, tr("Save Error"),
573 tr("%1\ncould not be removed before saving").arg(backupFileName));
575 else if (!f.rename(backupFileName))
577 QMessageBox::warning(0, tr("Save Error"),
578 tr("%1\ncould not be renamed before saving").arg(destPath));
585 // Create temporary directory for packing
587 tmpZipDir=makeTmpDir (ok,"vym-zip");
590 QMessageBox::critical( 0, tr( "Critical Load Error" ),
591 tr("Couldn't create temporary directory before save\n"));
595 safeFilePath=filePath;
596 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
599 // Create mapName and fileDir
600 makeSubDirs (fileDir);
603 if (savemode==CompleteMap || selModel->selection().isEmpty())
606 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
609 autosaveTimer->stop();
614 if (selectionType()==TreeItem::Image)
617 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
618 // TODO take care of multiselections
621 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
624 qWarning ("ME::saveStringToDisk failed!");
630 if (err==success) err=zipDir (tmpZipDir,destPath);
633 removeDir (QDir(tmpZipDir));
635 // Restore original filepath outside of tmp zip dir
636 setFilePath (safeFilePath);
640 fileChangedTime=QFileInfo (destPath).lastModified();
644 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree
646 QString pathDir=path.left(path.findRev("/"));
652 // We need to parse saved XML data
653 parseVYMHandler handler;
654 QXmlInputSource source( file);
655 QXmlSimpleReader reader;
656 reader.setContentHandler( &handler );
657 reader.setErrorHandler( &handler );
658 handler.setModel ( this);
659 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
660 if (undoSel.isEmpty())
664 handler.setLoadMode (NewMap);
668 handler.setLoadMode (ImportReplace);
670 blockReposition=true;
671 bool ok = reader.parse( source );
672 blockReposition=false;
675 // This should never ever happen
676 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
677 handler.errorProtocol());
680 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
683 bool VymModel::addMapInsertInt (const QString &path)
685 QString pathDir=path.left(path.findRev("/"));
691 // We need to parse saved XML data
692 parseVYMHandler handler;
693 QXmlInputSource source( file);
694 QXmlSimpleReader reader;
695 reader.setContentHandler( &handler );
696 reader.setErrorHandler( &handler );
697 handler.setModel (this);
698 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
699 handler.setLoadMode (ImportAdd);
700 blockReposition=true;
701 bool ok = reader.parse( source );
702 blockReposition=false;
703 if ( ok ) return true;
705 // This should never ever happen
706 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
707 handler.errorProtocol());
710 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
714 bool VymModel::addMapInsertInt (const QString &path, int pos)
716 BranchItem *selbi=getSelectedBranch();
719 if (addMapInsertInt (path))
721 if (selbi->depth()>0)
722 relinkBranch (selbi->getLastBranch(), selbi,pos);
726 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
730 qWarning ("ME::addMapInsertInt nothing selected");
734 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
736 ImageItem *ii=createImage(dst);
746 void VymModel::loadFloatImage ()
748 BranchItem *selbi=getSelectedBranch();
752 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
753 fd->setMode (Q3FileDialog::ExistingFiles);
754 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
755 ImagePreview *p =new ImagePreview (fd);
756 fd->setContentsPreviewEnabled( TRUE );
757 fd->setContentsPreview( p, p );
758 fd->setPreviewMode( Q3FileDialog::Contents );
759 fd->setCaption(vymName+" - " +tr("Load image"));
760 fd->setDir (lastImageDir);
763 if ( fd->exec() == QDialog::Accepted )
765 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
766 lastImageDir=QDir (fd->dirPath());
769 for (int j=0; j<fd->selectedFiles().count(); j++)
771 s=fd->selectedFiles().at(j);
772 ii=loadFloatImageInt (selbi,s);
773 //FIXME-3 check savestate for loadImage
779 QString ("loadImage (%1)").arg(s ),
780 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
783 // TODO loadFIO error handling
784 qWarning ("Failed to load "+s);
792 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
797 void VymModel::saveFloatImage ()
799 ImageItem *ii=getSelectedImage();
802 QFileDialog *fd=new QFileDialog( NULL);
803 fd->setFilters (imageIO.getFilters());
804 fd->setCaption(vymName+" - " +tr("Save image"));
805 fd->setFileMode( QFileDialog::AnyFile );
806 fd->setDirectory (lastImageDir);
807 // fd->setSelection (fio->getOriginalFilename());
811 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
813 fn=fd->selectedFiles().at(0);
814 if (QFile (fn).exists() )
816 QMessageBox mb( vymName,
817 tr("The file %1 exists already.\n"
818 "Do you want to overwrite it?").arg(fn),
819 QMessageBox::Warning,
820 QMessageBox::Yes | QMessageBox::Default,
821 QMessageBox::Cancel | QMessageBox::Escape,
822 QMessageBox::NoButton );
824 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
825 mb.setButtonText( QMessageBox::No, tr("Cancel"));
828 case QMessageBox::Yes:
831 case QMessageBox::Cancel:
838 saveFloatImageInt (ii,fd->selectedFilter(),fn );
845 void VymModel::importDirInt(BranchObj *dst, QDir d)
847 /* FIXME-2 importDirInt not ported yet
848 BranchObj *bo=getSelectedBranch();
851 // Traverse directories
852 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
853 QFileInfoList list = d.entryInfoList();
856 for (int i = 0; i < list.size(); ++i)
859 if (fi.fileName() != "." && fi.fileName() != ".." )
862 bo=dst->getLastBranch();
863 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
864 bi->setHeading (fi.fileName() ); // FIXME-3 check this
865 bo->setColor (QColor("blue"));
867 if ( !d.cd(fi.fileName()) )
868 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
871 // Recursively add subdirs
878 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
879 list = d.entryInfoList();
881 for (int i = 0; i < list.size(); ++i)
885 bo=dst->getLastBranch();
886 bo->setHeading (fi.fileName() );
887 bo->setColor (QColor("black"));
888 if (fi.fileName().right(4) == ".vym" )
889 bo->setVymLink (fi.filePath());
895 void VymModel::importDirInt (const QString &s) // FIXME-2
898 BranchObj *bo=getSelectedBranch();
901 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
909 void VymModel::importDir() //FIXME-2
912 BranchObj *bo=getSelectedBranch();
916 filters <<"VYM map (*.vym)";
917 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
918 fd->setMode (QFileDialog::DirectoryOnly);
919 fd->setFilters (filters);
920 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
924 if ( fd->exec() == QDialog::Accepted )
926 importDirInt (fd->selectedFile() );
928 //FIXME-3 VM needed? scene()->update();
935 void VymModel::autosave()
940 cout << "VymModel::autosave rejected due to missing filePath\n";
943 QDateTime now=QDateTime().currentDateTime();
945 // Disable autosave, while we have gone back in history
946 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
947 if (redosAvail>0) return;
949 // Also disable autosave for new map without filename
950 if (filePath.isEmpty()) return;
953 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
955 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
956 mainWindow->fileSave (this);
959 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
964 void VymModel::fileChanged()
966 // Check if file on disk has changed meanwhile
967 if (!filePath.isEmpty())
969 QDateTime tmod=QFileInfo (filePath).lastModified();
970 if (tmod>fileChangedTime)
972 // FIXME-2 VM switch to current mapeditor and finish lineedits...
973 QMessageBox mb( vymName,
974 tr("The file of the map on disk has changed:\n\n"
975 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
976 QMessageBox::Question,
978 QMessageBox::Cancel | QMessageBox::Default,
979 QMessageBox::NoButton );
981 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
982 mb.setButtonText( QMessageBox::No, tr("Ignore"));
985 case QMessageBox::Yes:
987 load (filePath,NewMap,fileType);
988 case QMessageBox::Cancel:
989 fileChangedTime=tmod; // allow autosave to overwrite newer file!
995 bool VymModel::isDefault()
1000 void VymModel::makeDefault()
1006 bool VymModel::hasChanged()
1011 void VymModel::setChanged()
1014 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1018 latestAddedItem=NULL;
1022 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1024 if (!lmo || !lmo->getTreeItem() ) return QString();
1025 return getObjectName (lmo->getTreeItem() );
1029 QString VymModel::getObjectName (TreeItem *ti)
1032 if (!ti) return QString("Error: NULL has no name!");
1034 if (s=="") s="unnamed";
1036 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1039 void VymModel::redo()
1041 // Can we undo at all?
1042 if (redosAvail<1) return;
1044 bool blockSaveStateOrg=blockSaveState;
1045 blockSaveState=true;
1049 if (undosAvail<stepsTotal) undosAvail++;
1051 if (curStep>stepsTotal) curStep=1;
1052 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1053 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1054 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1055 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1056 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1057 QString version=undoSet.readEntry ("/history/version");
1059 /* TODO Maybe check for version, if we save the history
1060 if (!checkVersion(version))
1061 QMessageBox::warning(0,tr("Warning"),
1062 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1065 // Find out current undo directory
1066 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1070 cout << "VymModel::redo() begin\n";
1071 cout << " undosAvail="<<undosAvail<<endl;
1072 cout << " redosAvail="<<redosAvail<<endl;
1073 cout << " curStep="<<curStep<<endl;
1074 cout << " ---------------------------"<<endl;
1075 cout << " comment="<<comment.toStdString()<<endl;
1076 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1077 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1078 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1079 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1080 cout << " ---------------------------"<<endl<<endl;
1083 // select object before redo
1084 if (!redoSelection.isEmpty())
1085 select (redoSelection);
1088 parseAtom (redoCommand);
1091 blockSaveState=blockSaveStateOrg;
1093 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1094 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1095 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1096 undoSet.writeSettings(histPath);
1098 mainWindow->updateHistory (undoSet);
1101 /* TODO remove testing
1102 cout << "ME::redo() end\n";
1103 cout << " undosAvail="<<undosAvail<<endl;
1104 cout << " redosAvail="<<redosAvail<<endl;
1105 cout << " curStep="<<curStep<<endl;
1106 cout << " ---------------------------"<<endl<<endl;
1112 bool VymModel::isRedoAvailable()
1114 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1120 void VymModel::undo()
1122 // Can we undo at all?
1123 if (undosAvail<1) return;
1125 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1127 bool blockSaveStateOrg=blockSaveState;
1128 blockSaveState=true;
1130 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1131 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1132 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1133 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1134 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1135 QString version=undoSet.readEntry ("/history/version");
1137 /* TODO Maybe check for version, if we save the history
1138 if (!checkVersion(version))
1139 QMessageBox::warning(0,tr("Warning"),
1140 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1143 // Find out current undo directory
1144 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1146 // select object before undo
1147 select (undoSelection);
1151 cout << "VymModel::undo() begin\n";
1152 cout << " undosAvail="<<undosAvail<<endl;
1153 cout << " redosAvail="<<redosAvail<<endl;
1154 cout << " curStep="<<curStep<<endl;
1155 cout << " ---------------------------"<<endl;
1156 cout << " comment="<<comment.toStdString()<<endl;
1157 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1158 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1159 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1160 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1161 cout << " ---------------------------"<<endl<<endl;
1163 parseAtom (undoCommand);
1168 if (curStep<1) curStep=stepsTotal;
1172 blockSaveState=blockSaveStateOrg;
1174 cout << "VymModel::undo() end\n";
1175 cout << " undosAvail="<<undosAvail<<endl;
1176 cout << " redosAvail="<<redosAvail<<endl;
1177 cout << " curStep="<<curStep<<endl;
1178 cout << " ---------------------------"<<endl<<endl;
1181 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1182 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1183 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1184 undoSet.writeSettings(histPath);
1186 mainWindow->updateHistory (undoSet);
1188 emitSelectionChanged();
1191 bool VymModel::isUndoAvailable()
1193 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1199 void VymModel::gotoHistoryStep (int i)
1201 // Restore variables
1202 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1203 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1205 if (i<0) i=undosAvail+redosAvail;
1207 // Clicking above current step makes us undo things
1210 for (int j=0; j<undosAvail-i; j++) undo();
1213 // Clicking below current step makes us redo things
1215 for (int j=undosAvail; j<i; j++)
1217 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1221 // And ignore clicking the current row ;-)
1225 QString VymModel::getHistoryPath()
1227 QString histName(QString("history-%1").arg(curStep));
1228 return (tmpMapDir+"/"+histName);
1231 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1233 sendData(redoCom); //FIXME-3 testing
1238 if (blockSaveState) return;
1240 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1242 // Find out current undo directory
1243 if (undosAvail<stepsTotal) undosAvail++;
1245 if (curStep>stepsTotal) curStep=1;
1247 QString backupXML="";
1248 QString histDir=getHistoryPath();
1249 QString bakMapPath=histDir+"/map.xml";
1251 // Create histDir if not available
1254 makeSubDirs (histDir);
1256 // Save depending on how much needs to be saved
1258 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1260 QString undoCommand="";
1261 if (savemode==UndoCommand)
1263 undoCommand=undoCom;
1265 else if (savemode==PartOfMap )
1267 undoCommand=undoCom;
1268 undoCommand.replace ("PATH",bakMapPath);
1272 if (!backupXML.isEmpty())
1273 // Write XML Data to disk
1274 saveStringToDisk (bakMapPath,backupXML);
1276 // We would have to save all actions in a tree, to keep track of
1277 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1280 // Write the current state to disk
1281 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1282 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1283 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1284 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1285 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1286 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1287 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1288 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1289 undoSet.setEntry (QString("/history/version"),vymVersion);
1290 undoSet.writeSettings(histPath);
1294 // TODO remove after testing
1295 //cout << " into="<< histPath.toStdString()<<endl;
1296 cout << " stepsTotal="<<stepsTotal<<
1297 ", undosAvail="<<undosAvail<<
1298 ", redosAvail="<<redosAvail<<
1299 ", curStep="<<curStep<<endl;
1300 cout << " ---------------------------"<<endl;
1301 cout << " comment="<<comment.toStdString()<<endl;
1302 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1303 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1304 cout << " redoCom="<<redoCom.toStdString()<<endl;
1305 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1306 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1307 cout << " ---------------------------"<<endl;
1310 mainWindow->updateHistory (undoSet);
1316 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1318 // save the selected part of the map, Undo will replace part of map
1319 QString undoSelection="";
1321 undoSelection=getSelectString(undoSel);
1323 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1324 QString redoSelection="";
1326 redoSelection=getSelectString(undoSel);
1328 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1331 saveState (PartOfMap,
1332 undoSelection, "addMapReplace (\"PATH\")",
1338 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1342 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1345 QString undoSelection;
1346 QString redoSelection=getSelectString(redoSel);
1347 if (redoSel->getType()==TreeItem::Branch)
1349 undoSelection=getSelectString (redoSel->parent());
1350 // save the selected branch of the map, Undo will insert part of map
1351 saveState (PartOfMap,
1352 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1353 redoSelection, "delete ()",
1357 if (redoSel->getType()==TreeItem::MapCenter)
1359 // save the selected branch of the map, Undo will insert part of map
1360 saveState (PartOfMap,
1361 undoSelection, QString("addMapInsert (\"PATH\")"),
1362 redoSelection, "delete ()",
1369 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1371 // "Normal" savestate: save commands, selections and comment
1372 // so just save commands for undo and redo
1373 // and use current selection
1375 QString redoSelection="";
1376 if (redoSel) redoSelection=getSelectString(redoSel);
1377 QString undoSelection="";
1378 if (undoSel) undoSelection=getSelectString(undoSel);
1380 saveState (UndoCommand,
1387 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1389 // "Normal" savestate: save commands, selections and comment
1390 // so just save commands for undo and redo
1391 // and use current selection
1392 saveState (UndoCommand,
1399 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1401 // "Normal" savestate applied to model (no selection needed):
1402 // save commands and comment
1403 saveState (UndoCommand,
1411 QGraphicsScene* VymModel::getScene ()
1416 TreeItem* VymModel::findBySelectString(QString s)
1418 if (s.isEmpty() ) return NULL;
1420 // Old maps don't have multiple mapcenters and don't save full path
1421 if (s.left(2) !="mc")
1424 QStringList parts=s.split (",");
1427 TreeItem *ti=rootItem;
1429 while (!parts.isEmpty() )
1431 typ=parts.first().left(2);
1432 n=parts.first().right(parts.first().length() - 3).toInt();
1433 parts.removeFirst();
1434 if (typ=="mc" || typ=="bo")
1435 ti=ti->getBranchNum (n);
1439 ti=ti->getImageNum (n);
1445 TreeItem* VymModel::findID (const QString &s)
1448 for (int i=0; i<rootItem->branchCount(); i++)
1450 ti=rootItem->getBranchNum(i)->findID (s);
1456 //////////////////////////////////////////////
1458 //////////////////////////////////////////////
1459 void VymModel::setVersion (const QString &s)
1464 void VymModel::setAuthor (const QString &s)
1467 QString ("setMapAuthor (\"%1\")").arg(author),
1468 QString ("setMapAuthor (\"%1\")").arg(s),
1469 QString ("Set author of map to \"%1\"").arg(s)
1474 QString VymModel::getAuthor()
1479 void VymModel::setComment (const QString &s)
1482 QString ("setMapComment (\"%1\")").arg(comment),
1483 QString ("setMapComment (\"%1\")").arg(s),
1484 QString ("Set comment of map")
1489 QString VymModel::getComment ()
1494 QString VymModel::getDate ()
1496 return QDate::currentDate().toString ("yyyy-MM-dd");
1499 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1502 BranchItem *cur=NULL;
1503 BranchItem *prev=NULL;
1513 void VymModel::setHeading(const QString &s)
1515 BranchItem *selbi=getSelectedBranch();
1520 "setHeading (\""+selbi->getHeading()+"\")",
1522 "setHeading (\""+s+"\")",
1523 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1524 selbi->setHeading(s );
1525 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1527 emitSelectionChanged();
1531 QString VymModel::getHeading()
1533 TreeItem *selti=getSelectedItem();
1535 return selti->getHeading();
1540 BranchItem* VymModel::findText (QString s, bool cs)
1542 QTextDocument::FindFlags flags=0;
1543 if (cs) flags=QTextDocument::FindCaseSensitively;
1546 { // Nothing found or new find process
1548 // nothing found, start again
1552 next (findCurrent,findPrevious);
1554 bool searching=true;
1555 bool foundNote=false;
1556 while (searching && !EOFind)
1560 // Searching in Note
1561 if (findCurrent->getNote().contains(s,cs))
1563 select (findCurrent);
1565 if (getSelectedBranch()!=itFind)
1568 emitShowSelection();
1571 if (textEditor->findText(s,flags))
1577 // Searching in Heading
1578 if (searching && findCurrent->getHeading().contains (s,cs) )
1580 select(findCurrent);
1586 if (!next(findCurrent,findPrevious) )
1589 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1592 return getSelectedBranch();
1597 void VymModel::findReset()
1598 { // Necessary if text to find changes during a find process
1604 void VymModel::setScene (QGraphicsScene *s)
1606 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1607 //init(); // Here we have a mapScene set,
1608 // which is (still) needed to create MapCenters
1611 void VymModel::setURL(const QString &url)
1613 TreeItem *selti=getSelectedItem();
1616 QString oldurl=selti->getURL();
1617 selti->setURL (url);
1620 QString ("setURL (\"%1\")").arg(oldurl),
1622 QString ("setURL (\"%1\")").arg(url),
1623 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1626 emitDataHasChanged (selti);
1627 emitShowSelection();
1631 QString VymModel::getURL()
1633 TreeItem *selti=getSelectedItem();
1635 return selti->getURL();
1640 QStringList VymModel::getURLs()
1643 BranchItem *selbi=getSelectedBranch();
1644 BranchItem *cur=selbi;
1645 BranchItem *prev=NULL;
1648 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1649 cur=next (cur,prev,selbi);
1655 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1657 BranchItem *bi=getSelectedBranch();
1660 BranchObj *bo=(BranchObj*)(bi->getLMO());
1663 QString s=bo->getFrameTypeName();
1664 bo->setFrameType (t);
1665 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1666 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1668 bo->updateLinkGeometry();
1673 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1675 BranchItem *bi=getSelectedBranch();
1678 BranchObj *bo=(BranchObj*)(bi->getLMO());
1681 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1682 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1683 bo->setFrameType (s);
1685 bo->updateLinkGeometry();
1690 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1693 BranchItem *bi=getSelectedBranch();
1696 BranchObj *bo=(BranchObj*)(bi->getLMO());
1699 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1700 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1701 bo->setFramePenColor (c);
1706 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1708 BranchItem *bi=getSelectedBranch();
1711 BranchObj *bo=(BranchObj*)(bi->getLMO());
1714 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1715 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1716 bo->setFrameBrushColor (c);
1721 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1723 BranchItem *bi=getSelectedBranch();
1726 BranchObj *bo=(BranchObj*)(bi->getLMO());
1729 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1730 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1731 bo->setFramePadding (i);
1733 bo->updateLinkGeometry();
1738 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1740 BranchItem *bi=getSelectedBranch();
1743 BranchObj *bo=(BranchObj*)(bi->getLMO());
1746 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1747 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1748 bo->setFrameBorderWidth (i);
1750 bo->updateLinkGeometry();
1755 void VymModel::setIncludeImagesVer(bool b)
1757 BranchItem *bi=getSelectedBranch();
1760 QString u= b ? "false" : "true";
1761 QString r=!b ? "false" : "true";
1765 QString("setIncludeImagesVertically (%1)").arg(u),
1767 QString("setIncludeImagesVertically (%1)").arg(r),
1768 QString("Include images vertically in %1").arg(getObjectName(bi))
1770 bi->setIncludeImagesVer(b);
1771 emitDataHasChanged ( bi);
1776 void VymModel::setIncludeImagesHor(bool b)
1778 BranchItem *bi=getSelectedBranch();
1781 QString u= b ? "false" : "true";
1782 QString r=!b ? "false" : "true";
1786 QString("setIncludeImagesHorizontally (%1)").arg(u),
1788 QString("setIncludeImagesHorizontally (%1)").arg(r),
1789 QString("Include images horizontally in %1").arg(getObjectName(bi))
1791 bi->setIncludeImagesHor(b);
1792 emitDataHasChanged ( bi);
1797 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1799 TreeItem *ti=getSelectedItem();
1800 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1802 QString u= b ? "false" : "true";
1803 QString r=!b ? "false" : "true";
1807 QString("setHideLinkUnselected (%1)").arg(u),
1809 QString("setHideLinkUnselected (%1)").arg(r),
1810 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1812 ((MapItem*)ti)->setHideLinkUnselected(b);
1816 void VymModel::setHideExport(bool b)
1818 TreeItem *ti=getSelectedItem();
1820 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1822 ti->setHideInExport (b);
1823 QString u= b ? "false" : "true";
1824 QString r=!b ? "false" : "true";
1828 QString ("setHideExport (%1)").arg(u),
1830 QString ("setHideExport (%1)").arg(r),
1831 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1833 emitDataHasChanged(ti);
1834 emitSelectionChanged();
1837 // emitSelectionChanged();
1838 // FIXME-3 VM needed? scene()->update();
1842 void VymModel::toggleHideExport()
1844 TreeItem *selti=getSelectedItem();
1846 setHideExport ( !selti->hideInExport() );
1850 void VymModel::copy()
1852 TreeItem *selti=getSelectedItem();
1854 (selti->getType() == TreeItem::Branch ||
1855 selti->getType() == TreeItem::MapCenter ||
1856 selti->getType() == TreeItem::Image ))
1858 if (redosAvail == 0)
1861 QString s=getSelectString(selti);
1862 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1863 curClipboard=curStep;
1866 // Copy also to global clipboard, because we are at last step in history
1867 QString bakMapName(QString("history-%1").arg(curStep));
1868 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1869 copyDir (bakMapDir,clipboardDir );
1871 clipboardEmpty=false;
1877 void VymModel::pasteNoSave(const int &n)
1879 bool old=blockSaveState;
1880 blockSaveState=true;
1881 bool zippedOrg=zipped;
1882 if (redosAvail > 0 || n!=0)
1884 // Use the "historical" buffer
1885 QString bakMapName(QString("history-%1").arg(n));
1886 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1887 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1889 // Use the global buffer
1890 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1895 void VymModel::paste()
1897 BranchItem *selbi=getSelectedBranch();
1900 saveStateChangingPart(
1903 QString ("paste (%1)").arg(curClipboard),
1904 QString("Paste to %1").arg( getObjectName(selbi))
1911 void VymModel::cut()
1913 TreeItem *selti=getSelectedItem();
1914 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1922 void VymModel::moveUp()
1924 BranchItem *selbi=getSelectedBranch();
1927 if (!selbi->canMoveUp()) return;
1928 QString oldsel=getSelectString();
1929 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1931 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1935 void VymModel::moveDown()
1937 BranchItem *selbi=getSelectedBranch();
1940 if (!selbi->canMoveDown()) return;
1941 QString oldsel=getSelectString();
1942 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1944 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1948 void VymModel::sortChildren() // FIXME-2 not implemented yet
1951 BranchObj* bo=getSelectedBranch();
1954 if(treeItem->branchCount()>1)
1956 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1959 emitShowSelection();
1965 BranchItem* VymModel::createMapCenter()
1967 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1971 BranchItem* VymModel::createBranch(BranchItem *dst)
1974 return addNewBranchInt (dst,-2);
1979 ImageItem* VymModel::createImage(BranchItem *dst)
1986 QList<QVariant> cData;
1987 cData << "new" << "undef"<<"undef";
1989 ImageItem *newii=new ImageItem(cData) ;
1990 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1992 emit (layoutAboutToBeChanged() );
1995 n=dst->getRowNumAppend(newii);
1996 beginInsertRows (parix,n,n+1);
1997 dst->appendChild (newii);
2000 emit (layoutChanged() );
2002 // save scroll state. If scrolled, automatically select
2003 // new branch in order to tmp unscroll parent...
2004 newii->createMapObj(mapScene);
2011 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2013 BranchItem *selbi=getSelectedBranch();
2016 QList<QVariant> cData;
2017 cData << "new attribute" << "undef"<<"undef";
2018 AttributeItem *a=new AttributeItem (cData);
2020 emit (layoutAboutToBeChanged() );
2022 QModelIndex parix=index(selbi);
2023 int n=selbi->getRowNumAppend (a);
2024 beginInsertRows (parix,n,n+1);
2025 selbi->appendChild (a);
2028 emit (layoutChanged() );
2036 BranchItem* VymModel::addMapCenter ()
2038 BranchItem *bi=addMapCenter (contextPos);
2040 emitShowSelection();
2045 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2046 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2051 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2052 // createMapCenter could then probably be merged with createBranch
2056 QModelIndex parix=index(rootItem);
2058 int n=rootItem->branchCount();
2060 emit (layoutAboutToBeChanged() );
2061 beginInsertRows (parix,n,n+1);
2063 QList<QVariant> cData;
2064 cData << "VM:addMapCenter" << "undef"<<"undef";
2065 BranchItem *newbi=new BranchItem (cData,rootItem);
2066 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2067 rootItem->appendChild (newbi);
2070 emit (layoutChanged() );
2073 newbi->setPositionMode (MapItem::Absolute);
2074 newbi->createMapObj(mapScene);
2079 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2081 // Depending on pos:
2082 // -3 insert in children of parent above selection
2083 // -2 add branch to selection
2084 // -1 insert in children of parent below selection
2085 // 0..n insert in children of parent at pos
2088 QList<QVariant> cData;
2089 cData << "new" << "undef"<<"undef";
2094 BranchItem *newbi=new BranchItem (cData);
2095 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2097 emit (layoutAboutToBeChanged() );
2103 n=parbi->getRowNumAppend (newbi);
2104 beginInsertRows (parix,n,n+1);
2105 parbi->appendChild (newbi);
2107 }else if (num==-1 || num==-3)
2109 // insert below selection
2110 parbi=(BranchItem*)dst->parent();
2113 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2114 beginInsertRows (parix,n,n);
2115 parbi->insertBranch(n,newbi);
2118 emit (layoutChanged() );
2120 // save scroll state. If scrolled, automatically select
2121 // new branch in order to tmp unscroll parent...
2122 newbi->createMapObj(mapScene);
2127 BranchItem* VymModel::addNewBranch(int pos)
2129 // Different meaning than num in addNewBranchInt!
2133 BranchItem *newbi=NULL;
2134 BranchItem *selbi=getSelectedBranch();
2138 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2140 newbi=addNewBranchInt (selbi,pos-2);
2148 QString ("addBranch (%1)").arg(pos),
2149 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2152 // emitSelectionChanged(); FIXME-3
2153 latestAddedItem=newbi;
2154 // In Network mode, the client needs to know where the new branch is,
2155 // so we have to pass on this information via saveState.
2156 // TODO: Get rid of this positioning workaround
2157 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2158 sendData ("selectLatestAdded ()");
2159 sendData (QString("move %1").arg(ps));
2168 BranchItem* VymModel::addNewBranchBefore()
2170 BranchItem *newbi=NULL;
2171 BranchItem *selbi=getSelectedBranch();
2172 if (selbi && selbi->getType()==TreeItem::Branch)
2173 // We accept no MapCenter here, so we _have_ a parent
2175 //QPointF p=bo->getRelPos();
2178 // add below selection
2179 newbi=addNewBranchInt (selbi,-1);
2183 //newbi->move2RelPos (p);
2185 // Move selection to new branch
2186 relinkBranch (selbi,newbi,0);
2188 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2189 QString ("Add branch before %1").arg(getObjectName(selbi)));
2191 // FIXME-3 needed? reposition();
2192 // emitSelectionChanged(); FIXME-3
2198 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2202 if (branch->depth()==0)
2204 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2206 emit (layoutAboutToBeChanged() );
2207 BranchItem *branchpi=(BranchItem*)branch->parent();
2208 // Remove at current position
2209 int n=branch->childNum();
2210 beginRemoveRows (index(branchpi),n,n);
2211 branchpi->removeChild (n);
2214 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2216 // Append as last branch to dst
2217 if (dst->branchCount()==0)
2220 n=dst->getFirstBranch()->childNumber();
2221 beginInsertRows (index(dst),n+pos,n+pos);
2222 dst->insertBranch (pos,branch);
2225 // Correct type if necessesary
2226 if (branch->getType()==TreeItem::MapCenter)
2227 branch->setType(TreeItem::Branch);
2229 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2230 branch->updateStyles();
2232 emit (layoutChanged() );
2233 reposition(); // both for moveUp/Down and relinking
2234 if (dst->isScrolled() )
2237 branch->updateVisibility();
2246 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2250 emit (layoutAboutToBeChanged() );
2252 BranchItem *pi=(BranchItem*)(image->parent());
2253 QString oldParString=getSelectString (pi);
2254 // Remove at current position
2255 int n=image->childNum();
2256 beginRemoveRows (index(pi),n,n);
2257 pi->removeChild (n);
2261 QModelIndex dstix=index(dst);
2262 n=dst->getRowNumAppend (image);
2263 beginInsertRows (dstix,n,n+1);
2264 dst->appendChild (image);
2267 // Set new parent also for lmo
2268 if (image->getLMO() && dst->getLMO() )
2269 image->getLMO()->setParObj (dst->getLMO() );
2271 emit (layoutChanged() );
2274 QString("relinkTo (\"%1\")").arg(oldParString),
2276 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2277 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2283 void VymModel::deleteSelection()
2285 BranchItem *selbi=getSelectedBranch();
2290 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2292 TreeItem *pi=deleteItem (selbi);
2296 emitShowSelection();
2300 TreeItem *ti=getSelectedItem();
2301 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2303 TreeItem *pi=ti->parent();
2304 saveStateChangingPart(
2308 QString("Delete %1").arg(getObjectName(ti))
2312 emitDataHasChanged (pi);
2315 emitShowSelection();
2320 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2323 BranchItem *selbi=getSelectedBranch();
2327 // Don't use this on mapcenter
2328 if (selbi->depth()<2) return;
2330 pi=(BranchItem*)(selbi->parent());
2331 // Check if we have childs at all to keep
2332 if (selbi->branchCount()==0)
2339 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2340 saveStateChangingPart(
2343 "deleteKeepChildren ()",
2344 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2347 QString sel=getSelectString(selbi);
2349 int pos=selbi->num();
2350 BranchItem *bi=selbi->getFirstBranch();
2353 relinkBranch (bi,pi,pos);
2354 bi=selbi->getFirstBranch();
2360 BranchObj *bo=getSelectedBranchObj();
2363 bo->move2RelPos (p);
2369 void VymModel::deleteChildren()
2372 BranchItem *selbi=getSelectedBranch();
2375 saveStateChangingPart(
2378 "deleteChildren ()",
2379 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2381 emit (layoutAboutToBeChanged() );
2383 QModelIndex ix=index (selbi);
2384 int n=selbi->branchCount()-1;
2385 beginRemoveRows (ix,0,n);
2386 removeRows (0,n+1,ix);
2388 if (selbi->isScrolled()) selbi->unScroll();
2389 emit (layoutChanged() );
2394 TreeItem* VymModel::deleteItem (TreeItem *ti)
2398 TreeItem *pi=ti->parent();
2399 QModelIndex parentIndex=index(pi);
2401 emit (layoutAboutToBeChanged() );
2403 int n=ti->childNum();
2404 beginRemoveRows (parentIndex,n,n);
2405 removeRows (n,1,parentIndex);
2409 emit (layoutChanged() );
2410 if (pi->depth()>=0) return pi;
2415 bool VymModel::scrollBranch(BranchItem *bi)
2419 if (bi->isScrolled()) return false;
2420 if (bi->branchCount()==0) return false;
2421 if (bi->depth()==0) return false;
2422 if (bi->toggleScroll())
2429 QString ("%1 ()").arg(u),
2431 QString ("%1 ()").arg(r),
2432 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2434 emitDataHasChanged(bi);
2435 emitSelectionChanged();
2436 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2443 bool VymModel::unscrollBranch(BranchItem *bi)
2447 if (!bi->isScrolled()) return false;
2448 if (bi->branchCount()==0) return false;
2449 if (bi->depth()==0) return false;
2456 QString ("%1 ()").arg(u),
2458 QString ("%1 ()").arg(r),
2459 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2462 emitDataHasChanged(bi);
2463 emitSelectionChanged();
2465 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2471 void VymModel::toggleScroll()
2473 BranchItem *bi=(BranchItem*)getSelectedBranch();
2474 if (bi && bi->isBranchLikeType() )
2476 if (bi->isScrolled())
2477 unscrollBranch (bi);
2481 // saveState is called in above functions
2484 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2488 BranchObj *bo=getSelectedBranch();
2494 if (bo->isScrolled()) unscrollBranch (bo);
2501 void VymModel::emitExpandAll()
2503 emit (expandAll() );
2506 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2508 BranchItem *bi=getSelectedBranch();
2512 if (bi->isActiveStandardFlag(name))
2524 QString("%1 (\"%2\")").arg(u).arg(name),
2526 QString("%1 (\"%2\")").arg(r).arg(name),
2527 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2528 bi->toggleStandardFlag (name, master);
2530 emitSelectionChanged();
2534 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2537 BranchObj *bo=getSelectedBranch();
2540 FloatImageObj *fio=bo->addFloatImage();
2542 fio->setOriginalFilename("No original filename (image added by dropevent)");
2543 QString s=getSelectString(bo);
2544 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2545 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2547 // FIXME-3 VM needed? scene()->update();
2553 void VymModel::colorBranch (QColor c)
2555 BranchItem *selbi=getSelectedBranch();
2560 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2562 QString ("colorBranch (\"%1\")").arg(c.name()),
2563 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2565 selbi->setHeadingColor(c); // color branch
2569 void VymModel::colorSubtree (QColor c)
2571 BranchItem *selbi=getSelectedBranch();
2574 saveStateChangingPart(
2577 QString ("colorSubtree (\"%1\")").arg(c.name()),
2578 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2580 BranchItem *prev=NULL;
2581 BranchItem *cur=selbi;
2584 cur->setHeadingColor(c); // color links, color children
2585 cur=next (cur,prev,selbi);
2591 QColor VymModel::getCurrentHeadingColor()
2593 BranchItem *selbi=getSelectedBranch();
2594 if (selbi) return selbi->getHeadingColor();
2596 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2602 void VymModel::editURL()
2604 TreeItem *selti=getSelectedItem();
2608 QString text = QInputDialog::getText(
2609 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2610 selti->getURL(), &ok, NULL);
2612 // user entered something and pressed OK
2617 void VymModel::editLocalURL()
2619 TreeItem *selti=getSelectedItem();
2622 QStringList filters;
2623 filters <<"All files (*)";
2624 filters << tr("Text","Filedialog") + " (*.txt)";
2625 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2626 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2627 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2628 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2629 fd->setFilters (filters);
2630 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2631 fd->setDirectory (lastFileDir);
2632 if (! selti->getVymLink().isEmpty() )
2633 fd->selectFile( selti->getURL() );
2636 if ( fd->exec() == QDialog::Accepted )
2638 lastFileDir=QDir (fd->directory().path());
2639 setURL (fd->selectedFile() );
2645 void VymModel::editHeading2URL()
2647 TreeItem *selti=getSelectedItem();
2649 setURL (selti->getHeading());
2652 void VymModel::editBugzilla2URL()
2654 TreeItem *selti=getSelectedItem();
2657 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2662 void VymModel::editFATE2URL()
2664 TreeItem *selti=getSelectedItem();
2667 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2670 "setURL (\""+selti->getURL()+"\")",
2672 "setURL (\""+url+"\")",
2673 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2675 selti->setURL (url);
2676 // FIXME-4 updateActions();
2680 void VymModel::editVymLink()
2682 BranchItem *bi=getSelectedBranch();
2685 QStringList filters;
2686 filters <<"VYM map (*.vym)";
2687 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2688 fd->setFilters (filters);
2689 fd->setCaption(vymName+" - " +tr("Link to another map"));
2690 fd->setDirectory (lastFileDir);
2691 if (! bi->getVymLink().isEmpty() )
2692 fd->selectFile( bi->getVymLink() );
2696 if ( fd->exec() == QDialog::Accepted )
2698 lastFileDir=QDir (fd->directory().path());
2701 "setVymLink (\""+bi->getVymLink()+"\")",
2703 "setVymLink (\""+fd->selectedFile()+"\")",
2704 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2706 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2711 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2713 // Internal function, no saveState needed
2714 TreeItem *selti=getSelectedItem();
2717 selti->setVymLink(s);
2719 emitDataHasChanged (selti);
2720 emitShowSelection();
2724 void VymModel::deleteVymLink()
2726 BranchItem *bi=getSelectedBranch();
2731 "setVymLink (\""+bi->getVymLink()+"\")",
2733 "setVymLink (\"\")",
2734 QString("Unset vymlink of %1").arg(getObjectName(bi))
2736 bi->setVymLink ("" );
2742 QString VymModel::getVymLink()
2744 BranchItem *bi=getSelectedBranch();
2746 return bi->getVymLink();
2752 QStringList VymModel::getVymLinks()
2755 BranchItem *selbi=getSelectedBranch();
2756 BranchItem *cur=selbi;
2757 BranchItem *prev=NULL;
2760 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2761 cur=next (cur,prev,selbi);
2767 void VymModel::followXLink(int i) // FIXME-2
2771 BranchObj *bo=getSelectedBranch();
2774 bo=bo->XLinkTargetAt(i);
2777 selection.select(bo);
2778 emitShowSelection();
2784 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2788 BranchObj *bo=getSelectedBranch();
2791 XLinkObj *xlo=bo->XLinkAt(i);
2794 EditXLinkDialog dia;
2796 dia.setSelection(bo);
2797 if (dia.exec() == QDialog::Accepted)
2799 if (dia.useSettingsGlobal() )
2801 setMapDefXLinkColor (xlo->getColor() );
2802 setMapDefXLinkWidth (xlo->getWidth() );
2804 if (dia.deleteXLink())
2805 bo->deleteXLinkAt(i);
2816 //////////////////////////////////////////////
2818 //////////////////////////////////////////////
2820 void VymModel::parseAtom(const QString &atom)
2822 TreeItem* selti=getSelectedItem();
2823 BranchItem *selbi=getSelectedBranch();
2829 // Split string s into command and parameters
2830 parser.parseAtom (atom);
2831 QString com=parser.getCommand();
2833 // External commands
2834 /////////////////////////////////////////////////////////////////////
2835 if (com=="addBranch")
2839 parser.setError (Aborted,"Nothing selected");
2840 } else if (! selbi )
2842 parser.setError (Aborted,"Type of selection is not a branch");
2847 if (parser.checkParCount(pl))
2849 if (parser.parCount()==0)
2853 n=parser.parInt (ok,0);
2854 if (ok ) addNewBranch (n);
2858 /////////////////////////////////////////////////////////////////////
2859 } else if (com=="addBranchBefore")
2863 parser.setError (Aborted,"Nothing selected");
2864 } else if (! selbi )
2866 parser.setError (Aborted,"Type of selection is not a branch");
2869 if (parser.parCount()==0)
2871 addNewBranchBefore ();
2874 /////////////////////////////////////////////////////////////////////
2875 } else if (com==QString("addMapCenter"))
2877 if (parser.checkParCount(2))
2879 x=parser.parDouble (ok,0);
2882 y=parser.parDouble (ok,1);
2883 if (ok) addMapCenter (QPointF(x,y));
2886 /////////////////////////////////////////////////////////////////////
2887 } else if (com==QString("addMapReplace"))
2891 parser.setError (Aborted,"Nothing selected");
2892 } else if (! selbi )
2894 parser.setError (Aborted,"Type of selection is not a branch");
2895 } else if (parser.checkParCount(1))
2897 //s=parser.parString (ok,0); // selection
2898 t=parser.parString (ok,0); // path to map
2899 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2900 addMapReplaceInt(getSelectString(selbi),t);
2902 /////////////////////////////////////////////////////////////////////
2903 } else if (com==QString("addMapInsert"))
2905 if (parser.parCount()==2)
2910 parser.setError (Aborted,"Nothing selected");
2911 } else if (! selbi )
2913 parser.setError (Aborted,"Type of selection is not a branch");
2916 t=parser.parString (ok,0); // path to map
2917 n=parser.parInt(ok,1); // position
2918 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2919 addMapInsertInt(t,n);
2921 } else if (parser.parCount()==1)
2923 t=parser.parString (ok,0); // path to map
2924 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2927 parser.setError (Aborted,"Wrong number of parameters");
2928 /////////////////////////////////////////////////////////////////////
2929 } else if (com=="clearFlags")
2933 parser.setError (Aborted,"Nothing selected");
2934 } else if (! selbi )
2936 parser.setError (Aborted,"Type of selection is not a branch");
2937 } else if (parser.checkParCount(0))
2939 selbi->deactivateAllStandardFlags();
2941 /////////////////////////////////////////////////////////////////////
2942 } else if (com=="colorBranch")
2946 parser.setError (Aborted,"Nothing selected");
2947 } else if (! selbi )
2949 parser.setError (Aborted,"Type of selection is not a branch");
2950 } else if (parser.checkParCount(1))
2952 QColor c=parser.parColor (ok,0);
2953 if (ok) colorBranch (c);
2955 /////////////////////////////////////////////////////////////////////
2956 } else if (com=="colorSubtree")
2960 parser.setError (Aborted,"Nothing selected");
2961 } else if (! selbi )
2963 parser.setError (Aborted,"Type of selection is not a branch");
2964 } else if (parser.checkParCount(1))
2966 QColor c=parser.parColor (ok,0);
2967 if (ok) colorSubtree (c);
2969 /////////////////////////////////////////////////////////////////////
2970 } else if (com=="copy")
2974 parser.setError (Aborted,"Nothing selected");
2975 } else if ( selectionType()!=TreeItem::Branch &&
2976 selectionType()!=TreeItem::MapCenter &&
2977 selectionType()!=TreeItem::Image )
2979 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2980 } else if (parser.checkParCount(0))
2984 /////////////////////////////////////////////////////////////////////
2985 } else if (com=="cut")
2989 parser.setError (Aborted,"Nothing selected");
2990 } else if ( selectionType()!=TreeItem::Branch &&
2991 selectionType()!=TreeItem::MapCenter &&
2992 selectionType()!=TreeItem::Image )
2994 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2995 } else if (parser.checkParCount(0))
2999 /////////////////////////////////////////////////////////////////////
3000 } else if (com=="delete")
3004 parser.setError (Aborted,"Nothing selected");
3006 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3008 parser.setError (Aborted,"Type of selection is wrong.");
3011 else if (parser.checkParCount(0))
3015 /////////////////////////////////////////////////////////////////////
3016 } else if (com=="deleteKeepChildren")
3020 parser.setError (Aborted,"Nothing selected");
3021 } else if (! selbi )
3023 parser.setError (Aborted,"Type of selection is not a branch");
3024 } else if (parser.checkParCount(0))
3026 deleteKeepChildren();
3028 /////////////////////////////////////////////////////////////////////
3029 } else if (com=="deleteChildren")
3033 parser.setError (Aborted,"Nothing selected");
3036 parser.setError (Aborted,"Type of selection is not a branch");
3037 } else if (parser.checkParCount(0))
3041 /////////////////////////////////////////////////////////////////////
3042 } else if (com=="exportASCII")
3046 if (parser.parCount()>=1)
3047 // Hey, we even have a filename
3048 fname=parser.parString(ok,0);
3051 parser.setError (Aborted,"Could not read filename");
3054 exportASCII (fname,false);
3056 /////////////////////////////////////////////////////////////////////
3057 } else if (com=="exportImage")
3061 if (parser.parCount()>=2)
3062 // Hey, we even have a filename
3063 fname=parser.parString(ok,0);
3066 parser.setError (Aborted,"Could not read filename");
3069 QString format="PNG";
3070 if (parser.parCount()>=2)
3072 format=parser.parString(ok,1);
3074 exportImage (fname,false,format);
3076 /////////////////////////////////////////////////////////////////////
3077 } else if (com=="exportXHTML")
3081 if (parser.parCount()>=2)
3082 // Hey, we even have a filename
3083 fname=parser.parString(ok,1);
3086 parser.setError (Aborted,"Could not read filename");
3089 exportXHTML (fname,false);
3091 /////////////////////////////////////////////////////////////////////
3092 } else if (com=="exportXML")
3096 if (parser.parCount()>=2)
3097 // Hey, we even have a filename
3098 fname=parser.parString(ok,1);
3101 parser.setError (Aborted,"Could not read filename");
3104 exportXML (fname,false);
3106 /////////////////////////////////////////////////////////////////////
3107 } else if (com=="importDir")
3111 parser.setError (Aborted,"Nothing selected");
3112 } else if (! selbi )
3114 parser.setError (Aborted,"Type of selection is not a branch");
3115 } else if (parser.checkParCount(1))
3117 s=parser.parString(ok,0);
3118 if (ok) importDirInt(s);
3120 /////////////////////////////////////////////////////////////////////
3121 } else if (com=="relinkTo")
3125 parser.setError (Aborted,"Nothing selected");
3128 if (parser.checkParCount(4))
3130 // 0 selectstring of parent
3131 // 1 num in parent (for branches)
3132 // 2,3 x,y of mainbranch or mapcenter
3133 s=parser.parString(ok,0);
3134 TreeItem *dst=findBySelectString (s);
3137 if (dst->getType()==TreeItem::Branch)
3139 // Get number in parent
3140 n=parser.parInt (ok,1);
3143 relinkBranch (selbi,(BranchItem*)dst,n);
3144 emitSelectionChanged();
3146 } else if (dst->getType()==TreeItem::MapCenter)
3148 relinkBranch (selbi,(BranchItem*)dst);
3149 // Get coordinates of mainbranch
3150 x=parser.parDouble(ok,2);
3153 y=parser.parDouble(ok,3);
3156 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3157 emitSelectionChanged();
3163 } else if ( selti->getType() == TreeItem::Image)
3165 if (parser.checkParCount(1))
3167 // 0 selectstring of parent
3168 s=parser.parString(ok,0);
3169 TreeItem *dst=findBySelectString (s);
3172 if (dst->isBranchLikeType())
3173 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3175 parser.setError (Aborted,"Destination is not a branch");
3178 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3179 /////////////////////////////////////////////////////////////////////
3180 } else if (com=="loadImage")
3184 parser.setError (Aborted,"Nothing selected");
3185 } else if (! selbi )
3187 parser.setError (Aborted,"Type of selection is not a branch");
3188 } else if (parser.checkParCount(1))
3190 s=parser.parString(ok,0);
3191 if (ok) loadFloatImageInt (selbi,s);
3193 /////////////////////////////////////////////////////////////////////
3194 } else if (com=="moveUp")
3198 parser.setError (Aborted,"Nothing selected");
3199 } else if (! selbi )
3201 parser.setError (Aborted,"Type of selection is not a branch");
3202 } else if (parser.checkParCount(0))
3206 /////////////////////////////////////////////////////////////////////
3207 } else if (com=="moveDown")
3211 parser.setError (Aborted,"Nothing selected");
3212 } else if (! selbi )
3214 parser.setError (Aborted,"Type of selection is not a branch");
3215 } else if (parser.checkParCount(0))
3219 /////////////////////////////////////////////////////////////////////
3220 } else if (com=="move")
3224 parser.setError (Aborted,"Nothing selected");
3225 } else if ( selectionType()!=TreeItem::Branch &&
3226 selectionType()!=TreeItem::MapCenter &&
3227 selectionType()!=TreeItem::Image )
3229 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3230 } else if (parser.checkParCount(2))
3232 x=parser.parDouble (ok,0);
3235 y=parser.parDouble (ok,1);
3239 /////////////////////////////////////////////////////////////////////
3240 } else if (com=="moveRel")
3244 parser.setError (Aborted,"Nothing selected");
3245 } else if ( selectionType()!=TreeItem::Branch &&
3246 selectionType()!=TreeItem::MapCenter &&
3247 selectionType()!=TreeItem::Image )
3249 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3250 } else if (parser.checkParCount(2))
3252 x=parser.parDouble (ok,0);
3255 y=parser.parDouble (ok,1);
3256 if (ok) moveRel (x,y);
3259 /////////////////////////////////////////////////////////////////////
3260 } else if (com=="nop")
3262 /////////////////////////////////////////////////////////////////////
3263 } else if (com=="paste")
3267 parser.setError (Aborted,"Nothing selected");
3268 } else if (! selbi )
3270 parser.setError (Aborted,"Type of selection is not a branch");
3271 } else if (parser.checkParCount(1))
3273 n=parser.parInt (ok,0);
3274 if (ok) pasteNoSave(n);
3276 /////////////////////////////////////////////////////////////////////
3277 } else if (com=="qa")
3281 parser.setError (Aborted,"Nothing selected");
3282 } else if (! selbi )
3284 parser.setError (Aborted,"Type of selection is not a branch");
3285 } else if (parser.checkParCount(4))
3288 c=parser.parString (ok,0);
3291 parser.setError (Aborted,"No comment given");
3294 s=parser.parString (ok,1);
3297 parser.setError (Aborted,"First parameter is not a string");
3300 t=parser.parString (ok,2);
3303 parser.setError (Aborted,"Condition is not a string");
3306 u=parser.parString (ok,3);
3309 parser.setError (Aborted,"Third parameter is not a string");
3314 parser.setError (Aborted,"Unknown type: "+s);
3319 parser.setError (Aborted,"Unknown operator: "+t);
3324 parser.setError (Aborted,"Type of selection is not a branch");
3327 if (selbi->getHeading() == u)
3329 cout << "PASSED: " << qPrintable (c) << endl;
3332 cout << "FAILED: " << qPrintable (c) << endl;
3342 /////////////////////////////////////////////////////////////////////
3343 } else if (com=="saveImage")
3345 ImageItem *ii=getSelectedImage();
3348 parser.setError (Aborted,"No image selected");
3349 } else if (parser.checkParCount(2))
3351 s=parser.parString(ok,0);
3354 t=parser.parString(ok,1);
3355 if (ok) saveFloatImageInt (ii,t,s);
3358 /////////////////////////////////////////////////////////////////////
3359 } else if (com=="scroll")
3363 parser.setError (Aborted,"Nothing selected");
3364 } else if (! selbi )
3366 parser.setError (Aborted,"Type of selection is not a branch");
3367 } else if (parser.checkParCount(0))
3369 if (!scrollBranch (selbi))
3370 parser.setError (Aborted,"Could not scroll branch");
3372 /////////////////////////////////////////////////////////////////////
3373 } else if (com=="select")
3375 if (parser.checkParCount(1))
3377 s=parser.parString(ok,0);
3380 /////////////////////////////////////////////////////////////////////
3381 } else if (com=="selectLastBranch")
3385 parser.setError (Aborted,"Nothing selected");
3386 } else if (! selbi )
3388 parser.setError (Aborted,"Type of selection is not a branch");
3389 } else if (parser.checkParCount(0))
3391 BranchItem *bi=selbi->getLastBranch();
3393 parser.setError (Aborted,"Could not select last branch");
3394 select (bi); // FIXME-3 was selectInt
3397 /////////////////////////////////////////////////////////////////////
3398 } else /* FIXME-2 if (com=="selectLastImage")
3402 parser.setError (Aborted,"Nothing selected");
3403 } else if (! selbi )
3405 parser.setError (Aborted,"Type of selection is not a branch");
3406 } else if (parser.checkParCount(0))
3408 FloatImageObj *fio=selb->getLastFloatImage();
3410 parser.setError (Aborted,"Could not select last image");
3411 select (fio); // FIXME-3 was selectInt
3414 /////////////////////////////////////////////////////////////////////
3415 } else */ if (com=="selectLatestAdded")
3417 if (!latestAddedItem)
3419 parser.setError (Aborted,"No latest added object");
3422 if (!select (latestAddedItem))
3423 parser.setError (Aborted,"Could not select latest added object ");
3425 /////////////////////////////////////////////////////////////////////
3426 } else if (com=="setFrameType")
3428 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3430 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3432 else if (parser.checkParCount(1))
3434 s=parser.parString(ok,0);
3435 if (ok) setFrameType (s);
3437 /////////////////////////////////////////////////////////////////////
3438 } else if (com=="setFramePenColor")
3440 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3442 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3444 else if (parser.checkParCount(1))
3446 QColor c=parser.parColor(ok,0);
3447 if (ok) setFramePenColor (c);
3449 /////////////////////////////////////////////////////////////////////
3450 } else if (com=="setFrameBrushColor")
3452 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3454 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3456 else if (parser.checkParCount(1))
3458 QColor c=parser.parColor(ok,0);
3459 if (ok) setFrameBrushColor (c);
3461 /////////////////////////////////////////////////////////////////////
3462 } else if (com=="setFramePadding")
3464 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3466 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3468 else if (parser.checkParCount(1))
3470 n=parser.parInt(ok,0);
3471 if (ok) setFramePadding(n);
3473 /////////////////////////////////////////////////////////////////////
3474 } else if (com=="setFrameBorderWidth")
3476 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3478 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3480 else if (parser.checkParCount(1))
3482 n=parser.parInt(ok,0);
3483 if (ok) setFrameBorderWidth (n);
3485 /////////////////////////////////////////////////////////////////////
3486 } else if (com=="setMapAuthor")
3488 if (parser.checkParCount(1))
3490 s=parser.parString(ok,0);
3491 if (ok) setAuthor (s);
3493 /////////////////////////////////////////////////////////////////////
3494 } else if (com=="setMapComment")
3496 if (parser.checkParCount(1))
3498 s=parser.parString(ok,0);
3499 if (ok) setComment(s);
3501 /////////////////////////////////////////////////////////////////////
3502 } else if (com=="setMapBackgroundColor")
3506 parser.setError (Aborted,"Nothing selected");
3507 } else if (! selbi )
3509 parser.setError (Aborted,"Type of selection is not a branch");
3510 } else if (parser.checkParCount(1))
3512 QColor c=parser.parColor (ok,0);
3513 if (ok) setMapBackgroundColor (c);
3515 /////////////////////////////////////////////////////////////////////
3516 } else if (com=="setMapDefLinkColor")
3520 parser.setError (Aborted,"Nothing selected");
3521 } else if (! selbi )
3523 parser.setError (Aborted,"Type of selection is not a branch");
3524 } else if (parser.checkParCount(1))
3526 QColor c=parser.parColor (ok,0);
3527 if (ok) setMapDefLinkColor (c);
3529 /////////////////////////////////////////////////////////////////////
3530 } else if (com=="setMapLinkStyle")
3532 if (parser.checkParCount(1))
3534 s=parser.parString (ok,0);
3535 if (ok) setMapLinkStyle(s);
3537 /////////////////////////////////////////////////////////////////////
3538 } else if (com=="setHeading")
3542 parser.setError (Aborted,"Nothing selected");
3543 } else if (! selbi )
3545 parser.setError (Aborted,"Type of selection is not a branch");
3546 } else if (parser.checkParCount(1))
3548 s=parser.parString (ok,0);
3552 /////////////////////////////////////////////////////////////////////
3553 } else if (com=="setHideExport")
3557 parser.setError (Aborted,"Nothing selected");
3558 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3560 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3561 } else if (parser.checkParCount(1))
3563 b=parser.parBool(ok,0);
3564 if (ok) setHideExport (b);
3566 /////////////////////////////////////////////////////////////////////
3567 } else if (com=="setIncludeImagesHorizontally")
3571 parser.setError (Aborted,"Nothing selected");
3574 parser.setError (Aborted,"Type of selection is not a branch");
3575 } else if (parser.checkParCount(1))
3577 b=parser.parBool(ok,0);
3578 if (ok) setIncludeImagesHor(b);
3580 /////////////////////////////////////////////////////////////////////
3581 } else if (com=="setIncludeImagesVertically")
3585 parser.setError (Aborted,"Nothing selected");
3588 parser.setError (Aborted,"Type of selection is not a branch");
3589 } else if (parser.checkParCount(1))
3591 b=parser.parBool(ok,0);
3592 if (ok) setIncludeImagesVer(b);
3594 /////////////////////////////////////////////////////////////////////
3595 } else if (com=="setHideLinkUnselected")
3599 parser.setError (Aborted,"Nothing selected");
3600 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3602 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3603 } else if (parser.checkParCount(1))
3605 b=parser.parBool(ok,0);
3606 if (ok) setHideLinkUnselected(b);
3608 /////////////////////////////////////////////////////////////////////
3609 } else if (com=="setSelectionColor")
3611 if (parser.checkParCount(1))
3613 QColor c=parser.parColor (ok,0);
3614 if (ok) setSelectionColorInt (c);
3616 /////////////////////////////////////////////////////////////////////
3617 } else if (com=="setURL")
3621 parser.setError (Aborted,"Nothing selected");
3622 } else if (! selbi )
3624 parser.setError (Aborted,"Type of selection is not a branch");
3625 } else if (parser.checkParCount(1))
3627 s=parser.parString (ok,0);
3630 /////////////////////////////////////////////////////////////////////
3631 } else if (com=="setVymLink")
3635 parser.setError (Aborted,"Nothing selected");
3636 } else if (! selbi )
3638 parser.setError (Aborted,"Type of selection is not a branch");
3639 } else if (parser.checkParCount(1))
3641 s=parser.parString (ok,0);
3642 if (ok) setVymLink(s);
3645 /////////////////////////////////////////////////////////////////////
3646 else if (com=="setFlag")
3650 parser.setError (Aborted,"Nothing selected");
3651 } else if (! selbi )
3653 parser.setError (Aborted,"Type of selection is not a branch");
3654 } else if (parser.checkParCount(1))
3656 s=parser.parString(ok,0);
3658 selbi->activateStandardFlag(s);
3660 /////////////////////////////////////////////////////////////////////
3661 } else /* FIXME-2 if (com=="setFrameType")
3665 parser.setError (Aborted,"Nothing selected");
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(1))
3671 s=parser.parString(ok,0);
3675 /////////////////////////////////////////////////////////////////////
3676 } else*/ if (com=="sortChildren")
3680 parser.setError (Aborted,"Nothing selected");
3681 } else if (! selbi )
3683 parser.setError (Aborted,"Type of selection is not a branch");
3684 } else if (parser.checkParCount(0))
3688 /////////////////////////////////////////////////////////////////////
3689 } else if (com=="toggleFlag")
3693 parser.setError (Aborted,"Nothing selected");
3694 } else if (! selbi )
3696 parser.setError (Aborted,"Type of selection is not a branch");
3697 } else if (parser.checkParCount(1))
3699 s=parser.parString(ok,0);
3701 selbi->toggleStandardFlag(s);
3703 /////////////////////////////////////////////////////////////////////
3704 } else if (com=="unscroll")
3708 parser.setError (Aborted,"Nothing selected");
3709 } else if (! selbi )
3711 parser.setError (Aborted,"Type of selection is not a branch");
3712 } else if (parser.checkParCount(0))
3714 if (!unscrollBranch (selbi))
3715 parser.setError (Aborted,"Could not unscroll branch");
3717 /////////////////////////////////////////////////////////////////////
3718 } else if (com=="unscrollChildren")
3722 parser.setError (Aborted,"Nothing selected");
3723 } else if (! selbi )
3725 parser.setError (Aborted,"Type of selection is not a branch");
3726 } else if (parser.checkParCount(0))
3728 unscrollChildren ();
3730 /////////////////////////////////////////////////////////////////////
3731 } else if (com=="unsetFlag")
3735 parser.setError (Aborted,"Nothing selected");
3736 } else if (! selbi )
3738 parser.setError (Aborted,"Type of selection is not a branch");
3739 } else if (parser.checkParCount(1))
3741 s=parser.parString(ok,0);
3743 selbi->deactivateStandardFlag(s);
3746 parser.setError (Aborted,"Unknown command");
3749 if (parser.errorLevel()==NoError)
3751 // setChanged(); FIXME-2 should not be called e.g. for export?!
3756 // TODO Error handling
3757 qWarning("VymModel::parseAtom: Error!");
3758 qWarning(parser.errorMessage());
3762 void VymModel::runScript (QString script)
3764 parser.setScript (script);
3766 while (parser.next() )
3767 parseAtom(parser.getAtom());
3770 void VymModel::setExportMode (bool b)
3772 // should be called before and after exports
3773 // depending on the settings
3774 if (b && settings.value("/export/useHideExport","true")=="true")
3775 setHideTmpMode (TreeItem::HideExport);
3777 setHideTmpMode (TreeItem::HideNone);
3780 void VymModel::exportImage(QString fname, bool askName, QString format)
3782 /* FIXME-2 export as image, but directly from mapEditor?!
3785 fname=getMapName()+".png";
3792 QFileDialog *fd=new QFileDialog (NULL);
3793 fd->setCaption (tr("Export map as image"));
3794 fd->setDirectory (lastImageDir);
3795 fd->setFileMode(QFileDialog::AnyFile);
3796 fd->setFilters (imageIO.getFilters() );
3799 fl=fd->selectedFiles();
3801 format=imageIO.getType(fd->selectedFilter());
3805 setExportMode (true);
3806 QPixmap pix (mapEditor->getPixmap());
3807 pix.save(fname, format);
3808 setExportMode (false);
3813 void VymModel::exportXML(QString dir, bool askForName)
3817 dir=browseDirectory(NULL,tr("Export XML to directory"));
3818 if (dir =="" && !reallyWriteDirectory(dir) )
3822 // Hide stuff during export, if settings want this
3823 setExportMode (true);
3825 // Create subdirectories
3828 // write to directory //FIXME-4 check totalBBox here...
3829 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3832 file.setName ( dir + "/"+mapName+".xml");
3833 if ( !file.open( QIODevice::WriteOnly ) )
3835 // This should neverever happen
3836 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3840 // Write it finally, and write in UTF8, no matter what
3841 QTextStream ts( &file );
3842 ts.setEncoding (QTextStream::UnicodeUTF8);
3846 // Now write image, too
3847 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3849 setExportMode (false);
3852 void VymModel::exportASCII(QString fname,bool askName)
3857 ex.setFile (mapName+".txt");
3863 //ex.addFilter ("TXT (*.txt)");
3864 ex.setDir(lastImageDir);
3865 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3870 setExportMode(true);
3872 setExportMode(false);
3876 void VymModel::exportXHTML (const QString &dir, bool askForName)
3878 ExportXHTMLDialog dia(NULL);
3879 dia.setFilePath (filePath );
3880 dia.setMapName (mapName );
3882 if (dir!="") dia.setDir (dir);
3888 if (dia.exec()!=QDialog::Accepted)
3892 QDir d (dia.getDir());
3893 // Check, if warnings should be used before overwriting
3894 // the output directory
3895 if (d.exists() && d.count()>0)
3898 warn.showCancelButton (true);
3899 warn.setText(QString(
3900 "The directory %1 is not empty.\n"
3901 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3902 warn.setCaption("Warning: Directory not empty");
3903 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3905 if (warn.exec()!=QDialog::Accepted) ok=false;
3912 exportXML (dia.getDir(),false );
3913 dia.doExport(mapName );
3914 //if (dia.hasChanged()) setChanged();
3918 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3923 if (ex.setConfigFile(cf))
3925 setExportMode (true);
3926 ex.exportPresentation();
3927 setExportMode (false);
3934 //////////////////////////////////////////////
3936 //////////////////////////////////////////////
3938 void VymModel::registerEditor(QWidget *me)
3940 mapEditor=(MapEditor*)me;
3943 void VymModel::unregisterEditor(QWidget *)
3948 void VymModel::setContextPos(QPointF p)
3953 void VymModel::unsetContextPos()
3955 contextPos=QPointF();
3958 void VymModel::updateNoteFlag()
3961 TreeItem *selti=getSelectedItem();
3964 if (textEditor->isEmpty())
3967 selti->setNote (textEditor->getText());
3968 emitDataHasChanged(selti);
3969 emitSelectionChanged();
3974 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3977 for (int i=0; i<rootItem->branchCount(); i++)
3978 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3981 void MapCenterObj::updateRelPositions()
3983 if (repositionRequest) unsetAllRepositionRequests();
3985 // update relative Positions of branches and floats
3986 for (int i=0; i<treeItem->branchCount(); ++i)
3988 treeItem->getBranchObjNum(i)->setRelPos();
3989 treeItem->getBranchObjNum(i)->setOrientation();
3992 for (int i=0; i<floatimage.size(); ++i)
3993 floatimage.at(i)->setRelPos();
3995 if (repositionRequest) reposition();
4000 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
4002 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4003 if (blockReposition) return;
4005 for (int i=0;i<rootItem->branchCount(); i++)
4006 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4010 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
4012 return QPolygonF ();
4013 // Creating (arbitrary) shapes
4016 QRectF rb=bo->getBBox();
4017 if (bo->getDepth()==0)
4019 // Just take BBox of this mapCenter
4020 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
4024 // Take union of BBox and TotalBBox
4026 QRectF ra=bo->getTotalBBox();
4027 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4030 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
4033 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
4035 p <<ra.bottomRight()
4037 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4040 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4046 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4050 // Move all branches and MapCenters away from lmo
4051 // to avoid collisions
4056 BranchObj *boA=(BranchObj*)lmo;
4058 for (int i=0; i<rootItem->branchCount(); i++)
4060 boB=rootItem->getBranchNum(i);
4063 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4066 <<" ("<<qPrintable(boA->getHeading() )<<")"
4067 <<" with ("<< qPrintable (boB->getHeading() )
4070 <<" minT="<<r.minTranslation<<endl<<endl;
4076 void VymModel::setMapLinkStyle (const QString & s)
4081 case LinkableMapObj::Line :
4084 case LinkableMapObj::Parabel:
4085 snow="StyleParabel";
4087 case LinkableMapObj::PolyLine:
4088 snow="StylePolyLine";
4090 case LinkableMapObj::PolyParabel:
4091 snow="StylePolyParabel";
4094 snow="UndefinedStyle";
4099 QString("setMapLinkStyle (\"%1\")").arg(s),
4100 QString("setMapLinkStyle (\"%1\")").arg(snow),
4101 QString("Set map link style (\"%1\")").arg(s)
4105 linkstyle=LinkableMapObj::Line;
4106 else if (s=="StyleParabel")
4107 linkstyle=LinkableMapObj::Parabel;
4108 else if (s=="StylePolyLine")
4109 linkstyle=LinkableMapObj::PolyLine;
4110 else if (s=="StylePolyParabel")
4111 linkstyle=LinkableMapObj::PolyParabel;
4113 linkstyle=LinkableMapObj::UndefinedStyle;
4115 BranchItem *cur=NULL;
4116 BranchItem *prev=NULL;
4121 bo=(BranchObj*)(cur->getLMO() );
4122 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4128 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4133 void VymModel::setMapDefLinkColor(QColor col)
4135 if ( !col.isValid() ) return;
4137 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4138 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4139 QString("Set map link color to %1").arg(col.name())
4143 BranchItem *cur=NULL;
4144 BranchItem *prev=NULL;
4149 bo=(BranchObj*)(cur->getLMO() );
4156 void VymModel::setMapLinkColorHintInt()
4158 // called from setMapLinkColorHint(lch) or at end of parse
4159 BranchItem *cur=NULL;
4160 BranchItem *prev=NULL;
4165 bo=(BranchObj*)(cur->getLMO() );
4171 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4174 setMapLinkColorHintInt();
4177 void VymModel::toggleMapLinkColorHint()
4179 if (linkcolorhint==LinkableMapObj::HeadingColor)
4180 linkcolorhint=LinkableMapObj::DefaultColor;
4182 linkcolorhint=LinkableMapObj::HeadingColor;
4183 BranchItem *cur=NULL;
4184 BranchItem *prev=NULL;
4189 bo=(BranchObj*)(cur->getLMO() );
4195 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4197 Q3FileDialog *fd=new Q3FileDialog( NULL);
4198 fd->setMode (Q3FileDialog::ExistingFile);
4199 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4200 ImagePreview *p =new ImagePreview (fd);
4201 fd->setContentsPreviewEnabled( TRUE );
4202 fd->setContentsPreview( p, p );
4203 fd->setPreviewMode( Q3FileDialog::Contents );
4204 fd->setCaption(vymName+" - " +tr("Load background image"));
4205 fd->setDir (lastImageDir);
4208 if ( fd->exec() == QDialog::Accepted )
4210 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4211 lastImageDir=QDir (fd->dirPath());
4212 setMapBackgroundImage (fd->selectedFile());
4216 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate, move to ME
4218 QColor oldcol=mapScene->backgroundBrush().color();
4222 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4224 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4225 QString("Set background color of map to %1").arg(col.name()));
4228 brush.setTextureImage (QPixmap (fn));
4229 mapScene->setBackgroundBrush(brush);
4232 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4234 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4235 if ( !col.isValid() ) return;
4236 setMapBackgroundColor( col );
4240 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4242 QColor oldcol=mapScene->backgroundBrush().color();
4244 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4245 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4246 QString("Set background color of map to %1").arg(col.name()));
4247 mapScene->setBackgroundBrush(col);
4250 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4252 return mapScene->backgroundBrush().color();
4256 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4258 return linkcolorhint;
4261 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4263 return defLinkColor;
4266 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4271 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4273 return defXLinkColor;
4276 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4281 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4283 return defXLinkWidth;
4286 void VymModel::move(const double &x, const double &y) // FIXME-3
4290 BranchObj *bo = getSelectedBranch();
4292 (selectionType()==TreeItem::Branch ||
4293 selectionType()==TreeItem::MapCenter ||
4294 selectionType()==TreeItem::Image
4297 QPointF ap(bo->getAbsPos());
4301 QString ps=qpointfToString(ap);
4302 QString s=getSelectString();
4305 s, "move "+qpointfToString(to),
4306 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4309 emitSelectionChanged();
4315 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4319 BranchObj *bo = getSelectedBranch();
4321 (selectionType()==TreeItem::Branch ||
4322 selectionType()==TreeItem::MapCenter ||
4323 selectionType()==TreeItem::Image
4327 QPointF rp(bo->getRelPos());
4331 QString ps=qpointfToString (bo->getRelPos());
4332 QString s=getSelectString(bo);
4335 s, "moveRel "+qpointfToString(to),
4336 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4337 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4339 bo->updateLinkGeometry();
4340 emitSelectionChanged();
4347 void VymModel::animate()
4349 animationTimer->stop();
4352 while (i<animObjList.size() )
4354 bo=(BranchObj*)animObjList.at(i);
4359 animObjList.removeAt(i);
4366 QItemSelection sel=selModel->selection();
4367 emit (selectionChanged(sel,sel));
4370 if (!animObjList.isEmpty()) animationTimer->start();
4374 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4376 if (bo && bo->getTreeItem()->depth()>0)
4379 ap.setStart (start);
4381 ap.setTicks (animationTicks);
4382 ap.setAnimated (true);
4383 bo->setAnimation (ap);
4384 animObjList.append( bo );
4385 animationTimer->setSingleShot (true);
4386 animationTimer->start(animationInterval);
4390 void VymModel::stopAnimation (MapObj *mo)
4392 int i=animObjList.indexOf(mo);
4394 animObjList.removeAt (i);
4397 void VymModel::sendSelection()
4399 if (netstate!=Server) return;
4400 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4403 void VymModel::newServer()
4407 tcpServer = new QTcpServer(this);
4408 if (!tcpServer->listen(QHostAddress::Any,port)) {
4409 QMessageBox::critical(NULL, "vym server",
4410 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4411 //FIXME-3 needed? we are no widget any longer... close();
4414 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4416 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4419 void VymModel::connectToServer()
4422 server="salam.suse.de";
4424 clientSocket = new QTcpSocket (this);
4425 clientSocket->abort();
4426 clientSocket->connectToHost(server ,port);
4427 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4428 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4429 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4431 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4436 void VymModel::newClient()
4438 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4439 connect(newClient, SIGNAL(disconnected()),
4440 newClient, SLOT(deleteLater()));
4442 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4444 clientList.append (newClient);
4448 void VymModel::sendData(const QString &s)
4450 if (clientList.size()==0) return;
4452 // Create bytearray to send
4454 QDataStream out(&block, QIODevice::WriteOnly);
4455 out.setVersion(QDataStream::Qt_4_0);
4457 // Reserve some space for blocksize
4460 // Write sendCounter
4461 out << sendCounter++;
4466 // Go back and write blocksize so far
4467 out.device()->seek(0);
4468 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4472 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4474 for (int i=0; i<clientList.size(); ++i)
4476 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4477 clientList.at(i)->write (block);
4481 void VymModel::readData ()
4483 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4486 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4490 QDataStream in(clientSocket);
4491 in.setVersion(QDataStream::Qt_4_0);
4499 cout << " t="<<qPrintable (t)<<endl;
4505 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4507 switch (socketError) {
4508 case QAbstractSocket::RemoteHostClosedError:
4510 case QAbstractSocket::HostNotFoundError:
4511 QMessageBox::information(NULL, vymName +" Network client",
4512 "The host was not found. Please check the "
4513 "host name and port settings.");
4515 case QAbstractSocket::ConnectionRefusedError:
4516 QMessageBox::information(NULL, vymName + " Network client",
4517 "The connection was refused by the peer. "
4518 "Make sure the fortune server is running, "
4519 "and check that the host name and port "
4520 "settings are correct.");
4523 QMessageBox::information(NULL, vymName + " Network client",
4524 QString("The following error occurred: %1.")
4525 .arg(clientSocket->errorString()));
4529 /* FIXME-3 Playing with DBUS...
4530 QDBusVariant VymModel::query (const QString &query)
4532 TreeItem *selti=getSelectedItem();
4534 return QDBusVariant (selti->getHeading());
4536 return QDBusVariant ("Nothing selected.");
4540 void VymModel::testslot() //FIXME-3
4542 cout << "VM::testslot called\n";
4545 void VymModel::selectMapSelectionColor()
4547 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4548 setSelectionColor (col);
4551 void VymModel::setSelectionColorInt (QColor col)
4553 if ( !col.isValid() ) return;
4555 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4556 QString("setSelectionColor (%1)").arg(col.name()),
4557 QString("Set color of selection box to %1").arg(col.name())
4560 mapEditor->setSelectionColor (col);
4564 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4566 cout << "VymModel::changeSelection (";
4567 if (!newsel.indexes().isEmpty() )
4568 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4570 if (!oldsel.indexes().isEmpty() )
4571 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4576 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4580 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4582 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4583 emitShowSelection();
4587 void VymModel::emitSelectionChanged()
4589 QItemSelection newsel=selModel->selection();
4590 emitSelectionChanged (newsel);
4593 void VymModel::setSelectionColor(QColor col)
4595 if ( !col.isValid() ) return;
4597 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4598 QString("setSelectionColor (%1)").arg(col.name()),
4599 QString("Set color of selection box to %1").arg(col.name())
4601 setSelectionColorInt (col);
4604 QColor VymModel::getSelectionColor()
4606 return mapEditor->getSelectionColor();
4609 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4612 for (int i=0;i<rootItem->childCount();i++)
4613 rootItem->child(i)->setHideTmp (mode);
4615 // FIXME-3 needed? scene()->update();
4618 //////////////////////////////////////////////
4619 // Selection related
4620 //////////////////////////////////////////////
4622 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4627 QItemSelectionModel* VymModel::getSelectionModel()
4632 void VymModel::setSelectionBlocked (bool b)
4637 bool VymModel::isSelectionBlocked()
4639 return selectionBlocked;
4642 bool VymModel::select ()
4644 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4647 bool VymModel::select (const QString &s)
4654 TreeItem *ti=findBySelectString(s);
4655 if (ti) return select (index(ti));
4659 bool VymModel::select (LinkableMapObj *lmo)
4661 QItemSelection oldsel=selModel->selection();
4664 return select (index (lmo->getTreeItem()) );
4669 bool VymModel::select (TreeItem *ti)
4671 if (ti) return select (index(ti));
4675 bool VymModel::select (const QModelIndex &index)
4677 if (index.isValid() )
4679 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4680 BranchItem *bi=getSelectedBranch();
4681 if (bi) bi->setLastSelectedBranch();
4687 void VymModel::unselect()
4689 lastSelectString=getSelectString();
4690 selModel->clearSelection();
4693 bool VymModel::reselect()
4695 return select (lastSelectString);
4698 void VymModel::emitShowSelection()
4700 if (!blockReposition)
4701 emit (showSelection() );
4704 void VymModel::emitNoteHasChanged (TreeItem *ti)
4706 QModelIndex ix=index(ti);
4707 emit (noteHasChanged (ix) );
4710 void VymModel::emitDataHasChanged (TreeItem *ti)
4712 QModelIndex ix=index(ti);
4713 emit (dataChanged (ix,ix) );
4717 //bool VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4720 if (selection.select(lmo))
4722 //emitSelectionChanged();
4726 bool VymModel::selectInt (TreeItem *ti)
4728 if (selection.select(lmo))
4730 //emitSelectionChanged();
4735 bool VymModel::selectFirstBranch()
4737 TreeItem *ti=getSelectedBranch();
4740 TreeItem *par=ti->parent();
4743 TreeItem *ti2=par->getFirstBranch();
4744 if (ti2) return select(ti2);
4750 bool VymModel::selectLastBranch()
4752 TreeItem *ti=getSelectedBranch();
4755 TreeItem *par=ti->parent();
4758 TreeItem *ti2=par->getLastBranch();
4759 if (ti2) return select(ti2);
4765 bool VymModel::selectLastSelectedBranch()
4767 BranchItem *bi=getSelectedBranch();
4770 bi=bi->getLastSelectedBranch();
4771 if (bi) return select (bi);
4776 bool VymModel::selectParent()
4778 TreeItem *ti=getSelectedItem();
4789 TreeItem::Type VymModel::selectionType()
4791 QModelIndexList list=selModel->selectedIndexes();
4792 if (list.isEmpty()) return TreeItem::Undefined;
4793 TreeItem *ti = getItem (list.first() );
4794 return ti->getType();
4798 LinkableMapObj* VymModel::getSelectedLMO()
4800 QModelIndexList list=selModel->selectedIndexes();
4801 if (!list.isEmpty() )
4803 TreeItem *ti = getItem (list.first() );
4804 TreeItem::Type type=ti->getType();
4805 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4806 return ((MapItem*)ti)->getLMO();
4811 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4813 TreeItem *ti = getSelectedBranch();
4815 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4820 BranchItem* VymModel::getSelectedBranch()
4822 QModelIndexList list=selModel->selectedIndexes();
4823 if (!list.isEmpty() )
4825 TreeItem *ti = getItem (list.first() );
4826 TreeItem::Type type=ti->getType();
4827 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4828 return (BranchItem*)ti;
4833 ImageItem* VymModel::getSelectedImage()
4835 QModelIndexList list=selModel->selectedIndexes();
4836 if (!list.isEmpty())
4838 TreeItem *ti=getItem (list.first());
4839 if (ti && ti->getType()==TreeItem::Image)
4840 return (ImageItem*)ti;
4845 AttributeItem* VymModel::getSelectedAttribute()
4847 QModelIndexList list=selModel->selectedIndexes();
4848 if (!list.isEmpty() )
4850 TreeItem *ti = getItem (list.first() );
4851 TreeItem::Type type=ti->getType();
4852 if (type ==TreeItem::Attribute)
4853 return (AttributeItem*)ti;
4858 TreeItem* VymModel::getSelectedItem()
4860 QModelIndexList list=selModel->selectedIndexes();
4861 if (!list.isEmpty() )
4862 return getItem (list.first() );
4867 QModelIndex VymModel::getSelectedIndex()
4869 QModelIndexList list=selModel->selectedIndexes();
4870 if (list.isEmpty() )
4871 return QModelIndex();
4873 return list.first();
4876 QString VymModel::getSelectString ()
4878 return getSelectString (getSelectedItem());
4881 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
4883 if (!lmo) return QString();
4884 return getSelectString (lmo->getTreeItem() );
4887 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
4891 switch (ti->getType())
4893 case TreeItem::MapCenter: s="mc:"; break;
4894 case TreeItem::Branch: s="bo:";break;
4895 case TreeItem::Image: s="fi:";break;
4896 case TreeItem::Attribute: s="ai:";break;
4899 s= s + QString("%1").arg(ti->num());
4901 // call myself recursively
4902 s= getSelectString(ti->parent()) +","+s;