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) // FIXME-1 test e.g. with undo color subtree
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);
1082 blockSaveState=blockSaveStateOrg;
1084 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1085 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1086 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1087 undoSet.writeSettings(histPath);
1089 mainWindow->updateHistory (undoSet);
1092 /* TODO remove testing
1093 cout << "ME::redo() end\n";
1094 cout << " undosAvail="<<undosAvail<<endl;
1095 cout << " redosAvail="<<redosAvail<<endl;
1096 cout << " curStep="<<curStep<<endl;
1097 cout << " ---------------------------"<<endl<<endl;
1103 bool VymModel::isRedoAvailable()
1105 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1111 void VymModel::undo()
1113 // Can we undo at all?
1114 if (undosAvail<1) return;
1116 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1118 bool blockSaveStateOrg=blockSaveState;
1119 blockSaveState=true;
1121 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1122 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1123 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1124 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1125 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1126 QString version=undoSet.readEntry ("/history/version");
1128 /* TODO Maybe check for version, if we save the history
1129 if (!checkVersion(version))
1130 QMessageBox::warning(0,tr("Warning"),
1131 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1134 // Find out current undo directory
1135 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1137 // select object before undo
1138 select (undoSelection);
1142 cout << "VymModel::undo() begin\n";
1143 cout << " undosAvail="<<undosAvail<<endl;
1144 cout << " redosAvail="<<redosAvail<<endl;
1145 cout << " curStep="<<curStep<<endl;
1146 cout << " ---------------------------"<<endl;
1147 cout << " comment="<<comment.toStdString()<<endl;
1148 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1149 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1150 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1151 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1152 cout << " ---------------------------"<<endl<<endl;
1154 parseAtom (undoCommand);
1159 if (curStep<1) curStep=stepsTotal;
1163 blockSaveState=blockSaveStateOrg;
1165 cout << "VymModel::undo() end\n";
1166 cout << " undosAvail="<<undosAvail<<endl;
1167 cout << " redosAvail="<<redosAvail<<endl;
1168 cout << " curStep="<<curStep<<endl;
1169 cout << " ---------------------------"<<endl<<endl;
1172 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1173 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1174 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1175 undoSet.writeSettings(histPath);
1177 mainWindow->updateHistory (undoSet);
1179 emitSelectionChanged();
1182 bool VymModel::isUndoAvailable()
1184 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1190 void VymModel::gotoHistoryStep (int i)
1192 // Restore variables
1193 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1194 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1196 if (i<0) i=undosAvail+redosAvail;
1198 // Clicking above current step makes us undo things
1201 for (int j=0; j<undosAvail-i; j++) undo();
1204 // Clicking below current step makes us redo things
1206 for (int j=undosAvail; j<i; j++)
1208 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1212 // And ignore clicking the current row ;-)
1216 QString VymModel::getHistoryPath()
1218 QString histName(QString("history-%1").arg(curStep));
1219 return (tmpMapDir+"/"+histName);
1222 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1224 sendData(redoCom); //FIXME-3 testing
1229 if (blockSaveState) return;
1231 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1233 // Find out current undo directory
1234 if (undosAvail<stepsTotal) undosAvail++;
1236 if (curStep>stepsTotal) curStep=1;
1238 QString backupXML="";
1239 QString histDir=getHistoryPath();
1240 QString bakMapPath=histDir+"/map.xml";
1242 // Create histDir if not available
1245 makeSubDirs (histDir);
1247 // Save depending on how much needs to be saved
1249 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1251 QString undoCommand="";
1252 if (savemode==UndoCommand)
1254 undoCommand=undoCom;
1256 else if (savemode==PartOfMap )
1258 undoCommand=undoCom;
1259 undoCommand.replace ("PATH",bakMapPath);
1263 if (!backupXML.isEmpty())
1264 // Write XML Data to disk
1265 saveStringToDisk (bakMapPath,backupXML);
1267 // We would have to save all actions in a tree, to keep track of
1268 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1271 // Write the current state to disk
1272 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1273 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1274 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1275 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1276 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1277 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1278 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1279 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1280 undoSet.setEntry (QString("/history/version"),vymVersion);
1281 undoSet.writeSettings(histPath);
1285 // TODO remove after testing
1286 //cout << " into="<< histPath.toStdString()<<endl;
1287 cout << " stepsTotal="<<stepsTotal<<
1288 ", undosAvail="<<undosAvail<<
1289 ", redosAvail="<<redosAvail<<
1290 ", curStep="<<curStep<<endl;
1291 cout << " ---------------------------"<<endl;
1292 cout << " comment="<<comment.toStdString()<<endl;
1293 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1294 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1295 cout << " redoCom="<<redoCom.toStdString()<<endl;
1296 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1297 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1298 cout << " ---------------------------"<<endl;
1301 mainWindow->updateHistory (undoSet);
1307 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1309 // save the selected part of the map, Undo will replace part of map
1310 QString undoSelection="";
1312 undoSelection=getSelectString(undoSel);
1314 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1315 QString redoSelection="";
1317 redoSelection=getSelectString(undoSel);
1319 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1322 saveState (PartOfMap,
1323 undoSelection, "addMapReplace (\"PATH\")",
1329 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1333 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1336 QString undoSelection;
1337 QString redoSelection=getSelectString(redoSel);
1338 if (redoSel->getType()==TreeItem::Branch)
1340 undoSelection=getSelectString (redoSel->parent());
1341 // save the selected branch of the map, Undo will insert part of map
1342 saveState (PartOfMap,
1343 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1344 redoSelection, "delete ()",
1348 if (redoSel->getType()==TreeItem::MapCenter)
1350 // save the selected branch of the map, Undo will insert part of map
1351 saveState (PartOfMap,
1352 undoSelection, QString("addMapInsert (\"PATH\")"),
1353 redoSelection, "delete ()",
1360 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1362 // "Normal" savestate: save commands, selections and comment
1363 // so just save commands for undo and redo
1364 // and use current selection
1366 QString redoSelection="";
1367 if (redoSel) redoSelection=getSelectString(redoSel);
1368 QString undoSelection="";
1369 if (undoSel) undoSelection=getSelectString(undoSel);
1371 saveState (UndoCommand,
1378 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1380 // "Normal" savestate: save commands, selections and comment
1381 // so just save commands for undo and redo
1382 // and use current selection
1383 saveState (UndoCommand,
1390 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1392 // "Normal" savestate applied to model (no selection needed):
1393 // save commands and comment
1394 saveState (UndoCommand,
1402 QGraphicsScene* VymModel::getScene ()
1407 TreeItem* VymModel::findBySelectString(QString s)
1409 if (s.isEmpty() ) return NULL;
1411 // Old maps don't have multiple mapcenters and don't save full path
1412 if (s.left(2) !="mc")
1415 QStringList parts=s.split (",");
1418 TreeItem *ti=rootItem;
1420 while (!parts.isEmpty() )
1422 typ=parts.first().left(2);
1423 n=parts.first().right(parts.first().length() - 3).toInt();
1424 parts.removeFirst();
1425 if (typ=="mc" || typ=="bo")
1426 ti=ti->getBranchNum (n);
1427 /* FIXME-2 add other types to getSelectionString and findBy...
1430 ti=ti->getImageNum (n);
1432 if(!ti) return NULL;
1437 TreeItem* VymModel::findID (const QString &s)
1439 BranchItem *cur=NULL;
1440 BranchItem *prev=NULL;
1444 if (s==cur->getID() ) return cur;
1450 //////////////////////////////////////////////
1452 //////////////////////////////////////////////
1453 void VymModel::setVersion (const QString &s)
1458 void VymModel::setAuthor (const QString &s)
1461 QString ("setMapAuthor (\"%1\")").arg(author),
1462 QString ("setMapAuthor (\"%1\")").arg(s),
1463 QString ("Set author of map to \"%1\"").arg(s)
1468 QString VymModel::getAuthor()
1473 void VymModel::setComment (const QString &s)
1476 QString ("setMapComment (\"%1\")").arg(comment),
1477 QString ("setMapComment (\"%1\")").arg(s),
1478 QString ("Set comment of map")
1483 QString VymModel::getComment ()
1488 QString VymModel::getDate ()
1490 return QDate::currentDate().toString ("yyyy-MM-dd");
1493 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1496 BranchItem *cur=NULL;
1497 BranchItem *prev=NULL;
1507 void VymModel::setHeading(const QString &s)
1509 BranchItem *selbi=getSelectedBranch();
1514 "setHeading (\""+selbi->getHeading()+"\")",
1516 "setHeading (\""+s+"\")",
1517 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1518 selbi->setHeading(s );
1519 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1521 emitSelectionChanged();
1525 QString VymModel::getHeading()
1527 TreeItem *selti=getSelectedItem();
1529 return selti->getHeading();
1534 BranchItem* VymModel::findText (QString s, bool cs)
1536 QTextDocument::FindFlags flags=0;
1537 if (cs) flags=QTextDocument::FindCaseSensitively;
1540 { // Nothing found or new find process
1542 // nothing found, start again
1546 next (findCurrent,findPrevious);
1548 bool searching=true;
1549 bool foundNote=false;
1550 while (searching && !EOFind)
1554 // Searching in Note
1555 if (findCurrent->getNote().contains(s,cs))
1557 select (findCurrent);
1559 if (getSelectedBranch()!=itFind)
1562 emitShowSelection();
1565 if (textEditor->findText(s,flags))
1571 // Searching in Heading
1572 if (searching && findCurrent->getHeading().contains (s,cs) )
1574 select(findCurrent);
1580 if (!next(findCurrent,findPrevious) )
1583 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1586 return getSelectedBranch();
1591 void VymModel::findReset()
1592 { // Necessary if text to find changes during a find process
1598 void VymModel::setScene (QGraphicsScene *s)
1600 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1601 //init(); // Here we have a mapScene set,
1602 // which is (still) needed to create MapCenters
1605 void VymModel::setURL(const QString &url)
1607 TreeItem *selti=getSelectedItem();
1610 QString oldurl=selti->getURL();
1611 selti->setURL (url);
1614 QString ("setURL (\"%1\")").arg(oldurl),
1616 QString ("setURL (\"%1\")").arg(url),
1617 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1620 emitDataHasChanged (selti);
1621 emitShowSelection();
1625 QString VymModel::getURL()
1627 TreeItem *selti=getSelectedItem();
1629 return selti->getURL();
1634 QStringList VymModel::getURLs()
1637 BranchItem *selbi=getSelectedBranch();
1638 BranchItem *cur=selbi;
1639 BranchItem *prev=NULL;
1642 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1643 cur=next (cur,prev,selbi);
1649 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1651 BranchItem *bi=getSelectedBranch();
1654 BranchObj *bo=(BranchObj*)(bi->getLMO());
1657 QString s=bo->getFrameTypeName();
1658 bo->setFrameType (t);
1659 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1660 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1662 bo->updateLinkGeometry();
1667 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1669 BranchItem *bi=getSelectedBranch();
1672 BranchObj *bo=(BranchObj*)(bi->getLMO());
1675 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1676 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1677 bo->setFrameType (s);
1679 bo->updateLinkGeometry();
1684 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1687 BranchItem *bi=getSelectedBranch();
1690 BranchObj *bo=(BranchObj*)(bi->getLMO());
1693 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1694 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1695 bo->setFramePenColor (c);
1700 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1702 BranchItem *bi=getSelectedBranch();
1705 BranchObj *bo=(BranchObj*)(bi->getLMO());
1708 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1709 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1710 bo->setFrameBrushColor (c);
1715 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1717 BranchItem *bi=getSelectedBranch();
1720 BranchObj *bo=(BranchObj*)(bi->getLMO());
1723 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1724 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1725 bo->setFramePadding (i);
1727 bo->updateLinkGeometry();
1732 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1734 BranchItem *bi=getSelectedBranch();
1737 BranchObj *bo=(BranchObj*)(bi->getLMO());
1740 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1741 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1742 bo->setFrameBorderWidth (i);
1744 bo->updateLinkGeometry();
1749 void VymModel::setIncludeImagesVer(bool b)
1751 BranchItem *bi=getSelectedBranch();
1754 QString u= b ? "false" : "true";
1755 QString r=!b ? "false" : "true";
1759 QString("setIncludeImagesVertically (%1)").arg(u),
1761 QString("setIncludeImagesVertically (%1)").arg(r),
1762 QString("Include images vertically in %1").arg(getObjectName(bi))
1764 bi->setIncludeImagesVer(b);
1765 emitDataHasChanged ( bi);
1770 void VymModel::setIncludeImagesHor(bool b)
1772 BranchItem *bi=getSelectedBranch();
1775 QString u= b ? "false" : "true";
1776 QString r=!b ? "false" : "true";
1780 QString("setIncludeImagesHorizontally (%1)").arg(u),
1782 QString("setIncludeImagesHorizontally (%1)").arg(r),
1783 QString("Include images horizontally in %1").arg(getObjectName(bi))
1785 bi->setIncludeImagesHor(b);
1786 emitDataHasChanged ( bi);
1791 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1793 TreeItem *ti=getSelectedItem();
1794 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1796 QString u= b ? "false" : "true";
1797 QString r=!b ? "false" : "true";
1801 QString("setHideLinkUnselected (%1)").arg(u),
1803 QString("setHideLinkUnselected (%1)").arg(r),
1804 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1806 ((MapItem*)ti)->setHideLinkUnselected(b);
1810 void VymModel::setHideExport(bool b)
1812 TreeItem *ti=getSelectedItem();
1814 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1816 ti->setHideInExport (b);
1817 QString u= b ? "false" : "true";
1818 QString r=!b ? "false" : "true";
1822 QString ("setHideExport (%1)").arg(u),
1824 QString ("setHideExport (%1)").arg(r),
1825 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1827 emitDataHasChanged(ti);
1828 emitSelectionChanged();
1831 // emitSelectionChanged();
1832 // FIXME-3 VM needed? scene()->update();
1836 void VymModel::toggleHideExport()
1838 TreeItem *selti=getSelectedItem();
1840 setHideExport ( !selti->hideInExport() );
1844 void VymModel::copy()
1846 TreeItem *selti=getSelectedItem();
1848 (selti->getType() == TreeItem::Branch ||
1849 selti->getType() == TreeItem::MapCenter ||
1850 selti->getType() == TreeItem::Image ))
1852 if (redosAvail == 0)
1855 QString s=getSelectString(selti);
1856 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1857 curClipboard=curStep;
1860 // Copy also to global clipboard, because we are at last step in history
1861 QString bakMapName(QString("history-%1").arg(curStep));
1862 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1863 copyDir (bakMapDir,clipboardDir );
1865 clipboardEmpty=false;
1871 void VymModel::pasteNoSave(const int &n)
1873 bool old=blockSaveState;
1874 blockSaveState=true;
1875 bool zippedOrg=zipped;
1876 if (redosAvail > 0 || n!=0)
1878 // Use the "historical" buffer
1879 QString bakMapName(QString("history-%1").arg(n));
1880 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1881 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1883 // Use the global buffer
1884 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1889 void VymModel::paste()
1891 BranchItem *selbi=getSelectedBranch();
1894 saveStateChangingPart(
1897 QString ("paste (%1)").arg(curClipboard),
1898 QString("Paste to %1").arg( getObjectName(selbi))
1905 void VymModel::cut()
1907 TreeItem *selti=getSelectedItem();
1908 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1916 void VymModel::moveUp() //FIXME-2 crashes if trying to move MCO
1918 BranchItem *selbi=getSelectedBranch();
1921 if (!selbi->canMoveUp()) return;
1922 QString oldsel=getSelectString();
1923 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1925 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1929 void VymModel::moveDown()
1931 BranchItem *selbi=getSelectedBranch();
1934 if (!selbi->canMoveDown()) return;
1935 QString oldsel=getSelectString();
1936 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1938 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1942 void VymModel::sortChildren() // FIXME-2 not implemented yet
1945 BranchObj* bo=getSelectedBranch();
1948 if(treeItem->branchCount()>1)
1950 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1953 emitShowSelection();
1959 BranchItem* VymModel::createMapCenter()
1961 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1965 BranchItem* VymModel::createBranch(BranchItem *dst)
1968 return addNewBranchInt (dst,-2);
1973 ImageItem* VymModel::createImage(BranchItem *dst)
1980 QList<QVariant> cData;
1981 cData << "new" << "undef";
1983 ImageItem *newii=new ImageItem(cData) ;
1984 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1986 emit (layoutAboutToBeChanged() );
1989 if (!parix.isValid()) cout << "VM::createII invalid index\n";
1990 n=dst->getRowNumAppend(newii);
1991 beginInsertRows (parix,n,n);
1992 dst->appendChild (newii);
1995 emit (layoutChanged() );
1997 // save scroll state. If scrolled, automatically select
1998 // new branch in order to tmp unscroll parent...
1999 newii->createMapObj(mapScene);
2006 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2013 QList<QVariant> cData;
2014 cData << "new xLink"<<"undef";
2016 XLinkItem *newxli=new XLinkItem(cData) ;
2017 newxli->setBegin (bi);
2019 emit (layoutAboutToBeChanged() );
2022 n=bi->getRowNumAppend(newxli);
2023 beginInsertRows (parix,n,n);
2024 bi->appendChild (newxli);
2027 emit (layoutChanged() );
2029 // save scroll state. If scrolled, automatically select
2030 // new branch in order to tmp unscroll parent...
2033 newxli->createMapObj(mapScene);
2041 AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing
2043 BranchItem *selbi=getSelectedBranch();
2046 QList<QVariant> cData;
2047 cData << "new attribute" << "undef";
2048 AttributeItem *a=new AttributeItem (cData);
2050 emit (layoutAboutToBeChanged() );
2052 QModelIndex parix=index(selbi);
2053 int n=selbi->getRowNumAppend (a);
2054 beginInsertRows (parix,n,n);
2055 selbi->appendChild (a);
2058 emit (layoutChanged() );
2066 BranchItem* VymModel::addMapCenter ()
2068 BranchItem *bi=addMapCenter (contextPos);
2070 emitShowSelection();
2075 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2076 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2081 BranchItem* VymModel::addMapCenter(QPointF absPos)
2082 // createMapCenter could then probably be merged with createBranch
2086 QModelIndex parix=index(rootItem);
2088 QList<QVariant> cData;
2089 cData << "VM:addMapCenter" << "undef";
2090 BranchItem *newbi=new BranchItem (cData,rootItem);
2091 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2092 int n=rootItem->getRowNumAppend (newbi);
2094 emit (layoutAboutToBeChanged() );
2095 beginInsertRows (parix,n,n);
2097 rootItem->appendChild (newbi);
2100 emit (layoutChanged() );
2103 newbi->setPositionMode (MapItem::Absolute);
2104 BranchObj *bo=newbi->createMapObj(mapScene);
2105 if (bo) bo->move (absPos);
2110 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2112 // Depending on pos:
2113 // -3 insert in children of parent above selection
2114 // -2 add branch to selection
2115 // -1 insert in children of parent below selection
2116 // 0..n insert in children of parent at pos
2119 QList<QVariant> cData;
2120 cData << "new" << "undef";
2125 BranchItem *newbi=new BranchItem (cData);
2126 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2128 emit (layoutAboutToBeChanged() );
2134 n=parbi->getRowNumAppend (newbi);
2135 beginInsertRows (parix,n,n);
2136 parbi->appendChild (newbi);
2138 }else if (num==-1 || num==-3)
2140 // insert below selection
2141 parbi=(BranchItem*)dst->parent();
2144 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2145 beginInsertRows (parix,n,n);
2146 parbi->insertBranch(n,newbi);
2149 emit (layoutChanged() );
2151 // save scroll state. If scrolled, automatically select
2152 // new branch in order to tmp unscroll parent...
2153 newbi->createMapObj(mapScene);
2158 BranchItem* VymModel::addNewBranch(int pos)
2160 // Different meaning than num in addNewBranchInt!
2164 BranchItem *newbi=NULL;
2165 BranchItem *selbi=getSelectedBranch();
2169 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2171 newbi=addNewBranchInt (selbi,pos-2);
2179 QString ("addBranch (%1)").arg(pos),
2180 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2183 // emitSelectionChanged(); FIXME-3
2184 latestAddedItem=newbi;
2185 // In Network mode, the client needs to know where the new branch is,
2186 // so we have to pass on this information via saveState.
2187 // TODO: Get rid of this positioning workaround
2188 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2189 sendData ("selectLatestAdded ()");
2190 sendData (QString("move %1").arg(ps));
2199 BranchItem* VymModel::addNewBranchBefore()
2201 BranchItem *newbi=NULL;
2202 BranchItem *selbi=getSelectedBranch();
2203 if (selbi && selbi->getType()==TreeItem::Branch)
2204 // We accept no MapCenter here, so we _have_ a parent
2206 //QPointF p=bo->getRelPos();
2209 // add below selection
2210 newbi=addNewBranchInt (selbi,-1);
2214 //newbi->move2RelPos (p);
2216 // Move selection to new branch
2217 relinkBranch (selbi,newbi,0);
2219 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2220 QString ("Add branch before %1").arg(getObjectName(selbi)));
2222 // FIXME-3 needed? reposition();
2223 // emitSelectionChanged(); FIXME-3
2229 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2233 if (branch->depth()==0)
2235 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2237 emit (layoutAboutToBeChanged() );
2238 BranchItem *branchpi=(BranchItem*)branch->parent();
2239 // Remove at current position
2240 int n=branch->childNum();
2241 beginRemoveRows (index(branchpi),n,n);
2242 branchpi->removeChild (n);
2245 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2247 // Append as last branch to dst
2248 if (dst->branchCount()==0)
2251 n=dst->getFirstBranch()->childNumber();
2252 beginInsertRows (index(dst),n+pos,n+pos);
2253 dst->insertBranch (pos,branch);
2256 // Correct type if necessesary
2257 if (branch->getType()==TreeItem::MapCenter)
2258 branch->setType(TreeItem::Branch);
2260 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2261 branch->updateStyles();
2263 emit (layoutChanged() );
2264 reposition(); // both for moveUp/Down and relinking
2265 if (dst->isScrolled() )
2268 branch->updateVisibility();
2277 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2281 emit (layoutAboutToBeChanged() );
2283 BranchItem *pi=(BranchItem*)(image->parent());
2284 QString oldParString=getSelectString (pi);
2285 // Remove at current position
2286 int n=image->childNum();
2287 beginRemoveRows (index(pi),n,n);
2288 pi->removeChild (n);
2292 QModelIndex dstix=index(dst);
2293 n=dst->getRowNumAppend (image);
2294 beginInsertRows (dstix,n,n+1);
2295 dst->appendChild (image);
2298 // Set new parent also for lmo
2299 if (image->getLMO() && dst->getLMO() )
2300 image->getLMO()->setParObj (dst->getLMO() );
2302 emit (layoutChanged() );
2305 QString("relinkTo (\"%1\")").arg(oldParString),
2307 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2308 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2314 void VymModel::deleteSelection()
2316 BranchItem *selbi=getSelectedBranch();
2321 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2323 TreeItem *pi=deleteItem (selbi);
2327 emitShowSelection();
2331 TreeItem *ti=getSelectedItem();
2334 TreeItem *pi=ti->parent();
2336 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2338 saveStateChangingPart(
2342 QString("Delete %1").arg(getObjectName(ti))
2345 // FIXME-1 savestate missing for deletion of other types than above
2348 emitDataHasChanged (pi);
2351 emitShowSelection();
2356 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2359 BranchItem *selbi=getSelectedBranch();
2363 // Don't use this on mapcenter
2364 if (selbi->depth()<2) return;
2366 pi=(BranchItem*)(selbi->parent());
2367 // Check if we have childs at all to keep
2368 if (selbi->branchCount()==0)
2375 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2376 saveStateChangingPart(
2379 "deleteKeepChildren ()",
2380 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2383 QString sel=getSelectString(selbi);
2385 int pos=selbi->num();
2386 BranchItem *bi=selbi->getFirstBranch();
2389 relinkBranch (bi,pi,pos);
2390 bi=selbi->getFirstBranch();
2396 BranchObj *bo=getSelectedBranchObj();
2399 bo->move2RelPos (p);
2405 void VymModel::deleteChildren()
2408 BranchItem *selbi=getSelectedBranch();
2411 saveStateChangingPart(
2414 "deleteChildren ()",
2415 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2417 emit (layoutAboutToBeChanged() );
2419 QModelIndex ix=index (selbi);
2420 int n=selbi->branchCount()-1;
2421 beginRemoveRows (ix,0,n);
2422 removeRows (0,n+1,ix);
2424 if (selbi->isScrolled()) selbi->unScroll();
2425 emit (layoutChanged() );
2430 TreeItem* VymModel::deleteItem (TreeItem *ti)
2432 cout << "VM::deleteItem "<<ti<<endl;
2435 TreeItem *pi=ti->parent();
2436 QModelIndex parentIndex=index(pi);
2438 emit (layoutAboutToBeChanged() );
2440 int n=ti->childNum();
2441 beginRemoveRows (parentIndex,n,n);
2442 removeRows (n,1,parentIndex);
2446 emit (layoutChanged() );
2447 if (pi->depth()>=0) return pi;
2452 bool VymModel::scrollBranch(BranchItem *bi)
2456 if (bi->isScrolled()) return false;
2457 if (bi->branchCount()==0) return false;
2458 if (bi->depth()==0) return false;
2459 if (bi->toggleScroll())
2466 QString ("%1 ()").arg(u),
2468 QString ("%1 ()").arg(r),
2469 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2471 emitDataHasChanged(bi);
2472 emitSelectionChanged();
2473 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2480 bool VymModel::unscrollBranch(BranchItem *bi)
2484 if (!bi->isScrolled()) return false;
2485 if (bi->branchCount()==0) return false;
2486 if (bi->depth()==0) return false;
2493 QString ("%1 ()").arg(u),
2495 QString ("%1 ()").arg(r),
2496 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2499 emitDataHasChanged(bi);
2500 emitSelectionChanged();
2502 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2508 void VymModel::toggleScroll()
2510 BranchItem *bi=(BranchItem*)getSelectedBranch();
2511 if (bi && bi->isBranchLikeType() )
2513 if (bi->isScrolled())
2514 unscrollBranch (bi);
2518 // saveState is called in above functions
2521 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2525 BranchObj *bo=getSelectedBranch();
2531 if (bo->isScrolled()) unscrollBranch (bo);
2538 void VymModel::emitExpandAll()
2540 emit (expandAll() );
2543 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2545 BranchItem *bi=getSelectedBranch();
2549 if (bi->isActiveStandardFlag(name))
2561 QString("%1 (\"%2\")").arg(u).arg(name),
2563 QString("%1 (\"%2\")").arg(r).arg(name),
2564 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2565 bi->toggleStandardFlag (name, master);
2567 emitSelectionChanged();
2571 void VymModel::addFloatImage (const QPixmap &img)
2573 BranchItem *selbi=getSelectedBranch();
2576 ImageItem *ii=createImage (selbi);
2578 ii->setOriginalFilename("No original filename (image added by dropevent)");
2579 QString s=getSelectString(selbi);
2580 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2581 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2583 // FIXME-3 VM needed? scene()->update();
2588 void VymModel::colorBranch (QColor c)
2590 BranchItem *selbi=getSelectedBranch();
2595 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2597 QString ("colorBranch (\"%1\")").arg(c.name()),
2598 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2600 selbi->setHeadingColor(c); // color branch
2604 void VymModel::colorSubtree (QColor c)
2606 BranchItem *selbi=getSelectedBranch();
2609 saveStateChangingPart(
2612 QString ("colorSubtree (\"%1\")").arg(c.name()),
2613 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2615 BranchItem *prev=NULL;
2616 BranchItem *cur=selbi;
2619 cur->setHeadingColor(c); // color links, color children
2620 cur=next (cur,prev,selbi);
2626 QColor VymModel::getCurrentHeadingColor()
2628 BranchItem *selbi=getSelectedBranch();
2629 if (selbi) return selbi->getHeadingColor();
2631 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2637 void VymModel::editURL()
2639 TreeItem *selti=getSelectedItem();
2643 QString text = QInputDialog::getText(
2644 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2645 selti->getURL(), &ok, NULL);
2647 // user entered something and pressed OK
2652 void VymModel::editLocalURL()
2654 TreeItem *selti=getSelectedItem();
2657 QStringList filters;
2658 filters <<"All files (*)";
2659 filters << tr("Text","Filedialog") + " (*.txt)";
2660 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2661 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2662 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2663 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2664 fd->setFilters (filters);
2665 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2666 fd->setDirectory (lastFileDir);
2667 if (! selti->getVymLink().isEmpty() )
2668 fd->selectFile( selti->getURL() );
2671 if ( fd->exec() == QDialog::Accepted )
2673 lastFileDir=QDir (fd->directory().path());
2674 setURL (fd->selectedFile() );
2680 void VymModel::editHeading2URL()
2682 TreeItem *selti=getSelectedItem();
2684 setURL (selti->getHeading());
2687 void VymModel::editBugzilla2URL()
2689 TreeItem *selti=getSelectedItem();
2692 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2697 void VymModel::editFATE2URL()
2699 TreeItem *selti=getSelectedItem();
2702 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2705 "setURL (\""+selti->getURL()+"\")",
2707 "setURL (\""+url+"\")",
2708 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2710 selti->setURL (url);
2711 // FIXME-4 updateActions();
2715 void VymModel::editVymLink()
2717 BranchItem *bi=getSelectedBranch();
2720 QStringList filters;
2721 filters <<"VYM map (*.vym)";
2722 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2723 fd->setFilters (filters);
2724 fd->setCaption(vymName+" - " +tr("Link to another map"));
2725 fd->setDirectory (lastFileDir);
2726 if (! bi->getVymLink().isEmpty() )
2727 fd->selectFile( bi->getVymLink() );
2731 if ( fd->exec() == QDialog::Accepted )
2733 lastFileDir=QDir (fd->directory().path());
2736 "setVymLink (\""+bi->getVymLink()+"\")",
2738 "setVymLink (\""+fd->selectedFile()+"\")",
2739 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2741 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2746 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2748 // Internal function, no saveState needed
2749 TreeItem *selti=getSelectedItem();
2752 selti->setVymLink(s);
2754 emitDataHasChanged (selti);
2755 emitShowSelection();
2759 void VymModel::deleteVymLink()
2761 BranchItem *bi=getSelectedBranch();
2766 "setVymLink (\""+bi->getVymLink()+"\")",
2768 "setVymLink (\"\")",
2769 QString("Unset vymlink of %1").arg(getObjectName(bi))
2771 bi->setVymLink ("" );
2777 QString VymModel::getVymLink()
2779 BranchItem *bi=getSelectedBranch();
2781 return bi->getVymLink();
2787 QStringList VymModel::getVymLinks()
2790 BranchItem *selbi=getSelectedBranch();
2791 BranchItem *cur=selbi;
2792 BranchItem *prev=NULL;
2795 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2796 cur=next (cur,prev,selbi);
2802 void VymModel::followXLink(int i)
2805 BranchItem *selbi=getSelectedBranch();
2808 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2809 if (selbi) select (selbi);
2813 void VymModel::editXLink(int i)
2816 BranchItem *selbi=getSelectedBranch();
2819 XLinkItem *xli=selbi->getXLinkNum(i);
2822 EditXLinkDialog dia;
2824 dia.setSelection(selbi);
2825 if (dia.exec() == QDialog::Accepted)
2827 if (dia.useSettingsGlobal() )
2829 setMapDefXLinkColor (xli->getColor() );
2830 setMapDefXLinkWidth (xli->getWidth() );
2832 if (dia.deleteXLink()) deleteItem (xli);
2842 //////////////////////////////////////////////
2844 //////////////////////////////////////////////
2846 void VymModel::parseAtom(const QString &atom)
2848 TreeItem* selti=getSelectedItem();
2849 BranchItem *selbi=getSelectedBranch();
2855 // Split string s into command and parameters
2856 parser.parseAtom (atom);
2857 QString com=parser.getCommand();
2859 // External commands
2860 /////////////////////////////////////////////////////////////////////
2861 if (com=="addBranch")
2865 parser.setError (Aborted,"Nothing selected");
2866 } else if (! selbi )
2868 parser.setError (Aborted,"Type of selection is not a branch");
2873 if (parser.checkParCount(pl))
2875 if (parser.parCount()==0)
2879 n=parser.parInt (ok,0);
2880 if (ok ) addNewBranch (n);
2884 /////////////////////////////////////////////////////////////////////
2885 } else if (com=="addBranchBefore")
2889 parser.setError (Aborted,"Nothing selected");
2890 } else if (! selbi )
2892 parser.setError (Aborted,"Type of selection is not a branch");
2895 if (parser.parCount()==0)
2897 addNewBranchBefore ();
2900 /////////////////////////////////////////////////////////////////////
2901 } else if (com==QString("addMapCenter"))
2903 if (parser.checkParCount(2))
2905 x=parser.parDouble (ok,0);
2908 y=parser.parDouble (ok,1);
2909 if (ok) addMapCenter (QPointF(x,y));
2912 /////////////////////////////////////////////////////////////////////
2913 } else if (com==QString("addMapReplace"))
2917 parser.setError (Aborted,"Nothing selected");
2918 } else if (! selbi )
2920 parser.setError (Aborted,"Type of selection is not a branch");
2921 } else if (parser.checkParCount(1))
2923 //s=parser.parString (ok,0); // selection
2924 t=parser.parString (ok,0); // path to map
2925 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2926 addMapReplaceInt(getSelectString(selbi),t);
2928 /////////////////////////////////////////////////////////////////////
2929 } else if (com==QString("addMapInsert"))
2931 if (parser.parCount()==2)
2936 parser.setError (Aborted,"Nothing selected");
2937 } else if (! selbi )
2939 parser.setError (Aborted,"Type of selection is not a branch");
2942 t=parser.parString (ok,0); // path to map
2943 n=parser.parInt(ok,1); // position
2944 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2945 addMapInsertInt(t,n);
2947 } else if (parser.parCount()==1)
2949 t=parser.parString (ok,0); // path to map
2950 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2953 parser.setError (Aborted,"Wrong number of parameters");
2954 /////////////////////////////////////////////////////////////////////
2955 } else if (com=="clearFlags")
2959 parser.setError (Aborted,"Nothing selected");
2960 } else if (! selbi )
2962 parser.setError (Aborted,"Type of selection is not a branch");
2963 } else if (parser.checkParCount(0))
2965 selbi->deactivateAllStandardFlags();
2967 /////////////////////////////////////////////////////////////////////
2968 } else if (com=="colorBranch")
2972 parser.setError (Aborted,"Nothing selected");
2973 } else if (! selbi )
2975 parser.setError (Aborted,"Type of selection is not a branch");
2976 } else if (parser.checkParCount(1))
2978 QColor c=parser.parColor (ok,0);
2979 if (ok) colorBranch (c);
2981 /////////////////////////////////////////////////////////////////////
2982 } else if (com=="colorSubtree")
2986 parser.setError (Aborted,"Nothing selected");
2987 } else if (! selbi )
2989 parser.setError (Aborted,"Type of selection is not a branch");
2990 } else if (parser.checkParCount(1))
2992 QColor c=parser.parColor (ok,0);
2993 if (ok) colorSubtree (c);
2995 /////////////////////////////////////////////////////////////////////
2996 } else if (com=="copy")
3000 parser.setError (Aborted,"Nothing selected");
3001 } else if ( selectionType()!=TreeItem::Branch &&
3002 selectionType()!=TreeItem::MapCenter &&
3003 selectionType()!=TreeItem::Image )
3005 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3006 } else if (parser.checkParCount(0))
3010 /////////////////////////////////////////////////////////////////////
3011 } else if (com=="cut")
3015 parser.setError (Aborted,"Nothing selected");
3016 } else if ( selectionType()!=TreeItem::Branch &&
3017 selectionType()!=TreeItem::MapCenter &&
3018 selectionType()!=TreeItem::Image )
3020 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3021 } else if (parser.checkParCount(0))
3025 /////////////////////////////////////////////////////////////////////
3026 } else if (com=="delete")
3030 parser.setError (Aborted,"Nothing selected");
3032 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3034 parser.setError (Aborted,"Type of selection is wrong.");
3037 else if (parser.checkParCount(0))
3041 /////////////////////////////////////////////////////////////////////
3042 } else if (com=="deleteKeepChildren")
3046 parser.setError (Aborted,"Nothing selected");
3047 } else if (! selbi )
3049 parser.setError (Aborted,"Type of selection is not a branch");
3050 } else if (parser.checkParCount(0))
3052 deleteKeepChildren();
3054 /////////////////////////////////////////////////////////////////////
3055 } else if (com=="deleteChildren")
3059 parser.setError (Aborted,"Nothing selected");
3062 parser.setError (Aborted,"Type of selection is not a branch");
3063 } else if (parser.checkParCount(0))
3067 /////////////////////////////////////////////////////////////////////
3068 } else if (com=="exportASCII")
3072 if (parser.parCount()>=1)
3073 // Hey, we even have a filename
3074 fname=parser.parString(ok,0);
3077 parser.setError (Aborted,"Could not read filename");
3080 exportASCII (fname,false);
3082 /////////////////////////////////////////////////////////////////////
3083 } else if (com=="exportImage")
3087 if (parser.parCount()>=2)
3088 // Hey, we even have a filename
3089 fname=parser.parString(ok,0);
3092 parser.setError (Aborted,"Could not read filename");
3095 QString format="PNG";
3096 if (parser.parCount()>=2)
3098 format=parser.parString(ok,1);
3100 exportImage (fname,false,format);
3102 /////////////////////////////////////////////////////////////////////
3103 } else if (com=="exportXHTML")
3107 if (parser.parCount()>=2)
3108 // Hey, we even have a filename
3109 fname=parser.parString(ok,1);
3112 parser.setError (Aborted,"Could not read filename");
3115 exportXHTML (fname,false);
3117 /////////////////////////////////////////////////////////////////////
3118 } else if (com=="exportXML")
3122 if (parser.parCount()>=2)
3123 // Hey, we even have a filename
3124 fname=parser.parString(ok,1);
3127 parser.setError (Aborted,"Could not read filename");
3130 exportXML (fname,false);
3132 /////////////////////////////////////////////////////////////////////
3133 } else if (com=="importDir")
3137 parser.setError (Aborted,"Nothing selected");
3138 } else if (! selbi )
3140 parser.setError (Aborted,"Type of selection is not a branch");
3141 } else if (parser.checkParCount(1))
3143 s=parser.parString(ok,0);
3144 if (ok) importDirInt(s);
3146 /////////////////////////////////////////////////////////////////////
3147 } else if (com=="relinkTo")
3151 parser.setError (Aborted,"Nothing selected");
3154 if (parser.checkParCount(4))
3156 // 0 selectstring of parent
3157 // 1 num in parent (for branches)
3158 // 2,3 x,y of mainbranch or mapcenter
3159 s=parser.parString(ok,0);
3160 TreeItem *dst=findBySelectString (s);
3163 if (dst->getType()==TreeItem::Branch)
3165 // Get number in parent
3166 n=parser.parInt (ok,1);
3169 relinkBranch (selbi,(BranchItem*)dst,n);
3170 emitSelectionChanged();
3172 } else if (dst->getType()==TreeItem::MapCenter)
3174 relinkBranch (selbi,(BranchItem*)dst);
3175 // Get coordinates of mainbranch
3176 x=parser.parDouble(ok,2);
3179 y=parser.parDouble(ok,3);
3182 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3183 emitSelectionChanged();
3189 } else if ( selti->getType() == TreeItem::Image)
3191 if (parser.checkParCount(1))
3193 // 0 selectstring of parent
3194 s=parser.parString(ok,0);
3195 TreeItem *dst=findBySelectString (s);
3198 if (dst->isBranchLikeType())
3199 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3201 parser.setError (Aborted,"Destination is not a branch");
3204 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3205 /////////////////////////////////////////////////////////////////////
3206 } else if (com=="loadImage")
3210 parser.setError (Aborted,"Nothing selected");
3211 } else if (! selbi )
3213 parser.setError (Aborted,"Type of selection is not a branch");
3214 } else if (parser.checkParCount(1))
3216 s=parser.parString(ok,0);
3217 if (ok) loadFloatImageInt (selbi,s);
3219 /////////////////////////////////////////////////////////////////////
3220 } else if (com=="moveUp")
3224 parser.setError (Aborted,"Nothing selected");
3225 } else if (! selbi )
3227 parser.setError (Aborted,"Type of selection is not a branch");
3228 } else if (parser.checkParCount(0))
3232 /////////////////////////////////////////////////////////////////////
3233 } else if (com=="moveDown")
3237 parser.setError (Aborted,"Nothing selected");
3238 } else if (! selbi )
3240 parser.setError (Aborted,"Type of selection is not a branch");
3241 } else if (parser.checkParCount(0))
3245 /////////////////////////////////////////////////////////////////////
3246 } else if (com=="move")
3250 parser.setError (Aborted,"Nothing selected");
3251 } else if ( selectionType()!=TreeItem::Branch &&
3252 selectionType()!=TreeItem::MapCenter &&
3253 selectionType()!=TreeItem::Image )
3255 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3256 } else if (parser.checkParCount(2))
3258 x=parser.parDouble (ok,0);
3261 y=parser.parDouble (ok,1);
3265 /////////////////////////////////////////////////////////////////////
3266 } else if (com=="moveRel")
3270 parser.setError (Aborted,"Nothing selected");
3271 } else if ( selectionType()!=TreeItem::Branch &&
3272 selectionType()!=TreeItem::MapCenter &&
3273 selectionType()!=TreeItem::Image )
3275 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3276 } else if (parser.checkParCount(2))
3278 x=parser.parDouble (ok,0);
3281 y=parser.parDouble (ok,1);
3282 if (ok) moveRel (x,y);
3285 /////////////////////////////////////////////////////////////////////
3286 } else if (com=="nop")
3288 /////////////////////////////////////////////////////////////////////
3289 } else if (com=="paste")
3293 parser.setError (Aborted,"Nothing selected");
3294 } else if (! selbi )
3296 parser.setError (Aborted,"Type of selection is not a branch");
3297 } else if (parser.checkParCount(1))
3299 n=parser.parInt (ok,0);
3300 if (ok) pasteNoSave(n);
3302 /////////////////////////////////////////////////////////////////////
3303 } else if (com=="qa")
3307 parser.setError (Aborted,"Nothing selected");
3308 } else if (! selbi )
3310 parser.setError (Aborted,"Type of selection is not a branch");
3311 } else if (parser.checkParCount(4))
3314 c=parser.parString (ok,0);
3317 parser.setError (Aborted,"No comment given");
3320 s=parser.parString (ok,1);
3323 parser.setError (Aborted,"First parameter is not a string");
3326 t=parser.parString (ok,2);
3329 parser.setError (Aborted,"Condition is not a string");
3332 u=parser.parString (ok,3);
3335 parser.setError (Aborted,"Third parameter is not a string");
3340 parser.setError (Aborted,"Unknown type: "+s);
3345 parser.setError (Aborted,"Unknown operator: "+t);
3350 parser.setError (Aborted,"Type of selection is not a branch");
3353 if (selbi->getHeading() == u)
3355 cout << "PASSED: " << qPrintable (c) << endl;
3358 cout << "FAILED: " << qPrintable (c) << endl;
3368 /////////////////////////////////////////////////////////////////////
3369 } else if (com=="saveImage")
3371 ImageItem *ii=getSelectedImage();
3374 parser.setError (Aborted,"No image selected");
3375 } else if (parser.checkParCount(2))
3377 s=parser.parString(ok,0);
3380 t=parser.parString(ok,1);
3381 if (ok) saveFloatImageInt (ii,t,s);
3384 /////////////////////////////////////////////////////////////////////
3385 } else if (com=="scroll")
3389 parser.setError (Aborted,"Nothing selected");
3390 } else if (! selbi )
3392 parser.setError (Aborted,"Type of selection is not a branch");
3393 } else if (parser.checkParCount(0))
3395 if (!scrollBranch (selbi))
3396 parser.setError (Aborted,"Could not scroll branch");
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="select")
3401 if (parser.checkParCount(1))
3403 s=parser.parString(ok,0);
3406 /////////////////////////////////////////////////////////////////////
3407 } else if (com=="selectLastBranch")
3411 parser.setError (Aborted,"Nothing selected");
3412 } else if (! selbi )
3414 parser.setError (Aborted,"Type of selection is not a branch");
3415 } else if (parser.checkParCount(0))
3417 BranchItem *bi=selbi->getLastBranch();
3419 parser.setError (Aborted,"Could not select last branch");
3420 select (bi); // FIXME-3 was selectInt
3423 /////////////////////////////////////////////////////////////////////
3424 } else /* FIXME-2 if (com=="selectLastImage")
3428 parser.setError (Aborted,"Nothing selected");
3429 } else if (! selbi )
3431 parser.setError (Aborted,"Type of selection is not a branch");
3432 } else if (parser.checkParCount(0))
3434 FloatImageObj *fio=selb->getLastFloatImage();
3436 parser.setError (Aborted,"Could not select last image");
3437 select (fio); // FIXME-3 was selectInt
3440 /////////////////////////////////////////////////////////////////////
3441 } else */ if (com=="selectLatestAdded")
3443 if (!latestAddedItem)
3445 parser.setError (Aborted,"No latest added object");
3448 if (!select (latestAddedItem))
3449 parser.setError (Aborted,"Could not select latest added object ");
3451 /////////////////////////////////////////////////////////////////////
3452 } else if (com=="setFrameType")
3454 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3456 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3458 else if (parser.checkParCount(1))
3460 s=parser.parString(ok,0);
3461 if (ok) setFrameType (s);
3463 /////////////////////////////////////////////////////////////////////
3464 } else if (com=="setFramePenColor")
3466 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3468 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3470 else if (parser.checkParCount(1))
3472 QColor c=parser.parColor(ok,0);
3473 if (ok) setFramePenColor (c);
3475 /////////////////////////////////////////////////////////////////////
3476 } else if (com=="setFrameBrushColor")
3478 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3480 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3482 else if (parser.checkParCount(1))
3484 QColor c=parser.parColor(ok,0);
3485 if (ok) setFrameBrushColor (c);
3487 /////////////////////////////////////////////////////////////////////
3488 } else if (com=="setFramePadding")
3490 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3492 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3494 else if (parser.checkParCount(1))
3496 n=parser.parInt(ok,0);
3497 if (ok) setFramePadding(n);
3499 /////////////////////////////////////////////////////////////////////
3500 } else if (com=="setFrameBorderWidth")
3502 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3504 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3506 else if (parser.checkParCount(1))
3508 n=parser.parInt(ok,0);
3509 if (ok) setFrameBorderWidth (n);
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="setMapAuthor")
3514 if (parser.checkParCount(1))
3516 s=parser.parString(ok,0);
3517 if (ok) setAuthor (s);
3519 /////////////////////////////////////////////////////////////////////
3520 } else if (com=="setMapComment")
3522 if (parser.checkParCount(1))
3524 s=parser.parString(ok,0);
3525 if (ok) setComment(s);
3527 /////////////////////////////////////////////////////////////////////
3528 } else if (com=="setMapBackgroundColor")
3532 parser.setError (Aborted,"Nothing selected");
3533 } else if (! selbi )
3535 parser.setError (Aborted,"Type of selection is not a branch");
3536 } else if (parser.checkParCount(1))
3538 QColor c=parser.parColor (ok,0);
3539 if (ok) setMapBackgroundColor (c);
3541 /////////////////////////////////////////////////////////////////////
3542 } else if (com=="setMapDefLinkColor")
3546 parser.setError (Aborted,"Nothing selected");
3547 } else if (! selbi )
3549 parser.setError (Aborted,"Type of selection is not a branch");
3550 } else if (parser.checkParCount(1))
3552 QColor c=parser.parColor (ok,0);
3553 if (ok) setMapDefLinkColor (c);
3555 /////////////////////////////////////////////////////////////////////
3556 } else if (com=="setMapLinkStyle")
3558 if (parser.checkParCount(1))
3560 s=parser.parString (ok,0);
3561 if (ok) setMapLinkStyle(s);
3563 /////////////////////////////////////////////////////////////////////
3564 } else if (com=="setHeading")
3568 parser.setError (Aborted,"Nothing selected");
3569 } else if (! selbi )
3571 parser.setError (Aborted,"Type of selection is not a branch");
3572 } else if (parser.checkParCount(1))
3574 s=parser.parString (ok,0);
3578 /////////////////////////////////////////////////////////////////////
3579 } else if (com=="setHideExport")
3583 parser.setError (Aborted,"Nothing selected");
3584 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3586 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3587 } else if (parser.checkParCount(1))
3589 b=parser.parBool(ok,0);
3590 if (ok) setHideExport (b);
3592 /////////////////////////////////////////////////////////////////////
3593 } else if (com=="setIncludeImagesHorizontally")
3597 parser.setError (Aborted,"Nothing selected");
3600 parser.setError (Aborted,"Type of selection is not a branch");
3601 } else if (parser.checkParCount(1))
3603 b=parser.parBool(ok,0);
3604 if (ok) setIncludeImagesHor(b);
3606 /////////////////////////////////////////////////////////////////////
3607 } else if (com=="setIncludeImagesVertically")
3611 parser.setError (Aborted,"Nothing selected");
3614 parser.setError (Aborted,"Type of selection is not a branch");
3615 } else if (parser.checkParCount(1))
3617 b=parser.parBool(ok,0);
3618 if (ok) setIncludeImagesVer(b);
3620 /////////////////////////////////////////////////////////////////////
3621 } else if (com=="setHideLinkUnselected")
3625 parser.setError (Aborted,"Nothing selected");
3626 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3628 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3629 } else if (parser.checkParCount(1))
3631 b=parser.parBool(ok,0);
3632 if (ok) setHideLinkUnselected(b);
3634 /////////////////////////////////////////////////////////////////////
3635 } else if (com=="setSelectionColor")
3637 if (parser.checkParCount(1))
3639 QColor c=parser.parColor (ok,0);
3640 if (ok) setSelectionColorInt (c);
3642 /////////////////////////////////////////////////////////////////////
3643 } else if (com=="setURL")
3647 parser.setError (Aborted,"Nothing selected");
3648 } else if (! selbi )
3650 parser.setError (Aborted,"Type of selection is not a branch");
3651 } else if (parser.checkParCount(1))
3653 s=parser.parString (ok,0);
3656 /////////////////////////////////////////////////////////////////////
3657 } else if (com=="setVymLink")
3661 parser.setError (Aborted,"Nothing selected");
3662 } else if (! selbi )
3664 parser.setError (Aborted,"Type of selection is not a branch");
3665 } else if (parser.checkParCount(1))
3667 s=parser.parString (ok,0);
3668 if (ok) setVymLink(s);
3671 /////////////////////////////////////////////////////////////////////
3672 else if (com=="setFlag")
3676 parser.setError (Aborted,"Nothing selected");
3677 } else if (! selbi )
3679 parser.setError (Aborted,"Type of selection is not a branch");
3680 } else if (parser.checkParCount(1))
3682 s=parser.parString(ok,0);
3684 selbi->activateStandardFlag(s);
3686 /////////////////////////////////////////////////////////////////////
3687 } else /* FIXME-2 if (com=="setFrameType")
3691 parser.setError (Aborted,"Nothing selected");
3694 parser.setError (Aborted,"Type of selection is not a branch");
3695 } else if (parser.checkParCount(1))
3697 s=parser.parString(ok,0);
3701 /////////////////////////////////////////////////////////////////////
3702 } else*/ if (com=="sortChildren")
3706 parser.setError (Aborted,"Nothing selected");
3707 } else if (! selbi )
3709 parser.setError (Aborted,"Type of selection is not a branch");
3710 } else if (parser.checkParCount(0))
3714 /////////////////////////////////////////////////////////////////////
3715 } else if (com=="toggleFlag")
3719 parser.setError (Aborted,"Nothing selected");
3720 } else if (! selbi )
3722 parser.setError (Aborted,"Type of selection is not a branch");
3723 } else if (parser.checkParCount(1))
3725 s=parser.parString(ok,0);
3727 selbi->toggleStandardFlag(s);
3729 /////////////////////////////////////////////////////////////////////
3730 } else if (com=="unscroll")
3734 parser.setError (Aborted,"Nothing selected");
3735 } else if (! selbi )
3737 parser.setError (Aborted,"Type of selection is not a branch");
3738 } else if (parser.checkParCount(0))
3740 if (!unscrollBranch (selbi))
3741 parser.setError (Aborted,"Could not unscroll branch");
3743 /////////////////////////////////////////////////////////////////////
3744 } else if (com=="unscrollChildren")
3748 parser.setError (Aborted,"Nothing selected");
3749 } else if (! selbi )
3751 parser.setError (Aborted,"Type of selection is not a branch");
3752 } else if (parser.checkParCount(0))
3754 unscrollChildren ();
3756 /////////////////////////////////////////////////////////////////////
3757 } else if (com=="unsetFlag")
3761 parser.setError (Aborted,"Nothing selected");
3762 } else if (! selbi )
3764 parser.setError (Aborted,"Type of selection is not a branch");
3765 } else if (parser.checkParCount(1))
3767 s=parser.parString(ok,0);
3769 selbi->deactivateStandardFlag(s);
3772 parser.setError (Aborted,"Unknown command");
3775 if (parser.errorLevel()==NoError)
3777 // setChanged(); FIXME-2 should not be called e.g. for export?!
3782 // TODO Error handling
3783 qWarning("VymModel::parseAtom: Error!");
3784 qWarning(parser.errorMessage());
3788 void VymModel::runScript (QString script)
3790 parser.setScript (script);
3792 while (parser.next() )
3793 parseAtom(parser.getAtom());
3796 void VymModel::setExportMode (bool b)
3798 // should be called before and after exports
3799 // depending on the settings
3800 if (b && settings.value("/export/useHideExport","true")=="true")
3801 setHideTmpMode (TreeItem::HideExport);
3803 setHideTmpMode (TreeItem::HideNone);
3806 void VymModel::exportImage(QString fname, bool askName, QString format)
3810 fname=getMapName()+".png";
3817 QFileDialog *fd=new QFileDialog (NULL);
3818 fd->setCaption (tr("Export map as image"));
3819 fd->setDirectory (lastImageDir);
3820 fd->setFileMode(QFileDialog::AnyFile);
3821 fd->setFilters (imageIO.getFilters() );
3824 fl=fd->selectedFiles();
3826 format=imageIO.getType(fd->selectedFilter());
3830 setExportMode (true);
3831 QPixmap pix (mapEditor->getPixmap());
3832 pix.save(fname, format);
3833 setExportMode (false);
3837 void VymModel::exportXML(QString dir, bool askForName)
3841 dir=browseDirectory(NULL,tr("Export XML to directory"));
3842 if (dir =="" && !reallyWriteDirectory(dir) )
3846 // Hide stuff during export, if settings want this
3847 setExportMode (true);
3849 // Create subdirectories
3852 // write to directory //FIXME-4 check totalBBox here...
3853 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3856 file.setName ( dir + "/"+mapName+".xml");
3857 if ( !file.open( QIODevice::WriteOnly ) )
3859 // This should neverever happen
3860 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3864 // Write it finally, and write in UTF8, no matter what
3865 QTextStream ts( &file );
3866 ts.setEncoding (QTextStream::UnicodeUTF8);
3870 // Now write image, too
3871 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3873 setExportMode (false);
3876 void VymModel::exportASCII(QString fname,bool askName)
3881 ex.setFile (mapName+".txt");
3887 //ex.addFilter ("TXT (*.txt)");
3888 ex.setDir(lastImageDir);
3889 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3894 setExportMode(true);
3896 setExportMode(false);
3900 void VymModel::exportXHTML (const QString &dir, bool askForName)
3902 ExportXHTMLDialog dia(NULL);
3903 dia.setFilePath (filePath );
3904 dia.setMapName (mapName );
3906 if (dir!="") dia.setDir (dir);
3912 if (dia.exec()!=QDialog::Accepted)
3916 QDir d (dia.getDir());
3917 // Check, if warnings should be used before overwriting
3918 // the output directory
3919 if (d.exists() && d.count()>0)
3922 warn.showCancelButton (true);
3923 warn.setText(QString(
3924 "The directory %1 is not empty.\n"
3925 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3926 warn.setCaption("Warning: Directory not empty");
3927 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3929 if (warn.exec()!=QDialog::Accepted) ok=false;
3936 exportXML (dia.getDir(),false );
3937 dia.doExport(mapName );
3938 //if (dia.hasChanged()) setChanged();
3942 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3947 if (ex.setConfigFile(cf))
3949 setExportMode (true);
3950 ex.exportPresentation();
3951 setExportMode (false);
3958 //////////////////////////////////////////////
3960 //////////////////////////////////////////////
3962 void VymModel::registerEditor(QWidget *me)
3964 mapEditor=(MapEditor*)me;
3967 void VymModel::unregisterEditor(QWidget *)
3972 void VymModel::setContextPos(QPointF p)
3977 void VymModel::unsetContextPos()
3979 contextPos=QPointF();
3982 void VymModel::updateNoteFlag()
3985 TreeItem *selti=getSelectedItem();
3988 if (textEditor->isEmpty())
3991 selti->setNote (textEditor->getText());
3992 emitDataHasChanged(selti);
3993 emitSelectionChanged();
3998 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
4001 for (int i=0; i<rootItem->branchCount(); i++)
4002 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
4005 void MapCenterObj::updateRelPositions()
4007 if (repositionRequest) unsetAllRepositionRequests();
4009 // update relative Positions of branches and floats
4010 for (int i=0; i<treeItem->branchCount(); ++i)
4012 treeItem->getBranchObjNum(i)->setRelPos();
4013 treeItem->getBranchObjNum(i)->setOrientation();
4016 for (int i=0; i<floatimage.size(); ++i)
4017 floatimage.at(i)->setRelPos();
4019 if (repositionRequest) reposition();
4024 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
4026 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4027 if (blockReposition) return;
4029 for (int i=0;i<rootItem->branchCount(); i++)
4030 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4034 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
4036 return QPolygonF ();
4037 // Creating (arbitrary) shapes
4040 QRectF rb=bo->getBBox();
4041 if (bo->getDepth()==0)
4043 // Just take BBox of this mapCenter
4044 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
4048 // Take union of BBox and TotalBBox
4050 QRectF ra=bo->getTotalBBox();
4051 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4054 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
4057 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
4059 p <<ra.bottomRight()
4061 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4064 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4070 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4074 // Move all branches and MapCenters away from lmo
4075 // to avoid collisions
4080 BranchObj *boA=(BranchObj*)lmo;
4082 for (int i=0; i<rootItem->branchCount(); i++)
4084 boB=rootItem->getBranchNum(i);
4087 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4090 <<" ("<<qPrintable(boA->getHeading() )<<")"
4091 <<" with ("<< qPrintable (boB->getHeading() )
4094 <<" minT="<<r.minTranslation<<endl<<endl;
4100 void VymModel::setMapLinkStyle (const QString & s)
4105 case LinkableMapObj::Line :
4108 case LinkableMapObj::Parabel:
4109 snow="StyleParabel";
4111 case LinkableMapObj::PolyLine:
4112 snow="StylePolyLine";
4114 case LinkableMapObj::PolyParabel:
4115 snow="StylePolyParabel";
4118 snow="UndefinedStyle";
4123 QString("setMapLinkStyle (\"%1\")").arg(s),
4124 QString("setMapLinkStyle (\"%1\")").arg(snow),
4125 QString("Set map link style (\"%1\")").arg(s)
4129 linkstyle=LinkableMapObj::Line;
4130 else if (s=="StyleParabel")
4131 linkstyle=LinkableMapObj::Parabel;
4132 else if (s=="StylePolyLine")
4133 linkstyle=LinkableMapObj::PolyLine;
4134 else if (s=="StylePolyParabel")
4135 linkstyle=LinkableMapObj::PolyParabel;
4137 linkstyle=LinkableMapObj::UndefinedStyle;
4139 BranchItem *cur=NULL;
4140 BranchItem *prev=NULL;
4145 bo=(BranchObj*)(cur->getLMO() );
4146 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4152 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4157 void VymModel::setMapDefLinkColor(QColor col)
4159 if ( !col.isValid() ) return;
4161 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4162 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4163 QString("Set map link color to %1").arg(col.name())
4167 BranchItem *cur=NULL;
4168 BranchItem *prev=NULL;
4173 bo=(BranchObj*)(cur->getLMO() );
4180 void VymModel::setMapLinkColorHintInt()
4182 // called from setMapLinkColorHint(lch) or at end of parse
4183 BranchItem *cur=NULL;
4184 BranchItem *prev=NULL;
4189 bo=(BranchObj*)(cur->getLMO() );
4195 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4198 setMapLinkColorHintInt();
4201 void VymModel::toggleMapLinkColorHint()
4203 if (linkcolorhint==LinkableMapObj::HeadingColor)
4204 linkcolorhint=LinkableMapObj::DefaultColor;
4206 linkcolorhint=LinkableMapObj::HeadingColor;
4207 BranchItem *cur=NULL;
4208 BranchItem *prev=NULL;
4213 bo=(BranchObj*)(cur->getLMO() );
4219 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4221 Q3FileDialog *fd=new Q3FileDialog( NULL);
4222 fd->setMode (Q3FileDialog::ExistingFile);
4223 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4224 ImagePreview *p =new ImagePreview (fd);
4225 fd->setContentsPreviewEnabled( TRUE );
4226 fd->setContentsPreview( p, p );
4227 fd->setPreviewMode( Q3FileDialog::Contents );
4228 fd->setCaption(vymName+" - " +tr("Load background image"));
4229 fd->setDir (lastImageDir);
4232 if ( fd->exec() == QDialog::Accepted )
4234 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4235 lastImageDir=QDir (fd->dirPath());
4236 setMapBackgroundImage (fd->selectedFile());
4240 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate, move to ME
4242 QColor oldcol=mapScene->backgroundBrush().color();
4246 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4248 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4249 QString("Set background color of map to %1").arg(col.name()));
4252 brush.setTextureImage (QPixmap (fn));
4253 mapScene->setBackgroundBrush(brush);
4256 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4258 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4259 if ( !col.isValid() ) return;
4260 setMapBackgroundColor( col );
4264 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4266 QColor oldcol=mapScene->backgroundBrush().color();
4268 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4269 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4270 QString("Set background color of map to %1").arg(col.name()));
4271 mapScene->setBackgroundBrush(col);
4274 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4276 return mapScene->backgroundBrush().color();
4280 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4282 return linkcolorhint;
4285 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4287 return defLinkColor;
4290 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4295 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4297 return defXLinkColor;
4300 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4305 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4307 return defXLinkWidth;
4310 void VymModel::move(const double &x, const double &y) // FIXME-3
4314 BranchObj *bo = getSelectedBranch();
4316 (selectionType()==TreeItem::Branch ||
4317 selectionType()==TreeItem::MapCenter ||
4318 selectionType()==TreeItem::Image
4321 QPointF ap(bo->getAbsPos());
4325 QString ps=qpointfToString(ap);
4326 QString s=getSelectString();
4329 s, "move "+qpointfToString(to),
4330 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4333 emitSelectionChanged();
4339 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4343 BranchObj *bo = getSelectedBranch();
4345 (selectionType()==TreeItem::Branch ||
4346 selectionType()==TreeItem::MapCenter ||
4347 selectionType()==TreeItem::Image
4351 QPointF rp(bo->getRelPos());
4355 QString ps=qpointfToString (bo->getRelPos());
4356 QString s=getSelectString(bo);
4359 s, "moveRel "+qpointfToString(to),
4360 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4361 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4363 bo->updateLinkGeometry();
4364 emitSelectionChanged();
4371 void VymModel::animate()
4373 animationTimer->stop();
4376 while (i<animObjList.size() )
4378 bo=(BranchObj*)animObjList.at(i);
4383 animObjList.removeAt(i);
4390 QItemSelection sel=selModel->selection();
4391 emit (selectionChanged(sel,sel));
4394 if (!animObjList.isEmpty()) animationTimer->start();
4398 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4400 if (bo && bo->getTreeItem()->depth()>0)
4403 ap.setStart (start);
4405 ap.setTicks (animationTicks);
4406 ap.setAnimated (true);
4407 bo->setAnimation (ap);
4408 animObjList.append( bo );
4409 animationTimer->setSingleShot (true);
4410 animationTimer->start(animationInterval);
4414 void VymModel::stopAnimation (MapObj *mo)
4416 int i=animObjList.indexOf(mo);
4418 animObjList.removeAt (i);
4421 void VymModel::sendSelection()
4423 if (netstate!=Server) return;
4424 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4427 void VymModel::newServer()
4431 tcpServer = new QTcpServer(this);
4432 if (!tcpServer->listen(QHostAddress::Any,port)) {
4433 QMessageBox::critical(NULL, "vym server",
4434 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4435 //FIXME-3 needed? we are no widget any longer... close();
4438 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4440 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4443 void VymModel::connectToServer()
4446 server="salam.suse.de";
4448 clientSocket = new QTcpSocket (this);
4449 clientSocket->abort();
4450 clientSocket->connectToHost(server ,port);
4451 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4452 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4453 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4455 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4460 void VymModel::newClient()
4462 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4463 connect(newClient, SIGNAL(disconnected()),
4464 newClient, SLOT(deleteLater()));
4466 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4468 clientList.append (newClient);
4472 void VymModel::sendData(const QString &s)
4474 if (clientList.size()==0) return;
4476 // Create bytearray to send
4478 QDataStream out(&block, QIODevice::WriteOnly);
4479 out.setVersion(QDataStream::Qt_4_0);
4481 // Reserve some space for blocksize
4484 // Write sendCounter
4485 out << sendCounter++;
4490 // Go back and write blocksize so far
4491 out.device()->seek(0);
4492 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4496 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4498 for (int i=0; i<clientList.size(); ++i)
4500 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4501 clientList.at(i)->write (block);
4505 void VymModel::readData ()
4507 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4510 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4514 QDataStream in(clientSocket);
4515 in.setVersion(QDataStream::Qt_4_0);
4523 cout << " t="<<qPrintable (t)<<endl;
4529 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4531 switch (socketError) {
4532 case QAbstractSocket::RemoteHostClosedError:
4534 case QAbstractSocket::HostNotFoundError:
4535 QMessageBox::information(NULL, vymName +" Network client",
4536 "The host was not found. Please check the "
4537 "host name and port settings.");
4539 case QAbstractSocket::ConnectionRefusedError:
4540 QMessageBox::information(NULL, vymName + " Network client",
4541 "The connection was refused by the peer. "
4542 "Make sure the fortune server is running, "
4543 "and check that the host name and port "
4544 "settings are correct.");
4547 QMessageBox::information(NULL, vymName + " Network client",
4548 QString("The following error occurred: %1.")
4549 .arg(clientSocket->errorString()));
4553 /* FIXME-3 Playing with DBUS...
4554 QDBusVariant VymModel::query (const QString &query)
4556 TreeItem *selti=getSelectedItem();
4558 return QDBusVariant (selti->getHeading());
4560 return QDBusVariant ("Nothing selected.");
4564 void VymModel::testslot() //FIXME-3
4566 cout << "VM::testslot called\n";
4569 void VymModel::selectMapSelectionColor()
4571 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4572 setSelectionColor (col);
4575 void VymModel::setSelectionColorInt (QColor col)
4577 if ( !col.isValid() ) return;
4579 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4580 QString("setSelectionColor (%1)").arg(col.name()),
4581 QString("Set color of selection box to %1").arg(col.name())
4584 mapEditor->setSelectionColor (col);
4587 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4589 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4590 emitShowSelection();
4594 void VymModel::emitSelectionChanged()
4596 QItemSelection newsel=selModel->selection();
4597 emitSelectionChanged (newsel);
4600 void VymModel::setSelectionColor(QColor col)
4602 if ( !col.isValid() ) return;
4604 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4605 QString("setSelectionColor (%1)").arg(col.name()),
4606 QString("Set color of selection box to %1").arg(col.name())
4608 setSelectionColorInt (col);
4611 QColor VymModel::getSelectionColor()
4613 return mapEditor->getSelectionColor();
4616 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4619 for (int i=0;i<rootItem->childCount();i++)
4620 rootItem->child(i)->setHideTmp (mode);
4622 // FIXME-3 needed? scene()->update();
4625 //////////////////////////////////////////////
4626 // Selection related
4627 //////////////////////////////////////////////
4629 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4634 QItemSelectionModel* VymModel::getSelectionModel()
4639 void VymModel::setSelectionBlocked (bool b)
4644 bool VymModel::isSelectionBlocked()
4646 return selectionBlocked;
4649 bool VymModel::select ()
4651 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4654 bool VymModel::select (const QString &s)
4661 TreeItem *ti=findBySelectString(s);
4662 if (ti) return select (index(ti));
4666 bool VymModel::select (LinkableMapObj *lmo)
4668 QItemSelection oldsel=selModel->selection();
4671 return select (index (lmo->getTreeItem()) );
4676 bool VymModel::select (TreeItem *ti)
4678 if (ti) return select (index(ti));
4682 bool VymModel::select (const QModelIndex &index)
4684 if (index.isValid() )
4686 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4687 BranchItem *bi=getSelectedBranch();
4688 if (bi) bi->setLastSelectedBranch();
4694 void VymModel::unselect()
4696 lastSelectString=getSelectString();
4697 selModel->clearSelection();
4700 bool VymModel::reselect()
4702 return select (lastSelectString);
4705 void VymModel::emitShowSelection()
4707 if (!blockReposition)
4708 emit (showSelection() );
4711 void VymModel::emitNoteHasChanged (TreeItem *ti)
4713 QModelIndex ix=index(ti);
4714 emit (noteHasChanged (ix) );
4717 void VymModel::emitDataHasChanged (TreeItem *ti)
4719 QModelIndex ix=index(ti);
4720 emit (dataChanged (ix,ix) );
4724 //bool VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4727 if (selection.select(lmo))
4729 //emitSelectionChanged();
4733 bool VymModel::selectInt (TreeItem *ti)
4735 if (selection.select(lmo))
4737 //emitSelectionChanged();
4742 bool VymModel::selectFirstBranch()
4744 TreeItem *ti=getSelectedBranch();
4747 TreeItem *par=ti->parent();
4750 TreeItem *ti2=par->getFirstBranch();
4751 if (ti2) return select(ti2);
4757 bool VymModel::selectLastBranch()
4759 TreeItem *ti=getSelectedBranch();
4762 TreeItem *par=ti->parent();
4765 TreeItem *ti2=par->getLastBranch();
4766 if (ti2) return select(ti2);
4772 bool VymModel::selectLastSelectedBranch()
4774 BranchItem *bi=getSelectedBranch();
4777 bi=bi->getLastSelectedBranch();
4778 if (bi) return select (bi);
4783 bool VymModel::selectParent()
4785 TreeItem *ti=getSelectedItem();
4796 TreeItem::Type VymModel::selectionType()
4798 QModelIndexList list=selModel->selectedIndexes();
4799 if (list.isEmpty()) return TreeItem::Undefined;
4800 TreeItem *ti = getItem (list.first() );
4801 return ti->getType();
4805 LinkableMapObj* VymModel::getSelectedLMO()
4807 QModelIndexList list=selModel->selectedIndexes();
4808 if (!list.isEmpty() )
4810 TreeItem *ti = getItem (list.first() );
4811 TreeItem::Type type=ti->getType();
4812 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4813 return ((MapItem*)ti)->getLMO();
4818 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4820 TreeItem *ti = getSelectedBranch();
4822 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4827 BranchItem* VymModel::getSelectedBranch()
4829 QModelIndexList list=selModel->selectedIndexes();
4830 if (!list.isEmpty() )
4832 TreeItem *ti = getItem (list.first() );
4833 TreeItem::Type type=ti->getType();
4834 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4835 return (BranchItem*)ti;
4840 ImageItem* VymModel::getSelectedImage()
4842 QModelIndexList list=selModel->selectedIndexes();
4843 if (!list.isEmpty())
4845 TreeItem *ti=getItem (list.first());
4846 if (ti && ti->getType()==TreeItem::Image)
4847 return (ImageItem*)ti;
4852 AttributeItem* VymModel::getSelectedAttribute()
4854 QModelIndexList list=selModel->selectedIndexes();
4855 if (!list.isEmpty() )
4857 TreeItem *ti = getItem (list.first() );
4858 TreeItem::Type type=ti->getType();
4859 if (type ==TreeItem::Attribute)
4860 return (AttributeItem*)ti;
4865 TreeItem* VymModel::getSelectedItem()
4867 QModelIndexList list=selModel->selectedIndexes();
4868 if (!list.isEmpty() )
4869 return getItem (list.first() );
4874 QModelIndex VymModel::getSelectedIndex()
4876 QModelIndexList list=selModel->selectedIndexes();
4877 if (list.isEmpty() )
4878 return QModelIndex();
4880 return list.first();
4883 QString VymModel::getSelectString ()
4885 return getSelectString (getSelectedItem());
4888 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
4890 if (!lmo) return QString();
4891 return getSelectString (lmo->getTreeItem() );
4894 QString VymModel::getSelectString (TreeItem *ti)
4898 switch (ti->getType())
4900 case TreeItem::MapCenter: s="mc:"; break;
4901 case TreeItem::Branch: s="bo:";break;
4902 case TreeItem::Image: s="fi:";break;
4903 case TreeItem::Attribute: s="ai:";break;
4906 s= s + QString("%1").arg(ti->num());
4908 // call myself recursively
4909 s= getSelectString(ti->parent()) +","+s;