1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
18 #include "warningdialog.h"
19 #include "xlinkitem.h"
20 #include "xml-freemind.h"
26 extern Main *mainWindow;
27 extern QDBusConnection dbusConnection;
29 extern Settings settings;
30 extern QString tmpVymDir;
32 extern TextEditor *textEditor;
33 extern FlagRow *standardFlagsMaster;
35 extern QString clipboardDir;
36 extern QString clipboardFile;
37 extern bool clipboardEmpty;
39 extern ImageIO imageIO;
41 extern QString vymName;
42 extern QString vymVersion;
43 extern QDir vymBaseDir;
45 extern QDir lastImageDir;
46 extern QDir lastFileDir;
48 extern Settings settings;
52 int VymModel::mapNum=0; // make instance
56 // cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 selModel->clearSelection();
74 //QModelIndex ri=index(rootItem);
75 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
78 void VymModel::init ()
83 // Also no scene yet (should not be needed anyway) FIXME-3 VM
96 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
97 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
98 mainWindow->updateHistory (undoSet);
101 makeTmpDirectories();
106 fileName=tr("unnamed");
108 blockReposition=false;
109 blockSaveState=false;
111 autosaveTimer=new QTimer (this);
112 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
114 fileChangedTimer=new QTimer (this);
115 fileChangedTimer->start(3000);
116 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
121 selectionBlocked=false;
128 // animations // FIXME-3 switch to new animation system
129 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
130 animationTicks=settings.readNumEntry("/animation/ticks",10);
131 animationInterval=settings.readNumEntry("/animation/interval",50);
133 animationTimer=new QTimer (this);
134 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
137 defLinkColor=QColor (0,0,255);
138 defXLinkColor=QColor (180,180,180);
139 linkcolorhint=LinkableMapObj::DefaultColor;
140 linkstyle=LinkableMapObj::PolyParabel;
142 defXLinkColor=QColor (230,230,230);
144 hidemode=TreeItem::HideNone;
150 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
153 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
154 //adaptor->setModel (this);
155 //connection.registerObject("/Car", car);
156 dbusConnection.registerService("org.insilmaril.VymModel");
157 dbusConnection.sessionBus().registerObject ("/Object1",this);
160 void VymModel::makeTmpDirectories()
162 // Create unique temporary directories
163 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
164 histPath = tmpMapDir+"/history";
170 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
175 bool VymModel::isRepositionBlocked()
177 return blockReposition;
180 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
182 //cout << "VM::updateActions \n";
183 // Tell mainwindow to update states of actions
184 mainWindow->updateActions();
189 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
191 // tmpdir temporary directory to which data will be written
192 // prefix mapname, which will be appended to images etc.
193 // writeflags Only write flags for "real" save of map, not undo
194 // offset offset of bbox of whole map in scene.
195 // Needed for XML export
204 case LinkableMapObj::Line:
207 case LinkableMapObj::Parabel:
210 case LinkableMapObj::PolyLine:
214 ls="StylePolyParabel";
218 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
220 if (linkcolorhint==LinkableMapObj::HeadingColor)
221 colhint=xml.attribut("linkColorHint","HeadingColor");
223 QString mapAttr=xml.attribut("version",vymVersion);
225 mapAttr+= xml.attribut("author",author) +
226 xml.attribut("comment",comment) +
227 xml.attribut("date",getDate()) +
228 xml.attribut("branchCount", QString().number(branchCount())) +
229 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
230 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
231 xml.attribut("linkStyle", ls ) +
232 xml.attribut("linkColor", defLinkColor.name() ) +
233 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
234 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
236 s+=xml.beginElement("vymmap",mapAttr);
239 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
240 standardFlagsMaster->resetUsedCounter();
242 // Build xml recursivly
244 // Save all mapcenters as complete map, if saveSel not set
245 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
248 switch (saveSel->getType())
250 case TreeItem::Branch:
252 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
254 case TreeItem::MapCenter:
256 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
258 case TreeItem::Image:
260 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
263 // other types shouldn't be safed directly...
268 // Save local settings
269 s+=settings.getDataXML (destPath);
272 if (getSelectedItem() && !saveSel )
273 s+=xml.valueElement("select",getSelectString());
276 s+=xml.endElement("vymmap");
278 //cout << s.toStdString() << endl;
280 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
284 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
288 for (int i=0; i<rootItem->branchCount(); i++)
289 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
293 void VymModel::setFilePath(QString fpath, QString destname)
295 if (fpath.isEmpty() || fpath=="")
302 filePath=fpath; // becomes absolute path
303 fileName=fpath; // gets stripped of path
304 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
306 // If fpath is not an absolute path, complete it
307 filePath=QDir(fpath).absPath();
308 fileDir=filePath.left (1+filePath.findRev ("/"));
310 // Set short name, too. Search from behind:
311 int i=fileName.findRev("/");
312 if (i>=0) fileName=fileName.remove (0,i+1);
314 // Forget the .vym (or .xml) for name of map
315 mapName=fileName.left(fileName.findRev(".",-1,true) );
319 void VymModel::setFilePath(QString fpath)
321 setFilePath (fpath,fpath);
324 QString VymModel::getFilePath()
329 QString VymModel::getFileName()
334 QString VymModel::getMapName()
339 QString VymModel::getDestPath()
344 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
346 ErrorCode err=success;
348 parseBaseHandler *handler;
352 case VymMap: handler=new parseVYMHandler; break;
353 case FreemindMap : handler=new parseFreemindHandler; break;
355 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
356 "Unknown FileType in VymModel::load()");
360 bool zipped_org=zipped;
364 selModel->clearSelection();
365 // FIXME-2 VM not needed??? model->setMapEditor(this);
366 // (map state is set later at end of load...)
369 BranchItem *bi=getSelectedBranch();
370 if (!bi) return aborted;
371 if (lmode==ImportAdd)
372 saveStateChangingPart(
375 QString("addMapInsert (%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
378 saveStateChangingPart(
381 QString("addMapReplace(%1)").arg(fname),
382 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
386 // Create temporary directory for packing
388 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
391 QMessageBox::critical( 0, tr( "Critical Load Error" ),
392 tr("Couldn't create temporary directory before load\n"));
397 err=unzipDir (tmpZipDir,fname);
407 // Look for mapname.xml
408 xmlfile= fname.left(fname.findRev(".",-1,true));
409 xmlfile=xmlfile.section( '/', -1 );
410 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
411 if (!mfile.exists() )
413 // mapname.xml does not exist, well,
414 // maybe someone renamed the mapname.vym file...
415 // Try to find any .xml in the toplevel
416 // directory of the .vym file
417 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
418 if (flist.count()==1)
420 // Only one entry, take this one
421 xmlfile=tmpZipDir + "/"+flist.first();
424 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
425 *it=tmpZipDir + "/" + *it;
426 // TODO Multiple entries, load all (but only the first one into this ME)
427 //mainWindow->fileLoadFromTmp (flist);
428 //returnCode=1; // Silently forget this attempt to load
429 qWarning ("MainWindow::load (fn) multimap found...");
432 if (flist.isEmpty() )
434 QMessageBox::critical( 0, tr( "Critical Load Error" ),
435 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
438 } //file doesn't exist
440 xmlfile=mfile.name();
443 QFile file( xmlfile);
445 // I am paranoid: file should exist anyway
446 // according to check in mainwindow.
449 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
450 tr(QString("Couldn't open map %1").arg(file.name())));
454 bool blockSaveStateOrg=blockSaveState;
455 blockReposition=true;
457 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
458 QXmlInputSource source( file);
459 QXmlSimpleReader reader;
460 reader.setContentHandler( handler );
461 reader.setErrorHandler( handler );
462 handler->setModel ( this);
465 // We need to set the tmpDir in order to load files with rel. path
470 tmpdir=fname.left(fname.findRev("/",-1));
471 handler->setTmpDir (tmpdir);
472 handler->setInputFile (file.name());
473 handler->setLoadMode (lmode);
474 bool ok = reader.parse( source );
475 blockReposition=false;
476 blockSaveState=blockSaveStateOrg;
477 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
481 reposition(); // FIXME-2 VM reposition the view instead...
482 emitSelectionChanged();
488 autosaveTimer->stop();
491 // Reset timestamp to check for later updates of file
492 fileChangedTime=QFileInfo (destPath).lastModified();
495 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
496 tr( handler->errorProtocol() ) );
498 // Still return "success": the map maybe at least
499 // partially read by the parser
504 removeDir (QDir(tmpZipDir));
506 // Restore original zip state
513 ErrorCode VymModel::save (const SaveMode &savemode)
517 QString safeFilePath;
519 ErrorCode err=success;
523 mapFileName=mapName+".xml";
525 // use name given by user, even if he chooses .doc
526 mapFileName=fileName;
528 // Look, if we should zip the data:
531 QMessageBox mb( vymName,
532 tr("The map %1\ndid not use the compressed "
533 "vym file format.\nWriting it uncompressed will also write images \n"
534 "and flags and thus may overwrite files in the "
535 "given directory\n\nDo you want to write the map").arg(filePath),
536 QMessageBox::Warning,
537 QMessageBox::Yes | QMessageBox::Default,
539 QMessageBox::Cancel | QMessageBox::Escape);
540 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
541 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
542 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
545 case QMessageBox::Yes:
546 // save compressed (default file format)
549 case QMessageBox::No:
553 case QMessageBox::Cancel:
560 // First backup existing file, we
561 // don't want to add to old zip archives
565 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
567 QString backupFileName(destPath + "~");
568 QFile backupFile(backupFileName);
569 if (backupFile.exists() && !backupFile.remove())
571 QMessageBox::warning(0, tr("Save Error"),
572 tr("%1\ncould not be removed before saving").arg(backupFileName));
574 else if (!f.rename(backupFileName))
576 QMessageBox::warning(0, tr("Save Error"),
577 tr("%1\ncould not be renamed before saving").arg(destPath));
584 // Create temporary directory for packing
586 tmpZipDir=makeTmpDir (ok,"vym-zip");
589 QMessageBox::critical( 0, tr( "Critical Load Error" ),
590 tr("Couldn't create temporary directory before save\n"));
594 safeFilePath=filePath;
595 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
598 // Create mapName and fileDir
599 makeSubDirs (fileDir);
602 if (savemode==CompleteMap || selModel->selection().isEmpty())
605 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
608 autosaveTimer->stop();
613 if (selectionType()==TreeItem::Image)
616 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
617 // TODO take care of multiselections
620 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
623 qWarning ("ME::saveStringToDisk failed!");
629 if (err==success) err=zipDir (tmpZipDir,destPath);
632 removeDir (QDir(tmpZipDir));
634 // Restore original filepath outside of tmp zip dir
635 setFilePath (safeFilePath);
639 fileChangedTime=QFileInfo (destPath).lastModified();
643 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
645 QString pathDir=path.left(path.findRev("/"));
651 // We need to parse saved XML data
652 parseVYMHandler handler;
653 QXmlInputSource source( file);
654 QXmlSimpleReader reader;
655 reader.setContentHandler( &handler );
656 reader.setErrorHandler( &handler );
657 handler.setModel ( this);
658 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
659 if (undoSel.isEmpty())
663 handler.setLoadMode (NewMap);
667 handler.setLoadMode (ImportReplace);
669 blockReposition=true;
670 bool ok = reader.parse( source );
671 blockReposition=false;
674 // This should never ever happen
675 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
676 handler.errorProtocol());
679 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
682 bool VymModel::addMapInsertInt (const QString &path)
684 QString pathDir=path.left(path.findRev("/"));
690 // We need to parse saved XML data
691 parseVYMHandler handler;
692 QXmlInputSource source( file);
693 QXmlSimpleReader reader;
694 reader.setContentHandler( &handler );
695 reader.setErrorHandler( &handler );
696 handler.setModel (this);
697 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
698 handler.setLoadMode (ImportAdd);
699 blockReposition=true;
700 bool ok = reader.parse( source );
701 blockReposition=false;
702 if ( ok ) return true;
704 // This should never ever happen
705 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
706 handler.errorProtocol());
709 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
713 bool VymModel::addMapInsertInt (const QString &path, int pos)
715 BranchItem *selbi=getSelectedBranch();
718 if (addMapInsertInt (path))
720 if (selbi->depth()>0)
721 relinkBranch (selbi->getLastBranch(), selbi,pos);
725 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
729 qWarning ("ME::addMapInsertInt nothing selected");
733 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
735 ImageItem *ii=createImage(dst);
745 void VymModel::loadFloatImage ()
747 BranchItem *selbi=getSelectedBranch();
751 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
752 fd->setMode (Q3FileDialog::ExistingFiles);
753 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
754 ImagePreview *p =new ImagePreview (fd);
755 fd->setContentsPreviewEnabled( TRUE );
756 fd->setContentsPreview( p, p );
757 fd->setPreviewMode( Q3FileDialog::Contents );
758 fd->setCaption(vymName+" - " +tr("Load image"));
759 fd->setDir (lastImageDir);
762 if ( fd->exec() == QDialog::Accepted )
764 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
765 lastImageDir=QDir (fd->dirPath());
768 for (int j=0; j<fd->selectedFiles().count(); j++)
770 s=fd->selectedFiles().at(j);
771 ii=loadFloatImageInt (selbi,s);
772 //FIXME-3 check savestate for loadImage
778 QString ("loadImage (%1)").arg(s ),
779 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
782 // TODO loadFIO error handling
783 qWarning ("Failed to load "+s);
791 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
796 void VymModel::saveFloatImage ()
798 ImageItem *ii=getSelectedImage();
801 QFileDialog *fd=new QFileDialog( NULL);
802 fd->setFilters (imageIO.getFilters());
803 fd->setCaption(vymName+" - " +tr("Save image"));
804 fd->setFileMode( QFileDialog::AnyFile );
805 fd->setDirectory (lastImageDir);
806 // fd->setSelection (fio->getOriginalFilename());
810 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
812 fn=fd->selectedFiles().at(0);
813 if (QFile (fn).exists() )
815 QMessageBox mb( vymName,
816 tr("The file %1 exists already.\n"
817 "Do you want to overwrite it?").arg(fn),
818 QMessageBox::Warning,
819 QMessageBox::Yes | QMessageBox::Default,
820 QMessageBox::Cancel | QMessageBox::Escape,
821 QMessageBox::NoButton );
823 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
824 mb.setButtonText( QMessageBox::No, tr("Cancel"));
827 case QMessageBox::Yes:
830 case QMessageBox::Cancel:
837 saveFloatImageInt (ii,fd->selectedFilter(),fn );
844 void VymModel::importDirInt(BranchItem *dst, QDir d)
846 BranchItem *selbi=getSelectedBranch();
850 // Traverse directories
851 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
852 QFileInfoList list = d.entryInfoList();
855 for (int i = 0; i < list.size(); ++i)
858 if (fi.fileName() != "." && fi.fileName() != ".." )
860 bi=addNewBranchInt(dst,-2);
861 bi->setHeading (fi.fileName() ); // FIXME-3 check this
862 bi->setHeadingColor (QColor("blue"));
864 if ( !d.cd(fi.fileName()) )
865 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
868 // Recursively add subdirs
875 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
876 list = d.entryInfoList();
878 for (int i = 0; i < list.size(); ++i)
881 bi=addNewBranchInt (dst,-2);
882 bi->setHeading (fi.fileName() );
883 bi->setHeadingColor (QColor("black"));
884 if (fi.fileName().right(4) == ".vym" )
885 bi->setVymLink (fi.filePath());
890 void VymModel::importDirInt (const QString &s)
892 BranchItem *selbi=getSelectedBranch();
895 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
898 importDirInt (selbi,d);
902 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
904 BranchItem *selbi=getSelectedBranch();
908 filters <<"VYM map (*.vym)";
909 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
910 fd->setMode (QFileDialog::DirectoryOnly);
911 fd->setFilters (filters);
912 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
916 if ( fd->exec() == QDialog::Accepted )
918 importDirInt (fd->selectedFile() );
920 //FIXME-3 VM needed? scene()->update();
926 void VymModel::autosave()
931 cout << "VymModel::autosave rejected due to missing filePath\n";
934 QDateTime now=QDateTime().currentDateTime();
936 // Disable autosave, while we have gone back in history
937 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
938 if (redosAvail>0) return;
940 // Also disable autosave for new map without filename
941 if (filePath.isEmpty()) return;
944 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
946 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
947 mainWindow->fileSave (this);
950 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
955 void VymModel::fileChanged()
957 // Check if file on disk has changed meanwhile
958 if (!filePath.isEmpty())
960 QDateTime tmod=QFileInfo (filePath).lastModified();
961 if (tmod>fileChangedTime)
963 // FIXME-2 VM switch to current mapeditor and finish lineedits...
964 QMessageBox mb( vymName,
965 tr("The file of the map on disk has changed:\n\n"
966 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
967 QMessageBox::Question,
969 QMessageBox::Cancel | QMessageBox::Default,
970 QMessageBox::NoButton );
972 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
973 mb.setButtonText( QMessageBox::No, tr("Ignore"));
976 case QMessageBox::Yes:
978 load (filePath,NewMap,fileType);
979 case QMessageBox::Cancel:
980 fileChangedTime=tmod; // allow autosave to overwrite newer file!
986 bool VymModel::isDefault()
991 void VymModel::makeDefault()
997 bool VymModel::hasChanged()
1002 void VymModel::setChanged()
1005 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1009 latestAddedItem=NULL;
1013 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1015 if (!lmo || !lmo->getTreeItem() ) return QString();
1016 return getObjectName (lmo->getTreeItem() );
1020 QString VymModel::getObjectName (TreeItem *ti)
1023 if (!ti) return QString("Error: NULL has no name!");
1025 if (s=="") s="unnamed";
1027 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1030 void VymModel::redo()
1032 // Can we undo at all?
1033 if (redosAvail<1) return;
1035 bool blockSaveStateOrg=blockSaveState;
1036 blockSaveState=true;
1040 if (undosAvail<stepsTotal) undosAvail++;
1042 if (curStep>stepsTotal) curStep=1;
1043 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1044 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1045 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1046 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1047 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1048 QString version=undoSet.readEntry ("/history/version");
1050 /* TODO Maybe check for version, if we save the history
1051 if (!checkVersion(version))
1052 QMessageBox::warning(0,tr("Warning"),
1053 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1056 // Find out current undo directory
1057 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1061 cout << "VymModel::redo() begin\n";
1062 cout << " undosAvail="<<undosAvail<<endl;
1063 cout << " redosAvail="<<redosAvail<<endl;
1064 cout << " curStep="<<curStep<<endl;
1065 cout << " ---------------------------"<<endl;
1066 cout << " comment="<<comment.toStdString()<<endl;
1067 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1068 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1069 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1070 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1071 cout << " ---------------------------"<<endl<<endl;
1074 // select object before redo
1075 if (!redoSelection.isEmpty())
1076 select (redoSelection);
1079 parseAtom (redoCommand);
1081 blockSaveState=blockSaveStateOrg;
1083 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1084 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1085 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1086 undoSet.writeSettings(histPath);
1088 mainWindow->updateHistory (undoSet);
1091 /* TODO remove testing
1092 cout << "ME::redo() end\n";
1093 cout << " undosAvail="<<undosAvail<<endl;
1094 cout << " redosAvail="<<redosAvail<<endl;
1095 cout << " curStep="<<curStep<<endl;
1096 cout << " ---------------------------"<<endl<<endl;
1102 bool VymModel::isRedoAvailable()
1104 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1110 void VymModel::undo()
1112 // Can we undo at all?
1113 if (undosAvail<1) return;
1115 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1117 bool blockSaveStateOrg=blockSaveState;
1118 blockSaveState=true;
1120 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1121 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1122 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1123 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1124 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1125 QString version=undoSet.readEntry ("/history/version");
1127 /* TODO Maybe check for version, if we save the history
1128 if (!checkVersion(version))
1129 QMessageBox::warning(0,tr("Warning"),
1130 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1133 // Find out current undo directory
1134 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1136 // select object before undo
1137 if (!select (undoSelection))
1139 qWarning ("VymModel::undo() Could not select object for undo");
1145 cout << "VymModel::undo() begin\n";
1146 cout << " undosAvail="<<undosAvail<<endl;
1147 cout << " redosAvail="<<redosAvail<<endl;
1148 cout << " curStep="<<curStep<<endl;
1149 cout << " ---------------------------"<<endl;
1150 cout << " comment="<<comment.toStdString()<<endl;
1151 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1152 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1153 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1154 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1155 cout << " ---------------------------"<<endl<<endl;
1157 parseAtom (undoCommand);
1161 if (curStep<1) curStep=stepsTotal;
1165 blockSaveState=blockSaveStateOrg;
1167 cout << "VymModel::undo() end\n";
1168 cout << " undosAvail="<<undosAvail<<endl;
1169 cout << " redosAvail="<<redosAvail<<endl;
1170 cout << " curStep="<<curStep<<endl;
1171 cout << " ---------------------------"<<endl<<endl;
1174 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1175 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1176 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1177 undoSet.writeSettings(histPath);
1179 mainWindow->updateHistory (undoSet);
1181 //emitSelectionChanged();
1184 bool VymModel::isUndoAvailable()
1186 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1192 void VymModel::gotoHistoryStep (int i)
1194 // Restore variables
1195 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1196 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1198 if (i<0) i=undosAvail+redosAvail;
1200 // Clicking above current step makes us undo things
1203 for (int j=0; j<undosAvail-i; j++) undo();
1206 // Clicking below current step makes us redo things
1208 for (int j=undosAvail; j<i; j++)
1210 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1214 // And ignore clicking the current row ;-)
1218 QString VymModel::getHistoryPath()
1220 QString histName(QString("history-%1").arg(curStep));
1221 return (tmpMapDir+"/"+histName);
1224 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1226 sendData(redoCom); //FIXME-3 testing
1231 if (blockSaveState) return;
1233 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1235 // Find out current undo directory
1236 if (undosAvail<stepsTotal) undosAvail++;
1238 if (curStep>stepsTotal) curStep=1;
1240 QString backupXML="";
1241 QString histDir=getHistoryPath();
1242 QString bakMapPath=histDir+"/map.xml";
1244 // Create histDir if not available
1247 makeSubDirs (histDir);
1249 // Save depending on how much needs to be saved
1251 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1253 QString undoCommand="";
1254 if (savemode==UndoCommand)
1256 undoCommand=undoCom;
1258 else if (savemode==PartOfMap )
1260 undoCommand=undoCom;
1261 undoCommand.replace ("PATH",bakMapPath);
1265 if (!backupXML.isEmpty())
1266 // Write XML Data to disk
1267 saveStringToDisk (bakMapPath,backupXML);
1269 // We would have to save all actions in a tree, to keep track of
1270 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1273 // Write the current state to disk
1274 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1275 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1276 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1277 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1278 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1280 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1282 undoSet.setEntry (QString("/history/version"),vymVersion);
1283 undoSet.writeSettings(histPath);
1287 // TODO remove after testing
1288 //cout << " into="<< histPath.toStdString()<<endl;
1289 cout << " stepsTotal="<<stepsTotal<<
1290 ", undosAvail="<<undosAvail<<
1291 ", redosAvail="<<redosAvail<<
1292 ", curStep="<<curStep<<endl;
1293 cout << " ---------------------------"<<endl;
1294 cout << " comment="<<comment.toStdString()<<endl;
1295 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1296 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1297 cout << " redoCom="<<redoCom.toStdString()<<endl;
1298 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1299 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1300 cout << " ---------------------------"<<endl;
1303 mainWindow->updateHistory (undoSet);
1309 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1311 // save the selected part of the map, Undo will replace part of map
1312 QString undoSelection="";
1314 undoSelection=getSelectString(undoSel);
1316 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1317 QString redoSelection="";
1319 redoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1324 saveState (PartOfMap,
1325 undoSelection, "addMapReplace (\"PATH\")",
1331 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1335 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1338 QString undoSelection;
1339 QString redoSelection=getSelectString(redoSel);
1340 if (redoSel->getType()==TreeItem::Branch)
1342 undoSelection=getSelectString (redoSel->parent());
1343 // save the selected branch of the map, Undo will insert part of map
1344 saveState (PartOfMap,
1345 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1346 redoSelection, "delete ()",
1350 if (redoSel->getType()==TreeItem::MapCenter)
1352 // save the selected branch of the map, Undo will insert part of map
1353 saveState (PartOfMap,
1354 undoSelection, QString("addMapInsert (\"PATH\")"),
1355 redoSelection, "delete ()",
1362 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1364 // "Normal" savestate: save commands, selections and comment
1365 // so just save commands for undo and redo
1366 // and use current selection
1368 QString redoSelection="";
1369 if (redoSel) redoSelection=getSelectString(redoSel);
1370 QString undoSelection="";
1371 if (undoSel) undoSelection=getSelectString(undoSel);
1373 saveState (UndoCommand,
1380 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1382 // "Normal" savestate: save commands, selections and comment
1383 // so just save commands for undo and redo
1384 // and use current selection
1385 saveState (UndoCommand,
1392 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1394 // "Normal" savestate applied to model (no selection needed):
1395 // save commands and comment
1396 saveState (UndoCommand,
1404 QGraphicsScene* VymModel::getScene ()
1409 TreeItem* VymModel::findBySelectString(QString s)
1411 if (s.isEmpty() ) return NULL;
1413 // Old maps don't have multiple mapcenters and don't save full path
1414 if (s.left(2) !="mc")
1417 QStringList parts=s.split (",");
1420 TreeItem *ti=rootItem;
1422 while (!parts.isEmpty() )
1424 typ=parts.first().left(2);
1425 n=parts.first().right(parts.first().length() - 3).toInt();
1426 parts.removeFirst();
1427 if (typ=="mc" || typ=="bo")
1428 ti=ti->getBranchNum (n);
1430 ti=ti->getImageNum (n);
1432 ti=ti->getAttributeNum (n);
1434 ti=ti->getXLinkNum (n);
1435 if(!ti) return NULL;
1440 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1442 BranchItem *cur=NULL;
1443 BranchItem *prev=NULL;
1447 if (s==cur->getID() ) return cur;
1453 //////////////////////////////////////////////
1455 //////////////////////////////////////////////
1456 void VymModel::setVersion (const QString &s)
1461 void VymModel::setAuthor (const QString &s)
1464 QString ("setMapAuthor (\"%1\")").arg(author),
1465 QString ("setMapAuthor (\"%1\")").arg(s),
1466 QString ("Set author of map to \"%1\"").arg(s)
1471 QString VymModel::getAuthor()
1476 void VymModel::setComment (const QString &s)
1479 QString ("setMapComment (\"%1\")").arg(comment),
1480 QString ("setMapComment (\"%1\")").arg(s),
1481 QString ("Set comment of map")
1486 QString VymModel::getComment ()
1491 QString VymModel::getDate ()
1493 return QDate::currentDate().toString ("yyyy-MM-dd");
1496 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1499 BranchItem *cur=NULL;
1500 BranchItem *prev=NULL;
1510 void VymModel::setHeading(const QString &s)
1512 BranchItem *selbi=getSelectedBranch();
1517 "setHeading (\""+selbi->getHeading()+"\")",
1519 "setHeading (\""+s+"\")",
1520 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1521 selbi->setHeading(s );
1522 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1524 emitSelectionChanged();
1528 QString VymModel::getHeading()
1530 TreeItem *selti=getSelectedItem();
1532 return selti->getHeading();
1537 BranchItem* VymModel::findText (QString s, bool cs)
1539 QTextDocument::FindFlags flags=0;
1540 if (cs) flags=QTextDocument::FindCaseSensitively;
1543 { // Nothing found or new find process
1545 // nothing found, start again
1549 next (findCurrent,findPrevious);
1551 bool searching=true;
1552 bool foundNote=false;
1553 while (searching && !EOFind)
1557 // Searching in Note
1558 if (findCurrent->getNote().contains(s,cs))
1560 select (findCurrent);
1562 if (getSelectedBranch()!=itFind)
1565 emitShowSelection();
1568 if (textEditor->findText(s,flags))
1574 // Searching in Heading
1575 if (searching && findCurrent->getHeading().contains (s,cs) )
1577 select(findCurrent);
1583 if (!next(findCurrent,findPrevious) )
1586 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1589 return getSelectedBranch();
1594 void VymModel::findReset()
1595 { // Necessary if text to find changes during a find process
1601 void VymModel::setScene (QGraphicsScene *s)
1606 void VymModel::setURL(const QString &url)
1608 TreeItem *selti=getSelectedItem();
1611 QString oldurl=selti->getURL();
1612 selti->setURL (url);
1615 QString ("setURL (\"%1\")").arg(oldurl),
1617 QString ("setURL (\"%1\")").arg(url),
1618 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1621 emitDataHasChanged (selti);
1622 emitShowSelection();
1626 QString VymModel::getURL()
1628 TreeItem *selti=getSelectedItem();
1630 return selti->getURL();
1635 QStringList VymModel::getURLs()
1638 BranchItem *selbi=getSelectedBranch();
1639 BranchItem *cur=selbi;
1640 BranchItem *prev=NULL;
1643 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1644 cur=next (cur,prev,selbi);
1650 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1652 BranchItem *bi=getSelectedBranch();
1655 BranchObj *bo=(BranchObj*)(bi->getLMO());
1658 QString s=bo->getFrameTypeName();
1659 bo->setFrameType (t);
1660 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1661 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1663 bo->updateLinkGeometry();
1668 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1670 BranchItem *bi=getSelectedBranch();
1673 BranchObj *bo=(BranchObj*)(bi->getLMO());
1676 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1677 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1678 bo->setFrameType (s);
1680 bo->updateLinkGeometry();
1685 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1688 BranchItem *bi=getSelectedBranch();
1691 BranchObj *bo=(BranchObj*)(bi->getLMO());
1694 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1695 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1696 bo->setFramePenColor (c);
1701 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1703 BranchItem *bi=getSelectedBranch();
1706 BranchObj *bo=(BranchObj*)(bi->getLMO());
1709 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1710 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1711 bo->setFrameBrushColor (c);
1716 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1718 BranchItem *bi=getSelectedBranch();
1721 BranchObj *bo=(BranchObj*)(bi->getLMO());
1724 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1725 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1726 bo->setFramePadding (i);
1728 bo->updateLinkGeometry();
1733 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1735 BranchItem *bi=getSelectedBranch();
1738 BranchObj *bo=(BranchObj*)(bi->getLMO());
1741 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1742 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1743 bo->setFrameBorderWidth (i);
1745 bo->updateLinkGeometry();
1750 void VymModel::setIncludeImagesVer(bool b)
1752 BranchItem *bi=getSelectedBranch();
1755 QString u= b ? "false" : "true";
1756 QString r=!b ? "false" : "true";
1760 QString("setIncludeImagesVertically (%1)").arg(u),
1762 QString("setIncludeImagesVertically (%1)").arg(r),
1763 QString("Include images vertically in %1").arg(getObjectName(bi))
1765 bi->setIncludeImagesVer(b);
1766 emitDataHasChanged ( bi);
1771 void VymModel::setIncludeImagesHor(bool b)
1773 BranchItem *bi=getSelectedBranch();
1776 QString u= b ? "false" : "true";
1777 QString r=!b ? "false" : "true";
1781 QString("setIncludeImagesHorizontally (%1)").arg(u),
1783 QString("setIncludeImagesHorizontally (%1)").arg(r),
1784 QString("Include images horizontally in %1").arg(getObjectName(bi))
1786 bi->setIncludeImagesHor(b);
1787 emitDataHasChanged ( bi);
1792 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1794 TreeItem *ti=getSelectedItem();
1795 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1797 QString u= b ? "false" : "true";
1798 QString r=!b ? "false" : "true";
1802 QString("setHideLinkUnselected (%1)").arg(u),
1804 QString("setHideLinkUnselected (%1)").arg(r),
1805 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1807 ((MapItem*)ti)->setHideLinkUnselected(b);
1811 void VymModel::setHideExport(bool b)
1813 TreeItem *ti=getSelectedItem();
1815 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1817 ti->setHideInExport (b);
1818 QString u= b ? "false" : "true";
1819 QString r=!b ? "false" : "true";
1823 QString ("setHideExport (%1)").arg(u),
1825 QString ("setHideExport (%1)").arg(r),
1826 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1828 emitDataHasChanged(ti);
1829 emitSelectionChanged();
1832 // emitSelectionChanged();
1833 // FIXME-3 VM needed? scene()->update();
1837 void VymModel::toggleHideExport()
1839 TreeItem *selti=getSelectedItem();
1841 setHideExport ( !selti->hideInExport() );
1845 void VymModel::copy()
1847 TreeItem *selti=getSelectedItem();
1849 (selti->getType() == TreeItem::Branch ||
1850 selti->getType() == TreeItem::MapCenter ||
1851 selti->getType() == TreeItem::Image ))
1853 if (redosAvail == 0)
1856 QString s=getSelectString(selti);
1857 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1858 curClipboard=curStep;
1861 // Copy also to global clipboard, because we are at last step in history
1862 QString bakMapName(QString("history-%1").arg(curStep));
1863 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1864 copyDir (bakMapDir,clipboardDir );
1866 clipboardEmpty=false;
1872 void VymModel::pasteNoSave(const int &n)
1874 bool old=blockSaveState;
1875 blockSaveState=true;
1876 bool zippedOrg=zipped;
1877 if (redosAvail > 0 || n!=0)
1879 // Use the "historical" buffer
1880 QString bakMapName(QString("history-%1").arg(n));
1881 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1882 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1884 // Use the global buffer
1885 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1890 void VymModel::paste()
1892 BranchItem *selbi=getSelectedBranch();
1895 saveStateChangingPart(
1898 QString ("paste (%1)").arg(curClipboard),
1899 QString("Paste to %1").arg( getObjectName(selbi))
1906 void VymModel::cut()
1908 TreeItem *selti=getSelectedItem();
1909 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1917 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
1919 if (bi && bi->canMoveUp())
1920 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
1925 void VymModel::moveUp()
1927 BranchItem *selbi=getSelectedBranch();
1930 QString oldsel=getSelectString();
1933 getSelectString(),"moveDown ()",
1935 QString("Move up %1").arg(getObjectName(selbi)));
1939 bool VymModel::moveDown(BranchItem *bi)
1941 if (bi && bi->canMoveDown())
1942 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
1947 void VymModel::moveDown()
1949 BranchItem *selbi=getSelectedBranch();
1952 QString oldsel=getSelectString();
1953 if ( moveDown(selbi))
1955 getSelectString(),"moveUp ()",
1956 oldsel,"moveDown ()",
1957 QString("Move down %1").arg(getObjectName(selbi)));
1961 void VymModel::detach()
1963 BranchItem *selbi=getSelectedBranch();
1964 if (selbi && selbi->depth()>0)
1966 //QString oldsel=getSelectString();
1967 if ( relinkBranch (selbi,rootItem,-1) )
1969 selbi,QString("relink()"), //FIXME-1 add paramters
1971 QString("Detach %1").arg(getObjectName(selbi))
1976 void VymModel::sortChildren()
1978 BranchItem* selbi=getSelectedBranch();
1981 if(selbi->branchCount()>1)
1983 saveStateChangingPart(
1984 selbi,selbi, "sortChildren ()",
1985 QString("Sort children of %1").arg(getObjectName(selbi)));
1986 selbi->sortChildren();
1988 emitShowSelection();
1993 BranchItem* VymModel::createMapCenter()
1995 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1999 BranchItem* VymModel::createBranch(BranchItem *dst)
2002 return addNewBranchInt (dst,-2);
2007 ImageItem* VymModel::createImage(BranchItem *dst)
2014 QList<QVariant> cData;
2015 cData << "new" << "undef";
2017 ImageItem *newii=new ImageItem(cData) ;
2018 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2020 emit (layoutAboutToBeChanged() );
2023 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2024 n=dst->getRowNumAppend(newii);
2025 beginInsertRows (parix,n,n);
2026 dst->appendChild (newii);
2029 emit (layoutChanged() );
2031 // save scroll state. If scrolled, automatically select
2032 // new branch in order to tmp unscroll parent...
2033 newii->createMapObj(mapScene);
2040 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2047 QList<QVariant> cData;
2048 cData << "new xLink"<<"undef";
2050 XLinkItem *newxli=new XLinkItem(cData) ;
2051 newxli->setBegin (bi);
2053 emit (layoutAboutToBeChanged() );
2056 n=bi->getRowNumAppend(newxli);
2057 beginInsertRows (parix,n,n);
2058 bi->appendChild (newxli);
2061 emit (layoutChanged() );
2063 // save scroll state. If scrolled, automatically select
2064 // new branch in order to tmp unscroll parent...
2067 newxli->createMapObj(mapScene);
2075 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2077 BranchItem *selbi=getSelectedBranch();
2080 QList<QVariant> cData;
2081 cData << "new attribute" << "undef";
2082 AttributeItem *a=new AttributeItem (cData);
2084 emit (layoutAboutToBeChanged() );
2086 QModelIndex parix=index(selbi);
2087 int n=selbi->getRowNumAppend (a);
2088 beginInsertRows (parix,n,n);
2089 selbi->appendChild (a);
2092 emit (layoutChanged() );
2100 BranchItem* VymModel::addMapCenter ()
2102 BranchItem *bi=addMapCenter (contextPos);
2104 emitShowSelection();
2109 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2110 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2115 BranchItem* VymModel::addMapCenter(QPointF absPos)
2116 // createMapCenter could then probably be merged with createBranch
2120 QModelIndex parix=index(rootItem);
2122 QList<QVariant> cData;
2123 cData << "VM:addMapCenter" << "undef";
2124 BranchItem *newbi=new BranchItem (cData,rootItem);
2125 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2126 int n=rootItem->getRowNumAppend (newbi);
2128 emit (layoutAboutToBeChanged() );
2129 beginInsertRows (parix,n,n);
2131 rootItem->appendChild (newbi);
2134 emit (layoutChanged() );
2137 newbi->setPositionMode (MapItem::Absolute);
2138 BranchObj *bo=newbi->createMapObj(mapScene);
2139 if (bo) bo->move (absPos);
2144 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2146 // Depending on pos:
2147 // -3 insert in children of parent above selection
2148 // -2 add branch to selection
2149 // -1 insert in children of parent below selection
2150 // 0..n insert in children of parent at pos
2153 QList<QVariant> cData;
2154 cData << "new" << "undef";
2159 BranchItem *newbi=new BranchItem (cData);
2160 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2162 emit (layoutAboutToBeChanged() );
2168 n=parbi->getRowNumAppend (newbi);
2169 beginInsertRows (parix,n,n);
2170 parbi->appendChild (newbi);
2172 }else if (num==-1 || num==-3)
2174 // insert below selection
2175 parbi=(BranchItem*)dst->parent();
2178 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2179 beginInsertRows (parix,n,n);
2180 parbi->insertBranch(n,newbi);
2183 emit (layoutChanged() );
2185 // save scroll state. If scrolled, automatically select
2186 // new branch in order to tmp unscroll parent...
2187 newbi->createMapObj(mapScene);
2192 BranchItem* VymModel::addNewBranch(int pos)
2194 // Different meaning than num in addNewBranchInt!
2198 BranchItem *newbi=NULL;
2199 BranchItem *selbi=getSelectedBranch();
2203 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2205 newbi=addNewBranchInt (selbi,pos-2);
2213 QString ("addBranch (%1)").arg(pos),
2214 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2217 // emitSelectionChanged(); FIXME-3
2218 latestAddedItem=newbi;
2219 // In Network mode, the client needs to know where the new branch is,
2220 // so we have to pass on this information via saveState.
2221 // TODO: Get rid of this positioning workaround
2222 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2223 sendData ("selectLatestAdded ()");
2224 sendData (QString("move %1").arg(ps));
2233 BranchItem* VymModel::addNewBranchBefore()
2235 BranchItem *newbi=NULL;
2236 BranchItem *selbi=getSelectedBranch();
2237 if (selbi && selbi->getType()==TreeItem::Branch)
2238 // We accept no MapCenter here, so we _have_ a parent
2240 //QPointF p=bo->getRelPos();
2243 // add below selection
2244 newbi=addNewBranchInt (selbi,-1);
2248 //newbi->move2RelPos (p);
2250 // Move selection to new branch
2251 relinkBranch (selbi,newbi,0);
2253 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2254 QString ("Add branch before %1").arg(getObjectName(selbi)));
2256 // FIXME-3 needed? reposition();
2257 // emitSelectionChanged(); FIXME-3
2263 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2267 if (branch->depth()==0)
2269 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2271 emit (layoutAboutToBeChanged() );
2272 BranchItem *branchpi=(BranchItem*)branch->parent();
2273 // Remove at current position
2274 int n=branch->childNum();
2275 beginRemoveRows (index(branchpi),n,n);
2276 branchpi->removeChild (n);
2279 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2281 // Append as last branch to dst
2282 if (dst->branchCount()==0)
2285 n=dst->getFirstBranch()->childNumber();
2286 beginInsertRows (index(dst),n+pos,n+pos);
2287 dst->insertBranch (pos,branch);
2290 // Correct type if necessesary
2291 if (branch->getType()==TreeItem::MapCenter)
2292 branch->setType(TreeItem::Branch);
2294 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2295 branch->updateStyles();
2297 emit (layoutChanged() );
2298 reposition(); // both for moveUp/Down and relinking
2299 if (dst->isScrolled() )
2302 branch->updateVisibility();
2311 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2315 emit (layoutAboutToBeChanged() );
2317 BranchItem *pi=(BranchItem*)(image->parent());
2318 QString oldParString=getSelectString (pi);
2319 // Remove at current position
2320 int n=image->childNum();
2321 beginRemoveRows (index(pi),n,n);
2322 pi->removeChild (n);
2326 QModelIndex dstix=index(dst);
2327 n=dst->getRowNumAppend (image);
2328 beginInsertRows (dstix,n,n+1);
2329 dst->appendChild (image);
2332 // Set new parent also for lmo
2333 if (image->getLMO() && dst->getLMO() )
2334 image->getLMO()->setParObj (dst->getLMO() );
2336 emit (layoutChanged() );
2339 QString("relinkTo (\"%1\")").arg(oldParString),
2341 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2342 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2348 void VymModel::deleteSelection()
2350 BranchItem *selbi=getSelectedBranch();
2355 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2357 TreeItem *pi=deleteItem (selbi);
2361 emitShowSelection();
2365 TreeItem *ti=getSelectedItem();
2368 TreeItem *pi=ti->parent();
2370 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2372 saveStateChangingPart(
2376 QString("Delete %1").arg(getObjectName(ti))
2380 emitDataHasChanged (pi);
2383 emitShowSelection();
2384 } else if (ti->getType()==TreeItem::XLink)
2386 //FIXME-2 savestate missing
2389 qWarning ("VymmModel::deleteSelection() unknown type?!");
2393 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2396 BranchItem *selbi=getSelectedBranch();
2400 // Don't use this on mapcenter
2401 if (selbi->depth()<2) return;
2403 pi=(BranchItem*)(selbi->parent());
2404 // Check if we have childs at all to keep
2405 if (selbi->branchCount()==0)
2412 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2413 saveStateChangingPart(
2416 "deleteKeepChildren ()",
2417 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2420 QString sel=getSelectString(selbi);
2422 int pos=selbi->num();
2423 BranchItem *bi=selbi->getFirstBranch();
2426 relinkBranch (bi,pi,pos);
2427 bi=selbi->getFirstBranch();
2433 BranchObj *bo=getSelectedBranchObj();
2436 bo->move2RelPos (p);
2442 void VymModel::deleteChildren()
2445 BranchItem *selbi=getSelectedBranch();
2448 saveStateChangingPart(
2451 "deleteChildren ()",
2452 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2454 emit (layoutAboutToBeChanged() );
2456 QModelIndex ix=index (selbi);
2457 int n=selbi->branchCount()-1;
2458 beginRemoveRows (ix,0,n);
2459 removeRows (0,n+1,ix);
2461 if (selbi->isScrolled()) selbi->unScroll();
2462 emit (layoutChanged() );
2467 TreeItem* VymModel::deleteItem (TreeItem *ti)
2471 TreeItem *pi=ti->parent();
2472 QModelIndex parentIndex=index(pi);
2474 emit (layoutAboutToBeChanged() );
2476 int n=ti->childNum();
2477 beginRemoveRows (parentIndex,n,n);
2478 removeRows (n,1,parentIndex);
2482 emit (layoutChanged() );
2483 if (pi->depth()>=0) return pi;
2488 void VymModel::clearItem (TreeItem *ti)
2492 QModelIndex parentIndex=index(ti);
2493 if (!parentIndex.isValid()) return;
2495 int n=ti->childCount();
2498 emit (layoutAboutToBeChanged() );
2500 beginRemoveRows (parentIndex,0,n-1);
2501 removeRows (0,n,parentIndex);
2505 emit (layoutChanged() );
2511 bool VymModel::scrollBranch(BranchItem *bi)
2515 if (bi->isScrolled()) return false;
2516 if (bi->branchCount()==0) return false;
2517 if (bi->depth()==0) return false;
2518 if (bi->toggleScroll())
2525 QString ("%1 ()").arg(u),
2527 QString ("%1 ()").arg(r),
2528 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2530 emitDataHasChanged(bi);
2531 emitSelectionChanged();
2532 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2539 bool VymModel::unscrollBranch(BranchItem *bi)
2543 if (!bi->isScrolled()) return false;
2544 if (bi->branchCount()==0) return false;
2545 if (bi->depth()==0) return false;
2546 if (bi->toggleScroll())
2554 QString ("%1 ()").arg(u),
2556 QString ("%1 ()").arg(r),
2557 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2559 emitDataHasChanged(bi);
2560 emitSelectionChanged();
2561 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2568 void VymModel::toggleScroll()
2570 BranchItem *bi=(BranchItem*)getSelectedBranch();
2571 if (bi && bi->isBranchLikeType() )
2573 if (bi->isScrolled())
2574 unscrollBranch (bi);
2578 // saveState & reposition are called in above functions
2581 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2583 BranchItem *selbi=getSelectedBranch();
2584 BranchItem *prev=NULL;
2585 BranchItem *cur=selbi;
2588 saveStateChangingPart(
2591 QString ("unscrollChildren ()"),
2592 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2596 if (cur->isScrolled())
2598 cur->toggleScroll();
2599 emitDataHasChanged (cur);
2601 cur=next (cur,prev,selbi);
2608 void VymModel::emitExpandAll()
2610 emit (expandAll() );
2613 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2615 BranchItem *bi=getSelectedBranch();
2619 if (bi->isActiveStandardFlag(name))
2631 QString("%1 (\"%2\")").arg(u).arg(name),
2633 QString("%1 (\"%2\")").arg(r).arg(name),
2634 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2635 bi->toggleStandardFlag (name, master);
2637 emitSelectionChanged();
2641 void VymModel::addFloatImage (const QPixmap &img)
2643 BranchItem *selbi=getSelectedBranch();
2646 ImageItem *ii=createImage (selbi);
2648 ii->setOriginalFilename("No original filename (image added by dropevent)");
2649 QString s=getSelectString(selbi);
2650 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2651 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2653 // FIXME-3 VM needed? scene()->update();
2658 void VymModel::colorBranch (QColor c)
2660 BranchItem *selbi=getSelectedBranch();
2665 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2667 QString ("colorBranch (\"%1\")").arg(c.name()),
2668 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2670 selbi->setHeadingColor(c); // color branch
2675 void VymModel::colorSubtree (QColor c)
2677 BranchItem *selbi=getSelectedBranch();
2680 saveStateChangingPart(
2683 QString ("colorSubtree (\"%1\")").arg(c.name()),
2684 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2686 BranchItem *prev=NULL;
2687 BranchItem *cur=selbi;
2690 cur->setHeadingColor(c); // color links, color children
2691 cur=next (cur,prev,selbi);
2697 QColor VymModel::getCurrentHeadingColor()
2699 BranchItem *selbi=getSelectedBranch();
2700 if (selbi) return selbi->getHeadingColor();
2702 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2708 void VymModel::editURL()
2710 TreeItem *selti=getSelectedItem();
2714 QString text = QInputDialog::getText(
2715 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2716 selti->getURL(), &ok, NULL);
2718 // user entered something and pressed OK
2723 void VymModel::editLocalURL()
2725 TreeItem *selti=getSelectedItem();
2728 QStringList filters;
2729 filters <<"All files (*)";
2730 filters << tr("Text","Filedialog") + " (*.txt)";
2731 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2732 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2733 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2734 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2735 fd->setFilters (filters);
2736 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2737 fd->setDirectory (lastFileDir);
2738 if (! selti->getVymLink().isEmpty() )
2739 fd->selectFile( selti->getURL() );
2742 if ( fd->exec() == QDialog::Accepted )
2744 lastFileDir=QDir (fd->directory().path());
2745 setURL (fd->selectedFile() );
2751 void VymModel::editHeading2URL()
2753 TreeItem *selti=getSelectedItem();
2755 setURL (selti->getHeading());
2758 void VymModel::editBugzilla2URL()
2760 TreeItem *selti=getSelectedItem();
2763 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2768 void VymModel::editFATE2URL()
2770 TreeItem *selti=getSelectedItem();
2773 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2776 "setURL (\""+selti->getURL()+"\")",
2778 "setURL (\""+url+"\")",
2779 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2781 selti->setURL (url);
2782 // FIXME-4 updateActions();
2786 void VymModel::editVymLink()
2788 BranchItem *bi=getSelectedBranch();
2791 QStringList filters;
2792 filters <<"VYM map (*.vym)";
2793 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2794 fd->setFilters (filters);
2795 fd->setCaption(vymName+" - " +tr("Link to another map"));
2796 fd->setDirectory (lastFileDir);
2797 if (! bi->getVymLink().isEmpty() )
2798 fd->selectFile( bi->getVymLink() );
2802 if ( fd->exec() == QDialog::Accepted )
2804 lastFileDir=QDir (fd->directory().path());
2807 "setVymLink (\""+bi->getVymLink()+"\")",
2809 "setVymLink (\""+fd->selectedFile()+"\")",
2810 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2812 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2817 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2819 // Internal function, no saveState needed
2820 TreeItem *selti=getSelectedItem();
2823 selti->setVymLink(s);
2825 emitDataHasChanged (selti);
2826 emitShowSelection();
2830 void VymModel::deleteVymLink()
2832 BranchItem *bi=getSelectedBranch();
2837 "setVymLink (\""+bi->getVymLink()+"\")",
2839 "setVymLink (\"\")",
2840 QString("Unset vymlink of %1").arg(getObjectName(bi))
2842 bi->setVymLink ("" );
2848 QString VymModel::getVymLink()
2850 BranchItem *bi=getSelectedBranch();
2852 return bi->getVymLink();
2858 QStringList VymModel::getVymLinks()
2861 BranchItem *selbi=getSelectedBranch();
2862 BranchItem *cur=selbi;
2863 BranchItem *prev=NULL;
2866 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2867 cur=next (cur,prev,selbi);
2873 void VymModel::followXLink(int i)
2876 BranchItem *selbi=getSelectedBranch();
2879 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2880 if (selbi) select (selbi);
2884 void VymModel::editXLink(int i)
2887 BranchItem *selbi=getSelectedBranch();
2890 XLinkItem *xli=selbi->getXLinkNum(i);
2893 EditXLinkDialog dia;
2895 dia.setSelection(selbi);
2896 if (dia.exec() == QDialog::Accepted)
2898 if (dia.useSettingsGlobal() )
2900 setMapDefXLinkColor (xli->getColor() );
2901 setMapDefXLinkWidth (xli->getWidth() );
2903 if (dia.deleteXLink()) deleteItem (xli);
2913 //////////////////////////////////////////////
2915 //////////////////////////////////////////////
2917 void VymModel::parseAtom(const QString &atom)
2919 TreeItem* selti=getSelectedItem();
2920 BranchItem *selbi=getSelectedBranch();
2926 // Split string s into command and parameters
2927 parser.parseAtom (atom);
2928 QString com=parser.getCommand();
2930 // External commands
2931 /////////////////////////////////////////////////////////////////////
2932 if (com=="addBranch")
2936 parser.setError (Aborted,"Nothing selected");
2937 } else if (! selbi )
2939 parser.setError (Aborted,"Type of selection is not a branch");
2944 if (parser.checkParCount(pl))
2946 if (parser.parCount()==0)
2950 n=parser.parInt (ok,0);
2951 if (ok ) addNewBranch (n);
2955 /////////////////////////////////////////////////////////////////////
2956 } else if (com=="addBranchBefore")
2960 parser.setError (Aborted,"Nothing selected");
2961 } else if (! selbi )
2963 parser.setError (Aborted,"Type of selection is not a branch");
2966 if (parser.parCount()==0)
2968 addNewBranchBefore ();
2971 /////////////////////////////////////////////////////////////////////
2972 } else if (com==QString("addMapCenter"))
2974 if (parser.checkParCount(2))
2976 x=parser.parDouble (ok,0);
2979 y=parser.parDouble (ok,1);
2980 if (ok) addMapCenter (QPointF(x,y));
2983 /////////////////////////////////////////////////////////////////////
2984 } else if (com==QString("addMapReplace"))
2988 parser.setError (Aborted,"Nothing selected");
2989 } else if (! selbi )
2991 parser.setError (Aborted,"Type of selection is not a branch");
2992 } else if (parser.checkParCount(1))
2994 //s=parser.parString (ok,0); // selection
2995 t=parser.parString (ok,0); // path to map
2996 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2997 addMapReplaceInt(getSelectString(selbi),t);
2999 /////////////////////////////////////////////////////////////////////
3000 } else if (com==QString("addMapInsert"))
3002 if (parser.parCount()==2)
3007 parser.setError (Aborted,"Nothing selected");
3008 } else if (! selbi )
3010 parser.setError (Aborted,"Type of selection is not a branch");
3013 t=parser.parString (ok,0); // path to map
3014 n=parser.parInt(ok,1); // position
3015 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3016 addMapInsertInt(t,n);
3018 } else if (parser.parCount()==1)
3020 t=parser.parString (ok,0); // path to map
3021 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3024 parser.setError (Aborted,"Wrong number of parameters");
3025 /////////////////////////////////////////////////////////////////////
3026 } else if (com==QString("addXLink"))
3028 if (parser.parCount()>1)
3030 s=parser.parString (ok,0); // begin
3031 t=parser.parString (ok,1); // end
3032 BranchItem *begin=(BranchItem*)findBySelectString(s);
3033 BranchItem *end=(BranchItem*)findBySelectString(t);
3036 if (begin->isBranchLikeType() && end->isBranchLikeType())
3038 XLinkItem *xl=createXLink (begin,true);
3044 parser.setError (Aborted,"Failed to create xLink");
3047 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3050 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3052 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3053 /////////////////////////////////////////////////////////////////////
3054 } else if (com=="clearFlags")
3058 parser.setError (Aborted,"Nothing selected");
3059 } else if (! selbi )
3061 parser.setError (Aborted,"Type of selection is not a branch");
3062 } else if (parser.checkParCount(0))
3064 selbi->deactivateAllStandardFlags();
3066 /////////////////////////////////////////////////////////////////////
3067 } else if (com=="colorBranch")
3071 parser.setError (Aborted,"Nothing selected");
3072 } else if (! selbi )
3074 parser.setError (Aborted,"Type of selection is not a branch");
3075 } else if (parser.checkParCount(1))
3077 QColor c=parser.parColor (ok,0);
3078 if (ok) colorBranch (c);
3080 /////////////////////////////////////////////////////////////////////
3081 } else if (com=="colorSubtree")
3085 parser.setError (Aborted,"Nothing selected");
3086 } else if (! selbi )
3088 parser.setError (Aborted,"Type of selection is not a branch");
3089 } else if (parser.checkParCount(1))
3091 QColor c=parser.parColor (ok,0);
3092 if (ok) colorSubtree (c);
3094 /////////////////////////////////////////////////////////////////////
3095 } else if (com=="copy")
3099 parser.setError (Aborted,"Nothing selected");
3100 } else if ( selectionType()!=TreeItem::Branch &&
3101 selectionType()!=TreeItem::MapCenter &&
3102 selectionType()!=TreeItem::Image )
3104 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3105 } else if (parser.checkParCount(0))
3109 /////////////////////////////////////////////////////////////////////
3110 } else if (com=="cut")
3114 parser.setError (Aborted,"Nothing selected");
3115 } else if ( selectionType()!=TreeItem::Branch &&
3116 selectionType()!=TreeItem::MapCenter &&
3117 selectionType()!=TreeItem::Image )
3119 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3120 } else if (parser.checkParCount(0))
3124 /////////////////////////////////////////////////////////////////////
3125 } else if (com=="delete")
3129 parser.setError (Aborted,"Nothing selected");
3131 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3133 parser.setError (Aborted,"Type of selection is wrong.");
3136 else if (parser.checkParCount(0))
3140 /////////////////////////////////////////////////////////////////////
3141 } else if (com=="deleteKeepChildren")
3145 parser.setError (Aborted,"Nothing selected");
3146 } else if (! selbi )
3148 parser.setError (Aborted,"Type of selection is not a branch");
3149 } else if (parser.checkParCount(0))
3151 deleteKeepChildren();
3153 /////////////////////////////////////////////////////////////////////
3154 } else if (com=="deleteChildren")
3158 parser.setError (Aborted,"Nothing selected");
3161 parser.setError (Aborted,"Type of selection is not a branch");
3162 } else if (parser.checkParCount(0))
3166 /////////////////////////////////////////////////////////////////////
3167 } else if (com=="exportASCII")
3171 if (parser.parCount()>=1)
3172 // Hey, we even have a filename
3173 fname=parser.parString(ok,0);
3176 parser.setError (Aborted,"Could not read filename");
3179 exportASCII (fname,false);
3181 /////////////////////////////////////////////////////////////////////
3182 } else if (com=="exportImage")
3186 if (parser.parCount()>=2)
3187 // Hey, we even have a filename
3188 fname=parser.parString(ok,0);
3191 parser.setError (Aborted,"Could not read filename");
3194 QString format="PNG";
3195 if (parser.parCount()>=2)
3197 format=parser.parString(ok,1);
3199 exportImage (fname,false,format);
3201 /////////////////////////////////////////////////////////////////////
3202 } else if (com=="exportXHTML")
3206 if (parser.parCount()>=2)
3207 // Hey, we even have a filename
3208 fname=parser.parString(ok,1);
3211 parser.setError (Aborted,"Could not read filename");
3214 exportXHTML (fname,false);
3216 /////////////////////////////////////////////////////////////////////
3217 } else if (com=="exportXML")
3221 if (parser.parCount()>=2)
3222 // Hey, we even have a filename
3223 fname=parser.parString(ok,1);
3226 parser.setError (Aborted,"Could not read filename");
3229 exportXML (fname,false);
3231 /////////////////////////////////////////////////////////////////////
3232 } else if (com=="importDir")
3236 parser.setError (Aborted,"Nothing selected");
3237 } else if (! selbi )
3239 parser.setError (Aborted,"Type of selection is not a branch");
3240 } else if (parser.checkParCount(1))
3242 s=parser.parString(ok,0);
3243 if (ok) importDirInt(s);
3245 /////////////////////////////////////////////////////////////////////
3246 } else if (com=="relinkTo")
3250 parser.setError (Aborted,"Nothing selected");
3253 if (parser.checkParCount(4))
3255 // 0 selectstring of parent
3256 // 1 num in parent (for branches)
3257 // 2,3 x,y of mainbranch or mapcenter
3258 s=parser.parString(ok,0);
3259 TreeItem *dst=findBySelectString (s);
3262 if (dst->getType()==TreeItem::Branch)
3264 // Get number in parent
3265 n=parser.parInt (ok,1);
3268 relinkBranch (selbi,(BranchItem*)dst,n);
3269 emitSelectionChanged();
3271 } else if (dst->getType()==TreeItem::MapCenter)
3273 relinkBranch (selbi,(BranchItem*)dst);
3274 // Get coordinates of mainbranch
3275 x=parser.parDouble(ok,2);
3278 y=parser.parDouble(ok,3);
3281 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3282 emitSelectionChanged();
3288 } else if ( selti->getType() == TreeItem::Image)
3290 if (parser.checkParCount(1))
3292 // 0 selectstring of parent
3293 s=parser.parString(ok,0);
3294 TreeItem *dst=findBySelectString (s);
3297 if (dst->isBranchLikeType())
3298 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3300 parser.setError (Aborted,"Destination is not a branch");
3303 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3304 /////////////////////////////////////////////////////////////////////
3305 } else if (com=="loadImage")
3309 parser.setError (Aborted,"Nothing selected");
3310 } else if (! selbi )
3312 parser.setError (Aborted,"Type of selection is not a branch");
3313 } else if (parser.checkParCount(1))
3315 s=parser.parString(ok,0);
3316 if (ok) loadFloatImageInt (selbi,s);
3318 /////////////////////////////////////////////////////////////////////
3319 } else if (com=="moveUp")
3323 parser.setError (Aborted,"Nothing selected");
3324 } else if (! selbi )
3326 parser.setError (Aborted,"Type of selection is not a branch");
3327 } else if (parser.checkParCount(0))
3331 /////////////////////////////////////////////////////////////////////
3332 } else if (com=="moveDown")
3336 parser.setError (Aborted,"Nothing selected");
3337 } else if (! selbi )
3339 parser.setError (Aborted,"Type of selection is not a branch");
3340 } else if (parser.checkParCount(0))
3344 /////////////////////////////////////////////////////////////////////
3345 } else if (com=="move")
3349 parser.setError (Aborted,"Nothing selected");
3350 } else if ( selectionType()!=TreeItem::Branch &&
3351 selectionType()!=TreeItem::MapCenter &&
3352 selectionType()!=TreeItem::Image )
3354 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3355 } else if (parser.checkParCount(2))
3357 x=parser.parDouble (ok,0);
3360 y=parser.parDouble (ok,1);
3364 /////////////////////////////////////////////////////////////////////
3365 } else if (com=="moveRel")
3369 parser.setError (Aborted,"Nothing selected");
3370 } else if ( selectionType()!=TreeItem::Branch &&
3371 selectionType()!=TreeItem::MapCenter &&
3372 selectionType()!=TreeItem::Image )
3374 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3375 } else if (parser.checkParCount(2))
3377 x=parser.parDouble (ok,0);
3380 y=parser.parDouble (ok,1);
3381 if (ok) moveRel (x,y);
3384 /////////////////////////////////////////////////////////////////////
3385 } else if (com=="nop")
3387 /////////////////////////////////////////////////////////////////////
3388 } else if (com=="paste")
3392 parser.setError (Aborted,"Nothing selected");
3393 } else if (! selbi )
3395 parser.setError (Aborted,"Type of selection is not a branch");
3396 } else if (parser.checkParCount(1))
3398 n=parser.parInt (ok,0);
3399 if (ok) pasteNoSave(n);
3401 /////////////////////////////////////////////////////////////////////
3402 } else if (com=="qa")
3406 parser.setError (Aborted,"Nothing selected");
3407 } else if (! selbi )
3409 parser.setError (Aborted,"Type of selection is not a branch");
3410 } else if (parser.checkParCount(4))
3413 c=parser.parString (ok,0);
3416 parser.setError (Aborted,"No comment given");
3419 s=parser.parString (ok,1);
3422 parser.setError (Aborted,"First parameter is not a string");
3425 t=parser.parString (ok,2);
3428 parser.setError (Aborted,"Condition is not a string");
3431 u=parser.parString (ok,3);
3434 parser.setError (Aborted,"Third parameter is not a string");
3439 parser.setError (Aborted,"Unknown type: "+s);
3444 parser.setError (Aborted,"Unknown operator: "+t);
3449 parser.setError (Aborted,"Type of selection is not a branch");
3452 if (selbi->getHeading() == u)
3454 cout << "PASSED: " << qPrintable (c) << endl;
3457 cout << "FAILED: " << qPrintable (c) << endl;
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="saveImage")
3470 ImageItem *ii=getSelectedImage();
3473 parser.setError (Aborted,"No image selected");
3474 } else if (parser.checkParCount(2))
3476 s=parser.parString(ok,0);
3479 t=parser.parString(ok,1);
3480 if (ok) saveFloatImageInt (ii,t,s);
3483 /////////////////////////////////////////////////////////////////////
3484 } else if (com=="scroll")
3488 parser.setError (Aborted,"Nothing selected");
3489 } else if (! selbi )
3491 parser.setError (Aborted,"Type of selection is not a branch");
3492 } else if (parser.checkParCount(0))
3494 if (!scrollBranch (selbi))
3495 parser.setError (Aborted,"Could not scroll branch");
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="select")
3500 if (parser.checkParCount(1))
3502 s=parser.parString(ok,0);
3505 /////////////////////////////////////////////////////////////////////
3506 } else if (com=="selectLastBranch")
3510 parser.setError (Aborted,"Nothing selected");
3511 } else if (! selbi )
3513 parser.setError (Aborted,"Type of selection is not a branch");
3514 } else if (parser.checkParCount(0))
3516 BranchItem *bi=selbi->getLastBranch();
3518 parser.setError (Aborted,"Could not select last branch");
3519 select (bi); // FIXME-3 was selectInt
3522 /////////////////////////////////////////////////////////////////////
3523 } else /* FIXME-2 if (com=="selectLastImage")
3527 parser.setError (Aborted,"Nothing selected");
3528 } else if (! selbi )
3530 parser.setError (Aborted,"Type of selection is not a branch");
3531 } else if (parser.checkParCount(0))
3533 FloatImageObj *fio=selb->getLastFloatImage();
3535 parser.setError (Aborted,"Could not select last image");
3536 select (fio); // FIXME-3 was selectInt
3539 /////////////////////////////////////////////////////////////////////
3540 } else */ if (com=="selectLatestAdded")
3542 if (!latestAddedItem)
3544 parser.setError (Aborted,"No latest added object");
3547 if (!select (latestAddedItem))
3548 parser.setError (Aborted,"Could not select latest added object ");
3550 /////////////////////////////////////////////////////////////////////
3551 } else if (com=="setFrameType")
3553 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3555 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3557 else if (parser.checkParCount(1))
3559 s=parser.parString(ok,0);
3560 if (ok) setFrameType (s);
3562 /////////////////////////////////////////////////////////////////////
3563 } else if (com=="setFramePenColor")
3565 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3567 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3569 else if (parser.checkParCount(1))
3571 QColor c=parser.parColor(ok,0);
3572 if (ok) setFramePenColor (c);
3574 /////////////////////////////////////////////////////////////////////
3575 } else if (com=="setFrameBrushColor")
3577 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3579 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3581 else if (parser.checkParCount(1))
3583 QColor c=parser.parColor(ok,0);
3584 if (ok) setFrameBrushColor (c);
3586 /////////////////////////////////////////////////////////////////////
3587 } else if (com=="setFramePadding")
3589 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3591 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3593 else if (parser.checkParCount(1))
3595 n=parser.parInt(ok,0);
3596 if (ok) setFramePadding(n);
3598 /////////////////////////////////////////////////////////////////////
3599 } else if (com=="setFrameBorderWidth")
3601 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3603 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3605 else if (parser.checkParCount(1))
3607 n=parser.parInt(ok,0);
3608 if (ok) setFrameBorderWidth (n);
3610 /////////////////////////////////////////////////////////////////////
3611 } else if (com=="setMapAuthor")
3613 if (parser.checkParCount(1))
3615 s=parser.parString(ok,0);
3616 if (ok) setAuthor (s);
3618 /////////////////////////////////////////////////////////////////////
3619 } else if (com=="setMapComment")
3621 if (parser.checkParCount(1))
3623 s=parser.parString(ok,0);
3624 if (ok) setComment(s);
3626 /////////////////////////////////////////////////////////////////////
3627 } else if (com=="setMapBackgroundColor")
3631 parser.setError (Aborted,"Nothing selected");
3632 } else if (! selbi )
3634 parser.setError (Aborted,"Type of selection is not a branch");
3635 } else if (parser.checkParCount(1))
3637 QColor c=parser.parColor (ok,0);
3638 if (ok) setMapBackgroundColor (c);
3640 /////////////////////////////////////////////////////////////////////
3641 } else if (com=="setMapDefLinkColor")
3645 parser.setError (Aborted,"Nothing selected");
3646 } else if (! selbi )
3648 parser.setError (Aborted,"Type of selection is not a branch");
3649 } else if (parser.checkParCount(1))
3651 QColor c=parser.parColor (ok,0);
3652 if (ok) setMapDefLinkColor (c);
3654 /////////////////////////////////////////////////////////////////////
3655 } else if (com=="setMapLinkStyle")
3657 if (parser.checkParCount(1))
3659 s=parser.parString (ok,0);
3660 if (ok) setMapLinkStyle(s);
3662 /////////////////////////////////////////////////////////////////////
3663 } else if (com=="setHeading")
3667 parser.setError (Aborted,"Nothing selected");
3668 } else if (! selbi )
3670 parser.setError (Aborted,"Type of selection is not a branch");
3671 } else if (parser.checkParCount(1))
3673 s=parser.parString (ok,0);
3677 /////////////////////////////////////////////////////////////////////
3678 } else if (com=="setHideExport")
3682 parser.setError (Aborted,"Nothing selected");
3683 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3685 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3686 } else if (parser.checkParCount(1))
3688 b=parser.parBool(ok,0);
3689 if (ok) setHideExport (b);
3691 /////////////////////////////////////////////////////////////////////
3692 } else if (com=="setIncludeImagesHorizontally")
3696 parser.setError (Aborted,"Nothing selected");
3699 parser.setError (Aborted,"Type of selection is not a branch");
3700 } else if (parser.checkParCount(1))
3702 b=parser.parBool(ok,0);
3703 if (ok) setIncludeImagesHor(b);
3705 /////////////////////////////////////////////////////////////////////
3706 } else if (com=="setIncludeImagesVertically")
3710 parser.setError (Aborted,"Nothing selected");
3713 parser.setError (Aborted,"Type of selection is not a branch");
3714 } else if (parser.checkParCount(1))
3716 b=parser.parBool(ok,0);
3717 if (ok) setIncludeImagesVer(b);
3719 /////////////////////////////////////////////////////////////////////
3720 } else if (com=="setHideLinkUnselected")
3724 parser.setError (Aborted,"Nothing selected");
3725 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3727 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3728 } else if (parser.checkParCount(1))
3730 b=parser.parBool(ok,0);
3731 if (ok) setHideLinkUnselected(b);
3733 /////////////////////////////////////////////////////////////////////
3734 } else if (com=="setSelectionColor")
3736 if (parser.checkParCount(1))
3738 QColor c=parser.parColor (ok,0);
3739 if (ok) setSelectionColorInt (c);
3741 /////////////////////////////////////////////////////////////////////
3742 } else if (com=="setURL")
3746 parser.setError (Aborted,"Nothing selected");
3747 } else if (! selbi )
3749 parser.setError (Aborted,"Type of selection is not a branch");
3750 } else if (parser.checkParCount(1))
3752 s=parser.parString (ok,0);
3755 /////////////////////////////////////////////////////////////////////
3756 } else if (com=="setVymLink")
3760 parser.setError (Aborted,"Nothing selected");
3761 } else if (! selbi )
3763 parser.setError (Aborted,"Type of selection is not a branch");
3764 } else if (parser.checkParCount(1))
3766 s=parser.parString (ok,0);
3767 if (ok) setVymLink(s);
3770 /////////////////////////////////////////////////////////////////////
3771 else if (com=="setFlag")
3775 parser.setError (Aborted,"Nothing selected");
3776 } else if (! selbi )
3778 parser.setError (Aborted,"Type of selection is not a branch");
3779 } else if (parser.checkParCount(1))
3781 s=parser.parString(ok,0);
3783 selbi->activateStandardFlag(s);
3785 /////////////////////////////////////////////////////////////////////
3786 } else /* FIXME-2 if (com=="setFrameType")
3790 parser.setError (Aborted,"Nothing selected");
3793 parser.setError (Aborted,"Type of selection is not a branch");
3794 } else if (parser.checkParCount(1))
3796 s=parser.parString(ok,0);
3800 /////////////////////////////////////////////////////////////////////
3801 } else*/ if (com=="sortChildren")
3805 parser.setError (Aborted,"Nothing selected");
3806 } else if (! selbi )
3808 parser.setError (Aborted,"Type of selection is not a branch");
3809 } else if (parser.checkParCount(0))
3813 /////////////////////////////////////////////////////////////////////
3814 } else if (com=="toggleFlag")
3818 parser.setError (Aborted,"Nothing selected");
3819 } else if (! selbi )
3821 parser.setError (Aborted,"Type of selection is not a branch");
3822 } else if (parser.checkParCount(1))
3824 s=parser.parString(ok,0);
3826 selbi->toggleStandardFlag(s);
3828 /////////////////////////////////////////////////////////////////////
3829 } else if (com=="unscroll")
3833 parser.setError (Aborted,"Nothing selected");
3834 } else if (! selbi )
3836 parser.setError (Aborted,"Type of selection is not a branch");
3837 } else if (parser.checkParCount(0))
3839 if (!unscrollBranch (selbi))
3840 parser.setError (Aborted,"Could not unscroll branch");
3842 /////////////////////////////////////////////////////////////////////
3843 } else if (com=="unscrollChildren")
3847 parser.setError (Aborted,"Nothing selected");
3848 } else if (! selbi )
3850 parser.setError (Aborted,"Type of selection is not a branch");
3851 } else if (parser.checkParCount(0))
3853 unscrollChildren ();
3855 /////////////////////////////////////////////////////////////////////
3856 } else if (com=="unsetFlag")
3860 parser.setError (Aborted,"Nothing selected");
3861 } else if (! selbi )
3863 parser.setError (Aborted,"Type of selection is not a branch");
3864 } else if (parser.checkParCount(1))
3866 s=parser.parString(ok,0);
3868 selbi->deactivateStandardFlag(s);
3871 parser.setError (Aborted,"Unknown command");
3874 if (parser.errorLevel()==NoError)
3876 // setChanged(); FIXME-2 should not be called e.g. for export?!
3881 // TODO Error handling
3882 qWarning("VymModel::parseAtom: Error!");
3883 qWarning(parser.errorMessage());
3887 void VymModel::runScript (QString script)
3889 parser.setScript (script);
3891 while (parser.next() )
3892 parseAtom(parser.getAtom());
3895 void VymModel::setExportMode (bool b)
3897 // should be called before and after exports
3898 // depending on the settings
3899 if (b && settings.value("/export/useHideExport","true")=="true")
3900 setHideTmpMode (TreeItem::HideExport);
3902 setHideTmpMode (TreeItem::HideNone);
3905 void VymModel::exportImage(QString fname, bool askName, QString format)
3909 fname=getMapName()+".png";
3916 QFileDialog *fd=new QFileDialog (NULL);
3917 fd->setCaption (tr("Export map as image"));
3918 fd->setDirectory (lastImageDir);
3919 fd->setFileMode(QFileDialog::AnyFile);
3920 fd->setFilters (imageIO.getFilters() );
3923 fl=fd->selectedFiles();
3925 format=imageIO.getType(fd->selectedFilter());
3929 setExportMode (true);
3930 QPixmap pix (mapEditor->getPixmap());
3931 pix.save(fname, format);
3932 setExportMode (false);
3936 void VymModel::exportXML(QString dir, bool askForName)
3940 dir=browseDirectory(NULL,tr("Export XML to directory"));
3941 if (dir =="" && !reallyWriteDirectory(dir) )
3945 // Hide stuff during export, if settings want this
3946 setExportMode (true);
3948 // Create subdirectories
3951 // write to directory //FIXME-4 check totalBBox here...
3952 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3955 file.setName ( dir + "/"+mapName+".xml");
3956 if ( !file.open( QIODevice::WriteOnly ) )
3958 // This should neverever happen
3959 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3963 // Write it finally, and write in UTF8, no matter what
3964 QTextStream ts( &file );
3965 ts.setEncoding (QTextStream::UnicodeUTF8);
3969 // Now write image, too
3970 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3972 setExportMode (false);
3975 void VymModel::exportASCII(QString fname,bool askName)
3980 ex.setFile (mapName+".txt");
3986 //ex.addFilter ("TXT (*.txt)");
3987 ex.setDir(lastImageDir);
3988 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3993 setExportMode(true);
3995 setExportMode(false);
3999 void VymModel::exportXHTML (const QString &dir, bool askForName)
4001 ExportXHTMLDialog dia(NULL);
4002 dia.setFilePath (filePath );
4003 dia.setMapName (mapName );
4005 if (dir!="") dia.setDir (dir);
4011 if (dia.exec()!=QDialog::Accepted)
4015 QDir d (dia.getDir());
4016 // Check, if warnings should be used before overwriting
4017 // the output directory
4018 if (d.exists() && d.count()>0)
4021 warn.showCancelButton (true);
4022 warn.setText(QString(
4023 "The directory %1 is not empty.\n"
4024 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4025 warn.setCaption("Warning: Directory not empty");
4026 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4028 if (warn.exec()!=QDialog::Accepted) ok=false;
4035 exportXML (dia.getDir(),false );
4036 dia.doExport(mapName );
4037 //if (dia.hasChanged()) setChanged();
4041 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4046 if (ex.setConfigFile(cf))
4048 setExportMode (true);
4049 ex.exportPresentation();
4050 setExportMode (false);
4057 //////////////////////////////////////////////
4059 //////////////////////////////////////////////
4061 void VymModel::registerEditor(QWidget *me)
4063 mapEditor=(MapEditor*)me;
4066 void VymModel::unregisterEditor(QWidget *)
4071 void VymModel::setContextPos(QPointF p)
4076 void VymModel::unsetContextPos()
4078 contextPos=QPointF();
4081 void VymModel::updateNoteFlag()
4084 TreeItem *selti=getSelectedItem();
4087 if (textEditor->isEmpty())
4090 selti->setNote (textEditor->getText());
4091 emitDataHasChanged(selti);
4092 emitSelectionChanged();
4097 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
4100 for (int i=0; i<rootItem->branchCount(); i++)
4101 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
4104 void MapCenterObj::updateRelPositions()
4106 if (repositionRequest) unsetAllRepositionRequests();
4108 // update relative Positions of branches and floats
4109 for (int i=0; i<treeItem->branchCount(); ++i)
4111 treeItem->getBranchObjNum(i)->setRelPos();
4112 treeItem->getBranchObjNum(i)->setOrientation();
4115 for (int i=0; i<floatimage.size(); ++i)
4116 floatimage.at(i)->setRelPos();
4118 if (repositionRequest) reposition();
4123 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4125 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4126 if (blockReposition) return;
4128 for (int i=0;i<rootItem->branchCount(); i++)
4129 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4130 //emitSelectionChanged();
4134 void VymModel::setMapLinkStyle (const QString & s)
4139 case LinkableMapObj::Line :
4142 case LinkableMapObj::Parabel:
4143 snow="StyleParabel";
4145 case LinkableMapObj::PolyLine:
4146 snow="StylePolyLine";
4148 case LinkableMapObj::PolyParabel:
4149 snow="StylePolyParabel";
4152 snow="UndefinedStyle";
4157 QString("setMapLinkStyle (\"%1\")").arg(s),
4158 QString("setMapLinkStyle (\"%1\")").arg(snow),
4159 QString("Set map link style (\"%1\")").arg(s)
4163 linkstyle=LinkableMapObj::Line;
4164 else if (s=="StyleParabel")
4165 linkstyle=LinkableMapObj::Parabel;
4166 else if (s=="StylePolyLine")
4167 linkstyle=LinkableMapObj::PolyLine;
4168 else if (s=="StylePolyParabel")
4169 linkstyle=LinkableMapObj::PolyParabel;
4171 linkstyle=LinkableMapObj::UndefinedStyle;
4173 BranchItem *cur=NULL;
4174 BranchItem *prev=NULL;
4179 bo=(BranchObj*)(cur->getLMO() );
4180 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4186 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4191 void VymModel::setMapDefLinkColor(QColor col)
4193 if ( !col.isValid() ) return;
4195 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4196 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4197 QString("Set map link color to %1").arg(col.name())
4201 BranchItem *cur=NULL;
4202 BranchItem *prev=NULL;
4207 bo=(BranchObj*)(cur->getLMO() );
4214 void VymModel::setMapLinkColorHintInt()
4216 // called from setMapLinkColorHint(lch) or at end of parse
4217 BranchItem *cur=NULL;
4218 BranchItem *prev=NULL;
4223 bo=(BranchObj*)(cur->getLMO() );
4229 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4232 setMapLinkColorHintInt();
4235 void VymModel::toggleMapLinkColorHint()
4237 if (linkcolorhint==LinkableMapObj::HeadingColor)
4238 linkcolorhint=LinkableMapObj::DefaultColor;
4240 linkcolorhint=LinkableMapObj::HeadingColor;
4241 BranchItem *cur=NULL;
4242 BranchItem *prev=NULL;
4247 bo=(BranchObj*)(cur->getLMO() );
4253 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4255 Q3FileDialog *fd=new Q3FileDialog( NULL);
4256 fd->setMode (Q3FileDialog::ExistingFile);
4257 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4258 ImagePreview *p =new ImagePreview (fd);
4259 fd->setContentsPreviewEnabled( TRUE );
4260 fd->setContentsPreview( p, p );
4261 fd->setPreviewMode( Q3FileDialog::Contents );
4262 fd->setCaption(vymName+" - " +tr("Load background image"));
4263 fd->setDir (lastImageDir);
4266 if ( fd->exec() == QDialog::Accepted )
4268 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4269 lastImageDir=QDir (fd->dirPath());
4270 setMapBackgroundImage (fd->selectedFile());
4274 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4276 QColor oldcol=mapScene->backgroundBrush().color();
4280 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4282 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4283 QString("Set background color of map to %1").arg(col.name()));
4286 brush.setTextureImage (QPixmap (fn));
4287 mapScene->setBackgroundBrush(brush);
4290 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4292 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4293 if ( !col.isValid() ) return;
4294 setMapBackgroundColor( col );
4298 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4300 QColor oldcol=mapScene->backgroundBrush().color();
4302 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4303 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4304 QString("Set background color of map to %1").arg(col.name()));
4305 mapScene->setBackgroundBrush(col);
4308 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4310 return mapScene->backgroundBrush().color();
4314 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4316 return linkcolorhint;
4319 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4321 return defLinkColor;
4324 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4329 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4331 return defXLinkColor;
4334 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4339 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4341 return defXLinkWidth;
4344 void VymModel::move(const double &x, const double &y)
4347 MapItem *seli = (MapItem*)getSelectedItem();
4348 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4350 LinkableMapObj *lmo=seli->getLMO();
4353 QPointF ap(lmo->getAbsPos());
4357 QString ps=qpointFToString(ap);
4358 QString s=getSelectString(seli);
4361 s, "move "+qpointFToString(to),
4362 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4365 emitSelectionChanged();
4371 void VymModel::moveRel (const double &x, const double &y)
4374 MapItem *seli = (MapItem*)getSelectedItem();
4375 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4377 LinkableMapObj *lmo=seli->getLMO();
4380 QPointF rp(lmo->getRelPos());
4384 QString ps=qpointFToString (lmo->getRelPos());
4385 QString s=getSelectString(seli);
4388 s, "moveRel "+qpointFToString(to),
4389 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4390 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4392 lmo->updateLinkGeometry();
4393 emitSelectionChanged();
4400 void VymModel::animate()
4402 animationTimer->stop();
4405 while (i<animObjList.size() )
4407 bo=(BranchObj*)animObjList.at(i);
4412 animObjList.removeAt(i);
4419 QItemSelection sel=selModel->selection();
4420 emit (selectionChanged(sel,sel));
4423 if (!animObjList.isEmpty()) animationTimer->start();
4427 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4429 if (bo && bo->getTreeItem()->depth()>0)
4432 ap.setStart (start);
4434 ap.setTicks (animationTicks);
4435 ap.setAnimated (true);
4436 bo->setAnimation (ap);
4437 animObjList.append( bo );
4438 animationTimer->setSingleShot (true);
4439 animationTimer->start(animationInterval);
4443 void VymModel::stopAnimation (MapObj *mo)
4445 int i=animObjList.indexOf(mo);
4447 animObjList.removeAt (i);
4450 void VymModel::sendSelection()
4452 if (netstate!=Server) return;
4453 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4456 void VymModel::newServer()
4460 tcpServer = new QTcpServer(this);
4461 if (!tcpServer->listen(QHostAddress::Any,port)) {
4462 QMessageBox::critical(NULL, "vym server",
4463 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4464 //FIXME-3 needed? we are no widget any longer... close();
4467 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4469 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4472 void VymModel::connectToServer()
4475 server="salam.suse.de";
4477 clientSocket = new QTcpSocket (this);
4478 clientSocket->abort();
4479 clientSocket->connectToHost(server ,port);
4480 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4481 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4482 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4484 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4489 void VymModel::newClient()
4491 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4492 connect(newClient, SIGNAL(disconnected()),
4493 newClient, SLOT(deleteLater()));
4495 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4497 clientList.append (newClient);
4501 void VymModel::sendData(const QString &s)
4503 if (clientList.size()==0) return;
4505 // Create bytearray to send
4507 QDataStream out(&block, QIODevice::WriteOnly);
4508 out.setVersion(QDataStream::Qt_4_0);
4510 // Reserve some space for blocksize
4513 // Write sendCounter
4514 out << sendCounter++;
4519 // Go back and write blocksize so far
4520 out.device()->seek(0);
4521 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4525 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4527 for (int i=0; i<clientList.size(); ++i)
4529 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4530 clientList.at(i)->write (block);
4534 void VymModel::readData ()
4536 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4539 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4543 QDataStream in(clientSocket);
4544 in.setVersion(QDataStream::Qt_4_0);
4552 cout << " t="<<qPrintable (t)<<endl;
4558 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4560 switch (socketError) {
4561 case QAbstractSocket::RemoteHostClosedError:
4563 case QAbstractSocket::HostNotFoundError:
4564 QMessageBox::information(NULL, vymName +" Network client",
4565 "The host was not found. Please check the "
4566 "host name and port settings.");
4568 case QAbstractSocket::ConnectionRefusedError:
4569 QMessageBox::information(NULL, vymName + " Network client",
4570 "The connection was refused by the peer. "
4571 "Make sure the fortune server is running, "
4572 "and check that the host name and port "
4573 "settings are correct.");
4576 QMessageBox::information(NULL, vymName + " Network client",
4577 QString("The following error occurred: %1.")
4578 .arg(clientSocket->errorString()));
4582 /* FIXME-3 Playing with DBUS...
4583 QDBusVariant VymModel::query (const QString &query)
4585 TreeItem *selti=getSelectedItem();
4587 return QDBusVariant (selti->getHeading());
4589 return QDBusVariant ("Nothing selected.");
4593 void VymModel::testslot() //FIXME-3
4595 cout << "VM::testslot called\n";
4598 void VymModel::selectMapSelectionColor()
4600 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4601 setSelectionColor (col);
4604 void VymModel::setSelectionColorInt (QColor col)
4606 if ( !col.isValid() ) return;
4608 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4609 QString("setSelectionColor (%1)").arg(col.name()),
4610 QString("Set color of selection box to %1").arg(col.name())
4613 mapEditor->setSelectionColor (col);
4616 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4618 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4619 emitShowSelection();
4623 void VymModel::emitSelectionChanged()
4625 QItemSelection newsel=selModel->selection();
4626 emitSelectionChanged (newsel);
4629 void VymModel::setSelectionColor(QColor col)
4631 if ( !col.isValid() ) return;
4633 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4634 QString("setSelectionColor (%1)").arg(col.name()),
4635 QString("Set color of selection box to %1").arg(col.name())
4637 setSelectionColorInt (col);
4640 QColor VymModel::getSelectionColor()
4642 return mapEditor->getSelectionColor();
4645 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4648 for (int i=0;i<rootItem->childCount();i++)
4649 rootItem->child(i)->setHideTmp (mode);
4651 // FIXME-3 needed? scene()->update();
4654 //////////////////////////////////////////////
4655 // Selection related
4656 //////////////////////////////////////////////
4658 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4663 QItemSelectionModel* VymModel::getSelectionModel()
4668 void VymModel::setSelectionBlocked (bool b)
4673 bool VymModel::isSelectionBlocked()
4675 return selectionBlocked;
4678 bool VymModel::select ()
4680 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4683 bool VymModel::select (const QString &s)
4690 TreeItem *ti=findBySelectString(s);
4691 if (ti) return select (index(ti));
4695 bool VymModel::select (LinkableMapObj *lmo)
4697 QItemSelection oldsel=selModel->selection();
4700 return select (index (lmo->getTreeItem()) );
4705 bool VymModel::select (TreeItem *ti)
4707 if (ti) return select (index(ti));
4711 bool VymModel::select (const QModelIndex &index)
4713 if (index.isValid() )
4715 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4716 BranchItem *bi=getSelectedBranch();
4717 if (bi) bi->setLastSelectedBranch();
4723 void VymModel::unselect()
4725 lastSelectString=getSelectString();
4726 selModel->clearSelection();
4729 bool VymModel::reselect()
4731 return select (lastSelectString);
4734 void VymModel::emitShowSelection()
4736 if (!blockReposition)
4737 emit (showSelection() );
4740 void VymModel::emitNoteHasChanged (TreeItem *ti)
4742 QModelIndex ix=index(ti);
4743 emit (noteHasChanged (ix) );
4746 void VymModel::emitDataHasChanged (TreeItem *ti)
4748 QModelIndex ix=index(ti);
4749 emit (dataChanged (ix,ix) );
4753 bool VymModel::selectFirstBranch()
4755 TreeItem *ti=getSelectedBranch();
4758 TreeItem *par=ti->parent();
4761 TreeItem *ti2=par->getFirstBranch();
4762 if (ti2) return select(ti2);
4768 bool VymModel::selectLastBranch()
4770 TreeItem *ti=getSelectedBranch();
4773 TreeItem *par=ti->parent();
4776 TreeItem *ti2=par->getLastBranch();
4777 if (ti2) return select(ti2);
4783 bool VymModel::selectLastSelectedBranch()
4785 BranchItem *bi=getSelectedBranch();
4788 bi=bi->getLastSelectedBranch();
4789 if (bi) return select (bi);
4794 bool VymModel::selectParent()
4796 TreeItem *ti=getSelectedItem();
4807 TreeItem::Type VymModel::selectionType()
4809 QModelIndexList list=selModel->selectedIndexes();
4810 if (list.isEmpty()) return TreeItem::Undefined;
4811 TreeItem *ti = getItem (list.first() );
4812 return ti->getType();
4816 LinkableMapObj* VymModel::getSelectedLMO()
4818 QModelIndexList list=selModel->selectedIndexes();
4819 if (!list.isEmpty() )
4821 TreeItem *ti = getItem (list.first() );
4822 TreeItem::Type type=ti->getType();
4823 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4824 return ((MapItem*)ti)->getLMO();
4829 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4831 TreeItem *ti = getSelectedBranch();
4833 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4838 BranchItem* VymModel::getSelectedBranch()
4840 QModelIndexList list=selModel->selectedIndexes();
4841 if (!list.isEmpty() )
4843 TreeItem *ti = getItem (list.first() );
4844 TreeItem::Type type=ti->getType();
4845 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4846 return (BranchItem*)ti;
4851 ImageItem* VymModel::getSelectedImage()
4853 QModelIndexList list=selModel->selectedIndexes();
4854 if (!list.isEmpty())
4856 TreeItem *ti=getItem (list.first());
4857 if (ti && ti->getType()==TreeItem::Image)
4858 return (ImageItem*)ti;
4863 AttributeItem* VymModel::getSelectedAttribute()
4865 QModelIndexList list=selModel->selectedIndexes();
4866 if (!list.isEmpty() )
4868 TreeItem *ti = getItem (list.first() );
4869 TreeItem::Type type=ti->getType();
4870 if (type ==TreeItem::Attribute)
4871 return (AttributeItem*)ti;
4876 TreeItem* VymModel::getSelectedItem()
4878 QModelIndexList list=selModel->selectedIndexes();
4879 if (!list.isEmpty() )
4880 return getItem (list.first() );
4885 QModelIndex VymModel::getSelectedIndex()
4887 QModelIndexList list=selModel->selectedIndexes();
4888 if (list.isEmpty() )
4889 return QModelIndex();
4891 return list.first();
4894 QString VymModel::getSelectString ()
4896 return getSelectString (getSelectedItem());
4899 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
4901 if (!lmo) return QString();
4902 return getSelectString (lmo->getTreeItem() );
4905 QString VymModel::getSelectString (TreeItem *ti)
4909 switch (ti->getType())
4911 case TreeItem::MapCenter: s="mc:"; break;
4912 case TreeItem::Branch: s="bo:";break;
4913 case TreeItem::Image: s="fi:";break;
4914 case TreeItem::Attribute: s="ai:";break;
4915 case TreeItem::XLink: s="xl:";break;
4917 s="unknown type in VymModel::getSelectString()";
4920 s= s + QString("%1").arg(ti->num());
4922 // call myself recursively
4923 s= getSelectString(ti->parent()) +","+s;