1 #include <QApplication>
7 #include "branchitem.h"
8 #include "editxlinkdialog.h"
10 #include "exportxhtmldialog.h"
12 #include "geometry.h" // for addBBox
13 #include "mainwindow.h"
17 #include "warningdialog.h"
18 #include "xml-freemind.h"
24 extern Main *mainWindow;
25 extern Settings settings;
26 extern QString tmpVymDir;
28 extern TextEditor *textEditor;
29 extern FlagRow *standardFlagsMaster;
31 extern QString clipboardDir;
32 extern QString clipboardFile;
33 extern bool clipboardEmpty;
35 extern ImageIO imageIO;
37 extern QString vymName;
38 extern QString vymVersion;
39 extern QDir vymBaseDir;
41 extern QDir lastImageDir;
42 extern QDir lastFileDir;
44 extern Settings settings;
48 int VymModel::mapNum=0; // make instance
52 // cout << "Const VymModel\n";
54 rootItem->setModel (this);
60 cout << "Destr VymModel\n";
61 autosaveTimer->stop();
62 fileChangedTimer->stop();
66 void VymModel::clear()
68 selModel->clearSelection();
70 //QModelIndex ri=index(rootItem);
71 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
74 void VymModel::init ()
76 // We should have at least one map center to start with
77 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
82 // Also no scene yet (should not be needed anyway) FIXME-3 VM
95 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
96 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
97 mainWindow->updateHistory (undoSet);
100 makeTmpDirectories();
105 fileName=tr("unnamed");
107 blockReposition=false;
108 blockSaveState=false;
110 autosaveTimer=new QTimer (this);
111 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
113 fileChangedTimer=new QTimer (this);
114 fileChangedTimer->start(3000);
115 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
120 selectionBlocked=false;
128 animationUse=settings.readBoolEntry("/animation/use",false);
129 animationTicks=settings.readNumEntry("/animation/ticks",10);
130 animationInterval=settings.readNumEntry("/animation/interval",50);
132 animationTimer=new QTimer (this);
133 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
136 defLinkColor=QColor (0,0,255);
137 defXLinkColor=QColor (180,180,180);
138 linkcolorhint=LinkableMapObj::DefaultColor;
139 linkstyle=LinkableMapObj::PolyParabel;
141 defXLinkColor=QColor (230,230,230);
143 hidemode=TreeItem::HideNone;
149 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
153 void VymModel::makeTmpDirectories()
155 // Create unique temporary directories
156 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
157 histPath = tmpMapDir+"/history";
163 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
168 bool VymModel::isRepositionBlocked()
170 return blockReposition;
173 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
175 //cout << "VM::updateActions \n";
176 // Tell mainwindow to update states of actions
177 mainWindow->updateActions();
182 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
184 // tmpdir temporary directory to which data will be written
185 // prefix mapname, which will be appended to images etc.
186 // writeflags Only write flags for "real" save of map, not undo
187 // offset offset of bbox of whole map in scene.
188 // Needed for XML export
197 case LinkableMapObj::Line:
200 case LinkableMapObj::Parabel:
203 case LinkableMapObj::PolyLine:
207 ls="StylePolyParabel";
211 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
213 if (linkcolorhint==LinkableMapObj::HeadingColor)
214 colhint=xml.attribut("linkColorHint","HeadingColor");
216 QString mapAttr=xml.attribut("version",vymVersion);
218 mapAttr+= xml.attribut("author",author) +
219 xml.attribut("comment",comment) +
220 xml.attribut("date",getDate()) +
221 xml.attribut("branchCount", QString().number(branchCount())) +
222 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
223 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
224 xml.attribut("linkStyle", ls ) +
225 xml.attribut("linkColor", defLinkColor.name() ) +
226 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
227 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
229 s+=xml.beginElement("vymmap",mapAttr);
232 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
233 standardFlagsMaster->resetUsedCounter();
235 // Reset the counters before saving
236 // TODO constr. of FIO creates lots of objects, better do this in some other way...
237 ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
239 // Build xml recursivly
240 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
241 // Save all mapcenters as complete map, if saveSel not set
242 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
245 if (saveSel->isBranchLikeType())
247 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
248 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
250 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
253 // Save local settings
254 s+=settings.getDataXML (destPath);
257 if (getSelectedItem() && !saveSel )
258 s+=xml.valueElement("select",getSelectString());
261 s+=xml.endElement("vymmap");
263 //cout << s.toStdString() << endl;
265 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
269 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
273 for (int i=0; i<rootItem->branchCount(); i++)
274 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
278 void VymModel::setFilePath(QString fpath, QString destname)
280 if (fpath.isEmpty() || fpath=="")
287 filePath=fpath; // becomes absolute path
288 fileName=fpath; // gets stripped of path
289 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
291 // If fpath is not an absolute path, complete it
292 filePath=QDir(fpath).absPath();
293 fileDir=filePath.left (1+filePath.findRev ("/"));
295 // Set short name, too. Search from behind:
296 int i=fileName.findRev("/");
297 if (i>=0) fileName=fileName.remove (0,i+1);
299 // Forget the .vym (or .xml) for name of map
300 mapName=fileName.left(fileName.findRev(".",-1,true) );
304 void VymModel::setFilePath(QString fpath)
306 setFilePath (fpath,fpath);
309 QString VymModel::getFilePath()
314 QString VymModel::getFileName()
319 QString VymModel::getMapName()
324 QString VymModel::getDestPath()
329 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
331 ErrorCode err=success;
333 parseBaseHandler *handler;
337 case VymMap: handler=new parseVYMHandler; break;
338 case FreemindMap : handler=new parseFreemindHandler; break;
340 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
341 "Unknown FileType in VymModel::load()");
345 bool zipped_org=zipped;
349 selModel->clearSelection();
350 // FIXME-2 VM not needed??? model->setMapEditor(this);
351 // (map state is set later at end of load...)
354 BranchItem *bi=getSelectedBranchItem();
355 if (!bi) return aborted;
356 if (lmode==ImportAdd)
357 saveStateChangingPart(
360 QString("addMapInsert (%1)").arg(fname),
361 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
363 saveStateChangingPart(
366 QString("addMapReplace(%1)").arg(fname),
367 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
371 // Create temporary directory for packing
373 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
376 QMessageBox::critical( 0, tr( "Critical Load Error" ),
377 tr("Couldn't create temporary directory before load\n"));
382 err=unzipDir (tmpZipDir,fname);
392 // Look for mapname.xml
393 xmlfile= fname.left(fname.findRev(".",-1,true));
394 xmlfile=xmlfile.section( '/', -1 );
395 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
396 if (!mfile.exists() )
398 // mapname.xml does not exist, well,
399 // maybe someone renamed the mapname.vym file...
400 // Try to find any .xml in the toplevel
401 // directory of the .vym file
402 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
403 if (flist.count()==1)
405 // Only one entry, take this one
406 xmlfile=tmpZipDir + "/"+flist.first();
409 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
410 *it=tmpZipDir + "/" + *it;
411 // TODO Multiple entries, load all (but only the first one into this ME)
412 //mainWindow->fileLoadFromTmp (flist);
413 //returnCode=1; // Silently forget this attempt to load
414 qWarning ("MainWindow::load (fn) multimap found...");
417 if (flist.isEmpty() )
419 QMessageBox::critical( 0, tr( "Critical Load Error" ),
420 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
423 } //file doesn't exist
425 xmlfile=mfile.name();
428 QFile file( xmlfile);
430 // I am paranoid: file should exist anyway
431 // according to check in mainwindow.
434 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
435 tr(QString("Couldn't open map %1").arg(file.name())));
439 bool blockSaveStateOrg=blockSaveState;
440 blockReposition=true;
442 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
443 QXmlInputSource source( file);
444 QXmlSimpleReader reader;
445 reader.setContentHandler( handler );
446 reader.setErrorHandler( handler );
447 handler->setModel ( this);
450 // We need to set the tmpDir in order to load files with rel. path
455 tmpdir=fname.left(fname.findRev("/",-1));
456 handler->setTmpDir (tmpdir);
457 handler->setInputFile (file.name());
458 handler->setLoadMode (lmode);
459 bool ok = reader.parse( source );
460 blockReposition=false;
461 blockSaveState=blockSaveStateOrg;
462 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
466 reposition(); // FIXME-2 VM reposition the view instead...
467 emitSelectionChanged();
473 autosaveTimer->stop();
476 // Reset timestamp to check for later updates of file
477 fileChangedTime=QFileInfo (destPath).lastModified();
480 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
481 tr( handler->errorProtocol() ) );
483 // Still return "success": the map maybe at least
484 // partially read by the parser
489 removeDir (QDir(tmpZipDir));
491 // Restore original zip state
498 ErrorCode VymModel::save (const SaveMode &savemode)
502 QString safeFilePath;
504 ErrorCode err=success;
508 mapFileName=mapName+".xml";
510 // use name given by user, even if he chooses .doc
511 mapFileName=fileName;
513 // Look, if we should zip the data:
516 QMessageBox mb( vymName,
517 tr("The map %1\ndid not use the compressed "
518 "vym file format.\nWriting it uncompressed will also write images \n"
519 "and flags and thus may overwrite files in the "
520 "given directory\n\nDo you want to write the map").arg(filePath),
521 QMessageBox::Warning,
522 QMessageBox::Yes | QMessageBox::Default,
524 QMessageBox::Cancel | QMessageBox::Escape);
525 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
526 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
527 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
530 case QMessageBox::Yes:
531 // save compressed (default file format)
534 case QMessageBox::No:
538 case QMessageBox::Cancel:
545 // First backup existing file, we
546 // don't want to add to old zip archives
550 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
552 QString backupFileName(destPath + "~");
553 QFile backupFile(backupFileName);
554 if (backupFile.exists() && !backupFile.remove())
556 QMessageBox::warning(0, tr("Save Error"),
557 tr("%1\ncould not be removed before saving").arg(backupFileName));
559 else if (!f.rename(backupFileName))
561 QMessageBox::warning(0, tr("Save Error"),
562 tr("%1\ncould not be renamed before saving").arg(destPath));
569 // Create temporary directory for packing
571 tmpZipDir=makeTmpDir (ok,"vym-zip");
574 QMessageBox::critical( 0, tr( "Critical Load Error" ),
575 tr("Couldn't create temporary directory before save\n"));
579 safeFilePath=filePath;
580 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
583 // Create mapName and fileDir
584 makeSubDirs (fileDir);
587 if (savemode==CompleteMap || selModel->selection().isEmpty())
590 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
593 autosaveTimer->stop();
598 if (selectionType()==TreeItem::Image)
601 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
602 // TODO take care of multiselections
605 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
608 qWarning ("ME::saveStringToDisk failed!");
614 if (err==success) err=zipDir (tmpZipDir,destPath);
617 removeDir (QDir(tmpZipDir));
619 // Restore original filepath outside of tmp zip dir
620 setFilePath (safeFilePath);
624 fileChangedTime=QFileInfo (destPath).lastModified();
628 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree
630 QString pathDir=path.left(path.findRev("/"));
636 // We need to parse saved XML data
637 parseVYMHandler handler;
638 QXmlInputSource source( file);
639 QXmlSimpleReader reader;
640 reader.setContentHandler( &handler );
641 reader.setErrorHandler( &handler );
642 handler.setModel ( this);
643 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
644 if (undoSel.isEmpty())
648 handler.setLoadMode (NewMap);
652 handler.setLoadMode (ImportReplace);
654 blockReposition=true;
655 bool ok = reader.parse( source );
656 blockReposition=false;
659 // This should never ever happen
660 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
661 handler.errorProtocol());
664 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
667 void VymModel::addMapInsertInt (const QString &path, int pos)
669 /* FIXME-2 addMapInsertInt not ported yet
670 BranchObj *sel=getSelectedBranch();
673 QString pathDir=path.left(path.findRev("/"));
679 // We need to parse saved XML data
680 parseVYMHandler handler;
681 QXmlInputSource source( file);
682 QXmlSimpleReader reader;
683 reader.setContentHandler( &handler );
684 reader.setErrorHandler( &handler );
685 handler.setModel (this);
686 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
687 handler.setLoadMode (ImportAdd);
688 blockReposition=true;
689 bool ok = reader.parse( source );
690 blockReposition=false;
693 // This should never ever happen
694 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
695 handler.errorProtocol());
697 if (sel->getDepth()>0)
698 sel->getLastBranch()->linkTo (sel,pos);
700 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
705 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
707 ImageItem *ii=createImage(dst);
717 void VymModel::loadFloatImage ()
719 BranchItem *selbi=getSelectedBranchItem();
723 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
724 fd->setMode (Q3FileDialog::ExistingFiles);
725 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
726 ImagePreview *p =new ImagePreview (fd);
727 fd->setContentsPreviewEnabled( TRUE );
728 fd->setContentsPreview( p, p );
729 fd->setPreviewMode( Q3FileDialog::Contents );
730 fd->setCaption(vymName+" - " +tr("Load image"));
731 fd->setDir (lastImageDir);
734 if ( fd->exec() == QDialog::Accepted )
736 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
737 lastImageDir=QDir (fd->dirPath());
740 for (int j=0; j<fd->selectedFiles().count(); j++)
742 s=fd->selectedFiles().at(j);
743 ii=loadFloatImageInt (selbi,s);
744 //FIXME-3 check savestate for loadImage
750 QString ("loadImage (%1)").arg(s ),
751 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
754 // TODO loadFIO error handling
755 qWarning ("Failed to load "+s);
763 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
768 void VymModel::saveFloatImage ()
770 ImageItem *ii=getSelectedImageItem();
773 QFileDialog *fd=new QFileDialog( NULL);
774 fd->setFilters (imageIO.getFilters());
775 fd->setCaption(vymName+" - " +tr("Save image"));
776 fd->setFileMode( QFileDialog::AnyFile );
777 fd->setDirectory (lastImageDir);
778 // fd->setSelection (fio->getOriginalFilename());
782 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
784 fn=fd->selectedFiles().at(0);
785 if (QFile (fn).exists() )
787 QMessageBox mb( vymName,
788 tr("The file %1 exists already.\n"
789 "Do you want to overwrite it?").arg(fn),
790 QMessageBox::Warning,
791 QMessageBox::Yes | QMessageBox::Default,
792 QMessageBox::Cancel | QMessageBox::Escape,
793 QMessageBox::NoButton );
795 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
796 mb.setButtonText( QMessageBox::No, tr("Cancel"));
799 case QMessageBox::Yes:
802 case QMessageBox::Cancel:
809 saveFloatImageInt (ii,fd->selectedFilter(),fn );
816 void VymModel::importDirInt(BranchObj *dst, QDir d)
818 /* FIXME-2 importDirInt not ported yet
819 BranchObj *bo=getSelectedBranch();
822 // Traverse directories
823 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
824 QFileInfoList list = d.entryInfoList();
827 for (int i = 0; i < list.size(); ++i)
830 if (fi.fileName() != "." && fi.fileName() != ".." )
833 bo=dst->getLastBranch();
834 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
835 bi->setHeading (fi.fileName() ); // FIXME-3 check this
836 bo->setColor (QColor("blue"));
838 if ( !d.cd(fi.fileName()) )
839 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
842 // Recursively add subdirs
849 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
850 list = d.entryInfoList();
852 for (int i = 0; i < list.size(); ++i)
856 bo=dst->getLastBranch();
857 bo->setHeading (fi.fileName() );
858 bo->setColor (QColor("black"));
859 if (fi.fileName().right(4) == ".vym" )
860 bo->setVymLink (fi.filePath());
866 void VymModel::importDirInt (const QString &s) // FIXME-2
869 BranchObj *bo=getSelectedBranch();
872 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
880 void VymModel::importDir() //FIXME-2
883 BranchObj *bo=getSelectedBranch();
887 filters <<"VYM map (*.vym)";
888 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
889 fd->setMode (QFileDialog::DirectoryOnly);
890 fd->setFilters (filters);
891 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
895 if ( fd->exec() == QDialog::Accepted )
897 importDirInt (fd->selectedFile() );
899 //FIXME-3 VM needed? scene()->update();
906 void VymModel::autosave()
911 cout << "VymModel::autosave rejected due to missing filePath\n";
914 QDateTime now=QDateTime().currentDateTime();
916 // Disable autosave, while we have gone back in history
917 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
918 if (redosAvail>0) return;
920 // Also disable autosave for new map without filename
921 if (filePath.isEmpty()) return;
924 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
926 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
927 mainWindow->fileSave (this);
930 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
935 void VymModel::fileChanged()
937 // Check if file on disk has changed meanwhile
938 if (!filePath.isEmpty())
940 QDateTime tmod=QFileInfo (filePath).lastModified();
941 if (tmod>fileChangedTime)
943 // FIXME-2 VM switch to current mapeditor and finish lineedits...
944 QMessageBox mb( vymName,
945 tr("The file of the map on disk has changed:\n\n"
946 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
947 QMessageBox::Question,
949 QMessageBox::Cancel | QMessageBox::Default,
950 QMessageBox::NoButton );
952 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
953 mb.setButtonText( QMessageBox::No, tr("Ignore"));
956 case QMessageBox::Yes:
958 load (filePath,NewMap,fileType);
959 case QMessageBox::Cancel:
960 fileChangedTime=tmod; // allow autosave to overwrite newer file!
966 bool VymModel::isDefault()
971 void VymModel::makeDefault()
977 bool VymModel::hasChanged()
982 void VymModel::setChanged()
985 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
989 latestAddedItem=NULL;
993 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
995 if (!lmo || !lmo->getTreeItem() ) return QString();
996 return getObjectName (lmo->getTreeItem() );
1000 QString VymModel::getObjectName (TreeItem *ti)
1003 if (!ti) return QString("Error: NULL has no name!");
1005 if (s=="") s="unnamed";
1007 if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter??
1008 return QString("branch (%1)").arg(s);
1009 if (ti->getType()==TreeItem::Image)
1010 return QString ("image (%1)").arg(ti->getHeading());
1011 return QString("Unknown type has no name!");
1014 void VymModel::redo()
1016 // Can we undo at all?
1017 if (redosAvail<1) return;
1019 bool blockSaveStateOrg=blockSaveState;
1020 blockSaveState=true;
1024 if (undosAvail<stepsTotal) undosAvail++;
1026 if (curStep>stepsTotal) curStep=1;
1027 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1028 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1029 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1030 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1031 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1032 QString version=undoSet.readEntry ("/history/version");
1034 /* TODO Maybe check for version, if we save the history
1035 if (!checkVersion(version))
1036 QMessageBox::warning(0,tr("Warning"),
1037 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1040 // Find out current undo directory
1041 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1045 cout << "VymModel::redo() begin\n";
1046 cout << " undosAvail="<<undosAvail<<endl;
1047 cout << " redosAvail="<<redosAvail<<endl;
1048 cout << " curStep="<<curStep<<endl;
1049 cout << " ---------------------------"<<endl;
1050 cout << " comment="<<comment.toStdString()<<endl;
1051 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1052 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1053 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1054 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1055 cout << " ---------------------------"<<endl<<endl;
1058 // select object before redo
1059 if (!redoSelection.isEmpty())
1060 select (redoSelection);
1063 parseAtom (redoCommand);
1066 blockSaveState=blockSaveStateOrg;
1068 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1069 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1070 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1071 undoSet.writeSettings(histPath);
1073 mainWindow->updateHistory (undoSet);
1076 /* TODO remove testing
1077 cout << "ME::redo() end\n";
1078 cout << " undosAvail="<<undosAvail<<endl;
1079 cout << " redosAvail="<<redosAvail<<endl;
1080 cout << " curStep="<<curStep<<endl;
1081 cout << " ---------------------------"<<endl<<endl;
1087 bool VymModel::isRedoAvailable()
1089 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1095 void VymModel::undo()
1097 // Can we undo at all?
1098 if (undosAvail<1) return;
1100 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1102 bool blockSaveStateOrg=blockSaveState;
1103 blockSaveState=true;
1105 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1106 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1107 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1108 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1109 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1110 QString version=undoSet.readEntry ("/history/version");
1112 /* TODO Maybe check for version, if we save the history
1113 if (!checkVersion(version))
1114 QMessageBox::warning(0,tr("Warning"),
1115 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1118 // Find out current undo directory
1119 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1121 // select object before undo
1122 if (!undoSelection.isEmpty())
1123 select (undoSelection);
1127 cout << "VymModel::undo() begin\n";
1128 cout << " undosAvail="<<undosAvail<<endl;
1129 cout << " redosAvail="<<redosAvail<<endl;
1130 cout << " curStep="<<curStep<<endl;
1131 cout << " ---------------------------"<<endl;
1132 cout << " comment="<<comment.toStdString()<<endl;
1133 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1134 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1135 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1136 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1137 cout << " ---------------------------"<<endl<<endl;
1139 parseAtom (undoCommand);
1144 if (curStep<1) curStep=stepsTotal;
1148 blockSaveState=blockSaveStateOrg;
1149 /* TODO remove testing
1150 cout << "VymModel::undo() end\n";
1151 cout << " undosAvail="<<undosAvail<<endl;
1152 cout << " redosAvail="<<redosAvail<<endl;
1153 cout << " curStep="<<curStep<<endl;
1154 cout << " ---------------------------"<<endl<<endl;
1157 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1158 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1159 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1160 undoSet.writeSettings(histPath);
1162 mainWindow->updateHistory (undoSet);
1164 emitSelectionChanged();
1167 bool VymModel::isUndoAvailable()
1169 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1175 void VymModel::gotoHistoryStep (int i)
1177 // Restore variables
1178 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1179 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1181 if (i<0) i=undosAvail+redosAvail;
1183 // Clicking above current step makes us undo things
1186 for (int j=0; j<undosAvail-i; j++) undo();
1189 // Clicking below current step makes us redo things
1191 for (int j=undosAvail; j<i; j++)
1193 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1197 // And ignore clicking the current row ;-)
1201 QString VymModel::getHistoryPath()
1203 QString histName(QString("history-%1").arg(curStep));
1204 return (tmpMapDir+"/"+histName);
1207 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1209 sendData(redoCom); //FIXME-3 testing
1214 if (blockSaveState) return;
1216 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1218 // Find out current undo directory
1219 if (undosAvail<stepsTotal) undosAvail++;
1221 if (curStep>stepsTotal) curStep=1;
1223 QString backupXML="";
1224 QString histDir=getHistoryPath();
1225 QString bakMapPath=histDir+"/map.xml";
1227 // Create histDir if not available
1230 makeSubDirs (histDir);
1232 // Save depending on how much needs to be saved
1234 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1236 QString undoCommand="";
1237 if (savemode==UndoCommand)
1239 undoCommand=undoCom;
1241 else if (savemode==PartOfMap )
1243 undoCommand=undoCom;
1244 undoCommand.replace ("PATH",bakMapPath);
1248 if (!backupXML.isEmpty())
1249 // Write XML Data to disk
1250 saveStringToDisk (bakMapPath,backupXML);
1252 // We would have to save all actions in a tree, to keep track of
1253 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1256 // Write the current state to disk
1257 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1258 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1259 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1260 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1261 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1262 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1263 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1264 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1265 undoSet.setEntry (QString("/history/version"),vymVersion);
1266 undoSet.writeSettings(histPath);
1270 // TODO remove after testing
1271 //cout << " into="<< histPath.toStdString()<<endl;
1272 cout << " stepsTotal="<<stepsTotal<<
1273 ", undosAvail="<<undosAvail<<
1274 ", redosAvail="<<redosAvail<<
1275 ", curStep="<<curStep<<endl;
1276 cout << " ---------------------------"<<endl;
1277 cout << " comment="<<comment.toStdString()<<endl;
1278 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1279 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1280 cout << " redoCom="<<redoCom.toStdString()<<endl;
1281 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1282 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1283 cout << " ---------------------------"<<endl;
1286 mainWindow->updateHistory (undoSet);
1292 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1294 // save the selected part of the map, Undo will replace part of map
1295 QString undoSelection="";
1297 undoSelection=getSelectString(undoSel);
1299 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1300 QString redoSelection="";
1302 redoSelection=getSelectString(undoSel);
1304 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1307 saveState (PartOfMap,
1308 undoSelection, "addMapReplace (\"PATH\")",
1314 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1318 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1321 QString undoSelection=getSelectString (redoSel->parent() );
1322 QString redoSelection=getSelectString(redoSel);
1323 if (redoSel->getType()==TreeItem::Branch)
1325 // save the selected branch of the map, Undo will insert part of map
1326 saveState (PartOfMap,
1327 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1328 redoSelection, "delete ()",
1335 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1337 // "Normal" savestate: save commands, selections and comment
1338 // so just save commands for undo and redo
1339 // and use current selection
1341 QString redoSelection="";
1342 if (redoSel) redoSelection=getSelectString(redoSel);
1343 QString undoSelection="";
1344 if (undoSel) undoSelection=getSelectString(undoSel);
1346 saveState (UndoCommand,
1353 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1355 // "Normal" savestate: save commands, selections and comment
1356 // so just save commands for undo and redo
1357 // and use current selection
1358 saveState (UndoCommand,
1365 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1367 // "Normal" savestate applied to model (no selection needed):
1368 // save commands and comment
1369 saveState (UndoCommand,
1377 QGraphicsScene* VymModel::getScene ()
1382 TreeItem* VymModel::findBySelectString(QString s)
1384 if (s.isEmpty() ) return NULL;
1386 // Old maps don't have multiple mapcenters and don't save full path
1387 if (s.left(2) !="mc")
1390 QStringList parts=s.split (",");
1393 TreeItem *ti=rootItem;
1395 while (!parts.isEmpty() )
1397 typ=parts.first().left(2);
1398 n=parts.first().right(parts.first().length() - 3).toInt();
1399 parts.removeFirst();
1400 if (typ=="mc" || typ=="bo")
1401 ti=ti->getBranchNum (n);
1405 ti=ti->getImageNum (n);
1411 TreeItem* VymModel::findID (const QString &s)
1414 for (int i=0; i<rootItem->branchCount(); i++)
1416 ti=rootItem->getBranchNum(i)->findID (s);
1422 //////////////////////////////////////////////
1424 //////////////////////////////////////////////
1425 void VymModel::setVersion (const QString &s)
1430 void VymModel::setAuthor (const QString &s)
1433 QString ("setMapAuthor (\"%1\")").arg(author),
1434 QString ("setMapAuthor (\"%1\")").arg(s),
1435 QString ("Set author of map to \"%1\"").arg(s)
1440 QString VymModel::getAuthor()
1445 void VymModel::setComment (const QString &s)
1448 QString ("setMapComment (\"%1\")").arg(comment),
1449 QString ("setMapComment (\"%1\")").arg(s),
1450 QString ("Set comment of map")
1455 QString VymModel::getComment ()
1460 QString VymModel::getDate ()
1462 return QDate::currentDate().toString ("yyyy-MM-dd");
1465 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1468 BranchItem *cur=NULL;
1469 BranchItem *prev=NULL;
1479 void VymModel::setHeading(const QString &s)
1481 BranchItem *selbi=getSelectedBranchItem();
1486 "setHeading (\""+selbi->getHeading()+"\")",
1488 "setHeading (\""+s+"\")",
1489 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1490 selbi->setHeading(s );
1491 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1494 emitSelectionChanged();
1498 BranchItem* VymModel::findText (QString s, bool cs)
1500 QTextDocument::FindFlags flags=0;
1501 if (cs) flags=QTextDocument::FindCaseSensitively;
1504 { // Nothing found or new find process
1506 // nothing found, start again
1510 next (findCurrent,findPrevious);
1512 bool searching=true;
1513 bool foundNote=false;
1514 while (searching && !EOFind)
1518 // Searching in Note
1519 if (findCurrent->getNote().contains(s,cs))
1521 select (findCurrent);
1523 if (getSelectedBranch()!=itFind)
1526 emitShowSelection();
1529 if (textEditor->findText(s,flags))
1535 // Searching in Heading
1536 if (searching && findCurrent->getHeading().contains (s,cs) )
1538 select(findCurrent);
1544 if (!next(findCurrent,findPrevious) )
1547 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1550 return getSelectedBranchItem();
1555 void VymModel::findReset()
1556 { // Necessary if text to find changes during a find process
1562 void VymModel::setScene (QGraphicsScene *s)
1564 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1565 //init(); // Here we have a mapScene set,
1566 // which is (still) needed to create MapCenters
1569 void VymModel::setURL(const QString &url)
1571 TreeItem *selti=getSelectedItem();
1574 QString oldurl=selti->getURL();
1575 selti->setURL (url);
1578 QString ("setURL (\"%1\")").arg(oldurl),
1580 QString ("setURL (\"%1\")").arg(url),
1581 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1584 emitDataHasChanged (selti);
1585 emitShowSelection();
1589 QString VymModel::getURL()
1591 TreeItem *selti=getSelectedItem();
1593 return selti->getURL();
1598 QStringList VymModel::getURLs()
1601 BranchItem *selbi=getSelectedBranchItem();
1602 BranchItem *cur=selbi;
1603 BranchItem *prev=NULL;
1606 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1607 cur=next (cur,prev,selbi);
1613 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1615 BranchItem *bi=getSelectedBranchItem();
1618 BranchObj *bo=(BranchObj*)(bi->getLMO());
1621 QString s=bo->getFrameTypeName();
1622 bo->setFrameType (t);
1623 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1624 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1626 bo->updateLinkGeometry();
1631 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1633 BranchItem *bi=getSelectedBranchItem();
1636 BranchObj *bo=(BranchObj*)(bi->getLMO());
1639 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1640 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1641 bo->setFrameType (s);
1643 bo->updateLinkGeometry();
1648 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1651 BranchItem *bi=getSelectedBranchItem();
1654 BranchObj *bo=(BranchObj*)(bi->getLMO());
1657 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1658 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1659 bo->setFramePenColor (c);
1664 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1666 BranchItem *bi=getSelectedBranchItem();
1669 BranchObj *bo=(BranchObj*)(bi->getLMO());
1672 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1673 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1674 bo->setFrameBrushColor (c);
1679 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1681 BranchItem *bi=getSelectedBranchItem();
1684 BranchObj *bo=(BranchObj*)(bi->getLMO());
1687 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1688 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1689 bo->setFramePadding (i);
1691 bo->updateLinkGeometry();
1696 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1698 BranchItem *bi=getSelectedBranchItem();
1701 BranchObj *bo=(BranchObj*)(bi->getLMO());
1704 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1705 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1706 bo->setFrameBorderWidth (i);
1708 bo->updateLinkGeometry();
1713 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1716 BranchItem *bi=getSelectedBranchItem();
1719 BranchObj *bo=bi->getLMO();
1722 QString u= b ? "false" : "true";
1723 QString r=!b ? "false" : "true";
1727 QString("setIncludeImagesVertically (%1)").arg(u),
1729 QString("setIncludeImagesVertically (%1)").arg(r),
1730 QString("Include images vertically in %1").arg(getObjectName(bo))
1732 bo->setIncludeImagesVer(b);
1738 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1741 TreeItem *bi=getSelectedBranchItem();
1744 BranchObj *bo=bi->getLMO();
1747 QString u= b ? "false" : "true";
1748 QString r=!b ? "false" : "true";
1752 QString("setIncludeImagesHorizontally (%1)").arg(u),
1754 QString("setIncludeImagesHorizontally (%1)").arg(r),
1755 QString("Include images horizontally in %1").arg(getObjectName(bo))
1757 bo->setIncludeImagesHor(b);
1764 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1766 TreeItem *ti=getSelectedItem();
1767 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1769 QString u= b ? "false" : "true";
1770 QString r=!b ? "false" : "true";
1774 QString("setHideLinkUnselected (%1)").arg(u),
1776 QString("setHideLinkUnselected (%1)").arg(r),
1777 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1779 ((MapItem*)ti)->setHideLinkUnselected(b);
1783 void VymModel::setHideExport(bool b)
1785 TreeItem *ti=getSelectedItem();
1787 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1789 ti->setHideInExport (b);
1790 QString u= b ? "false" : "true";
1791 QString r=!b ? "false" : "true";
1795 QString ("setHideExport (%1)").arg(u),
1797 QString ("setHideExport (%1)").arg(r),
1798 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1800 emitDataHasChanged(ti);
1801 emitSelectionChanged();
1804 // emitSelectionChanged();
1805 // FIXME-3 VM needed? scene()->update();
1809 void VymModel::toggleHideExport()
1811 TreeItem *selti=getSelectedItem();
1813 setHideExport ( !selti->hideInExport() );
1817 void VymModel::copy()
1819 TreeItem *selti=getSelectedItem();
1821 (selti->getType() == TreeItem::Branch ||
1822 selti->getType() == TreeItem::MapCenter ||
1823 selti->getType() == TreeItem::Image ))
1825 if (redosAvail == 0)
1828 QString s=getSelectString(selti);
1829 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1830 curClipboard=curStep;
1833 // Copy also to global clipboard, because we are at last step in history
1834 QString bakMapName(QString("history-%1").arg(curStep));
1835 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1836 copyDir (bakMapDir,clipboardDir );
1838 clipboardEmpty=false;
1844 void VymModel::pasteNoSave(const int &n)
1846 bool old=blockSaveState;
1847 blockSaveState=true;
1848 bool zippedOrg=zipped;
1849 if (redosAvail > 0 || n!=0)
1851 // Use the "historical" buffer
1852 QString bakMapName(QString("history-%1").arg(n));
1853 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1854 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1856 // Use the global buffer
1857 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1862 void VymModel::paste()
1864 BranchItem *selbi=getSelectedBranchItem();
1867 saveStateChangingPart(
1870 QString ("paste (%1)").arg(curClipboard),
1871 QString("Paste to %1").arg( getObjectName(selbi))
1878 void VymModel::cut()
1880 TreeItem *selti=getSelectedItem();
1881 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1889 void VymModel::moveUp()
1891 BranchItem *selbi=getSelectedBranchItem();
1894 if (!selbi->canMoveUp()) return;
1895 QString oldsel=getSelectString();
1896 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1898 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1902 void VymModel::moveDown()
1904 BranchItem *selbi=getSelectedBranchItem();
1907 if (!selbi->canMoveDown()) return;
1908 QString oldsel=getSelectString();
1909 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1911 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1915 void VymModel::sortChildren() // FIXME-2 not implemented yet
1918 BranchObj* bo=getSelectedBranch();
1921 if(treeItem->branchCount()>1)
1923 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1926 emitShowSelection();
1932 BranchItem* VymModel::createMapCenter()
1934 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1938 BranchItem* VymModel::createBranch(BranchItem *dst)
1941 return addNewBranchInt (dst,-2);
1946 ImageItem* VymModel::createImage(BranchItem *dst)
1953 QList<QVariant> cData;
1954 cData << "new" << "undef"<<"undef";
1956 ImageItem *newii=new ImageItem(cData) ;
1957 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1959 emit (layoutAboutToBeChanged() );
1962 n=dst->getRowNumAppend(newii);
1963 beginInsertRows (parix,n,n+1);
1964 dst->appendChild (newii);
1967 emit (layoutChanged() );
1969 // save scroll state. If scrolled, automatically select
1970 // new branch in order to tmp unscroll parent...
1971 newii->createMapObj(mapScene);
1978 BranchItem* VymModel::addMapCenter ()
1980 BranchItem *bi=addMapCenter (contextPos);
1982 emitShowSelection();
1987 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
1988 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
1993 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
1994 // createMapCenter could then probably be merged with createBranch
1998 QModelIndex parix=index(rootItem);
2000 int n=rootItem->branchCount();
2002 emit (layoutAboutToBeChanged() );
2003 beginInsertRows (parix,n,n+1);
2005 QList<QVariant> cData;
2006 cData << "VM:addMapCenter" << "undef"<<"undef";
2007 BranchItem *newbi=new BranchItem (cData);
2008 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2009 rootItem->appendChild (newbi);
2012 emit (layoutChanged() );
2015 newbi->setPositionMode (MapItem::Absolute);
2016 newbi->createMapObj(mapScene);
2021 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2023 // Depending on pos:
2024 // -3 insert in children of parent above selection
2025 // -2 add branch to selection
2026 // -1 insert in children of parent below selection
2027 // 0..n insert in children of parent at pos
2030 QList<QVariant> cData;
2031 cData << "new" << "undef"<<"undef";
2036 BranchItem *newbi=new BranchItem (cData);
2037 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2039 emit (layoutAboutToBeChanged() );
2045 n=parbi->getRowNumAppend (newbi);
2046 beginInsertRows (parix,n,n+1);
2047 parbi->appendChild (newbi);
2049 }else if (num==-1 || num==-3)
2051 // insert below selection
2052 parbi=(BranchItem*)dst->parent();
2055 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2056 beginInsertRows (parix,n,n);
2057 parbi->insertBranch(n,newbi);
2060 emit (layoutChanged() );
2062 // save scroll state. If scrolled, automatically select
2063 // new branch in order to tmp unscroll parent...
2064 newbi->createMapObj(mapScene);
2069 BranchItem* VymModel::addNewBranch(int pos)
2071 // Different meaning than num in addNewBranchInt!
2075 BranchItem *newbi=NULL;
2076 BranchItem *selbi=getSelectedBranchItem();
2080 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2082 newbi=addNewBranchInt (selbi,pos-2);
2090 QString ("addBranch (%1)").arg(pos),
2091 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2094 // emitSelectionChanged(); FIXME-3
2095 latestAddedItem=newbi;
2096 // In Network mode, the client needs to know where the new branch is,
2097 // so we have to pass on this information via saveState.
2098 // TODO: Get rid of this positioning workaround
2099 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2100 sendData ("selectLatestAdded ()");
2101 sendData (QString("move %1").arg(ps));
2110 BranchItem* VymModel::addNewBranchBefore()
2112 BranchItem *newbi=NULL;
2113 BranchItem *selbi=getSelectedBranchItem();
2114 if (selbi && selbi->getType()==TreeItem::Branch)
2115 // We accept no MapCenter here, so we _have_ a parent
2117 //QPointF p=bo->getRelPos();
2120 // add below selection
2121 newbi=addNewBranchInt (selbi,-1);
2125 //newbi->move2RelPos (p);
2127 // Move selection to new branch
2128 relinkBranch (selbi,newbi,0);
2130 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2131 QString ("Add branch before %1").arg(getObjectName(selbi)));
2133 // FIXME-3 needed? reposition();
2134 // emitSelectionChanged(); FIXME-3
2140 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2144 if (branch->depth()==0)
2146 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2148 emit (layoutAboutToBeChanged() );
2149 BranchItem *branchpi=(BranchItem*)branch->parent();
2150 // Remove at current position
2151 int n=branch->childNum();
2152 beginRemoveRows (index(branchpi),n,n);
2153 branchpi->removeChild (n);
2156 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2158 // Append as last branch to dst
2159 if (dst->branchCount()==0)
2162 n=dst->getFirstBranch()->childNumber();
2163 beginInsertRows (index(dst),n+pos,n+pos);
2164 dst->insertBranch (pos,branch);
2167 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2168 branch->updateStyles();
2170 emit (layoutChanged() );
2171 reposition(); // both for moveUp/Down and relinking
2178 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2182 emit (layoutAboutToBeChanged() );
2184 BranchItem *pi=(BranchItem*)(image->parent());
2185 QString oldParString=getSelectString (pi);
2186 // Remove at current position
2187 int n=image->childNum();
2188 beginRemoveRows (index(pi),n,n);
2189 pi->removeChild (n);
2193 QModelIndex dstix=index(dst);
2194 n=dst->getRowNumAppend (image);
2195 beginInsertRows (dstix,n,n+1);
2196 dst->appendChild (image);
2199 // Set new parent also for lmo
2200 if (image->getLMO() && dst->getLMO() )
2201 image->getLMO()->setParObj (dst->getLMO() );
2203 emit (layoutChanged() );
2206 QString("relinkTo (\"%1\")").arg(oldParString),
2208 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2209 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2215 void VymModel::deleteSelection()
2217 BranchItem *selbi=getSelectedBranchItem();
2219 if (selbi && selbi->isBranchLikeType() )
2222 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2224 TreeItem *pi=deleteItem (selbi);
2228 emitShowSelection();
2232 ImageItem *ii=getSelectedImageItem();
2235 BranchItem *pi=(BranchItem*)(ii->parent());
2236 saveStateChangingPart(
2240 QString("Delete %1").arg(getObjectName(ii))
2246 emitShowSelection();
2251 void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters
2254 BranchItem *selbi=getSelectedBranchItem();
2258 // Don't use this on mapcenter
2259 if (selbi->depth()<2) return;
2261 pi=(BranchItem*)(selbi->parent());
2262 // Check if we have childs at all to keep
2263 if (selbi->branchCount()==0)
2270 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2271 saveStateChangingPart(
2274 "deleteKeepChildren ()",
2275 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2278 QString sel=getSelectString(selbi);
2280 int pos=selbi->num();
2281 BranchItem *bi=selbi->getFirstBranch();
2284 relinkBranch (bi,pi,pos);
2285 bi=selbi->getFirstBranch();
2291 BranchObj *bo=getSelectedBranchObj();
2294 bo->move2RelPos (p);
2300 void VymModel::deleteChildren()
2303 BranchItem *selbi=getSelectedBranchItem();
2306 saveStateChangingPart(
2309 "deleteChildren ()",
2310 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2312 emit (layoutAboutToBeChanged() );
2314 QModelIndex ix=index (selbi);
2315 int n=selbi->branchCount()-1;
2316 beginRemoveRows (ix,0,n);
2317 removeRows (0,n+1,ix);
2319 emit (layoutChanged() );
2324 TreeItem* VymModel::deleteItem (TreeItem *ti)
2328 TreeItem *pi=ti->parent();
2329 QModelIndex parentIndex=index(pi);
2331 emit (layoutAboutToBeChanged() );
2333 int n=ti->childNum();
2334 beginRemoveRows (parentIndex,n,n);
2335 removeRows (n,1,parentIndex);
2339 emit (layoutChanged() );
2340 if (pi->depth()>0) return pi;
2345 bool VymModel::scrollBranch(BranchItem *bi)
2349 if (bi->isScrolled()) return false;
2350 if (bi->branchCount()==0) return false;
2351 if (bi->depth()==0) return false;
2352 if (bi->toggleScroll())
2359 QString ("%1 ()").arg(u),
2361 QString ("%1 ()").arg(r),
2362 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2364 emitDataHasChanged(bi);
2365 emitSelectionChanged();
2366 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2373 bool VymModel::unscrollBranch(BranchItem *bi)
2377 if (!bi->isScrolled()) return false;
2378 if (bi->branchCount()==0) return false;
2379 if (bi->depth()==0) return false;
2386 QString ("%1 ()").arg(u),
2388 QString ("%1 ()").arg(r),
2389 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2392 emitDataHasChanged(bi);
2393 emitSelectionChanged();
2395 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2401 void VymModel::toggleScroll()
2403 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2404 if (bi && bi->isBranchLikeType() )
2406 if (bi->isScrolled())
2407 unscrollBranch (bi);
2411 // saveState is called in above functions
2414 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2418 BranchObj *bo=getSelectedBranch();
2424 if (bo->isScrolled()) unscrollBranch (bo);
2431 void VymModel::emitExpandAll()
2433 emit (expandAll() );
2436 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2438 BranchItem *bi=getSelectedBranchItem();
2442 if (bi->isActiveStandardFlag(name))
2454 QString("%1 (\"%2\")").arg(u).arg(name),
2456 QString("%1 (\"%2\")").arg(r).arg(name),
2457 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2458 bi->toggleStandardFlag (name, master);
2460 emitSelectionChanged();
2464 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2467 BranchObj *bo=getSelectedBranch();
2470 FloatImageObj *fio=bo->addFloatImage();
2472 fio->setOriginalFilename("No original filename (image added by dropevent)");
2473 QString s=getSelectString(bo);
2474 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2475 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2477 // FIXME-3 VM needed? scene()->update();
2483 void VymModel::colorBranch (QColor c)
2485 BranchItem *selbi=getSelectedBranchItem();
2490 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2492 QString ("colorBranch (\"%1\")").arg(c.name()),
2493 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2495 selbi->setHeadingColor(c); // color branch
2499 void VymModel::colorSubtree (QColor c)
2501 BranchItem *selbi=getSelectedBranchItem();
2504 saveStateChangingPart(
2507 QString ("colorSubtree (\"%1\")").arg(c.name()),
2508 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2510 BranchItem *prev=NULL;
2511 BranchItem *cur=selbi;
2514 cur->setHeadingColor(c); // color links, color children
2515 cur=next (cur,prev,selbi);
2521 QColor VymModel::getCurrentHeadingColor()
2523 BranchItem *selbi=getSelectedBranchItem();
2524 if (selbi) return selbi->getHeadingColor();
2526 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2532 void VymModel::editURL()
2534 TreeItem *selti=getSelectedItem();
2538 QString text = QInputDialog::getText(
2539 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2540 selti->getURL(), &ok, NULL);
2542 // user entered something and pressed OK
2547 void VymModel::editLocalURL()
2549 TreeItem *selti=getSelectedItem();
2552 QStringList filters;
2553 filters <<"All files (*)";
2554 filters << tr("Text","Filedialog") + " (*.txt)";
2555 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2556 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2557 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2558 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2559 fd->setFilters (filters);
2560 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2561 fd->setDirectory (lastFileDir);
2562 if (! selti->getVymLink().isEmpty() )
2563 fd->selectFile( selti->getURL() );
2566 if ( fd->exec() == QDialog::Accepted )
2568 lastFileDir=QDir (fd->directory().path());
2569 setURL (fd->selectedFile() );
2575 void VymModel::editHeading2URL()
2577 TreeItem *selti=getSelectedItem();
2579 setURL (selti->getHeading());
2582 void VymModel::editBugzilla2URL()
2584 TreeItem *selti=getSelectedItem();
2587 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2592 void VymModel::editFATE2URL()
2594 TreeItem *selti=getSelectedItem();
2597 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2600 "setURL (\""+selti->getURL()+"\")",
2602 "setURL (\""+url+"\")",
2603 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2605 selti->setURL (url);
2606 // FIXME-4 updateActions();
2610 void VymModel::editVymLink()
2612 BranchItem *bi=getSelectedBranchItem();
2615 QStringList filters;
2616 filters <<"VYM map (*.vym)";
2617 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2618 fd->setFilters (filters);
2619 fd->setCaption(vymName+" - " +tr("Link to another map"));
2620 fd->setDirectory (lastFileDir);
2621 if (! bi->getVymLink().isEmpty() )
2622 fd->selectFile( bi->getVymLink() );
2626 if ( fd->exec() == QDialog::Accepted )
2628 lastFileDir=QDir (fd->directory().path());
2631 "setVymLink (\""+bi->getVymLink()+"\")",
2633 "setVymLink (\""+fd->selectedFile()+"\")",
2634 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2636 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2641 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2643 // Internal function, no saveState needed
2644 TreeItem *selti=getSelectedItem();
2647 selti->setVymLink(s);
2649 emitDataHasChanged (selti);
2650 emitShowSelection();
2654 void VymModel::deleteVymLink()
2656 BranchItem *bi=getSelectedBranchItem();
2661 "setVymLink (\""+bi->getVymLink()+"\")",
2663 "setVymLink (\"\")",
2664 QString("Unset vymlink of %1").arg(getObjectName(bi))
2666 bi->setVymLink ("" );
2672 QString VymModel::getVymLink()
2674 BranchItem *bi=getSelectedBranchItem();
2676 return bi->getVymLink();
2682 QStringList VymModel::getVymLinks()
2685 BranchItem *selbi=getSelectedBranchItem();
2686 BranchItem *cur=selbi;
2687 BranchItem *prev=NULL;
2690 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2691 cur=next (cur,prev,selbi);
2697 void VymModel::followXLink(int i) // FIXME-2
2701 BranchObj *bo=getSelectedBranch();
2704 bo=bo->XLinkTargetAt(i);
2707 selection.select(bo);
2708 emitShowSelection();
2714 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2718 BranchObj *bo=getSelectedBranch();
2721 XLinkObj *xlo=bo->XLinkAt(i);
2724 EditXLinkDialog dia;
2726 dia.setSelection(bo);
2727 if (dia.exec() == QDialog::Accepted)
2729 if (dia.useSettingsGlobal() )
2731 setMapDefXLinkColor (xlo->getColor() );
2732 setMapDefXLinkWidth (xlo->getWidth() );
2734 if (dia.deleteXLink())
2735 bo->deleteXLinkAt(i);
2746 //////////////////////////////////////////////
2748 //////////////////////////////////////////////
2750 void VymModel::parseAtom(const QString &atom)
2752 TreeItem* selti=getSelectedItem();
2753 BranchItem *selbi=getSelectedBranchItem();
2759 // Split string s into command and parameters
2760 parser.parseAtom (atom);
2761 QString com=parser.getCommand();
2763 // External commands
2764 /////////////////////////////////////////////////////////////////////
2765 if (com=="addBranch")
2769 parser.setError (Aborted,"Nothing selected");
2770 } else if (! selbi )
2772 parser.setError (Aborted,"Type of selection is not a branch");
2777 if (parser.checkParCount(pl))
2779 if (parser.parCount()==0)
2783 n=parser.parInt (ok,0);
2784 if (ok ) addNewBranch (n);
2788 /////////////////////////////////////////////////////////////////////
2789 } else if (com=="addBranchBefore")
2793 parser.setError (Aborted,"Nothing selected");
2794 } else if (! selbi )
2796 parser.setError (Aborted,"Type of selection is not a branch");
2799 if (parser.parCount()==0)
2801 addNewBranchBefore ();
2804 /////////////////////////////////////////////////////////////////////
2805 } else if (com==QString("addMapCenter"))
2807 if (parser.checkParCount(2))
2809 x=parser.parDouble (ok,0);
2812 y=parser.parDouble (ok,1);
2813 if (ok) addMapCenter (QPointF(x,y));
2816 /////////////////////////////////////////////////////////////////////
2817 } else if (com==QString("addMapReplace"))
2821 parser.setError (Aborted,"Nothing selected");
2822 } else if (! selbi )
2824 parser.setError (Aborted,"Type of selection is not a branch");
2825 } else if (parser.checkParCount(1))
2827 //s=parser.parString (ok,0); // selection
2828 t=parser.parString (ok,0); // path to map
2829 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2830 addMapReplaceInt(getSelectString(selbi),t);
2832 /////////////////////////////////////////////////////////////////////
2833 } else if (com==QString("addMapInsert"))
2837 parser.setError (Aborted,"Nothing selected");
2838 } else if (! selbi )
2840 parser.setError (Aborted,"Type of selection is not a branch");
2843 if (parser.checkParCount(2))
2845 t=parser.parString (ok,0); // path to map
2846 n=parser.parInt(ok,1); // position
2847 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2848 addMapInsertInt(t,n);
2851 /////////////////////////////////////////////////////////////////////
2852 } else if (com=="clearFlags")
2856 parser.setError (Aborted,"Nothing selected");
2857 } else if (! selbi )
2859 parser.setError (Aborted,"Type of selection is not a branch");
2860 } else if (parser.checkParCount(0))
2862 selbi->deactivateAllStandardFlags();
2864 /////////////////////////////////////////////////////////////////////
2865 } else if (com=="colorBranch")
2869 parser.setError (Aborted,"Nothing selected");
2870 } else if (! selbi )
2872 parser.setError (Aborted,"Type of selection is not a branch");
2873 } else if (parser.checkParCount(1))
2875 QColor c=parser.parColor (ok,0);
2876 if (ok) colorBranch (c);
2878 /////////////////////////////////////////////////////////////////////
2879 } else if (com=="colorSubtree")
2883 parser.setError (Aborted,"Nothing selected");
2884 } else if (! selbi )
2886 parser.setError (Aborted,"Type of selection is not a branch");
2887 } else if (parser.checkParCount(1))
2889 QColor c=parser.parColor (ok,0);
2890 if (ok) colorSubtree (c);
2892 /////////////////////////////////////////////////////////////////////
2893 } else if (com=="copy")
2897 parser.setError (Aborted,"Nothing selected");
2898 } else if ( selectionType()!=TreeItem::Branch &&
2899 selectionType()!=TreeItem::MapCenter &&
2900 selectionType()!=TreeItem::Image )
2902 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2903 } else if (parser.checkParCount(0))
2907 /////////////////////////////////////////////////////////////////////
2908 } else if (com=="cut")
2912 parser.setError (Aborted,"Nothing selected");
2913 } else if ( selectionType()!=TreeItem::Branch &&
2914 selectionType()!=TreeItem::MapCenter &&
2915 selectionType()!=TreeItem::Image )
2917 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2918 } else if (parser.checkParCount(0))
2922 /////////////////////////////////////////////////////////////////////
2923 } else if (com=="delete")
2927 parser.setError (Aborted,"Nothing selected");
2929 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2931 parser.setError (Aborted,"Type of selection is wrong.");
2934 else if (parser.checkParCount(0))
2938 /////////////////////////////////////////////////////////////////////
2939 } else if (com=="deleteKeepChildren")
2943 parser.setError (Aborted,"Nothing selected");
2944 } else if (! selbi )
2946 parser.setError (Aborted,"Type of selection is not a branch");
2947 } else if (parser.checkParCount(0))
2949 deleteKeepChildren();
2951 /////////////////////////////////////////////////////////////////////
2952 } else if (com=="deleteChildren")
2956 parser.setError (Aborted,"Nothing selected");
2959 parser.setError (Aborted,"Type of selection is not a branch");
2960 } else if (parser.checkParCount(0))
2964 /////////////////////////////////////////////////////////////////////
2965 } else if (com=="exportASCII")
2969 if (parser.parCount()>=1)
2970 // Hey, we even have a filename
2971 fname=parser.parString(ok,0);
2974 parser.setError (Aborted,"Could not read filename");
2977 exportASCII (fname,false);
2979 /////////////////////////////////////////////////////////////////////
2980 } else if (com=="exportImage")
2984 if (parser.parCount()>=2)
2985 // Hey, we even have a filename
2986 fname=parser.parString(ok,0);
2989 parser.setError (Aborted,"Could not read filename");
2992 QString format="PNG";
2993 if (parser.parCount()>=2)
2995 format=parser.parString(ok,1);
2997 exportImage (fname,false,format);
2999 /////////////////////////////////////////////////////////////////////
3000 } else if (com=="exportXHTML")
3004 if (parser.parCount()>=2)
3005 // Hey, we even have a filename
3006 fname=parser.parString(ok,1);
3009 parser.setError (Aborted,"Could not read filename");
3012 exportXHTML (fname,false);
3014 /////////////////////////////////////////////////////////////////////
3015 } else if (com=="exportXML")
3019 if (parser.parCount()>=2)
3020 // Hey, we even have a filename
3021 fname=parser.parString(ok,1);
3024 parser.setError (Aborted,"Could not read filename");
3027 exportXML (fname,false);
3029 /////////////////////////////////////////////////////////////////////
3030 } else if (com=="importDir")
3034 parser.setError (Aborted,"Nothing selected");
3035 } else if (! selbi )
3037 parser.setError (Aborted,"Type of selection is not a branch");
3038 } else if (parser.checkParCount(1))
3040 s=parser.parString(ok,0);
3041 if (ok) importDirInt(s);
3043 /////////////////////////////////////////////////////////////////////
3044 } else if (com=="relinkTo")
3048 parser.setError (Aborted,"Nothing selected");
3051 if (parser.checkParCount(4))
3053 // 0 selectstring of parent
3054 // 1 num in parent (for branches)
3055 // 2,3 x,y of mainbranch or mapcenter
3056 s=parser.parString(ok,0);
3057 TreeItem *dst=findBySelectString (s);
3060 if (dst->getType()==TreeItem::Branch)
3062 // Get number in parent
3063 n=parser.parInt (ok,1);
3066 relinkBranch (selbi,(BranchItem*)dst,n);
3067 emitSelectionChanged();
3069 } else if (dst->getType()==TreeItem::MapCenter)
3071 relinkBranch (selbi,(BranchItem*)dst);
3072 // Get coordinates of mainbranch
3073 x=parser.parDouble(ok,2);
3076 y=parser.parDouble(ok,3);
3079 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3080 emitSelectionChanged();
3086 } else if ( selti->getType() == TreeItem::Image)
3088 if (parser.checkParCount(1))
3090 // 0 selectstring of parent
3091 s=parser.parString(ok,0);
3092 TreeItem *dst=findBySelectString (s);
3095 if (dst->isBranchLikeType())
3096 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3098 parser.setError (Aborted,"Destination is not a branch");
3101 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3102 /////////////////////////////////////////////////////////////////////
3103 } else if (com=="loadImage")
3107 parser.setError (Aborted,"Nothing selected");
3108 } else if (! selbi )
3110 parser.setError (Aborted,"Type of selection is not a branch");
3111 } else if (parser.checkParCount(1))
3113 s=parser.parString(ok,0);
3114 if (ok) loadFloatImageInt (selbi,s);
3116 /////////////////////////////////////////////////////////////////////
3117 } else if (com=="moveUp")
3121 parser.setError (Aborted,"Nothing selected");
3122 } else if (! selbi )
3124 parser.setError (Aborted,"Type of selection is not a branch");
3125 } else if (parser.checkParCount(0))
3129 /////////////////////////////////////////////////////////////////////
3130 } else if (com=="moveDown")
3134 parser.setError (Aborted,"Nothing selected");
3135 } else if (! selbi )
3137 parser.setError (Aborted,"Type of selection is not a branch");
3138 } else if (parser.checkParCount(0))
3142 /////////////////////////////////////////////////////////////////////
3143 } else if (com=="move")
3147 parser.setError (Aborted,"Nothing selected");
3148 } else if ( selectionType()!=TreeItem::Branch &&
3149 selectionType()!=TreeItem::MapCenter &&
3150 selectionType()!=TreeItem::Image )
3152 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3153 } else if (parser.checkParCount(2))
3155 x=parser.parDouble (ok,0);
3158 y=parser.parDouble (ok,1);
3162 /////////////////////////////////////////////////////////////////////
3163 } else if (com=="moveRel")
3167 parser.setError (Aborted,"Nothing selected");
3168 } else if ( selectionType()!=TreeItem::Branch &&
3169 selectionType()!=TreeItem::MapCenter &&
3170 selectionType()!=TreeItem::Image )
3172 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3173 } else if (parser.checkParCount(2))
3175 x=parser.parDouble (ok,0);
3178 y=parser.parDouble (ok,1);
3179 if (ok) moveRel (x,y);
3182 /////////////////////////////////////////////////////////////////////
3183 } else if (com=="nop")
3185 /////////////////////////////////////////////////////////////////////
3186 } else if (com=="paste")
3190 parser.setError (Aborted,"Nothing selected");
3191 } else if (! selbi )
3193 parser.setError (Aborted,"Type of selection is not a branch");
3194 } else if (parser.checkParCount(1))
3196 n=parser.parInt (ok,0);
3197 if (ok) pasteNoSave(n);
3199 /////////////////////////////////////////////////////////////////////
3200 } else if (com=="qa")
3204 parser.setError (Aborted,"Nothing selected");
3205 } else if (! selbi )
3207 parser.setError (Aborted,"Type of selection is not a branch");
3208 } else if (parser.checkParCount(4))
3211 c=parser.parString (ok,0);
3214 parser.setError (Aborted,"No comment given");
3217 s=parser.parString (ok,1);
3220 parser.setError (Aborted,"First parameter is not a string");
3223 t=parser.parString (ok,2);
3226 parser.setError (Aborted,"Condition is not a string");
3229 u=parser.parString (ok,3);
3232 parser.setError (Aborted,"Third parameter is not a string");
3237 parser.setError (Aborted,"Unknown type: "+s);
3242 parser.setError (Aborted,"Unknown operator: "+t);
3247 parser.setError (Aborted,"Type of selection is not a branch");
3250 if (selbi->getHeading() == u)
3252 cout << "PASSED: " << qPrintable (c) << endl;
3255 cout << "FAILED: " << qPrintable (c) << endl;
3265 /////////////////////////////////////////////////////////////////////
3266 } else if (com=="saveImage")
3268 ImageItem *ii=getSelectedImageItem();
3271 parser.setError (Aborted,"No image selected");
3272 } else if (parser.checkParCount(2))
3274 s=parser.parString(ok,0);
3277 t=parser.parString(ok,1);
3278 if (ok) saveFloatImageInt (ii,t,s);
3281 /////////////////////////////////////////////////////////////////////
3282 } else if (com=="scroll")
3286 parser.setError (Aborted,"Nothing selected");
3287 } else if (! selbi )
3289 parser.setError (Aborted,"Type of selection is not a branch");
3290 } else if (parser.checkParCount(0))
3292 if (!scrollBranch (selbi))
3293 parser.setError (Aborted,"Could not scroll branch");
3295 /////////////////////////////////////////////////////////////////////
3296 } else if (com=="select")
3298 if (parser.checkParCount(1))
3300 s=parser.parString(ok,0);
3303 /////////////////////////////////////////////////////////////////////
3304 } else if (com=="selectLastBranch")
3308 parser.setError (Aborted,"Nothing selected");
3309 } else if (! selbi )
3311 parser.setError (Aborted,"Type of selection is not a branch");
3312 } else if (parser.checkParCount(0))
3314 BranchItem *bi=selbi->getLastBranch();
3316 parser.setError (Aborted,"Could not select last branch");
3317 select (bi); // FIXME-3 was selectInt
3320 /////////////////////////////////////////////////////////////////////
3321 } else /* FIXME-2 if (com=="selectLastImage")
3325 parser.setError (Aborted,"Nothing selected");
3326 } else if (! selbi )
3328 parser.setError (Aborted,"Type of selection is not a branch");
3329 } else if (parser.checkParCount(0))
3331 FloatImageObj *fio=selb->getLastFloatImage();
3333 parser.setError (Aborted,"Could not select last image");
3334 select (fio); // FIXME-3 was selectInt
3337 /////////////////////////////////////////////////////////////////////
3338 } else */ if (com=="selectLatestAdded")
3340 if (!latestAddedItem)
3342 parser.setError (Aborted,"No latest added object");
3345 if (!select (latestAddedItem))
3346 parser.setError (Aborted,"Could not select latest added object ");
3348 /////////////////////////////////////////////////////////////////////
3349 } else if (com=="setFrameType")
3351 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3353 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3355 else if (parser.checkParCount(1))
3357 s=parser.parString(ok,0);
3358 if (ok) setFrameType (s);
3360 /////////////////////////////////////////////////////////////////////
3361 } else if (com=="setFramePenColor")
3363 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3365 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3367 else if (parser.checkParCount(1))
3369 QColor c=parser.parColor(ok,0);
3370 if (ok) setFramePenColor (c);
3372 /////////////////////////////////////////////////////////////////////
3373 } else if (com=="setFrameBrushColor")
3375 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3377 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3379 else if (parser.checkParCount(1))
3381 QColor c=parser.parColor(ok,0);
3382 if (ok) setFrameBrushColor (c);
3384 /////////////////////////////////////////////////////////////////////
3385 } else if (com=="setFramePadding")
3387 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3389 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3391 else if (parser.checkParCount(1))
3393 n=parser.parInt(ok,0);
3394 if (ok) setFramePadding(n);
3396 /////////////////////////////////////////////////////////////////////
3397 } else if (com=="setFrameBorderWidth")
3399 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3401 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3403 else if (parser.checkParCount(1))
3405 n=parser.parInt(ok,0);
3406 if (ok) setFrameBorderWidth (n);
3408 /////////////////////////////////////////////////////////////////////
3409 } else if (com=="setMapAuthor")
3411 if (parser.checkParCount(1))
3413 s=parser.parString(ok,0);
3414 if (ok) setAuthor (s);
3416 /////////////////////////////////////////////////////////////////////
3417 } else if (com=="setMapComment")
3419 if (parser.checkParCount(1))
3421 s=parser.parString(ok,0);
3422 if (ok) setComment(s);
3424 /////////////////////////////////////////////////////////////////////
3425 } else if (com=="setMapBackgroundColor")
3429 parser.setError (Aborted,"Nothing selected");
3430 } else if (! selbi )
3432 parser.setError (Aborted,"Type of selection is not a branch");
3433 } else if (parser.checkParCount(1))
3435 QColor c=parser.parColor (ok,0);
3436 if (ok) setMapBackgroundColor (c);
3438 /////////////////////////////////////////////////////////////////////
3439 } else if (com=="setMapDefLinkColor")
3443 parser.setError (Aborted,"Nothing selected");
3444 } else if (! selbi )
3446 parser.setError (Aborted,"Type of selection is not a branch");
3447 } else if (parser.checkParCount(1))
3449 QColor c=parser.parColor (ok,0);
3450 if (ok) setMapDefLinkColor (c);
3452 /////////////////////////////////////////////////////////////////////
3453 } else if (com=="setMapLinkStyle")
3455 if (parser.checkParCount(1))
3457 s=parser.parString (ok,0);
3458 if (ok) setMapLinkStyle(s);
3460 /////////////////////////////////////////////////////////////////////
3461 } else if (com=="setHeading")
3465 parser.setError (Aborted,"Nothing selected");
3466 } else if (! selbi )
3468 parser.setError (Aborted,"Type of selection is not a branch");
3469 } else if (parser.checkParCount(1))
3471 s=parser.parString (ok,0);
3475 /////////////////////////////////////////////////////////////////////
3476 } else if (com=="setHideExport")
3480 parser.setError (Aborted,"Nothing selected");
3481 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3483 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3484 } else if (parser.checkParCount(1))
3486 b=parser.parBool(ok,0);
3487 if (ok) setHideExport (b);
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="setIncludeImagesHorizontally")
3494 parser.setError (Aborted,"Nothing selected");
3497 parser.setError (Aborted,"Type of selection is not a branch");
3498 } else if (parser.checkParCount(1))
3500 b=parser.parBool(ok,0);
3501 if (ok) setIncludeImagesHor(b);
3503 /////////////////////////////////////////////////////////////////////
3504 } else if (com=="setIncludeImagesVertically")
3508 parser.setError (Aborted,"Nothing selected");
3511 parser.setError (Aborted,"Type of selection is not a branch");
3512 } else if (parser.checkParCount(1))
3514 b=parser.parBool(ok,0);
3515 if (ok) setIncludeImagesVer(b);
3517 /////////////////////////////////////////////////////////////////////
3518 } else if (com=="setHideLinkUnselected")
3522 parser.setError (Aborted,"Nothing selected");
3523 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3525 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3526 } else if (parser.checkParCount(1))
3528 b=parser.parBool(ok,0);
3529 if (ok) setHideLinkUnselected(b);
3531 /////////////////////////////////////////////////////////////////////
3532 } else if (com=="setSelectionColor")
3534 if (parser.checkParCount(1))
3536 QColor c=parser.parColor (ok,0);
3537 if (ok) setSelectionColorInt (c);
3539 /////////////////////////////////////////////////////////////////////
3540 } else if (com=="setURL")
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 s=parser.parString (ok,0);
3553 /////////////////////////////////////////////////////////////////////
3554 } else if (com=="setVymLink")
3558 parser.setError (Aborted,"Nothing selected");
3559 } else if (! selbi )
3561 parser.setError (Aborted,"Type of selection is not a branch");
3562 } else if (parser.checkParCount(1))
3564 s=parser.parString (ok,0);
3565 if (ok) setVymLink(s);
3568 /////////////////////////////////////////////////////////////////////
3569 else if (com=="setFlag")
3573 parser.setError (Aborted,"Nothing selected");
3574 } else if (! selbi )
3576 parser.setError (Aborted,"Type of selection is not a branch");
3577 } else if (parser.checkParCount(1))
3579 s=parser.parString(ok,0);
3581 selbi->activateStandardFlag(s);
3583 /////////////////////////////////////////////////////////////////////
3584 } else /* FIXME-2 if (com=="setFrameType")
3588 parser.setError (Aborted,"Nothing selected");
3591 parser.setError (Aborted,"Type of selection is not a branch");
3592 } else if (parser.checkParCount(1))
3594 s=parser.parString(ok,0);
3598 /////////////////////////////////////////////////////////////////////
3599 } else*/ if (com=="sortChildren")
3603 parser.setError (Aborted,"Nothing selected");
3604 } else if (! selbi )
3606 parser.setError (Aborted,"Type of selection is not a branch");
3607 } else if (parser.checkParCount(0))
3611 /////////////////////////////////////////////////////////////////////
3612 } else if (com=="toggleFlag")
3616 parser.setError (Aborted,"Nothing selected");
3617 } else if (! selbi )
3619 parser.setError (Aborted,"Type of selection is not a branch");
3620 } else if (parser.checkParCount(1))
3622 s=parser.parString(ok,0);
3624 selbi->toggleStandardFlag(s);
3626 /////////////////////////////////////////////////////////////////////
3627 } else if (com=="unscroll")
3631 parser.setError (Aborted,"Nothing selected");
3632 } else if (! selbi )
3634 parser.setError (Aborted,"Type of selection is not a branch");
3635 } else if (parser.checkParCount(0))
3637 if (!unscrollBranch (selbi))
3638 parser.setError (Aborted,"Could not unscroll branch");
3640 /////////////////////////////////////////////////////////////////////
3641 } else if (com=="unscrollChildren")
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(0))
3651 unscrollChildren ();
3653 /////////////////////////////////////////////////////////////////////
3654 } else if (com=="unsetFlag")
3658 parser.setError (Aborted,"Nothing selected");
3659 } else if (! selbi )
3661 parser.setError (Aborted,"Type of selection is not a branch");
3662 } else if (parser.checkParCount(1))
3664 s=parser.parString(ok,0);
3666 selbi->deactivateStandardFlag(s);
3669 parser.setError (Aborted,"Unknown command");
3672 if (parser.errorLevel()==NoError)
3674 // setChanged(); FIXME-2 should not be called e.g. for export?!
3679 // TODO Error handling
3680 qWarning("VymModel::parseAtom: Error!");
3681 qWarning(parser.errorMessage());
3685 void VymModel::runScript (QString script)
3687 parser.setScript (script);
3689 while (parser.next() )
3690 parseAtom(parser.getAtom());
3693 void VymModel::setExportMode (bool b)
3695 // should be called before and after exports
3696 // depending on the settings
3697 if (b && settings.value("/export/useHideExport","true")=="true")
3698 setHideTmpMode (TreeItem::HideExport);
3700 setHideTmpMode (TreeItem::HideNone);
3703 void VymModel::exportImage(QString fname, bool askName, QString format)
3707 fname=getMapName()+".png";
3714 QFileDialog *fd=new QFileDialog (NULL);
3715 fd->setCaption (tr("Export map as image"));
3716 fd->setDirectory (lastImageDir);
3717 fd->setFileMode(QFileDialog::AnyFile);
3718 fd->setFilters (imageIO.getFilters() );
3721 fl=fd->selectedFiles();
3723 format=imageIO.getType(fd->selectedFilter());
3727 setExportMode (true);
3728 QPixmap pix (getPixmap());
3729 pix.save(fname, format);
3730 setExportMode (false);
3734 void VymModel::exportXML(QString dir, bool askForName)
3738 dir=browseDirectory(NULL,tr("Export XML to directory"));
3739 if (dir =="" && !reallyWriteDirectory(dir) )
3743 // Hide stuff during export, if settings want this
3744 setExportMode (true);
3746 // Create subdirectories
3749 // write to directory
3750 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3753 file.setName ( dir + "/"+mapName+".xml");
3754 if ( !file.open( QIODevice::WriteOnly ) )
3756 // This should neverever happen
3757 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3761 // Write it finally, and write in UTF8, no matter what
3762 QTextStream ts( &file );
3763 ts.setEncoding (QTextStream::UnicodeUTF8);
3767 // Now write image, too
3768 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3770 setExportMode (false);
3773 void VymModel::exportASCII(QString fname,bool askName)
3778 ex.setFile (mapName+".txt");
3784 //ex.addFilter ("TXT (*.txt)");
3785 ex.setDir(lastImageDir);
3786 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3791 setExportMode(true);
3793 setExportMode(false);
3797 void VymModel::exportXHTML (const QString &dir, bool askForName)
3799 ExportXHTMLDialog dia(NULL);
3800 dia.setFilePath (filePath );
3801 dia.setMapName (mapName );
3803 if (dir!="") dia.setDir (dir);
3809 if (dia.exec()!=QDialog::Accepted)
3813 QDir d (dia.getDir());
3814 // Check, if warnings should be used before overwriting
3815 // the output directory
3816 if (d.exists() && d.count()>0)
3819 warn.showCancelButton (true);
3820 warn.setText(QString(
3821 "The directory %1 is not empty.\n"
3822 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3823 warn.setCaption("Warning: Directory not empty");
3824 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3826 if (warn.exec()!=QDialog::Accepted) ok=false;
3833 exportXML (dia.getDir(),false );
3834 dia.doExport(mapName );
3835 //if (dia.hasChanged()) setChanged();
3839 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3844 if (ex.setConfigFile(cf))
3846 setExportMode (true);
3847 ex.exportPresentation();
3848 setExportMode (false);
3855 //////////////////////////////////////////////
3857 //////////////////////////////////////////////
3859 void VymModel::registerEditor(QWidget *me)
3861 mapEditor=(MapEditor*)me;
3864 void VymModel::unregisterEditor(QWidget *)
3869 void VymModel::setContextPos(QPointF p)
3874 void VymModel::unsetContextPos()
3876 contextPos=QPointF();
3879 void VymModel::updateNoteFlag()
3882 TreeItem *selti=getSelectedItem();
3885 if (textEditor->isEmpty())
3888 selti->setNote (textEditor->getText());
3889 emitDataHasChanged(selti);
3890 emitSelectionChanged();
3895 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3898 for (int i=0; i<rootItem->branchCount(); i++)
3899 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3902 void MapCenterObj::updateRelPositions()
3904 if (repositionRequest) unsetAllRepositionRequests();
3906 // update relative Positions of branches and floats
3907 for (int i=0; i<treeItem->branchCount(); ++i)
3909 treeItem->getBranchObjNum(i)->setRelPos();
3910 treeItem->getBranchObjNum(i)->setOrientation();
3913 for (int i=0; i<floatimage.size(); ++i)
3914 floatimage.at(i)->setRelPos();
3916 if (repositionRequest) reposition();
3921 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3923 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3924 if (blockReposition) return;
3926 for (int i=0;i<rootItem->branchCount(); i++)
3927 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3931 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3933 return QPolygonF ();
3934 // Creating (arbitrary) shapes
3937 QRectF rb=bo->getBBox();
3938 if (bo->getDepth()==0)
3940 // Just take BBox of this mapCenter
3941 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3945 // Take union of BBox and TotalBBox
3947 QRectF ra=bo->getTotalBBox();
3948 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3951 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3954 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3956 p <<ra.bottomRight()
3958 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3961 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3967 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3971 // Move all branches and MapCenters away from lmo
3972 // to avoid collisions
3977 BranchObj *boA=(BranchObj*)lmo;
3979 for (int i=0; i<rootItem->branchCount(); i++)
3981 boB=rootItem->getBranchNum(i);
3984 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3987 <<" ("<<qPrintable(boA->getHeading() )<<")"
3988 <<" with ("<< qPrintable (boB->getHeading() )
3991 <<" minT="<<r.minTranslation<<endl<<endl;
3996 QPixmap VymModel::getPixmap()
3998 QRectF mapRect=getTotalBBox();
3999 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
4002 pp.setRenderHints(mapEditor->renderHints());
4004 // Don't print the visualisation of selection
4007 mapScene->render ( &pp,
4008 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
4009 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
4011 // Restore selection
4018 void VymModel::setMapLinkStyle (const QString & s)
4023 case LinkableMapObj::Line :
4026 case LinkableMapObj::Parabel:
4027 snow="StyleParabel";
4029 case LinkableMapObj::PolyLine:
4030 snow="StylePolyLine";
4032 case LinkableMapObj::PolyParabel:
4033 snow="StylePolyParabel";
4036 snow="UndefinedStyle";
4041 QString("setMapLinkStyle (\"%1\")").arg(s),
4042 QString("setMapLinkStyle (\"%1\")").arg(snow),
4043 QString("Set map link style (\"%1\")").arg(s)
4047 linkstyle=LinkableMapObj::Line;
4048 else if (s=="StyleParabel")
4049 linkstyle=LinkableMapObj::Parabel;
4050 else if (s=="StylePolyLine")
4051 linkstyle=LinkableMapObj::PolyLine;
4052 else if (s=="StylePolyParabel")
4053 linkstyle=LinkableMapObj::PolyParabel;
4055 linkstyle=LinkableMapObj::UndefinedStyle;
4057 BranchItem *cur=NULL;
4058 BranchItem *prev=NULL;
4063 bo=(BranchObj*)(cur->getLMO() );
4064 bo->setLinkStyle(bo->getDefLinkStyle());
4070 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4075 void VymModel::setMapDefLinkColor(QColor col)
4077 if ( !col.isValid() ) return;
4079 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4080 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4081 QString("Set map link color to %1").arg(col.name())
4085 BranchItem *cur=NULL;
4086 BranchItem *prev=NULL;
4091 bo=(BranchObj*)(cur->getLMO() );
4098 void VymModel::setMapLinkColorHintInt()
4100 // called from setMapLinkColorHint(lch) or at end of parse
4101 BranchItem *cur=NULL;
4102 BranchItem *prev=NULL;
4107 bo=(BranchObj*)(cur->getLMO() );
4113 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4116 setMapLinkColorHintInt();
4119 void VymModel::toggleMapLinkColorHint()
4121 if (linkcolorhint==LinkableMapObj::HeadingColor)
4122 linkcolorhint=LinkableMapObj::DefaultColor;
4124 linkcolorhint=LinkableMapObj::HeadingColor;
4125 BranchItem *cur=NULL;
4126 BranchItem *prev=NULL;
4131 bo=(BranchObj*)(cur->getLMO() );
4137 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4139 Q3FileDialog *fd=new Q3FileDialog( NULL);
4140 fd->setMode (Q3FileDialog::ExistingFile);
4141 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4142 ImagePreview *p =new ImagePreview (fd);
4143 fd->setContentsPreviewEnabled( TRUE );
4144 fd->setContentsPreview( p, p );
4145 fd->setPreviewMode( Q3FileDialog::Contents );
4146 fd->setCaption(vymName+" - " +tr("Load background image"));
4147 fd->setDir (lastImageDir);
4150 if ( fd->exec() == QDialog::Accepted )
4152 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4153 lastImageDir=QDir (fd->dirPath());
4154 setMapBackgroundImage (fd->selectedFile());
4158 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4160 QColor oldcol=mapScene->backgroundBrush().color();
4164 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4166 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4167 QString("Set background color of map to %1").arg(col.name()));
4170 brush.setTextureImage (QPixmap (fn));
4171 mapScene->setBackgroundBrush(brush);
4174 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4176 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4177 if ( !col.isValid() ) return;
4178 setMapBackgroundColor( col );
4182 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4184 QColor oldcol=mapScene->backgroundBrush().color();
4186 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4187 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4188 QString("Set background color of map to %1").arg(col.name()));
4189 mapScene->setBackgroundBrush(col);
4192 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4194 return mapScene->backgroundBrush().color();
4198 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4200 return linkcolorhint;
4203 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4205 return defLinkColor;
4208 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4213 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4215 return defXLinkColor;
4218 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4223 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4225 return defXLinkWidth;
4228 void VymModel::move(const double &x, const double &y) // FIXME-3
4232 BranchObj *bo = getSelectedBranch();
4234 (selectionType()==TreeItem::Branch ||
4235 selectionType()==TreeItem::MapCenter ||
4236 selectionType()==TreeItem::Image
4239 QPointF ap(bo->getAbsPos());
4243 QString ps=qpointfToString(ap);
4244 QString s=getSelectString();
4247 s, "move "+qpointfToString(to),
4248 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4251 emitSelectionChanged();
4257 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4261 BranchObj *bo = getSelectedBranch();
4263 (selectionType()==TreeItem::Branch ||
4264 selectionType()==TreeItem::MapCenter ||
4265 selectionType()==TreeItem::Image
4269 QPointF rp(bo->getRelPos());
4273 QString ps=qpointfToString (bo->getRelPos());
4274 QString s=getSelectString(bo);
4277 s, "moveRel "+qpointfToString(to),
4278 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4279 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4281 bo->updateLinkGeometry();
4282 emitSelectionChanged();
4289 void VymModel::animate()
4291 animationTimer->stop();
4294 while (i<animObjList.size() )
4296 bo=(BranchObj*)animObjList.at(i);
4301 animObjList.removeAt(i);
4308 QItemSelection sel=selModel->selection();
4309 emit (selectionChanged(sel,sel));
4312 if (!animObjList.isEmpty()) animationTimer->start();
4316 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4318 if (bo && bo->getTreeItem()->depth()>0)
4321 ap.setStart (start);
4323 ap.setTicks (animationTicks);
4324 ap.setAnimated (true);
4325 bo->setAnimation (ap);
4326 animObjList.append( bo );
4327 animationTimer->setSingleShot (true);
4328 animationTimer->start(animationInterval);
4332 void VymModel::stopAnimation (MapObj *mo)
4334 int i=animObjList.indexOf(mo);
4336 animObjList.removeAt (i);
4339 void VymModel::sendSelection()
4341 if (netstate!=Server) return;
4342 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4345 void VymModel::newServer()
4349 tcpServer = new QTcpServer(this);
4350 if (!tcpServer->listen(QHostAddress::Any,port)) {
4351 QMessageBox::critical(NULL, "vym server",
4352 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4353 //FIXME-3 needed? we are no widget any longer... close();
4356 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4358 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4361 void VymModel::connectToServer()
4364 server="salam.suse.de";
4366 clientSocket = new QTcpSocket (this);
4367 clientSocket->abort();
4368 clientSocket->connectToHost(server ,port);
4369 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4370 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4371 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4373 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4378 void VymModel::newClient()
4380 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4381 connect(newClient, SIGNAL(disconnected()),
4382 newClient, SLOT(deleteLater()));
4384 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4386 clientList.append (newClient);
4390 void VymModel::sendData(const QString &s)
4392 if (clientList.size()==0) return;
4394 // Create bytearray to send
4396 QDataStream out(&block, QIODevice::WriteOnly);
4397 out.setVersion(QDataStream::Qt_4_0);
4399 // Reserve some space for blocksize
4402 // Write sendCounter
4403 out << sendCounter++;
4408 // Go back and write blocksize so far
4409 out.device()->seek(0);
4410 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4414 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4416 for (int i=0; i<clientList.size(); ++i)
4418 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4419 clientList.at(i)->write (block);
4423 void VymModel::readData ()
4425 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4428 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4432 QDataStream in(clientSocket);
4433 in.setVersion(QDataStream::Qt_4_0);
4441 cout << " t="<<qPrintable (t)<<endl;
4447 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4449 switch (socketError) {
4450 case QAbstractSocket::RemoteHostClosedError:
4452 case QAbstractSocket::HostNotFoundError:
4453 QMessageBox::information(NULL, vymName +" Network client",
4454 "The host was not found. Please check the "
4455 "host name and port settings.");
4457 case QAbstractSocket::ConnectionRefusedError:
4458 QMessageBox::information(NULL, vymName + " Network client",
4459 "The connection was refused by the peer. "
4460 "Make sure the fortune server is running, "
4461 "and check that the host name and port "
4462 "settings are correct.");
4465 QMessageBox::information(NULL, vymName + " Network client",
4466 QString("The following error occurred: %1.")
4467 .arg(clientSocket->errorString()));
4474 void VymModel::selectMapSelectionColor()
4476 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4477 setSelectionColor (col);
4480 void VymModel::setSelectionColorInt (QColor col)
4482 if ( !col.isValid() ) return;
4484 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4485 QString("setSelectionColor (%1)").arg(col.name()),
4486 QString("Set color of selection box to %1").arg(col.name())
4489 mapEditor->setSelectionColor (col);
4493 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4495 cout << "VymModel::changeSelection (";
4496 if (!newsel.indexes().isEmpty() )
4497 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4499 if (!oldsel.indexes().isEmpty() )
4500 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4505 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4509 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4511 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4512 emitShowSelection();
4516 void VymModel::emitSelectionChanged()
4518 QItemSelection newsel=selModel->selection();
4519 emitSelectionChanged (newsel);
4522 void VymModel::setSelectionColor(QColor col)
4524 if ( !col.isValid() ) return;
4526 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4527 QString("setSelectionColor (%1)").arg(col.name()),
4528 QString("Set color of selection box to %1").arg(col.name())
4530 setSelectionColorInt (col);
4533 QColor VymModel::getSelectionColor()
4535 return mapEditor->getSelectionColor();
4538 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4541 for (int i=0;i<rootItem->childCount();i++)
4542 rootItem->child(i)->setHideTmp (mode);
4544 // FIXME-3 needed? scene()->update();
4548 QRectF VymModel::getTotalBBox() //FIXME-2
4552 for (int i=0;i<rootItem->branchCount(); i++)
4553 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4558 //////////////////////////////////////////////
4559 // Selection related
4560 //////////////////////////////////////////////
4562 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4567 QItemSelectionModel* VymModel::getSelectionModel()
4572 void VymModel::setSelectionBlocked (bool b)
4577 bool VymModel::isSelectionBlocked()
4579 return selectionBlocked;
4582 bool VymModel::select ()
4584 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4587 bool VymModel::select (const QString &s)
4589 TreeItem *ti=findBySelectString(s);
4599 bool VymModel::select (LinkableMapObj *lmo)
4601 QItemSelection oldsel=selModel->selection();
4604 return select (lmo->getTreeItem() );
4609 bool VymModel::select (TreeItem *ti)
4611 if (ti) return select (index(ti));
4615 bool VymModel::select (const QModelIndex &index)
4617 if (index.isValid() )
4619 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4620 getSelectedItem()->setLastSelectedBranch();
4626 void VymModel::unselect()
4628 lastSelectString=getSelectString();
4629 selModel->clearSelection();
4632 void VymModel::reselect()
4634 select (lastSelectString);
4637 void VymModel::emitShowSelection()
4639 if (!blockReposition)
4640 emit (showSelection() );
4643 void VymModel::emitNoteHasChanged (TreeItem *ti)
4645 QModelIndex ix=index(ti);
4646 emit (noteHasChanged (ix) );
4649 void VymModel::emitDataHasChanged (TreeItem *ti)
4651 QModelIndex ix=index(ti);
4652 emit (dataChanged (ix,ix) );
4656 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4659 if (selection.select(lmo))
4661 //emitSelectionChanged();
4665 void VymModel::selectInt (TreeItem *ti)
4667 if (selection.select(lmo))
4669 //emitSelectionChanged();
4674 void VymModel::selectNextBranchInt()
4676 BranchItem *bi=getSelectedBranchItem();
4679 TreeItem *pi=bi->parent();
4683 if (i<pi->branchCount() )
4685 // select previous branch with same parent
4687 select (pi->getBranchNum(i));
4695 void VymModel::selectPrevBranchInt()
4698 BranchItem *bi=getSelectedBranchItem();
4701 BranchItem *pi=(BranchItem*)bi->parent();
4707 // select previous branch with same parent
4708 bi=pi->getBranchNum(i-1);
4713 while (bi->branchCount() >0)
4714 bi=bi->getLastBranch();
4717 // Try to select last branch in parent pi2 previous to own parent pi
4719 TreeItem *pi2=pi->parent();
4730 void VymModel::selectAboveBranchInt()
4732 BranchItem *bi=getSelectedBranchItem();
4735 BranchItem *newbi=NULL;
4736 BranchItem *pi=(BranchItem*)bi->parent();
4740 // goto previous branch with same parent
4741 newbi=pi->getBranchNum(i-1);
4742 while (newbi->branchCount() >0 )
4743 newbi=newbi->getLastBranch();
4747 if (newbi==rootItem)
4748 // already at top branch (resp. mapcenter)
4754 void VymModel::selectBelowBranchInt()
4756 BranchItem *bi=getSelectedBranchItem();
4759 BranchItem *newbi=NULL;
4761 if (bi->branchCount() >0)
4762 newbi=bi->getFirstBranch();
4769 pi=(BranchItem*)bi->parent();
4771 if (pi->branchCount()-1 > i)
4773 newbi=(BranchItem*)pi->getBranchNum(i+1);
4778 // look for siblings of myself
4779 // or parent, or parent of parent...
4790 void VymModel::selectUpperBranch()
4792 BranchItem *bi=getSelectedBranchItem();
4793 if (bi && bi->isBranchLikeType())
4794 selectAboveBranchInt();
4797 void VymModel::selectLowerBranch()
4799 BranchItem *bi=getSelectedBranchItem();
4800 if (bi && bi->isBranchLikeType())
4801 selectBelowBranchInt();
4805 void VymModel::selectLeftBranch()
4807 QItemSelection oldsel=selModel->selection();
4810 BranchItem *selbi=getSelectedBranchItem();
4811 TreeItem::Type type=selbi->getType();
4814 if (type == TreeItem::MapCenter)
4816 QModelIndex ix=index(selbi);
4817 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4820 par=(BranchItem*)selbi->parent();
4821 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4824 if (type == TreeItem::Branch ||
4825 type == TreeItem::Image)
4827 QModelIndex ix=index (selbi->parent());
4828 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4833 if (type == TreeItem::Branch )
4835 selectLastSelectedBranch();
4843 void VymModel::selectRightBranch()
4845 QItemSelection oldsel=selModel->selection();
4848 BranchItem *selbi=getSelectedBranchItem();
4849 TreeItem::Type type=selbi->getType();
4852 if (type==TreeItem::MapCenter)
4854 QModelIndex ix=index(selbi);
4855 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4858 par=(BranchItem*)selbi->parent();
4859 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4862 if ( type== TreeItem::Branch )
4864 selectLastSelectedBranch();
4870 if (type == TreeItem::Branch ||
4871 type == TreeItem::Image)
4873 QModelIndex ix=index(selbi->parent());
4874 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4881 void VymModel::selectFirstBranch()
4883 TreeItem *ti=getSelectedBranchItem();
4886 TreeItem *par=ti->parent();
4888 TreeItem *ti2=par->getFirstBranch();
4891 emitSelectionChanged();
4896 void VymModel::selectLastBranch()
4898 TreeItem *ti=getSelectedBranchItem();
4901 TreeItem *par=ti->parent();
4903 TreeItem *ti2=par->getLastBranch();
4906 emitSelectionChanged();
4911 void VymModel::selectLastSelectedBranch()
4913 TreeItem *ti=getSelectedBranchItem();
4916 ti=ti->getLastSelectedBranch();
4917 if (ti) select (ti);
4921 void VymModel::selectParent()
4923 TreeItem *ti=getSelectedItem();
4930 emitSelectionChanged();
4934 TreeItem::Type VymModel::selectionType()
4936 QModelIndexList list=selModel->selectedIndexes();
4937 if (list.isEmpty()) return TreeItem::Undefined;
4938 TreeItem *ti = getItem (list.first() );
4939 return ti->getType();
4943 LinkableMapObj* VymModel::getSelectedLMO()
4945 QModelIndexList list=selModel->selectedIndexes();
4946 if (!list.isEmpty() )
4948 TreeItem *ti = getItem (list.first() );
4949 TreeItem::Type type=ti->getType();
4950 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4951 return ((MapItem*)ti)->getLMO();
4956 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4958 TreeItem *ti = getSelectedBranchItem();
4960 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4965 BranchItem* VymModel::getSelectedBranchItem()
4967 QModelIndexList list=selModel->selectedIndexes();
4968 if (!list.isEmpty() )
4970 TreeItem *ti = getItem (list.first() );
4971 TreeItem::Type type=ti->getType();
4972 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4973 return (BranchItem*)ti;
4978 TreeItem* VymModel::getSelectedItem()
4980 QModelIndexList list=selModel->selectedIndexes();
4981 if (!list.isEmpty() )
4982 return getItem (list.first() );
4987 QModelIndex VymModel::getSelectedIndex()
4989 QModelIndexList list=selModel->selectedIndexes();
4990 if (list.isEmpty() )
4991 return QModelIndex();
4993 return list.first();
4996 ImageItem* VymModel::getSelectedImageItem()
4998 QModelIndexList list=selModel->selectedIndexes();
4999 if (!list.isEmpty())
5001 TreeItem *ti=getItem (list.first());
5002 if (ti && ti->getType()==TreeItem::Image)
5003 return (ImageItem*)ti;
5008 QString VymModel::getSelectString ()
5010 return getSelectString (getSelectedItem());
5013 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5015 if (!lmo) return QString();
5016 return getSelectString (lmo->getTreeItem() );
5019 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
5023 switch (ti->getType())
5025 case TreeItem::MapCenter: s="mc:"; break;
5026 case TreeItem::Branch: s="bo:";break;
5027 case TreeItem::Image: s="fi:";break;
5030 s= s + QString("%1").arg(ti->num());
5032 // call myself recursively
5033 s= getSelectString(ti->parent()) +","+s;