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))
2346 emitDataHasChanged (pi);
2349 emitShowSelection();
2354 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2357 BranchItem *selbi=getSelectedBranch();
2361 // Don't use this on mapcenter
2362 if (selbi->depth()<2) return;
2364 pi=(BranchItem*)(selbi->parent());
2365 // Check if we have childs at all to keep
2366 if (selbi->branchCount()==0)
2373 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2374 saveStateChangingPart(
2377 "deleteKeepChildren ()",
2378 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2381 QString sel=getSelectString(selbi);
2383 int pos=selbi->num();
2384 BranchItem *bi=selbi->getFirstBranch();
2387 relinkBranch (bi,pi,pos);
2388 bi=selbi->getFirstBranch();
2394 BranchObj *bo=getSelectedBranchObj();
2397 bo->move2RelPos (p);
2403 void VymModel::deleteChildren()
2406 BranchItem *selbi=getSelectedBranch();
2409 saveStateChangingPart(
2412 "deleteChildren ()",
2413 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2415 emit (layoutAboutToBeChanged() );
2417 QModelIndex ix=index (selbi);
2418 int n=selbi->branchCount()-1;
2419 beginRemoveRows (ix,0,n);
2420 removeRows (0,n+1,ix);
2422 if (selbi->isScrolled()) selbi->unScroll();
2423 emit (layoutChanged() );
2428 TreeItem* VymModel::deleteItem (TreeItem *ti)
2430 cout << "VM::deleteItem "<<ti<<endl;
2433 TreeItem *pi=ti->parent();
2434 QModelIndex parentIndex=index(pi);
2436 emit (layoutAboutToBeChanged() );
2438 int n=ti->childNum();
2439 beginRemoveRows (parentIndex,n,n);
2440 removeRows (n,1,parentIndex);
2444 emit (layoutChanged() );
2445 if (pi->depth()>=0) return pi;
2450 bool VymModel::scrollBranch(BranchItem *bi)
2454 if (bi->isScrolled()) return false;
2455 if (bi->branchCount()==0) return false;
2456 if (bi->depth()==0) return false;
2457 if (bi->toggleScroll())
2464 QString ("%1 ()").arg(u),
2466 QString ("%1 ()").arg(r),
2467 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2469 emitDataHasChanged(bi);
2470 emitSelectionChanged();
2471 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2478 bool VymModel::unscrollBranch(BranchItem *bi)
2482 if (!bi->isScrolled()) return false;
2483 if (bi->branchCount()==0) return false;
2484 if (bi->depth()==0) return false;
2491 QString ("%1 ()").arg(u),
2493 QString ("%1 ()").arg(r),
2494 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2497 emitDataHasChanged(bi);
2498 emitSelectionChanged();
2500 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2506 void VymModel::toggleScroll()
2508 BranchItem *bi=(BranchItem*)getSelectedBranch();
2509 if (bi && bi->isBranchLikeType() )
2511 if (bi->isScrolled())
2512 unscrollBranch (bi);
2516 // saveState is called in above functions
2519 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2523 BranchObj *bo=getSelectedBranch();
2529 if (bo->isScrolled()) unscrollBranch (bo);
2536 void VymModel::emitExpandAll()
2538 emit (expandAll() );
2541 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2543 BranchItem *bi=getSelectedBranch();
2547 if (bi->isActiveStandardFlag(name))
2559 QString("%1 (\"%2\")").arg(u).arg(name),
2561 QString("%1 (\"%2\")").arg(r).arg(name),
2562 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2563 bi->toggleStandardFlag (name, master);
2565 emitSelectionChanged();
2569 void VymModel::addFloatImage (const QPixmap &img)
2571 BranchItem *selbi=getSelectedBranch();
2574 ImageItem *ii=createImage (selbi);
2576 ii->setOriginalFilename("No original filename (image added by dropevent)");
2577 QString s=getSelectString(selbi);
2578 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2579 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2581 // FIXME-3 VM needed? scene()->update();
2586 void VymModel::colorBranch (QColor c)
2588 BranchItem *selbi=getSelectedBranch();
2593 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2595 QString ("colorBranch (\"%1\")").arg(c.name()),
2596 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2598 selbi->setHeadingColor(c); // color branch
2602 void VymModel::colorSubtree (QColor c)
2604 BranchItem *selbi=getSelectedBranch();
2607 saveStateChangingPart(
2610 QString ("colorSubtree (\"%1\")").arg(c.name()),
2611 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2613 BranchItem *prev=NULL;
2614 BranchItem *cur=selbi;
2617 cur->setHeadingColor(c); // color links, color children
2618 cur=next (cur,prev,selbi);
2624 QColor VymModel::getCurrentHeadingColor()
2626 BranchItem *selbi=getSelectedBranch();
2627 if (selbi) return selbi->getHeadingColor();
2629 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2635 void VymModel::editURL()
2637 TreeItem *selti=getSelectedItem();
2641 QString text = QInputDialog::getText(
2642 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2643 selti->getURL(), &ok, NULL);
2645 // user entered something and pressed OK
2650 void VymModel::editLocalURL()
2652 TreeItem *selti=getSelectedItem();
2655 QStringList filters;
2656 filters <<"All files (*)";
2657 filters << tr("Text","Filedialog") + " (*.txt)";
2658 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2659 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2660 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2661 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2662 fd->setFilters (filters);
2663 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2664 fd->setDirectory (lastFileDir);
2665 if (! selti->getVymLink().isEmpty() )
2666 fd->selectFile( selti->getURL() );
2669 if ( fd->exec() == QDialog::Accepted )
2671 lastFileDir=QDir (fd->directory().path());
2672 setURL (fd->selectedFile() );
2678 void VymModel::editHeading2URL()
2680 TreeItem *selti=getSelectedItem();
2682 setURL (selti->getHeading());
2685 void VymModel::editBugzilla2URL()
2687 TreeItem *selti=getSelectedItem();
2690 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2695 void VymModel::editFATE2URL()
2697 TreeItem *selti=getSelectedItem();
2700 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2703 "setURL (\""+selti->getURL()+"\")",
2705 "setURL (\""+url+"\")",
2706 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2708 selti->setURL (url);
2709 // FIXME-4 updateActions();
2713 void VymModel::editVymLink()
2715 BranchItem *bi=getSelectedBranch();
2718 QStringList filters;
2719 filters <<"VYM map (*.vym)";
2720 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2721 fd->setFilters (filters);
2722 fd->setCaption(vymName+" - " +tr("Link to another map"));
2723 fd->setDirectory (lastFileDir);
2724 if (! bi->getVymLink().isEmpty() )
2725 fd->selectFile( bi->getVymLink() );
2729 if ( fd->exec() == QDialog::Accepted )
2731 lastFileDir=QDir (fd->directory().path());
2734 "setVymLink (\""+bi->getVymLink()+"\")",
2736 "setVymLink (\""+fd->selectedFile()+"\")",
2737 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2739 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2744 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2746 // Internal function, no saveState needed
2747 TreeItem *selti=getSelectedItem();
2750 selti->setVymLink(s);
2752 emitDataHasChanged (selti);
2753 emitShowSelection();
2757 void VymModel::deleteVymLink()
2759 BranchItem *bi=getSelectedBranch();
2764 "setVymLink (\""+bi->getVymLink()+"\")",
2766 "setVymLink (\"\")",
2767 QString("Unset vymlink of %1").arg(getObjectName(bi))
2769 bi->setVymLink ("" );
2775 QString VymModel::getVymLink()
2777 BranchItem *bi=getSelectedBranch();
2779 return bi->getVymLink();
2785 QStringList VymModel::getVymLinks()
2788 BranchItem *selbi=getSelectedBranch();
2789 BranchItem *cur=selbi;
2790 BranchItem *prev=NULL;
2793 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2794 cur=next (cur,prev,selbi);
2800 void VymModel::followXLink(int i)
2803 BranchItem *selbi=getSelectedBranch();
2806 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
2807 if (selbi) select (selbi);
2811 void VymModel::editXLink(int i)
2814 BranchItem *selbi=getSelectedBranch();
2817 XLinkItem *xli=selbi->getXLinkNum(i);
2820 EditXLinkDialog dia;
2822 dia.setSelection(selbi);
2823 if (dia.exec() == QDialog::Accepted)
2825 if (dia.useSettingsGlobal() )
2827 setMapDefXLinkColor (xli->getColor() );
2828 setMapDefXLinkWidth (xli->getWidth() );
2830 if (dia.deleteXLink()) deleteItem (xli);
2840 //////////////////////////////////////////////
2842 //////////////////////////////////////////////
2844 void VymModel::parseAtom(const QString &atom)
2846 TreeItem* selti=getSelectedItem();
2847 BranchItem *selbi=getSelectedBranch();
2853 // Split string s into command and parameters
2854 parser.parseAtom (atom);
2855 QString com=parser.getCommand();
2857 // External commands
2858 /////////////////////////////////////////////////////////////////////
2859 if (com=="addBranch")
2863 parser.setError (Aborted,"Nothing selected");
2864 } else if (! selbi )
2866 parser.setError (Aborted,"Type of selection is not a branch");
2871 if (parser.checkParCount(pl))
2873 if (parser.parCount()==0)
2877 n=parser.parInt (ok,0);
2878 if (ok ) addNewBranch (n);
2882 /////////////////////////////////////////////////////////////////////
2883 } else if (com=="addBranchBefore")
2887 parser.setError (Aborted,"Nothing selected");
2888 } else if (! selbi )
2890 parser.setError (Aborted,"Type of selection is not a branch");
2893 if (parser.parCount()==0)
2895 addNewBranchBefore ();
2898 /////////////////////////////////////////////////////////////////////
2899 } else if (com==QString("addMapCenter"))
2901 if (parser.checkParCount(2))
2903 x=parser.parDouble (ok,0);
2906 y=parser.parDouble (ok,1);
2907 if (ok) addMapCenter (QPointF(x,y));
2910 /////////////////////////////////////////////////////////////////////
2911 } else if (com==QString("addMapReplace"))
2915 parser.setError (Aborted,"Nothing selected");
2916 } else if (! selbi )
2918 parser.setError (Aborted,"Type of selection is not a branch");
2919 } else if (parser.checkParCount(1))
2921 //s=parser.parString (ok,0); // selection
2922 t=parser.parString (ok,0); // path to map
2923 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2924 addMapReplaceInt(getSelectString(selbi),t);
2926 /////////////////////////////////////////////////////////////////////
2927 } else if (com==QString("addMapInsert"))
2929 if (parser.parCount()==2)
2934 parser.setError (Aborted,"Nothing selected");
2935 } else if (! selbi )
2937 parser.setError (Aborted,"Type of selection is not a branch");
2940 t=parser.parString (ok,0); // path to map
2941 n=parser.parInt(ok,1); // position
2942 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2943 addMapInsertInt(t,n);
2945 } else if (parser.parCount()==1)
2947 t=parser.parString (ok,0); // path to map
2948 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2951 parser.setError (Aborted,"Wrong number of parameters");
2952 /////////////////////////////////////////////////////////////////////
2953 } else if (com=="clearFlags")
2957 parser.setError (Aborted,"Nothing selected");
2958 } else if (! selbi )
2960 parser.setError (Aborted,"Type of selection is not a branch");
2961 } else if (parser.checkParCount(0))
2963 selbi->deactivateAllStandardFlags();
2965 /////////////////////////////////////////////////////////////////////
2966 } else if (com=="colorBranch")
2970 parser.setError (Aborted,"Nothing selected");
2971 } else if (! selbi )
2973 parser.setError (Aborted,"Type of selection is not a branch");
2974 } else if (parser.checkParCount(1))
2976 QColor c=parser.parColor (ok,0);
2977 if (ok) colorBranch (c);
2979 /////////////////////////////////////////////////////////////////////
2980 } else if (com=="colorSubtree")
2984 parser.setError (Aborted,"Nothing selected");
2985 } else if (! selbi )
2987 parser.setError (Aborted,"Type of selection is not a branch");
2988 } else if (parser.checkParCount(1))
2990 QColor c=parser.parColor (ok,0);
2991 if (ok) colorSubtree (c);
2993 /////////////////////////////////////////////////////////////////////
2994 } else if (com=="copy")
2998 parser.setError (Aborted,"Nothing selected");
2999 } else if ( selectionType()!=TreeItem::Branch &&
3000 selectionType()!=TreeItem::MapCenter &&
3001 selectionType()!=TreeItem::Image )
3003 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3004 } else if (parser.checkParCount(0))
3008 /////////////////////////////////////////////////////////////////////
3009 } else if (com=="cut")
3013 parser.setError (Aborted,"Nothing selected");
3014 } else if ( selectionType()!=TreeItem::Branch &&
3015 selectionType()!=TreeItem::MapCenter &&
3016 selectionType()!=TreeItem::Image )
3018 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3019 } else if (parser.checkParCount(0))
3023 /////////////////////////////////////////////////////////////////////
3024 } else if (com=="delete")
3028 parser.setError (Aborted,"Nothing selected");
3030 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3032 parser.setError (Aborted,"Type of selection is wrong.");
3035 else if (parser.checkParCount(0))
3039 /////////////////////////////////////////////////////////////////////
3040 } else if (com=="deleteKeepChildren")
3044 parser.setError (Aborted,"Nothing selected");
3045 } else if (! selbi )
3047 parser.setError (Aborted,"Type of selection is not a branch");
3048 } else if (parser.checkParCount(0))
3050 deleteKeepChildren();
3052 /////////////////////////////////////////////////////////////////////
3053 } else if (com=="deleteChildren")
3057 parser.setError (Aborted,"Nothing selected");
3060 parser.setError (Aborted,"Type of selection is not a branch");
3061 } else if (parser.checkParCount(0))
3065 /////////////////////////////////////////////////////////////////////
3066 } else if (com=="exportASCII")
3070 if (parser.parCount()>=1)
3071 // Hey, we even have a filename
3072 fname=parser.parString(ok,0);
3075 parser.setError (Aborted,"Could not read filename");
3078 exportASCII (fname,false);
3080 /////////////////////////////////////////////////////////////////////
3081 } else if (com=="exportImage")
3085 if (parser.parCount()>=2)
3086 // Hey, we even have a filename
3087 fname=parser.parString(ok,0);
3090 parser.setError (Aborted,"Could not read filename");
3093 QString format="PNG";
3094 if (parser.parCount()>=2)
3096 format=parser.parString(ok,1);
3098 exportImage (fname,false,format);
3100 /////////////////////////////////////////////////////////////////////
3101 } else if (com=="exportXHTML")
3105 if (parser.parCount()>=2)
3106 // Hey, we even have a filename
3107 fname=parser.parString(ok,1);
3110 parser.setError (Aborted,"Could not read filename");
3113 exportXHTML (fname,false);
3115 /////////////////////////////////////////////////////////////////////
3116 } else if (com=="exportXML")
3120 if (parser.parCount()>=2)
3121 // Hey, we even have a filename
3122 fname=parser.parString(ok,1);
3125 parser.setError (Aborted,"Could not read filename");
3128 exportXML (fname,false);
3130 /////////////////////////////////////////////////////////////////////
3131 } else if (com=="importDir")
3135 parser.setError (Aborted,"Nothing selected");
3136 } else if (! selbi )
3138 parser.setError (Aborted,"Type of selection is not a branch");
3139 } else if (parser.checkParCount(1))
3141 s=parser.parString(ok,0);
3142 if (ok) importDirInt(s);
3144 /////////////////////////////////////////////////////////////////////
3145 } else if (com=="relinkTo")
3149 parser.setError (Aborted,"Nothing selected");
3152 if (parser.checkParCount(4))
3154 // 0 selectstring of parent
3155 // 1 num in parent (for branches)
3156 // 2,3 x,y of mainbranch or mapcenter
3157 s=parser.parString(ok,0);
3158 TreeItem *dst=findBySelectString (s);
3161 if (dst->getType()==TreeItem::Branch)
3163 // Get number in parent
3164 n=parser.parInt (ok,1);
3167 relinkBranch (selbi,(BranchItem*)dst,n);
3168 emitSelectionChanged();
3170 } else if (dst->getType()==TreeItem::MapCenter)
3172 relinkBranch (selbi,(BranchItem*)dst);
3173 // Get coordinates of mainbranch
3174 x=parser.parDouble(ok,2);
3177 y=parser.parDouble(ok,3);
3180 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3181 emitSelectionChanged();
3187 } else if ( selti->getType() == TreeItem::Image)
3189 if (parser.checkParCount(1))
3191 // 0 selectstring of parent
3192 s=parser.parString(ok,0);
3193 TreeItem *dst=findBySelectString (s);
3196 if (dst->isBranchLikeType())
3197 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3199 parser.setError (Aborted,"Destination is not a branch");
3202 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3203 /////////////////////////////////////////////////////////////////////
3204 } else if (com=="loadImage")
3208 parser.setError (Aborted,"Nothing selected");
3209 } else if (! selbi )
3211 parser.setError (Aborted,"Type of selection is not a branch");
3212 } else if (parser.checkParCount(1))
3214 s=parser.parString(ok,0);
3215 if (ok) loadFloatImageInt (selbi,s);
3217 /////////////////////////////////////////////////////////////////////
3218 } else if (com=="moveUp")
3222 parser.setError (Aborted,"Nothing selected");
3223 } else if (! selbi )
3225 parser.setError (Aborted,"Type of selection is not a branch");
3226 } else if (parser.checkParCount(0))
3230 /////////////////////////////////////////////////////////////////////
3231 } else if (com=="moveDown")
3235 parser.setError (Aborted,"Nothing selected");
3236 } else if (! selbi )
3238 parser.setError (Aborted,"Type of selection is not a branch");
3239 } else if (parser.checkParCount(0))
3243 /////////////////////////////////////////////////////////////////////
3244 } else if (com=="move")
3248 parser.setError (Aborted,"Nothing selected");
3249 } else if ( selectionType()!=TreeItem::Branch &&
3250 selectionType()!=TreeItem::MapCenter &&
3251 selectionType()!=TreeItem::Image )
3253 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3254 } else if (parser.checkParCount(2))
3256 x=parser.parDouble (ok,0);
3259 y=parser.parDouble (ok,1);
3263 /////////////////////////////////////////////////////////////////////
3264 } else if (com=="moveRel")
3268 parser.setError (Aborted,"Nothing selected");
3269 } else if ( selectionType()!=TreeItem::Branch &&
3270 selectionType()!=TreeItem::MapCenter &&
3271 selectionType()!=TreeItem::Image )
3273 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3274 } else if (parser.checkParCount(2))
3276 x=parser.parDouble (ok,0);
3279 y=parser.parDouble (ok,1);
3280 if (ok) moveRel (x,y);
3283 /////////////////////////////////////////////////////////////////////
3284 } else if (com=="nop")
3286 /////////////////////////////////////////////////////////////////////
3287 } else if (com=="paste")
3291 parser.setError (Aborted,"Nothing selected");
3292 } else if (! selbi )
3294 parser.setError (Aborted,"Type of selection is not a branch");
3295 } else if (parser.checkParCount(1))
3297 n=parser.parInt (ok,0);
3298 if (ok) pasteNoSave(n);
3300 /////////////////////////////////////////////////////////////////////
3301 } else if (com=="qa")
3305 parser.setError (Aborted,"Nothing selected");
3306 } else if (! selbi )
3308 parser.setError (Aborted,"Type of selection is not a branch");
3309 } else if (parser.checkParCount(4))
3312 c=parser.parString (ok,0);
3315 parser.setError (Aborted,"No comment given");
3318 s=parser.parString (ok,1);
3321 parser.setError (Aborted,"First parameter is not a string");
3324 t=parser.parString (ok,2);
3327 parser.setError (Aborted,"Condition is not a string");
3330 u=parser.parString (ok,3);
3333 parser.setError (Aborted,"Third parameter is not a string");
3338 parser.setError (Aborted,"Unknown type: "+s);
3343 parser.setError (Aborted,"Unknown operator: "+t);
3348 parser.setError (Aborted,"Type of selection is not a branch");
3351 if (selbi->getHeading() == u)
3353 cout << "PASSED: " << qPrintable (c) << endl;
3356 cout << "FAILED: " << qPrintable (c) << endl;
3366 /////////////////////////////////////////////////////////////////////
3367 } else if (com=="saveImage")
3369 ImageItem *ii=getSelectedImage();
3372 parser.setError (Aborted,"No image selected");
3373 } else if (parser.checkParCount(2))
3375 s=parser.parString(ok,0);
3378 t=parser.parString(ok,1);
3379 if (ok) saveFloatImageInt (ii,t,s);
3382 /////////////////////////////////////////////////////////////////////
3383 } else if (com=="scroll")
3387 parser.setError (Aborted,"Nothing selected");
3388 } else if (! selbi )
3390 parser.setError (Aborted,"Type of selection is not a branch");
3391 } else if (parser.checkParCount(0))
3393 if (!scrollBranch (selbi))
3394 parser.setError (Aborted,"Could not scroll branch");
3396 /////////////////////////////////////////////////////////////////////
3397 } else if (com=="select")
3399 if (parser.checkParCount(1))
3401 s=parser.parString(ok,0);
3404 /////////////////////////////////////////////////////////////////////
3405 } else if (com=="selectLastBranch")
3409 parser.setError (Aborted,"Nothing selected");
3410 } else if (! selbi )
3412 parser.setError (Aborted,"Type of selection is not a branch");
3413 } else if (parser.checkParCount(0))
3415 BranchItem *bi=selbi->getLastBranch();
3417 parser.setError (Aborted,"Could not select last branch");
3418 select (bi); // FIXME-3 was selectInt
3421 /////////////////////////////////////////////////////////////////////
3422 } else /* FIXME-2 if (com=="selectLastImage")
3426 parser.setError (Aborted,"Nothing selected");
3427 } else if (! selbi )
3429 parser.setError (Aborted,"Type of selection is not a branch");
3430 } else if (parser.checkParCount(0))
3432 FloatImageObj *fio=selb->getLastFloatImage();
3434 parser.setError (Aborted,"Could not select last image");
3435 select (fio); // FIXME-3 was selectInt
3438 /////////////////////////////////////////////////////////////////////
3439 } else */ if (com=="selectLatestAdded")
3441 if (!latestAddedItem)
3443 parser.setError (Aborted,"No latest added object");
3446 if (!select (latestAddedItem))
3447 parser.setError (Aborted,"Could not select latest added object ");
3449 /////////////////////////////////////////////////////////////////////
3450 } else if (com=="setFrameType")
3452 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3454 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3456 else if (parser.checkParCount(1))
3458 s=parser.parString(ok,0);
3459 if (ok) setFrameType (s);
3461 /////////////////////////////////////////////////////////////////////
3462 } else if (com=="setFramePenColor")
3464 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3466 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3468 else if (parser.checkParCount(1))
3470 QColor c=parser.parColor(ok,0);
3471 if (ok) setFramePenColor (c);
3473 /////////////////////////////////////////////////////////////////////
3474 } else if (com=="setFrameBrushColor")
3476 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3478 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3480 else if (parser.checkParCount(1))
3482 QColor c=parser.parColor(ok,0);
3483 if (ok) setFrameBrushColor (c);
3485 /////////////////////////////////////////////////////////////////////
3486 } else if (com=="setFramePadding")
3488 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3490 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3492 else if (parser.checkParCount(1))
3494 n=parser.parInt(ok,0);
3495 if (ok) setFramePadding(n);
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="setFrameBorderWidth")
3500 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3502 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3504 else if (parser.checkParCount(1))
3506 n=parser.parInt(ok,0);
3507 if (ok) setFrameBorderWidth (n);
3509 /////////////////////////////////////////////////////////////////////
3510 } else if (com=="setMapAuthor")
3512 if (parser.checkParCount(1))
3514 s=parser.parString(ok,0);
3515 if (ok) setAuthor (s);
3517 /////////////////////////////////////////////////////////////////////
3518 } else if (com=="setMapComment")
3520 if (parser.checkParCount(1))
3522 s=parser.parString(ok,0);
3523 if (ok) setComment(s);
3525 /////////////////////////////////////////////////////////////////////
3526 } else if (com=="setMapBackgroundColor")
3530 parser.setError (Aborted,"Nothing selected");
3531 } else if (! selbi )
3533 parser.setError (Aborted,"Type of selection is not a branch");
3534 } else if (parser.checkParCount(1))
3536 QColor c=parser.parColor (ok,0);
3537 if (ok) setMapBackgroundColor (c);
3539 /////////////////////////////////////////////////////////////////////
3540 } else if (com=="setMapDefLinkColor")
3544 parser.setError (Aborted,"Nothing selected");
3545 } else if (! selbi )
3547 parser.setError (Aborted,"Type of selection is not a branch");
3548 } else if (parser.checkParCount(1))
3550 QColor c=parser.parColor (ok,0);
3551 if (ok) setMapDefLinkColor (c);
3553 /////////////////////////////////////////////////////////////////////
3554 } else if (com=="setMapLinkStyle")
3556 if (parser.checkParCount(1))
3558 s=parser.parString (ok,0);
3559 if (ok) setMapLinkStyle(s);
3561 /////////////////////////////////////////////////////////////////////
3562 } else if (com=="setHeading")
3566 parser.setError (Aborted,"Nothing selected");
3567 } else if (! selbi )
3569 parser.setError (Aborted,"Type of selection is not a branch");
3570 } else if (parser.checkParCount(1))
3572 s=parser.parString (ok,0);
3576 /////////////////////////////////////////////////////////////////////
3577 } else if (com=="setHideExport")
3581 parser.setError (Aborted,"Nothing selected");
3582 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3584 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3585 } else if (parser.checkParCount(1))
3587 b=parser.parBool(ok,0);
3588 if (ok) setHideExport (b);
3590 /////////////////////////////////////////////////////////////////////
3591 } else if (com=="setIncludeImagesHorizontally")
3595 parser.setError (Aborted,"Nothing selected");
3598 parser.setError (Aborted,"Type of selection is not a branch");
3599 } else if (parser.checkParCount(1))
3601 b=parser.parBool(ok,0);
3602 if (ok) setIncludeImagesHor(b);
3604 /////////////////////////////////////////////////////////////////////
3605 } else if (com=="setIncludeImagesVertically")
3609 parser.setError (Aborted,"Nothing selected");
3612 parser.setError (Aborted,"Type of selection is not a branch");
3613 } else if (parser.checkParCount(1))
3615 b=parser.parBool(ok,0);
3616 if (ok) setIncludeImagesVer(b);
3618 /////////////////////////////////////////////////////////////////////
3619 } else if (com=="setHideLinkUnselected")
3623 parser.setError (Aborted,"Nothing selected");
3624 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3626 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3627 } else if (parser.checkParCount(1))
3629 b=parser.parBool(ok,0);
3630 if (ok) setHideLinkUnselected(b);
3632 /////////////////////////////////////////////////////////////////////
3633 } else if (com=="setSelectionColor")
3635 if (parser.checkParCount(1))
3637 QColor c=parser.parColor (ok,0);
3638 if (ok) setSelectionColorInt (c);
3640 /////////////////////////////////////////////////////////////////////
3641 } else if (com=="setURL")
3645 parser.setError (Aborted,"Nothing selected");
3646 } else if (! selbi )
3648 parser.setError (Aborted,"Type of selection is not a branch");
3649 } else if (parser.checkParCount(1))
3651 s=parser.parString (ok,0);
3654 /////////////////////////////////////////////////////////////////////
3655 } else if (com=="setVymLink")
3659 parser.setError (Aborted,"Nothing selected");
3660 } else if (! selbi )
3662 parser.setError (Aborted,"Type of selection is not a branch");
3663 } else if (parser.checkParCount(1))
3665 s=parser.parString (ok,0);
3666 if (ok) setVymLink(s);
3669 /////////////////////////////////////////////////////////////////////
3670 else if (com=="setFlag")
3674 parser.setError (Aborted,"Nothing selected");
3675 } else if (! selbi )
3677 parser.setError (Aborted,"Type of selection is not a branch");
3678 } else if (parser.checkParCount(1))
3680 s=parser.parString(ok,0);
3682 selbi->activateStandardFlag(s);
3684 /////////////////////////////////////////////////////////////////////
3685 } else /* FIXME-2 if (com=="setFrameType")
3689 parser.setError (Aborted,"Nothing selected");
3692 parser.setError (Aborted,"Type of selection is not a branch");
3693 } else if (parser.checkParCount(1))
3695 s=parser.parString(ok,0);
3699 /////////////////////////////////////////////////////////////////////
3700 } else*/ if (com=="sortChildren")
3704 parser.setError (Aborted,"Nothing selected");
3705 } else if (! selbi )
3707 parser.setError (Aborted,"Type of selection is not a branch");
3708 } else if (parser.checkParCount(0))
3712 /////////////////////////////////////////////////////////////////////
3713 } else if (com=="toggleFlag")
3717 parser.setError (Aborted,"Nothing selected");
3718 } else if (! selbi )
3720 parser.setError (Aborted,"Type of selection is not a branch");
3721 } else if (parser.checkParCount(1))
3723 s=parser.parString(ok,0);
3725 selbi->toggleStandardFlag(s);
3727 /////////////////////////////////////////////////////////////////////
3728 } else if (com=="unscroll")
3732 parser.setError (Aborted,"Nothing selected");
3733 } else if (! selbi )
3735 parser.setError (Aborted,"Type of selection is not a branch");
3736 } else if (parser.checkParCount(0))
3738 if (!unscrollBranch (selbi))
3739 parser.setError (Aborted,"Could not unscroll branch");
3741 /////////////////////////////////////////////////////////////////////
3742 } else if (com=="unscrollChildren")
3746 parser.setError (Aborted,"Nothing selected");
3747 } else if (! selbi )
3749 parser.setError (Aborted,"Type of selection is not a branch");
3750 } else if (parser.checkParCount(0))
3752 unscrollChildren ();
3754 /////////////////////////////////////////////////////////////////////
3755 } else if (com=="unsetFlag")
3759 parser.setError (Aborted,"Nothing selected");
3760 } else if (! selbi )
3762 parser.setError (Aborted,"Type of selection is not a branch");
3763 } else if (parser.checkParCount(1))
3765 s=parser.parString(ok,0);
3767 selbi->deactivateStandardFlag(s);
3770 parser.setError (Aborted,"Unknown command");
3773 if (parser.errorLevel()==NoError)
3775 // setChanged(); FIXME-2 should not be called e.g. for export?!
3780 // TODO Error handling
3781 qWarning("VymModel::parseAtom: Error!");
3782 qWarning(parser.errorMessage());
3786 void VymModel::runScript (QString script)
3788 parser.setScript (script);
3790 while (parser.next() )
3791 parseAtom(parser.getAtom());
3794 void VymModel::setExportMode (bool b)
3796 // should be called before and after exports
3797 // depending on the settings
3798 if (b && settings.value("/export/useHideExport","true")=="true")
3799 setHideTmpMode (TreeItem::HideExport);
3801 setHideTmpMode (TreeItem::HideNone);
3804 void VymModel::exportImage(QString fname, bool askName, QString format)
3808 fname=getMapName()+".png";
3815 QFileDialog *fd=new QFileDialog (NULL);
3816 fd->setCaption (tr("Export map as image"));
3817 fd->setDirectory (lastImageDir);
3818 fd->setFileMode(QFileDialog::AnyFile);
3819 fd->setFilters (imageIO.getFilters() );
3822 fl=fd->selectedFiles();
3824 format=imageIO.getType(fd->selectedFilter());
3828 setExportMode (true);
3829 QPixmap pix (mapEditor->getPixmap());
3830 pix.save(fname, format);
3831 setExportMode (false);
3835 void VymModel::exportXML(QString dir, bool askForName)
3839 dir=browseDirectory(NULL,tr("Export XML to directory"));
3840 if (dir =="" && !reallyWriteDirectory(dir) )
3844 // Hide stuff during export, if settings want this
3845 setExportMode (true);
3847 // Create subdirectories
3850 // write to directory //FIXME-4 check totalBBox here...
3851 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3854 file.setName ( dir + "/"+mapName+".xml");
3855 if ( !file.open( QIODevice::WriteOnly ) )
3857 // This should neverever happen
3858 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3862 // Write it finally, and write in UTF8, no matter what
3863 QTextStream ts( &file );
3864 ts.setEncoding (QTextStream::UnicodeUTF8);
3868 // Now write image, too
3869 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3871 setExportMode (false);
3874 void VymModel::exportASCII(QString fname,bool askName)
3879 ex.setFile (mapName+".txt");
3885 //ex.addFilter ("TXT (*.txt)");
3886 ex.setDir(lastImageDir);
3887 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3892 setExportMode(true);
3894 setExportMode(false);
3898 void VymModel::exportXHTML (const QString &dir, bool askForName)
3900 ExportXHTMLDialog dia(NULL);
3901 dia.setFilePath (filePath );
3902 dia.setMapName (mapName );
3904 if (dir!="") dia.setDir (dir);
3910 if (dia.exec()!=QDialog::Accepted)
3914 QDir d (dia.getDir());
3915 // Check, if warnings should be used before overwriting
3916 // the output directory
3917 if (d.exists() && d.count()>0)
3920 warn.showCancelButton (true);
3921 warn.setText(QString(
3922 "The directory %1 is not empty.\n"
3923 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3924 warn.setCaption("Warning: Directory not empty");
3925 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3927 if (warn.exec()!=QDialog::Accepted) ok=false;
3934 exportXML (dia.getDir(),false );
3935 dia.doExport(mapName );
3936 //if (dia.hasChanged()) setChanged();
3940 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3945 if (ex.setConfigFile(cf))
3947 setExportMode (true);
3948 ex.exportPresentation();
3949 setExportMode (false);
3956 //////////////////////////////////////////////
3958 //////////////////////////////////////////////
3960 void VymModel::registerEditor(QWidget *me)
3962 mapEditor=(MapEditor*)me;
3965 void VymModel::unregisterEditor(QWidget *)
3970 void VymModel::setContextPos(QPointF p)
3975 void VymModel::unsetContextPos()
3977 contextPos=QPointF();
3980 void VymModel::updateNoteFlag()
3983 TreeItem *selti=getSelectedItem();
3986 if (textEditor->isEmpty())
3989 selti->setNote (textEditor->getText());
3990 emitDataHasChanged(selti);
3991 emitSelectionChanged();
3996 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3999 for (int i=0; i<rootItem->branchCount(); i++)
4000 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
4003 void MapCenterObj::updateRelPositions()
4005 if (repositionRequest) unsetAllRepositionRequests();
4007 // update relative Positions of branches and floats
4008 for (int i=0; i<treeItem->branchCount(); ++i)
4010 treeItem->getBranchObjNum(i)->setRelPos();
4011 treeItem->getBranchObjNum(i)->setOrientation();
4014 for (int i=0; i<floatimage.size(); ++i)
4015 floatimage.at(i)->setRelPos();
4017 if (repositionRequest) reposition();
4022 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
4024 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4025 if (blockReposition) return;
4027 for (int i=0;i<rootItem->branchCount(); i++)
4028 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4029 emitSelectionChanged();
4033 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
4035 return QPolygonF ();
4036 // Creating (arbitrary) shapes
4039 QRectF rb=bo->getBBox();
4040 if (bo->getDepth()==0)
4042 // Just take BBox of this mapCenter
4043 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
4047 // Take union of BBox and TotalBBox
4049 QRectF ra=bo->getTotalBBox();
4050 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4053 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
4056 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
4058 p <<ra.bottomRight()
4060 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4063 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4069 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4073 // Move all branches and MapCenters away from lmo
4074 // to avoid collisions
4079 BranchObj *boA=(BranchObj*)lmo;
4081 for (int i=0; i<rootItem->branchCount(); i++)
4083 boB=rootItem->getBranchNum(i);
4086 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4089 <<" ("<<qPrintable(boA->getHeading() )<<")"
4090 <<" with ("<< qPrintable (boB->getHeading() )
4093 <<" minT="<<r.minTranslation<<endl<<endl;
4099 void VymModel::setMapLinkStyle (const QString & s)
4104 case LinkableMapObj::Line :
4107 case LinkableMapObj::Parabel:
4108 snow="StyleParabel";
4110 case LinkableMapObj::PolyLine:
4111 snow="StylePolyLine";
4113 case LinkableMapObj::PolyParabel:
4114 snow="StylePolyParabel";
4117 snow="UndefinedStyle";
4122 QString("setMapLinkStyle (\"%1\")").arg(s),
4123 QString("setMapLinkStyle (\"%1\")").arg(snow),
4124 QString("Set map link style (\"%1\")").arg(s)
4128 linkstyle=LinkableMapObj::Line;
4129 else if (s=="StyleParabel")
4130 linkstyle=LinkableMapObj::Parabel;
4131 else if (s=="StylePolyLine")
4132 linkstyle=LinkableMapObj::PolyLine;
4133 else if (s=="StylePolyParabel")
4134 linkstyle=LinkableMapObj::PolyParabel;
4136 linkstyle=LinkableMapObj::UndefinedStyle;
4138 BranchItem *cur=NULL;
4139 BranchItem *prev=NULL;
4144 bo=(BranchObj*)(cur->getLMO() );
4145 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4151 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4156 void VymModel::setMapDefLinkColor(QColor col)
4158 if ( !col.isValid() ) return;
4160 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4161 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4162 QString("Set map link color to %1").arg(col.name())
4166 BranchItem *cur=NULL;
4167 BranchItem *prev=NULL;
4172 bo=(BranchObj*)(cur->getLMO() );
4179 void VymModel::setMapLinkColorHintInt()
4181 // called from setMapLinkColorHint(lch) or at end of parse
4182 BranchItem *cur=NULL;
4183 BranchItem *prev=NULL;
4188 bo=(BranchObj*)(cur->getLMO() );
4194 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4197 setMapLinkColorHintInt();
4200 void VymModel::toggleMapLinkColorHint()
4202 if (linkcolorhint==LinkableMapObj::HeadingColor)
4203 linkcolorhint=LinkableMapObj::DefaultColor;
4205 linkcolorhint=LinkableMapObj::HeadingColor;
4206 BranchItem *cur=NULL;
4207 BranchItem *prev=NULL;
4212 bo=(BranchObj*)(cur->getLMO() );
4218 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4220 Q3FileDialog *fd=new Q3FileDialog( NULL);
4221 fd->setMode (Q3FileDialog::ExistingFile);
4222 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4223 ImagePreview *p =new ImagePreview (fd);
4224 fd->setContentsPreviewEnabled( TRUE );
4225 fd->setContentsPreview( p, p );
4226 fd->setPreviewMode( Q3FileDialog::Contents );
4227 fd->setCaption(vymName+" - " +tr("Load background image"));
4228 fd->setDir (lastImageDir);
4231 if ( fd->exec() == QDialog::Accepted )
4233 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4234 lastImageDir=QDir (fd->dirPath());
4235 setMapBackgroundImage (fd->selectedFile());
4239 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate, move to ME
4241 QColor oldcol=mapScene->backgroundBrush().color();
4245 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4247 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4248 QString("Set background color of map to %1").arg(col.name()));
4251 brush.setTextureImage (QPixmap (fn));
4252 mapScene->setBackgroundBrush(brush);
4255 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4257 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4258 if ( !col.isValid() ) return;
4259 setMapBackgroundColor( col );
4263 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4265 QColor oldcol=mapScene->backgroundBrush().color();
4267 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4268 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4269 QString("Set background color of map to %1").arg(col.name()));
4270 mapScene->setBackgroundBrush(col);
4273 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4275 return mapScene->backgroundBrush().color();
4279 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4281 return linkcolorhint;
4284 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4286 return defLinkColor;
4289 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4294 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4296 return defXLinkColor;
4299 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4304 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4306 return defXLinkWidth;
4309 void VymModel::move(const double &x, const double &y) // FIXME-3
4313 BranchObj *bo = getSelectedBranch();
4315 (selectionType()==TreeItem::Branch ||
4316 selectionType()==TreeItem::MapCenter ||
4317 selectionType()==TreeItem::Image
4320 QPointF ap(bo->getAbsPos());
4324 QString ps=qpointfToString(ap);
4325 QString s=getSelectString();
4328 s, "move "+qpointfToString(to),
4329 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4332 emitSelectionChanged();
4338 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4342 BranchObj *bo = getSelectedBranch();
4344 (selectionType()==TreeItem::Branch ||
4345 selectionType()==TreeItem::MapCenter ||
4346 selectionType()==TreeItem::Image
4350 QPointF rp(bo->getRelPos());
4354 QString ps=qpointfToString (bo->getRelPos());
4355 QString s=getSelectString(bo);
4358 s, "moveRel "+qpointfToString(to),
4359 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4360 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4362 bo->updateLinkGeometry();
4363 emitSelectionChanged();
4370 void VymModel::animate()
4372 animationTimer->stop();
4375 while (i<animObjList.size() )
4377 bo=(BranchObj*)animObjList.at(i);
4382 animObjList.removeAt(i);
4389 QItemSelection sel=selModel->selection();
4390 emit (selectionChanged(sel,sel));
4393 if (!animObjList.isEmpty()) animationTimer->start();
4397 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4399 if (bo && bo->getTreeItem()->depth()>0)
4402 ap.setStart (start);
4404 ap.setTicks (animationTicks);
4405 ap.setAnimated (true);
4406 bo->setAnimation (ap);
4407 animObjList.append( bo );
4408 animationTimer->setSingleShot (true);
4409 animationTimer->start(animationInterval);
4413 void VymModel::stopAnimation (MapObj *mo)
4415 int i=animObjList.indexOf(mo);
4417 animObjList.removeAt (i);
4420 void VymModel::sendSelection()
4422 if (netstate!=Server) return;
4423 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4426 void VymModel::newServer()
4430 tcpServer = new QTcpServer(this);
4431 if (!tcpServer->listen(QHostAddress::Any,port)) {
4432 QMessageBox::critical(NULL, "vym server",
4433 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4434 //FIXME-3 needed? we are no widget any longer... close();
4437 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4439 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4442 void VymModel::connectToServer()
4445 server="salam.suse.de";
4447 clientSocket = new QTcpSocket (this);
4448 clientSocket->abort();
4449 clientSocket->connectToHost(server ,port);
4450 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4451 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4452 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4454 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4459 void VymModel::newClient()
4461 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4462 connect(newClient, SIGNAL(disconnected()),
4463 newClient, SLOT(deleteLater()));
4465 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4467 clientList.append (newClient);
4471 void VymModel::sendData(const QString &s)
4473 if (clientList.size()==0) return;
4475 // Create bytearray to send
4477 QDataStream out(&block, QIODevice::WriteOnly);
4478 out.setVersion(QDataStream::Qt_4_0);
4480 // Reserve some space for blocksize
4483 // Write sendCounter
4484 out << sendCounter++;
4489 // Go back and write blocksize so far
4490 out.device()->seek(0);
4491 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4495 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4497 for (int i=0; i<clientList.size(); ++i)
4499 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4500 clientList.at(i)->write (block);
4504 void VymModel::readData ()
4506 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4509 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4513 QDataStream in(clientSocket);
4514 in.setVersion(QDataStream::Qt_4_0);
4522 cout << " t="<<qPrintable (t)<<endl;
4528 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4530 switch (socketError) {
4531 case QAbstractSocket::RemoteHostClosedError:
4533 case QAbstractSocket::HostNotFoundError:
4534 QMessageBox::information(NULL, vymName +" Network client",
4535 "The host was not found. Please check the "
4536 "host name and port settings.");
4538 case QAbstractSocket::ConnectionRefusedError:
4539 QMessageBox::information(NULL, vymName + " Network client",
4540 "The connection was refused by the peer. "
4541 "Make sure the fortune server is running, "
4542 "and check that the host name and port "
4543 "settings are correct.");
4546 QMessageBox::information(NULL, vymName + " Network client",
4547 QString("The following error occurred: %1.")
4548 .arg(clientSocket->errorString()));
4552 /* FIXME-3 Playing with DBUS...
4553 QDBusVariant VymModel::query (const QString &query)
4555 TreeItem *selti=getSelectedItem();
4557 return QDBusVariant (selti->getHeading());
4559 return QDBusVariant ("Nothing selected.");
4563 void VymModel::testslot() //FIXME-3
4565 cout << "VM::testslot called\n";
4568 void VymModel::selectMapSelectionColor()
4570 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4571 setSelectionColor (col);
4574 void VymModel::setSelectionColorInt (QColor col)
4576 if ( !col.isValid() ) return;
4578 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4579 QString("setSelectionColor (%1)").arg(col.name()),
4580 QString("Set color of selection box to %1").arg(col.name())
4583 mapEditor->setSelectionColor (col);
4586 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4588 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4589 emitShowSelection();
4593 void VymModel::emitSelectionChanged()
4595 QItemSelection newsel=selModel->selection();
4596 emitSelectionChanged (newsel);
4599 void VymModel::setSelectionColor(QColor col)
4601 if ( !col.isValid() ) return;
4603 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4604 QString("setSelectionColor (%1)").arg(col.name()),
4605 QString("Set color of selection box to %1").arg(col.name())
4607 setSelectionColorInt (col);
4610 QColor VymModel::getSelectionColor()
4612 return mapEditor->getSelectionColor();
4615 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4618 for (int i=0;i<rootItem->childCount();i++)
4619 rootItem->child(i)->setHideTmp (mode);
4621 // FIXME-3 needed? scene()->update();
4624 //////////////////////////////////////////////
4625 // Selection related
4626 //////////////////////////////////////////////
4628 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4633 QItemSelectionModel* VymModel::getSelectionModel()
4638 void VymModel::setSelectionBlocked (bool b)
4643 bool VymModel::isSelectionBlocked()
4645 return selectionBlocked;
4648 bool VymModel::select ()
4650 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4653 bool VymModel::select (const QString &s)
4660 TreeItem *ti=findBySelectString(s);
4661 if (ti) return select (index(ti));
4665 bool VymModel::select (LinkableMapObj *lmo)
4667 QItemSelection oldsel=selModel->selection();
4670 return select (index (lmo->getTreeItem()) );
4675 bool VymModel::select (TreeItem *ti)
4677 if (ti) return select (index(ti));
4681 bool VymModel::select (const QModelIndex &index)
4683 if (index.isValid() )
4685 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4686 BranchItem *bi=getSelectedBranch();
4687 if (bi) bi->setLastSelectedBranch();
4693 void VymModel::unselect()
4695 lastSelectString=getSelectString();
4696 selModel->clearSelection();
4699 bool VymModel::reselect()
4701 return select (lastSelectString);
4704 void VymModel::emitShowSelection()
4706 if (!blockReposition)
4707 emit (showSelection() );
4710 void VymModel::emitNoteHasChanged (TreeItem *ti)
4712 QModelIndex ix=index(ti);
4713 emit (noteHasChanged (ix) );
4716 void VymModel::emitDataHasChanged (TreeItem *ti)
4718 QModelIndex ix=index(ti);
4719 emit (dataChanged (ix,ix) );
4723 //bool VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4726 if (selection.select(lmo))
4728 //emitSelectionChanged();
4732 bool VymModel::selectInt (TreeItem *ti)
4734 if (selection.select(lmo))
4736 //emitSelectionChanged();
4741 bool VymModel::selectFirstBranch()
4743 TreeItem *ti=getSelectedBranch();
4746 TreeItem *par=ti->parent();
4749 TreeItem *ti2=par->getFirstBranch();
4750 if (ti2) return select(ti2);
4756 bool VymModel::selectLastBranch()
4758 TreeItem *ti=getSelectedBranch();
4761 TreeItem *par=ti->parent();
4764 TreeItem *ti2=par->getLastBranch();
4765 if (ti2) return select(ti2);
4771 bool VymModel::selectLastSelectedBranch()
4773 BranchItem *bi=getSelectedBranch();
4776 bi=bi->getLastSelectedBranch();
4777 if (bi) return select (bi);
4782 bool VymModel::selectParent()
4784 TreeItem *ti=getSelectedItem();
4795 TreeItem::Type VymModel::selectionType()
4797 QModelIndexList list=selModel->selectedIndexes();
4798 if (list.isEmpty()) return TreeItem::Undefined;
4799 TreeItem *ti = getItem (list.first() );
4800 return ti->getType();
4804 LinkableMapObj* VymModel::getSelectedLMO()
4806 QModelIndexList list=selModel->selectedIndexes();
4807 if (!list.isEmpty() )
4809 TreeItem *ti = getItem (list.first() );
4810 TreeItem::Type type=ti->getType();
4811 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4812 return ((MapItem*)ti)->getLMO();
4817 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4819 TreeItem *ti = getSelectedBranch();
4821 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4826 BranchItem* VymModel::getSelectedBranch()
4828 QModelIndexList list=selModel->selectedIndexes();
4829 if (!list.isEmpty() )
4831 TreeItem *ti = getItem (list.first() );
4832 TreeItem::Type type=ti->getType();
4833 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4834 return (BranchItem*)ti;
4839 ImageItem* VymModel::getSelectedImage()
4841 QModelIndexList list=selModel->selectedIndexes();
4842 if (!list.isEmpty())
4844 TreeItem *ti=getItem (list.first());
4845 if (ti && ti->getType()==TreeItem::Image)
4846 return (ImageItem*)ti;
4851 AttributeItem* VymModel::getSelectedAttribute()
4853 QModelIndexList list=selModel->selectedIndexes();
4854 if (!list.isEmpty() )
4856 TreeItem *ti = getItem (list.first() );
4857 TreeItem::Type type=ti->getType();
4858 if (type ==TreeItem::Attribute)
4859 return (AttributeItem*)ti;
4864 TreeItem* VymModel::getSelectedItem()
4866 QModelIndexList list=selModel->selectedIndexes();
4867 if (!list.isEmpty() )
4868 return getItem (list.first() );
4873 QModelIndex VymModel::getSelectedIndex()
4875 QModelIndexList list=selModel->selectedIndexes();
4876 if (list.isEmpty() )
4877 return QModelIndex();
4879 return list.first();
4882 QString VymModel::getSelectString ()
4884 return getSelectString (getSelectedItem());
4887 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
4889 if (!lmo) return QString();
4890 return getSelectString (lmo->getTreeItem() );
4893 QString VymModel::getSelectString (TreeItem *ti)
4897 switch (ti->getType())
4899 case TreeItem::MapCenter: s="mc:"; break;
4900 case TreeItem::Branch: s="bo:";break;
4901 case TreeItem::Image: s="fi:";break;
4902 case TreeItem::Attribute: s="ai:";break;
4905 s= s + QString("%1").arg(ti->num());
4907 // call myself recursively
4908 s= getSelectString(ti->parent()) +","+s;