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::setSortFilter (const QString &s)
1513 emit (sortFilterChanged (sortFilter));
1516 QString VymModel::getSortFilter ()
1521 void VymModel::setHeading(const QString &s)
1523 BranchItem *selbi=getSelectedBranch();
1528 "setHeading (\""+selbi->getHeading()+"\")",
1530 "setHeading (\""+s+"\")",
1531 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1532 selbi->setHeading(s );
1533 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1535 emitSelectionChanged();
1539 QString VymModel::getHeading()
1541 TreeItem *selti=getSelectedItem();
1543 return selti->getHeading();
1548 BranchItem* VymModel::findText (QString s, bool cs)
1550 QTextDocument::FindFlags flags=0;
1551 if (cs) flags=QTextDocument::FindCaseSensitively;
1554 { // Nothing found or new find process
1556 // nothing found, start again
1560 next (findCurrent,findPrevious);
1562 bool searching=true;
1563 bool foundNote=false;
1564 while (searching && !EOFind)
1568 // Searching in Note
1569 if (findCurrent->getNote().contains(s,cs))
1571 select (findCurrent);
1573 if (getSelectedBranch()!=itFind)
1576 emitShowSelection();
1579 if (textEditor->findText(s,flags))
1585 // Searching in Heading
1586 if (searching && findCurrent->getHeading().contains (s,cs) )
1588 select(findCurrent);
1594 if (!next(findCurrent,findPrevious) )
1597 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1600 return getSelectedBranch();
1605 void VymModel::findReset()
1606 { // Necessary if text to find changes during a find process
1612 void VymModel::setScene (QGraphicsScene *s)
1617 void VymModel::setURL(const QString &url)
1619 TreeItem *selti=getSelectedItem();
1622 QString oldurl=selti->getURL();
1623 selti->setURL (url);
1626 QString ("setURL (\"%1\")").arg(oldurl),
1628 QString ("setURL (\"%1\")").arg(url),
1629 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1632 emitDataHasChanged (selti);
1633 emitShowSelection();
1637 QString VymModel::getURL()
1639 TreeItem *selti=getSelectedItem();
1641 return selti->getURL();
1646 QStringList VymModel::getURLs()
1649 BranchItem *selbi=getSelectedBranch();
1650 BranchItem *cur=selbi;
1651 BranchItem *prev=NULL;
1654 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1655 cur=next (cur,prev,selbi);
1661 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1663 BranchItem *bi=getSelectedBranch();
1666 BranchObj *bo=(BranchObj*)(bi->getLMO());
1669 QString s=bo->getFrameTypeName();
1670 bo->setFrameType (t);
1671 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1672 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1674 bo->updateLinkGeometry();
1679 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1681 BranchItem *bi=getSelectedBranch();
1684 BranchObj *bo=(BranchObj*)(bi->getLMO());
1687 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1688 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1689 bo->setFrameType (s);
1691 bo->updateLinkGeometry();
1696 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1699 BranchItem *bi=getSelectedBranch();
1702 BranchObj *bo=(BranchObj*)(bi->getLMO());
1705 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1706 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1707 bo->setFramePenColor (c);
1712 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1714 BranchItem *bi=getSelectedBranch();
1717 BranchObj *bo=(BranchObj*)(bi->getLMO());
1720 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1721 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1722 bo->setFrameBrushColor (c);
1727 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1729 BranchItem *bi=getSelectedBranch();
1732 BranchObj *bo=(BranchObj*)(bi->getLMO());
1735 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1736 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1737 bo->setFramePadding (i);
1739 bo->updateLinkGeometry();
1744 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1746 BranchItem *bi=getSelectedBranch();
1749 BranchObj *bo=(BranchObj*)(bi->getLMO());
1752 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1753 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1754 bo->setFrameBorderWidth (i);
1756 bo->updateLinkGeometry();
1761 void VymModel::setIncludeImagesVer(bool b)
1763 BranchItem *bi=getSelectedBranch();
1766 QString u= b ? "false" : "true";
1767 QString r=!b ? "false" : "true";
1771 QString("setIncludeImagesVertically (%1)").arg(u),
1773 QString("setIncludeImagesVertically (%1)").arg(r),
1774 QString("Include images vertically in %1").arg(getObjectName(bi))
1776 bi->setIncludeImagesVer(b);
1777 emitDataHasChanged ( bi);
1782 void VymModel::setIncludeImagesHor(bool b)
1784 BranchItem *bi=getSelectedBranch();
1787 QString u= b ? "false" : "true";
1788 QString r=!b ? "false" : "true";
1792 QString("setIncludeImagesHorizontally (%1)").arg(u),
1794 QString("setIncludeImagesHorizontally (%1)").arg(r),
1795 QString("Include images horizontally in %1").arg(getObjectName(bi))
1797 bi->setIncludeImagesHor(b);
1798 emitDataHasChanged ( bi);
1803 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1805 TreeItem *ti=getSelectedItem();
1806 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1808 QString u= b ? "false" : "true";
1809 QString r=!b ? "false" : "true";
1813 QString("setHideLinkUnselected (%1)").arg(u),
1815 QString("setHideLinkUnselected (%1)").arg(r),
1816 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1818 ((MapItem*)ti)->setHideLinkUnselected(b);
1822 void VymModel::setHideExport(bool b)
1824 TreeItem *ti=getSelectedItem();
1826 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1828 ti->setHideInExport (b);
1829 QString u= b ? "false" : "true";
1830 QString r=!b ? "false" : "true";
1834 QString ("setHideExport (%1)").arg(u),
1836 QString ("setHideExport (%1)").arg(r),
1837 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1839 emitDataHasChanged(ti);
1840 emitSelectionChanged();
1843 // emitSelectionChanged();
1844 // FIXME-3 VM needed? scene()->update();
1848 void VymModel::toggleHideExport()
1850 TreeItem *selti=getSelectedItem();
1852 setHideExport ( !selti->hideInExport() );
1856 void VymModel::copy()
1858 TreeItem *selti=getSelectedItem();
1860 (selti->getType() == TreeItem::Branch ||
1861 selti->getType() == TreeItem::MapCenter ||
1862 selti->getType() == TreeItem::Image ))
1864 if (redosAvail == 0)
1867 QString s=getSelectString(selti);
1868 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1869 curClipboard=curStep;
1872 // Copy also to global clipboard, because we are at last step in history
1873 QString bakMapName(QString("history-%1").arg(curStep));
1874 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1875 copyDir (bakMapDir,clipboardDir );
1877 clipboardEmpty=false;
1883 void VymModel::pasteNoSave(const int &n)
1885 bool old=blockSaveState;
1886 blockSaveState=true;
1887 bool zippedOrg=zipped;
1888 if (redosAvail > 0 || n!=0)
1890 // Use the "historical" buffer
1891 QString bakMapName(QString("history-%1").arg(n));
1892 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1893 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1895 // Use the global buffer
1896 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1901 void VymModel::paste()
1903 BranchItem *selbi=getSelectedBranch();
1906 saveStateChangingPart(
1909 QString ("paste (%1)").arg(curClipboard),
1910 QString("Paste to %1").arg( getObjectName(selbi))
1917 void VymModel::cut()
1919 TreeItem *selti=getSelectedItem();
1920 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1928 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1930 if (bi && bi->canMoveUp())
1931 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1936 void VymModel::moveUp()
1938 BranchItem *selbi=getSelectedBranch();
1941 QString oldsel=getSelectString();
1944 getSelectString(),"moveDown ()",
1946 QString("Move up %1").arg(getObjectName(selbi)));
1950 bool VymModel::moveDown(BranchItem *bi)
1952 if (bi && bi->canMoveDown())
1953 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
1958 void VymModel::moveDown()
1960 BranchItem *selbi=getSelectedBranch();
1963 QString oldsel=getSelectString();
1964 if ( moveDown(selbi))
1966 getSelectString(),"moveUp ()",
1967 oldsel,"moveDown ()",
1968 QString("Move down %1").arg(getObjectName(selbi)));
1972 void VymModel::detach()
1974 BranchItem *selbi=getSelectedBranch();
1975 if (selbi && selbi->depth()>0)
1977 // if no relPos have been set before, try to use current rel positions
1978 if (selbi->getLMO())
1979 for (int i=0; i<selbi->branchCount();++i)
1980 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
1982 //QString oldsel=getSelectString();
1983 if ( relinkBranch (selbi,rootItem,-1) )
1985 selbi,QString("relink()"), //FIXME-1 add paramters when detaching
1987 QString("Detach %1").arg(getObjectName(selbi))
1992 void VymModel::sortChildren()
1994 BranchItem* selbi=getSelectedBranch();
1997 if(selbi->branchCount()>1)
1999 saveStateChangingPart(
2000 selbi,selbi, "sortChildren ()",
2001 QString("Sort children of %1").arg(getObjectName(selbi)));
2002 selbi->sortChildren();
2004 emitShowSelection();
2009 BranchItem* VymModel::createMapCenter()
2011 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2015 BranchItem* VymModel::createBranch(BranchItem *dst)
2018 return addNewBranchInt (dst,-2);
2023 ImageItem* VymModel::createImage(BranchItem *dst)
2030 QList<QVariant> cData;
2031 cData << "new" << "undef";
2033 ImageItem *newii=new ImageItem(cData) ;
2034 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2036 emit (layoutAboutToBeChanged() );
2039 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2040 n=dst->getRowNumAppend(newii);
2041 beginInsertRows (parix,n,n);
2042 dst->appendChild (newii);
2045 emit (layoutChanged() );
2047 // save scroll state. If scrolled, automatically select
2048 // new branch in order to tmp unscroll parent...
2049 newii->createMapObj(mapScene);
2056 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2063 QList<QVariant> cData;
2064 cData << "new xLink"<<"undef";
2066 XLinkItem *newxli=new XLinkItem(cData) ;
2067 newxli->setBegin (bi);
2069 emit (layoutAboutToBeChanged() );
2072 n=bi->getRowNumAppend(newxli);
2073 beginInsertRows (parix,n,n);
2074 bi->appendChild (newxli);
2077 emit (layoutChanged() );
2079 // save scroll state. If scrolled, automatically select
2080 // new branch in order to tmp unscroll parent...
2083 newxli->createMapObj(mapScene);
2091 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2093 BranchItem *selbi=getSelectedBranch();
2096 QList<QVariant> cData;
2097 cData << "new attribute" << "undef";
2098 AttributeItem *a=new AttributeItem (cData);
2100 emit (layoutAboutToBeChanged() );
2102 QModelIndex parix=index(selbi);
2103 int n=selbi->getRowNumAppend (a);
2104 beginInsertRows (parix,n,n);
2105 selbi->appendChild (a);
2108 emit (layoutChanged() );
2116 BranchItem* VymModel::addMapCenter ()
2118 BranchItem *bi=addMapCenter (contextPos);
2120 emitShowSelection();
2125 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2126 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2131 BranchItem* VymModel::addMapCenter(QPointF absPos)
2132 // createMapCenter could then probably be merged with createBranch
2136 QModelIndex parix=index(rootItem);
2138 QList<QVariant> cData;
2139 cData << "VM:addMapCenter" << "undef";
2140 BranchItem *newbi=new BranchItem (cData,rootItem);
2141 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2142 int n=rootItem->getRowNumAppend (newbi);
2144 emit (layoutAboutToBeChanged() );
2145 beginInsertRows (parix,n,n);
2147 rootItem->appendChild (newbi);
2150 emit (layoutChanged() );
2153 newbi->setPositionMode (MapItem::Absolute);
2154 BranchObj *bo=newbi->createMapObj(mapScene);
2155 if (bo) bo->move (absPos);
2160 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2162 // Depending on pos:
2163 // -3 insert in children of parent above selection
2164 // -2 add branch to selection
2165 // -1 insert in children of parent below selection
2166 // 0..n insert in children of parent at pos
2169 QList<QVariant> cData;
2170 cData << "new" << "undef";
2175 BranchItem *newbi=new BranchItem (cData);
2176 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2178 emit (layoutAboutToBeChanged() );
2184 n=parbi->getRowNumAppend (newbi);
2185 beginInsertRows (parix,n,n);
2186 parbi->appendChild (newbi);
2188 }else if (num==-1 || num==-3)
2190 // insert below selection
2191 parbi=(BranchItem*)dst->parent();
2194 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2195 beginInsertRows (parix,n,n);
2196 parbi->insertBranch(n,newbi);
2199 emit (layoutChanged() );
2201 // save scroll state. If scrolled, automatically select
2202 // new branch in order to tmp unscroll parent...
2203 newbi->createMapObj(mapScene);
2208 BranchItem* VymModel::addNewBranch(int pos)
2210 // Different meaning than num in addNewBranchInt!
2214 BranchItem *newbi=NULL;
2215 BranchItem *selbi=getSelectedBranch();
2219 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2221 newbi=addNewBranchInt (selbi,pos-2);
2229 QString ("addBranch (%1)").arg(pos),
2230 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2233 // emitSelectionChanged(); FIXME-3
2234 latestAddedItem=newbi;
2235 // In Network mode, the client needs to know where the new branch is,
2236 // so we have to pass on this information via saveState.
2237 // TODO: Get rid of this positioning workaround
2238 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2239 sendData ("selectLatestAdded ()");
2240 sendData (QString("move %1").arg(ps));
2249 BranchItem* VymModel::addNewBranchBefore()
2251 BranchItem *newbi=NULL;
2252 BranchItem *selbi=getSelectedBranch();
2253 if (selbi && selbi->getType()==TreeItem::Branch)
2254 // We accept no MapCenter here, so we _have_ a parent
2256 //QPointF p=bo->getRelPos();
2259 // add below selection
2260 newbi=addNewBranchInt (selbi,-1);
2264 //newbi->move2RelPos (p);
2266 // Move selection to new branch
2267 relinkBranch (selbi,newbi,0);
2269 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2270 QString ("Add branch before %1").arg(getObjectName(selbi)));
2272 // FIXME-3 needed? reposition();
2273 // emitSelectionChanged(); FIXME-3
2279 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2283 emit (layoutAboutToBeChanged() );
2284 BranchItem *branchpi=(BranchItem*)branch->parent();
2285 // Remove at current position
2286 int n=branch->childNum();
2287 beginRemoveRows (index(branchpi),n,n);
2288 branchpi->removeChild (n);
2291 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2293 // Append as last branch to dst
2294 if (dst->branchCount()==0)
2297 n=dst->getFirstBranch()->childNumber();
2298 beginInsertRows (index(dst),n+pos,n+pos);
2299 dst->insertBranch (pos,branch);
2302 // Correct type if necessesary
2303 if (branch->getType()==TreeItem::MapCenter)
2304 branch->setType(TreeItem::Branch);
2306 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2307 branch->updateStyles();
2309 emit (layoutChanged() );
2310 reposition(); // both for moveUp/Down and relinking
2311 if (dst->isScrolled() )
2314 branch->updateVisibility();
2323 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2327 emit (layoutAboutToBeChanged() );
2329 BranchItem *pi=(BranchItem*)(image->parent());
2330 QString oldParString=getSelectString (pi);
2331 // Remove at current position
2332 int n=image->childNum();
2333 beginRemoveRows (index(pi),n,n);
2334 pi->removeChild (n);
2338 QModelIndex dstix=index(dst);
2339 n=dst->getRowNumAppend (image);
2340 beginInsertRows (dstix,n,n+1);
2341 dst->appendChild (image);
2344 // Set new parent also for lmo
2345 if (image->getLMO() && dst->getLMO() )
2346 image->getLMO()->setParObj (dst->getLMO() );
2348 emit (layoutChanged() );
2351 QString("relinkTo (\"%1\")").arg(oldParString),
2353 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2354 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2360 void VymModel::deleteSelection()
2362 BranchItem *selbi=getSelectedBranch();
2367 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2369 TreeItem *pi=deleteItem (selbi);
2373 emitShowSelection();
2377 TreeItem *ti=getSelectedItem();
2380 TreeItem *pi=ti->parent();
2382 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2384 saveStateChangingPart(
2388 QString("Delete %1").arg(getObjectName(ti))
2392 emitDataHasChanged (pi);
2395 emitShowSelection();
2396 } else if (ti->getType()==TreeItem::XLink)
2398 //FIXME-2 savestate missing
2401 qWarning ("VymmModel::deleteSelection() unknown type?!");
2405 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2408 BranchItem *selbi=getSelectedBranch();
2412 // Don't use this on mapcenter
2413 if (selbi->depth()<2) return;
2415 pi=(BranchItem*)(selbi->parent());
2416 // Check if we have childs at all to keep
2417 if (selbi->branchCount()==0)
2424 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2425 saveStateChangingPart(
2428 "deleteKeepChildren ()",
2429 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2432 QString sel=getSelectString(selbi);
2434 int pos=selbi->num();
2435 BranchItem *bi=selbi->getFirstBranch();
2438 relinkBranch (bi,pi,pos);
2439 bi=selbi->getFirstBranch();
2445 BranchObj *bo=getSelectedBranchObj();
2448 bo->move2RelPos (p);
2454 void VymModel::deleteChildren()
2457 BranchItem *selbi=getSelectedBranch();
2460 saveStateChangingPart(
2463 "deleteChildren ()",
2464 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2466 emit (layoutAboutToBeChanged() );
2468 QModelIndex ix=index (selbi);
2469 int n=selbi->branchCount()-1;
2470 beginRemoveRows (ix,0,n);
2471 removeRows (0,n+1,ix);
2473 if (selbi->isScrolled()) selbi->unScroll();
2474 emit (layoutChanged() );
2479 TreeItem* VymModel::deleteItem (TreeItem *ti)
2483 TreeItem *pi=ti->parent();
2484 QModelIndex parentIndex=index(pi);
2486 emit (layoutAboutToBeChanged() );
2488 int n=ti->childNum();
2489 beginRemoveRows (parentIndex,n,n);
2490 removeRows (n,1,parentIndex);
2494 emit (layoutChanged() );
2495 if (pi->depth()>=0) return pi;
2500 void VymModel::clearItem (TreeItem *ti)
2504 QModelIndex parentIndex=index(ti);
2505 if (!parentIndex.isValid()) return;
2507 int n=ti->childCount();
2510 emit (layoutAboutToBeChanged() );
2512 beginRemoveRows (parentIndex,0,n-1);
2513 removeRows (0,n,parentIndex);
2517 emit (layoutChanged() );
2523 bool VymModel::scrollBranch(BranchItem *bi)
2527 if (bi->isScrolled()) return false;
2528 if (bi->branchCount()==0) return false;
2529 if (bi->depth()==0) return false;
2530 if (bi->toggleScroll())
2538 QString ("%1 ()").arg(u),
2540 QString ("%1 ()").arg(r),
2541 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2543 emitDataHasChanged(bi);
2544 emitSelectionChanged();
2545 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2552 bool VymModel::unscrollBranch(BranchItem *bi)
2556 if (!bi->isScrolled()) return false;
2557 if (bi->branchCount()==0) return false;
2558 if (bi->depth()==0) return false;
2559 if (bi->toggleScroll())
2567 QString ("%1 ()").arg(u),
2569 QString ("%1 ()").arg(r),
2570 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2572 emitDataHasChanged(bi);
2573 emitSelectionChanged();
2574 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2581 void VymModel::toggleScroll()
2583 BranchItem *bi=(BranchItem*)getSelectedBranch();
2584 if (bi && bi->isBranchLikeType() )
2586 if (bi->isScrolled())
2587 unscrollBranch (bi);
2591 // saveState & reposition are called in above functions
2594 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2596 BranchItem *selbi=getSelectedBranch();
2597 BranchItem *prev=NULL;
2598 BranchItem *cur=selbi;
2601 saveStateChangingPart(
2604 QString ("unscrollChildren ()"),
2605 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2609 if (cur->isScrolled())
2611 cur->toggleScroll();
2612 emitDataHasChanged (cur);
2614 cur=next (cur,prev,selbi);
2621 void VymModel::emitExpandAll()
2623 emit (expandAll() );
2626 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2628 BranchItem *bi=getSelectedBranch();
2632 if (bi->isActiveStandardFlag(name))
2644 QString("%1 (\"%2\")").arg(u).arg(name),
2646 QString("%1 (\"%2\")").arg(r).arg(name),
2647 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2648 bi->toggleStandardFlag (name, master);
2650 emitSelectionChanged();
2654 void VymModel::addFloatImage (const QPixmap &img)
2656 BranchItem *selbi=getSelectedBranch();
2659 ImageItem *ii=createImage (selbi);
2661 ii->setOriginalFilename("No original filename (image added by dropevent)");
2662 QString s=getSelectString(selbi);
2663 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2664 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2666 // FIXME-3 VM needed? scene()->update();
2671 void VymModel::colorBranch (QColor c)
2673 cout << "VM::colBranch\n";
2674 BranchItem *selbi=getSelectedBranch();
2679 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2681 QString ("colorBranch (\"%1\")").arg(c.name()),
2682 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2684 selbi->setHeadingColor(c); // color branch
2689 void VymModel::colorSubtree (QColor c)
2691 BranchItem *selbi=getSelectedBranch();
2694 saveStateChangingPart(
2697 QString ("colorSubtree (\"%1\")").arg(c.name()),
2698 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2700 BranchItem *prev=NULL;
2701 BranchItem *cur=selbi;
2704 cur->setHeadingColor(c); // color links, color children
2705 cur=next (cur,prev,selbi);
2711 QColor VymModel::getCurrentHeadingColor()
2713 BranchItem *selbi=getSelectedBranch();
2714 if (selbi) return selbi->getHeadingColor();
2716 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2722 void VymModel::editURL()
2724 TreeItem *selti=getSelectedItem();
2728 QString text = QInputDialog::getText(
2729 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2730 selti->getURL(), &ok, NULL);
2732 // user entered something and pressed OK
2737 void VymModel::editLocalURL()
2739 TreeItem *selti=getSelectedItem();
2742 QStringList filters;
2743 filters <<"All files (*)";
2744 filters << tr("Text","Filedialog") + " (*.txt)";
2745 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2746 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2747 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2748 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2749 fd->setFilters (filters);
2750 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2751 fd->setDirectory (lastFileDir);
2752 if (! selti->getVymLink().isEmpty() )
2753 fd->selectFile( selti->getURL() );
2756 if ( fd->exec() == QDialog::Accepted )
2758 lastFileDir=QDir (fd->directory().path());
2759 setURL (fd->selectedFile() );
2765 void VymModel::editHeading2URL()
2767 TreeItem *selti=getSelectedItem();
2769 setURL (selti->getHeading());
2772 void VymModel::editBugzilla2URL()
2774 TreeItem *selti=getSelectedItem();
2777 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2782 void VymModel::editFATE2URL()
2784 TreeItem *selti=getSelectedItem();
2787 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2790 "setURL (\""+selti->getURL()+"\")",
2792 "setURL (\""+url+"\")",
2793 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2795 selti->setURL (url);
2796 // FIXME-4 updateActions();
2800 void VymModel::editVymLink()
2802 BranchItem *bi=getSelectedBranch();
2805 QStringList filters;
2806 filters <<"VYM map (*.vym)";
2807 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2808 fd->setFilters (filters);
2809 fd->setCaption(vymName+" - " +tr("Link to another map"));
2810 fd->setDirectory (lastFileDir);
2811 if (! bi->getVymLink().isEmpty() )
2812 fd->selectFile( bi->getVymLink() );
2816 if ( fd->exec() == QDialog::Accepted )
2818 lastFileDir=QDir (fd->directory().path());
2821 "setVymLink (\""+bi->getVymLink()+"\")",
2823 "setVymLink (\""+fd->selectedFile()+"\")",
2824 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2826 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2831 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2833 // Internal function, no saveState needed
2834 TreeItem *selti=getSelectedItem();
2837 selti->setVymLink(s);
2839 emitDataHasChanged (selti);
2840 emitShowSelection();
2844 void VymModel::deleteVymLink()
2846 BranchItem *bi=getSelectedBranch();
2851 "setVymLink (\""+bi->getVymLink()+"\")",
2853 "setVymLink (\"\")",
2854 QString("Unset vymlink of %1").arg(getObjectName(bi))
2856 bi->setVymLink ("" );
2862 QString VymModel::getVymLink()
2864 BranchItem *bi=getSelectedBranch();
2866 return bi->getVymLink();
2872 QStringList VymModel::getVymLinks()
2875 BranchItem *selbi=getSelectedBranch();
2876 BranchItem *cur=selbi;
2877 BranchItem *prev=NULL;
2880 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2881 cur=next (cur,prev,selbi);
2887 void VymModel::followXLink(int i)
2890 BranchItem *selbi=getSelectedBranch();
2893 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2894 if (selbi) select (selbi);
2898 void VymModel::editXLink(int i)
2901 BranchItem *selbi=getSelectedBranch();
2904 XLinkItem *xli=selbi->getXLinkNum(i);
2907 EditXLinkDialog dia;
2909 dia.setSelection(selbi);
2910 if (dia.exec() == QDialog::Accepted)
2912 if (dia.useSettingsGlobal() )
2914 setMapDefXLinkColor (xli->getColor() );
2915 setMapDefXLinkWidth (xli->getWidth() );
2917 if (dia.deleteXLink()) deleteItem (xli);
2927 //////////////////////////////////////////////
2929 //////////////////////////////////////////////
2931 void VymModel::parseAtom(const QString &atom)
2933 TreeItem* selti=getSelectedItem();
2934 BranchItem *selbi=getSelectedBranch();
2940 // Split string s into command and parameters
2941 parser.parseAtom (atom);
2942 QString com=parser.getCommand();
2944 // External commands
2945 /////////////////////////////////////////////////////////////////////
2946 if (com=="addBranch")
2950 parser.setError (Aborted,"Nothing selected");
2951 } else if (! selbi )
2953 parser.setError (Aborted,"Type of selection is not a branch");
2958 if (parser.checkParCount(pl))
2960 if (parser.parCount()==0)
2964 n=parser.parInt (ok,0);
2965 if (ok ) addNewBranch (n);
2969 /////////////////////////////////////////////////////////////////////
2970 } else if (com=="addBranchBefore")
2974 parser.setError (Aborted,"Nothing selected");
2975 } else if (! selbi )
2977 parser.setError (Aborted,"Type of selection is not a branch");
2980 if (parser.parCount()==0)
2982 addNewBranchBefore ();
2985 /////////////////////////////////////////////////////////////////////
2986 } else if (com==QString("addMapCenter"))
2988 if (parser.checkParCount(2))
2990 x=parser.parDouble (ok,0);
2993 y=parser.parDouble (ok,1);
2994 if (ok) addMapCenter (QPointF(x,y));
2997 /////////////////////////////////////////////////////////////////////
2998 } else if (com==QString("addMapReplace"))
3002 parser.setError (Aborted,"Nothing selected");
3003 } else if (! selbi )
3005 parser.setError (Aborted,"Type of selection is not a branch");
3006 } else if (parser.checkParCount(1))
3008 //s=parser.parString (ok,0); // selection
3009 t=parser.parString (ok,0); // path to map
3010 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3011 addMapReplaceInt(getSelectString(selbi),t);
3013 /////////////////////////////////////////////////////////////////////
3014 } else if (com==QString("addMapInsert"))
3016 if (parser.parCount()==2)
3021 parser.setError (Aborted,"Nothing selected");
3022 } else if (! selbi )
3024 parser.setError (Aborted,"Type of selection is not a branch");
3027 t=parser.parString (ok,0); // path to map
3028 n=parser.parInt(ok,1); // position
3029 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3030 addMapInsertInt(t,n);
3032 } else if (parser.parCount()==1)
3034 t=parser.parString (ok,0); // path to map
3035 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3038 parser.setError (Aborted,"Wrong number of parameters");
3039 /////////////////////////////////////////////////////////////////////
3040 } else if (com==QString("addXLink"))
3042 if (parser.parCount()>1)
3044 s=parser.parString (ok,0); // begin
3045 t=parser.parString (ok,1); // end
3046 BranchItem *begin=(BranchItem*)findBySelectString(s);
3047 BranchItem *end=(BranchItem*)findBySelectString(t);
3050 if (begin->isBranchLikeType() && end->isBranchLikeType())
3052 XLinkItem *xl=createXLink (begin,true);
3058 parser.setError (Aborted,"Failed to create xLink");
3061 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3064 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3066 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3067 /////////////////////////////////////////////////////////////////////
3068 } else if (com=="clearFlags")
3072 parser.setError (Aborted,"Nothing selected");
3073 } else if (! selbi )
3075 parser.setError (Aborted,"Type of selection is not a branch");
3076 } else if (parser.checkParCount(0))
3078 selbi->deactivateAllStandardFlags();
3080 /////////////////////////////////////////////////////////////////////
3081 } else if (com=="colorBranch")
3085 parser.setError (Aborted,"Nothing selected");
3086 } else if (! selbi )
3088 parser.setError (Aborted,"Type of selection is not a branch");
3089 } else if (parser.checkParCount(1))
3091 QColor c=parser.parColor (ok,0);
3092 if (ok) colorBranch (c);
3094 /////////////////////////////////////////////////////////////////////
3095 } else if (com=="colorSubtree")
3099 parser.setError (Aborted,"Nothing selected");
3100 } else if (! selbi )
3102 parser.setError (Aborted,"Type of selection is not a branch");
3103 } else if (parser.checkParCount(1))
3105 QColor c=parser.parColor (ok,0);
3106 if (ok) colorSubtree (c);
3108 /////////////////////////////////////////////////////////////////////
3109 } else if (com=="copy")
3113 parser.setError (Aborted,"Nothing selected");
3114 } else if ( selectionType()!=TreeItem::Branch &&
3115 selectionType()!=TreeItem::MapCenter &&
3116 selectionType()!=TreeItem::Image )
3118 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3119 } else if (parser.checkParCount(0))
3123 /////////////////////////////////////////////////////////////////////
3124 } else if (com=="cut")
3128 parser.setError (Aborted,"Nothing selected");
3129 } else if ( selectionType()!=TreeItem::Branch &&
3130 selectionType()!=TreeItem::MapCenter &&
3131 selectionType()!=TreeItem::Image )
3133 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3134 } else if (parser.checkParCount(0))
3138 /////////////////////////////////////////////////////////////////////
3139 } else if (com=="delete")
3143 parser.setError (Aborted,"Nothing selected");
3145 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3147 parser.setError (Aborted,"Type of selection is wrong.");
3150 else if (parser.checkParCount(0))
3154 /////////////////////////////////////////////////////////////////////
3155 } else if (com=="deleteKeepChildren")
3159 parser.setError (Aborted,"Nothing selected");
3160 } else if (! selbi )
3162 parser.setError (Aborted,"Type of selection is not a branch");
3163 } else if (parser.checkParCount(0))
3165 deleteKeepChildren();
3167 /////////////////////////////////////////////////////////////////////
3168 } else if (com=="deleteChildren")
3172 parser.setError (Aborted,"Nothing selected");
3175 parser.setError (Aborted,"Type of selection is not a branch");
3176 } else if (parser.checkParCount(0))
3180 /////////////////////////////////////////////////////////////////////
3181 } else if (com=="exportASCII")
3185 if (parser.parCount()>=1)
3186 // Hey, we even have a filename
3187 fname=parser.parString(ok,0);
3190 parser.setError (Aborted,"Could not read filename");
3193 exportASCII (fname,false);
3195 /////////////////////////////////////////////////////////////////////
3196 } else if (com=="exportImage")
3200 if (parser.parCount()>=2)
3201 // Hey, we even have a filename
3202 fname=parser.parString(ok,0);
3205 parser.setError (Aborted,"Could not read filename");
3208 QString format="PNG";
3209 if (parser.parCount()>=2)
3211 format=parser.parString(ok,1);
3213 exportImage (fname,false,format);
3215 /////////////////////////////////////////////////////////////////////
3216 } else if (com=="exportXHTML")
3220 if (parser.parCount()>=2)
3221 // Hey, we even have a filename
3222 fname=parser.parString(ok,1);
3225 parser.setError (Aborted,"Could not read filename");
3228 exportXHTML (fname,false);
3230 /////////////////////////////////////////////////////////////////////
3231 } else if (com=="exportXML")
3235 if (parser.parCount()>=2)
3236 // Hey, we even have a filename
3237 fname=parser.parString(ok,1);
3240 parser.setError (Aborted,"Could not read filename");
3243 exportXML (fname,false);
3245 /////////////////////////////////////////////////////////////////////
3246 } else if (com=="importDir")
3250 parser.setError (Aborted,"Nothing selected");
3251 } else if (! selbi )
3253 parser.setError (Aborted,"Type of selection is not a branch");
3254 } else if (parser.checkParCount(1))
3256 s=parser.parString(ok,0);
3257 if (ok) importDirInt(s);
3259 /////////////////////////////////////////////////////////////////////
3260 } else if (com=="relinkTo")
3264 parser.setError (Aborted,"Nothing selected");
3267 if (parser.checkParCount(4))
3269 // 0 selectstring of parent
3270 // 1 num in parent (for branches)
3271 // 2,3 x,y of mainbranch or mapcenter
3272 s=parser.parString(ok,0);
3273 TreeItem *dst=findBySelectString (s);
3276 if (dst->getType()==TreeItem::Branch)
3278 // Get number in parent
3279 n=parser.parInt (ok,1);
3282 relinkBranch (selbi,(BranchItem*)dst,n);
3283 emitSelectionChanged();
3285 } else if (dst->getType()==TreeItem::MapCenter)
3287 relinkBranch (selbi,(BranchItem*)dst);
3288 // Get coordinates of mainbranch
3289 x=parser.parDouble(ok,2);
3292 y=parser.parDouble(ok,3);
3295 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3296 emitSelectionChanged();
3302 } else if ( selti->getType() == TreeItem::Image)
3304 if (parser.checkParCount(1))
3306 // 0 selectstring of parent
3307 s=parser.parString(ok,0);
3308 TreeItem *dst=findBySelectString (s);
3311 if (dst->isBranchLikeType())
3312 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3314 parser.setError (Aborted,"Destination is not a branch");
3317 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3318 /////////////////////////////////////////////////////////////////////
3319 } else if (com=="loadImage")
3323 parser.setError (Aborted,"Nothing selected");
3324 } else if (! selbi )
3326 parser.setError (Aborted,"Type of selection is not a branch");
3327 } else if (parser.checkParCount(1))
3329 s=parser.parString(ok,0);
3330 if (ok) loadFloatImageInt (selbi,s);
3332 /////////////////////////////////////////////////////////////////////
3333 } else if (com=="moveUp")
3337 parser.setError (Aborted,"Nothing selected");
3338 } else if (! selbi )
3340 parser.setError (Aborted,"Type of selection is not a branch");
3341 } else if (parser.checkParCount(0))
3345 /////////////////////////////////////////////////////////////////////
3346 } else if (com=="moveDown")
3350 parser.setError (Aborted,"Nothing selected");
3351 } else if (! selbi )
3353 parser.setError (Aborted,"Type of selection is not a branch");
3354 } else if (parser.checkParCount(0))
3358 /////////////////////////////////////////////////////////////////////
3359 } else if (com=="move")
3363 parser.setError (Aborted,"Nothing selected");
3364 } else if ( selectionType()!=TreeItem::Branch &&
3365 selectionType()!=TreeItem::MapCenter &&
3366 selectionType()!=TreeItem::Image )
3368 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3369 } else if (parser.checkParCount(2))
3371 x=parser.parDouble (ok,0);
3374 y=parser.parDouble (ok,1);
3378 /////////////////////////////////////////////////////////////////////
3379 } else if (com=="moveRel")
3383 parser.setError (Aborted,"Nothing selected");
3384 } else if ( selectionType()!=TreeItem::Branch &&
3385 selectionType()!=TreeItem::MapCenter &&
3386 selectionType()!=TreeItem::Image )
3388 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3389 } else if (parser.checkParCount(2))
3391 x=parser.parDouble (ok,0);
3394 y=parser.parDouble (ok,1);
3395 if (ok) moveRel (x,y);
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="nop")
3401 /////////////////////////////////////////////////////////////////////
3402 } else if (com=="paste")
3406 parser.setError (Aborted,"Nothing selected");
3407 } else if (! selbi )
3409 parser.setError (Aborted,"Type of selection is not a branch");
3410 } else if (parser.checkParCount(1))
3412 n=parser.parInt (ok,0);
3413 if (ok) pasteNoSave(n);
3415 /////////////////////////////////////////////////////////////////////
3416 } else if (com=="qa")
3420 parser.setError (Aborted,"Nothing selected");
3421 } else if (! selbi )
3423 parser.setError (Aborted,"Type of selection is not a branch");
3424 } else if (parser.checkParCount(4))
3427 c=parser.parString (ok,0);
3430 parser.setError (Aborted,"No comment given");
3433 s=parser.parString (ok,1);
3436 parser.setError (Aborted,"First parameter is not a string");
3439 t=parser.parString (ok,2);
3442 parser.setError (Aborted,"Condition is not a string");
3445 u=parser.parString (ok,3);
3448 parser.setError (Aborted,"Third parameter is not a string");
3453 parser.setError (Aborted,"Unknown type: "+s);
3458 parser.setError (Aborted,"Unknown operator: "+t);
3463 parser.setError (Aborted,"Type of selection is not a branch");
3466 if (selbi->getHeading() == u)
3468 cout << "PASSED: " << qPrintable (c) << endl;
3471 cout << "FAILED: " << qPrintable (c) << endl;
3481 /////////////////////////////////////////////////////////////////////
3482 } else if (com=="saveImage")
3484 ImageItem *ii=getSelectedImage();
3487 parser.setError (Aborted,"No image selected");
3488 } else if (parser.checkParCount(2))
3490 s=parser.parString(ok,0);
3493 t=parser.parString(ok,1);
3494 if (ok) saveFloatImageInt (ii,t,s);
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="scroll")
3502 parser.setError (Aborted,"Nothing selected");
3503 } else if (! selbi )
3505 parser.setError (Aborted,"Type of selection is not a branch");
3506 } else if (parser.checkParCount(0))
3508 if (!scrollBranch (selbi))
3509 parser.setError (Aborted,"Could not scroll branch");
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="select")
3514 if (parser.checkParCount(1))
3516 s=parser.parString(ok,0);
3519 /////////////////////////////////////////////////////////////////////
3520 } else if (com=="selectLastBranch")
3524 parser.setError (Aborted,"Nothing selected");
3525 } else if (! selbi )
3527 parser.setError (Aborted,"Type of selection is not a branch");
3528 } else if (parser.checkParCount(0))
3530 BranchItem *bi=selbi->getLastBranch();
3532 parser.setError (Aborted,"Could not select last branch");
3533 select (bi); // FIXME-3 was selectInt
3536 /////////////////////////////////////////////////////////////////////
3537 } else /* FIXME-2 if (com=="selectLastImage")
3541 parser.setError (Aborted,"Nothing selected");
3542 } else if (! selbi )
3544 parser.setError (Aborted,"Type of selection is not a branch");
3545 } else if (parser.checkParCount(0))
3547 FloatImageObj *fio=selb->getLastFloatImage();
3549 parser.setError (Aborted,"Could not select last image");
3550 select (fio); // FIXME-3 was selectInt
3553 /////////////////////////////////////////////////////////////////////
3554 } else */ if (com=="selectLatestAdded")
3556 if (!latestAddedItem)
3558 parser.setError (Aborted,"No latest added object");
3561 if (!select (latestAddedItem))
3562 parser.setError (Aborted,"Could not select latest added object ");
3564 /////////////////////////////////////////////////////////////////////
3565 } else if (com=="setFrameType")
3567 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3569 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3571 else if (parser.checkParCount(1))
3573 s=parser.parString(ok,0);
3574 if (ok) setFrameType (s);
3576 /////////////////////////////////////////////////////////////////////
3577 } else if (com=="setFramePenColor")
3579 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3581 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3583 else if (parser.checkParCount(1))
3585 QColor c=parser.parColor(ok,0);
3586 if (ok) setFramePenColor (c);
3588 /////////////////////////////////////////////////////////////////////
3589 } else if (com=="setFrameBrushColor")
3591 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3593 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3595 else if (parser.checkParCount(1))
3597 QColor c=parser.parColor(ok,0);
3598 if (ok) setFrameBrushColor (c);
3600 /////////////////////////////////////////////////////////////////////
3601 } else if (com=="setFramePadding")
3603 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3605 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3607 else if (parser.checkParCount(1))
3609 n=parser.parInt(ok,0);
3610 if (ok) setFramePadding(n);
3612 /////////////////////////////////////////////////////////////////////
3613 } else if (com=="setFrameBorderWidth")
3615 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3617 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3619 else if (parser.checkParCount(1))
3621 n=parser.parInt(ok,0);
3622 if (ok) setFrameBorderWidth (n);
3624 /////////////////////////////////////////////////////////////////////
3625 } else if (com=="setMapAuthor")
3627 if (parser.checkParCount(1))
3629 s=parser.parString(ok,0);
3630 if (ok) setAuthor (s);
3632 /////////////////////////////////////////////////////////////////////
3633 } else if (com=="setMapComment")
3635 if (parser.checkParCount(1))
3637 s=parser.parString(ok,0);
3638 if (ok) setComment(s);
3640 /////////////////////////////////////////////////////////////////////
3641 } else if (com=="setMapBackgroundColor")
3645 parser.setError (Aborted,"Nothing selected");
3646 } else if (! selbi )
3648 parser.setError (Aborted,"Type of selection is not a branch");
3649 } else if (parser.checkParCount(1))
3651 QColor c=parser.parColor (ok,0);
3652 if (ok) setMapBackgroundColor (c);
3654 /////////////////////////////////////////////////////////////////////
3655 } else if (com=="setMapDefLinkColor")
3659 parser.setError (Aborted,"Nothing selected");
3660 } else if (! selbi )
3662 parser.setError (Aborted,"Type of selection is not a branch");
3663 } else if (parser.checkParCount(1))
3665 QColor c=parser.parColor (ok,0);
3666 if (ok) setMapDefLinkColor (c);
3668 /////////////////////////////////////////////////////////////////////
3669 } else if (com=="setMapLinkStyle")
3671 if (parser.checkParCount(1))
3673 s=parser.parString (ok,0);
3674 if (ok) setMapLinkStyle(s);
3676 /////////////////////////////////////////////////////////////////////
3677 } else if (com=="setHeading")
3681 parser.setError (Aborted,"Nothing selected");
3682 } else if (! selbi )
3684 parser.setError (Aborted,"Type of selection is not a branch");
3685 } else if (parser.checkParCount(1))
3687 s=parser.parString (ok,0);
3691 /////////////////////////////////////////////////////////////////////
3692 } else if (com=="setHideExport")
3696 parser.setError (Aborted,"Nothing selected");
3697 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3699 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3700 } else if (parser.checkParCount(1))
3702 b=parser.parBool(ok,0);
3703 if (ok) setHideExport (b);
3705 /////////////////////////////////////////////////////////////////////
3706 } else if (com=="setIncludeImagesHorizontally")
3710 parser.setError (Aborted,"Nothing selected");
3713 parser.setError (Aborted,"Type of selection is not a branch");
3714 } else if (parser.checkParCount(1))
3716 b=parser.parBool(ok,0);
3717 if (ok) setIncludeImagesHor(b);
3719 /////////////////////////////////////////////////////////////////////
3720 } else if (com=="setIncludeImagesVertically")
3724 parser.setError (Aborted,"Nothing selected");
3727 parser.setError (Aborted,"Type of selection is not a branch");
3728 } else if (parser.checkParCount(1))
3730 b=parser.parBool(ok,0);
3731 if (ok) setIncludeImagesVer(b);
3733 /////////////////////////////////////////////////////////////////////
3734 } else if (com=="setHideLinkUnselected")
3738 parser.setError (Aborted,"Nothing selected");
3739 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3741 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3742 } else if (parser.checkParCount(1))
3744 b=parser.parBool(ok,0);
3745 if (ok) setHideLinkUnselected(b);
3747 /////////////////////////////////////////////////////////////////////
3748 } else if (com=="setSelectionColor")
3750 if (parser.checkParCount(1))
3752 QColor c=parser.parColor (ok,0);
3753 if (ok) setSelectionColorInt (c);
3755 /////////////////////////////////////////////////////////////////////
3756 } else if (com=="setURL")
3760 parser.setError (Aborted,"Nothing selected");
3761 } else if (! selbi )
3763 parser.setError (Aborted,"Type of selection is not a branch");
3764 } else if (parser.checkParCount(1))
3766 s=parser.parString (ok,0);
3769 /////////////////////////////////////////////////////////////////////
3770 } else if (com=="setVymLink")
3774 parser.setError (Aborted,"Nothing selected");
3775 } else if (! selbi )
3777 parser.setError (Aborted,"Type of selection is not a branch");
3778 } else if (parser.checkParCount(1))
3780 s=parser.parString (ok,0);
3781 if (ok) setVymLink(s);
3784 /////////////////////////////////////////////////////////////////////
3785 else if (com=="setFlag")
3789 parser.setError (Aborted,"Nothing selected");
3790 } else if (! selbi )
3792 parser.setError (Aborted,"Type of selection is not a branch");
3793 } else if (parser.checkParCount(1))
3795 s=parser.parString(ok,0);
3797 selbi->activateStandardFlag(s);
3799 /////////////////////////////////////////////////////////////////////
3800 } else /* FIXME-2 if (com=="setFrameType")
3804 parser.setError (Aborted,"Nothing selected");
3807 parser.setError (Aborted,"Type of selection is not a branch");
3808 } else if (parser.checkParCount(1))
3810 s=parser.parString(ok,0);
3814 /////////////////////////////////////////////////////////////////////
3815 } else*/ if (com=="sortChildren")
3819 parser.setError (Aborted,"Nothing selected");
3820 } else if (! selbi )
3822 parser.setError (Aborted,"Type of selection is not a branch");
3823 } else if (parser.checkParCount(0))
3827 /////////////////////////////////////////////////////////////////////
3828 } else if (com=="toggleFlag")
3832 parser.setError (Aborted,"Nothing selected");
3833 } else if (! selbi )
3835 parser.setError (Aborted,"Type of selection is not a branch");
3836 } else if (parser.checkParCount(1))
3838 s=parser.parString(ok,0);
3840 selbi->toggleStandardFlag(s);
3842 /////////////////////////////////////////////////////////////////////
3843 } else if (com=="unscroll")
3847 parser.setError (Aborted,"Nothing selected");
3848 } else if (! selbi )
3850 parser.setError (Aborted,"Type of selection is not a branch");
3851 } else if (parser.checkParCount(0))
3853 if (!unscrollBranch (selbi))
3854 parser.setError (Aborted,"Could not unscroll branch");
3856 /////////////////////////////////////////////////////////////////////
3857 } else if (com=="unscrollChildren")
3861 parser.setError (Aborted,"Nothing selected");
3862 } else if (! selbi )
3864 parser.setError (Aborted,"Type of selection is not a branch");
3865 } else if (parser.checkParCount(0))
3867 unscrollChildren ();
3869 /////////////////////////////////////////////////////////////////////
3870 } else if (com=="unsetFlag")
3874 parser.setError (Aborted,"Nothing selected");
3875 } else if (! selbi )
3877 parser.setError (Aborted,"Type of selection is not a branch");
3878 } else if (parser.checkParCount(1))
3880 s=parser.parString(ok,0);
3882 selbi->deactivateStandardFlag(s);
3885 parser.setError (Aborted,"Unknown command");
3888 if (parser.errorLevel()==NoError)
3890 // setChanged(); FIXME-2 should not be called e.g. for export?!
3895 // TODO Error handling
3896 qWarning("VymModel::parseAtom: Error!");
3897 qWarning(parser.errorMessage());
3901 void VymModel::runScript (QString script)
3903 parser.setScript (script);
3905 while (parser.next() )
3906 parseAtom(parser.getAtom());
3909 void VymModel::setExportMode (bool b)
3911 // should be called before and after exports
3912 // depending on the settings
3913 if (b && settings.value("/export/useHideExport","true")=="true")
3914 setHideTmpMode (TreeItem::HideExport);
3916 setHideTmpMode (TreeItem::HideNone);
3919 void VymModel::exportImage(QString fname, bool askName, QString format)
3923 fname=getMapName()+".png";
3930 QFileDialog *fd=new QFileDialog (NULL);
3931 fd->setCaption (tr("Export map as image"));
3932 fd->setDirectory (lastImageDir);
3933 fd->setFileMode(QFileDialog::AnyFile);
3934 fd->setFilters (imageIO.getFilters() );
3937 fl=fd->selectedFiles();
3939 format=imageIO.getType(fd->selectedFilter());
3943 setExportMode (true);
3944 QPixmap pix (mapEditor->getPixmap());
3945 pix.save(fname, format);
3946 setExportMode (false);
3950 void VymModel::exportXML(QString dir, bool askForName)
3954 dir=browseDirectory(NULL,tr("Export XML to directory"));
3955 if (dir =="" && !reallyWriteDirectory(dir) )
3959 // Hide stuff during export, if settings want this
3960 setExportMode (true);
3962 // Create subdirectories
3965 // write to directory //FIXME-4 check totalBBox here...
3966 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3969 file.setName ( dir + "/"+mapName+".xml");
3970 if ( !file.open( QIODevice::WriteOnly ) )
3972 // This should neverever happen
3973 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3977 // Write it finally, and write in UTF8, no matter what
3978 QTextStream ts( &file );
3979 ts.setEncoding (QTextStream::UnicodeUTF8);
3983 // Now write image, too
3984 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3986 setExportMode (false);
3989 void VymModel::exportASCII(QString fname,bool askName)
3994 ex.setFile (mapName+".txt");
4000 //ex.addFilter ("TXT (*.txt)");
4001 ex.setDir(lastImageDir);
4002 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4007 setExportMode(true);
4009 setExportMode(false);
4013 void VymModel::exportXHTML (const QString &dir, bool askForName)
4015 ExportXHTMLDialog dia(NULL);
4016 dia.setFilePath (filePath );
4017 dia.setMapName (mapName );
4019 if (dir!="") dia.setDir (dir);
4025 if (dia.exec()!=QDialog::Accepted)
4029 QDir d (dia.getDir());
4030 // Check, if warnings should be used before overwriting
4031 // the output directory
4032 if (d.exists() && d.count()>0)
4035 warn.showCancelButton (true);
4036 warn.setText(QString(
4037 "The directory %1 is not empty.\n"
4038 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4039 warn.setCaption("Warning: Directory not empty");
4040 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4042 if (warn.exec()!=QDialog::Accepted) ok=false;
4049 exportXML (dia.getDir(),false );
4050 dia.doExport(mapName );
4051 //if (dia.hasChanged()) setChanged();
4055 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4060 if (ex.setConfigFile(cf))
4062 setExportMode (true);
4063 ex.exportPresentation();
4064 setExportMode (false);
4071 //////////////////////////////////////////////
4073 //////////////////////////////////////////////
4075 void VymModel::registerEditor(QWidget *me)
4077 mapEditor=(MapEditor*)me;
4080 void VymModel::unregisterEditor(QWidget *)
4085 void VymModel::setContextPos(QPointF p)
4090 void VymModel::unsetContextPos()
4092 contextPos=QPointF();
4095 void VymModel::updateNoteFlag()
4098 TreeItem *selti=getSelectedItem();
4101 if (textEditor->isEmpty())
4104 selti->setNote (textEditor->getText());
4105 emitDataHasChanged(selti);
4106 emitSelectionChanged();
4111 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4113 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4114 if (blockReposition) return;
4116 for (int i=0;i<rootItem->branchCount(); i++)
4117 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4118 //emitSelectionChanged();
4122 void VymModel::setMapLinkStyle (const QString & s)
4127 case LinkableMapObj::Line :
4130 case LinkableMapObj::Parabel:
4131 snow="StyleParabel";
4133 case LinkableMapObj::PolyLine:
4134 snow="StylePolyLine";
4136 case LinkableMapObj::PolyParabel:
4137 snow="StylePolyParabel";
4140 snow="UndefinedStyle";
4145 QString("setMapLinkStyle (\"%1\")").arg(s),
4146 QString("setMapLinkStyle (\"%1\")").arg(snow),
4147 QString("Set map link style (\"%1\")").arg(s)
4151 linkstyle=LinkableMapObj::Line;
4152 else if (s=="StyleParabel")
4153 linkstyle=LinkableMapObj::Parabel;
4154 else if (s=="StylePolyLine")
4155 linkstyle=LinkableMapObj::PolyLine;
4156 else if (s=="StylePolyParabel")
4157 linkstyle=LinkableMapObj::PolyParabel;
4159 linkstyle=LinkableMapObj::UndefinedStyle;
4161 BranchItem *cur=NULL;
4162 BranchItem *prev=NULL;
4167 bo=(BranchObj*)(cur->getLMO() );
4168 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4174 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4179 void VymModel::setMapDefLinkColor(QColor col)
4181 if ( !col.isValid() ) return;
4183 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4184 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4185 QString("Set map link color to %1").arg(col.name())
4189 BranchItem *cur=NULL;
4190 BranchItem *prev=NULL;
4195 bo=(BranchObj*)(cur->getLMO() );
4202 void VymModel::setMapLinkColorHintInt()
4204 // called from setMapLinkColorHint(lch) or at end of parse
4205 BranchItem *cur=NULL;
4206 BranchItem *prev=NULL;
4211 bo=(BranchObj*)(cur->getLMO() );
4217 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4220 setMapLinkColorHintInt();
4223 void VymModel::toggleMapLinkColorHint()
4225 if (linkcolorhint==LinkableMapObj::HeadingColor)
4226 linkcolorhint=LinkableMapObj::DefaultColor;
4228 linkcolorhint=LinkableMapObj::HeadingColor;
4229 BranchItem *cur=NULL;
4230 BranchItem *prev=NULL;
4235 bo=(BranchObj*)(cur->getLMO() );
4241 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4242 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4244 Q3FileDialog *fd=new Q3FileDialog( NULL);
4245 fd->setMode (Q3FileDialog::ExistingFile);
4246 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4247 ImagePreview *p =new ImagePreview (fd);
4248 fd->setContentsPreviewEnabled( TRUE );
4249 fd->setContentsPreview( p, p );
4250 fd->setPreviewMode( Q3FileDialog::Contents );
4251 fd->setCaption(vymName+" - " +tr("Load background image"));
4252 fd->setDir (lastImageDir);
4255 if ( fd->exec() == QDialog::Accepted )
4257 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4258 lastImageDir=QDir (fd->dirPath());
4259 setMapBackgroundImage (fd->selectedFile());
4263 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4265 QColor oldcol=mapScene->backgroundBrush().color();
4269 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4271 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4272 QString("Set background color of map to %1").arg(col.name()));
4275 brush.setTextureImage (QPixmap (fn));
4276 mapScene->setBackgroundBrush(brush);
4279 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4281 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4282 if ( !col.isValid() ) return;
4283 setMapBackgroundColor( col );
4287 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4289 QColor oldcol=mapScene->backgroundBrush().color();
4291 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4292 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4293 QString("Set background color of map to %1").arg(col.name()));
4294 mapScene->setBackgroundBrush(col);
4297 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4299 return mapScene->backgroundBrush().color();
4303 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4305 return linkcolorhint;
4308 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4310 return defLinkColor;
4313 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4318 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4320 return defXLinkColor;
4323 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4328 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4330 return defXLinkWidth;
4333 void VymModel::move(const double &x, const double &y)
4336 MapItem *seli = (MapItem*)getSelectedItem();
4337 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4339 LinkableMapObj *lmo=seli->getLMO();
4342 QPointF ap(lmo->getAbsPos());
4346 QString ps=qpointFToString(ap);
4347 QString s=getSelectString(seli);
4350 s, "move "+qpointFToString(to),
4351 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4354 emitSelectionChanged();
4360 void VymModel::moveRel (const double &x, const double &y)
4363 MapItem *seli = (MapItem*)getSelectedItem();
4364 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4366 LinkableMapObj *lmo=seli->getLMO();
4369 QPointF rp(lmo->getRelPos());
4373 QString ps=qpointFToString (lmo->getRelPos());
4374 QString s=getSelectString(seli);
4377 s, "moveRel "+qpointFToString(to),
4378 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4379 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4381 lmo->updateLinkGeometry();
4382 emitSelectionChanged();
4389 void VymModel::animate()
4391 animationTimer->stop();
4394 while (i<animObjList.size() )
4396 bo=(BranchObj*)animObjList.at(i);
4401 animObjList.removeAt(i);
4408 QItemSelection sel=selModel->selection();
4409 emit (selectionChanged(sel,sel));
4412 if (!animObjList.isEmpty()) animationTimer->start();
4416 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4418 if (start==dest) return;
4419 if (bo && bo->getTreeItem()->depth()>0)
4422 ap.setStart (start);
4424 ap.setTicks (animationTicks);
4425 ap.setAnimated (true);
4426 bo->setAnimation (ap);
4427 animObjList.append( bo );
4428 animationTimer->setSingleShot (true);
4429 animationTimer->start(animationInterval);
4433 void VymModel::stopAnimation (MapObj *mo)
4435 int i=animObjList.indexOf(mo);
4437 animObjList.removeAt (i);
4440 void VymModel::sendSelection()
4442 if (netstate!=Server) return;
4443 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4446 void VymModel::newServer()
4450 tcpServer = new QTcpServer(this);
4451 if (!tcpServer->listen(QHostAddress::Any,port)) {
4452 QMessageBox::critical(NULL, "vym server",
4453 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4454 //FIXME-3 needed? we are no widget any longer... close();
4457 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4459 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4462 void VymModel::connectToServer()
4465 server="salam.suse.de";
4467 clientSocket = new QTcpSocket (this);
4468 clientSocket->abort();
4469 clientSocket->connectToHost(server ,port);
4470 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4471 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4472 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4474 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4479 void VymModel::newClient()
4481 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4482 connect(newClient, SIGNAL(disconnected()),
4483 newClient, SLOT(deleteLater()));
4485 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4487 clientList.append (newClient);
4491 void VymModel::sendData(const QString &s)
4493 if (clientList.size()==0) return;
4495 // Create bytearray to send
4497 QDataStream out(&block, QIODevice::WriteOnly);
4498 out.setVersion(QDataStream::Qt_4_0);
4500 // Reserve some space for blocksize
4503 // Write sendCounter
4504 out << sendCounter++;
4509 // Go back and write blocksize so far
4510 out.device()->seek(0);
4511 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4515 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4517 for (int i=0; i<clientList.size(); ++i)
4519 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4520 clientList.at(i)->write (block);
4524 void VymModel::readData ()
4526 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4529 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4533 QDataStream in(clientSocket);
4534 in.setVersion(QDataStream::Qt_4_0);
4542 cout << " t="<<qPrintable (t)<<endl;
4548 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4550 switch (socketError) {
4551 case QAbstractSocket::RemoteHostClosedError:
4553 case QAbstractSocket::HostNotFoundError:
4554 QMessageBox::information(NULL, vymName +" Network client",
4555 "The host was not found. Please check the "
4556 "host name and port settings.");
4558 case QAbstractSocket::ConnectionRefusedError:
4559 QMessageBox::information(NULL, vymName + " Network client",
4560 "The connection was refused by the peer. "
4561 "Make sure the fortune server is running, "
4562 "and check that the host name and port "
4563 "settings are correct.");
4566 QMessageBox::information(NULL, vymName + " Network client",
4567 QString("The following error occurred: %1.")
4568 .arg(clientSocket->errorString()));
4572 /* FIXME-3 Playing with DBUS...
4573 QDBusVariant VymModel::query (const QString &query)
4575 TreeItem *selti=getSelectedItem();
4577 return QDBusVariant (selti->getHeading());
4579 return QDBusVariant ("Nothing selected.");
4583 void VymModel::testslot() //FIXME-3
4585 cout << "VM::testslot called\n";
4588 void VymModel::selectMapSelectionColor()
4590 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4591 setSelectionColor (col);
4594 void VymModel::setSelectionColorInt (QColor col)
4596 if ( !col.isValid() ) return;
4598 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4599 QString("setSelectionColor (%1)").arg(col.name()),
4600 QString("Set color of selection box to %1").arg(col.name())
4603 mapEditor->setSelectionColor (col);
4606 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4608 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4609 //FIXME-3 emitShowSelection();
4613 void VymModel::emitSelectionChanged()
4615 QItemSelection newsel=selModel->selection();
4616 emitSelectionChanged (newsel);
4619 void VymModel::setSelectionColor(QColor col)
4621 if ( !col.isValid() ) return;
4623 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4624 QString("setSelectionColor (%1)").arg(col.name()),
4625 QString("Set color of selection box to %1").arg(col.name())
4627 setSelectionColorInt (col);
4630 QColor VymModel::getSelectionColor()
4632 return mapEditor->getSelectionColor();
4635 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4638 for (int i=0;i<rootItem->childCount();i++)
4639 rootItem->child(i)->setHideTmp (mode);
4641 // FIXME-3 needed? scene()->update();
4644 //////////////////////////////////////////////
4645 // Selection related
4646 //////////////////////////////////////////////
4648 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4653 QItemSelectionModel* VymModel::getSelectionModel()
4658 void VymModel::setSelectionBlocked (bool b)
4663 bool VymModel::isSelectionBlocked()
4665 return selectionBlocked;
4668 bool VymModel::select ()
4670 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4673 bool VymModel::select (const QString &s)
4680 TreeItem *ti=findBySelectString(s);
4681 if (ti) return select (index(ti));
4685 bool VymModel::select (LinkableMapObj *lmo)
4687 QItemSelection oldsel=selModel->selection();
4690 return select (index (lmo->getTreeItem()) );
4695 bool VymModel::select (TreeItem *ti)
4697 if (ti) return select (index(ti));
4701 bool VymModel::select (const QModelIndex &index)
4703 if (index.isValid() )
4705 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4706 BranchItem *bi=getSelectedBranch();
4707 if (bi) bi->setLastSelectedBranch();
4713 void VymModel::unselect()
4715 lastSelectString=getSelectString();
4716 selModel->clearSelection();
4719 bool VymModel::reselect()
4721 return select (lastSelectString);
4724 void VymModel::emitShowSelection()
4726 if (!blockReposition)
4727 emit (showSelection() );
4730 void VymModel::emitNoteHasChanged (TreeItem *ti)
4732 QModelIndex ix=index(ti);
4733 emit (noteHasChanged (ix) );
4736 void VymModel::emitDataHasChanged (TreeItem *ti)
4738 QModelIndex ix=index(ti);
4739 emit (dataChanged (ix,ix) );
4743 bool VymModel::selectFirstBranch()
4745 TreeItem *ti=getSelectedBranch();
4748 TreeItem *par=ti->parent();
4751 TreeItem *ti2=par->getFirstBranch();
4752 if (ti2) return select(ti2);
4758 bool VymModel::selectLastBranch()
4760 TreeItem *ti=getSelectedBranch();
4763 TreeItem *par=ti->parent();
4766 TreeItem *ti2=par->getLastBranch();
4767 if (ti2) return select(ti2);
4773 bool VymModel::selectLastSelectedBranch()
4775 BranchItem *bi=getSelectedBranch();
4778 bi=bi->getLastSelectedBranch();
4779 if (bi) return select (bi);
4784 bool VymModel::selectParent()
4786 TreeItem *ti=getSelectedItem();
4797 TreeItem::Type VymModel::selectionType()
4799 QModelIndexList list=selModel->selectedIndexes();
4800 if (list.isEmpty()) return TreeItem::Undefined;
4801 TreeItem *ti = getItem (list.first() );
4802 return ti->getType();
4806 LinkableMapObj* VymModel::getSelectedLMO()
4808 QModelIndexList list=selModel->selectedIndexes();
4809 if (!list.isEmpty() )
4811 TreeItem *ti = getItem (list.first() );
4812 TreeItem::Type type=ti->getType();
4813 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4814 return ((MapItem*)ti)->getLMO();
4819 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4821 TreeItem *ti = getSelectedBranch();
4823 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4828 BranchItem* VymModel::getSelectedBranch()
4830 QModelIndexList list=selModel->selectedIndexes();
4831 if (!list.isEmpty() )
4833 TreeItem *ti = getItem (list.first() );
4834 TreeItem::Type type=ti->getType();
4835 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4836 return (BranchItem*)ti;
4841 ImageItem* VymModel::getSelectedImage()
4843 QModelIndexList list=selModel->selectedIndexes();
4844 if (!list.isEmpty())
4846 TreeItem *ti=getItem (list.first());
4847 if (ti && ti->getType()==TreeItem::Image)
4848 return (ImageItem*)ti;
4853 AttributeItem* VymModel::getSelectedAttribute()
4855 QModelIndexList list=selModel->selectedIndexes();
4856 if (!list.isEmpty() )
4858 TreeItem *ti = getItem (list.first() );
4859 TreeItem::Type type=ti->getType();
4860 if (type ==TreeItem::Attribute)
4861 return (AttributeItem*)ti;
4866 TreeItem* VymModel::getSelectedItem()
4868 QModelIndexList list=selModel->selectedIndexes();
4869 if (!list.isEmpty() )
4870 return getItem (list.first() );
4875 QModelIndex VymModel::getSelectedIndex()
4877 QModelIndexList list=selModel->selectedIndexes();
4878 if (list.isEmpty() )
4879 return QModelIndex();
4881 return list.first();
4884 QString VymModel::getSelectString ()
4886 return getSelectString (getSelectedItem());
4889 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
4891 if (!lmo) return QString();
4892 return getSelectString (lmo->getTreeItem() );
4895 QString VymModel::getSelectString (TreeItem *ti)
4899 switch (ti->getType())
4901 case TreeItem::MapCenter: s="mc:"; break;
4902 case TreeItem::Branch: s="bo:";break;
4903 case TreeItem::Image: s="fi:";break;
4904 case TreeItem::Attribute: s="ai:";break;
4905 case TreeItem::XLink: s="xl:";break;
4907 s="unknown type in VymModel::getSelectString()";
4910 s= s + QString("%1").arg(ti->num());
4912 // call myself recursively
4913 s= getSelectString(ti->parent()) +","+s;