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 << "" << "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 // Set color of heading to that of parent
2202 newbi->setHeadingColor (parbi->getHeadingColor());
2204 // save scroll state. If scrolled, automatically select
2205 // new branch in order to tmp unscroll parent...
2206 newbi->createMapObj(mapScene);
2211 BranchItem* VymModel::addNewBranch(int pos)
2213 // Different meaning than num in addNewBranchInt!
2217 BranchItem *newbi=NULL;
2218 BranchItem *selbi=getSelectedBranch();
2222 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2224 newbi=addNewBranchInt (selbi,pos-2);
2232 QString ("addBranch (%1)").arg(pos),
2233 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2236 // emitSelectionChanged(); FIXME-3
2237 latestAddedItem=newbi;
2238 // In Network mode, the client needs to know where the new branch is,
2239 // so we have to pass on this information via saveState.
2240 // TODO: Get rid of this positioning workaround
2241 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2242 sendData ("selectLatestAdded ()");
2243 sendData (QString("move %1").arg(ps));
2252 BranchItem* VymModel::addNewBranchBefore()
2254 BranchItem *newbi=NULL;
2255 BranchItem *selbi=getSelectedBranch();
2256 if (selbi && selbi->getType()==TreeItem::Branch)
2257 // We accept no MapCenter here, so we _have_ a parent
2259 //QPointF p=bo->getRelPos();
2262 // add below selection
2263 newbi=addNewBranchInt (selbi,-1);
2267 //newbi->move2RelPos (p);
2269 // Move selection to new branch
2270 relinkBranch (selbi,newbi,0);
2272 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2273 QString ("Add branch before %1").arg(getObjectName(selbi)));
2275 // FIXME-3 needed? reposition();
2276 // emitSelectionChanged(); FIXME-3
2282 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2286 emit (layoutAboutToBeChanged() );
2287 BranchItem *branchpi=(BranchItem*)branch->parent();
2288 // Remove at current position
2289 int n=branch->childNum();
2290 beginRemoveRows (index(branchpi),n,n);
2291 branchpi->removeChild (n);
2294 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2296 // Append as last branch to dst
2297 if (dst->branchCount()==0)
2300 n=dst->getFirstBranch()->childNumber();
2301 beginInsertRows (index(dst),n+pos,n+pos);
2302 dst->insertBranch (pos,branch);
2305 // Correct type if necessesary
2306 if (branch->getType()==TreeItem::MapCenter)
2307 branch->setType(TreeItem::Branch);
2309 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2310 branch->updateStyles();
2312 emit (layoutChanged() );
2313 reposition(); // both for moveUp/Down and relinking
2314 if (dst->isScrolled() )
2317 branch->updateVisibility();
2326 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2330 emit (layoutAboutToBeChanged() );
2332 BranchItem *pi=(BranchItem*)(image->parent());
2333 QString oldParString=getSelectString (pi);
2334 // Remove at current position
2335 int n=image->childNum();
2336 beginRemoveRows (index(pi),n,n);
2337 pi->removeChild (n);
2341 QModelIndex dstix=index(dst);
2342 n=dst->getRowNumAppend (image);
2343 beginInsertRows (dstix,n,n+1);
2344 dst->appendChild (image);
2347 // Set new parent also for lmo
2348 if (image->getLMO() && dst->getLMO() )
2349 image->getLMO()->setParObj (dst->getLMO() );
2351 emit (layoutChanged() );
2354 QString("relinkTo (\"%1\")").arg(oldParString),
2356 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2357 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2363 void VymModel::deleteSelection()
2365 BranchItem *selbi=getSelectedBranch();
2370 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2372 TreeItem *pi=deleteItem (selbi);
2376 emitShowSelection();
2380 TreeItem *ti=getSelectedItem();
2383 TreeItem *pi=ti->parent();
2385 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2387 saveStateChangingPart(
2391 QString("Delete %1").arg(getObjectName(ti))
2395 emitDataHasChanged (pi);
2398 emitShowSelection();
2399 } else if (ti->getType()==TreeItem::XLink)
2401 //FIXME-2 savestate missing
2404 qWarning ("VymmModel::deleteSelection() unknown type?!");
2408 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2411 BranchItem *selbi=getSelectedBranch();
2415 // Don't use this on mapcenter
2416 if (selbi->depth()<2) return;
2418 pi=(BranchItem*)(selbi->parent());
2419 // Check if we have childs at all to keep
2420 if (selbi->branchCount()==0)
2427 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2428 saveStateChangingPart(
2431 "deleteKeepChildren ()",
2432 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2435 QString sel=getSelectString(selbi);
2437 int pos=selbi->num();
2438 BranchItem *bi=selbi->getFirstBranch();
2441 relinkBranch (bi,pi,pos);
2442 bi=selbi->getFirstBranch();
2448 BranchObj *bo=getSelectedBranchObj();
2451 bo->move2RelPos (p);
2457 void VymModel::deleteChildren()
2460 BranchItem *selbi=getSelectedBranch();
2463 saveStateChangingPart(
2466 "deleteChildren ()",
2467 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2469 emit (layoutAboutToBeChanged() );
2471 QModelIndex ix=index (selbi);
2472 int n=selbi->branchCount()-1;
2473 beginRemoveRows (ix,0,n);
2474 removeRows (0,n+1,ix);
2476 if (selbi->isScrolled()) selbi->unScroll();
2477 emit (layoutChanged() );
2482 TreeItem* VymModel::deleteItem (TreeItem *ti)
2486 TreeItem *pi=ti->parent();
2487 QModelIndex parentIndex=index(pi);
2489 emit (layoutAboutToBeChanged() );
2491 int n=ti->childNum();
2492 beginRemoveRows (parentIndex,n,n);
2493 removeRows (n,1,parentIndex);
2497 emit (layoutChanged() );
2498 if (pi->depth()>=0) return pi;
2503 void VymModel::clearItem (TreeItem *ti)
2507 QModelIndex parentIndex=index(ti);
2508 if (!parentIndex.isValid()) return;
2510 int n=ti->childCount();
2513 emit (layoutAboutToBeChanged() );
2515 beginRemoveRows (parentIndex,0,n-1);
2516 removeRows (0,n,parentIndex);
2520 emit (layoutChanged() );
2526 bool VymModel::scrollBranch(BranchItem *bi)
2530 if (bi->isScrolled()) return false;
2531 if (bi->branchCount()==0) return false;
2532 if (bi->depth()==0) return false;
2533 if (bi->toggleScroll())
2541 QString ("%1 ()").arg(u),
2543 QString ("%1 ()").arg(r),
2544 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2546 emitDataHasChanged(bi);
2547 emitSelectionChanged();
2548 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2555 bool VymModel::unscrollBranch(BranchItem *bi)
2559 if (!bi->isScrolled()) return false;
2560 if (bi->branchCount()==0) return false;
2561 if (bi->depth()==0) return false;
2562 if (bi->toggleScroll())
2570 QString ("%1 ()").arg(u),
2572 QString ("%1 ()").arg(r),
2573 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2575 emitDataHasChanged(bi);
2576 emitSelectionChanged();
2577 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2584 void VymModel::toggleScroll()
2586 BranchItem *bi=(BranchItem*)getSelectedBranch();
2587 if (bi && bi->isBranchLikeType() )
2589 if (bi->isScrolled())
2590 unscrollBranch (bi);
2594 // saveState & reposition are called in above functions
2597 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2599 BranchItem *selbi=getSelectedBranch();
2600 BranchItem *prev=NULL;
2601 BranchItem *cur=selbi;
2604 saveStateChangingPart(
2607 QString ("unscrollChildren ()"),
2608 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2612 if (cur->isScrolled())
2614 cur->toggleScroll();
2615 emitDataHasChanged (cur);
2617 cur=next (cur,prev,selbi);
2624 void VymModel::emitExpandAll()
2626 emit (expandAll() );
2629 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2631 BranchItem *bi=getSelectedBranch();
2635 if (bi->isActiveStandardFlag(name))
2647 QString("%1 (\"%2\")").arg(u).arg(name),
2649 QString("%1 (\"%2\")").arg(r).arg(name),
2650 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2651 bi->toggleStandardFlag (name, master);
2653 emitSelectionChanged();
2657 void VymModel::addFloatImage (const QPixmap &img)
2659 BranchItem *selbi=getSelectedBranch();
2662 ImageItem *ii=createImage (selbi);
2664 ii->setOriginalFilename("No original filename (image added by dropevent)");
2665 QString s=getSelectString(selbi);
2666 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2667 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2669 // FIXME-3 VM needed? scene()->update();
2674 void VymModel::colorBranch (QColor c)
2676 cout << "VM::colBranch\n";
2677 BranchItem *selbi=getSelectedBranch();
2682 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2684 QString ("colorBranch (\"%1\")").arg(c.name()),
2685 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2687 selbi->setHeadingColor(c); // color branch
2692 void VymModel::colorSubtree (QColor c)
2694 BranchItem *selbi=getSelectedBranch();
2697 saveStateChangingPart(
2700 QString ("colorSubtree (\"%1\")").arg(c.name()),
2701 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2703 BranchItem *prev=NULL;
2704 BranchItem *cur=selbi;
2707 cur->setHeadingColor(c); // color links, color children
2708 cur=next (cur,prev,selbi);
2714 QColor VymModel::getCurrentHeadingColor()
2716 BranchItem *selbi=getSelectedBranch();
2717 if (selbi) return selbi->getHeadingColor();
2719 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2725 void VymModel::editURL()
2727 TreeItem *selti=getSelectedItem();
2731 QString text = QInputDialog::getText(
2732 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2733 selti->getURL(), &ok, NULL);
2735 // user entered something and pressed OK
2740 void VymModel::editLocalURL()
2742 TreeItem *selti=getSelectedItem();
2745 QStringList filters;
2746 filters <<"All files (*)";
2747 filters << tr("Text","Filedialog") + " (*.txt)";
2748 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2749 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2750 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2751 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2752 fd->setFilters (filters);
2753 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2754 fd->setDirectory (lastFileDir);
2755 if (! selti->getVymLink().isEmpty() )
2756 fd->selectFile( selti->getURL() );
2759 if ( fd->exec() == QDialog::Accepted )
2761 lastFileDir=QDir (fd->directory().path());
2762 setURL (fd->selectedFile() );
2768 void VymModel::editHeading2URL()
2770 TreeItem *selti=getSelectedItem();
2772 setURL (selti->getHeading());
2775 void VymModel::editBugzilla2URL()
2777 TreeItem *selti=getSelectedItem();
2780 QString h=selti->getHeading();
2781 QRegExp rx("^(\\d+)");
2782 if (rx.indexIn(h) !=-1)
2783 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2787 void VymModel::editFATE2URL()
2789 TreeItem *selti=getSelectedItem();
2792 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2795 "setURL (\""+selti->getURL()+"\")",
2797 "setURL (\""+url+"\")",
2798 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2800 selti->setURL (url);
2801 // FIXME-4 updateActions();
2805 void VymModel::editVymLink()
2807 BranchItem *bi=getSelectedBranch();
2810 QStringList filters;
2811 filters <<"VYM map (*.vym)";
2812 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2813 fd->setFilters (filters);
2814 fd->setCaption(vymName+" - " +tr("Link to another map"));
2815 fd->setDirectory (lastFileDir);
2816 if (! bi->getVymLink().isEmpty() )
2817 fd->selectFile( bi->getVymLink() );
2821 if ( fd->exec() == QDialog::Accepted )
2823 lastFileDir=QDir (fd->directory().path());
2826 "setVymLink (\""+bi->getVymLink()+"\")",
2828 "setVymLink (\""+fd->selectedFile()+"\")",
2829 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2831 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2836 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2838 // Internal function, no saveState needed
2839 TreeItem *selti=getSelectedItem();
2842 selti->setVymLink(s);
2844 emitDataHasChanged (selti);
2845 emitShowSelection();
2849 void VymModel::deleteVymLink()
2851 BranchItem *bi=getSelectedBranch();
2856 "setVymLink (\""+bi->getVymLink()+"\")",
2858 "setVymLink (\"\")",
2859 QString("Unset vymlink of %1").arg(getObjectName(bi))
2861 bi->setVymLink ("" );
2867 QString VymModel::getVymLink()
2869 BranchItem *bi=getSelectedBranch();
2871 return bi->getVymLink();
2877 QStringList VymModel::getVymLinks()
2880 BranchItem *selbi=getSelectedBranch();
2881 BranchItem *cur=selbi;
2882 BranchItem *prev=NULL;
2885 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2886 cur=next (cur,prev,selbi);
2892 void VymModel::followXLink(int i)
2895 BranchItem *selbi=getSelectedBranch();
2898 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2899 if (selbi) select (selbi);
2903 void VymModel::editXLink(int i)
2906 BranchItem *selbi=getSelectedBranch();
2909 XLinkItem *xli=selbi->getXLinkNum(i);
2912 EditXLinkDialog dia;
2914 dia.setSelection(selbi);
2915 if (dia.exec() == QDialog::Accepted)
2917 if (dia.useSettingsGlobal() )
2919 setMapDefXLinkColor (xli->getColor() );
2920 setMapDefXLinkWidth (xli->getWidth() );
2922 if (dia.deleteXLink()) deleteItem (xli);
2932 //////////////////////////////////////////////
2934 //////////////////////////////////////////////
2936 void VymModel::parseAtom(const QString &atom)
2938 TreeItem* selti=getSelectedItem();
2939 BranchItem *selbi=getSelectedBranch();
2945 // Split string s into command and parameters
2946 parser.parseAtom (atom);
2947 QString com=parser.getCommand();
2949 // External commands
2950 /////////////////////////////////////////////////////////////////////
2951 if (com=="addBranch")
2955 parser.setError (Aborted,"Nothing selected");
2956 } else if (! selbi )
2958 parser.setError (Aborted,"Type of selection is not a branch");
2963 if (parser.checkParCount(pl))
2965 if (parser.parCount()==0)
2969 n=parser.parInt (ok,0);
2970 if (ok ) addNewBranch (n);
2974 /////////////////////////////////////////////////////////////////////
2975 } else if (com=="addBranchBefore")
2979 parser.setError (Aborted,"Nothing selected");
2980 } else if (! selbi )
2982 parser.setError (Aborted,"Type of selection is not a branch");
2985 if (parser.parCount()==0)
2987 addNewBranchBefore ();
2990 /////////////////////////////////////////////////////////////////////
2991 } else if (com==QString("addMapCenter"))
2993 if (parser.checkParCount(2))
2995 x=parser.parDouble (ok,0);
2998 y=parser.parDouble (ok,1);
2999 if (ok) addMapCenter (QPointF(x,y));
3002 /////////////////////////////////////////////////////////////////////
3003 } else if (com==QString("addMapReplace"))
3007 parser.setError (Aborted,"Nothing selected");
3008 } else if (! selbi )
3010 parser.setError (Aborted,"Type of selection is not a branch");
3011 } else if (parser.checkParCount(1))
3013 //s=parser.parString (ok,0); // selection
3014 t=parser.parString (ok,0); // path to map
3015 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3016 addMapReplaceInt(getSelectString(selbi),t);
3018 /////////////////////////////////////////////////////////////////////
3019 } else if (com==QString("addMapInsert"))
3021 if (parser.parCount()==2)
3026 parser.setError (Aborted,"Nothing selected");
3027 } else if (! selbi )
3029 parser.setError (Aborted,"Type of selection is not a branch");
3032 t=parser.parString (ok,0); // path to map
3033 n=parser.parInt(ok,1); // position
3034 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3035 addMapInsertInt(t,n);
3037 } else if (parser.parCount()==1)
3039 t=parser.parString (ok,0); // path to map
3040 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3043 parser.setError (Aborted,"Wrong number of parameters");
3044 /////////////////////////////////////////////////////////////////////
3045 } else if (com==QString("addXLink"))
3047 if (parser.parCount()>1)
3049 s=parser.parString (ok,0); // begin
3050 t=parser.parString (ok,1); // end
3051 BranchItem *begin=(BranchItem*)findBySelectString(s);
3052 BranchItem *end=(BranchItem*)findBySelectString(t);
3055 if (begin->isBranchLikeType() && end->isBranchLikeType())
3057 XLinkItem *xl=createXLink (begin,true);
3063 parser.setError (Aborted,"Failed to create xLink");
3066 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3069 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3071 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3072 /////////////////////////////////////////////////////////////////////
3073 } else if (com=="clearFlags")
3077 parser.setError (Aborted,"Nothing selected");
3078 } else if (! selbi )
3080 parser.setError (Aborted,"Type of selection is not a branch");
3081 } else if (parser.checkParCount(0))
3083 selbi->deactivateAllStandardFlags();
3085 /////////////////////////////////////////////////////////////////////
3086 } else if (com=="colorBranch")
3090 parser.setError (Aborted,"Nothing selected");
3091 } else if (! selbi )
3093 parser.setError (Aborted,"Type of selection is not a branch");
3094 } else if (parser.checkParCount(1))
3096 QColor c=parser.parColor (ok,0);
3097 if (ok) colorBranch (c);
3099 /////////////////////////////////////////////////////////////////////
3100 } else if (com=="colorSubtree")
3104 parser.setError (Aborted,"Nothing selected");
3105 } else if (! selbi )
3107 parser.setError (Aborted,"Type of selection is not a branch");
3108 } else if (parser.checkParCount(1))
3110 QColor c=parser.parColor (ok,0);
3111 if (ok) colorSubtree (c);
3113 /////////////////////////////////////////////////////////////////////
3114 } else if (com=="copy")
3118 parser.setError (Aborted,"Nothing selected");
3119 } else if ( selectionType()!=TreeItem::Branch &&
3120 selectionType()!=TreeItem::MapCenter &&
3121 selectionType()!=TreeItem::Image )
3123 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3124 } else if (parser.checkParCount(0))
3128 /////////////////////////////////////////////////////////////////////
3129 } else if (com=="cut")
3133 parser.setError (Aborted,"Nothing selected");
3134 } else if ( selectionType()!=TreeItem::Branch &&
3135 selectionType()!=TreeItem::MapCenter &&
3136 selectionType()!=TreeItem::Image )
3138 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3139 } else if (parser.checkParCount(0))
3143 /////////////////////////////////////////////////////////////////////
3144 } else if (com=="delete")
3148 parser.setError (Aborted,"Nothing selected");
3150 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3152 parser.setError (Aborted,"Type of selection is wrong.");
3155 else if (parser.checkParCount(0))
3159 /////////////////////////////////////////////////////////////////////
3160 } else if (com=="deleteKeepChildren")
3164 parser.setError (Aborted,"Nothing selected");
3165 } else if (! selbi )
3167 parser.setError (Aborted,"Type of selection is not a branch");
3168 } else if (parser.checkParCount(0))
3170 deleteKeepChildren();
3172 /////////////////////////////////////////////////////////////////////
3173 } else if (com=="deleteChildren")
3177 parser.setError (Aborted,"Nothing selected");
3180 parser.setError (Aborted,"Type of selection is not a branch");
3181 } else if (parser.checkParCount(0))
3185 /////////////////////////////////////////////////////////////////////
3186 } else if (com=="exportASCII")
3190 if (parser.parCount()>=1)
3191 // Hey, we even have a filename
3192 fname=parser.parString(ok,0);
3195 parser.setError (Aborted,"Could not read filename");
3198 exportASCII (fname,false);
3200 /////////////////////////////////////////////////////////////////////
3201 } else if (com=="exportImage")
3205 if (parser.parCount()>=2)
3206 // Hey, we even have a filename
3207 fname=parser.parString(ok,0);
3210 parser.setError (Aborted,"Could not read filename");
3213 QString format="PNG";
3214 if (parser.parCount()>=2)
3216 format=parser.parString(ok,1);
3218 exportImage (fname,false,format);
3220 /////////////////////////////////////////////////////////////////////
3221 } else if (com=="exportXHTML")
3225 if (parser.parCount()>=2)
3226 // Hey, we even have a filename
3227 fname=parser.parString(ok,1);
3230 parser.setError (Aborted,"Could not read filename");
3233 exportXHTML (fname,false);
3235 /////////////////////////////////////////////////////////////////////
3236 } else if (com=="exportXML")
3240 if (parser.parCount()>=2)
3241 // Hey, we even have a filename
3242 fname=parser.parString(ok,1);
3245 parser.setError (Aborted,"Could not read filename");
3248 exportXML (fname,false);
3250 /////////////////////////////////////////////////////////////////////
3251 } else if (com=="importDir")
3255 parser.setError (Aborted,"Nothing selected");
3256 } else if (! selbi )
3258 parser.setError (Aborted,"Type of selection is not a branch");
3259 } else if (parser.checkParCount(1))
3261 s=parser.parString(ok,0);
3262 if (ok) importDirInt(s);
3264 /////////////////////////////////////////////////////////////////////
3265 } else if (com=="relinkTo")
3269 parser.setError (Aborted,"Nothing selected");
3272 if (parser.checkParCount(4))
3274 // 0 selectstring of parent
3275 // 1 num in parent (for branches)
3276 // 2,3 x,y of mainbranch or mapcenter
3277 s=parser.parString(ok,0);
3278 TreeItem *dst=findBySelectString (s);
3281 if (dst->getType()==TreeItem::Branch)
3283 // Get number in parent
3284 n=parser.parInt (ok,1);
3287 relinkBranch (selbi,(BranchItem*)dst,n);
3288 emitSelectionChanged();
3290 } else if (dst->getType()==TreeItem::MapCenter)
3292 relinkBranch (selbi,(BranchItem*)dst);
3293 // Get coordinates of mainbranch
3294 x=parser.parDouble(ok,2);
3297 y=parser.parDouble(ok,3);
3300 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3301 emitSelectionChanged();
3307 } else if ( selti->getType() == TreeItem::Image)
3309 if (parser.checkParCount(1))
3311 // 0 selectstring of parent
3312 s=parser.parString(ok,0);
3313 TreeItem *dst=findBySelectString (s);
3316 if (dst->isBranchLikeType())
3317 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3319 parser.setError (Aborted,"Destination is not a branch");
3322 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3323 /////////////////////////////////////////////////////////////////////
3324 } else if (com=="loadImage")
3328 parser.setError (Aborted,"Nothing selected");
3329 } else if (! selbi )
3331 parser.setError (Aborted,"Type of selection is not a branch");
3332 } else if (parser.checkParCount(1))
3334 s=parser.parString(ok,0);
3335 if (ok) loadFloatImageInt (selbi,s);
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="moveUp")
3342 parser.setError (Aborted,"Nothing selected");
3343 } else if (! selbi )
3345 parser.setError (Aborted,"Type of selection is not a branch");
3346 } else if (parser.checkParCount(0))
3350 /////////////////////////////////////////////////////////////////////
3351 } else if (com=="moveDown")
3355 parser.setError (Aborted,"Nothing selected");
3356 } else if (! selbi )
3358 parser.setError (Aborted,"Type of selection is not a branch");
3359 } else if (parser.checkParCount(0))
3363 /////////////////////////////////////////////////////////////////////
3364 } else if (com=="move")
3368 parser.setError (Aborted,"Nothing selected");
3369 } else if ( selectionType()!=TreeItem::Branch &&
3370 selectionType()!=TreeItem::MapCenter &&
3371 selectionType()!=TreeItem::Image )
3373 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3374 } else if (parser.checkParCount(2))
3376 x=parser.parDouble (ok,0);
3379 y=parser.parDouble (ok,1);
3383 /////////////////////////////////////////////////////////////////////
3384 } else if (com=="moveRel")
3388 parser.setError (Aborted,"Nothing selected");
3389 } else if ( selectionType()!=TreeItem::Branch &&
3390 selectionType()!=TreeItem::MapCenter &&
3391 selectionType()!=TreeItem::Image )
3393 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3394 } else if (parser.checkParCount(2))
3396 x=parser.parDouble (ok,0);
3399 y=parser.parDouble (ok,1);
3400 if (ok) moveRel (x,y);
3403 /////////////////////////////////////////////////////////////////////
3404 } else if (com=="nop")
3406 /////////////////////////////////////////////////////////////////////
3407 } else if (com=="paste")
3411 parser.setError (Aborted,"Nothing selected");
3412 } else if (! selbi )
3414 parser.setError (Aborted,"Type of selection is not a branch");
3415 } else if (parser.checkParCount(1))
3417 n=parser.parInt (ok,0);
3418 if (ok) pasteNoSave(n);
3420 /////////////////////////////////////////////////////////////////////
3421 } else if (com=="qa")
3425 parser.setError (Aborted,"Nothing selected");
3426 } else if (! selbi )
3428 parser.setError (Aborted,"Type of selection is not a branch");
3429 } else if (parser.checkParCount(4))
3432 c=parser.parString (ok,0);
3435 parser.setError (Aborted,"No comment given");
3438 s=parser.parString (ok,1);
3441 parser.setError (Aborted,"First parameter is not a string");
3444 t=parser.parString (ok,2);
3447 parser.setError (Aborted,"Condition is not a string");
3450 u=parser.parString (ok,3);
3453 parser.setError (Aborted,"Third parameter is not a string");
3458 parser.setError (Aborted,"Unknown type: "+s);
3463 parser.setError (Aborted,"Unknown operator: "+t);
3468 parser.setError (Aborted,"Type of selection is not a branch");
3471 if (selbi->getHeading() == u)
3473 cout << "PASSED: " << qPrintable (c) << endl;
3476 cout << "FAILED: " << qPrintable (c) << endl;
3486 /////////////////////////////////////////////////////////////////////
3487 } else if (com=="saveImage")
3489 ImageItem *ii=getSelectedImage();
3492 parser.setError (Aborted,"No image selected");
3493 } else if (parser.checkParCount(2))
3495 s=parser.parString(ok,0);
3498 t=parser.parString(ok,1);
3499 if (ok) saveFloatImageInt (ii,t,s);
3502 /////////////////////////////////////////////////////////////////////
3503 } else if (com=="scroll")
3507 parser.setError (Aborted,"Nothing selected");
3508 } else if (! selbi )
3510 parser.setError (Aborted,"Type of selection is not a branch");
3511 } else if (parser.checkParCount(0))
3513 if (!scrollBranch (selbi))
3514 parser.setError (Aborted,"Could not scroll branch");
3516 /////////////////////////////////////////////////////////////////////
3517 } else if (com=="select")
3519 if (parser.checkParCount(1))
3521 s=parser.parString(ok,0);
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="selectLastBranch")
3529 parser.setError (Aborted,"Nothing selected");
3530 } else if (! selbi )
3532 parser.setError (Aborted,"Type of selection is not a branch");
3533 } else if (parser.checkParCount(0))
3535 BranchItem *bi=selbi->getLastBranch();
3537 parser.setError (Aborted,"Could not select last branch");
3538 select (bi); // FIXME-3 was selectInt
3541 /////////////////////////////////////////////////////////////////////
3542 } else /* FIXME-2 if (com=="selectLastImage")
3546 parser.setError (Aborted,"Nothing selected");
3547 } else if (! selbi )
3549 parser.setError (Aborted,"Type of selection is not a branch");
3550 } else if (parser.checkParCount(0))
3552 FloatImageObj *fio=selb->getLastFloatImage();
3554 parser.setError (Aborted,"Could not select last image");
3555 select (fio); // FIXME-3 was selectInt
3558 /////////////////////////////////////////////////////////////////////
3559 } else */ if (com=="selectLatestAdded")
3561 if (!latestAddedItem)
3563 parser.setError (Aborted,"No latest added object");
3566 if (!select (latestAddedItem))
3567 parser.setError (Aborted,"Could not select latest added object ");
3569 /////////////////////////////////////////////////////////////////////
3570 } else if (com=="setFrameType")
3572 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3574 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3576 else if (parser.checkParCount(1))
3578 s=parser.parString(ok,0);
3579 if (ok) setFrameType (s);
3581 /////////////////////////////////////////////////////////////////////
3582 } else if (com=="setFramePenColor")
3584 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3586 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3588 else if (parser.checkParCount(1))
3590 QColor c=parser.parColor(ok,0);
3591 if (ok) setFramePenColor (c);
3593 /////////////////////////////////////////////////////////////////////
3594 } else if (com=="setFrameBrushColor")
3596 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3598 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3600 else if (parser.checkParCount(1))
3602 QColor c=parser.parColor(ok,0);
3603 if (ok) setFrameBrushColor (c);
3605 /////////////////////////////////////////////////////////////////////
3606 } else if (com=="setFramePadding")
3608 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3610 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3612 else if (parser.checkParCount(1))
3614 n=parser.parInt(ok,0);
3615 if (ok) setFramePadding(n);
3617 /////////////////////////////////////////////////////////////////////
3618 } else if (com=="setFrameBorderWidth")
3620 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3622 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3624 else if (parser.checkParCount(1))
3626 n=parser.parInt(ok,0);
3627 if (ok) setFrameBorderWidth (n);
3629 /////////////////////////////////////////////////////////////////////
3630 } else if (com=="setMapAuthor")
3632 if (parser.checkParCount(1))
3634 s=parser.parString(ok,0);
3635 if (ok) setAuthor (s);
3637 /////////////////////////////////////////////////////////////////////
3638 } else if (com=="setMapComment")
3640 if (parser.checkParCount(1))
3642 s=parser.parString(ok,0);
3643 if (ok) setComment(s);
3645 /////////////////////////////////////////////////////////////////////
3646 } else if (com=="setMapBackgroundColor")
3650 parser.setError (Aborted,"Nothing selected");
3651 } else if (! selbi )
3653 parser.setError (Aborted,"Type of selection is not a branch");
3654 } else if (parser.checkParCount(1))
3656 QColor c=parser.parColor (ok,0);
3657 if (ok) setMapBackgroundColor (c);
3659 /////////////////////////////////////////////////////////////////////
3660 } else if (com=="setMapDefLinkColor")
3664 parser.setError (Aborted,"Nothing selected");
3665 } else if (! selbi )
3667 parser.setError (Aborted,"Type of selection is not a branch");
3668 } else if (parser.checkParCount(1))
3670 QColor c=parser.parColor (ok,0);
3671 if (ok) setMapDefLinkColor (c);
3673 /////////////////////////////////////////////////////////////////////
3674 } else if (com=="setMapLinkStyle")
3676 if (parser.checkParCount(1))
3678 s=parser.parString (ok,0);
3679 if (ok) setMapLinkStyle(s);
3681 /////////////////////////////////////////////////////////////////////
3682 } else if (com=="setHeading")
3686 parser.setError (Aborted,"Nothing selected");
3687 } else if (! selbi )
3689 parser.setError (Aborted,"Type of selection is not a branch");
3690 } else if (parser.checkParCount(1))
3692 s=parser.parString (ok,0);
3696 /////////////////////////////////////////////////////////////////////
3697 } else if (com=="setHideExport")
3701 parser.setError (Aborted,"Nothing selected");
3702 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3704 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3705 } else if (parser.checkParCount(1))
3707 b=parser.parBool(ok,0);
3708 if (ok) setHideExport (b);
3710 /////////////////////////////////////////////////////////////////////
3711 } else if (com=="setIncludeImagesHorizontally")
3715 parser.setError (Aborted,"Nothing selected");
3718 parser.setError (Aborted,"Type of selection is not a branch");
3719 } else if (parser.checkParCount(1))
3721 b=parser.parBool(ok,0);
3722 if (ok) setIncludeImagesHor(b);
3724 /////////////////////////////////////////////////////////////////////
3725 } else if (com=="setIncludeImagesVertically")
3729 parser.setError (Aborted,"Nothing selected");
3732 parser.setError (Aborted,"Type of selection is not a branch");
3733 } else if (parser.checkParCount(1))
3735 b=parser.parBool(ok,0);
3736 if (ok) setIncludeImagesVer(b);
3738 /////////////////////////////////////////////////////////////////////
3739 } else if (com=="setHideLinkUnselected")
3743 parser.setError (Aborted,"Nothing selected");
3744 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3746 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3747 } else if (parser.checkParCount(1))
3749 b=parser.parBool(ok,0);
3750 if (ok) setHideLinkUnselected(b);
3752 /////////////////////////////////////////////////////////////////////
3753 } else if (com=="setSelectionColor")
3755 if (parser.checkParCount(1))
3757 QColor c=parser.parColor (ok,0);
3758 if (ok) setSelectionColorInt (c);
3760 /////////////////////////////////////////////////////////////////////
3761 } else if (com=="setURL")
3765 parser.setError (Aborted,"Nothing selected");
3766 } else if (! selbi )
3768 parser.setError (Aborted,"Type of selection is not a branch");
3769 } else if (parser.checkParCount(1))
3771 s=parser.parString (ok,0);
3774 /////////////////////////////////////////////////////////////////////
3775 } else if (com=="setVymLink")
3779 parser.setError (Aborted,"Nothing selected");
3780 } else if (! selbi )
3782 parser.setError (Aborted,"Type of selection is not a branch");
3783 } else if (parser.checkParCount(1))
3785 s=parser.parString (ok,0);
3786 if (ok) setVymLink(s);
3789 /////////////////////////////////////////////////////////////////////
3790 else if (com=="setFlag")
3794 parser.setError (Aborted,"Nothing selected");
3795 } else if (! selbi )
3797 parser.setError (Aborted,"Type of selection is not a branch");
3798 } else if (parser.checkParCount(1))
3800 s=parser.parString(ok,0);
3802 selbi->activateStandardFlag(s);
3804 /////////////////////////////////////////////////////////////////////
3805 } else /* FIXME-2 if (com=="setFrameType")
3809 parser.setError (Aborted,"Nothing selected");
3812 parser.setError (Aborted,"Type of selection is not a branch");
3813 } else if (parser.checkParCount(1))
3815 s=parser.parString(ok,0);
3819 /////////////////////////////////////////////////////////////////////
3820 } else*/ if (com=="sortChildren")
3824 parser.setError (Aborted,"Nothing selected");
3825 } else if (! selbi )
3827 parser.setError (Aborted,"Type of selection is not a branch");
3828 } else if (parser.checkParCount(0))
3832 /////////////////////////////////////////////////////////////////////
3833 } else if (com=="toggleFlag")
3837 parser.setError (Aborted,"Nothing selected");
3838 } else if (! selbi )
3840 parser.setError (Aborted,"Type of selection is not a branch");
3841 } else if (parser.checkParCount(1))
3843 s=parser.parString(ok,0);
3845 selbi->toggleStandardFlag(s);
3847 /////////////////////////////////////////////////////////////////////
3848 } else if (com=="unscroll")
3852 parser.setError (Aborted,"Nothing selected");
3853 } else if (! selbi )
3855 parser.setError (Aborted,"Type of selection is not a branch");
3856 } else if (parser.checkParCount(0))
3858 if (!unscrollBranch (selbi))
3859 parser.setError (Aborted,"Could not unscroll branch");
3861 /////////////////////////////////////////////////////////////////////
3862 } else if (com=="unscrollChildren")
3866 parser.setError (Aborted,"Nothing selected");
3867 } else if (! selbi )
3869 parser.setError (Aborted,"Type of selection is not a branch");
3870 } else if (parser.checkParCount(0))
3872 unscrollChildren ();
3874 /////////////////////////////////////////////////////////////////////
3875 } else if (com=="unsetFlag")
3879 parser.setError (Aborted,"Nothing selected");
3880 } else if (! selbi )
3882 parser.setError (Aborted,"Type of selection is not a branch");
3883 } else if (parser.checkParCount(1))
3885 s=parser.parString(ok,0);
3887 selbi->deactivateStandardFlag(s);
3890 parser.setError (Aborted,"Unknown command");
3893 if (parser.errorLevel()==NoError)
3895 // setChanged(); FIXME-2 should not be called e.g. for export?!
3900 // TODO Error handling
3901 qWarning("VymModel::parseAtom: Error!");
3902 qWarning(parser.errorMessage());
3906 void VymModel::runScript (QString script)
3908 parser.setScript (script);
3910 while (parser.next() )
3911 parseAtom(parser.getAtom());
3914 void VymModel::setExportMode (bool b)
3916 // should be called before and after exports
3917 // depending on the settings
3918 if (b && settings.value("/export/useHideExport","true")=="true")
3919 setHideTmpMode (TreeItem::HideExport);
3921 setHideTmpMode (TreeItem::HideNone);
3924 void VymModel::exportImage(QString fname, bool askName, QString format)
3928 fname=getMapName()+".png";
3935 QFileDialog *fd=new QFileDialog (NULL);
3936 fd->setCaption (tr("Export map as image"));
3937 fd->setDirectory (lastImageDir);
3938 fd->setFileMode(QFileDialog::AnyFile);
3939 fd->setFilters (imageIO.getFilters() );
3942 fl=fd->selectedFiles();
3944 format=imageIO.getType(fd->selectedFilter());
3948 setExportMode (true);
3949 QPixmap pix (mapEditor->getPixmap());
3950 pix.save(fname, format);
3951 setExportMode (false);
3955 void VymModel::exportXML(QString dir, bool askForName)
3959 dir=browseDirectory(NULL,tr("Export XML to directory"));
3960 if (dir =="" && !reallyWriteDirectory(dir) )
3964 // Hide stuff during export, if settings want this
3965 setExportMode (true);
3967 // Create subdirectories
3970 // write to directory //FIXME-4 check totalBBox here...
3971 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3974 file.setName ( dir + "/"+mapName+".xml");
3975 if ( !file.open( QIODevice::WriteOnly ) )
3977 // This should neverever happen
3978 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3982 // Write it finally, and write in UTF8, no matter what
3983 QTextStream ts( &file );
3984 ts.setEncoding (QTextStream::UnicodeUTF8);
3988 // Now write image, too
3989 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3991 setExportMode (false);
3994 void VymModel::exportASCII(QString fname,bool askName)
3999 ex.setFile (mapName+".txt");
4005 //ex.addFilter ("TXT (*.txt)");
4006 ex.setDir(lastImageDir);
4007 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4012 setExportMode(true);
4014 setExportMode(false);
4018 void VymModel::exportXHTML (const QString &dir, bool askForName)
4020 ExportXHTMLDialog dia(NULL);
4021 dia.setFilePath (filePath );
4022 dia.setMapName (mapName );
4024 if (dir!="") dia.setDir (dir);
4030 if (dia.exec()!=QDialog::Accepted)
4034 QDir d (dia.getDir());
4035 // Check, if warnings should be used before overwriting
4036 // the output directory
4037 if (d.exists() && d.count()>0)
4040 warn.showCancelButton (true);
4041 warn.setText(QString(
4042 "The directory %1 is not empty.\n"
4043 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4044 warn.setCaption("Warning: Directory not empty");
4045 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4047 if (warn.exec()!=QDialog::Accepted) ok=false;
4054 exportXML (dia.getDir(),false );
4055 dia.doExport(mapName );
4056 //if (dia.hasChanged()) setChanged();
4060 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4065 if (ex.setConfigFile(cf))
4067 setExportMode (true);
4068 ex.exportPresentation();
4069 setExportMode (false);
4076 //////////////////////////////////////////////
4078 //////////////////////////////////////////////
4080 void VymModel::registerEditor(QWidget *me)
4082 mapEditor=(MapEditor*)me;
4085 void VymModel::unregisterEditor(QWidget *)
4090 void VymModel::setContextPos(QPointF p)
4095 void VymModel::unsetContextPos()
4097 contextPos=QPointF();
4100 void VymModel::updateNoteFlag()
4103 TreeItem *selti=getSelectedItem();
4106 if (textEditor->isEmpty())
4109 selti->setNote (textEditor->getText());
4110 emitDataHasChanged(selti);
4111 emitSelectionChanged();
4116 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4118 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4119 if (blockReposition) return;
4121 for (int i=0;i<rootItem->branchCount(); i++)
4122 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4123 //emitSelectionChanged();
4127 void VymModel::setMapLinkStyle (const QString & s)
4132 case LinkableMapObj::Line :
4135 case LinkableMapObj::Parabel:
4136 snow="StyleParabel";
4138 case LinkableMapObj::PolyLine:
4139 snow="StylePolyLine";
4141 case LinkableMapObj::PolyParabel:
4142 snow="StylePolyParabel";
4145 snow="UndefinedStyle";
4150 QString("setMapLinkStyle (\"%1\")").arg(s),
4151 QString("setMapLinkStyle (\"%1\")").arg(snow),
4152 QString("Set map link style (\"%1\")").arg(s)
4156 linkstyle=LinkableMapObj::Line;
4157 else if (s=="StyleParabel")
4158 linkstyle=LinkableMapObj::Parabel;
4159 else if (s=="StylePolyLine")
4160 linkstyle=LinkableMapObj::PolyLine;
4161 else if (s=="StylePolyParabel")
4162 linkstyle=LinkableMapObj::PolyParabel;
4164 linkstyle=LinkableMapObj::UndefinedStyle;
4166 BranchItem *cur=NULL;
4167 BranchItem *prev=NULL;
4172 bo=(BranchObj*)(cur->getLMO() );
4173 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4179 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4184 void VymModel::setMapDefLinkColor(QColor col)
4186 if ( !col.isValid() ) return;
4188 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4189 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4190 QString("Set map link color to %1").arg(col.name())
4194 BranchItem *cur=NULL;
4195 BranchItem *prev=NULL;
4200 bo=(BranchObj*)(cur->getLMO() );
4207 void VymModel::setMapLinkColorHintInt()
4209 // called from setMapLinkColorHint(lch) or at end of parse
4210 BranchItem *cur=NULL;
4211 BranchItem *prev=NULL;
4216 bo=(BranchObj*)(cur->getLMO() );
4222 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4225 setMapLinkColorHintInt();
4228 void VymModel::toggleMapLinkColorHint()
4230 if (linkcolorhint==LinkableMapObj::HeadingColor)
4231 linkcolorhint=LinkableMapObj::DefaultColor;
4233 linkcolorhint=LinkableMapObj::HeadingColor;
4234 BranchItem *cur=NULL;
4235 BranchItem *prev=NULL;
4240 bo=(BranchObj*)(cur->getLMO() );
4246 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4247 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4249 Q3FileDialog *fd=new Q3FileDialog( NULL);
4250 fd->setMode (Q3FileDialog::ExistingFile);
4251 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4252 ImagePreview *p =new ImagePreview (fd);
4253 fd->setContentsPreviewEnabled( TRUE );
4254 fd->setContentsPreview( p, p );
4255 fd->setPreviewMode( Q3FileDialog::Contents );
4256 fd->setCaption(vymName+" - " +tr("Load background image"));
4257 fd->setDir (lastImageDir);
4260 if ( fd->exec() == QDialog::Accepted )
4262 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4263 lastImageDir=QDir (fd->dirPath());
4264 setMapBackgroundImage (fd->selectedFile());
4268 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4270 QColor oldcol=mapScene->backgroundBrush().color();
4274 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4276 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4277 QString("Set background color of map to %1").arg(col.name()));
4280 brush.setTextureImage (QPixmap (fn));
4281 mapScene->setBackgroundBrush(brush);
4284 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4286 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4287 if ( !col.isValid() ) return;
4288 setMapBackgroundColor( col );
4292 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4294 QColor oldcol=mapScene->backgroundBrush().color();
4296 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4297 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4298 QString("Set background color of map to %1").arg(col.name()));
4299 mapScene->setBackgroundBrush(col);
4302 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4304 return mapScene->backgroundBrush().color();
4308 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4310 return linkcolorhint;
4313 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4315 return defLinkColor;
4318 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4323 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4325 return defXLinkColor;
4328 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4333 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4335 return defXLinkWidth;
4338 void VymModel::move(const double &x, const double &y)
4341 MapItem *seli = (MapItem*)getSelectedItem();
4342 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4344 LinkableMapObj *lmo=seli->getLMO();
4347 QPointF ap(lmo->getAbsPos());
4351 QString ps=qpointFToString(ap);
4352 QString s=getSelectString(seli);
4355 s, "move "+qpointFToString(to),
4356 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4359 emitSelectionChanged();
4365 void VymModel::moveRel (const double &x, const double &y)
4368 MapItem *seli = (MapItem*)getSelectedItem();
4369 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4371 LinkableMapObj *lmo=seli->getLMO();
4374 QPointF rp(lmo->getRelPos());
4378 QString ps=qpointFToString (lmo->getRelPos());
4379 QString s=getSelectString(seli);
4382 s, "moveRel "+qpointFToString(to),
4383 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4384 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4386 lmo->updateLinkGeometry();
4387 emitSelectionChanged();
4394 void VymModel::animate()
4396 animationTimer->stop();
4399 while (i<animObjList.size() )
4401 bo=(BranchObj*)animObjList.at(i);
4406 animObjList.removeAt(i);
4413 QItemSelection sel=selModel->selection();
4414 emit (selectionChanged(sel,sel));
4417 if (!animObjList.isEmpty()) animationTimer->start();
4421 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4423 if (start==dest) return;
4424 if (bo && bo->getTreeItem()->depth()>0)
4427 ap.setStart (start);
4429 ap.setTicks (animationTicks);
4430 ap.setAnimated (true);
4431 bo->setAnimation (ap);
4432 animObjList.append( bo );
4433 animationTimer->setSingleShot (true);
4434 animationTimer->start(animationInterval);
4438 void VymModel::stopAnimation (MapObj *mo)
4440 int i=animObjList.indexOf(mo);
4442 animObjList.removeAt (i);
4445 void VymModel::sendSelection()
4447 if (netstate!=Server) return;
4448 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4451 void VymModel::newServer()
4455 tcpServer = new QTcpServer(this);
4456 if (!tcpServer->listen(QHostAddress::Any,port)) {
4457 QMessageBox::critical(NULL, "vym server",
4458 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4459 //FIXME-3 needed? we are no widget any longer... close();
4462 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4464 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4467 void VymModel::connectToServer()
4470 server="salam.suse.de";
4472 clientSocket = new QTcpSocket (this);
4473 clientSocket->abort();
4474 clientSocket->connectToHost(server ,port);
4475 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4476 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4477 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4479 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4484 void VymModel::newClient()
4486 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4487 connect(newClient, SIGNAL(disconnected()),
4488 newClient, SLOT(deleteLater()));
4490 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4492 clientList.append (newClient);
4496 void VymModel::sendData(const QString &s)
4498 if (clientList.size()==0) return;
4500 // Create bytearray to send
4502 QDataStream out(&block, QIODevice::WriteOnly);
4503 out.setVersion(QDataStream::Qt_4_0);
4505 // Reserve some space for blocksize
4508 // Write sendCounter
4509 out << sendCounter++;
4514 // Go back and write blocksize so far
4515 out.device()->seek(0);
4516 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4520 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4522 for (int i=0; i<clientList.size(); ++i)
4524 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4525 clientList.at(i)->write (block);
4529 void VymModel::readData ()
4531 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4534 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4538 QDataStream in(clientSocket);
4539 in.setVersion(QDataStream::Qt_4_0);
4547 cout << " t="<<qPrintable (t)<<endl;
4553 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4555 switch (socketError) {
4556 case QAbstractSocket::RemoteHostClosedError:
4558 case QAbstractSocket::HostNotFoundError:
4559 QMessageBox::information(NULL, vymName +" Network client",
4560 "The host was not found. Please check the "
4561 "host name and port settings.");
4563 case QAbstractSocket::ConnectionRefusedError:
4564 QMessageBox::information(NULL, vymName + " Network client",
4565 "The connection was refused by the peer. "
4566 "Make sure the fortune server is running, "
4567 "and check that the host name and port "
4568 "settings are correct.");
4571 QMessageBox::information(NULL, vymName + " Network client",
4572 QString("The following error occurred: %1.")
4573 .arg(clientSocket->errorString()));
4577 /* FIXME-3 Playing with DBUS...
4578 QDBusVariant VymModel::query (const QString &query)
4580 TreeItem *selti=getSelectedItem();
4582 return QDBusVariant (selti->getHeading());
4584 return QDBusVariant ("Nothing selected.");
4588 void VymModel::testslot() //FIXME-3 Playing with DBUS
4590 cout << "VM::testslot called\n";
4593 void VymModel::selectMapSelectionColor()
4595 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4596 setSelectionColor (col);
4599 void VymModel::setSelectionColorInt (QColor col)
4601 if ( !col.isValid() ) return;
4603 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4604 QString("setSelectionColor (%1)").arg(col.name()),
4605 QString("Set color of selection box to %1").arg(col.name())
4608 mapEditor->setSelectionColor (col);
4611 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4613 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4614 //FIXME-3 emitShowSelection();
4618 void VymModel::emitSelectionChanged()
4620 QItemSelection newsel=selModel->selection();
4621 emitSelectionChanged (newsel);
4624 void VymModel::setSelectionColor(QColor col)
4626 if ( !col.isValid() ) return;
4628 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4629 QString("setSelectionColor (%1)").arg(col.name()),
4630 QString("Set color of selection box to %1").arg(col.name())
4632 setSelectionColorInt (col);
4635 QColor VymModel::getSelectionColor()
4637 return mapEditor->getSelectionColor();
4640 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4643 for (int i=0;i<rootItem->childCount();i++)
4644 rootItem->child(i)->setHideTmp (mode);
4646 // FIXME-3 needed? scene()->update();
4649 //////////////////////////////////////////////
4650 // Selection related
4651 //////////////////////////////////////////////
4653 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4658 QItemSelectionModel* VymModel::getSelectionModel()
4663 void VymModel::setSelectionBlocked (bool b)
4668 bool VymModel::isSelectionBlocked()
4670 return selectionBlocked;
4673 bool VymModel::select ()
4675 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4678 bool VymModel::select (const QString &s)
4685 TreeItem *ti=findBySelectString(s);
4686 if (ti) return select (index(ti));
4690 bool VymModel::select (LinkableMapObj *lmo)
4692 QItemSelection oldsel=selModel->selection();
4695 return select (index (lmo->getTreeItem()) );
4700 bool VymModel::select (TreeItem *ti)
4702 if (ti) return select (index(ti));
4706 bool VymModel::select (const QModelIndex &index)
4708 if (index.isValid() )
4710 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4711 BranchItem *bi=getSelectedBranch();
4712 if (bi) bi->setLastSelectedBranch();
4718 void VymModel::unselect()
4720 lastSelectString=getSelectString();
4721 selModel->clearSelection();
4724 bool VymModel::reselect()
4726 return select (lastSelectString);
4729 void VymModel::emitShowSelection()
4731 if (!blockReposition)
4732 emit (showSelection() );
4735 void VymModel::emitNoteHasChanged (TreeItem *ti)
4737 QModelIndex ix=index(ti);
4738 emit (noteHasChanged (ix) );
4741 void VymModel::emitDataHasChanged (TreeItem *ti)
4743 QModelIndex ix=index(ti);
4744 emit (dataChanged (ix,ix) );
4748 bool VymModel::selectFirstBranch()
4750 TreeItem *ti=getSelectedBranch();
4753 TreeItem *par=ti->parent();
4756 TreeItem *ti2=par->getFirstBranch();
4757 if (ti2) return select(ti2);
4763 bool VymModel::selectLastBranch()
4765 TreeItem *ti=getSelectedBranch();
4768 TreeItem *par=ti->parent();
4771 TreeItem *ti2=par->getLastBranch();
4772 if (ti2) return select(ti2);
4778 bool VymModel::selectLastSelectedBranch()
4780 BranchItem *bi=getSelectedBranch();
4783 bi=bi->getLastSelectedBranch();
4784 if (bi) return select (bi);
4789 bool VymModel::selectParent()
4791 TreeItem *ti=getSelectedItem();
4802 TreeItem::Type VymModel::selectionType()
4804 QModelIndexList list=selModel->selectedIndexes();
4805 if (list.isEmpty()) return TreeItem::Undefined;
4806 TreeItem *ti = getItem (list.first() );
4807 return ti->getType();
4811 LinkableMapObj* VymModel::getSelectedLMO()
4813 QModelIndexList list=selModel->selectedIndexes();
4814 if (!list.isEmpty() )
4816 TreeItem *ti = getItem (list.first() );
4817 TreeItem::Type type=ti->getType();
4818 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4819 return ((MapItem*)ti)->getLMO();
4824 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4826 TreeItem *ti = getSelectedBranch();
4828 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4833 BranchItem* VymModel::getSelectedBranch()
4835 QModelIndexList list=selModel->selectedIndexes();
4836 if (!list.isEmpty() )
4838 TreeItem *ti = getItem (list.first() );
4839 TreeItem::Type type=ti->getType();
4840 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4841 return (BranchItem*)ti;
4846 ImageItem* VymModel::getSelectedImage()
4848 QModelIndexList list=selModel->selectedIndexes();
4849 if (!list.isEmpty())
4851 TreeItem *ti=getItem (list.first());
4852 if (ti && ti->getType()==TreeItem::Image)
4853 return (ImageItem*)ti;
4858 AttributeItem* VymModel::getSelectedAttribute()
4860 QModelIndexList list=selModel->selectedIndexes();
4861 if (!list.isEmpty() )
4863 TreeItem *ti = getItem (list.first() );
4864 TreeItem::Type type=ti->getType();
4865 if (type ==TreeItem::Attribute)
4866 return (AttributeItem*)ti;
4871 TreeItem* VymModel::getSelectedItem()
4873 QModelIndexList list=selModel->selectedIndexes();
4874 if (!list.isEmpty() )
4875 return getItem (list.first() );
4880 QModelIndex VymModel::getSelectedIndex()
4882 QModelIndexList list=selModel->selectedIndexes();
4883 if (list.isEmpty() )
4884 return QModelIndex();
4886 return list.first();
4889 QString VymModel::getSelectString ()
4891 return getSelectString (getSelectedItem());
4894 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
4896 if (!lmo) return QString();
4897 return getSelectString (lmo->getTreeItem() );
4900 QString VymModel::getSelectString (TreeItem *ti)
4904 switch (ti->getType())
4906 case TreeItem::MapCenter: s="mc:"; break;
4907 case TreeItem::Branch: s="bo:";break;
4908 case TreeItem::Image: s="fi:";break;
4909 case TreeItem::Attribute: s="ai:";break;
4910 case TreeItem::XLink: s="xl:";break;
4912 s="unknown type in VymModel::getSelectString()";
4915 s= s + QString("%1").arg(ti->num());
4917 // call myself recursively
4918 s= getSelectString(ti->parent()) +","+s;