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 "xlinkitem.h"
20 #include "xml-freemind.h"
26 extern Main *mainWindow;
27 extern QDBusConnection dbusConnection;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
33 extern FlagRow *standardFlagsMaster;
35 extern QString clipboardDir;
36 extern QString clipboardFile;
37 extern bool clipboardEmpty;
39 extern ImageIO imageIO;
41 extern QString vymName;
42 extern QString vymVersion;
43 extern QDir vymBaseDir;
45 extern QDir lastImageDir;
46 extern QDir lastFileDir;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 // cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 selModel->clearSelection();
74 //QModelIndex ri=index(rootItem);
75 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
78 void VymModel::init ()
83 // Also no scene yet (should not be needed anyway) FIXME-3 VM
96 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
97 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
98 mainWindow->updateHistory (undoSet);
101 makeTmpDirectories();
106 fileName=tr("unnamed");
108 blockReposition=false;
109 blockSaveState=false;
111 autosaveTimer=new QTimer (this);
112 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
114 fileChangedTimer=new QTimer (this);
115 fileChangedTimer->start(3000);
116 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
121 selectionBlocked=false;
128 // animations // FIXME-3 switch to new animation system
129 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
130 animationTicks=settings.readNumEntry("/animation/ticks",10);
131 animationInterval=settings.readNumEntry("/animation/interval",50);
133 animationTimer=new QTimer (this);
134 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
137 defLinkColor=QColor (0,0,255);
138 defXLinkColor=QColor (180,180,180);
139 linkcolorhint=LinkableMapObj::DefaultColor;
140 linkstyle=LinkableMapObj::PolyParabel;
142 defXLinkColor=QColor (230,230,230);
144 hidemode=TreeItem::HideNone;
150 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
153 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
154 //adaptor->setModel (this);
155 //connection.registerObject("/Car", car);
156 dbusConnection.registerService("org.insilmaril.VymModel");
157 dbusConnection.sessionBus().registerObject ("/Object1",this);
160 void VymModel::makeTmpDirectories()
162 // Create unique temporary directories
163 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
164 histPath = tmpMapDir+"/history";
170 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
175 bool VymModel::isRepositionBlocked()
177 return blockReposition;
180 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
182 //cout << "VM::updateActions \n";
183 // Tell mainwindow to update states of actions
184 mainWindow->updateActions();
189 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
191 // tmpdir temporary directory to which data will be written
192 // prefix mapname, which will be appended to images etc.
193 // writeflags Only write flags for "real" save of map, not undo
194 // offset offset of bbox of whole map in scene.
195 // Needed for XML export
204 case LinkableMapObj::Line:
207 case LinkableMapObj::Parabel:
210 case LinkableMapObj::PolyLine:
214 ls="StylePolyParabel";
218 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
220 if (linkcolorhint==LinkableMapObj::HeadingColor)
221 colhint=xml.attribut("linkColorHint","HeadingColor");
223 QString mapAttr=xml.attribut("version",vymVersion);
225 mapAttr+= xml.attribut("author",author) +
226 xml.attribut("comment",comment) +
227 xml.attribut("date",getDate()) +
228 xml.attribut("branchCount", QString().number(branchCount())) +
229 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
230 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
231 xml.attribut("linkStyle", ls ) +
232 xml.attribut("linkColor", defLinkColor.name() ) +
233 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
234 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
236 s+=xml.beginElement("vymmap",mapAttr);
239 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
240 standardFlagsMaster->resetUsedCounter();
242 // Build xml recursivly
244 // Save all mapcenters as complete map, if saveSel not set
245 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
248 switch (saveSel->getType())
250 case TreeItem::Branch:
252 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
254 case TreeItem::MapCenter:
256 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
258 case TreeItem::Image:
260 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
263 // other types shouldn't be safed directly...
268 // Save local settings
269 s+=settings.getDataXML (destPath);
272 if (getSelectedItem() && !saveSel )
273 s+=xml.valueElement("select",getSelectString());
276 s+=xml.endElement("vymmap");
278 //cout << s.toStdString() << endl;
280 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
284 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
288 for (int i=0; i<rootItem->branchCount(); i++)
289 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
293 void VymModel::setFilePath(QString fpath, QString destname)
295 if (fpath.isEmpty() || fpath=="")
302 filePath=fpath; // becomes absolute path
303 fileName=fpath; // gets stripped of path
304 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
306 // If fpath is not an absolute path, complete it
307 filePath=QDir(fpath).absPath();
308 fileDir=filePath.left (1+filePath.findRev ("/"));
310 // Set short name, too. Search from behind:
311 int i=fileName.findRev("/");
312 if (i>=0) fileName=fileName.remove (0,i+1);
314 // Forget the .vym (or .xml) for name of map
315 mapName=fileName.left(fileName.findRev(".",-1,true) );
319 void VymModel::setFilePath(QString fpath)
321 setFilePath (fpath,fpath);
324 QString VymModel::getFilePath()
329 QString VymModel::getFileName()
334 QString VymModel::getMapName()
339 QString VymModel::getDestPath()
344 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
346 ErrorCode err=success;
348 parseBaseHandler *handler;
352 case VymMap: handler=new parseVYMHandler; break;
353 case FreemindMap : handler=new parseFreemindHandler; break;
355 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
356 "Unknown FileType in VymModel::load()");
360 bool zipped_org=zipped;
364 selModel->clearSelection();
365 // FIXME-2 VM not needed??? model->setMapEditor(this);
366 // (map state is set later at end of load...)
369 BranchItem *bi=getSelectedBranch();
370 if (!bi) return aborted;
371 if (lmode==ImportAdd)
372 saveStateChangingPart(
375 QString("addMapInsert (%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
378 saveStateChangingPart(
381 QString("addMapReplace(%1)").arg(fname),
382 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
386 // Create temporary directory for packing
388 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
391 QMessageBox::critical( 0, tr( "Critical Load Error" ),
392 tr("Couldn't create temporary directory before load\n"));
397 err=unzipDir (tmpZipDir,fname);
407 // Look for mapname.xml
408 xmlfile= fname.left(fname.findRev(".",-1,true));
409 xmlfile=xmlfile.section( '/', -1 );
410 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
411 if (!mfile.exists() )
413 // mapname.xml does not exist, well,
414 // maybe someone renamed the mapname.vym file...
415 // Try to find any .xml in the toplevel
416 // directory of the .vym file
417 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
418 if (flist.count()==1)
420 // Only one entry, take this one
421 xmlfile=tmpZipDir + "/"+flist.first();
424 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
425 *it=tmpZipDir + "/" + *it;
426 // TODO Multiple entries, load all (but only the first one into this ME)
427 //mainWindow->fileLoadFromTmp (flist);
428 //returnCode=1; // Silently forget this attempt to load
429 qWarning ("MainWindow::load (fn) multimap found...");
432 if (flist.isEmpty() )
434 QMessageBox::critical( 0, tr( "Critical Load Error" ),
435 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
438 } //file doesn't exist
440 xmlfile=mfile.name();
443 QFile file( xmlfile);
445 // I am paranoid: file should exist anyway
446 // according to check in mainwindow.
449 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
450 tr(QString("Couldn't open map %1").arg(file.name())));
454 bool blockSaveStateOrg=blockSaveState;
455 blockReposition=true;
457 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
458 QXmlInputSource source( file);
459 QXmlSimpleReader reader;
460 reader.setContentHandler( handler );
461 reader.setErrorHandler( handler );
462 handler->setModel ( this);
465 // We need to set the tmpDir in order to load files with rel. path
470 tmpdir=fname.left(fname.findRev("/",-1));
471 handler->setTmpDir (tmpdir);
472 handler->setInputFile (file.name());
473 handler->setLoadMode (lmode);
474 bool ok = reader.parse( source );
475 blockReposition=false;
476 blockSaveState=blockSaveStateOrg;
477 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
481 reposition(); // FIXME-2 VM reposition the view instead...
482 emitSelectionChanged();
488 autosaveTimer->stop();
491 // Reset timestamp to check for later updates of file
492 fileChangedTime=QFileInfo (destPath).lastModified();
495 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
496 tr( handler->errorProtocol() ) );
498 // Still return "success": the map maybe at least
499 // partially read by the parser
504 removeDir (QDir(tmpZipDir));
506 // Restore original zip state
513 ErrorCode VymModel::save (const SaveMode &savemode)
517 QString safeFilePath;
519 ErrorCode err=success;
523 mapFileName=mapName+".xml";
525 // use name given by user, even if he chooses .doc
526 mapFileName=fileName;
528 // Look, if we should zip the data:
531 QMessageBox mb( vymName,
532 tr("The map %1\ndid not use the compressed "
533 "vym file format.\nWriting it uncompressed will also write images \n"
534 "and flags and thus may overwrite files in the "
535 "given directory\n\nDo you want to write the map").arg(filePath),
536 QMessageBox::Warning,
537 QMessageBox::Yes | QMessageBox::Default,
539 QMessageBox::Cancel | QMessageBox::Escape);
540 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
541 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
542 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
545 case QMessageBox::Yes:
546 // save compressed (default file format)
549 case QMessageBox::No:
553 case QMessageBox::Cancel:
560 // First backup existing file, we
561 // don't want to add to old zip archives
565 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
567 QString backupFileName(destPath + "~");
568 QFile backupFile(backupFileName);
569 if (backupFile.exists() && !backupFile.remove())
571 QMessageBox::warning(0, tr("Save Error"),
572 tr("%1\ncould not be removed before saving").arg(backupFileName));
574 else if (!f.rename(backupFileName))
576 QMessageBox::warning(0, tr("Save Error"),
577 tr("%1\ncould not be renamed before saving").arg(destPath));
584 // Create temporary directory for packing
586 tmpZipDir=makeTmpDir (ok,"vym-zip");
589 QMessageBox::critical( 0, tr( "Critical Load Error" ),
590 tr("Couldn't create temporary directory before save\n"));
594 safeFilePath=filePath;
595 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
598 // Create mapName and fileDir
599 makeSubDirs (fileDir);
602 if (savemode==CompleteMap || selModel->selection().isEmpty())
605 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
608 autosaveTimer->stop();
613 if (selectionType()==TreeItem::Image)
616 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
617 // TODO take care of multiselections
620 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
623 qWarning ("ME::saveStringToDisk failed!");
629 if (err==success) err=zipDir (tmpZipDir,destPath);
632 removeDir (QDir(tmpZipDir));
634 // Restore original filepath outside of tmp zip dir
635 setFilePath (safeFilePath);
639 fileChangedTime=QFileInfo (destPath).lastModified();
643 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
645 QString pathDir=path.left(path.findRev("/"));
651 // We need to parse saved XML data
652 parseVYMHandler handler;
653 QXmlInputSource source( file);
654 QXmlSimpleReader reader;
655 reader.setContentHandler( &handler );
656 reader.setErrorHandler( &handler );
657 handler.setModel ( this);
658 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
659 if (undoSel.isEmpty())
663 handler.setLoadMode (NewMap);
667 handler.setLoadMode (ImportReplace);
669 blockReposition=true;
670 bool ok = reader.parse( source );
671 blockReposition=false;
674 // This should never ever happen
675 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
676 handler.errorProtocol());
679 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
682 bool VymModel::addMapInsertInt (const QString &path)
684 QString pathDir=path.left(path.findRev("/"));
690 // We need to parse saved XML data
691 parseVYMHandler handler;
692 QXmlInputSource source( file);
693 QXmlSimpleReader reader;
694 reader.setContentHandler( &handler );
695 reader.setErrorHandler( &handler );
696 handler.setModel (this);
697 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
698 handler.setLoadMode (ImportAdd);
699 blockReposition=true;
700 bool ok = reader.parse( source );
701 blockReposition=false;
702 if ( ok ) return true;
704 // This should never ever happen
705 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
706 handler.errorProtocol());
709 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
713 bool VymModel::addMapInsertInt (const QString &path, int pos)
715 BranchItem *selbi=getSelectedBranch();
718 if (addMapInsertInt (path))
720 if (selbi->depth()>0)
721 relinkBranch (selbi->getLastBranch(), selbi,pos);
725 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
729 qWarning ("ME::addMapInsertInt nothing selected");
733 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
735 ImageItem *ii=createImage(dst);
745 void VymModel::loadFloatImage ()
747 BranchItem *selbi=getSelectedBranch();
751 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
752 fd->setMode (Q3FileDialog::ExistingFiles);
753 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
754 ImagePreview *p =new ImagePreview (fd);
755 fd->setContentsPreviewEnabled( TRUE );
756 fd->setContentsPreview( p, p );
757 fd->setPreviewMode( Q3FileDialog::Contents );
758 fd->setCaption(vymName+" - " +tr("Load image"));
759 fd->setDir (lastImageDir);
762 if ( fd->exec() == QDialog::Accepted )
764 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
765 lastImageDir=QDir (fd->dirPath());
768 for (int j=0; j<fd->selectedFiles().count(); j++)
770 s=fd->selectedFiles().at(j);
771 ii=loadFloatImageInt (selbi,s);
772 //FIXME-3 check savestate for loadImage
778 QString ("loadImage (%1)").arg(s ),
779 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
782 // TODO loadFIO error handling
783 qWarning ("Failed to load "+s);
791 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
796 void VymModel::saveFloatImage ()
798 ImageItem *ii=getSelectedImage();
801 QFileDialog *fd=new QFileDialog( NULL);
802 fd->setFilters (imageIO.getFilters());
803 fd->setCaption(vymName+" - " +tr("Save image"));
804 fd->setFileMode( QFileDialog::AnyFile );
805 fd->setDirectory (lastImageDir);
806 // fd->setSelection (fio->getOriginalFilename());
810 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
812 fn=fd->selectedFiles().at(0);
813 if (QFile (fn).exists() )
815 QMessageBox mb( vymName,
816 tr("The file %1 exists already.\n"
817 "Do you want to overwrite it?").arg(fn),
818 QMessageBox::Warning,
819 QMessageBox::Yes | QMessageBox::Default,
820 QMessageBox::Cancel | QMessageBox::Escape,
821 QMessageBox::NoButton );
823 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
824 mb.setButtonText( QMessageBox::No, tr("Cancel"));
827 case QMessageBox::Yes:
830 case QMessageBox::Cancel:
837 saveFloatImageInt (ii,fd->selectedFilter(),fn );
844 void VymModel::importDirInt(BranchItem *dst, QDir d)
846 BranchItem *selbi=getSelectedBranch();
850 // Traverse directories
851 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
852 QFileInfoList list = d.entryInfoList();
855 for (int i = 0; i < list.size(); ++i)
858 if (fi.fileName() != "." && fi.fileName() != ".." )
860 bi=addNewBranchInt(dst,-2);
861 bi->setHeading (fi.fileName() ); // FIXME-3 check this
862 bi->setHeadingColor (QColor("blue"));
864 if ( !d.cd(fi.fileName()) )
865 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
868 // Recursively add subdirs
875 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
876 list = d.entryInfoList();
878 for (int i = 0; i < list.size(); ++i)
881 bi=addNewBranchInt (dst,-2);
882 bi->setHeading (fi.fileName() );
883 bi->setHeadingColor (QColor("black"));
884 if (fi.fileName().right(4) == ".vym" )
885 bi->setVymLink (fi.filePath());
890 void VymModel::importDirInt (const QString &s)
892 BranchItem *selbi=getSelectedBranch();
895 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
898 importDirInt (selbi,d);
902 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
904 BranchItem *selbi=getSelectedBranch();
908 filters <<"VYM map (*.vym)";
909 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
910 fd->setMode (QFileDialog::DirectoryOnly);
911 fd->setFilters (filters);
912 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
916 if ( fd->exec() == QDialog::Accepted )
918 importDirInt (fd->selectedFile() );
920 //FIXME-3 VM needed? scene()->update();
926 void VymModel::autosave()
931 cout << "VymModel::autosave rejected due to missing filePath\n";
934 QDateTime now=QDateTime().currentDateTime();
936 // Disable autosave, while we have gone back in history
937 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
938 if (redosAvail>0) return;
940 // Also disable autosave for new map without filename
941 if (filePath.isEmpty()) return;
944 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
946 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
947 mainWindow->fileSave (this);
950 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
955 void VymModel::fileChanged()
957 // Check if file on disk has changed meanwhile
958 if (!filePath.isEmpty())
960 QDateTime tmod=QFileInfo (filePath).lastModified();
961 if (tmod>fileChangedTime)
963 // FIXME-2 VM switch to current mapeditor and finish lineedits...
964 QMessageBox mb( vymName,
965 tr("The file of the map on disk has changed:\n\n"
966 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
967 QMessageBox::Question,
969 QMessageBox::Cancel | QMessageBox::Default,
970 QMessageBox::NoButton );
972 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
973 mb.setButtonText( QMessageBox::No, tr("Ignore"));
976 case QMessageBox::Yes:
978 load (filePath,NewMap,fileType);
979 case QMessageBox::Cancel:
980 fileChangedTime=tmod; // allow autosave to overwrite newer file!
986 bool VymModel::isDefault()
991 void VymModel::makeDefault()
997 bool VymModel::hasChanged()
1002 void VymModel::setChanged()
1005 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1009 latestAddedItem=NULL;
1013 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1015 if (!lmo || !lmo->getTreeItem() ) return QString();
1016 return getObjectName (lmo->getTreeItem() );
1020 QString VymModel::getObjectName (TreeItem *ti)
1023 if (!ti) return QString("Error: NULL has no name!");
1025 if (s=="") s="unnamed";
1027 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1030 void VymModel::redo()
1032 // Can we undo at all?
1033 if (redosAvail<1) return;
1035 bool blockSaveStateOrg=blockSaveState;
1036 blockSaveState=true;
1040 if (undosAvail<stepsTotal) undosAvail++;
1042 if (curStep>stepsTotal) curStep=1;
1043 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1044 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1045 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1046 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1047 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1048 QString version=undoSet.readEntry ("/history/version");
1050 /* TODO Maybe check for version, if we save the history
1051 if (!checkVersion(version))
1052 QMessageBox::warning(0,tr("Warning"),
1053 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1056 // Find out current undo directory
1057 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1061 cout << "VymModel::redo() begin\n";
1062 cout << " undosAvail="<<undosAvail<<endl;
1063 cout << " redosAvail="<<redosAvail<<endl;
1064 cout << " curStep="<<curStep<<endl;
1065 cout << " ---------------------------"<<endl;
1066 cout << " comment="<<comment.toStdString()<<endl;
1067 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1068 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1069 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1070 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1071 cout << " ---------------------------"<<endl<<endl;
1074 // select object before redo
1075 if (!redoSelection.isEmpty())
1076 select (redoSelection);
1079 parseAtom (redoCommand);
1081 blockSaveState=blockSaveStateOrg;
1083 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1084 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1085 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1086 undoSet.writeSettings(histPath);
1088 mainWindow->updateHistory (undoSet);
1091 /* TODO remove testing
1092 cout << "ME::redo() end\n";
1093 cout << " undosAvail="<<undosAvail<<endl;
1094 cout << " redosAvail="<<redosAvail<<endl;
1095 cout << " curStep="<<curStep<<endl;
1096 cout << " ---------------------------"<<endl<<endl;
1102 bool VymModel::isRedoAvailable()
1104 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1110 void VymModel::undo()
1112 // Can we undo at all?
1113 if (undosAvail<1) return;
1115 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1117 bool blockSaveStateOrg=blockSaveState;
1118 blockSaveState=true;
1120 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1121 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1122 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1123 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1124 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1125 QString version=undoSet.readEntry ("/history/version");
1127 /* TODO Maybe check for version, if we save the history
1128 if (!checkVersion(version))
1129 QMessageBox::warning(0,tr("Warning"),
1130 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1133 // Find out current undo directory
1134 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1136 // select object before undo
1137 if (!select (undoSelection))
1139 qWarning ("VymModel::undo() Could not select object for undo");
1145 cout << "VymModel::undo() begin\n";
1146 cout << " undosAvail="<<undosAvail<<endl;
1147 cout << " redosAvail="<<redosAvail<<endl;
1148 cout << " curStep="<<curStep<<endl;
1149 cout << " ---------------------------"<<endl;
1150 cout << " comment="<<comment.toStdString()<<endl;
1151 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1152 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1153 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1154 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1155 cout << " ---------------------------"<<endl<<endl;
1157 parseAtom (undoCommand);
1161 if (curStep<1) curStep=stepsTotal;
1165 blockSaveState=blockSaveStateOrg;
1167 cout << "VymModel::undo() end\n";
1168 cout << " undosAvail="<<undosAvail<<endl;
1169 cout << " redosAvail="<<redosAvail<<endl;
1170 cout << " curStep="<<curStep<<endl;
1171 cout << " ---------------------------"<<endl<<endl;
1174 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1175 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1176 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1177 undoSet.writeSettings(histPath);
1179 mainWindow->updateHistory (undoSet);
1181 //emitSelectionChanged();
1184 bool VymModel::isUndoAvailable()
1186 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1192 void VymModel::gotoHistoryStep (int i)
1194 // Restore variables
1195 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1196 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1198 if (i<0) i=undosAvail+redosAvail;
1200 // Clicking above current step makes us undo things
1203 for (int j=0; j<undosAvail-i; j++) undo();
1206 // Clicking below current step makes us redo things
1208 for (int j=undosAvail; j<i; j++)
1210 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1214 // And ignore clicking the current row ;-)
1218 QString VymModel::getHistoryPath()
1220 QString histName(QString("history-%1").arg(curStep));
1221 return (tmpMapDir+"/"+histName);
1224 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1226 sendData(redoCom); //FIXME-3 testing
1231 if (blockSaveState) return;
1233 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1235 // Find out current undo directory
1236 if (undosAvail<stepsTotal) undosAvail++;
1238 if (curStep>stepsTotal) curStep=1;
1240 QString backupXML="";
1241 QString histDir=getHistoryPath();
1242 QString bakMapPath=histDir+"/map.xml";
1244 // Create histDir if not available
1247 makeSubDirs (histDir);
1249 // Save depending on how much needs to be saved
1251 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1253 QString undoCommand="";
1254 if (savemode==UndoCommand)
1256 undoCommand=undoCom;
1258 else if (savemode==PartOfMap )
1260 undoCommand=undoCom;
1261 undoCommand.replace ("PATH",bakMapPath);
1265 if (!backupXML.isEmpty())
1266 // Write XML Data to disk
1267 saveStringToDisk (bakMapPath,backupXML);
1269 // We would have to save all actions in a tree, to keep track of
1270 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1273 // Write the current state to disk
1274 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1275 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1276 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1277 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1278 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1280 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1282 undoSet.setEntry (QString("/history/version"),vymVersion);
1283 undoSet.writeSettings(histPath);
1287 // TODO remove after testing
1288 //cout << " into="<< histPath.toStdString()<<endl;
1289 cout << " stepsTotal="<<stepsTotal<<
1290 ", undosAvail="<<undosAvail<<
1291 ", redosAvail="<<redosAvail<<
1292 ", curStep="<<curStep<<endl;
1293 cout << " ---------------------------"<<endl;
1294 cout << " comment="<<comment.toStdString()<<endl;
1295 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1296 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1297 cout << " redoCom="<<redoCom.toStdString()<<endl;
1298 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1299 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1300 cout << " ---------------------------"<<endl;
1303 mainWindow->updateHistory (undoSet);
1309 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1311 // save the selected part of the map, Undo will replace part of map
1312 QString undoSelection="";
1314 undoSelection=getSelectString(undoSel);
1316 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1317 QString redoSelection="";
1319 redoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1324 saveState (PartOfMap,
1325 undoSelection, "addMapReplace (\"PATH\")",
1331 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1335 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1338 QString undoSelection;
1339 QString redoSelection=getSelectString(redoSel);
1340 if (redoSel->getType()==TreeItem::Branch)
1342 undoSelection=getSelectString (redoSel->parent());
1343 // save the selected branch of the map, Undo will insert part of map
1344 saveState (PartOfMap,
1345 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1346 redoSelection, "delete ()",
1350 if (redoSel->getType()==TreeItem::MapCenter)
1352 // save the selected branch of the map, Undo will insert part of map
1353 saveState (PartOfMap,
1354 undoSelection, QString("addMapInsert (\"PATH\")"),
1355 redoSelection, "delete ()",
1362 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1364 // "Normal" savestate: save commands, selections and comment
1365 // so just save commands for undo and redo
1366 // and use current selection
1368 QString redoSelection="";
1369 if (redoSel) redoSelection=getSelectString(redoSel);
1370 QString undoSelection="";
1371 if (undoSel) undoSelection=getSelectString(undoSel);
1373 saveState (UndoCommand,
1380 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1382 // "Normal" savestate: save commands, selections and comment
1383 // so just save commands for undo and redo
1384 // and use current selection
1385 saveState (UndoCommand,
1392 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1394 // "Normal" savestate applied to model (no selection needed):
1395 // save commands and comment
1396 saveState (UndoCommand,
1404 QGraphicsScene* VymModel::getScene ()
1409 TreeItem* VymModel::findBySelectString(QString s)
1411 if (s.isEmpty() ) return NULL;
1413 // Old maps don't have multiple mapcenters and don't save full path
1414 if (s.left(2) !="mc")
1417 QStringList parts=s.split (",");
1420 TreeItem *ti=rootItem;
1422 while (!parts.isEmpty() )
1424 typ=parts.first().left(2);
1425 n=parts.first().right(parts.first().length() - 3).toInt();
1426 parts.removeFirst();
1427 if (typ=="mc" || typ=="bo")
1428 ti=ti->getBranchNum (n);
1430 ti=ti->getImageNum (n);
1432 ti=ti->getAttributeNum (n);
1434 ti=ti->getXLinkNum (n);
1435 if(!ti) return NULL;
1440 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1442 BranchItem *cur=NULL;
1443 BranchItem *prev=NULL;
1447 if (s==cur->getID() ) return cur;
1453 //////////////////////////////////////////////
1455 //////////////////////////////////////////////
1456 void VymModel::setVersion (const QString &s)
1461 void VymModel::setAuthor (const QString &s)
1464 QString ("setMapAuthor (\"%1\")").arg(author),
1465 QString ("setMapAuthor (\"%1\")").arg(s),
1466 QString ("Set author of map to \"%1\"").arg(s)
1471 QString VymModel::getAuthor()
1476 void VymModel::setComment (const QString &s)
1479 QString ("setMapComment (\"%1\")").arg(comment),
1480 QString ("setMapComment (\"%1\")").arg(s),
1481 QString ("Set comment of map")
1486 QString VymModel::getComment ()
1491 QString VymModel::getDate ()
1493 return QDate::currentDate().toString ("yyyy-MM-dd");
1496 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1499 BranchItem *cur=NULL;
1500 BranchItem *prev=NULL;
1510 void VymModel::setHeading(const QString &s)
1512 BranchItem *selbi=getSelectedBranch();
1517 "setHeading (\""+selbi->getHeading()+"\")",
1519 "setHeading (\""+s+"\")",
1520 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1521 selbi->setHeading(s );
1522 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1524 emitSelectionChanged();
1528 QString VymModel::getHeading()
1530 TreeItem *selti=getSelectedItem();
1532 return selti->getHeading();
1537 BranchItem* VymModel::findText (QString s, bool cs)
1539 QTextDocument::FindFlags flags=0;
1540 if (cs) flags=QTextDocument::FindCaseSensitively;
1543 { // Nothing found or new find process
1545 // nothing found, start again
1549 next (findCurrent,findPrevious);
1551 bool searching=true;
1552 bool foundNote=false;
1553 while (searching && !EOFind)
1557 // Searching in Note
1558 if (findCurrent->getNote().contains(s,cs))
1560 select (findCurrent);
1562 if (getSelectedBranch()!=itFind)
1565 emitShowSelection();
1568 if (textEditor->findText(s,flags))
1574 // Searching in Heading
1575 if (searching && findCurrent->getHeading().contains (s,cs) )
1577 select(findCurrent);
1583 if (!next(findCurrent,findPrevious) )
1586 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1589 return getSelectedBranch();
1594 void VymModel::findReset()
1595 { // Necessary if text to find changes during a find process
1601 void VymModel::setScene (QGraphicsScene *s)
1606 void VymModel::setURL(const QString &url)
1608 TreeItem *selti=getSelectedItem();
1611 QString oldurl=selti->getURL();
1612 selti->setURL (url);
1615 QString ("setURL (\"%1\")").arg(oldurl),
1617 QString ("setURL (\"%1\")").arg(url),
1618 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1621 emitDataHasChanged (selti);
1622 emitShowSelection();
1626 QString VymModel::getURL()
1628 TreeItem *selti=getSelectedItem();
1630 return selti->getURL();
1635 QStringList VymModel::getURLs()
1638 BranchItem *selbi=getSelectedBranch();
1639 BranchItem *cur=selbi;
1640 BranchItem *prev=NULL;
1643 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1644 cur=next (cur,prev,selbi);
1650 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1652 BranchItem *bi=getSelectedBranch();
1655 BranchObj *bo=(BranchObj*)(bi->getLMO());
1658 QString s=bo->getFrameTypeName();
1659 bo->setFrameType (t);
1660 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1661 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1663 bo->updateLinkGeometry();
1668 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1670 BranchItem *bi=getSelectedBranch();
1673 BranchObj *bo=(BranchObj*)(bi->getLMO());
1676 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1677 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1678 bo->setFrameType (s);
1680 bo->updateLinkGeometry();
1685 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1688 BranchItem *bi=getSelectedBranch();
1691 BranchObj *bo=(BranchObj*)(bi->getLMO());
1694 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1695 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1696 bo->setFramePenColor (c);
1701 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1703 BranchItem *bi=getSelectedBranch();
1706 BranchObj *bo=(BranchObj*)(bi->getLMO());
1709 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1710 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1711 bo->setFrameBrushColor (c);
1716 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1718 BranchItem *bi=getSelectedBranch();
1721 BranchObj *bo=(BranchObj*)(bi->getLMO());
1724 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1725 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1726 bo->setFramePadding (i);
1728 bo->updateLinkGeometry();
1733 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1735 BranchItem *bi=getSelectedBranch();
1738 BranchObj *bo=(BranchObj*)(bi->getLMO());
1741 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1742 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1743 bo->setFrameBorderWidth (i);
1745 bo->updateLinkGeometry();
1750 void VymModel::setIncludeImagesVer(bool b)
1752 BranchItem *bi=getSelectedBranch();
1755 QString u= b ? "false" : "true";
1756 QString r=!b ? "false" : "true";
1760 QString("setIncludeImagesVertically (%1)").arg(u),
1762 QString("setIncludeImagesVertically (%1)").arg(r),
1763 QString("Include images vertically in %1").arg(getObjectName(bi))
1765 bi->setIncludeImagesVer(b);
1766 emitDataHasChanged ( bi);
1771 void VymModel::setIncludeImagesHor(bool b)
1773 BranchItem *bi=getSelectedBranch();
1776 QString u= b ? "false" : "true";
1777 QString r=!b ? "false" : "true";
1781 QString("setIncludeImagesHorizontally (%1)").arg(u),
1783 QString("setIncludeImagesHorizontally (%1)").arg(r),
1784 QString("Include images horizontally in %1").arg(getObjectName(bi))
1786 bi->setIncludeImagesHor(b);
1787 emitDataHasChanged ( bi);
1792 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1794 TreeItem *ti=getSelectedItem();
1795 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1797 QString u= b ? "false" : "true";
1798 QString r=!b ? "false" : "true";
1802 QString("setHideLinkUnselected (%1)").arg(u),
1804 QString("setHideLinkUnselected (%1)").arg(r),
1805 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1807 ((MapItem*)ti)->setHideLinkUnselected(b);
1811 void VymModel::setHideExport(bool b)
1813 TreeItem *ti=getSelectedItem();
1815 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1817 ti->setHideInExport (b);
1818 QString u= b ? "false" : "true";
1819 QString r=!b ? "false" : "true";
1823 QString ("setHideExport (%1)").arg(u),
1825 QString ("setHideExport (%1)").arg(r),
1826 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1828 emitDataHasChanged(ti);
1829 emitSelectionChanged();
1832 // emitSelectionChanged();
1833 // FIXME-3 VM needed? scene()->update();
1837 void VymModel::toggleHideExport()
1839 TreeItem *selti=getSelectedItem();
1841 setHideExport ( !selti->hideInExport() );
1845 void VymModel::copy()
1847 TreeItem *selti=getSelectedItem();
1849 (selti->getType() == TreeItem::Branch ||
1850 selti->getType() == TreeItem::MapCenter ||
1851 selti->getType() == TreeItem::Image ))
1853 if (redosAvail == 0)
1856 QString s=getSelectString(selti);
1857 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1858 curClipboard=curStep;
1861 // Copy also to global clipboard, because we are at last step in history
1862 QString bakMapName(QString("history-%1").arg(curStep));
1863 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1864 copyDir (bakMapDir,clipboardDir );
1866 clipboardEmpty=false;
1872 void VymModel::pasteNoSave(const int &n)
1874 bool old=blockSaveState;
1875 blockSaveState=true;
1876 bool zippedOrg=zipped;
1877 if (redosAvail > 0 || n!=0)
1879 // Use the "historical" buffer
1880 QString bakMapName(QString("history-%1").arg(n));
1881 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1882 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1884 // Use the global buffer
1885 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1890 void VymModel::paste()
1892 BranchItem *selbi=getSelectedBranch();
1895 saveStateChangingPart(
1898 QString ("paste (%1)").arg(curClipboard),
1899 QString("Paste to %1").arg( getObjectName(selbi))
1906 void VymModel::cut()
1908 TreeItem *selti=getSelectedItem();
1909 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1917 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1919 if (bi && bi->canMoveUp())
1920 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1925 void VymModel::moveUp()
1927 BranchItem *selbi=getSelectedBranch();
1930 QString oldsel=getSelectString();
1933 getSelectString(),"moveDown ()",
1935 QString("Move up %1").arg(getObjectName(selbi)));
1939 bool VymModel::moveDown(BranchItem *bi)
1941 if (bi && bi->canMoveDown())
1942 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
1947 void VymModel::moveDown()
1949 BranchItem *selbi=getSelectedBranch();
1952 QString oldsel=getSelectString();
1953 if ( moveDown(selbi))
1955 getSelectString(),"moveUp ()",
1956 oldsel,"moveDown ()",
1957 QString("Move down %1").arg(getObjectName(selbi)));
1961 void VymModel::detach()
1963 BranchItem *selbi=getSelectedBranch();
1964 if (selbi && selbi->depth()>0)
1966 // if no relPos have been set before, try to use current rel positions
1967 if (selbi->getLMO())
1968 for (int i=0; i<selbi->branchCount();++i)
1969 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
1971 //QString oldsel=getSelectString();
1972 if ( relinkBranch (selbi,rootItem,-1) )
1974 selbi,QString("relink()"), //FIXME-1 add paramters when detaching
1976 QString("Detach %1").arg(getObjectName(selbi))
1981 void VymModel::sortChildren()
1983 BranchItem* selbi=getSelectedBranch();
1986 if(selbi->branchCount()>1)
1988 saveStateChangingPart(
1989 selbi,selbi, "sortChildren ()",
1990 QString("Sort children of %1").arg(getObjectName(selbi)));
1991 selbi->sortChildren();
1993 emitShowSelection();
1998 BranchItem* VymModel::createMapCenter()
2000 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2004 BranchItem* VymModel::createBranch(BranchItem *dst)
2007 return addNewBranchInt (dst,-2);
2012 ImageItem* VymModel::createImage(BranchItem *dst)
2019 QList<QVariant> cData;
2020 cData << "new" << "undef";
2022 ImageItem *newii=new ImageItem(cData) ;
2023 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2025 emit (layoutAboutToBeChanged() );
2028 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2029 n=dst->getRowNumAppend(newii);
2030 beginInsertRows (parix,n,n);
2031 dst->appendChild (newii);
2034 emit (layoutChanged() );
2036 // save scroll state. If scrolled, automatically select
2037 // new branch in order to tmp unscroll parent...
2038 newii->createMapObj(mapScene);
2045 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2052 QList<QVariant> cData;
2053 cData << "new xLink"<<"undef";
2055 XLinkItem *newxli=new XLinkItem(cData) ;
2056 newxli->setBegin (bi);
2058 emit (layoutAboutToBeChanged() );
2061 n=bi->getRowNumAppend(newxli);
2062 beginInsertRows (parix,n,n);
2063 bi->appendChild (newxli);
2066 emit (layoutChanged() );
2068 // save scroll state. If scrolled, automatically select
2069 // new branch in order to tmp unscroll parent...
2072 newxli->createMapObj(mapScene);
2080 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2082 BranchItem *selbi=getSelectedBranch();
2085 QList<QVariant> cData;
2086 cData << "new attribute" << "undef";
2087 AttributeItem *a=new AttributeItem (cData);
2089 emit (layoutAboutToBeChanged() );
2091 QModelIndex parix=index(selbi);
2092 int n=selbi->getRowNumAppend (a);
2093 beginInsertRows (parix,n,n);
2094 selbi->appendChild (a);
2097 emit (layoutChanged() );
2105 BranchItem* VymModel::addMapCenter ()
2107 BranchItem *bi=addMapCenter (contextPos);
2109 emitShowSelection();
2114 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2115 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2120 BranchItem* VymModel::addMapCenter(QPointF absPos)
2121 // createMapCenter could then probably be merged with createBranch
2125 QModelIndex parix=index(rootItem);
2127 QList<QVariant> cData;
2128 cData << "VM:addMapCenter" << "undef";
2129 BranchItem *newbi=new BranchItem (cData,rootItem);
2130 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2131 int n=rootItem->getRowNumAppend (newbi);
2133 emit (layoutAboutToBeChanged() );
2134 beginInsertRows (parix,n,n);
2136 rootItem->appendChild (newbi);
2139 emit (layoutChanged() );
2142 newbi->setPositionMode (MapItem::Absolute);
2143 BranchObj *bo=newbi->createMapObj(mapScene);
2144 if (bo) bo->move (absPos);
2149 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2151 // Depending on pos:
2152 // -3 insert in children of parent above selection
2153 // -2 add branch to selection
2154 // -1 insert in children of parent below selection
2155 // 0..n insert in children of parent at pos
2158 QList<QVariant> cData;
2159 cData << "new" << "undef";
2164 BranchItem *newbi=new BranchItem (cData);
2165 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2167 emit (layoutAboutToBeChanged() );
2173 n=parbi->getRowNumAppend (newbi);
2174 beginInsertRows (parix,n,n);
2175 parbi->appendChild (newbi);
2177 }else if (num==-1 || num==-3)
2179 // insert below selection
2180 parbi=(BranchItem*)dst->parent();
2183 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2184 beginInsertRows (parix,n,n);
2185 parbi->insertBranch(n,newbi);
2188 emit (layoutChanged() );
2190 // save scroll state. If scrolled, automatically select
2191 // new branch in order to tmp unscroll parent...
2192 newbi->createMapObj(mapScene);
2197 BranchItem* VymModel::addNewBranch(int pos)
2199 // Different meaning than num in addNewBranchInt!
2203 BranchItem *newbi=NULL;
2204 BranchItem *selbi=getSelectedBranch();
2208 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2210 newbi=addNewBranchInt (selbi,pos-2);
2218 QString ("addBranch (%1)").arg(pos),
2219 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2222 // emitSelectionChanged(); FIXME-3
2223 latestAddedItem=newbi;
2224 // In Network mode, the client needs to know where the new branch is,
2225 // so we have to pass on this information via saveState.
2226 // TODO: Get rid of this positioning workaround
2227 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2228 sendData ("selectLatestAdded ()");
2229 sendData (QString("move %1").arg(ps));
2238 BranchItem* VymModel::addNewBranchBefore()
2240 BranchItem *newbi=NULL;
2241 BranchItem *selbi=getSelectedBranch();
2242 if (selbi && selbi->getType()==TreeItem::Branch)
2243 // We accept no MapCenter here, so we _have_ a parent
2245 //QPointF p=bo->getRelPos();
2248 // add below selection
2249 newbi=addNewBranchInt (selbi,-1);
2253 //newbi->move2RelPos (p);
2255 // Move selection to new branch
2256 relinkBranch (selbi,newbi,0);
2258 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2259 QString ("Add branch before %1").arg(getObjectName(selbi)));
2261 // FIXME-3 needed? reposition();
2262 // emitSelectionChanged(); FIXME-3
2268 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2272 emit (layoutAboutToBeChanged() );
2273 BranchItem *branchpi=(BranchItem*)branch->parent();
2274 // Remove at current position
2275 int n=branch->childNum();
2276 beginRemoveRows (index(branchpi),n,n);
2277 branchpi->removeChild (n);
2280 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2282 // Append as last branch to dst
2283 if (dst->branchCount()==0)
2286 n=dst->getFirstBranch()->childNumber();
2287 beginInsertRows (index(dst),n+pos,n+pos);
2288 dst->insertBranch (pos,branch);
2291 // Correct type if necessesary
2292 if (branch->getType()==TreeItem::MapCenter)
2293 branch->setType(TreeItem::Branch);
2295 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2296 branch->updateStyles();
2298 emit (layoutChanged() );
2299 reposition(); // both for moveUp/Down and relinking
2300 if (dst->isScrolled() )
2303 branch->updateVisibility();
2312 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2316 emit (layoutAboutToBeChanged() );
2318 BranchItem *pi=(BranchItem*)(image->parent());
2319 QString oldParString=getSelectString (pi);
2320 // Remove at current position
2321 int n=image->childNum();
2322 beginRemoveRows (index(pi),n,n);
2323 pi->removeChild (n);
2327 QModelIndex dstix=index(dst);
2328 n=dst->getRowNumAppend (image);
2329 beginInsertRows (dstix,n,n+1);
2330 dst->appendChild (image);
2333 // Set new parent also for lmo
2334 if (image->getLMO() && dst->getLMO() )
2335 image->getLMO()->setParObj (dst->getLMO() );
2337 emit (layoutChanged() );
2340 QString("relinkTo (\"%1\")").arg(oldParString),
2342 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2343 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2349 void VymModel::deleteSelection()
2351 BranchItem *selbi=getSelectedBranch();
2356 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2358 TreeItem *pi=deleteItem (selbi);
2362 emitShowSelection();
2366 TreeItem *ti=getSelectedItem();
2369 TreeItem *pi=ti->parent();
2371 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2373 saveStateChangingPart(
2377 QString("Delete %1").arg(getObjectName(ti))
2381 emitDataHasChanged (pi);
2384 emitShowSelection();
2385 } else if (ti->getType()==TreeItem::XLink)
2387 //FIXME-2 savestate missing
2390 qWarning ("VymmModel::deleteSelection() unknown type?!");
2394 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2397 BranchItem *selbi=getSelectedBranch();
2401 // Don't use this on mapcenter
2402 if (selbi->depth()<2) return;
2404 pi=(BranchItem*)(selbi->parent());
2405 // Check if we have childs at all to keep
2406 if (selbi->branchCount()==0)
2413 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2414 saveStateChangingPart(
2417 "deleteKeepChildren ()",
2418 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2421 QString sel=getSelectString(selbi);
2423 int pos=selbi->num();
2424 BranchItem *bi=selbi->getFirstBranch();
2427 relinkBranch (bi,pi,pos);
2428 bi=selbi->getFirstBranch();
2434 BranchObj *bo=getSelectedBranchObj();
2437 bo->move2RelPos (p);
2443 void VymModel::deleteChildren()
2446 BranchItem *selbi=getSelectedBranch();
2449 saveStateChangingPart(
2452 "deleteChildren ()",
2453 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2455 emit (layoutAboutToBeChanged() );
2457 QModelIndex ix=index (selbi);
2458 int n=selbi->branchCount()-1;
2459 beginRemoveRows (ix,0,n);
2460 removeRows (0,n+1,ix);
2462 if (selbi->isScrolled()) selbi->unScroll();
2463 emit (layoutChanged() );
2468 TreeItem* VymModel::deleteItem (TreeItem *ti)
2472 TreeItem *pi=ti->parent();
2473 QModelIndex parentIndex=index(pi);
2475 emit (layoutAboutToBeChanged() );
2477 int n=ti->childNum();
2478 beginRemoveRows (parentIndex,n,n);
2479 removeRows (n,1,parentIndex);
2483 emit (layoutChanged() );
2484 if (pi->depth()>=0) return pi;
2489 void VymModel::clearItem (TreeItem *ti)
2493 QModelIndex parentIndex=index(ti);
2494 if (!parentIndex.isValid()) return;
2496 int n=ti->childCount();
2499 emit (layoutAboutToBeChanged() );
2501 beginRemoveRows (parentIndex,0,n-1);
2502 removeRows (0,n,parentIndex);
2506 emit (layoutChanged() );
2512 bool VymModel::scrollBranch(BranchItem *bi)
2516 if (bi->isScrolled()) return false;
2517 if (bi->branchCount()==0) return false;
2518 if (bi->depth()==0) return false;
2519 if (bi->toggleScroll())
2527 QString ("%1 ()").arg(u),
2529 QString ("%1 ()").arg(r),
2530 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2532 emitDataHasChanged(bi);
2533 emitSelectionChanged();
2534 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2541 bool VymModel::unscrollBranch(BranchItem *bi)
2545 if (!bi->isScrolled()) return false;
2546 if (bi->branchCount()==0) return false;
2547 if (bi->depth()==0) return false;
2548 if (bi->toggleScroll())
2556 QString ("%1 ()").arg(u),
2558 QString ("%1 ()").arg(r),
2559 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2561 emitDataHasChanged(bi);
2562 emitSelectionChanged();
2563 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2570 void VymModel::toggleScroll()
2572 BranchItem *bi=(BranchItem*)getSelectedBranch();
2573 if (bi && bi->isBranchLikeType() )
2575 if (bi->isScrolled())
2576 unscrollBranch (bi);
2580 // saveState & reposition are called in above functions
2583 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2585 BranchItem *selbi=getSelectedBranch();
2586 BranchItem *prev=NULL;
2587 BranchItem *cur=selbi;
2590 saveStateChangingPart(
2593 QString ("unscrollChildren ()"),
2594 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2598 if (cur->isScrolled())
2600 cur->toggleScroll();
2601 emitDataHasChanged (cur);
2603 cur=next (cur,prev,selbi);
2610 void VymModel::emitExpandAll()
2612 emit (expandAll() );
2615 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2617 BranchItem *bi=getSelectedBranch();
2621 if (bi->isActiveStandardFlag(name))
2633 QString("%1 (\"%2\")").arg(u).arg(name),
2635 QString("%1 (\"%2\")").arg(r).arg(name),
2636 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2637 bi->toggleStandardFlag (name, master);
2639 emitSelectionChanged();
2643 void VymModel::addFloatImage (const QPixmap &img)
2645 BranchItem *selbi=getSelectedBranch();
2648 ImageItem *ii=createImage (selbi);
2650 ii->setOriginalFilename("No original filename (image added by dropevent)");
2651 QString s=getSelectString(selbi);
2652 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2653 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2655 // FIXME-3 VM needed? scene()->update();
2660 void VymModel::colorBranch (QColor c)
2662 cout << "VM::colBranch\n";
2663 BranchItem *selbi=getSelectedBranch();
2668 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2670 QString ("colorBranch (\"%1\")").arg(c.name()),
2671 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2673 selbi->setHeadingColor(c); // color branch
2678 void VymModel::colorSubtree (QColor c)
2680 BranchItem *selbi=getSelectedBranch();
2683 saveStateChangingPart(
2686 QString ("colorSubtree (\"%1\")").arg(c.name()),
2687 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2689 BranchItem *prev=NULL;
2690 BranchItem *cur=selbi;
2693 cur->setHeadingColor(c); // color links, color children
2694 cur=next (cur,prev,selbi);
2700 QColor VymModel::getCurrentHeadingColor()
2702 BranchItem *selbi=getSelectedBranch();
2703 if (selbi) return selbi->getHeadingColor();
2705 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2711 void VymModel::editURL()
2713 TreeItem *selti=getSelectedItem();
2717 QString text = QInputDialog::getText(
2718 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2719 selti->getURL(), &ok, NULL);
2721 // user entered something and pressed OK
2726 void VymModel::editLocalURL()
2728 TreeItem *selti=getSelectedItem();
2731 QStringList filters;
2732 filters <<"All files (*)";
2733 filters << tr("Text","Filedialog") + " (*.txt)";
2734 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2735 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2736 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2737 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2738 fd->setFilters (filters);
2739 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2740 fd->setDirectory (lastFileDir);
2741 if (! selti->getVymLink().isEmpty() )
2742 fd->selectFile( selti->getURL() );
2745 if ( fd->exec() == QDialog::Accepted )
2747 lastFileDir=QDir (fd->directory().path());
2748 setURL (fd->selectedFile() );
2754 void VymModel::editHeading2URL()
2756 TreeItem *selti=getSelectedItem();
2758 setURL (selti->getHeading());
2761 void VymModel::editBugzilla2URL()
2763 TreeItem *selti=getSelectedItem();
2766 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2771 void VymModel::editFATE2URL()
2773 TreeItem *selti=getSelectedItem();
2776 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2779 "setURL (\""+selti->getURL()+"\")",
2781 "setURL (\""+url+"\")",
2782 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2784 selti->setURL (url);
2785 // FIXME-4 updateActions();
2789 void VymModel::editVymLink()
2791 BranchItem *bi=getSelectedBranch();
2794 QStringList filters;
2795 filters <<"VYM map (*.vym)";
2796 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2797 fd->setFilters (filters);
2798 fd->setCaption(vymName+" - " +tr("Link to another map"));
2799 fd->setDirectory (lastFileDir);
2800 if (! bi->getVymLink().isEmpty() )
2801 fd->selectFile( bi->getVymLink() );
2805 if ( fd->exec() == QDialog::Accepted )
2807 lastFileDir=QDir (fd->directory().path());
2810 "setVymLink (\""+bi->getVymLink()+"\")",
2812 "setVymLink (\""+fd->selectedFile()+"\")",
2813 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2815 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2820 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2822 // Internal function, no saveState needed
2823 TreeItem *selti=getSelectedItem();
2826 selti->setVymLink(s);
2828 emitDataHasChanged (selti);
2829 emitShowSelection();
2833 void VymModel::deleteVymLink()
2835 BranchItem *bi=getSelectedBranch();
2840 "setVymLink (\""+bi->getVymLink()+"\")",
2842 "setVymLink (\"\")",
2843 QString("Unset vymlink of %1").arg(getObjectName(bi))
2845 bi->setVymLink ("" );
2851 QString VymModel::getVymLink()
2853 BranchItem *bi=getSelectedBranch();
2855 return bi->getVymLink();
2861 QStringList VymModel::getVymLinks()
2864 BranchItem *selbi=getSelectedBranch();
2865 BranchItem *cur=selbi;
2866 BranchItem *prev=NULL;
2869 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2870 cur=next (cur,prev,selbi);
2876 void VymModel::followXLink(int i)
2879 BranchItem *selbi=getSelectedBranch();
2882 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2883 if (selbi) select (selbi);
2887 void VymModel::editXLink(int i)
2890 BranchItem *selbi=getSelectedBranch();
2893 XLinkItem *xli=selbi->getXLinkNum(i);
2896 EditXLinkDialog dia;
2898 dia.setSelection(selbi);
2899 if (dia.exec() == QDialog::Accepted)
2901 if (dia.useSettingsGlobal() )
2903 setMapDefXLinkColor (xli->getColor() );
2904 setMapDefXLinkWidth (xli->getWidth() );
2906 if (dia.deleteXLink()) deleteItem (xli);
2916 //////////////////////////////////////////////
2918 //////////////////////////////////////////////
2920 void VymModel::parseAtom(const QString &atom)
2922 TreeItem* selti=getSelectedItem();
2923 BranchItem *selbi=getSelectedBranch();
2929 // Split string s into command and parameters
2930 parser.parseAtom (atom);
2931 QString com=parser.getCommand();
2933 // External commands
2934 /////////////////////////////////////////////////////////////////////
2935 if (com=="addBranch")
2939 parser.setError (Aborted,"Nothing selected");
2940 } else if (! selbi )
2942 parser.setError (Aborted,"Type of selection is not a branch");
2947 if (parser.checkParCount(pl))
2949 if (parser.parCount()==0)
2953 n=parser.parInt (ok,0);
2954 if (ok ) addNewBranch (n);
2958 /////////////////////////////////////////////////////////////////////
2959 } else if (com=="addBranchBefore")
2963 parser.setError (Aborted,"Nothing selected");
2964 } else if (! selbi )
2966 parser.setError (Aborted,"Type of selection is not a branch");
2969 if (parser.parCount()==0)
2971 addNewBranchBefore ();
2974 /////////////////////////////////////////////////////////////////////
2975 } else if (com==QString("addMapCenter"))
2977 if (parser.checkParCount(2))
2979 x=parser.parDouble (ok,0);
2982 y=parser.parDouble (ok,1);
2983 if (ok) addMapCenter (QPointF(x,y));
2986 /////////////////////////////////////////////////////////////////////
2987 } else if (com==QString("addMapReplace"))
2991 parser.setError (Aborted,"Nothing selected");
2992 } else if (! selbi )
2994 parser.setError (Aborted,"Type of selection is not a branch");
2995 } else if (parser.checkParCount(1))
2997 //s=parser.parString (ok,0); // selection
2998 t=parser.parString (ok,0); // path to map
2999 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3000 addMapReplaceInt(getSelectString(selbi),t);
3002 /////////////////////////////////////////////////////////////////////
3003 } else if (com==QString("addMapInsert"))
3005 if (parser.parCount()==2)
3010 parser.setError (Aborted,"Nothing selected");
3011 } else if (! selbi )
3013 parser.setError (Aborted,"Type of selection is not a branch");
3016 t=parser.parString (ok,0); // path to map
3017 n=parser.parInt(ok,1); // position
3018 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3019 addMapInsertInt(t,n);
3021 } else if (parser.parCount()==1)
3023 t=parser.parString (ok,0); // path to map
3024 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3027 parser.setError (Aborted,"Wrong number of parameters");
3028 /////////////////////////////////////////////////////////////////////
3029 } else if (com==QString("addXLink"))
3031 if (parser.parCount()>1)
3033 s=parser.parString (ok,0); // begin
3034 t=parser.parString (ok,1); // end
3035 BranchItem *begin=(BranchItem*)findBySelectString(s);
3036 BranchItem *end=(BranchItem*)findBySelectString(t);
3039 if (begin->isBranchLikeType() && end->isBranchLikeType())
3041 XLinkItem *xl=createXLink (begin,true);
3047 parser.setError (Aborted,"Failed to create xLink");
3050 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3053 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3055 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3056 /////////////////////////////////////////////////////////////////////
3057 } else if (com=="clearFlags")
3061 parser.setError (Aborted,"Nothing selected");
3062 } else if (! selbi )
3064 parser.setError (Aborted,"Type of selection is not a branch");
3065 } else if (parser.checkParCount(0))
3067 selbi->deactivateAllStandardFlags();
3069 /////////////////////////////////////////////////////////////////////
3070 } else if (com=="colorBranch")
3074 parser.setError (Aborted,"Nothing selected");
3075 } else if (! selbi )
3077 parser.setError (Aborted,"Type of selection is not a branch");
3078 } else if (parser.checkParCount(1))
3080 QColor c=parser.parColor (ok,0);
3081 if (ok) colorBranch (c);
3083 /////////////////////////////////////////////////////////////////////
3084 } else if (com=="colorSubtree")
3088 parser.setError (Aborted,"Nothing selected");
3089 } else if (! selbi )
3091 parser.setError (Aborted,"Type of selection is not a branch");
3092 } else if (parser.checkParCount(1))
3094 QColor c=parser.parColor (ok,0);
3095 if (ok) colorSubtree (c);
3097 /////////////////////////////////////////////////////////////////////
3098 } else if (com=="copy")
3102 parser.setError (Aborted,"Nothing selected");
3103 } else if ( selectionType()!=TreeItem::Branch &&
3104 selectionType()!=TreeItem::MapCenter &&
3105 selectionType()!=TreeItem::Image )
3107 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3108 } else if (parser.checkParCount(0))
3112 /////////////////////////////////////////////////////////////////////
3113 } else if (com=="cut")
3117 parser.setError (Aborted,"Nothing selected");
3118 } else if ( selectionType()!=TreeItem::Branch &&
3119 selectionType()!=TreeItem::MapCenter &&
3120 selectionType()!=TreeItem::Image )
3122 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3123 } else if (parser.checkParCount(0))
3127 /////////////////////////////////////////////////////////////////////
3128 } else if (com=="delete")
3132 parser.setError (Aborted,"Nothing selected");
3134 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3136 parser.setError (Aborted,"Type of selection is wrong.");
3139 else if (parser.checkParCount(0))
3143 /////////////////////////////////////////////////////////////////////
3144 } else if (com=="deleteKeepChildren")
3148 parser.setError (Aborted,"Nothing selected");
3149 } else if (! selbi )
3151 parser.setError (Aborted,"Type of selection is not a branch");
3152 } else if (parser.checkParCount(0))
3154 deleteKeepChildren();
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="deleteChildren")
3161 parser.setError (Aborted,"Nothing selected");
3164 parser.setError (Aborted,"Type of selection is not a branch");
3165 } else if (parser.checkParCount(0))
3169 /////////////////////////////////////////////////////////////////////
3170 } else if (com=="exportASCII")
3174 if (parser.parCount()>=1)
3175 // Hey, we even have a filename
3176 fname=parser.parString(ok,0);
3179 parser.setError (Aborted,"Could not read filename");
3182 exportASCII (fname,false);
3184 /////////////////////////////////////////////////////////////////////
3185 } else if (com=="exportImage")
3189 if (parser.parCount()>=2)
3190 // Hey, we even have a filename
3191 fname=parser.parString(ok,0);
3194 parser.setError (Aborted,"Could not read filename");
3197 QString format="PNG";
3198 if (parser.parCount()>=2)
3200 format=parser.parString(ok,1);
3202 exportImage (fname,false,format);
3204 /////////////////////////////////////////////////////////////////////
3205 } else if (com=="exportXHTML")
3209 if (parser.parCount()>=2)
3210 // Hey, we even have a filename
3211 fname=parser.parString(ok,1);
3214 parser.setError (Aborted,"Could not read filename");
3217 exportXHTML (fname,false);
3219 /////////////////////////////////////////////////////////////////////
3220 } else if (com=="exportXML")
3224 if (parser.parCount()>=2)
3225 // Hey, we even have a filename
3226 fname=parser.parString(ok,1);
3229 parser.setError (Aborted,"Could not read filename");
3232 exportXML (fname,false);
3234 /////////////////////////////////////////////////////////////////////
3235 } else if (com=="importDir")
3239 parser.setError (Aborted,"Nothing selected");
3240 } else if (! selbi )
3242 parser.setError (Aborted,"Type of selection is not a branch");
3243 } else if (parser.checkParCount(1))
3245 s=parser.parString(ok,0);
3246 if (ok) importDirInt(s);
3248 /////////////////////////////////////////////////////////////////////
3249 } else if (com=="relinkTo")
3253 parser.setError (Aborted,"Nothing selected");
3256 if (parser.checkParCount(4))
3258 // 0 selectstring of parent
3259 // 1 num in parent (for branches)
3260 // 2,3 x,y of mainbranch or mapcenter
3261 s=parser.parString(ok,0);
3262 TreeItem *dst=findBySelectString (s);
3265 if (dst->getType()==TreeItem::Branch)
3267 // Get number in parent
3268 n=parser.parInt (ok,1);
3271 relinkBranch (selbi,(BranchItem*)dst,n);
3272 emitSelectionChanged();
3274 } else if (dst->getType()==TreeItem::MapCenter)
3276 relinkBranch (selbi,(BranchItem*)dst);
3277 // Get coordinates of mainbranch
3278 x=parser.parDouble(ok,2);
3281 y=parser.parDouble(ok,3);
3284 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3285 emitSelectionChanged();
3291 } else if ( selti->getType() == TreeItem::Image)
3293 if (parser.checkParCount(1))
3295 // 0 selectstring of parent
3296 s=parser.parString(ok,0);
3297 TreeItem *dst=findBySelectString (s);
3300 if (dst->isBranchLikeType())
3301 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3303 parser.setError (Aborted,"Destination is not a branch");
3306 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3307 /////////////////////////////////////////////////////////////////////
3308 } else if (com=="loadImage")
3312 parser.setError (Aborted,"Nothing selected");
3313 } else if (! selbi )
3315 parser.setError (Aborted,"Type of selection is not a branch");
3316 } else if (parser.checkParCount(1))
3318 s=parser.parString(ok,0);
3319 if (ok) loadFloatImageInt (selbi,s);
3321 /////////////////////////////////////////////////////////////////////
3322 } else if (com=="moveUp")
3326 parser.setError (Aborted,"Nothing selected");
3327 } else if (! selbi )
3329 parser.setError (Aborted,"Type of selection is not a branch");
3330 } else if (parser.checkParCount(0))
3334 /////////////////////////////////////////////////////////////////////
3335 } else if (com=="moveDown")
3339 parser.setError (Aborted,"Nothing selected");
3340 } else if (! selbi )
3342 parser.setError (Aborted,"Type of selection is not a branch");
3343 } else if (parser.checkParCount(0))
3347 /////////////////////////////////////////////////////////////////////
3348 } else if (com=="move")
3352 parser.setError (Aborted,"Nothing selected");
3353 } else if ( selectionType()!=TreeItem::Branch &&
3354 selectionType()!=TreeItem::MapCenter &&
3355 selectionType()!=TreeItem::Image )
3357 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3358 } else if (parser.checkParCount(2))
3360 x=parser.parDouble (ok,0);
3363 y=parser.parDouble (ok,1);
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="moveRel")
3372 parser.setError (Aborted,"Nothing selected");
3373 } else if ( selectionType()!=TreeItem::Branch &&
3374 selectionType()!=TreeItem::MapCenter &&
3375 selectionType()!=TreeItem::Image )
3377 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3378 } else if (parser.checkParCount(2))
3380 x=parser.parDouble (ok,0);
3383 y=parser.parDouble (ok,1);
3384 if (ok) moveRel (x,y);
3387 /////////////////////////////////////////////////////////////////////
3388 } else if (com=="nop")
3390 /////////////////////////////////////////////////////////////////////
3391 } else if (com=="paste")
3395 parser.setError (Aborted,"Nothing selected");
3396 } else if (! selbi )
3398 parser.setError (Aborted,"Type of selection is not a branch");
3399 } else if (parser.checkParCount(1))
3401 n=parser.parInt (ok,0);
3402 if (ok) pasteNoSave(n);
3404 /////////////////////////////////////////////////////////////////////
3405 } else if (com=="qa")
3409 parser.setError (Aborted,"Nothing selected");
3410 } else if (! selbi )
3412 parser.setError (Aborted,"Type of selection is not a branch");
3413 } else if (parser.checkParCount(4))
3416 c=parser.parString (ok,0);
3419 parser.setError (Aborted,"No comment given");
3422 s=parser.parString (ok,1);
3425 parser.setError (Aborted,"First parameter is not a string");
3428 t=parser.parString (ok,2);
3431 parser.setError (Aborted,"Condition is not a string");
3434 u=parser.parString (ok,3);
3437 parser.setError (Aborted,"Third parameter is not a string");
3442 parser.setError (Aborted,"Unknown type: "+s);
3447 parser.setError (Aborted,"Unknown operator: "+t);
3452 parser.setError (Aborted,"Type of selection is not a branch");
3455 if (selbi->getHeading() == u)
3457 cout << "PASSED: " << qPrintable (c) << endl;
3460 cout << "FAILED: " << qPrintable (c) << endl;
3470 /////////////////////////////////////////////////////////////////////
3471 } else if (com=="saveImage")
3473 ImageItem *ii=getSelectedImage();
3476 parser.setError (Aborted,"No image selected");
3477 } else if (parser.checkParCount(2))
3479 s=parser.parString(ok,0);
3482 t=parser.parString(ok,1);
3483 if (ok) saveFloatImageInt (ii,t,s);
3486 /////////////////////////////////////////////////////////////////////
3487 } else if (com=="scroll")
3491 parser.setError (Aborted,"Nothing selected");
3492 } else if (! selbi )
3494 parser.setError (Aborted,"Type of selection is not a branch");
3495 } else if (parser.checkParCount(0))
3497 if (!scrollBranch (selbi))
3498 parser.setError (Aborted,"Could not scroll branch");
3500 /////////////////////////////////////////////////////////////////////
3501 } else if (com=="select")
3503 if (parser.checkParCount(1))
3505 s=parser.parString(ok,0);
3508 /////////////////////////////////////////////////////////////////////
3509 } else if (com=="selectLastBranch")
3513 parser.setError (Aborted,"Nothing selected");
3514 } else if (! selbi )
3516 parser.setError (Aborted,"Type of selection is not a branch");
3517 } else if (parser.checkParCount(0))
3519 BranchItem *bi=selbi->getLastBranch();
3521 parser.setError (Aborted,"Could not select last branch");
3522 select (bi); // FIXME-3 was selectInt
3525 /////////////////////////////////////////////////////////////////////
3526 } else /* FIXME-2 if (com=="selectLastImage")
3530 parser.setError (Aborted,"Nothing selected");
3531 } else if (! selbi )
3533 parser.setError (Aborted,"Type of selection is not a branch");
3534 } else if (parser.checkParCount(0))
3536 FloatImageObj *fio=selb->getLastFloatImage();
3538 parser.setError (Aborted,"Could not select last image");
3539 select (fio); // FIXME-3 was selectInt
3542 /////////////////////////////////////////////////////////////////////
3543 } else */ if (com=="selectLatestAdded")
3545 if (!latestAddedItem)
3547 parser.setError (Aborted,"No latest added object");
3550 if (!select (latestAddedItem))
3551 parser.setError (Aborted,"Could not select latest added object ");
3553 /////////////////////////////////////////////////////////////////////
3554 } else if (com=="setFrameType")
3556 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3558 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3560 else if (parser.checkParCount(1))
3562 s=parser.parString(ok,0);
3563 if (ok) setFrameType (s);
3565 /////////////////////////////////////////////////////////////////////
3566 } else if (com=="setFramePenColor")
3568 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3570 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3572 else if (parser.checkParCount(1))
3574 QColor c=parser.parColor(ok,0);
3575 if (ok) setFramePenColor (c);
3577 /////////////////////////////////////////////////////////////////////
3578 } else if (com=="setFrameBrushColor")
3580 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3582 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3584 else if (parser.checkParCount(1))
3586 QColor c=parser.parColor(ok,0);
3587 if (ok) setFrameBrushColor (c);
3589 /////////////////////////////////////////////////////////////////////
3590 } else if (com=="setFramePadding")
3592 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3594 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3596 else if (parser.checkParCount(1))
3598 n=parser.parInt(ok,0);
3599 if (ok) setFramePadding(n);
3601 /////////////////////////////////////////////////////////////////////
3602 } else if (com=="setFrameBorderWidth")
3604 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3606 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3608 else if (parser.checkParCount(1))
3610 n=parser.parInt(ok,0);
3611 if (ok) setFrameBorderWidth (n);
3613 /////////////////////////////////////////////////////////////////////
3614 } else if (com=="setMapAuthor")
3616 if (parser.checkParCount(1))
3618 s=parser.parString(ok,0);
3619 if (ok) setAuthor (s);
3621 /////////////////////////////////////////////////////////////////////
3622 } else if (com=="setMapComment")
3624 if (parser.checkParCount(1))
3626 s=parser.parString(ok,0);
3627 if (ok) setComment(s);
3629 /////////////////////////////////////////////////////////////////////
3630 } else if (com=="setMapBackgroundColor")
3634 parser.setError (Aborted,"Nothing selected");
3635 } else if (! selbi )
3637 parser.setError (Aborted,"Type of selection is not a branch");
3638 } else if (parser.checkParCount(1))
3640 QColor c=parser.parColor (ok,0);
3641 if (ok) setMapBackgroundColor (c);
3643 /////////////////////////////////////////////////////////////////////
3644 } else if (com=="setMapDefLinkColor")
3648 parser.setError (Aborted,"Nothing selected");
3649 } else if (! selbi )
3651 parser.setError (Aborted,"Type of selection is not a branch");
3652 } else if (parser.checkParCount(1))
3654 QColor c=parser.parColor (ok,0);
3655 if (ok) setMapDefLinkColor (c);
3657 /////////////////////////////////////////////////////////////////////
3658 } else if (com=="setMapLinkStyle")
3660 if (parser.checkParCount(1))
3662 s=parser.parString (ok,0);
3663 if (ok) setMapLinkStyle(s);
3665 /////////////////////////////////////////////////////////////////////
3666 } else if (com=="setHeading")
3670 parser.setError (Aborted,"Nothing selected");
3671 } else if (! selbi )
3673 parser.setError (Aborted,"Type of selection is not a branch");
3674 } else if (parser.checkParCount(1))
3676 s=parser.parString (ok,0);
3680 /////////////////////////////////////////////////////////////////////
3681 } else if (com=="setHideExport")
3685 parser.setError (Aborted,"Nothing selected");
3686 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3688 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3689 } else if (parser.checkParCount(1))
3691 b=parser.parBool(ok,0);
3692 if (ok) setHideExport (b);
3694 /////////////////////////////////////////////////////////////////////
3695 } else if (com=="setIncludeImagesHorizontally")
3699 parser.setError (Aborted,"Nothing selected");
3702 parser.setError (Aborted,"Type of selection is not a branch");
3703 } else if (parser.checkParCount(1))
3705 b=parser.parBool(ok,0);
3706 if (ok) setIncludeImagesHor(b);
3708 /////////////////////////////////////////////////////////////////////
3709 } else if (com=="setIncludeImagesVertically")
3713 parser.setError (Aborted,"Nothing selected");
3716 parser.setError (Aborted,"Type of selection is not a branch");
3717 } else if (parser.checkParCount(1))
3719 b=parser.parBool(ok,0);
3720 if (ok) setIncludeImagesVer(b);
3722 /////////////////////////////////////////////////////////////////////
3723 } else if (com=="setHideLinkUnselected")
3727 parser.setError (Aborted,"Nothing selected");
3728 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3730 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3731 } else if (parser.checkParCount(1))
3733 b=parser.parBool(ok,0);
3734 if (ok) setHideLinkUnselected(b);
3736 /////////////////////////////////////////////////////////////////////
3737 } else if (com=="setSelectionColor")
3739 if (parser.checkParCount(1))
3741 QColor c=parser.parColor (ok,0);
3742 if (ok) setSelectionColorInt (c);
3744 /////////////////////////////////////////////////////////////////////
3745 } else if (com=="setURL")
3749 parser.setError (Aborted,"Nothing selected");
3750 } else if (! selbi )
3752 parser.setError (Aborted,"Type of selection is not a branch");
3753 } else if (parser.checkParCount(1))
3755 s=parser.parString (ok,0);
3758 /////////////////////////////////////////////////////////////////////
3759 } else if (com=="setVymLink")
3763 parser.setError (Aborted,"Nothing selected");
3764 } else if (! selbi )
3766 parser.setError (Aborted,"Type of selection is not a branch");
3767 } else if (parser.checkParCount(1))
3769 s=parser.parString (ok,0);
3770 if (ok) setVymLink(s);
3773 /////////////////////////////////////////////////////////////////////
3774 else if (com=="setFlag")
3778 parser.setError (Aborted,"Nothing selected");
3779 } else if (! selbi )
3781 parser.setError (Aborted,"Type of selection is not a branch");
3782 } else if (parser.checkParCount(1))
3784 s=parser.parString(ok,0);
3786 selbi->activateStandardFlag(s);
3788 /////////////////////////////////////////////////////////////////////
3789 } else /* FIXME-2 if (com=="setFrameType")
3793 parser.setError (Aborted,"Nothing selected");
3796 parser.setError (Aborted,"Type of selection is not a branch");
3797 } else if (parser.checkParCount(1))
3799 s=parser.parString(ok,0);
3803 /////////////////////////////////////////////////////////////////////
3804 } else*/ if (com=="sortChildren")
3808 parser.setError (Aborted,"Nothing selected");
3809 } else if (! selbi )
3811 parser.setError (Aborted,"Type of selection is not a branch");
3812 } else if (parser.checkParCount(0))
3816 /////////////////////////////////////////////////////////////////////
3817 } else if (com=="toggleFlag")
3821 parser.setError (Aborted,"Nothing selected");
3822 } else if (! selbi )
3824 parser.setError (Aborted,"Type of selection is not a branch");
3825 } else if (parser.checkParCount(1))
3827 s=parser.parString(ok,0);
3829 selbi->toggleStandardFlag(s);
3831 /////////////////////////////////////////////////////////////////////
3832 } else if (com=="unscroll")
3836 parser.setError (Aborted,"Nothing selected");
3837 } else if (! selbi )
3839 parser.setError (Aborted,"Type of selection is not a branch");
3840 } else if (parser.checkParCount(0))
3842 if (!unscrollBranch (selbi))
3843 parser.setError (Aborted,"Could not unscroll branch");
3845 /////////////////////////////////////////////////////////////////////
3846 } else if (com=="unscrollChildren")
3850 parser.setError (Aborted,"Nothing selected");
3851 } else if (! selbi )
3853 parser.setError (Aborted,"Type of selection is not a branch");
3854 } else if (parser.checkParCount(0))
3856 unscrollChildren ();
3858 /////////////////////////////////////////////////////////////////////
3859 } else if (com=="unsetFlag")
3863 parser.setError (Aborted,"Nothing selected");
3864 } else if (! selbi )
3866 parser.setError (Aborted,"Type of selection is not a branch");
3867 } else if (parser.checkParCount(1))
3869 s=parser.parString(ok,0);
3871 selbi->deactivateStandardFlag(s);
3874 parser.setError (Aborted,"Unknown command");
3877 if (parser.errorLevel()==NoError)
3879 // setChanged(); FIXME-2 should not be called e.g. for export?!
3884 // TODO Error handling
3885 qWarning("VymModel::parseAtom: Error!");
3886 qWarning(parser.errorMessage());
3890 void VymModel::runScript (QString script)
3892 parser.setScript (script);
3894 while (parser.next() )
3895 parseAtom(parser.getAtom());
3898 void VymModel::setExportMode (bool b)
3900 // should be called before and after exports
3901 // depending on the settings
3902 if (b && settings.value("/export/useHideExport","true")=="true")
3903 setHideTmpMode (TreeItem::HideExport);
3905 setHideTmpMode (TreeItem::HideNone);
3908 void VymModel::exportImage(QString fname, bool askName, QString format)
3912 fname=getMapName()+".png";
3919 QFileDialog *fd=new QFileDialog (NULL);
3920 fd->setCaption (tr("Export map as image"));
3921 fd->setDirectory (lastImageDir);
3922 fd->setFileMode(QFileDialog::AnyFile);
3923 fd->setFilters (imageIO.getFilters() );
3926 fl=fd->selectedFiles();
3928 format=imageIO.getType(fd->selectedFilter());
3932 setExportMode (true);
3933 QPixmap pix (mapEditor->getPixmap());
3934 pix.save(fname, format);
3935 setExportMode (false);
3939 void VymModel::exportXML(QString dir, bool askForName)
3943 dir=browseDirectory(NULL,tr("Export XML to directory"));
3944 if (dir =="" && !reallyWriteDirectory(dir) )
3948 // Hide stuff during export, if settings want this
3949 setExportMode (true);
3951 // Create subdirectories
3954 // write to directory //FIXME-4 check totalBBox here...
3955 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3958 file.setName ( dir + "/"+mapName+".xml");
3959 if ( !file.open( QIODevice::WriteOnly ) )
3961 // This should neverever happen
3962 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3966 // Write it finally, and write in UTF8, no matter what
3967 QTextStream ts( &file );
3968 ts.setEncoding (QTextStream::UnicodeUTF8);
3972 // Now write image, too
3973 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3975 setExportMode (false);
3978 void VymModel::exportASCII(QString fname,bool askName)
3983 ex.setFile (mapName+".txt");
3989 //ex.addFilter ("TXT (*.txt)");
3990 ex.setDir(lastImageDir);
3991 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3996 setExportMode(true);
3998 setExportMode(false);
4002 void VymModel::exportXHTML (const QString &dir, bool askForName)
4004 ExportXHTMLDialog dia(NULL);
4005 dia.setFilePath (filePath );
4006 dia.setMapName (mapName );
4008 if (dir!="") dia.setDir (dir);
4014 if (dia.exec()!=QDialog::Accepted)
4018 QDir d (dia.getDir());
4019 // Check, if warnings should be used before overwriting
4020 // the output directory
4021 if (d.exists() && d.count()>0)
4024 warn.showCancelButton (true);
4025 warn.setText(QString(
4026 "The directory %1 is not empty.\n"
4027 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4028 warn.setCaption("Warning: Directory not empty");
4029 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4031 if (warn.exec()!=QDialog::Accepted) ok=false;
4038 exportXML (dia.getDir(),false );
4039 dia.doExport(mapName );
4040 //if (dia.hasChanged()) setChanged();
4044 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4049 if (ex.setConfigFile(cf))
4051 setExportMode (true);
4052 ex.exportPresentation();
4053 setExportMode (false);
4060 //////////////////////////////////////////////
4062 //////////////////////////////////////////////
4064 void VymModel::registerEditor(QWidget *me)
4066 mapEditor=(MapEditor*)me;
4069 void VymModel::unregisterEditor(QWidget *)
4074 void VymModel::setContextPos(QPointF p)
4079 void VymModel::unsetContextPos()
4081 contextPos=QPointF();
4084 void VymModel::updateNoteFlag()
4087 TreeItem *selti=getSelectedItem();
4090 if (textEditor->isEmpty())
4093 selti->setNote (textEditor->getText());
4094 emitDataHasChanged(selti);
4095 emitSelectionChanged();
4100 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4102 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4103 if (blockReposition) return;
4105 for (int i=0;i<rootItem->branchCount(); i++)
4106 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4107 //emitSelectionChanged();
4111 void VymModel::setMapLinkStyle (const QString & s)
4116 case LinkableMapObj::Line :
4119 case LinkableMapObj::Parabel:
4120 snow="StyleParabel";
4122 case LinkableMapObj::PolyLine:
4123 snow="StylePolyLine";
4125 case LinkableMapObj::PolyParabel:
4126 snow="StylePolyParabel";
4129 snow="UndefinedStyle";
4134 QString("setMapLinkStyle (\"%1\")").arg(s),
4135 QString("setMapLinkStyle (\"%1\")").arg(snow),
4136 QString("Set map link style (\"%1\")").arg(s)
4140 linkstyle=LinkableMapObj::Line;
4141 else if (s=="StyleParabel")
4142 linkstyle=LinkableMapObj::Parabel;
4143 else if (s=="StylePolyLine")
4144 linkstyle=LinkableMapObj::PolyLine;
4145 else if (s=="StylePolyParabel")
4146 linkstyle=LinkableMapObj::PolyParabel;
4148 linkstyle=LinkableMapObj::UndefinedStyle;
4150 BranchItem *cur=NULL;
4151 BranchItem *prev=NULL;
4156 bo=(BranchObj*)(cur->getLMO() );
4157 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4163 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4168 void VymModel::setMapDefLinkColor(QColor col)
4170 if ( !col.isValid() ) return;
4172 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4173 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4174 QString("Set map link color to %1").arg(col.name())
4178 BranchItem *cur=NULL;
4179 BranchItem *prev=NULL;
4184 bo=(BranchObj*)(cur->getLMO() );
4191 void VymModel::setMapLinkColorHintInt()
4193 // called from setMapLinkColorHint(lch) or at end of parse
4194 BranchItem *cur=NULL;
4195 BranchItem *prev=NULL;
4200 bo=(BranchObj*)(cur->getLMO() );
4206 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4209 setMapLinkColorHintInt();
4212 void VymModel::toggleMapLinkColorHint()
4214 if (linkcolorhint==LinkableMapObj::HeadingColor)
4215 linkcolorhint=LinkableMapObj::DefaultColor;
4217 linkcolorhint=LinkableMapObj::HeadingColor;
4218 BranchItem *cur=NULL;
4219 BranchItem *prev=NULL;
4224 bo=(BranchObj*)(cur->getLMO() );
4230 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4231 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4233 Q3FileDialog *fd=new Q3FileDialog( NULL);
4234 fd->setMode (Q3FileDialog::ExistingFile);
4235 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4236 ImagePreview *p =new ImagePreview (fd);
4237 fd->setContentsPreviewEnabled( TRUE );
4238 fd->setContentsPreview( p, p );
4239 fd->setPreviewMode( Q3FileDialog::Contents );
4240 fd->setCaption(vymName+" - " +tr("Load background image"));
4241 fd->setDir (lastImageDir);
4244 if ( fd->exec() == QDialog::Accepted )
4246 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4247 lastImageDir=QDir (fd->dirPath());
4248 setMapBackgroundImage (fd->selectedFile());
4252 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4254 QColor oldcol=mapScene->backgroundBrush().color();
4258 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4260 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4261 QString("Set background color of map to %1").arg(col.name()));
4264 brush.setTextureImage (QPixmap (fn));
4265 mapScene->setBackgroundBrush(brush);
4268 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4270 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4271 if ( !col.isValid() ) return;
4272 setMapBackgroundColor( col );
4276 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4278 QColor oldcol=mapScene->backgroundBrush().color();
4280 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4281 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4282 QString("Set background color of map to %1").arg(col.name()));
4283 mapScene->setBackgroundBrush(col);
4286 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4288 return mapScene->backgroundBrush().color();
4292 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4294 return linkcolorhint;
4297 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4299 return defLinkColor;
4302 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4307 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4309 return defXLinkColor;
4312 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4317 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4319 return defXLinkWidth;
4322 void VymModel::move(const double &x, const double &y)
4325 MapItem *seli = (MapItem*)getSelectedItem();
4326 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4328 LinkableMapObj *lmo=seli->getLMO();
4331 QPointF ap(lmo->getAbsPos());
4335 QString ps=qpointFToString(ap);
4336 QString s=getSelectString(seli);
4339 s, "move "+qpointFToString(to),
4340 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4343 emitSelectionChanged();
4349 void VymModel::moveRel (const double &x, const double &y)
4352 MapItem *seli = (MapItem*)getSelectedItem();
4353 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4355 LinkableMapObj *lmo=seli->getLMO();
4358 QPointF rp(lmo->getRelPos());
4362 QString ps=qpointFToString (lmo->getRelPos());
4363 QString s=getSelectString(seli);
4366 s, "moveRel "+qpointFToString(to),
4367 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4368 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4370 lmo->updateLinkGeometry();
4371 emitSelectionChanged();
4378 void VymModel::animate()
4380 animationTimer->stop();
4383 while (i<animObjList.size() )
4385 bo=(BranchObj*)animObjList.at(i);
4390 animObjList.removeAt(i);
4397 QItemSelection sel=selModel->selection();
4398 emit (selectionChanged(sel,sel));
4401 if (!animObjList.isEmpty()) animationTimer->start();
4405 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4407 if (start==dest) return;
4408 if (bo && bo->getTreeItem()->depth()>0)
4411 ap.setStart (start);
4413 ap.setTicks (animationTicks);
4414 ap.setAnimated (true);
4415 bo->setAnimation (ap);
4416 animObjList.append( bo );
4417 animationTimer->setSingleShot (true);
4418 animationTimer->start(animationInterval);
4422 void VymModel::stopAnimation (MapObj *mo)
4424 int i=animObjList.indexOf(mo);
4426 animObjList.removeAt (i);
4429 void VymModel::sendSelection()
4431 if (netstate!=Server) return;
4432 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4435 void VymModel::newServer()
4439 tcpServer = new QTcpServer(this);
4440 if (!tcpServer->listen(QHostAddress::Any,port)) {
4441 QMessageBox::critical(NULL, "vym server",
4442 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4443 //FIXME-3 needed? we are no widget any longer... close();
4446 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4448 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4451 void VymModel::connectToServer()
4454 server="salam.suse.de";
4456 clientSocket = new QTcpSocket (this);
4457 clientSocket->abort();
4458 clientSocket->connectToHost(server ,port);
4459 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4460 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4461 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4463 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4468 void VymModel::newClient()
4470 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4471 connect(newClient, SIGNAL(disconnected()),
4472 newClient, SLOT(deleteLater()));
4474 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4476 clientList.append (newClient);
4480 void VymModel::sendData(const QString &s)
4482 if (clientList.size()==0) return;
4484 // Create bytearray to send
4486 QDataStream out(&block, QIODevice::WriteOnly);
4487 out.setVersion(QDataStream::Qt_4_0);
4489 // Reserve some space for blocksize
4492 // Write sendCounter
4493 out << sendCounter++;
4498 // Go back and write blocksize so far
4499 out.device()->seek(0);
4500 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4504 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4506 for (int i=0; i<clientList.size(); ++i)
4508 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4509 clientList.at(i)->write (block);
4513 void VymModel::readData ()
4515 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4518 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4522 QDataStream in(clientSocket);
4523 in.setVersion(QDataStream::Qt_4_0);
4531 cout << " t="<<qPrintable (t)<<endl;
4537 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4539 switch (socketError) {
4540 case QAbstractSocket::RemoteHostClosedError:
4542 case QAbstractSocket::HostNotFoundError:
4543 QMessageBox::information(NULL, vymName +" Network client",
4544 "The host was not found. Please check the "
4545 "host name and port settings.");
4547 case QAbstractSocket::ConnectionRefusedError:
4548 QMessageBox::information(NULL, vymName + " Network client",
4549 "The connection was refused by the peer. "
4550 "Make sure the fortune server is running, "
4551 "and check that the host name and port "
4552 "settings are correct.");
4555 QMessageBox::information(NULL, vymName + " Network client",
4556 QString("The following error occurred: %1.")
4557 .arg(clientSocket->errorString()));
4561 /* FIXME-3 Playing with DBUS...
4562 QDBusVariant VymModel::query (const QString &query)
4564 TreeItem *selti=getSelectedItem();
4566 return QDBusVariant (selti->getHeading());
4568 return QDBusVariant ("Nothing selected.");
4572 void VymModel::testslot() //FIXME-3
4574 cout << "VM::testslot called\n";
4577 void VymModel::selectMapSelectionColor()
4579 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4580 setSelectionColor (col);
4583 void VymModel::setSelectionColorInt (QColor col)
4585 if ( !col.isValid() ) return;
4587 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4588 QString("setSelectionColor (%1)").arg(col.name()),
4589 QString("Set color of selection box to %1").arg(col.name())
4592 mapEditor->setSelectionColor (col);
4595 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4597 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4598 //FIXME-3 emitShowSelection();
4602 void VymModel::emitSelectionChanged()
4604 QItemSelection newsel=selModel->selection();
4605 emitSelectionChanged (newsel);
4608 void VymModel::setSelectionColor(QColor col)
4610 if ( !col.isValid() ) return;
4612 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4613 QString("setSelectionColor (%1)").arg(col.name()),
4614 QString("Set color of selection box to %1").arg(col.name())
4616 setSelectionColorInt (col);
4619 QColor VymModel::getSelectionColor()
4621 return mapEditor->getSelectionColor();
4624 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4627 for (int i=0;i<rootItem->childCount();i++)
4628 rootItem->child(i)->setHideTmp (mode);
4630 // FIXME-3 needed? scene()->update();
4633 //////////////////////////////////////////////
4634 // Selection related
4635 //////////////////////////////////////////////
4637 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4642 QItemSelectionModel* VymModel::getSelectionModel()
4647 void VymModel::setSelectionBlocked (bool b)
4652 bool VymModel::isSelectionBlocked()
4654 return selectionBlocked;
4657 bool VymModel::select ()
4659 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4662 bool VymModel::select (const QString &s)
4669 TreeItem *ti=findBySelectString(s);
4670 if (ti) return select (index(ti));
4674 bool VymModel::select (LinkableMapObj *lmo)
4676 QItemSelection oldsel=selModel->selection();
4679 return select (index (lmo->getTreeItem()) );
4684 bool VymModel::select (TreeItem *ti)
4686 if (ti) return select (index(ti));
4690 bool VymModel::select (const QModelIndex &index)
4692 if (index.isValid() )
4694 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4695 BranchItem *bi=getSelectedBranch();
4696 if (bi) bi->setLastSelectedBranch();
4702 void VymModel::unselect()
4704 lastSelectString=getSelectString();
4705 selModel->clearSelection();
4708 bool VymModel::reselect()
4710 return select (lastSelectString);
4713 void VymModel::emitShowSelection()
4715 if (!blockReposition)
4716 emit (showSelection() );
4719 void VymModel::emitNoteHasChanged (TreeItem *ti)
4721 QModelIndex ix=index(ti);
4722 emit (noteHasChanged (ix) );
4725 void VymModel::emitDataHasChanged (TreeItem *ti)
4727 QModelIndex ix=index(ti);
4728 emit (dataChanged (ix,ix) );
4732 bool VymModel::selectFirstBranch()
4734 TreeItem *ti=getSelectedBranch();
4737 TreeItem *par=ti->parent();
4740 TreeItem *ti2=par->getFirstBranch();
4741 if (ti2) return select(ti2);
4747 bool VymModel::selectLastBranch()
4749 TreeItem *ti=getSelectedBranch();
4752 TreeItem *par=ti->parent();
4755 TreeItem *ti2=par->getLastBranch();
4756 if (ti2) return select(ti2);
4762 bool VymModel::selectLastSelectedBranch()
4764 BranchItem *bi=getSelectedBranch();
4767 bi=bi->getLastSelectedBranch();
4768 if (bi) return select (bi);
4773 bool VymModel::selectParent()
4775 TreeItem *ti=getSelectedItem();
4786 TreeItem::Type VymModel::selectionType()
4788 QModelIndexList list=selModel->selectedIndexes();
4789 if (list.isEmpty()) return TreeItem::Undefined;
4790 TreeItem *ti = getItem (list.first() );
4791 return ti->getType();
4795 LinkableMapObj* VymModel::getSelectedLMO()
4797 QModelIndexList list=selModel->selectedIndexes();
4798 if (!list.isEmpty() )
4800 TreeItem *ti = getItem (list.first() );
4801 TreeItem::Type type=ti->getType();
4802 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4803 return ((MapItem*)ti)->getLMO();
4808 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4810 TreeItem *ti = getSelectedBranch();
4812 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4817 BranchItem* VymModel::getSelectedBranch()
4819 QModelIndexList list=selModel->selectedIndexes();
4820 if (!list.isEmpty() )
4822 TreeItem *ti = getItem (list.first() );
4823 TreeItem::Type type=ti->getType();
4824 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4825 return (BranchItem*)ti;
4830 ImageItem* VymModel::getSelectedImage()
4832 QModelIndexList list=selModel->selectedIndexes();
4833 if (!list.isEmpty())
4835 TreeItem *ti=getItem (list.first());
4836 if (ti && ti->getType()==TreeItem::Image)
4837 return (ImageItem*)ti;
4842 AttributeItem* VymModel::getSelectedAttribute()
4844 QModelIndexList list=selModel->selectedIndexes();
4845 if (!list.isEmpty() )
4847 TreeItem *ti = getItem (list.first() );
4848 TreeItem::Type type=ti->getType();
4849 if (type ==TreeItem::Attribute)
4850 return (AttributeItem*)ti;
4855 TreeItem* VymModel::getSelectedItem()
4857 QModelIndexList list=selModel->selectedIndexes();
4858 if (!list.isEmpty() )
4859 return getItem (list.first() );
4864 QModelIndex VymModel::getSelectedIndex()
4866 QModelIndexList list=selModel->selectedIndexes();
4867 if (list.isEmpty() )
4868 return QModelIndex();
4870 return list.first();
4873 QString VymModel::getSelectString ()
4875 return getSelectString (getSelectedItem());
4878 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
4880 if (!lmo) return QString();
4881 return getSelectString (lmo->getTreeItem() );
4884 QString VymModel::getSelectString (TreeItem *ti)
4888 switch (ti->getType())
4890 case TreeItem::MapCenter: s="mc:"; break;
4891 case TreeItem::Branch: s="bo:";break;
4892 case TreeItem::Image: s="fi:";break;
4893 case TreeItem::Attribute: s="ai:";break;
4894 case TreeItem::XLink: s="xl:";break;
4896 s="unknown type in VymModel::getSelectString()";
4899 s= s + QString("%1").arg(ti->num());
4901 // call myself recursively
4902 s= getSelectString(ti->parent()) +","+s;