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 FloatImageObj (mapScene).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 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
267 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
271 for (int i=0; i<rootItem->branchCount(); i++)
272 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
276 void VymModel::setFilePath(QString fpath, QString destname)
278 if (fpath.isEmpty() || fpath=="")
285 filePath=fpath; // becomes absolute path
286 fileName=fpath; // gets stripped of path
287 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
289 // If fpath is not an absolute path, complete it
290 filePath=QDir(fpath).absPath();
291 fileDir=filePath.left (1+filePath.findRev ("/"));
293 // Set short name, too. Search from behind:
294 int i=fileName.findRev("/");
295 if (i>=0) fileName=fileName.remove (0,i+1);
297 // Forget the .vym (or .xml) for name of map
298 mapName=fileName.left(fileName.findRev(".",-1,true) );
302 void VymModel::setFilePath(QString fpath)
304 setFilePath (fpath,fpath);
307 QString VymModel::getFilePath()
312 QString VymModel::getFileName()
317 QString VymModel::getMapName()
322 QString VymModel::getDestPath()
327 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
329 ErrorCode err=success;
331 parseBaseHandler *handler;
335 case VymMap: handler=new parseVYMHandler; break;
336 case FreemindMap : handler=new parseFreemindHandler; break;
338 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
339 "Unknown FileType in VymModel::load()");
343 bool zipped_org=zipped;
347 selModel->clearSelection();
348 // FIXME-2 VM not needed??? model->setMapEditor(this);
349 // (map state is set later at end of load...)
352 BranchItem *bi=getSelectedBranchItem();
353 if (!bi) return aborted;
354 if (lmode==ImportAdd)
355 saveStateChangingPart(
358 QString("addMapInsert (%1)").arg(fname),
359 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
361 saveStateChangingPart(
364 QString("addMapReplace(%1)").arg(fname),
365 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
369 // Create temporary directory for packing
371 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
374 QMessageBox::critical( 0, tr( "Critical Load Error" ),
375 tr("Couldn't create temporary directory before load\n"));
380 err=unzipDir (tmpZipDir,fname);
390 // Look for mapname.xml
391 xmlfile= fname.left(fname.findRev(".",-1,true));
392 xmlfile=xmlfile.section( '/', -1 );
393 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
394 if (!mfile.exists() )
396 // mapname.xml does not exist, well,
397 // maybe someone renamed the mapname.vym file...
398 // Try to find any .xml in the toplevel
399 // directory of the .vym file
400 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
401 if (flist.count()==1)
403 // Only one entry, take this one
404 xmlfile=tmpZipDir + "/"+flist.first();
407 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
408 *it=tmpZipDir + "/" + *it;
409 // TODO Multiple entries, load all (but only the first one into this ME)
410 //mainWindow->fileLoadFromTmp (flist);
411 //returnCode=1; // Silently forget this attempt to load
412 qWarning ("MainWindow::load (fn) multimap found...");
415 if (flist.isEmpty() )
417 QMessageBox::critical( 0, tr( "Critical Load Error" ),
418 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
421 } //file doesn't exist
423 xmlfile=mfile.name();
426 QFile file( xmlfile);
428 // I am paranoid: file should exist anyway
429 // according to check in mainwindow.
432 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
433 tr(QString("Couldn't open map %1").arg(file.name())));
437 bool blockSaveStateOrg=blockSaveState;
438 blockReposition=true;
440 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
441 QXmlInputSource source( file);
442 QXmlSimpleReader reader;
443 reader.setContentHandler( handler );
444 reader.setErrorHandler( handler );
445 handler->setModel ( this);
448 // We need to set the tmpDir in order to load files with rel. path
453 tmpdir=fname.left(fname.findRev("/",-1));
454 handler->setTmpDir (tmpdir);
455 handler->setInputFile (file.name());
456 handler->setLoadMode (lmode);
457 bool ok = reader.parse( source );
458 blockReposition=false;
459 blockSaveState=blockSaveStateOrg;
460 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
464 reposition(); // FIXME-2 VM reposition the view instead...
465 emitSelectionChanged();
471 autosaveTimer->stop();
474 // Reset timestamp to check for later updates of file
475 fileChangedTime=QFileInfo (destPath).lastModified();
478 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
479 tr( handler->errorProtocol() ) );
481 // Still return "success": the map maybe at least
482 // partially read by the parser
487 removeDir (QDir(tmpZipDir));
489 // Restore original zip state
496 ErrorCode VymModel::save (const SaveMode &savemode)
500 QString safeFilePath;
502 ErrorCode err=success;
506 mapFileName=mapName+".xml";
508 // use name given by user, even if he chooses .doc
509 mapFileName=fileName;
511 // Look, if we should zip the data:
514 QMessageBox mb( vymName,
515 tr("The map %1\ndid not use the compressed "
516 "vym file format.\nWriting it uncompressed will also write images \n"
517 "and flags and thus may overwrite files in the "
518 "given directory\n\nDo you want to write the map").arg(filePath),
519 QMessageBox::Warning,
520 QMessageBox::Yes | QMessageBox::Default,
522 QMessageBox::Cancel | QMessageBox::Escape);
523 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
524 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
525 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
528 case QMessageBox::Yes:
529 // save compressed (default file format)
532 case QMessageBox::No:
536 case QMessageBox::Cancel:
543 // First backup existing file, we
544 // don't want to add to old zip archives
548 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
550 QString backupFileName(destPath + "~");
551 QFile backupFile(backupFileName);
552 if (backupFile.exists() && !backupFile.remove())
554 QMessageBox::warning(0, tr("Save Error"),
555 tr("%1\ncould not be removed before saving").arg(backupFileName));
557 else if (!f.rename(backupFileName))
559 QMessageBox::warning(0, tr("Save Error"),
560 tr("%1\ncould not be renamed before saving").arg(destPath));
567 // Create temporary directory for packing
569 tmpZipDir=makeTmpDir (ok,"vym-zip");
572 QMessageBox::critical( 0, tr( "Critical Load Error" ),
573 tr("Couldn't create temporary directory before save\n"));
577 safeFilePath=filePath;
578 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
581 // Create mapName and fileDir
582 makeSubDirs (fileDir);
585 if (savemode==CompleteMap || selModel->selection().isEmpty())
588 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
591 autosaveTimer->stop();
596 if (selectionType()==TreeItem::Image)
599 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
600 // TODO take care of multiselections
603 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
606 qWarning ("ME::saveStringToDisk failed!");
612 if (err==success) err=zipDir (tmpZipDir,destPath);
615 removeDir (QDir(tmpZipDir));
617 // Restore original filepath outside of tmp zip dir
618 setFilePath (safeFilePath);
622 fileChangedTime=QFileInfo (destPath).lastModified();
626 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
628 QString pathDir=path.left(path.findRev("/"));
634 // We need to parse saved XML data
635 parseVYMHandler handler;
636 QXmlInputSource source( file);
637 QXmlSimpleReader reader;
638 reader.setContentHandler( &handler );
639 reader.setErrorHandler( &handler );
640 handler.setModel ( this);
641 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
642 if (undoSel.isEmpty())
646 handler.setLoadMode (NewMap);
650 handler.setLoadMode (ImportReplace);
652 blockReposition=true;
653 bool ok = reader.parse( source );
654 blockReposition=false;
657 // This should never ever happen
658 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
659 handler.errorProtocol());
662 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
665 void VymModel::addMapInsertInt (const QString &path, int pos)
667 /* FIXME-2 addMapInsertInt not ported yet
668 BranchObj *sel=getSelectedBranch();
671 QString pathDir=path.left(path.findRev("/"));
677 // We need to parse saved XML data
678 parseVYMHandler handler;
679 QXmlInputSource source( file);
680 QXmlSimpleReader reader;
681 reader.setContentHandler( &handler );
682 reader.setErrorHandler( &handler );
683 handler.setModel (this);
684 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
685 handler.setLoadMode (ImportAdd);
686 blockReposition=true;
687 bool ok = reader.parse( source );
688 blockReposition=false;
691 // This should never ever happen
692 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
693 handler.errorProtocol());
695 if (sel->getDepth()>0)
696 sel->getLastBranch()->linkTo (sel,pos);
698 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
703 FloatImageObj* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
705 TreeItem *fi=createImage(dst);
708 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
716 void VymModel::loadFloatImage ()
718 BranchItem *selbi=getSelectedBranchItem();
722 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
723 fd->setMode (Q3FileDialog::ExistingFiles);
724 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
725 ImagePreview *p =new ImagePreview (fd);
726 fd->setContentsPreviewEnabled( TRUE );
727 fd->setContentsPreview( p, p );
728 fd->setPreviewMode( Q3FileDialog::Contents );
729 fd->setCaption(vymName+" - " +tr("Load image"));
730 fd->setDir (lastImageDir);
733 if ( fd->exec() == QDialog::Accepted )
735 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
736 lastImageDir=QDir (fd->dirPath());
739 for (int j=0; j<fd->selectedFiles().count(); j++)
741 s=fd->selectedFiles().at(j);
742 fio=loadFloatImageInt (selbi,s);
743 //FIXME-1 savestate for loadImage missing
747 (LinkableMapObj*)fio,
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);
764 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
769 void VymModel::saveFloatImage ()
771 //FIXME-1 FloatImageObj *fio=selection.getFloatImage();
772 FloatImageObj *fio=NULL;
775 QFileDialog *fd=new QFileDialog( NULL);
776 fd->setFilters (imageIO.getFilters());
777 fd->setCaption(vymName+" - " +tr("Save image"));
778 fd->setFileMode( QFileDialog::AnyFile );
779 fd->setDirectory (lastImageDir);
780 // fd->setSelection (fio->getOriginalFilename());
784 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
786 fn=fd->selectedFiles().at(0);
787 if (QFile (fn).exists() )
789 QMessageBox mb( vymName,
790 tr("The file %1 exists already.\n"
791 "Do you want to overwrite it?").arg(fn),
792 QMessageBox::Warning,
793 QMessageBox::Yes | QMessageBox::Default,
794 QMessageBox::Cancel | QMessageBox::Escape,
795 QMessageBox::NoButton );
797 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
798 mb.setButtonText( QMessageBox::No, tr("Cancel"));
801 case QMessageBox::Yes:
804 case QMessageBox::Cancel:
811 saveFloatImageInt (fio,fd->selectedFilter(),fn );
818 void VymModel::importDirInt(BranchObj *dst, QDir d)
820 /* FIXME-2 importDirInt not ported yet
821 BranchObj *bo=getSelectedBranch();
824 // Traverse directories
825 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
826 QFileInfoList list = d.entryInfoList();
829 for (int i = 0; i < list.size(); ++i)
832 if (fi.fileName() != "." && fi.fileName() != ".." )
835 bo=dst->getLastBranch();
836 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
837 bi->setHeading (fi.fileName() ); // FIXME-3 check this
838 bo->setColor (QColor("blue"));
840 if ( !d.cd(fi.fileName()) )
841 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
844 // Recursively add subdirs
851 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
852 list = d.entryInfoList();
854 for (int i = 0; i < list.size(); ++i)
858 bo=dst->getLastBranch();
859 bo->setHeading (fi.fileName() );
860 bo->setColor (QColor("black"));
861 if (fi.fileName().right(4) == ".vym" )
862 bo->setVymLink (fi.filePath());
868 void VymModel::importDirInt (const QString &s) // FIXME-2
871 BranchObj *bo=getSelectedBranch();
874 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
882 void VymModel::importDir() //FIXME-2
885 BranchObj *bo=getSelectedBranch();
889 filters <<"VYM map (*.vym)";
890 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
891 fd->setMode (QFileDialog::DirectoryOnly);
892 fd->setFilters (filters);
893 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
897 if ( fd->exec() == QDialog::Accepted )
899 importDirInt (fd->selectedFile() );
901 //FIXME-3 VM needed? scene()->update();
908 void VymModel::autosave()
913 cout << "VymModel::autosave rejected due to missing filePath\n";
916 QDateTime now=QDateTime().currentDateTime();
918 // Disable autosave, while we have gone back in history
919 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
920 if (redosAvail>0) return;
922 // Also disable autosave for new map without filename
923 if (filePath.isEmpty()) return;
926 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
928 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
929 mainWindow->fileSave (this);
932 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
937 void VymModel::fileChanged()
939 // Check if file on disk has changed meanwhile
940 if (!filePath.isEmpty())
942 QDateTime tmod=QFileInfo (filePath).lastModified();
943 if (tmod>fileChangedTime)
945 // FIXME-2 VM switch to current mapeditor and finish lineedits...
946 QMessageBox mb( vymName,
947 tr("The file of the map on disk has changed:\n\n"
948 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
949 QMessageBox::Question,
951 QMessageBox::Cancel | QMessageBox::Default,
952 QMessageBox::NoButton );
954 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
955 mb.setButtonText( QMessageBox::No, tr("Ignore"));
958 case QMessageBox::Yes:
960 load (filePath,NewMap,fileType);
961 case QMessageBox::Cancel:
962 fileChangedTime=tmod; // allow autosave to overwrite newer file!
968 bool VymModel::isDefault()
973 void VymModel::makeDefault()
979 bool VymModel::hasChanged()
984 void VymModel::setChanged()
987 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
991 latestAddedItem=NULL;
995 QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
998 if (!lmo) return QString("Error: NULL has no name!");
1000 TreeItem *ti=lmo->getTreeItem();
1001 if (ti->isBranchLikeType() )
1004 s=lmo->getTreeItem()->getHeading();
1005 if (s=="") s="unnamed";
1006 return QString("branch (%1)").arg(s);
1008 if (ti->getType()==TreeItem::Image)
1009 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1010 return QString("Unknown type has no name!");
1014 QString VymModel::getObjectName (const TreeItem *ti)
1017 if (!ti) return QString("Error: NULL has no name!");
1019 if (ti->isBranchLikeType() )
1022 if (s=="") s="unnamed";
1023 return QString("branch (%1)").arg(s);
1025 /* FIXME-2 move floatimage to TreeModel first
1026 if (type==TreeItem::Image)
1027 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1029 return QString("Unknown type has no name!");
1032 void VymModel::redo()
1034 // Can we undo at all?
1035 if (redosAvail<1) return;
1037 bool blockSaveStateOrg=blockSaveState;
1038 blockSaveState=true;
1042 if (undosAvail<stepsTotal) undosAvail++;
1044 if (curStep>stepsTotal) curStep=1;
1045 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1046 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1047 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1048 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1049 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1050 QString version=undoSet.readEntry ("/history/version");
1052 /* TODO Maybe check for version, if we save the history
1053 if (!checkVersion(version))
1054 QMessageBox::warning(0,tr("Warning"),
1055 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1058 // Find out current undo directory
1059 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1063 cout << "VymModel::redo() begin\n";
1064 cout << " undosAvail="<<undosAvail<<endl;
1065 cout << " redosAvail="<<redosAvail<<endl;
1066 cout << " curStep="<<curStep<<endl;
1067 cout << " ---------------------------"<<endl;
1068 cout << " comment="<<comment.toStdString()<<endl;
1069 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1070 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1071 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1072 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1073 cout << " ---------------------------"<<endl<<endl;
1076 // select object before redo
1077 if (!redoSelection.isEmpty())
1078 select (redoSelection);
1081 parseAtom (redoCommand);
1084 blockSaveState=blockSaveStateOrg;
1086 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1087 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1088 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1089 undoSet.writeSettings(histPath);
1091 mainWindow->updateHistory (undoSet);
1094 /* TODO remove testing
1095 cout << "ME::redo() end\n";
1096 cout << " undosAvail="<<undosAvail<<endl;
1097 cout << " redosAvail="<<redosAvail<<endl;
1098 cout << " curStep="<<curStep<<endl;
1099 cout << " ---------------------------"<<endl<<endl;
1105 bool VymModel::isRedoAvailable()
1107 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1113 void VymModel::undo()
1115 // Can we undo at all?
1116 if (undosAvail<1) return;
1118 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1120 bool blockSaveStateOrg=blockSaveState;
1121 blockSaveState=true;
1123 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1124 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1125 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1126 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1127 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1128 QString version=undoSet.readEntry ("/history/version");
1130 /* TODO Maybe check for version, if we save the history
1131 if (!checkVersion(version))
1132 QMessageBox::warning(0,tr("Warning"),
1133 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1136 // Find out current undo directory
1137 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1139 // select object before undo
1140 if (!undoSelection.isEmpty())
1141 select (undoSelection);
1145 cout << "VymModel::undo() begin\n";
1146 cout << " undosAvail="<<undosAvail<<endl;
1147 cout << " redosAvail="<<redosAvail<<endl;
1148 cout << " curStep="<<curStep<<endl;
1149 cout << " ---------------------------"<<endl;
1150 cout << " comment="<<comment.toStdString()<<endl;
1151 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1152 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1153 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1154 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1155 cout << " ---------------------------"<<endl<<endl;
1157 parseAtom (undoCommand);
1162 if (curStep<1) curStep=stepsTotal;
1166 blockSaveState=blockSaveStateOrg;
1167 /* TODO remove testing
1168 cout << "VymModel::undo() end\n";
1169 cout << " undosAvail="<<undosAvail<<endl;
1170 cout << " redosAvail="<<redosAvail<<endl;
1171 cout << " curStep="<<curStep<<endl;
1172 cout << " ---------------------------"<<endl<<endl;
1175 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1176 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1177 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1178 undoSet.writeSettings(histPath);
1180 mainWindow->updateHistory (undoSet);
1182 emitSelectionChanged();
1185 bool VymModel::isUndoAvailable()
1187 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1193 void VymModel::gotoHistoryStep (int i)
1195 // Restore variables
1196 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1197 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1199 if (i<0) i=undosAvail+redosAvail;
1201 // Clicking above current step makes us undo things
1204 for (int j=0; j<undosAvail-i; j++) undo();
1207 // Clicking below current step makes us redo things
1209 for (int j=undosAvail; j<i; j++)
1211 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1215 // And ignore clicking the current row ;-)
1219 QString VymModel::getHistoryPath()
1221 QString histName(QString("history-%1").arg(curStep));
1222 return (tmpMapDir+"/"+histName);
1225 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1227 sendData(redoCom); //FIXME-3 testing
1232 if (blockSaveState) return;
1234 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1236 // Find out current undo directory
1237 if (undosAvail<stepsTotal) undosAvail++;
1239 if (curStep>stepsTotal) curStep=1;
1241 QString backupXML="";
1242 QString histDir=getHistoryPath();
1243 QString bakMapPath=histDir+"/map.xml";
1245 // Create histDir if not available
1248 makeSubDirs (histDir);
1250 // Save depending on how much needs to be saved
1252 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1254 QString undoCommand="";
1255 if (savemode==UndoCommand)
1257 undoCommand=undoCom;
1259 else if (savemode==PartOfMap )
1261 undoCommand=undoCom;
1262 undoCommand.replace ("PATH",bakMapPath);
1266 if (!backupXML.isEmpty())
1267 // Write XML Data to disk
1268 saveStringToDisk (bakMapPath,backupXML);
1270 // We would have to save all actions in a tree, to keep track of
1271 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1274 // Write the current state to disk
1275 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1276 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1277 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1278 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1279 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1280 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1281 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1282 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1283 undoSet.setEntry (QString("/history/version"),vymVersion);
1284 undoSet.writeSettings(histPath);
1288 // TODO remove after testing
1289 //cout << " into="<< histPath.toStdString()<<endl;
1290 cout << " stepsTotal="<<stepsTotal<<
1291 ", undosAvail="<<undosAvail<<
1292 ", redosAvail="<<redosAvail<<
1293 ", curStep="<<curStep<<endl;
1294 cout << " ---------------------------"<<endl;
1295 cout << " comment="<<comment.toStdString()<<endl;
1296 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1297 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1298 cout << " redoCom="<<redoCom.toStdString()<<endl;
1299 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1300 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1301 cout << " ---------------------------"<<endl;
1304 mainWindow->updateHistory (undoSet);
1310 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1312 // save the selected part of the map, Undo will replace part of map
1313 QString undoSelection="";
1315 undoSelection=getSelectString(undoSel);
1317 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1318 QString redoSelection="";
1320 redoSelection=getSelectString(undoSel);
1322 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1325 saveState (PartOfMap,
1326 undoSelection, "addMapReplace (\"PATH\")",
1332 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1336 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1339 QString undoSelection=getSelectString (redoSel->parent() );
1340 QString redoSelection=getSelectString(redoSel);
1341 if (redoSel->getType()==TreeItem::Branch)
1343 // save the selected branch of the map, Undo will insert part of map
1344 saveState (PartOfMap,
1345 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1346 redoSelection, "delete ()",
1353 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *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
1359 QString redoSelection="";
1360 if (redoSel) redoSelection=getSelectString(redoSel);
1361 QString undoSelection="";
1362 if (undoSel) undoSelection=getSelectString(undoSel);
1364 saveState (UndoCommand,
1371 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1373 // "Normal" savestate: save commands, selections and comment
1374 // so just save commands for undo and redo
1375 // and use current selection
1376 saveState (UndoCommand,
1383 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1385 // "Normal" savestate applied to model (no selection needed):
1386 // save commands and comment
1387 saveState (UndoCommand,
1395 QGraphicsScene* VymModel::getScene ()
1400 TreeItem* VymModel::findBySelectString(QString s)
1402 if (s.isEmpty() ) return NULL;
1404 // Old maps don't have multiple mapcenters and don't save full path
1405 if (s.left(2) !="mc")
1408 QStringList parts=s.split (",");
1411 TreeItem *ti=rootItem;
1413 while (!parts.isEmpty() )
1415 typ=parts.first().left(2);
1416 n=parts.first().right(parts.first().length() - 3).toInt();
1417 parts.removeFirst();
1418 if (typ=="mc" || typ=="bo")
1419 ti=ti->getBranchNum (n);
1423 ti=ti->getImageNum (n);
1429 TreeItem* VymModel::findID (const QString &s)
1432 for (int i=0; i<rootItem->branchCount(); i++)
1434 ti=rootItem->getBranchNum(i)->findID (s);
1440 //////////////////////////////////////////////
1442 //////////////////////////////////////////////
1443 void VymModel::setVersion (const QString &s)
1448 void VymModel::setAuthor (const QString &s)
1451 QString ("setMapAuthor (\"%1\")").arg(author),
1452 QString ("setMapAuthor (\"%1\")").arg(s),
1453 QString ("Set author of map to \"%1\"").arg(s)
1458 QString VymModel::getAuthor()
1463 void VymModel::setComment (const QString &s)
1466 QString ("setMapComment (\"%1\")").arg(comment),
1467 QString ("setMapComment (\"%1\")").arg(s),
1468 QString ("Set comment of map")
1473 QString VymModel::getComment ()
1478 QString VymModel::getDate ()
1480 return QDate::currentDate().toString ("yyyy-MM-dd");
1483 int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1486 BranchItem *cur=NULL;
1487 BranchItem *prev=NULL;
1497 void VymModel::setHeading(const QString &s)
1499 BranchItem *selbi=getSelectedBranchItem();
1504 "setHeading (\""+selbi->getHeading()+"\")",
1506 "setHeading (\""+s+"\")",
1507 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1508 selbi->setHeading(s );
1509 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1512 emitSelectionChanged();
1516 BranchItem* VymModel::findText (QString s, bool cs)
1518 QTextDocument::FindFlags flags=0;
1519 if (cs) flags=QTextDocument::FindCaseSensitively;
1522 { // Nothing found or new find process
1524 // nothing found, start again
1528 next (findCurrent,findPrevious);
1530 bool searching=true;
1531 bool foundNote=false;
1532 while (searching && !EOFind)
1536 // Searching in Note
1537 if (findCurrent->getNote().contains(s,cs))
1539 select (findCurrent);
1541 if (getSelectedBranch()!=itFind)
1544 emitShowSelection();
1547 if (textEditor->findText(s,flags))
1553 // Searching in Heading
1554 if (searching && findCurrent->getHeading().contains (s,cs) )
1556 select(findCurrent);
1562 if (!next(findCurrent,findPrevious) )
1565 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1568 return getSelectedBranchItem();
1573 void VymModel::findReset()
1574 { // Necessary if text to find changes during a find process
1580 void VymModel::setScene (QGraphicsScene *s)
1582 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1583 //init(); // Here we have a mapScene set,
1584 // which is (still) needed to create MapCenters
1587 void VymModel::setURL(const QString &url)
1589 TreeItem *selti=getSelectedItem();
1592 QString oldurl=selti->getURL();
1593 selti->setURL (url);
1596 QString ("setURL (\"%1\")").arg(oldurl),
1598 QString ("setURL (\"%1\")").arg(url),
1599 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1602 emitDataHasChanged (selti);
1603 emitShowSelection();
1607 QString VymModel::getURL()
1609 TreeItem *selti=getSelectedItem();
1611 return selti->getURL();
1616 QStringList VymModel::getURLs()
1619 BranchItem *selbi=getSelectedBranchItem();
1620 BranchItem *cur=selbi;
1621 BranchItem *prev=NULL;
1624 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1625 cur=next (cur,prev,selbi);
1630 void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-1
1632 //FIXME-1 FloatImageObj *fio=selection.getFloatImage();
1633 FloatImageObj *fio=NULL;
1636 TreeItem *dst=findBySelectString (dstString);
1637 if (dst && dst->isBranchLikeType() )
1639 TreeItem *dstPar=dst->parent();
1640 QString parString=getSelectString(dstPar);
1641 QString fioPreSelectString=getSelectString(fio);
1642 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1643 // FIXME-1 ((BranchObj*)dst)->addFloatImage (fio);
1645 // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1646 fio=((BranchObj*)dst)->getLastFloatImage();
1651 getSelectString(fio),
1652 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1654 QString ("linkTo (\"%1\")").arg(dstString),
1655 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1661 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
1664 BranchObj *bo=getSelectedBranch();
1667 QString s=bo->getFrameTypeName();
1668 bo->setFrameType (t);
1669 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1670 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1677 void VymModel::setFrameType(const QString &s) //FIXME-2
1680 BranchObj *bo=getSelectedBranch();
1683 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1684 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1685 bo->setFrameType (s);
1692 void VymModel::setFramePenColor(const QColor &c) //FIXME-2
1695 BranchObj *bo=getSelectedBranch();
1698 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1699 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1700 bo->setFramePenColor (c);
1705 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
1708 BranchObj *bo=getSelectedBranch();
1711 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1712 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1713 bo->setFrameBrushColor (c);
1717 void VymModel::setFramePadding (const int &i) //FIXME-2
1720 BranchObj *bo=getSelectedBranch();
1723 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1724 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1725 bo->setFramePadding (i);
1732 void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
1735 BranchObj *bo=getSelectedBranch();
1738 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1739 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1740 bo->setFrameBorderWidth (i);
1747 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1750 BranchObj *bo=getSelectedBranch();
1753 QString u= b ? "false" : "true";
1754 QString r=!b ? "false" : "true";
1758 QString("setIncludeImagesVertically (%1)").arg(u),
1760 QString("setIncludeImagesVertically (%1)").arg(r),
1761 QString("Include images vertically in %1").arg(getObjectName(bo))
1763 bo->setIncludeImagesVer(b);
1768 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1771 BranchObj *bo=getSelectedBranch();
1774 QString u= b ? "false" : "true";
1775 QString r=!b ? "false" : "true";
1779 QString("setIncludeImagesHorizontally (%1)").arg(u),
1781 QString("setIncludeImagesHorizontally (%1)").arg(r),
1782 QString("Include images horizontally in %1").arg(getObjectName(bo))
1784 bo->setIncludeImagesHor(b);
1790 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1793 LinkableMapObj *sel=getSelectedLMO();
1795 (selectionType() == TreeItem::Branch ||
1796 selectionType() == TreeItem::MapCenter ||
1797 selectionType() == TreeItem::Image ))
1799 QString u= b ? "false" : "true";
1800 QString r=!b ? "false" : "true";
1804 QString("setHideLinkUnselected (%1)").arg(u),
1806 QString("setHideLinkUnselected (%1)").arg(r),
1807 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1809 sel->setHideLinkUnselected(b);
1814 void VymModel::setHideExport(bool b)
1816 BranchItem *bi=getSelectedBranchItem();
1819 bi->setHideInExport (b);
1820 QString u= b ? "false" : "true";
1821 QString r=!b ? "false" : "true";
1825 QString ("setHideExport (%1)").arg(u),
1827 QString ("setHideExport (%1)").arg(r),
1828 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
1832 // emitSelectionChanged();
1833 // FIXME-3 VM needed? scene()->update();
1837 void VymModel::toggleHideExport()
1839 BranchItem *selbi=getSelectedBranchItem();
1841 setHideExport ( !selbi->hideInExport() );
1845 void VymModel::copy()
1847 TreeItem *selti=getSelectedItem();
1849 (selti->getType() == TreeItem::Branch ||
1850 selti->getType() == TreeItem::MapCenter ||
1851 selti->getType() == TreeItem::Image ))
1853 if (redosAvail == 0)
1856 QString s=getSelectString(selti);
1857 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1858 curClipboard=curStep;
1861 // Copy also to global clipboard, because we are at last step in history
1862 QString bakMapName(QString("history-%1").arg(curStep));
1863 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1864 copyDir (bakMapDir,clipboardDir );
1866 clipboardEmpty=false;
1872 void VymModel::pasteNoSave(const int &n)
1874 bool old=blockSaveState;
1875 blockSaveState=true;
1876 bool zippedOrg=zipped;
1877 if (redosAvail > 0 || n!=0)
1879 // Use the "historical" buffer
1880 QString bakMapName(QString("history-%1").arg(n));
1881 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1882 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1884 // Use the global buffer
1885 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1890 void VymModel::paste()
1892 BranchItem *selbi=getSelectedBranchItem();
1895 saveStateChangingPart(
1898 QString ("paste (%1)").arg(curClipboard),
1899 QString("Paste to %1").arg( getObjectName(selbi))
1906 void VymModel::cut()
1908 TreeItem *selti=getSelectedItem();
1909 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1917 void VymModel::moveUp()
1919 BranchItem *selbi=getSelectedBranchItem();
1922 if (!selbi->canMoveUp()) return;
1923 QString oldsel=getSelectString();
1924 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1926 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1930 void VymModel::moveDown()
1932 BranchItem *selbi=getSelectedBranchItem();
1935 if (!selbi->canMoveDown()) return;
1936 QString oldsel=getSelectString();
1937 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1939 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1943 void VymModel::sortChildren() // FIXME-2 not implemented yet
1946 BranchObj* bo=getSelectedBranch();
1949 if(treeItem->branchCount()>1)
1951 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1954 emitShowSelection();
1960 BranchItem* VymModel::createMapCenter()
1962 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1966 BranchItem* VymModel::createBranch(BranchItem *dst)
1969 return addNewBranchInt (dst,-2);
1974 TreeItem* VymModel::createImage(BranchItem *dst) //FIXME-1
1980 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1983 QList<QVariant> cData;
1984 cData << "VM:createImage" << "undef"<<"undef";
1985 TreeItem *parti=bo->getTreeItem();
1986 TreeItem *ti=new TreeItem (cData,parti);
1987 ti->setLMO (newfio);
1988 ti->setType (TreeItem::Image);
1989 parti->appendChild (ti);
1993 newfio->setTreeItem (ti);
1994 select (newfio); // FIXME-2 VM really needed here?
2001 BranchItem* VymModel::addMapCenter ()
2003 BranchItem *bi=addMapCenter (contextPos);
2005 emitShowSelection();
2010 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2011 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2016 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2017 // createMapCenter could then probably be merged with createBranch
2021 QModelIndex parix=index(rootItem);
2023 int n=rootItem->branchCount();
2025 emit (layoutAboutToBeChanged() );
2026 beginInsertRows (parix,n,n+1);
2028 QList<QVariant> cData;
2029 cData << "VM:addMapCenter" << "undef"<<"undef";
2030 BranchItem *newbi=new BranchItem (cData);
2031 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2032 rootItem->appendChild (newbi);
2035 emit (layoutChanged() );
2038 newbi->setPositionMode (MapItem::Absolute);
2039 newbi->createMapObj(mapScene);
2044 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2046 // Depending on pos:
2047 // -3 insert in children of parent above selection
2048 // -2 add branch to selection
2049 // -1 insert in children of parent below selection
2050 // 0..n insert in children of parent at pos
2053 QList<QVariant> cData;
2054 cData << "new" << "undef"<<"undef";
2059 BranchItem *newbi=new BranchItem (cData);
2060 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2062 emit (layoutAboutToBeChanged() );
2068 n=parbi->childCount();
2069 beginInsertRows (parix,n,n+1);
2070 parbi->appendChild (newbi);
2072 }else if (num==-1 || num==-3)
2074 // insert below selection
2075 parbi=(BranchItem*)dst->parent();
2077 n=dst->childNumber()+ (3+num)/2; //-1 |-> 1;-3 |-> 0
2078 beginInsertRows (parix,n,n);
2079 parbi->insertBranch(n,newbi);
2082 emit (layoutChanged() );
2084 // save scroll state. If scrolled, automatically select
2085 // new branch in order to tmp unscroll parent...
2086 newbi->createMapObj(mapScene);
2091 BranchItem* VymModel::addNewBranch(int pos)
2093 // Different meaning than num in addNewBranchInt!
2097 BranchItem *newbi=NULL;
2098 BranchItem *selbi=getSelectedBranchItem();
2102 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2104 newbi=addNewBranchInt (selbi,pos-2);
2112 QString ("addBranch (%1)").arg(pos),
2113 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2116 // emitSelectionChanged(); FIXME-3
2117 latestAddedItem=newbi;
2118 // In Network mode, the client needs to know where the new branch is,
2119 // so we have to pass on this information via saveState.
2120 // TODO: Get rid of this positioning workaround
2121 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2122 sendData ("selectLatestAdded ()");
2123 sendData (QString("move %1").arg(ps));
2132 BranchItem* VymModel::addNewBranchBefore()
2134 BranchItem *newbi=NULL;
2135 BranchItem *selbi=getSelectedBranchItem();
2136 if (selbi && selbi->getType()==TreeItem::Branch)
2137 // We accept no MapCenter here, so we _have_ a parent
2139 //QPointF p=bo->getRelPos();
2142 // add below selection
2143 newbi=addNewBranchInt (selbi,-1);
2147 //newbi->move2RelPos (p);
2149 // Move selection to new branch
2150 relinkBranch (selbi,newbi,0);
2152 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2153 QString ("Add branch before %1").arg(getObjectName(selbi)));
2155 // FIXME-3 needed? reposition();
2156 // emitSelectionChanged(); FIXME-3
2162 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2166 if (branch->depth()==0)
2168 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2170 emit (layoutAboutToBeChanged() );
2171 BranchItem *branchpi=(BranchItem*)branch->parent();
2172 // Remove at current position
2173 int n=branch->childNum();
2174 beginRemoveRows (index(branchpi),n,n);
2175 branchpi->removeChild (n);
2178 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2180 // Append as last branch to dst
2181 if (dst->branchCount()==0)
2184 n=dst->getFirstBranch()->childNumber();
2185 beginInsertRows (index(dst),n+pos,n+pos);
2186 dst->insertBranch (pos,branch);
2189 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2190 branch->updateStyles();
2192 emit (layoutChanged() );
2193 reposition(); // both for moveUp/Down and relinking
2200 void VymModel::deleteSelection()
2202 BranchItem *selbi=getSelectedBranchItem();
2206 TreeItem *pi=selbi->parent();
2207 QModelIndex parentIndex=index(pi);
2209 if (selbi->isBranchLikeType() )
2212 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2214 emit (layoutAboutToBeChanged() );
2216 int n=selbi->childNum();
2217 beginRemoveRows (parentIndex,n,n);
2218 removeRows (n,1,parentIndex);
2221 emitShowSelection();
2224 emit (layoutChanged() );
2227 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2232 BranchObj* par=(BranchObj*)fio->getParObj();
2233 saveStateChangingPart(
2237 QString("Delete %1").arg(getObjectName(fio))
2240 par->removeFloatImage(fio);
2243 emitShowSelection();
2249 void VymModel::deleteKeepChildren()
2252 BranchItem *selbi=getSelectedBranchItem();
2256 // Don't use this on mapcenter
2257 if (selbi->depth()<2) return;
2259 pi=(BranchItem*)(selbi->parent());
2260 // Check if we have childs at all to keep
2261 if (selbi->branchCount()==0)
2268 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2269 saveStateChangingPart(
2272 "deleteKeepChildren ()",
2273 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2276 QString sel=getSelectString(selbi);
2278 //FIXME-0 missing in VM pi->removeBranchHere(selbi);
2281 BranchObj *bo=getSelectedBranchObj();
2284 bo->move2RelPos (p);
2290 void VymModel::deleteChildren()
2293 BranchItem *selbi=getSelectedBranchItem();
2296 saveStateChangingPart(
2299 "deleteChildren ()",
2300 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2302 emit (layoutAboutToBeChanged() );
2304 QModelIndex ix=index (selbi);
2305 int n=selbi->branchCount()-1;
2306 beginRemoveRows (ix,0,n);
2307 removeRows (0,n+1,ix);
2309 emit (layoutChanged() );
2314 bool VymModel::scrollBranch(BranchItem *bi)
2318 if (bi->isScrolled()) return false;
2319 if (bi->branchCount()==0) return false;
2320 if (bi->depth()==0) return false;
2321 if (bi->toggleScroll())
2328 QString ("%1 ()").arg(u),
2330 QString ("%1 ()").arg(r),
2331 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2333 emitDataHasChanged(bi);
2334 emitSelectionChanged();
2335 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2342 bool VymModel::unscrollBranch(BranchItem *bi)
2346 if (!bi->isScrolled()) return false;
2347 if (bi->branchCount()==0) return false;
2348 if (bi->depth()==0) return false;
2355 QString ("%1 ()").arg(u),
2357 QString ("%1 ()").arg(r),
2358 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2361 emitDataHasChanged(bi);
2362 emitSelectionChanged();
2364 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2370 void VymModel::toggleScroll()
2372 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2373 if (bi && bi->isBranchLikeType() )
2375 if (bi->isScrolled())
2376 unscrollBranch (bi);
2380 // saveState is called in above functions
2383 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2387 BranchObj *bo=getSelectedBranch();
2393 if (bo->isScrolled()) unscrollBranch (bo);
2400 void VymModel::emitExpandAll()
2402 emit (expandAll() );
2405 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2407 BranchItem *bi=getSelectedBranchItem();
2411 if (bi->isActiveStandardFlag(name))
2423 QString("%1 (\"%2\")").arg(u).arg(name),
2425 QString("%1 (\"%2\")").arg(r).arg(name),
2426 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2427 bi->toggleStandardFlag (name, master);
2429 emitSelectionChanged();
2433 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2436 BranchObj *bo=getSelectedBranch();
2439 FloatImageObj *fio=bo->addFloatImage();
2441 fio->setOriginalFilename("No original filename (image added by dropevent)");
2442 QString s=getSelectString(bo);
2443 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2444 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2446 // FIXME-3 VM needed? scene()->update();
2452 void VymModel::colorBranch (QColor c)
2454 BranchItem *selbi=getSelectedBranchItem();
2459 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2461 QString ("colorBranch (\"%1\")").arg(c.name()),
2462 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2464 selbi->setHeadingColor(c); // color branch
2468 void VymModel::colorSubtree (QColor c)
2470 BranchItem *selbi=getSelectedBranchItem();
2473 saveStateChangingPart(
2476 QString ("colorSubtree (\"%1\")").arg(c.name()),
2477 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2479 BranchItem *prev=NULL;
2480 BranchItem *cur=selbi;
2483 cur->setHeadingColor(c); // color links, color children
2484 cur=next (cur,prev,selbi);
2490 QColor VymModel::getCurrentHeadingColor()
2492 BranchItem *selbi=getSelectedBranchItem();
2493 if (selbi) return selbi->getHeadingColor();
2495 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2501 void VymModel::editURL()
2503 TreeItem *selti=getSelectedItem();
2507 QString text = QInputDialog::getText(
2508 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2509 selti->getURL(), &ok, NULL);
2511 // user entered something and pressed OK
2516 void VymModel::editLocalURL()
2518 TreeItem *selti=getSelectedItem();
2521 QStringList filters;
2522 filters <<"All files (*)";
2523 filters << tr("Text","Filedialog") + " (*.txt)";
2524 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2525 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2526 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2527 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2528 fd->setFilters (filters);
2529 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2530 fd->setDirectory (lastFileDir);
2531 if (! selti->getVymLink().isEmpty() )
2532 fd->selectFile( selti->getURL() );
2535 if ( fd->exec() == QDialog::Accepted )
2537 lastFileDir=QDir (fd->directory().path());
2538 setURL (fd->selectedFile() );
2544 void VymModel::editHeading2URL()
2546 TreeItem *selti=getSelectedItem();
2548 setURL (selti->getHeading());
2551 void VymModel::editBugzilla2URL()
2553 TreeItem *selti=getSelectedItem();
2556 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2561 void VymModel::editFATE2URL()
2563 TreeItem *selti=getSelectedItem();
2566 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2569 "setURL (\""+selti->getURL()+"\")",
2571 "setURL (\""+url+"\")",
2572 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2574 selti->setURL (url);
2575 // FIXME-4 updateActions();
2579 void VymModel::editVymLink()
2581 BranchItem *bi=getSelectedBranchItem();
2584 QStringList filters;
2585 filters <<"VYM map (*.vym)";
2586 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2587 fd->setFilters (filters);
2588 fd->setCaption(vymName+" - " +tr("Link to another map"));
2589 fd->setDirectory (lastFileDir);
2590 if (! bi->getVymLink().isEmpty() )
2591 fd->selectFile( bi->getVymLink() );
2595 if ( fd->exec() == QDialog::Accepted )
2597 lastFileDir=QDir (fd->directory().path());
2600 "setVymLink (\""+bi->getVymLink()+"\")",
2602 "setVymLink (\""+fd->selectedFile()+"\")",
2603 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2605 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2610 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2612 // Internal function, no saveState needed
2613 BranchItem *bi=getSelectedBranchItem();
2619 //emitSelectionChanged();
2623 void VymModel::deleteVymLink()
2625 BranchItem *bi=getSelectedBranchItem();
2630 "setVymLink (\""+bi->getVymLink()+"\")",
2632 "setVymLink (\"\")",
2633 QString("Unset vymlink of %1").arg(getObjectName(bi))
2635 bi->setVymLink ("" );
2641 QString VymModel::getVymLink()
2643 BranchItem *bi=getSelectedBranchItem();
2645 return bi->getVymLink();
2651 QStringList VymModel::getVymLinks()
2654 BranchItem *selbi=getSelectedBranchItem();
2655 BranchItem *cur=selbi;
2656 BranchItem *prev=NULL;
2659 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2660 cur=next (cur,prev,selbi);
2666 void VymModel::followXLink(int i) // FIXME-2
2670 BranchObj *bo=getSelectedBranch();
2673 bo=bo->XLinkTargetAt(i);
2676 selection.select(bo);
2677 emitShowSelection();
2683 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2687 BranchObj *bo=getSelectedBranch();
2690 XLinkObj *xlo=bo->XLinkAt(i);
2693 EditXLinkDialog dia;
2695 dia.setSelection(bo);
2696 if (dia.exec() == QDialog::Accepted)
2698 if (dia.useSettingsGlobal() )
2700 setMapDefXLinkColor (xlo->getColor() );
2701 setMapDefXLinkWidth (xlo->getWidth() );
2703 if (dia.deleteXLink())
2704 bo->deleteXLinkAt(i);
2715 //////////////////////////////////////////////
2717 //////////////////////////////////////////////
2719 void VymModel::parseAtom(const QString &atom)
2721 TreeItem* selti=getSelectedItem();
2722 BranchItem *selbi=getSelectedBranchItem();
2728 // Split string s into command and parameters
2729 parser.parseAtom (atom);
2730 QString com=parser.getCommand();
2732 // External commands
2733 /////////////////////////////////////////////////////////////////////
2734 if (com=="addBranch")
2738 parser.setError (Aborted,"Nothing selected");
2739 } else if (! selbi )
2741 parser.setError (Aborted,"Type of selection is not a branch");
2746 if (parser.checkParCount(pl))
2748 if (parser.parCount()==0)
2752 n=parser.parInt (ok,0);
2753 if (ok ) addNewBranch (n);
2757 /////////////////////////////////////////////////////////////////////
2758 } else if (com=="addBranchBefore")
2762 parser.setError (Aborted,"Nothing selected");
2763 } else if (! selbi )
2765 parser.setError (Aborted,"Type of selection is not a branch");
2768 if (parser.parCount()==0)
2770 addNewBranchBefore ();
2773 /////////////////////////////////////////////////////////////////////
2774 } else if (com==QString("addMapCenter"))
2776 if (parser.checkParCount(2))
2778 x=parser.parDouble (ok,0);
2781 y=parser.parDouble (ok,1);
2782 if (ok) addMapCenter (QPointF(x,y));
2785 /////////////////////////////////////////////////////////////////////
2786 } else if (com==QString("addMapReplace"))
2790 parser.setError (Aborted,"Nothing selected");
2791 } else if (! selbi )
2793 parser.setError (Aborted,"Type of selection is not a branch");
2794 } else if (parser.checkParCount(1))
2796 //s=parser.parString (ok,0); // selection
2797 t=parser.parString (ok,0); // path to map
2798 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2799 addMapReplaceInt(getSelectString(selbi),t);
2801 /////////////////////////////////////////////////////////////////////
2802 } else if (com==QString("addMapInsert"))
2806 parser.setError (Aborted,"Nothing selected");
2807 } else if (! selbi )
2809 parser.setError (Aborted,"Type of selection is not a branch");
2812 if (parser.checkParCount(2))
2814 t=parser.parString (ok,0); // path to map
2815 n=parser.parInt(ok,1); // position
2816 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2817 addMapInsertInt(t,n);
2820 /////////////////////////////////////////////////////////////////////
2821 } else if (com=="clearFlags")
2825 parser.setError (Aborted,"Nothing selected");
2826 } else if (! selbi )
2828 parser.setError (Aborted,"Type of selection is not a branch");
2829 } else if (parser.checkParCount(0))
2831 selbi->deactivateAllStandardFlags();
2833 /////////////////////////////////////////////////////////////////////
2834 } else if (com=="colorBranch")
2838 parser.setError (Aborted,"Nothing selected");
2839 } else if (! selbi )
2841 parser.setError (Aborted,"Type of selection is not a branch");
2842 } else if (parser.checkParCount(1))
2844 QColor c=parser.parColor (ok,0);
2845 if (ok) colorBranch (c);
2847 /////////////////////////////////////////////////////////////////////
2848 } else if (com=="colorSubtree")
2852 parser.setError (Aborted,"Nothing selected");
2853 } else if (! selbi )
2855 parser.setError (Aborted,"Type of selection is not a branch");
2856 } else if (parser.checkParCount(1))
2858 QColor c=parser.parColor (ok,0);
2859 if (ok) colorSubtree (c);
2861 /////////////////////////////////////////////////////////////////////
2862 } else if (com=="copy")
2866 parser.setError (Aborted,"Nothing selected");
2867 } else if ( selectionType()!=TreeItem::Branch &&
2868 selectionType()!=TreeItem::MapCenter &&
2869 selectionType()!=TreeItem::Image )
2871 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2872 } else if (parser.checkParCount(0))
2876 /////////////////////////////////////////////////////////////////////
2877 } else if (com=="cut")
2881 parser.setError (Aborted,"Nothing selected");
2882 } else if ( selectionType()!=TreeItem::Branch &&
2883 selectionType()!=TreeItem::MapCenter &&
2884 selectionType()!=TreeItem::Image )
2886 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2887 } else if (parser.checkParCount(0))
2891 /////////////////////////////////////////////////////////////////////
2892 } else if (com=="delete")
2896 parser.setError (Aborted,"Nothing selected");
2898 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2900 parser.setError (Aborted,"Type of selection is wrong.");
2903 else if (parser.checkParCount(0))
2907 /////////////////////////////////////////////////////////////////////
2908 } else if (com=="deleteKeepChildren")
2912 parser.setError (Aborted,"Nothing selected");
2913 } else if (! selbi )
2915 parser.setError (Aborted,"Type of selection is not a branch");
2916 } else if (parser.checkParCount(0))
2918 deleteKeepChildren();
2920 /////////////////////////////////////////////////////////////////////
2921 } else if (com=="deleteChildren")
2925 parser.setError (Aborted,"Nothing selected");
2928 parser.setError (Aborted,"Type of selection is not a branch");
2929 } else if (parser.checkParCount(0))
2933 /////////////////////////////////////////////////////////////////////
2934 } else if (com=="exportASCII")
2938 if (parser.parCount()>=1)
2939 // Hey, we even have a filename
2940 fname=parser.parString(ok,0);
2943 parser.setError (Aborted,"Could not read filename");
2946 exportASCII (fname,false);
2948 /////////////////////////////////////////////////////////////////////
2949 } else if (com=="exportImage")
2953 if (parser.parCount()>=2)
2954 // Hey, we even have a filename
2955 fname=parser.parString(ok,0);
2958 parser.setError (Aborted,"Could not read filename");
2961 QString format="PNG";
2962 if (parser.parCount()>=2)
2964 format=parser.parString(ok,1);
2966 exportImage (fname,false,format);
2968 /////////////////////////////////////////////////////////////////////
2969 } else if (com=="exportXHTML")
2973 if (parser.parCount()>=2)
2974 // Hey, we even have a filename
2975 fname=parser.parString(ok,1);
2978 parser.setError (Aborted,"Could not read filename");
2981 exportXHTML (fname,false);
2983 /////////////////////////////////////////////////////////////////////
2984 } else if (com=="exportXML")
2988 if (parser.parCount()>=2)
2989 // Hey, we even have a filename
2990 fname=parser.parString(ok,1);
2993 parser.setError (Aborted,"Could not read filename");
2996 exportXML (fname,false);
2998 /////////////////////////////////////////////////////////////////////
2999 } else if (com=="importDir")
3003 parser.setError (Aborted,"Nothing selected");
3004 } else if (! selbi )
3006 parser.setError (Aborted,"Type of selection is not a branch");
3007 } else if (parser.checkParCount(1))
3009 s=parser.parString(ok,0);
3010 if (ok) importDirInt(s);
3012 /////////////////////////////////////////////////////////////////////
3013 } else /* FIXME-2 if (com=="linkTo")
3017 parser.setError (Aborted,"Nothing selected");
3020 if (parser.checkParCount(4))
3022 // 0 selectstring of parent
3023 // 1 num in parent (for branches)
3024 // 2,3 x,y of mainbranch or mapcenter
3025 s=parser.parString(ok,0);
3026 LinkableMapObj *dst=findObjBySelect (s);
3029 if (typid(*dst) == typid(BranchObj) )
3031 // Get number in parent
3032 n=parser.parInt (ok,1);
3035 selb->linkTo ((BranchObj*)(dst),n);
3036 emitSelectionChanged();
3038 } else if (typid(*dst) == typid(MapCenterObj) )
3040 selb->linkTo ((BranchObj*)(dst),-1);
3041 // Get coordinates of mainbranch
3042 x=parser.parDouble(ok,2);
3045 y=parser.parDouble(ok,3);
3049 emitSelectionChanged();
3055 } else if ( selectionType() == TreeItem::Image)
3057 if (parser.checkParCount(1))
3059 // 0 selectstring of parent
3060 s=parser.parString(ok,0);
3061 LinkableMapObj *dst=findObjBySelect (s);
3064 if (typid(*dst) == typid(BranchObj) ||
3065 typid(*dst) == typid(MapCenterObj))
3066 linkFloatImageTo (getSelectString(dst));
3068 parser.setError (Aborted,"Destination is not a branch");
3071 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3072 /////////////////////////////////////////////////////////////////////
3073 } else */ if (com=="loadImage")
3077 parser.setError (Aborted,"Nothing selected");
3078 } else if (! selbi )
3080 parser.setError (Aborted,"Type of selection is not a branch");
3081 } else if (parser.checkParCount(1))
3083 s=parser.parString(ok,0);
3084 if (ok) loadFloatImageInt (selbi,s);
3086 /////////////////////////////////////////////////////////////////////
3087 } else if (com=="moveUp")
3091 parser.setError (Aborted,"Nothing selected");
3092 } else if (! selbi )
3094 parser.setError (Aborted,"Type of selection is not a branch");
3095 } else if (parser.checkParCount(0))
3099 /////////////////////////////////////////////////////////////////////
3100 } else if (com=="moveDown")
3104 parser.setError (Aborted,"Nothing selected");
3105 } else if (! selbi )
3107 parser.setError (Aborted,"Type of selection is not a branch");
3108 } else if (parser.checkParCount(0))
3112 /////////////////////////////////////////////////////////////////////
3113 } else if (com=="move")
3117 parser.setError (Aborted,"Nothing selected");
3118 } else if ( selectionType()!=TreeItem::Branch &&
3119 selectionType()!=TreeItem::MapCenter &&
3120 selectionType()!=TreeItem::Image )
3122 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3123 } else if (parser.checkParCount(2))
3125 x=parser.parDouble (ok,0);
3128 y=parser.parDouble (ok,1);
3132 /////////////////////////////////////////////////////////////////////
3133 } else if (com=="moveRel")
3137 parser.setError (Aborted,"Nothing selected");
3138 } else if ( selectionType()!=TreeItem::Branch &&
3139 selectionType()!=TreeItem::MapCenter &&
3140 selectionType()!=TreeItem::Image )
3142 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3143 } else if (parser.checkParCount(2))
3145 x=parser.parDouble (ok,0);
3148 y=parser.parDouble (ok,1);
3149 if (ok) moveRel (x,y);
3152 /////////////////////////////////////////////////////////////////////
3153 } else if (com=="nop")
3155 /////////////////////////////////////////////////////////////////////
3156 } else if (com=="paste")
3160 parser.setError (Aborted,"Nothing selected");
3161 } else if (! selbi )
3163 parser.setError (Aborted,"Type of selection is not a branch");
3164 } else if (parser.checkParCount(1))
3166 n=parser.parInt (ok,0);
3167 if (ok) pasteNoSave(n);
3169 /////////////////////////////////////////////////////////////////////
3170 } else if (com=="qa")
3174 parser.setError (Aborted,"Nothing selected");
3175 } else if (! selbi )
3177 parser.setError (Aborted,"Type of selection is not a branch");
3178 } else if (parser.checkParCount(4))
3181 c=parser.parString (ok,0);
3184 parser.setError (Aborted,"No comment given");
3187 s=parser.parString (ok,1);
3190 parser.setError (Aborted,"First parameter is not a string");
3193 t=parser.parString (ok,2);
3196 parser.setError (Aborted,"Condition is not a string");
3199 u=parser.parString (ok,3);
3202 parser.setError (Aborted,"Third parameter is not a string");
3207 parser.setError (Aborted,"Unknown type: "+s);
3212 parser.setError (Aborted,"Unknown operator: "+t);
3217 parser.setError (Aborted,"Type of selection is not a branch");
3220 if (selbi->getHeading() == u)
3222 cout << "PASSED: " << qPrintable (c) << endl;
3225 cout << "FAILED: " << qPrintable (c) << endl;
3235 /////////////////////////////////////////////////////////////////////
3236 } else if (com=="saveImage")
3238 //FIXME-2 FloatImageObj *fio=selection.getFloatImage();
3239 FloatImageObj* fio=NULL;
3242 parser.setError (Aborted,"Type of selection is not an image");
3243 } else if (parser.checkParCount(2))
3245 s=parser.parString(ok,0);
3248 t=parser.parString(ok,1);
3249 if (ok) saveFloatImageInt (fio,t,s);
3252 /////////////////////////////////////////////////////////////////////
3253 } else if (com=="scroll")
3257 parser.setError (Aborted,"Nothing selected");
3258 } else if (! selbi )
3260 parser.setError (Aborted,"Type of selection is not a branch");
3261 } else if (parser.checkParCount(0))
3263 if (!scrollBranch (selbi))
3264 parser.setError (Aborted,"Could not scroll branch");
3266 /////////////////////////////////////////////////////////////////////
3267 } else if (com=="select")
3269 if (parser.checkParCount(1))
3271 s=parser.parString(ok,0);
3274 /////////////////////////////////////////////////////////////////////
3275 } else if (com=="selectLastBranch")
3279 parser.setError (Aborted,"Nothing selected");
3280 } else if (! selbi )
3282 parser.setError (Aborted,"Type of selection is not a branch");
3283 } else if (parser.checkParCount(0))
3285 BranchItem *bi=selbi->getLastBranch();
3287 parser.setError (Aborted,"Could not select last branch");
3288 select (bi); // FIXME-3 was selectInt
3291 /////////////////////////////////////////////////////////////////////
3292 } else /* FIXME-2 if (com=="selectLastImage")
3296 parser.setError (Aborted,"Nothing selected");
3297 } else if (! selbi )
3299 parser.setError (Aborted,"Type of selection is not a branch");
3300 } else if (parser.checkParCount(0))
3302 FloatImageObj *fio=selb->getLastFloatImage();
3304 parser.setError (Aborted,"Could not select last image");
3305 select (fio); // FIXME-3 was selectInt
3308 /////////////////////////////////////////////////////////////////////
3309 } else */ if (com=="selectLatestAdded")
3311 if (!latestAddedItem)
3313 parser.setError (Aborted,"No latest added object");
3316 if (!select (latestAddedItem))
3317 parser.setError (Aborted,"Could not select latest added object ");
3319 /////////////////////////////////////////////////////////////////////
3320 } else if (com=="setFrameType")
3322 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3324 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3326 else if (parser.checkParCount(1))
3328 s=parser.parString(ok,0);
3329 if (ok) setFrameType (s);
3331 /////////////////////////////////////////////////////////////////////
3332 } else if (com=="setFramePenColor")
3334 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3336 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3338 else if (parser.checkParCount(1))
3340 QColor c=parser.parColor(ok,0);
3341 if (ok) setFramePenColor (c);
3343 /////////////////////////////////////////////////////////////////////
3344 } else if (com=="setFrameBrushColor")
3346 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3348 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3350 else if (parser.checkParCount(1))
3352 QColor c=parser.parColor(ok,0);
3353 if (ok) setFrameBrushColor (c);
3355 /////////////////////////////////////////////////////////////////////
3356 } else if (com=="setFramePadding")
3358 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3360 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3362 else if (parser.checkParCount(1))
3364 n=parser.parInt(ok,0);
3365 if (ok) setFramePadding(n);
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="setFrameBorderWidth")
3370 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3372 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3374 else if (parser.checkParCount(1))
3376 n=parser.parInt(ok,0);
3377 if (ok) setFrameBorderWidth (n);
3379 /////////////////////////////////////////////////////////////////////
3380 } else if (com=="setMapAuthor")
3382 if (parser.checkParCount(1))
3384 s=parser.parString(ok,0);
3385 if (ok) setAuthor (s);
3387 /////////////////////////////////////////////////////////////////////
3388 } else if (com=="setMapComment")
3390 if (parser.checkParCount(1))
3392 s=parser.parString(ok,0);
3393 if (ok) setComment(s);
3395 /////////////////////////////////////////////////////////////////////
3396 } else if (com=="setMapBackgroundColor")
3400 parser.setError (Aborted,"Nothing selected");
3401 } else if (! selbi )
3403 parser.setError (Aborted,"Type of selection is not a branch");
3404 } else if (parser.checkParCount(1))
3406 QColor c=parser.parColor (ok,0);
3407 if (ok) setMapBackgroundColor (c);
3409 /////////////////////////////////////////////////////////////////////
3410 } else if (com=="setMapDefLinkColor")
3414 parser.setError (Aborted,"Nothing selected");
3415 } else if (! selbi )
3417 parser.setError (Aborted,"Type of selection is not a branch");
3418 } else if (parser.checkParCount(1))
3420 QColor c=parser.parColor (ok,0);
3421 if (ok) setMapDefLinkColor (c);
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="setMapLinkStyle")
3426 if (parser.checkParCount(1))
3428 s=parser.parString (ok,0);
3429 if (ok) setMapLinkStyle(s);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="setHeading")
3436 parser.setError (Aborted,"Nothing selected");
3437 } else if (! selbi )
3439 parser.setError (Aborted,"Type of selection is not a branch");
3440 } else if (parser.checkParCount(1))
3442 s=parser.parString (ok,0);
3446 /////////////////////////////////////////////////////////////////////
3447 } else if (com=="setHideExport")
3451 parser.setError (Aborted,"Nothing selected");
3452 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3454 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3455 } else if (parser.checkParCount(1))
3457 b=parser.parBool(ok,0);
3458 if (ok) setHideExport (b);
3460 /////////////////////////////////////////////////////////////////////
3461 } else if (com=="setIncludeImagesHorizontally")
3465 parser.setError (Aborted,"Nothing selected");
3468 parser.setError (Aborted,"Type of selection is not a branch");
3469 } else if (parser.checkParCount(1))
3471 b=parser.parBool(ok,0);
3472 if (ok) setIncludeImagesHor(b);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="setIncludeImagesVertically")
3479 parser.setError (Aborted,"Nothing selected");
3482 parser.setError (Aborted,"Type of selection is not a branch");
3483 } else if (parser.checkParCount(1))
3485 b=parser.parBool(ok,0);
3486 if (ok) setIncludeImagesVer(b);
3488 /////////////////////////////////////////////////////////////////////
3489 } else if (com=="setHideLinkUnselected")
3493 parser.setError (Aborted,"Nothing selected");
3494 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3496 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3497 } else if (parser.checkParCount(1))
3499 b=parser.parBool(ok,0);
3500 if (ok) setHideLinkUnselected(b);
3502 /////////////////////////////////////////////////////////////////////
3503 } else if (com=="setSelectionColor")
3505 if (parser.checkParCount(1))
3507 QColor c=parser.parColor (ok,0);
3508 if (ok) setSelectionColorInt (c);
3510 /////////////////////////////////////////////////////////////////////
3511 } else if (com=="setURL")
3515 parser.setError (Aborted,"Nothing selected");
3516 } else if (! selbi )
3518 parser.setError (Aborted,"Type of selection is not a branch");
3519 } else if (parser.checkParCount(1))
3521 s=parser.parString (ok,0);
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="setVymLink")
3529 parser.setError (Aborted,"Nothing selected");
3530 } else if (! selbi )
3532 parser.setError (Aborted,"Type of selection is not a branch");
3533 } else if (parser.checkParCount(1))
3535 s=parser.parString (ok,0);
3536 if (ok) setVymLink(s);
3539 /////////////////////////////////////////////////////////////////////
3540 else if (com=="setFlag")
3544 parser.setError (Aborted,"Nothing selected");
3545 } else if (! selbi )
3547 parser.setError (Aborted,"Type of selection is not a branch");
3548 } else if (parser.checkParCount(1))
3550 s=parser.parString(ok,0);
3552 selbi->activateStandardFlag(s);
3554 /////////////////////////////////////////////////////////////////////
3555 } else /* FIXME-2 if (com=="setFrameType")
3559 parser.setError (Aborted,"Nothing selected");
3562 parser.setError (Aborted,"Type of selection is not a branch");
3563 } else if (parser.checkParCount(1))
3565 s=parser.parString(ok,0);
3569 /////////////////////////////////////////////////////////////////////
3570 } else*/ if (com=="sortChildren")
3574 parser.setError (Aborted,"Nothing selected");
3575 } else if (! selbi )
3577 parser.setError (Aborted,"Type of selection is not a branch");
3578 } else if (parser.checkParCount(0))
3582 /////////////////////////////////////////////////////////////////////
3583 } else if (com=="toggleFlag")
3587 parser.setError (Aborted,"Nothing selected");
3588 } else if (! selbi )
3590 parser.setError (Aborted,"Type of selection is not a branch");
3591 } else if (parser.checkParCount(1))
3593 s=parser.parString(ok,0);
3595 selbi->toggleStandardFlag(s);
3597 /////////////////////////////////////////////////////////////////////
3598 } else if (com=="unscroll")
3602 parser.setError (Aborted,"Nothing selected");
3603 } else if (! selbi )
3605 parser.setError (Aborted,"Type of selection is not a branch");
3606 } else if (parser.checkParCount(0))
3608 if (!unscrollBranch (selbi))
3609 parser.setError (Aborted,"Could not unscroll branch");
3611 /////////////////////////////////////////////////////////////////////
3612 } else if (com=="unscrollChildren")
3616 parser.setError (Aborted,"Nothing selected");
3617 } else if (! selbi )
3619 parser.setError (Aborted,"Type of selection is not a branch");
3620 } else if (parser.checkParCount(0))
3622 unscrollChildren ();
3624 /////////////////////////////////////////////////////////////////////
3625 } else if (com=="unsetFlag")
3629 parser.setError (Aborted,"Nothing selected");
3630 } else if (! selbi )
3632 parser.setError (Aborted,"Type of selection is not a branch");
3633 } else if (parser.checkParCount(1))
3635 s=parser.parString(ok,0);
3637 selbi->deactivateStandardFlag(s);
3640 parser.setError (Aborted,"Unknown command");
3643 if (parser.errorLevel()==NoError)
3645 // setChanged(); FIXME-2 should not be called e.g. for export?!
3650 // TODO Error handling
3651 qWarning("VymModel::parseAtom: Error!");
3652 qWarning(parser.errorMessage());
3656 void VymModel::runScript (QString script)
3658 parser.setScript (script);
3660 while (parser.next() )
3661 parseAtom(parser.getAtom());
3664 void VymModel::setExportMode (bool b)
3666 // should be called before and after exports
3667 // depending on the settings
3668 if (b && settings.value("/export/useHideExport","true")=="true")
3669 setHideTmpMode (TreeItem::HideExport);
3671 setHideTmpMode (TreeItem::HideNone);
3674 void VymModel::exportImage(QString fname, bool askName, QString format)
3678 fname=getMapName()+".png";
3685 QFileDialog *fd=new QFileDialog (NULL);
3686 fd->setCaption (tr("Export map as image"));
3687 fd->setDirectory (lastImageDir);
3688 fd->setFileMode(QFileDialog::AnyFile);
3689 fd->setFilters (imageIO.getFilters() );
3692 fl=fd->selectedFiles();
3694 format=imageIO.getType(fd->selectedFilter());
3698 setExportMode (true);
3699 QPixmap pix (getPixmap());
3700 pix.save(fname, format);
3701 setExportMode (false);
3705 void VymModel::exportXML(QString dir, bool askForName)
3709 dir=browseDirectory(NULL,tr("Export XML to directory"));
3710 if (dir =="" && !reallyWriteDirectory(dir) )
3714 // Hide stuff during export, if settings want this
3715 setExportMode (true);
3717 // Create subdirectories
3720 // write to directory
3721 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3724 file.setName ( dir + "/"+mapName+".xml");
3725 if ( !file.open( QIODevice::WriteOnly ) )
3727 // This should neverever happen
3728 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3732 // Write it finally, and write in UTF8, no matter what
3733 QTextStream ts( &file );
3734 ts.setEncoding (QTextStream::UnicodeUTF8);
3738 // Now write image, too
3739 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3741 setExportMode (false);
3744 void VymModel::exportASCII(QString fname,bool askName)
3749 ex.setFile (mapName+".txt");
3755 //ex.addFilter ("TXT (*.txt)");
3756 ex.setDir(lastImageDir);
3757 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3762 setExportMode(true);
3764 setExportMode(false);
3768 void VymModel::exportXHTML (const QString &dir, bool askForName)
3770 ExportXHTMLDialog dia(NULL);
3771 dia.setFilePath (filePath );
3772 dia.setMapName (mapName );
3774 if (dir!="") dia.setDir (dir);
3780 if (dia.exec()!=QDialog::Accepted)
3784 QDir d (dia.getDir());
3785 // Check, if warnings should be used before overwriting
3786 // the output directory
3787 if (d.exists() && d.count()>0)
3790 warn.showCancelButton (true);
3791 warn.setText(QString(
3792 "The directory %1 is not empty.\n"
3793 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3794 warn.setCaption("Warning: Directory not empty");
3795 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3797 if (warn.exec()!=QDialog::Accepted) ok=false;
3804 exportXML (dia.getDir(),false );
3805 dia.doExport(mapName );
3806 //if (dia.hasChanged()) setChanged();
3810 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3815 if (ex.setConfigFile(cf))
3817 setExportMode (true);
3818 ex.exportPresentation();
3819 setExportMode (false);
3826 //////////////////////////////////////////////
3828 //////////////////////////////////////////////
3830 void VymModel::registerEditor(QWidget *me)
3832 mapEditor=(MapEditor*)me;
3835 void VymModel::unregisterEditor(QWidget *)
3840 void VymModel::setContextPos(QPointF p)
3845 void VymModel::unsetContextPos()
3847 contextPos=QPointF();
3850 void VymModel::updateNoteFlag()
3853 TreeItem *selti=getSelectedItem();
3856 if (textEditor->isEmpty())
3859 selti->setNote (textEditor->getText());
3860 emitDataHasChanged(selti);
3861 emitSelectionChanged();
3866 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3868 cout << "VM::updateRelPos...\n";
3870 for (int i=0; i<rootItem->branchCount(); i++)
3871 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3874 void MapCenterObj::updateRelPositions()
3876 if (repositionRequest) unsetAllRepositionRequests();
3878 // update relative Positions of branches and floats
3879 for (int i=0; i<treeItem->branchCount(); ++i)
3881 treeItem->getBranchObjNum(i)->setRelPos();
3882 treeItem->getBranchObjNum(i)->setOrientation();
3885 for (int i=0; i<floatimage.size(); ++i)
3886 floatimage.at(i)->setRelPos();
3888 if (repositionRequest) reposition();
3893 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3895 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3896 if (blockReposition) return;
3898 for (int i=0;i<rootItem->branchCount(); i++)
3899 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3903 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3905 return QPolygonF ();
3906 // Creating (arbitrary) shapes
3909 QRectF rb=bo->getBBox();
3910 if (bo->getDepth()==0)
3912 // Just take BBox of this mapCenter
3913 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3917 // Take union of BBox and TotalBBox
3919 QRectF ra=bo->getTotalBBox();
3920 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3923 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3926 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3928 p <<ra.bottomRight()
3930 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3933 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3939 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3943 // Move all branches and MapCenters away from lmo
3944 // to avoid collisions
3949 BranchObj *boA=(BranchObj*)lmo;
3951 for (int i=0; i<rootItem->branchCount(); i++)
3953 boB=rootItem->getBranchNum(i);
3956 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3959 <<" ("<<qPrintable(boA->getHeading() )<<")"
3960 <<" with ("<< qPrintable (boB->getHeading() )
3963 <<" minT="<<r.minTranslation<<endl<<endl;
3968 QPixmap VymModel::getPixmap()
3970 QRectF mapRect=getTotalBBox();
3971 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3974 pp.setRenderHints(mapEditor->renderHints());
3976 // Don't print the visualisation of selection
3979 mapScene->render ( &pp,
3980 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3981 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3983 // Restore selection
3990 void VymModel::setMapLinkStyle (const QString & s)
3995 case LinkableMapObj::Line :
3998 case LinkableMapObj::Parabel:
3999 snow="StyleParabel";
4001 case LinkableMapObj::PolyLine:
4002 snow="StylePolyLine";
4004 case LinkableMapObj::PolyParabel:
4005 snow="StylePolyParabel";
4008 snow="UndefinedStyle";
4013 QString("setMapLinkStyle (\"%1\")").arg(s),
4014 QString("setMapLinkStyle (\"%1\")").arg(snow),
4015 QString("Set map link style (\"%1\")").arg(s)
4019 linkstyle=LinkableMapObj::Line;
4020 else if (s=="StyleParabel")
4021 linkstyle=LinkableMapObj::Parabel;
4022 else if (s=="StylePolyLine")
4023 linkstyle=LinkableMapObj::PolyLine;
4024 else if (s=="StylePolyParabel")
4025 linkstyle=LinkableMapObj::PolyParabel;
4027 linkstyle=LinkableMapObj::UndefinedStyle;
4029 BranchItem *cur=NULL;
4030 BranchItem *prev=NULL;
4035 bo=(BranchObj*)(cur->getLMO() );
4036 bo->setLinkStyle(bo->getDefLinkStyle());
4042 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4047 void VymModel::setMapDefLinkColor(QColor col)
4049 if ( !col.isValid() ) return;
4051 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4052 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4053 QString("Set map link color to %1").arg(col.name())
4057 BranchItem *cur=NULL;
4058 BranchItem *prev=NULL;
4063 bo=(BranchObj*)(cur->getLMO() );
4070 void VymModel::setMapLinkColorHintInt()
4072 // called from setMapLinkColorHint(lch) or at end of parse
4073 BranchItem *cur=NULL;
4074 BranchItem *prev=NULL;
4079 bo=(BranchObj*)(cur->getLMO() );
4085 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4088 setMapLinkColorHintInt();
4091 void VymModel::toggleMapLinkColorHint()
4093 if (linkcolorhint==LinkableMapObj::HeadingColor)
4094 linkcolorhint=LinkableMapObj::DefaultColor;
4096 linkcolorhint=LinkableMapObj::HeadingColor;
4097 BranchItem *cur=NULL;
4098 BranchItem *prev=NULL;
4103 bo=(BranchObj*)(cur->getLMO() );
4109 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4111 Q3FileDialog *fd=new Q3FileDialog( NULL);
4112 fd->setMode (Q3FileDialog::ExistingFile);
4113 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4114 ImagePreview *p =new ImagePreview (fd);
4115 fd->setContentsPreviewEnabled( TRUE );
4116 fd->setContentsPreview( p, p );
4117 fd->setPreviewMode( Q3FileDialog::Contents );
4118 fd->setCaption(vymName+" - " +tr("Load background image"));
4119 fd->setDir (lastImageDir);
4122 if ( fd->exec() == QDialog::Accepted )
4124 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4125 lastImageDir=QDir (fd->dirPath());
4126 setMapBackgroundImage (fd->selectedFile());
4130 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4132 QColor oldcol=mapScene->backgroundBrush().color();
4136 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4138 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4139 QString("Set background color of map to %1").arg(col.name()));
4142 brush.setTextureImage (QPixmap (fn));
4143 mapScene->setBackgroundBrush(brush);
4146 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4148 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4149 if ( !col.isValid() ) return;
4150 setMapBackgroundColor( col );
4154 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4156 QColor oldcol=mapScene->backgroundBrush().color();
4158 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4159 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4160 QString("Set background color of map to %1").arg(col.name()));
4161 mapScene->setBackgroundBrush(col);
4164 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4166 return mapScene->backgroundBrush().color();
4170 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4172 return linkcolorhint;
4175 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4177 return defLinkColor;
4180 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4185 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4187 return defXLinkColor;
4190 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4195 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4197 return defXLinkWidth;
4200 void VymModel::move(const double &x, const double &y) // FIXME-3
4204 BranchObj *bo = getSelectedBranch();
4206 (selectionType()==TreeItem::Branch ||
4207 selectionType()==TreeItem::MapCenter ||
4208 selectionType()==TreeItem::Image
4211 QPointF ap(bo->getAbsPos());
4215 QString ps=qpointfToString(ap);
4216 QString s=getSelectString();
4219 s, "move "+qpointfToString(to),
4220 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4223 emitSelectionChanged();
4229 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4233 BranchObj *bo = getSelectedBranch();
4235 (selectionType()==TreeItem::Branch ||
4236 selectionType()==TreeItem::MapCenter ||
4237 selectionType()==TreeItem::Image
4241 QPointF rp(bo->getRelPos());
4245 QString ps=qpointfToString (bo->getRelPos());
4246 QString s=getSelectString(bo);
4249 s, "moveRel "+qpointfToString(to),
4250 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4251 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4254 emitSelectionChanged();
4261 void VymModel::animate()
4263 animationTimer->stop();
4266 while (i<animObjList.size() )
4268 bo=(BranchObj*)animObjList.at(i);
4273 animObjList.removeAt(i);
4280 QItemSelection sel=selModel->selection();
4281 emit (selectionChanged(sel,sel));
4284 if (!animObjList.isEmpty()) animationTimer->start();
4288 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4290 if (bo && bo->getTreeItem()->depth()>0)
4293 ap.setStart (start);
4295 ap.setTicks (animationTicks);
4296 ap.setAnimated (true);
4297 bo->setAnimation (ap);
4298 animObjList.append( bo );
4299 animationTimer->setSingleShot (true);
4300 animationTimer->start(animationInterval);
4304 void VymModel::stopAnimation (MapObj *mo)
4306 int i=animObjList.indexOf(mo);
4308 animObjList.removeAt (i);
4311 void VymModel::sendSelection()
4313 if (netstate!=Server) return;
4314 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4317 void VymModel::newServer()
4321 tcpServer = new QTcpServer(this);
4322 if (!tcpServer->listen(QHostAddress::Any,port)) {
4323 QMessageBox::critical(NULL, "vym server",
4324 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4325 //FIXME-3 needed? we are no widget any longer... close();
4328 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4330 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4333 void VymModel::connectToServer()
4336 server="salam.suse.de";
4338 clientSocket = new QTcpSocket (this);
4339 clientSocket->abort();
4340 clientSocket->connectToHost(server ,port);
4341 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4342 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4343 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4345 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4350 void VymModel::newClient()
4352 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4353 connect(newClient, SIGNAL(disconnected()),
4354 newClient, SLOT(deleteLater()));
4356 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4358 clientList.append (newClient);
4362 void VymModel::sendData(const QString &s)
4364 if (clientList.size()==0) return;
4366 // Create bytearray to send
4368 QDataStream out(&block, QIODevice::WriteOnly);
4369 out.setVersion(QDataStream::Qt_4_0);
4371 // Reserve some space for blocksize
4374 // Write sendCounter
4375 out << sendCounter++;
4380 // Go back and write blocksize so far
4381 out.device()->seek(0);
4382 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4386 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4388 for (int i=0; i<clientList.size(); ++i)
4390 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4391 clientList.at(i)->write (block);
4395 void VymModel::readData ()
4397 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4400 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4404 QDataStream in(clientSocket);
4405 in.setVersion(QDataStream::Qt_4_0);
4413 cout << " t="<<qPrintable (t)<<endl;
4419 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4421 switch (socketError) {
4422 case QAbstractSocket::RemoteHostClosedError:
4424 case QAbstractSocket::HostNotFoundError:
4425 QMessageBox::information(NULL, vymName +" Network client",
4426 "The host was not found. Please check the "
4427 "host name and port settings.");
4429 case QAbstractSocket::ConnectionRefusedError:
4430 QMessageBox::information(NULL, vymName + " Network client",
4431 "The connection was refused by the peer. "
4432 "Make sure the fortune server is running, "
4433 "and check that the host name and port "
4434 "settings are correct.");
4437 QMessageBox::information(NULL, vymName + " Network client",
4438 QString("The following error occurred: %1.")
4439 .arg(clientSocket->errorString()));
4446 void VymModel::selectMapSelectionColor()
4448 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4449 setSelectionColor (col);
4452 void VymModel::setSelectionColorInt (QColor col)
4454 if ( !col.isValid() ) return;
4456 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4457 QString("setSelectionColor (%1)").arg(col.name()),
4458 QString("Set color of selection box to %1").arg(col.name())
4461 mapEditor->setSelectionColor (col);
4465 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4467 cout << "VymModel::changeSelection (";
4468 if (!newsel.indexes().isEmpty() )
4469 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4471 if (!oldsel.indexes().isEmpty() )
4472 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4477 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4481 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4483 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4484 emitShowSelection();
4488 void VymModel::emitSelectionChanged()
4490 QItemSelection newsel=selModel->selection();
4491 emitSelectionChanged (newsel);
4494 void VymModel::setSelectionColor(QColor col)
4496 if ( !col.isValid() ) return;
4498 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4499 QString("setSelectionColor (%1)").arg(col.name()),
4500 QString("Set color of selection box to %1").arg(col.name())
4502 setSelectionColorInt (col);
4505 QColor VymModel::getSelectionColor()
4507 return mapEditor->getSelectionColor();
4510 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4513 for (int i=0;i<rootItem->childCount();i++)
4514 rootItem->child(i)->setHideTmp (mode);
4516 // FIXME-3 needed? scene()->update();
4520 QRectF VymModel::getTotalBBox() //FIXME-2
4524 for (int i=0;i<rootItem->branchCount(); i++)
4525 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4530 //////////////////////////////////////////////
4531 // Selection related
4532 //////////////////////////////////////////////
4534 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4539 QItemSelectionModel* VymModel::getSelectionModel()
4544 void VymModel::setSelectionBlocked (bool b)
4549 bool VymModel::isSelectionBlocked()
4551 return selectionBlocked;
4554 bool VymModel::select ()
4556 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4558 TreeItem *item = getItem (index);
4559 return select (item->getLMO() );
4562 bool VymModel::select (const QString &s)
4564 TreeItem *ti=findBySelectString(s);
4574 bool VymModel::select (LinkableMapObj *lmo)
4576 QItemSelection oldsel=selModel->selection();
4579 return select (lmo->getTreeItem() );
4584 bool VymModel::select (TreeItem *ti)
4586 if (ti) return select (index(ti));
4590 bool VymModel::select (const QModelIndex &index)
4592 if (index.isValid() )
4594 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4595 getSelectedItem()->setLastSelectedBranch();
4601 void VymModel::unselect()
4603 lastSelectString=getSelectString();
4604 selModel->clearSelection();
4607 void VymModel::reselect()
4609 select (lastSelectString);
4612 void VymModel::emitShowSelection()
4614 if (!blockReposition)
4615 emit (showSelection() );
4618 void VymModel::emitNoteHasChanged (TreeItem *ti)
4620 QModelIndex ix=index(ti);
4621 emit (noteHasChanged (ix) );
4624 void VymModel::emitDataHasChanged (TreeItem *ti)
4626 QModelIndex ix=index(ti);
4627 emit (dataChanged (ix,ix) );
4631 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4634 if (selection.select(lmo))
4636 //emitSelectionChanged();
4640 void VymModel::selectInt (TreeItem *ti)
4642 if (selection.select(lmo))
4644 //emitSelectionChanged();
4649 void VymModel::selectNextBranchInt()
4651 BranchItem *bi=getSelectedBranchItem();
4654 TreeItem *pi=bi->parent();
4658 if (i<pi->branchCount() )
4660 // select previous branch with same parent
4662 select (pi->getBranchNum(i));
4670 void VymModel::selectPrevBranchInt()
4673 BranchItem *bi=getSelectedBranchItem();
4676 BranchItem *pi=(BranchItem*)bi->parent();
4682 // select previous branch with same parent
4683 bi=pi->getBranchNum(i-1);
4688 while (bi->branchCount() >0)
4689 bi=bi->getLastBranch();
4692 // Try to select last branch in parent pi2 previous to own parent pi
4694 TreeItem *pi2=pi->parent();
4705 void VymModel::selectAboveBranchInt()
4707 BranchItem *bi=getSelectedBranchItem();
4710 BranchItem *newbi=NULL;
4711 BranchItem *pi=(BranchItem*)bi->parent();
4715 // goto previous branch with same parent
4716 newbi=pi->getBranchNum(i-1);
4717 while (newbi->branchCount() >0 )
4718 newbi=newbi->getLastBranch();
4722 if (newbi==rootItem)
4723 // already at top branch (resp. mapcenter)
4729 void VymModel::selectBelowBranchInt()
4731 BranchItem *bi=getSelectedBranchItem();
4734 BranchItem *newbi=NULL;
4736 if (bi->branchCount() >0)
4737 newbi=bi->getFirstBranch();
4744 pi=(BranchItem*)bi->parent();
4746 if (pi->branchCount()-1 > i)
4748 newbi=(BranchItem*)pi->getBranchNum(i+1);
4753 // look for siblings of myself
4754 // or parent, or parent of parent...
4765 void VymModel::selectUpperBranch()
4767 BranchItem *bi=getSelectedBranchItem();
4768 if (bi && bi->isBranchLikeType())
4769 selectAboveBranchInt();
4772 void VymModel::selectLowerBranch()
4774 BranchItem *bi=getSelectedBranchItem();
4775 if (bi && bi->isBranchLikeType())
4776 selectBelowBranchInt();
4780 void VymModel::selectLeftBranch()
4782 QItemSelection oldsel=selModel->selection();
4785 BranchItem *selbi=getSelectedBranchItem();
4786 TreeItem::Type type=selbi->getType();
4789 if (type == TreeItem::MapCenter)
4791 QModelIndex ix=index(selbi);
4792 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4795 par=(BranchItem*)selbi->parent();
4796 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4799 if (type == TreeItem::Branch ||
4800 type == TreeItem::Image)
4802 QModelIndex ix=index (selbi->parent());
4803 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4808 if (type == TreeItem::Branch )
4810 selectLastSelectedBranch();
4818 void VymModel::selectRightBranch()
4820 QItemSelection oldsel=selModel->selection();
4823 BranchItem *selbi=getSelectedBranchItem();
4824 TreeItem::Type type=selbi->getType();
4827 if (type==TreeItem::MapCenter)
4829 QModelIndex ix=index(selbi);
4830 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4833 par=(BranchItem*)selbi->parent();
4834 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4837 if ( type== TreeItem::Branch )
4839 selectLastSelectedBranch();
4845 if (type == TreeItem::Branch ||
4846 type == TreeItem::Image)
4848 QModelIndex ix=index(selbi->parent());
4849 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4856 void VymModel::selectFirstBranch()
4858 TreeItem *ti=getSelectedBranchItem();
4861 TreeItem *par=ti->parent();
4863 TreeItem *ti2=par->getFirstBranch();
4866 emitSelectionChanged();
4871 void VymModel::selectLastBranch()
4873 TreeItem *ti=getSelectedBranchItem();
4876 TreeItem *par=ti->parent();
4878 TreeItem *ti2=par->getLastBranch();
4881 emitSelectionChanged();
4886 void VymModel::selectLastSelectedBranch()
4888 TreeItem *ti=getSelectedBranchItem();
4891 ti=ti->getLastSelectedBranch();
4892 if (ti) select (ti);
4896 void VymModel::selectParent()
4898 TreeItem *ti=getSelectedItem();
4905 emitSelectionChanged();
4909 TreeItem::Type VymModel::selectionType()
4911 QModelIndexList list=selModel->selectedIndexes();
4912 if (list.isEmpty()) return TreeItem::Undefined;
4913 TreeItem *ti = getItem (list.first() );
4914 return ti->getType();
4918 LinkableMapObj* VymModel::getSelectedLMO()
4920 QModelIndexList list=selModel->selectedIndexes();
4921 if (!list.isEmpty() )
4923 TreeItem *ti = getItem (list.first() );
4924 TreeItem::Type type=ti->getType();
4925 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4927 return ti->getLMO();
4933 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4935 TreeItem *ti = getSelectedBranchItem();
4937 return (BranchObj*)ti->getLMO();
4942 BranchItem* VymModel::getSelectedBranchItem()
4944 QModelIndexList list=selModel->selectedIndexes();
4945 if (!list.isEmpty() )
4947 TreeItem *ti = getItem (list.first() );
4948 TreeItem::Type type=ti->getType();
4949 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4950 return (BranchItem*)ti;
4955 TreeItem* VymModel::getSelectedItem()
4957 QModelIndexList list=selModel->selectedIndexes();
4958 if (!list.isEmpty() )
4959 return getItem (list.first() );
4964 QModelIndex VymModel::getSelectedIndex()
4966 QModelIndexList list=selModel->selectedIndexes();
4967 if (list.isEmpty() )
4968 return QModelIndex();
4970 return list.first();
4973 FloatImageObj* VymModel::getSelectedFloatImage()
4975 //FIXME-2 return selection.getFloatImage();
4979 QString VymModel::getSelectString ()
4981 return getSelectString (getSelectedItem());
4984 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
4986 if (!lmo) return QString();
4987 return getSelectString (lmo->getTreeItem() );
4990 QString VymModel::getSelectString (TreeItem *ti)
4994 if (ti->getType() == TreeItem::Branch ||
4995 ti->getType() == TreeItem::MapCenter)
4997 TreeItem *par=ti->parent();
5000 if (ti->depth() ==1)
5001 // Mainbranch, return
5002 s= "bo:" + QString("%1").arg(ti->num() );
5004 // Branch, call myself recursively
5005 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
5009 int i=rootItem->num(ti);
5010 if (i>=0) s=QString("mc:%1").arg(i);