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);
1612 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-0
1614 //FIXME-0 FloatImageObj *fio=selection.getFloatImage();
1615 FloatImageObj *fio=NULL;
1618 TreeItem *dst=findBySelectString (dstString);
1619 if (dst && dst->isBranchLikeType() )
1621 TreeItem *dstPar=dst->parent();
1622 QString parString=getSelectString(dstPar);
1623 QString fioPreSelectString=getSelectString(fio);
1624 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1625 // FIXME-0 ((BranchObj*)dst)->addFloatImage (fio);
1627 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1628 fio=((BranchObj*)dst)->getLastFloatImage();
1633 getSelectString(fio),
1634 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1636 QString ("linkTo (\"%1\")").arg(dstString),
1637 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1643 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1646 BranchObj *bo=getSelectedBranch();
1649 QString s=bo->getFrameTypeName();
1650 bo->setFrameType (t);
1651 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1652 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1659 void VymModel::setFrameType(const QString &s) //FIXME-2
1662 BranchObj *bo=getSelectedBranch();
1665 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1666 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1667 bo->setFrameType (s);
1674 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1677 BranchObj *bo=getSelectedBranch();
1680 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1681 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1682 bo->setFramePenColor (c);
1687 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1690 BranchObj *bo=getSelectedBranch();
1693 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1694 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1695 bo->setFrameBrushColor (c);
1699 void VymModel::setFramePadding (const int &i) //FIXME-2
1702 BranchObj *bo=getSelectedBranch();
1705 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1706 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1707 bo->setFramePadding (i);
1714 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1717 BranchObj *bo=getSelectedBranch();
1720 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1721 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1722 bo->setFrameBorderWidth (i);
1729 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1732 BranchObj *bo=getSelectedBranch();
1735 QString u= b ? "false" : "true";
1736 QString r=!b ? "false" : "true";
1740 QString("setIncludeImagesVertically (%1)").arg(u),
1742 QString("setIncludeImagesVertically (%1)").arg(r),
1743 QString("Include images vertically in %1").arg(getObjectName(bo))
1745 bo->setIncludeImagesVer(b);
1750 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1753 BranchObj *bo=getSelectedBranch();
1756 QString u= b ? "false" : "true";
1757 QString r=!b ? "false" : "true";
1761 QString("setIncludeImagesHorizontally (%1)").arg(u),
1763 QString("setIncludeImagesHorizontally (%1)").arg(r),
1764 QString("Include images horizontally in %1").arg(getObjectName(bo))
1766 bo->setIncludeImagesHor(b);
1772 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1775 LinkableMapObj *sel=getSelectedLMO();
1777 (selectionType() == TreeItem::Branch ||
1778 selectionType() == TreeItem::MapCenter ||
1779 selectionType() == TreeItem::Image ))
1781 QString u= b ? "false" : "true";
1782 QString r=!b ? "false" : "true";
1786 QString("setHideLinkUnselected (%1)").arg(u),
1788 QString("setHideLinkUnselected (%1)").arg(r),
1789 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1791 sel->setHideLinkUnselected(b);
1796 void VymModel::setHideExport(bool b)
1798 MapItem *mi=(MapItem*)getSelectedItem();
1800 (mi->getType()==TreeItem::Image ||mi->isBranchLikeType()))
1802 mi->setHideInExport (b);
1803 QString u= b ? "false" : "true";
1804 QString r=!b ? "false" : "true";
1808 QString ("setHideExport (%1)").arg(u),
1810 QString ("setHideExport (%1)").arg(r),
1811 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(mi)).arg (r)
1813 emitDataHasChanged(mi);
1814 emitSelectionChanged();
1817 // emitSelectionChanged();
1818 // FIXME-3 VM needed? scene()->update();
1822 void VymModel::toggleHideExport()
1824 TreeItem *selti=getSelectedItem();
1826 setHideExport ( !selti->hideInExport() );
1830 void VymModel::copy()
1832 TreeItem *selti=getSelectedItem();
1834 (selti->getType() == TreeItem::Branch ||
1835 selti->getType() == TreeItem::MapCenter ||
1836 selti->getType() == TreeItem::Image ))
1838 if (redosAvail == 0)
1841 QString s=getSelectString(selti);
1842 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1843 curClipboard=curStep;
1846 // Copy also to global clipboard, because we are at last step in history
1847 QString bakMapName(QString("history-%1").arg(curStep));
1848 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1849 copyDir (bakMapDir,clipboardDir );
1851 clipboardEmpty=false;
1857 void VymModel::pasteNoSave(const int &n)
1859 bool old=blockSaveState;
1860 blockSaveState=true;
1861 bool zippedOrg=zipped;
1862 if (redosAvail > 0 || n!=0)
1864 // Use the "historical" buffer
1865 QString bakMapName(QString("history-%1").arg(n));
1866 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1867 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1869 // Use the global buffer
1870 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1875 void VymModel::paste()
1877 BranchItem *selbi=getSelectedBranchItem();
1880 saveStateChangingPart(
1883 QString ("paste (%1)").arg(curClipboard),
1884 QString("Paste to %1").arg( getObjectName(selbi))
1891 void VymModel::cut()
1893 TreeItem *selti=getSelectedItem();
1894 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1902 void VymModel::moveUp()
1904 BranchItem *selbi=getSelectedBranchItem();
1907 if (!selbi->canMoveUp()) return;
1908 QString oldsel=getSelectString();
1909 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1911 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1915 void VymModel::moveDown()
1917 BranchItem *selbi=getSelectedBranchItem();
1920 if (!selbi->canMoveDown()) return;
1921 QString oldsel=getSelectString();
1922 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1924 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1928 void VymModel::sortChildren() // FIXME-2 not implemented yet
1931 BranchObj* bo=getSelectedBranch();
1934 if(treeItem->branchCount()>1)
1936 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1939 emitShowSelection();
1945 BranchItem* VymModel::createMapCenter()
1947 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1951 BranchItem* VymModel::createBranch(BranchItem *dst)
1954 return addNewBranchInt (dst,-2);
1959 ImageItem* VymModel::createImage(BranchItem *dst)
1965 QList<QVariant> cData;
1966 cData << "VM::createImage" << "undef"<<"undef";
1968 ImageItem *newii=new ImageItem (cData);
1969 newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1971 emit (layoutAboutToBeChanged() );
1974 n=dst->getRowNumAppend(newii);
1975 beginInsertRows (parix,n,n+1);
1976 dst->appendChild (newii);
1979 emit (layoutChanged() );
1981 // save scroll state. If scrolled, automatically select
1982 // new branch in order to tmp unscroll parent...
1983 newii->createMapObj(mapScene);
1990 BranchItem* VymModel::addMapCenter ()
1992 BranchItem *bi=addMapCenter (contextPos);
1994 emitShowSelection();
1999 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2000 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2005 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2006 // createMapCenter could then probably be merged with createBranch
2010 QModelIndex parix=index(rootItem);
2012 int n=rootItem->branchCount();
2014 emit (layoutAboutToBeChanged() );
2015 beginInsertRows (parix,n,n+1);
2017 QList<QVariant> cData;
2018 cData << "VM:addMapCenter" << "undef"<<"undef";
2019 BranchItem *newbi=new BranchItem (cData);
2020 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2021 rootItem->appendChild (newbi);
2024 emit (layoutChanged() );
2027 newbi->setPositionMode (MapItem::Absolute);
2028 newbi->createMapObj(mapScene);
2033 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2035 // Depending on pos:
2036 // -3 insert in children of parent above selection
2037 // -2 add branch to selection
2038 // -1 insert in children of parent below selection
2039 // 0..n insert in children of parent at pos
2042 QList<QVariant> cData;
2043 cData << "new" << "undef"<<"undef";
2048 BranchItem *newbi=new BranchItem (cData);
2049 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2051 emit (layoutAboutToBeChanged() );
2057 n=parbi->getRowNumAppend (newbi);
2058 beginInsertRows (parix,n,n+1);
2059 parbi->appendChild (newbi);
2061 }else if (num==-1 || num==-3)
2063 // insert below selection
2064 parbi=(BranchItem*)dst->parent();
2067 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2068 beginInsertRows (parix,n,n);
2069 parbi->insertBranch(n,newbi);
2072 emit (layoutChanged() );
2074 // save scroll state. If scrolled, automatically select
2075 // new branch in order to tmp unscroll parent...
2076 newbi->createMapObj(mapScene);
2081 BranchItem* VymModel::addNewBranch(int pos)
2083 // Different meaning than num in addNewBranchInt!
2087 BranchItem *newbi=NULL;
2088 BranchItem *selbi=getSelectedBranchItem();
2092 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2094 newbi=addNewBranchInt (selbi,pos-2);
2102 QString ("addBranch (%1)").arg(pos),
2103 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2106 // emitSelectionChanged(); FIXME-3
2107 latestAddedItem=newbi;
2108 // In Network mode, the client needs to know where the new branch is,
2109 // so we have to pass on this information via saveState.
2110 // TODO: Get rid of this positioning workaround
2111 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2112 sendData ("selectLatestAdded ()");
2113 sendData (QString("move %1").arg(ps));
2122 BranchItem* VymModel::addNewBranchBefore()
2124 BranchItem *newbi=NULL;
2125 BranchItem *selbi=getSelectedBranchItem();
2126 if (selbi && selbi->getType()==TreeItem::Branch)
2127 // We accept no MapCenter here, so we _have_ a parent
2129 //QPointF p=bo->getRelPos();
2132 // add below selection
2133 newbi=addNewBranchInt (selbi,-1);
2137 //newbi->move2RelPos (p);
2139 // Move selection to new branch
2140 relinkBranch (selbi,newbi,0);
2142 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2143 QString ("Add branch before %1").arg(getObjectName(selbi)));
2145 // FIXME-3 needed? reposition();
2146 // emitSelectionChanged(); FIXME-3
2152 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2156 if (branch->depth()==0)
2158 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2160 emit (layoutAboutToBeChanged() );
2161 BranchItem *branchpi=(BranchItem*)branch->parent();
2162 // Remove at current position
2163 int n=branch->childNum();
2164 beginRemoveRows (index(branchpi),n,n);
2165 branchpi->removeChild (n);
2168 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2170 // Append as last branch to dst
2171 if (dst->branchCount()==0)
2174 n=dst->getFirstBranch()->childNumber();
2175 beginInsertRows (index(dst),n+pos,n+pos);
2176 dst->insertBranch (pos,branch);
2179 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2180 branch->updateStyles();
2182 emit (layoutChanged() );
2183 reposition(); // both for moveUp/Down and relinking
2190 void VymModel::deleteSelection()
2192 BranchItem *selbi=getSelectedBranchItem();
2194 if (selbi && selbi->isBranchLikeType() )
2197 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2199 TreeItem *pi=deleteItem (selbi);
2203 emitShowSelection();
2207 ImageItem *ii=getSelectedImageItem();
2210 BranchItem *pi=(BranchItem*)(ii->parent());
2211 saveStateChangingPart(
2215 QString("Delete %1").arg(getObjectName(ii))
2221 emitShowSelection();
2226 void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters
2229 BranchItem *selbi=getSelectedBranchItem();
2233 // Don't use this on mapcenter
2234 if (selbi->depth()<2) return;
2236 pi=(BranchItem*)(selbi->parent());
2237 // Check if we have childs at all to keep
2238 if (selbi->branchCount()==0)
2245 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2246 saveStateChangingPart(
2249 "deleteKeepChildren ()",
2250 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2253 QString sel=getSelectString(selbi);
2255 int pos=selbi->num();
2256 BranchItem *bi=selbi->getFirstBranch();
2259 relinkBranch (bi,pi,pos);
2260 bi=selbi->getFirstBranch();
2266 BranchObj *bo=getSelectedBranchObj();
2269 bo->move2RelPos (p);
2275 void VymModel::deleteChildren()
2278 BranchItem *selbi=getSelectedBranchItem();
2281 saveStateChangingPart(
2284 "deleteChildren ()",
2285 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2287 emit (layoutAboutToBeChanged() );
2289 QModelIndex ix=index (selbi);
2290 int n=selbi->branchCount()-1;
2291 beginRemoveRows (ix,0,n);
2292 removeRows (0,n+1,ix);
2294 emit (layoutChanged() );
2299 TreeItem* VymModel::deleteItem (TreeItem *ti)
2303 TreeItem *pi=ti->parent();
2304 QModelIndex parentIndex=index(pi);
2306 emit (layoutAboutToBeChanged() );
2308 int n=ti->childNum();
2309 beginRemoveRows (parentIndex,n,n);
2310 removeRows (n,1,parentIndex);
2314 emit (layoutChanged() );
2315 if (pi->depth()>0) return pi;
2320 bool VymModel::scrollBranch(BranchItem *bi)
2324 if (bi->isScrolled()) return false;
2325 if (bi->branchCount()==0) return false;
2326 if (bi->depth()==0) return false;
2327 if (bi->toggleScroll())
2334 QString ("%1 ()").arg(u),
2336 QString ("%1 ()").arg(r),
2337 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2339 emitDataHasChanged(bi);
2340 emitSelectionChanged();
2341 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2348 bool VymModel::unscrollBranch(BranchItem *bi)
2352 if (!bi->isScrolled()) return false;
2353 if (bi->branchCount()==0) return false;
2354 if (bi->depth()==0) return false;
2361 QString ("%1 ()").arg(u),
2363 QString ("%1 ()").arg(r),
2364 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2367 emitDataHasChanged(bi);
2368 emitSelectionChanged();
2370 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2376 void VymModel::toggleScroll()
2378 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2379 if (bi && bi->isBranchLikeType() )
2381 if (bi->isScrolled())
2382 unscrollBranch (bi);
2386 // saveState is called in above functions
2389 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2393 BranchObj *bo=getSelectedBranch();
2399 if (bo->isScrolled()) unscrollBranch (bo);
2406 void VymModel::emitExpandAll()
2408 emit (expandAll() );
2411 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2413 BranchItem *bi=getSelectedBranchItem();
2417 if (bi->isActiveStandardFlag(name))
2429 QString("%1 (\"%2\")").arg(u).arg(name),
2431 QString("%1 (\"%2\")").arg(r).arg(name),
2432 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2433 bi->toggleStandardFlag (name, master);
2435 emitSelectionChanged();
2439 void VymModel::addFloatImage (const QPixmap &img) //FIXME-0
2442 BranchObj *bo=getSelectedBranch();
2445 FloatImageObj *fio=bo->addFloatImage();
2447 fio->setOriginalFilename("No original filename (image added by dropevent)");
2448 QString s=getSelectString(bo);
2449 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2450 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2452 // FIXME-3 VM needed? scene()->update();
2458 void VymModel::colorBranch (QColor c)
2460 BranchItem *selbi=getSelectedBranchItem();
2465 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2467 QString ("colorBranch (\"%1\")").arg(c.name()),
2468 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2470 selbi->setHeadingColor(c); // color branch
2474 void VymModel::colorSubtree (QColor c)
2476 BranchItem *selbi=getSelectedBranchItem();
2479 saveStateChangingPart(
2482 QString ("colorSubtree (\"%1\")").arg(c.name()),
2483 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2485 BranchItem *prev=NULL;
2486 BranchItem *cur=selbi;
2489 cur->setHeadingColor(c); // color links, color children
2490 cur=next (cur,prev,selbi);
2496 QColor VymModel::getCurrentHeadingColor()
2498 BranchItem *selbi=getSelectedBranchItem();
2499 if (selbi) return selbi->getHeadingColor();
2501 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2507 void VymModel::editURL()
2509 TreeItem *selti=getSelectedItem();
2513 QString text = QInputDialog::getText(
2514 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2515 selti->getURL(), &ok, NULL);
2517 // user entered something and pressed OK
2522 void VymModel::editLocalURL()
2524 TreeItem *selti=getSelectedItem();
2527 QStringList filters;
2528 filters <<"All files (*)";
2529 filters << tr("Text","Filedialog") + " (*.txt)";
2530 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2531 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2532 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2533 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2534 fd->setFilters (filters);
2535 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2536 fd->setDirectory (lastFileDir);
2537 if (! selti->getVymLink().isEmpty() )
2538 fd->selectFile( selti->getURL() );
2541 if ( fd->exec() == QDialog::Accepted )
2543 lastFileDir=QDir (fd->directory().path());
2544 setURL (fd->selectedFile() );
2550 void VymModel::editHeading2URL()
2552 TreeItem *selti=getSelectedItem();
2554 setURL (selti->getHeading());
2557 void VymModel::editBugzilla2URL()
2559 TreeItem *selti=getSelectedItem();
2562 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2567 void VymModel::editFATE2URL()
2569 TreeItem *selti=getSelectedItem();
2572 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2575 "setURL (\""+selti->getURL()+"\")",
2577 "setURL (\""+url+"\")",
2578 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2580 selti->setURL (url);
2581 // FIXME-4 updateActions();
2585 void VymModel::editVymLink()
2587 BranchItem *bi=getSelectedBranchItem();
2590 QStringList filters;
2591 filters <<"VYM map (*.vym)";
2592 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2593 fd->setFilters (filters);
2594 fd->setCaption(vymName+" - " +tr("Link to another map"));
2595 fd->setDirectory (lastFileDir);
2596 if (! bi->getVymLink().isEmpty() )
2597 fd->selectFile( bi->getVymLink() );
2601 if ( fd->exec() == QDialog::Accepted )
2603 lastFileDir=QDir (fd->directory().path());
2606 "setVymLink (\""+bi->getVymLink()+"\")",
2608 "setVymLink (\""+fd->selectedFile()+"\")",
2609 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2611 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2616 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2618 // Internal function, no saveState needed
2619 BranchItem *bi=getSelectedBranchItem();
2625 //emitSelectionChanged();
2629 void VymModel::deleteVymLink()
2631 BranchItem *bi=getSelectedBranchItem();
2636 "setVymLink (\""+bi->getVymLink()+"\")",
2638 "setVymLink (\"\")",
2639 QString("Unset vymlink of %1").arg(getObjectName(bi))
2641 bi->setVymLink ("" );
2647 QString VymModel::getVymLink()
2649 BranchItem *bi=getSelectedBranchItem();
2651 return bi->getVymLink();
2657 QStringList VymModel::getVymLinks()
2660 BranchItem *selbi=getSelectedBranchItem();
2661 BranchItem *cur=selbi;
2662 BranchItem *prev=NULL;
2665 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2666 cur=next (cur,prev,selbi);
2672 void VymModel::followXLink(int i) // FIXME-2
2676 BranchObj *bo=getSelectedBranch();
2679 bo=bo->XLinkTargetAt(i);
2682 selection.select(bo);
2683 emitShowSelection();
2689 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2693 BranchObj *bo=getSelectedBranch();
2696 XLinkObj *xlo=bo->XLinkAt(i);
2699 EditXLinkDialog dia;
2701 dia.setSelection(bo);
2702 if (dia.exec() == QDialog::Accepted)
2704 if (dia.useSettingsGlobal() )
2706 setMapDefXLinkColor (xlo->getColor() );
2707 setMapDefXLinkWidth (xlo->getWidth() );
2709 if (dia.deleteXLink())
2710 bo->deleteXLinkAt(i);
2721 //////////////////////////////////////////////
2723 //////////////////////////////////////////////
2725 void VymModel::parseAtom(const QString &atom)
2727 TreeItem* selti=getSelectedItem();
2728 BranchItem *selbi=getSelectedBranchItem();
2734 // Split string s into command and parameters
2735 parser.parseAtom (atom);
2736 QString com=parser.getCommand();
2738 // External commands
2739 /////////////////////////////////////////////////////////////////////
2740 if (com=="addBranch")
2744 parser.setError (Aborted,"Nothing selected");
2745 } else if (! selbi )
2747 parser.setError (Aborted,"Type of selection is not a branch");
2752 if (parser.checkParCount(pl))
2754 if (parser.parCount()==0)
2758 n=parser.parInt (ok,0);
2759 if (ok ) addNewBranch (n);
2763 /////////////////////////////////////////////////////////////////////
2764 } else if (com=="addBranchBefore")
2768 parser.setError (Aborted,"Nothing selected");
2769 } else if (! selbi )
2771 parser.setError (Aborted,"Type of selection is not a branch");
2774 if (parser.parCount()==0)
2776 addNewBranchBefore ();
2779 /////////////////////////////////////////////////////////////////////
2780 } else if (com==QString("addMapCenter"))
2782 if (parser.checkParCount(2))
2784 x=parser.parDouble (ok,0);
2787 y=parser.parDouble (ok,1);
2788 if (ok) addMapCenter (QPointF(x,y));
2791 /////////////////////////////////////////////////////////////////////
2792 } else if (com==QString("addMapReplace"))
2796 parser.setError (Aborted,"Nothing selected");
2797 } else if (! selbi )
2799 parser.setError (Aborted,"Type of selection is not a branch");
2800 } else if (parser.checkParCount(1))
2802 //s=parser.parString (ok,0); // selection
2803 t=parser.parString (ok,0); // path to map
2804 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2805 addMapReplaceInt(getSelectString(selbi),t);
2807 /////////////////////////////////////////////////////////////////////
2808 } else if (com==QString("addMapInsert"))
2812 parser.setError (Aborted,"Nothing selected");
2813 } else if (! selbi )
2815 parser.setError (Aborted,"Type of selection is not a branch");
2818 if (parser.checkParCount(2))
2820 t=parser.parString (ok,0); // path to map
2821 n=parser.parInt(ok,1); // position
2822 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2823 addMapInsertInt(t,n);
2826 /////////////////////////////////////////////////////////////////////
2827 } else if (com=="clearFlags")
2831 parser.setError (Aborted,"Nothing selected");
2832 } else if (! selbi )
2834 parser.setError (Aborted,"Type of selection is not a branch");
2835 } else if (parser.checkParCount(0))
2837 selbi->deactivateAllStandardFlags();
2839 /////////////////////////////////////////////////////////////////////
2840 } else if (com=="colorBranch")
2844 parser.setError (Aborted,"Nothing selected");
2845 } else if (! selbi )
2847 parser.setError (Aborted,"Type of selection is not a branch");
2848 } else if (parser.checkParCount(1))
2850 QColor c=parser.parColor (ok,0);
2851 if (ok) colorBranch (c);
2853 /////////////////////////////////////////////////////////////////////
2854 } else if (com=="colorSubtree")
2858 parser.setError (Aborted,"Nothing selected");
2859 } else if (! selbi )
2861 parser.setError (Aborted,"Type of selection is not a branch");
2862 } else if (parser.checkParCount(1))
2864 QColor c=parser.parColor (ok,0);
2865 if (ok) colorSubtree (c);
2867 /////////////////////////////////////////////////////////////////////
2868 } else if (com=="copy")
2872 parser.setError (Aborted,"Nothing selected");
2873 } else if ( selectionType()!=TreeItem::Branch &&
2874 selectionType()!=TreeItem::MapCenter &&
2875 selectionType()!=TreeItem::Image )
2877 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2878 } else if (parser.checkParCount(0))
2882 /////////////////////////////////////////////////////////////////////
2883 } else if (com=="cut")
2887 parser.setError (Aborted,"Nothing selected");
2888 } else if ( selectionType()!=TreeItem::Branch &&
2889 selectionType()!=TreeItem::MapCenter &&
2890 selectionType()!=TreeItem::Image )
2892 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2893 } else if (parser.checkParCount(0))
2897 /////////////////////////////////////////////////////////////////////
2898 } else if (com=="delete")
2902 parser.setError (Aborted,"Nothing selected");
2904 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2906 parser.setError (Aborted,"Type of selection is wrong.");
2909 else if (parser.checkParCount(0))
2913 /////////////////////////////////////////////////////////////////////
2914 } else if (com=="deleteKeepChildren")
2918 parser.setError (Aborted,"Nothing selected");
2919 } else if (! selbi )
2921 parser.setError (Aborted,"Type of selection is not a branch");
2922 } else if (parser.checkParCount(0))
2924 deleteKeepChildren();
2926 /////////////////////////////////////////////////////////////////////
2927 } else if (com=="deleteChildren")
2931 parser.setError (Aborted,"Nothing selected");
2934 parser.setError (Aborted,"Type of selection is not a branch");
2935 } else if (parser.checkParCount(0))
2939 /////////////////////////////////////////////////////////////////////
2940 } else if (com=="exportASCII")
2944 if (parser.parCount()>=1)
2945 // Hey, we even have a filename
2946 fname=parser.parString(ok,0);
2949 parser.setError (Aborted,"Could not read filename");
2952 exportASCII (fname,false);
2954 /////////////////////////////////////////////////////////////////////
2955 } else if (com=="exportImage")
2959 if (parser.parCount()>=2)
2960 // Hey, we even have a filename
2961 fname=parser.parString(ok,0);
2964 parser.setError (Aborted,"Could not read filename");
2967 QString format="PNG";
2968 if (parser.parCount()>=2)
2970 format=parser.parString(ok,1);
2972 exportImage (fname,false,format);
2974 /////////////////////////////////////////////////////////////////////
2975 } else if (com=="exportXHTML")
2979 if (parser.parCount()>=2)
2980 // Hey, we even have a filename
2981 fname=parser.parString(ok,1);
2984 parser.setError (Aborted,"Could not read filename");
2987 exportXHTML (fname,false);
2989 /////////////////////////////////////////////////////////////////////
2990 } else if (com=="exportXML")
2994 if (parser.parCount()>=2)
2995 // Hey, we even have a filename
2996 fname=parser.parString(ok,1);
2999 parser.setError (Aborted,"Could not read filename");
3002 exportXML (fname,false);
3004 /////////////////////////////////////////////////////////////////////
3005 } else if (com=="importDir")
3009 parser.setError (Aborted,"Nothing selected");
3010 } else if (! selbi )
3012 parser.setError (Aborted,"Type of selection is not a branch");
3013 } else if (parser.checkParCount(1))
3015 s=parser.parString(ok,0);
3016 if (ok) importDirInt(s);
3018 /////////////////////////////////////////////////////////////////////
3019 } else if (com=="relinkTo")
3023 parser.setError (Aborted,"Nothing selected");
3026 if (parser.checkParCount(4))
3028 // 0 selectstring of parent
3029 // 1 num in parent (for branches)
3030 // 2,3 x,y of mainbranch or mapcenter
3031 s=parser.parString(ok,0);
3032 TreeItem *dst=findBySelectString (s);
3035 if (dst->getType()==TreeItem::Branch)
3037 // Get number in parent
3038 n=parser.parInt (ok,1);
3041 relinkBranch (selbi,(BranchItem*)dst,n);
3042 emitSelectionChanged();
3044 } else if (dst->getType()==TreeItem::MapCenter)
3046 relinkBranch (selbi,(BranchItem*)dst);
3047 // Get coordinates of mainbranch
3048 x=parser.parDouble(ok,2);
3051 y=parser.parDouble(ok,3);
3054 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3055 emitSelectionChanged();
3061 } else if ( selti->getType() == TreeItem::Image)
3063 if (parser.checkParCount(1))
3065 // 0 selectstring of parent
3066 s=parser.parString(ok,0);
3067 TreeItem *dst=findBySelectString (s);
3070 /* FIXME-0 relink img
3071 if (dst->isBranchLikeType())
3072 linkFloatImageTo (getSelectString(dst));
3075 parser.setError (Aborted,"Destination is not a branch");
3078 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3079 /////////////////////////////////////////////////////////////////////
3080 } else if (com=="loadImage")
3084 parser.setError (Aborted,"Nothing selected");
3085 } else if (! selbi )
3087 parser.setError (Aborted,"Type of selection is not a branch");
3088 } else if (parser.checkParCount(1))
3090 s=parser.parString(ok,0);
3091 if (ok) loadFloatImageInt (selbi,s);
3093 /////////////////////////////////////////////////////////////////////
3094 } else if (com=="moveUp")
3098 parser.setError (Aborted,"Nothing selected");
3099 } else if (! selbi )
3101 parser.setError (Aborted,"Type of selection is not a branch");
3102 } else if (parser.checkParCount(0))
3106 /////////////////////////////////////////////////////////////////////
3107 } else if (com=="moveDown")
3111 parser.setError (Aborted,"Nothing selected");
3112 } else if (! selbi )
3114 parser.setError (Aborted,"Type of selection is not a branch");
3115 } else if (parser.checkParCount(0))
3119 /////////////////////////////////////////////////////////////////////
3120 } else if (com=="move")
3124 parser.setError (Aborted,"Nothing selected");
3125 } else if ( selectionType()!=TreeItem::Branch &&
3126 selectionType()!=TreeItem::MapCenter &&
3127 selectionType()!=TreeItem::Image )
3129 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3130 } else if (parser.checkParCount(2))
3132 x=parser.parDouble (ok,0);
3135 y=parser.parDouble (ok,1);
3139 /////////////////////////////////////////////////////////////////////
3140 } else if (com=="moveRel")
3144 parser.setError (Aborted,"Nothing selected");
3145 } else if ( selectionType()!=TreeItem::Branch &&
3146 selectionType()!=TreeItem::MapCenter &&
3147 selectionType()!=TreeItem::Image )
3149 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3150 } else if (parser.checkParCount(2))
3152 x=parser.parDouble (ok,0);
3155 y=parser.parDouble (ok,1);
3156 if (ok) moveRel (x,y);
3159 /////////////////////////////////////////////////////////////////////
3160 } else if (com=="nop")
3162 /////////////////////////////////////////////////////////////////////
3163 } else if (com=="paste")
3167 parser.setError (Aborted,"Nothing selected");
3168 } else if (! selbi )
3170 parser.setError (Aborted,"Type of selection is not a branch");
3171 } else if (parser.checkParCount(1))
3173 n=parser.parInt (ok,0);
3174 if (ok) pasteNoSave(n);
3176 /////////////////////////////////////////////////////////////////////
3177 } else if (com=="qa")
3181 parser.setError (Aborted,"Nothing selected");
3182 } else if (! selbi )
3184 parser.setError (Aborted,"Type of selection is not a branch");
3185 } else if (parser.checkParCount(4))
3188 c=parser.parString (ok,0);
3191 parser.setError (Aborted,"No comment given");
3194 s=parser.parString (ok,1);
3197 parser.setError (Aborted,"First parameter is not a string");
3200 t=parser.parString (ok,2);
3203 parser.setError (Aborted,"Condition is not a string");
3206 u=parser.parString (ok,3);
3209 parser.setError (Aborted,"Third parameter is not a string");
3214 parser.setError (Aborted,"Unknown type: "+s);
3219 parser.setError (Aborted,"Unknown operator: "+t);
3224 parser.setError (Aborted,"Type of selection is not a branch");
3227 if (selbi->getHeading() == u)
3229 cout << "PASSED: " << qPrintable (c) << endl;
3232 cout << "FAILED: " << qPrintable (c) << endl;
3242 /////////////////////////////////////////////////////////////////////
3243 } else if (com=="saveImage")
3245 ImageItem *ii=getSelectedImageItem();
3248 parser.setError (Aborted,"No image selected");
3249 } else if (parser.checkParCount(2))
3251 s=parser.parString(ok,0);
3254 t=parser.parString(ok,1);
3255 if (ok) saveFloatImageInt (ii,t,s);
3258 /////////////////////////////////////////////////////////////////////
3259 } else if (com=="scroll")
3263 parser.setError (Aborted,"Nothing selected");
3264 } else if (! selbi )
3266 parser.setError (Aborted,"Type of selection is not a branch");
3267 } else if (parser.checkParCount(0))
3269 if (!scrollBranch (selbi))
3270 parser.setError (Aborted,"Could not scroll branch");
3272 /////////////////////////////////////////////////////////////////////
3273 } else if (com=="select")
3275 if (parser.checkParCount(1))
3277 s=parser.parString(ok,0);
3280 /////////////////////////////////////////////////////////////////////
3281 } else if (com=="selectLastBranch")
3285 parser.setError (Aborted,"Nothing selected");
3286 } else if (! selbi )
3288 parser.setError (Aborted,"Type of selection is not a branch");
3289 } else if (parser.checkParCount(0))
3291 BranchItem *bi=selbi->getLastBranch();
3293 parser.setError (Aborted,"Could not select last branch");
3294 select (bi); // FIXME-3 was selectInt
3297 /////////////////////////////////////////////////////////////////////
3298 } else /* FIXME-2 if (com=="selectLastImage")
3302 parser.setError (Aborted,"Nothing selected");
3303 } else if (! selbi )
3305 parser.setError (Aborted,"Type of selection is not a branch");
3306 } else if (parser.checkParCount(0))
3308 FloatImageObj *fio=selb->getLastFloatImage();
3310 parser.setError (Aborted,"Could not select last image");
3311 select (fio); // FIXME-3 was selectInt
3314 /////////////////////////////////////////////////////////////////////
3315 } else */ if (com=="selectLatestAdded")
3317 if (!latestAddedItem)
3319 parser.setError (Aborted,"No latest added object");
3322 if (!select (latestAddedItem))
3323 parser.setError (Aborted,"Could not select latest added object ");
3325 /////////////////////////////////////////////////////////////////////
3326 } else if (com=="setFrameType")
3328 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3330 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3332 else if (parser.checkParCount(1))
3334 s=parser.parString(ok,0);
3335 if (ok) setFrameType (s);
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="setFramePenColor")
3340 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3342 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3344 else if (parser.checkParCount(1))
3346 QColor c=parser.parColor(ok,0);
3347 if (ok) setFramePenColor (c);
3349 /////////////////////////////////////////////////////////////////////
3350 } else if (com=="setFrameBrushColor")
3352 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3354 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3356 else if (parser.checkParCount(1))
3358 QColor c=parser.parColor(ok,0);
3359 if (ok) setFrameBrushColor (c);
3361 /////////////////////////////////////////////////////////////////////
3362 } else if (com=="setFramePadding")
3364 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3366 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3368 else if (parser.checkParCount(1))
3370 n=parser.parInt(ok,0);
3371 if (ok) setFramePadding(n);
3373 /////////////////////////////////////////////////////////////////////
3374 } else if (com=="setFrameBorderWidth")
3376 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3378 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3380 else if (parser.checkParCount(1))
3382 n=parser.parInt(ok,0);
3383 if (ok) setFrameBorderWidth (n);
3385 /////////////////////////////////////////////////////////////////////
3386 } else if (com=="setMapAuthor")
3388 if (parser.checkParCount(1))
3390 s=parser.parString(ok,0);
3391 if (ok) setAuthor (s);
3393 /////////////////////////////////////////////////////////////////////
3394 } else if (com=="setMapComment")
3396 if (parser.checkParCount(1))
3398 s=parser.parString(ok,0);
3399 if (ok) setComment(s);
3401 /////////////////////////////////////////////////////////////////////
3402 } else if (com=="setMapBackgroundColor")
3406 parser.setError (Aborted,"Nothing selected");
3407 } else if (! selbi )
3409 parser.setError (Aborted,"Type of selection is not a branch");
3410 } else if (parser.checkParCount(1))
3412 QColor c=parser.parColor (ok,0);
3413 if (ok) setMapBackgroundColor (c);
3415 /////////////////////////////////////////////////////////////////////
3416 } else if (com=="setMapDefLinkColor")
3420 parser.setError (Aborted,"Nothing selected");
3421 } else if (! selbi )
3423 parser.setError (Aborted,"Type of selection is not a branch");
3424 } else if (parser.checkParCount(1))
3426 QColor c=parser.parColor (ok,0);
3427 if (ok) setMapDefLinkColor (c);
3429 /////////////////////////////////////////////////////////////////////
3430 } else if (com=="setMapLinkStyle")
3432 if (parser.checkParCount(1))
3434 s=parser.parString (ok,0);
3435 if (ok) setMapLinkStyle(s);
3437 /////////////////////////////////////////////////////////////////////
3438 } else if (com=="setHeading")
3442 parser.setError (Aborted,"Nothing selected");
3443 } else if (! selbi )
3445 parser.setError (Aborted,"Type of selection is not a branch");
3446 } else if (parser.checkParCount(1))
3448 s=parser.parString (ok,0);
3452 /////////////////////////////////////////////////////////////////////
3453 } else if (com=="setHideExport")
3457 parser.setError (Aborted,"Nothing selected");
3458 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3460 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3461 } else if (parser.checkParCount(1))
3463 b=parser.parBool(ok,0);
3464 if (ok) setHideExport (b);
3466 /////////////////////////////////////////////////////////////////////
3467 } else if (com=="setIncludeImagesHorizontally")
3471 parser.setError (Aborted,"Nothing selected");
3474 parser.setError (Aborted,"Type of selection is not a branch");
3475 } else if (parser.checkParCount(1))
3477 b=parser.parBool(ok,0);
3478 if (ok) setIncludeImagesHor(b);
3480 /////////////////////////////////////////////////////////////////////
3481 } else if (com=="setIncludeImagesVertically")
3485 parser.setError (Aborted,"Nothing selected");
3488 parser.setError (Aborted,"Type of selection is not a branch");
3489 } else if (parser.checkParCount(1))
3491 b=parser.parBool(ok,0);
3492 if (ok) setIncludeImagesVer(b);
3494 /////////////////////////////////////////////////////////////////////
3495 } else if (com=="setHideLinkUnselected")
3499 parser.setError (Aborted,"Nothing selected");
3500 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3502 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3503 } else if (parser.checkParCount(1))
3505 b=parser.parBool(ok,0);
3506 if (ok) setHideLinkUnselected(b);
3508 /////////////////////////////////////////////////////////////////////
3509 } else if (com=="setSelectionColor")
3511 if (parser.checkParCount(1))
3513 QColor c=parser.parColor (ok,0);
3514 if (ok) setSelectionColorInt (c);
3516 /////////////////////////////////////////////////////////////////////
3517 } else if (com=="setURL")
3521 parser.setError (Aborted,"Nothing selected");
3522 } else if (! selbi )
3524 parser.setError (Aborted,"Type of selection is not a branch");
3525 } else if (parser.checkParCount(1))
3527 s=parser.parString (ok,0);
3530 /////////////////////////////////////////////////////////////////////
3531 } else if (com=="setVymLink")
3535 parser.setError (Aborted,"Nothing selected");
3536 } else if (! selbi )
3538 parser.setError (Aborted,"Type of selection is not a branch");
3539 } else if (parser.checkParCount(1))
3541 s=parser.parString (ok,0);
3542 if (ok) setVymLink(s);
3545 /////////////////////////////////////////////////////////////////////
3546 else if (com=="setFlag")
3550 parser.setError (Aborted,"Nothing selected");
3551 } else if (! selbi )
3553 parser.setError (Aborted,"Type of selection is not a branch");
3554 } else if (parser.checkParCount(1))
3556 s=parser.parString(ok,0);
3558 selbi->activateStandardFlag(s);
3560 /////////////////////////////////////////////////////////////////////
3561 } else /* FIXME-2 if (com=="setFrameType")
3565 parser.setError (Aborted,"Nothing selected");
3568 parser.setError (Aborted,"Type of selection is not a branch");
3569 } else if (parser.checkParCount(1))
3571 s=parser.parString(ok,0);
3575 /////////////////////////////////////////////////////////////////////
3576 } else*/ if (com=="sortChildren")
3580 parser.setError (Aborted,"Nothing selected");
3581 } else if (! selbi )
3583 parser.setError (Aborted,"Type of selection is not a branch");
3584 } else if (parser.checkParCount(0))
3588 /////////////////////////////////////////////////////////////////////
3589 } else if (com=="toggleFlag")
3593 parser.setError (Aborted,"Nothing selected");
3594 } else if (! selbi )
3596 parser.setError (Aborted,"Type of selection is not a branch");
3597 } else if (parser.checkParCount(1))
3599 s=parser.parString(ok,0);
3601 selbi->toggleStandardFlag(s);
3603 /////////////////////////////////////////////////////////////////////
3604 } else if (com=="unscroll")
3608 parser.setError (Aborted,"Nothing selected");
3609 } else if (! selbi )
3611 parser.setError (Aborted,"Type of selection is not a branch");
3612 } else if (parser.checkParCount(0))
3614 if (!unscrollBranch (selbi))
3615 parser.setError (Aborted,"Could not unscroll branch");
3617 /////////////////////////////////////////////////////////////////////
3618 } else if (com=="unscrollChildren")
3622 parser.setError (Aborted,"Nothing selected");
3623 } else if (! selbi )
3625 parser.setError (Aborted,"Type of selection is not a branch");
3626 } else if (parser.checkParCount(0))
3628 unscrollChildren ();
3630 /////////////////////////////////////////////////////////////////////
3631 } else if (com=="unsetFlag")
3635 parser.setError (Aborted,"Nothing selected");
3636 } else if (! selbi )
3638 parser.setError (Aborted,"Type of selection is not a branch");
3639 } else if (parser.checkParCount(1))
3641 s=parser.parString(ok,0);
3643 selbi->deactivateStandardFlag(s);
3646 parser.setError (Aborted,"Unknown command");
3649 if (parser.errorLevel()==NoError)
3651 // setChanged(); FIXME-2 should not be called e.g. for export?!
3656 // TODO Error handling
3657 qWarning("VymModel::parseAtom: Error!");
3658 qWarning(parser.errorMessage());
3662 void VymModel::runScript (QString script)
3664 parser.setScript (script);
3666 while (parser.next() )
3667 parseAtom(parser.getAtom());
3670 void VymModel::setExportMode (bool b)
3672 // should be called before and after exports
3673 // depending on the settings
3674 if (b && settings.value("/export/useHideExport","true")=="true")
3675 setHideTmpMode (TreeItem::HideExport);
3677 setHideTmpMode (TreeItem::HideNone);
3680 void VymModel::exportImage(QString fname, bool askName, QString format)
3684 fname=getMapName()+".png";
3691 QFileDialog *fd=new QFileDialog (NULL);
3692 fd->setCaption (tr("Export map as image"));
3693 fd->setDirectory (lastImageDir);
3694 fd->setFileMode(QFileDialog::AnyFile);
3695 fd->setFilters (imageIO.getFilters() );
3698 fl=fd->selectedFiles();
3700 format=imageIO.getType(fd->selectedFilter());
3704 setExportMode (true);
3705 QPixmap pix (getPixmap());
3706 pix.save(fname, format);
3707 setExportMode (false);
3711 void VymModel::exportXML(QString dir, bool askForName)
3715 dir=browseDirectory(NULL,tr("Export XML to directory"));
3716 if (dir =="" && !reallyWriteDirectory(dir) )
3720 // Hide stuff during export, if settings want this
3721 setExportMode (true);
3723 // Create subdirectories
3726 // write to directory
3727 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3730 file.setName ( dir + "/"+mapName+".xml");
3731 if ( !file.open( QIODevice::WriteOnly ) )
3733 // This should neverever happen
3734 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3738 // Write it finally, and write in UTF8, no matter what
3739 QTextStream ts( &file );
3740 ts.setEncoding (QTextStream::UnicodeUTF8);
3744 // Now write image, too
3745 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3747 setExportMode (false);
3750 void VymModel::exportASCII(QString fname,bool askName)
3755 ex.setFile (mapName+".txt");
3761 //ex.addFilter ("TXT (*.txt)");
3762 ex.setDir(lastImageDir);
3763 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3768 setExportMode(true);
3770 setExportMode(false);
3774 void VymModel::exportXHTML (const QString &dir, bool askForName)
3776 ExportXHTMLDialog dia(NULL);
3777 dia.setFilePath (filePath );
3778 dia.setMapName (mapName );
3780 if (dir!="") dia.setDir (dir);
3786 if (dia.exec()!=QDialog::Accepted)
3790 QDir d (dia.getDir());
3791 // Check, if warnings should be used before overwriting
3792 // the output directory
3793 if (d.exists() && d.count()>0)
3796 warn.showCancelButton (true);
3797 warn.setText(QString(
3798 "The directory %1 is not empty.\n"
3799 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3800 warn.setCaption("Warning: Directory not empty");
3801 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3803 if (warn.exec()!=QDialog::Accepted) ok=false;
3810 exportXML (dia.getDir(),false );
3811 dia.doExport(mapName );
3812 //if (dia.hasChanged()) setChanged();
3816 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3821 if (ex.setConfigFile(cf))
3823 setExportMode (true);
3824 ex.exportPresentation();
3825 setExportMode (false);
3832 //////////////////////////////////////////////
3834 //////////////////////////////////////////////
3836 void VymModel::registerEditor(QWidget *me)
3838 mapEditor=(MapEditor*)me;
3841 void VymModel::unregisterEditor(QWidget *)
3846 void VymModel::setContextPos(QPointF p)
3851 void VymModel::unsetContextPos()
3853 contextPos=QPointF();
3856 void VymModel::updateNoteFlag()
3859 TreeItem *selti=getSelectedItem();
3862 if (textEditor->isEmpty())
3865 selti->setNote (textEditor->getText());
3866 emitDataHasChanged(selti);
3867 emitSelectionChanged();
3872 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3874 cout << "VM::updateRelPos...\n";
3876 for (int i=0; i<rootItem->branchCount(); i++)
3877 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3880 void MapCenterObj::updateRelPositions()
3882 if (repositionRequest) unsetAllRepositionRequests();
3884 // update relative Positions of branches and floats
3885 for (int i=0; i<treeItem->branchCount(); ++i)
3887 treeItem->getBranchObjNum(i)->setRelPos();
3888 treeItem->getBranchObjNum(i)->setOrientation();
3891 for (int i=0; i<floatimage.size(); ++i)
3892 floatimage.at(i)->setRelPos();
3894 if (repositionRequest) reposition();
3899 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3901 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3902 if (blockReposition) return;
3904 for (int i=0;i<rootItem->branchCount(); i++)
3905 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3909 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3911 return QPolygonF ();
3912 // Creating (arbitrary) shapes
3915 QRectF rb=bo->getBBox();
3916 if (bo->getDepth()==0)
3918 // Just take BBox of this mapCenter
3919 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3923 // Take union of BBox and TotalBBox
3925 QRectF ra=bo->getTotalBBox();
3926 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3929 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3932 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3934 p <<ra.bottomRight()
3936 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3939 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3945 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3949 // Move all branches and MapCenters away from lmo
3950 // to avoid collisions
3955 BranchObj *boA=(BranchObj*)lmo;
3957 for (int i=0; i<rootItem->branchCount(); i++)
3959 boB=rootItem->getBranchNum(i);
3962 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3965 <<" ("<<qPrintable(boA->getHeading() )<<")"
3966 <<" with ("<< qPrintable (boB->getHeading() )
3969 <<" minT="<<r.minTranslation<<endl<<endl;
3974 QPixmap VymModel::getPixmap()
3976 QRectF mapRect=getTotalBBox();
3977 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3980 pp.setRenderHints(mapEditor->renderHints());
3982 // Don't print the visualisation of selection
3985 mapScene->render ( &pp,
3986 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3987 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3989 // Restore selection
3996 void VymModel::setMapLinkStyle (const QString & s)
4001 case LinkableMapObj::Line :
4004 case LinkableMapObj::Parabel:
4005 snow="StyleParabel";
4007 case LinkableMapObj::PolyLine:
4008 snow="StylePolyLine";
4010 case LinkableMapObj::PolyParabel:
4011 snow="StylePolyParabel";
4014 snow="UndefinedStyle";
4019 QString("setMapLinkStyle (\"%1\")").arg(s),
4020 QString("setMapLinkStyle (\"%1\")").arg(snow),
4021 QString("Set map link style (\"%1\")").arg(s)
4025 linkstyle=LinkableMapObj::Line;
4026 else if (s=="StyleParabel")
4027 linkstyle=LinkableMapObj::Parabel;
4028 else if (s=="StylePolyLine")
4029 linkstyle=LinkableMapObj::PolyLine;
4030 else if (s=="StylePolyParabel")
4031 linkstyle=LinkableMapObj::PolyParabel;
4033 linkstyle=LinkableMapObj::UndefinedStyle;
4035 BranchItem *cur=NULL;
4036 BranchItem *prev=NULL;
4041 bo=(BranchObj*)(cur->getLMO() );
4042 bo->setLinkStyle(bo->getDefLinkStyle());
4048 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4053 void VymModel::setMapDefLinkColor(QColor col)
4055 if ( !col.isValid() ) return;
4057 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4058 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4059 QString("Set map link color to %1").arg(col.name())
4063 BranchItem *cur=NULL;
4064 BranchItem *prev=NULL;
4069 bo=(BranchObj*)(cur->getLMO() );
4076 void VymModel::setMapLinkColorHintInt()
4078 // called from setMapLinkColorHint(lch) or at end of parse
4079 BranchItem *cur=NULL;
4080 BranchItem *prev=NULL;
4085 bo=(BranchObj*)(cur->getLMO() );
4091 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4094 setMapLinkColorHintInt();
4097 void VymModel::toggleMapLinkColorHint()
4099 if (linkcolorhint==LinkableMapObj::HeadingColor)
4100 linkcolorhint=LinkableMapObj::DefaultColor;
4102 linkcolorhint=LinkableMapObj::HeadingColor;
4103 BranchItem *cur=NULL;
4104 BranchItem *prev=NULL;
4109 bo=(BranchObj*)(cur->getLMO() );
4115 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4117 Q3FileDialog *fd=new Q3FileDialog( NULL);
4118 fd->setMode (Q3FileDialog::ExistingFile);
4119 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4120 ImagePreview *p =new ImagePreview (fd);
4121 fd->setContentsPreviewEnabled( TRUE );
4122 fd->setContentsPreview( p, p );
4123 fd->setPreviewMode( Q3FileDialog::Contents );
4124 fd->setCaption(vymName+" - " +tr("Load background image"));
4125 fd->setDir (lastImageDir);
4128 if ( fd->exec() == QDialog::Accepted )
4130 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4131 lastImageDir=QDir (fd->dirPath());
4132 setMapBackgroundImage (fd->selectedFile());
4136 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4138 QColor oldcol=mapScene->backgroundBrush().color();
4142 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4144 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4145 QString("Set background color of map to %1").arg(col.name()));
4148 brush.setTextureImage (QPixmap (fn));
4149 mapScene->setBackgroundBrush(brush);
4152 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4154 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4155 if ( !col.isValid() ) return;
4156 setMapBackgroundColor( col );
4160 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4162 QColor oldcol=mapScene->backgroundBrush().color();
4164 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4165 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4166 QString("Set background color of map to %1").arg(col.name()));
4167 mapScene->setBackgroundBrush(col);
4170 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4172 return mapScene->backgroundBrush().color();
4176 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4178 return linkcolorhint;
4181 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4183 return defLinkColor;
4186 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4191 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4193 return defXLinkColor;
4196 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4201 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4203 return defXLinkWidth;
4206 void VymModel::move(const double &x, const double &y) // FIXME-3
4210 BranchObj *bo = getSelectedBranch();
4212 (selectionType()==TreeItem::Branch ||
4213 selectionType()==TreeItem::MapCenter ||
4214 selectionType()==TreeItem::Image
4217 QPointF ap(bo->getAbsPos());
4221 QString ps=qpointfToString(ap);
4222 QString s=getSelectString();
4225 s, "move "+qpointfToString(to),
4226 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4229 emitSelectionChanged();
4235 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4239 BranchObj *bo = getSelectedBranch();
4241 (selectionType()==TreeItem::Branch ||
4242 selectionType()==TreeItem::MapCenter ||
4243 selectionType()==TreeItem::Image
4247 QPointF rp(bo->getRelPos());
4251 QString ps=qpointfToString (bo->getRelPos());
4252 QString s=getSelectString(bo);
4255 s, "moveRel "+qpointfToString(to),
4256 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4257 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4260 emitSelectionChanged();
4267 void VymModel::animate()
4269 animationTimer->stop();
4272 while (i<animObjList.size() )
4274 bo=(BranchObj*)animObjList.at(i);
4279 animObjList.removeAt(i);
4286 QItemSelection sel=selModel->selection();
4287 emit (selectionChanged(sel,sel));
4290 if (!animObjList.isEmpty()) animationTimer->start();
4294 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4296 if (bo && bo->getTreeItem()->depth()>0)
4299 ap.setStart (start);
4301 ap.setTicks (animationTicks);
4302 ap.setAnimated (true);
4303 bo->setAnimation (ap);
4304 animObjList.append( bo );
4305 animationTimer->setSingleShot (true);
4306 animationTimer->start(animationInterval);
4310 void VymModel::stopAnimation (MapObj *mo)
4312 int i=animObjList.indexOf(mo);
4314 animObjList.removeAt (i);
4317 void VymModel::sendSelection()
4319 if (netstate!=Server) return;
4320 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4323 void VymModel::newServer()
4327 tcpServer = new QTcpServer(this);
4328 if (!tcpServer->listen(QHostAddress::Any,port)) {
4329 QMessageBox::critical(NULL, "vym server",
4330 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4331 //FIXME-3 needed? we are no widget any longer... close();
4334 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4336 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4339 void VymModel::connectToServer()
4342 server="salam.suse.de";
4344 clientSocket = new QTcpSocket (this);
4345 clientSocket->abort();
4346 clientSocket->connectToHost(server ,port);
4347 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4348 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4349 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4351 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4356 void VymModel::newClient()
4358 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4359 connect(newClient, SIGNAL(disconnected()),
4360 newClient, SLOT(deleteLater()));
4362 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4364 clientList.append (newClient);
4368 void VymModel::sendData(const QString &s)
4370 if (clientList.size()==0) return;
4372 // Create bytearray to send
4374 QDataStream out(&block, QIODevice::WriteOnly);
4375 out.setVersion(QDataStream::Qt_4_0);
4377 // Reserve some space for blocksize
4380 // Write sendCounter
4381 out << sendCounter++;
4386 // Go back and write blocksize so far
4387 out.device()->seek(0);
4388 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4392 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4394 for (int i=0; i<clientList.size(); ++i)
4396 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4397 clientList.at(i)->write (block);
4401 void VymModel::readData ()
4403 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4406 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4410 QDataStream in(clientSocket);
4411 in.setVersion(QDataStream::Qt_4_0);
4419 cout << " t="<<qPrintable (t)<<endl;
4425 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4427 switch (socketError) {
4428 case QAbstractSocket::RemoteHostClosedError:
4430 case QAbstractSocket::HostNotFoundError:
4431 QMessageBox::information(NULL, vymName +" Network client",
4432 "The host was not found. Please check the "
4433 "host name and port settings.");
4435 case QAbstractSocket::ConnectionRefusedError:
4436 QMessageBox::information(NULL, vymName + " Network client",
4437 "The connection was refused by the peer. "
4438 "Make sure the fortune server is running, "
4439 "and check that the host name and port "
4440 "settings are correct.");
4443 QMessageBox::information(NULL, vymName + " Network client",
4444 QString("The following error occurred: %1.")
4445 .arg(clientSocket->errorString()));
4452 void VymModel::selectMapSelectionColor()
4454 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4455 setSelectionColor (col);
4458 void VymModel::setSelectionColorInt (QColor col)
4460 if ( !col.isValid() ) return;
4462 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4463 QString("setSelectionColor (%1)").arg(col.name()),
4464 QString("Set color of selection box to %1").arg(col.name())
4467 mapEditor->setSelectionColor (col);
4471 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4473 cout << "VymModel::changeSelection (";
4474 if (!newsel.indexes().isEmpty() )
4475 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4477 if (!oldsel.indexes().isEmpty() )
4478 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4483 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4487 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4489 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4490 emitShowSelection();
4494 void VymModel::emitSelectionChanged()
4496 QItemSelection newsel=selModel->selection();
4497 emitSelectionChanged (newsel);
4500 void VymModel::setSelectionColor(QColor col)
4502 if ( !col.isValid() ) return;
4504 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4505 QString("setSelectionColor (%1)").arg(col.name()),
4506 QString("Set color of selection box to %1").arg(col.name())
4508 setSelectionColorInt (col);
4511 QColor VymModel::getSelectionColor()
4513 return mapEditor->getSelectionColor();
4516 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4519 for (int i=0;i<rootItem->childCount();i++)
4520 rootItem->child(i)->setHideTmp (mode);
4522 // FIXME-3 needed? scene()->update();
4526 QRectF VymModel::getTotalBBox() //FIXME-2
4530 for (int i=0;i<rootItem->branchCount(); i++)
4531 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4536 //////////////////////////////////////////////
4537 // Selection related
4538 //////////////////////////////////////////////
4540 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4545 QItemSelectionModel* VymModel::getSelectionModel()
4550 void VymModel::setSelectionBlocked (bool b)
4555 bool VymModel::isSelectionBlocked()
4557 return selectionBlocked;
4560 bool VymModel::select ()
4562 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4565 bool VymModel::select (const QString &s)
4567 TreeItem *ti=findBySelectString(s);
4577 bool VymModel::select (LinkableMapObj *lmo)
4579 QItemSelection oldsel=selModel->selection();
4582 return select (lmo->getTreeItem() );
4587 bool VymModel::select (TreeItem *ti)
4589 if (ti) return select (index(ti));
4593 bool VymModel::select (const QModelIndex &index)
4595 if (index.isValid() )
4597 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4598 getSelectedItem()->setLastSelectedBranch();
4604 void VymModel::unselect()
4606 lastSelectString=getSelectString();
4607 selModel->clearSelection();
4610 void VymModel::reselect()
4612 select (lastSelectString);
4615 void VymModel::emitShowSelection()
4617 if (!blockReposition)
4618 emit (showSelection() );
4621 void VymModel::emitNoteHasChanged (TreeItem *ti)
4623 QModelIndex ix=index(ti);
4624 emit (noteHasChanged (ix) );
4627 void VymModel::emitDataHasChanged (TreeItem *ti)
4629 QModelIndex ix=index(ti);
4630 emit (dataChanged (ix,ix) );
4634 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4637 if (selection.select(lmo))
4639 //emitSelectionChanged();
4643 void VymModel::selectInt (TreeItem *ti)
4645 if (selection.select(lmo))
4647 //emitSelectionChanged();
4652 void VymModel::selectNextBranchInt()
4654 BranchItem *bi=getSelectedBranchItem();
4657 TreeItem *pi=bi->parent();
4661 if (i<pi->branchCount() )
4663 // select previous branch with same parent
4665 select (pi->getBranchNum(i));
4673 void VymModel::selectPrevBranchInt()
4676 BranchItem *bi=getSelectedBranchItem();
4679 BranchItem *pi=(BranchItem*)bi->parent();
4685 // select previous branch with same parent
4686 bi=pi->getBranchNum(i-1);
4691 while (bi->branchCount() >0)
4692 bi=bi->getLastBranch();
4695 // Try to select last branch in parent pi2 previous to own parent pi
4697 TreeItem *pi2=pi->parent();
4708 void VymModel::selectAboveBranchInt()
4710 BranchItem *bi=getSelectedBranchItem();
4713 BranchItem *newbi=NULL;
4714 BranchItem *pi=(BranchItem*)bi->parent();
4718 // goto previous branch with same parent
4719 newbi=pi->getBranchNum(i-1);
4720 while (newbi->branchCount() >0 )
4721 newbi=newbi->getLastBranch();
4725 if (newbi==rootItem)
4726 // already at top branch (resp. mapcenter)
4732 void VymModel::selectBelowBranchInt()
4734 BranchItem *bi=getSelectedBranchItem();
4737 BranchItem *newbi=NULL;
4739 if (bi->branchCount() >0)
4740 newbi=bi->getFirstBranch();
4747 pi=(BranchItem*)bi->parent();
4749 if (pi->branchCount()-1 > i)
4751 newbi=(BranchItem*)pi->getBranchNum(i+1);
4756 // look for siblings of myself
4757 // or parent, or parent of parent...
4768 void VymModel::selectUpperBranch()
4770 BranchItem *bi=getSelectedBranchItem();
4771 if (bi && bi->isBranchLikeType())
4772 selectAboveBranchInt();
4775 void VymModel::selectLowerBranch()
4777 BranchItem *bi=getSelectedBranchItem();
4778 if (bi && bi->isBranchLikeType())
4779 selectBelowBranchInt();
4783 void VymModel::selectLeftBranch()
4785 QItemSelection oldsel=selModel->selection();
4788 BranchItem *selbi=getSelectedBranchItem();
4789 TreeItem::Type type=selbi->getType();
4792 if (type == TreeItem::MapCenter)
4794 QModelIndex ix=index(selbi);
4795 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4798 par=(BranchItem*)selbi->parent();
4799 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4802 if (type == TreeItem::Branch ||
4803 type == TreeItem::Image)
4805 QModelIndex ix=index (selbi->parent());
4806 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4811 if (type == TreeItem::Branch )
4813 selectLastSelectedBranch();
4821 void VymModel::selectRightBranch()
4823 QItemSelection oldsel=selModel->selection();
4826 BranchItem *selbi=getSelectedBranchItem();
4827 TreeItem::Type type=selbi->getType();
4830 if (type==TreeItem::MapCenter)
4832 QModelIndex ix=index(selbi);
4833 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4836 par=(BranchItem*)selbi->parent();
4837 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4840 if ( type== TreeItem::Branch )
4842 selectLastSelectedBranch();
4848 if (type == TreeItem::Branch ||
4849 type == TreeItem::Image)
4851 QModelIndex ix=index(selbi->parent());
4852 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4859 void VymModel::selectFirstBranch()
4861 TreeItem *ti=getSelectedBranchItem();
4864 TreeItem *par=ti->parent();
4866 TreeItem *ti2=par->getFirstBranch();
4869 emitSelectionChanged();
4874 void VymModel::selectLastBranch()
4876 TreeItem *ti=getSelectedBranchItem();
4879 TreeItem *par=ti->parent();
4881 TreeItem *ti2=par->getLastBranch();
4884 emitSelectionChanged();
4889 void VymModel::selectLastSelectedBranch()
4891 TreeItem *ti=getSelectedBranchItem();
4894 ti=ti->getLastSelectedBranch();
4895 if (ti) select (ti);
4899 void VymModel::selectParent()
4901 TreeItem *ti=getSelectedItem();
4908 emitSelectionChanged();
4912 TreeItem::Type VymModel::selectionType()
4914 QModelIndexList list=selModel->selectedIndexes();
4915 if (list.isEmpty()) return TreeItem::Undefined;
4916 TreeItem *ti = getItem (list.first() );
4917 return ti->getType();
4921 LinkableMapObj* VymModel::getSelectedLMO()
4923 QModelIndexList list=selModel->selectedIndexes();
4924 if (!list.isEmpty() )
4926 TreeItem *ti = getItem (list.first() );
4927 TreeItem::Type type=ti->getType();
4928 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4930 return ((MapItem*)ti)->getLMO();
4936 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4938 TreeItem *ti = getSelectedBranchItem();
4940 return (BranchObj*)((MapItem*)ti)->getLMO();
4945 BranchItem* VymModel::getSelectedBranchItem()
4947 QModelIndexList list=selModel->selectedIndexes();
4948 if (!list.isEmpty() )
4950 TreeItem *ti = getItem (list.first() );
4951 TreeItem::Type type=ti->getType();
4952 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4953 return (BranchItem*)ti;
4958 TreeItem* VymModel::getSelectedItem()
4960 QModelIndexList list=selModel->selectedIndexes();
4961 if (!list.isEmpty() )
4962 return getItem (list.first() );
4967 QModelIndex VymModel::getSelectedIndex()
4969 QModelIndexList list=selModel->selectedIndexes();
4970 if (list.isEmpty() )
4971 return QModelIndex();
4973 return list.first();
4976 ImageItem* VymModel::getSelectedImageItem()
4978 QModelIndexList list=selModel->selectedIndexes();
4979 if (!list.isEmpty())
4981 TreeItem *ti=getItem (list.first());
4982 if (ti && ti->getType()==TreeItem::Image)
4983 return (ImageItem*)ti;
4988 QString VymModel::getSelectString ()
4990 return getSelectString (getSelectedItem());
4993 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
4995 if (!lmo) return QString();
4996 return getSelectString (lmo->getTreeItem() );
4999 QString VymModel::getSelectString (TreeItem *ti)
5003 if (ti->isBranchLikeType())
5005 TreeItem *par=ti->parent();
5008 if (ti->depth() ==1)
5009 // Mainbranch, return
5010 s= "bo:" + QString("%1").arg(ti->num() );
5012 // Branch, call myself recursively
5013 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5017 int i=rootItem->num(ti);
5018 if (i>=0) s=QString("mc:%1").arg(i);