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"
14 #include "mapcenterobj.h"
18 #include "warningdialog.h"
19 #include "xml-freemind.h"
25 extern Main *mainWindow;
26 extern Settings settings;
27 extern QString tmpVymDir;
29 extern TextEditor *textEditor;
30 extern FlagRow *standardFlagsMaster;
32 extern QString clipboardDir;
33 extern QString clipboardFile;
34 extern bool clipboardEmpty;
36 extern ImageIO imageIO;
38 extern QString vymName;
39 extern QString vymVersion;
40 extern QDir vymBaseDir;
42 extern QDir lastImageDir;
43 extern QDir lastFileDir;
45 extern Settings settings;
49 int VymModel::mapNum=0; // make instance
53 // cout << "Const VymModel\n";
55 rootItem->setModel (this);
61 cout << "Destr VymModel\n";
62 autosaveTimer->stop();
63 fileChangedTimer->stop();
67 void VymModel::clear()
69 selModel->clearSelection();
71 //QModelIndex ri=index(rootItem);
72 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
75 void VymModel::init ()
77 // We should have at least one map center to start with
78 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
83 // Also no scene yet (should not be needed anyway) FIXME-3 VM
96 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
97 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
98 mainWindow->updateHistory (undoSet);
101 makeTmpDirectories();
106 fileName=tr("unnamed");
108 blockReposition=false;
109 blockSaveState=false;
111 autosaveTimer=new QTimer (this);
112 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
114 fileChangedTimer=new QTimer (this);
115 fileChangedTimer->start(3000);
116 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
121 selectionBlocked=false;
129 animationUse=settings.readBoolEntry("/animation/use",false);
130 animationTicks=settings.readNumEntry("/animation/ticks",10);
131 animationInterval=settings.readNumEntry("/animation/interval",50);
133 animationTimer=new QTimer (this);
134 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
137 defLinkColor=QColor (0,0,255);
138 defXLinkColor=QColor (180,180,180);
139 linkcolorhint=LinkableMapObj::DefaultColor;
140 linkstyle=LinkableMapObj::PolyParabel;
142 defXLinkColor=QColor (230,230,230);
144 hidemode=TreeItem::HideNone;
150 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
154 void VymModel::makeTmpDirectories()
156 // Create unique temporary directories
157 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
158 histPath = tmpMapDir+"/history";
164 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
169 bool VymModel::isRepositionBlocked()
171 return blockReposition;
174 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
176 //cout << "VM::updateActions \n";
177 // Tell mainwindow to update states of actions
178 mainWindow->updateActions();
183 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
185 // tmpdir temporary directory to which data will be written
186 // prefix mapname, which will be appended to images etc.
187 // writeflags Only write flags for "real" save of map, not undo
188 // offset offset of bbox of whole map in scene.
189 // Needed for XML export
198 case LinkableMapObj::Line:
201 case LinkableMapObj::Parabel:
204 case LinkableMapObj::PolyLine:
208 ls="StylePolyParabel";
212 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
214 if (linkcolorhint==LinkableMapObj::HeadingColor)
215 colhint=xml.attribut("linkColorHint","HeadingColor");
217 QString mapAttr=xml.attribut("version",vymVersion);
219 mapAttr+= xml.attribut("author",author) +
220 xml.attribut("comment",comment) +
221 xml.attribut("date",getDate()) +
222 xml.attribut("branchCount", QString().number(branchCount())) +
223 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
224 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
225 xml.attribut("linkStyle", ls ) +
226 xml.attribut("linkColor", defLinkColor.name() ) +
227 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
228 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
230 s+=xml.beginElement("vymmap",mapAttr);
233 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
234 standardFlagsMaster->resetUsedCounter();
236 // Reset the counters before saving
237 // TODO constr. of FIO creates lots of objects, better do this in some other way...
238 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
240 // Build xml recursivly
241 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
242 // Save all mapcenters as complete map, if saveSel not set
243 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
246 if (saveSel->isBranchLikeType())
248 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
249 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
251 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
254 // Save local settings
255 s+=settings.getDataXML (destPath);
258 if (getSelectedItem() && !saveSel )
259 s+=xml.valueElement("select",getSelectString());
262 s+=xml.endElement("vymmap");
264 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
268 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
272 for (int i=0; i<rootItem->branchCount(); i++)
273 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
277 void VymModel::setFilePath(QString fpath, QString destname)
279 if (fpath.isEmpty() || fpath=="")
286 filePath=fpath; // becomes absolute path
287 fileName=fpath; // gets stripped of path
288 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
290 // If fpath is not an absolute path, complete it
291 filePath=QDir(fpath).absPath();
292 fileDir=filePath.left (1+filePath.findRev ("/"));
294 // Set short name, too. Search from behind:
295 int i=fileName.findRev("/");
296 if (i>=0) fileName=fileName.remove (0,i+1);
298 // Forget the .vym (or .xml) for name of map
299 mapName=fileName.left(fileName.findRev(".",-1,true) );
303 void VymModel::setFilePath(QString fpath)
305 setFilePath (fpath,fpath);
308 QString VymModel::getFilePath()
313 QString VymModel::getFileName()
318 QString VymModel::getMapName()
323 QString VymModel::getDestPath()
328 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
330 ErrorCode err=success;
332 parseBaseHandler *handler;
336 case VymMap: handler=new parseVYMHandler; break;
337 case FreemindMap : handler=new parseFreemindHandler; break;
339 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
340 "Unknown FileType in VymModel::load()");
344 bool zipped_org=zipped;
348 selModel->clearSelection();
349 // FIXME-2 VM not needed??? model->setMapEditor(this);
350 // (map state is set later at end of load...)
353 BranchItem *bi=getSelectedBranchItem();
354 if (!bi) return aborted;
355 if (lmode==ImportAdd)
356 saveStateChangingPart(
359 QString("addMapInsert (%1)").arg(fname),
360 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
362 saveStateChangingPart(
365 QString("addMapReplace(%1)").arg(fname),
366 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
370 // Create temporary directory for packing
372 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
375 QMessageBox::critical( 0, tr( "Critical Load Error" ),
376 tr("Couldn't create temporary directory before load\n"));
381 err=unzipDir (tmpZipDir,fname);
391 // Look for mapname.xml
392 xmlfile= fname.left(fname.findRev(".",-1,true));
393 xmlfile=xmlfile.section( '/', -1 );
394 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
395 if (!mfile.exists() )
397 // mapname.xml does not exist, well,
398 // maybe someone renamed the mapname.vym file...
399 // Try to find any .xml in the toplevel
400 // directory of the .vym file
401 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
402 if (flist.count()==1)
404 // Only one entry, take this one
405 xmlfile=tmpZipDir + "/"+flist.first();
408 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
409 *it=tmpZipDir + "/" + *it;
410 // TODO Multiple entries, load all (but only the first one into this ME)
411 //mainWindow->fileLoadFromTmp (flist);
412 //returnCode=1; // Silently forget this attempt to load
413 qWarning ("MainWindow::load (fn) multimap found...");
416 if (flist.isEmpty() )
418 QMessageBox::critical( 0, tr( "Critical Load Error" ),
419 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
422 } //file doesn't exist
424 xmlfile=mfile.name();
427 QFile file( xmlfile);
429 // I am paranoid: file should exist anyway
430 // according to check in mainwindow.
433 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
434 tr(QString("Couldn't open map %1").arg(file.name())));
438 bool blockSaveStateOrg=blockSaveState;
439 blockReposition=true;
441 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
442 QXmlInputSource source( file);
443 QXmlSimpleReader reader;
444 reader.setContentHandler( handler );
445 reader.setErrorHandler( handler );
446 handler->setModel ( this);
449 // We need to set the tmpDir in order to load files with rel. path
454 tmpdir=fname.left(fname.findRev("/",-1));
455 handler->setTmpDir (tmpdir);
456 handler->setInputFile (file.name());
457 handler->setLoadMode (lmode);
458 bool ok = reader.parse( source );
459 blockReposition=false;
460 blockSaveState=blockSaveStateOrg;
461 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
465 reposition(); // FIXME-2 VM reposition the view instead...
472 autosaveTimer->stop();
475 // Reset timestamp to check for later updates of file
476 fileChangedTime=QFileInfo (destPath).lastModified();
479 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
480 tr( handler->errorProtocol() ) );
482 // Still return "success": the map maybe at least
483 // partially read by the parser
488 removeDir (QDir(tmpZipDir));
490 // Restore original zip state
497 ErrorCode VymModel::save (const SaveMode &savemode)
501 QString safeFilePath;
503 ErrorCode err=success;
507 mapFileName=mapName+".xml";
509 // use name given by user, even if he chooses .doc
510 mapFileName=fileName;
512 // Look, if we should zip the data:
515 QMessageBox mb( vymName,
516 tr("The map %1\ndid not use the compressed "
517 "vym file format.\nWriting it uncompressed will also write images \n"
518 "and flags and thus may overwrite files in the "
519 "given directory\n\nDo you want to write the map").arg(filePath),
520 QMessageBox::Warning,
521 QMessageBox::Yes | QMessageBox::Default,
523 QMessageBox::Cancel | QMessageBox::Escape);
524 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
525 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
526 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
529 case QMessageBox::Yes:
530 // save compressed (default file format)
533 case QMessageBox::No:
537 case QMessageBox::Cancel:
544 // First backup existing file, we
545 // don't want to add to old zip archives
549 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
551 QString backupFileName(destPath + "~");
552 QFile backupFile(backupFileName);
553 if (backupFile.exists() && !backupFile.remove())
555 QMessageBox::warning(0, tr("Save Error"),
556 tr("%1\ncould not be removed before saving").arg(backupFileName));
558 else if (!f.rename(backupFileName))
560 QMessageBox::warning(0, tr("Save Error"),
561 tr("%1\ncould not be renamed before saving").arg(destPath));
568 // Create temporary directory for packing
570 tmpZipDir=makeTmpDir (ok,"vym-zip");
573 QMessageBox::critical( 0, tr( "Critical Load Error" ),
574 tr("Couldn't create temporary directory before save\n"));
578 safeFilePath=filePath;
579 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
582 // Create mapName and fileDir
583 makeSubDirs (fileDir);
586 if (savemode==CompleteMap || selModel->selection().isEmpty())
589 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
592 autosaveTimer->stop();
597 if (selectionType()==TreeItem::Image)
600 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
601 // TODO take care of multiselections
604 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
607 qWarning ("ME::saveStringToDisk failed!");
613 if (err==success) err=zipDir (tmpZipDir,destPath);
616 removeDir (QDir(tmpZipDir));
618 // Restore original filepath outside of tmp zip dir
619 setFilePath (safeFilePath);
623 fileChangedTime=QFileInfo (destPath).lastModified();
627 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
629 QString pathDir=path.left(path.findRev("/"));
635 // We need to parse saved XML data
636 parseVYMHandler handler;
637 QXmlInputSource source( file);
638 QXmlSimpleReader reader;
639 reader.setContentHandler( &handler );
640 reader.setErrorHandler( &handler );
641 handler.setModel ( this);
642 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
643 if (undoSel.isEmpty())
647 handler.setLoadMode (NewMap);
651 handler.setLoadMode (ImportReplace);
653 blockReposition=true;
654 bool ok = reader.parse( source );
655 blockReposition=false;
658 // This should never ever happen
659 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
660 handler.errorProtocol());
663 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
666 void VymModel::addMapInsertInt (const QString &path, int pos)
668 /* FIXME-2 addMapInsertInt not ported yet
669 BranchObj *sel=getSelectedBranch();
672 QString pathDir=path.left(path.findRev("/"));
678 // We need to parse saved XML data
679 parseVYMHandler handler;
680 QXmlInputSource source( file);
681 QXmlSimpleReader reader;
682 reader.setContentHandler( &handler );
683 reader.setErrorHandler( &handler );
684 handler.setModel (this);
685 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
686 handler.setLoadMode (ImportAdd);
687 blockReposition=true;
688 bool ok = reader.parse( source );
689 blockReposition=false;
692 // This should never ever happen
693 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
694 handler.errorProtocol());
696 if (sel->getDepth()>0)
697 sel->getLastBranch()->linkTo (sel,pos);
699 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
704 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
706 TreeItem *fi=createImage();
709 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
717 void VymModel::loadFloatImage () // FIXME-2
720 BranchObj *bo=getSelectedBranch();
724 Q3FileDialog *fd=new Q3FileDialog( NULL);
725 fd->setMode (Q3FileDialog::ExistingFiles);
726 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
727 ImagePreview *p =new ImagePreview (fd);
728 fd->setContentsPreviewEnabled( TRUE );
729 fd->setContentsPreview( p, p );
730 fd->setPreviewMode( Q3FileDialog::Contents );
731 fd->setCaption(vymName+" - " +tr("Load image"));
732 fd->setDir (lastImageDir);
735 if ( fd->exec() == QDialog::Accepted )
737 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
738 lastImageDir=QDir (fd->dirPath());
741 for (int j=0; j<fd->selectedFiles().count(); j++)
743 s=fd->selectedFiles().at(j);
744 fio=loadFloatImageInt (s);
747 (LinkableMapObj*)fio,
750 QString ("loadImage (%1)").arg(s ),
751 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
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);
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?
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 // updateSelection();
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) );
1967 BranchItem* VymModel::createBranch()
1969 BranchItem *selbi=getSelectedBranchItem();
1971 return addNewBranchInt (selbi,-2);
1976 TreeItem* VymModel::createImage() //FIXME-1
1980 BranchObj *bo=getSelectedBranch();
1983 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1986 QList<QVariant> cData;
1987 cData << "VM:createImage" << "undef"<<"undef";
1988 TreeItem *parti=bo->getTreeItem();
1989 TreeItem *ti=new TreeItem (cData,parti);
1990 ti->setLMO (newfio);
1991 ti->setType (TreeItem::Image);
1992 parti->appendChild (ti);
1996 newfio->setTreeItem (ti);
1997 select (newfio); // FIXME-2 VM really needed here?
2004 BranchItem* VymModel::addMapCenter ()
2006 BranchItem *bi=addMapCenter (contextPos);
2008 emitShowSelection();
2013 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2014 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2019 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2023 QModelIndex parix=index(rootItem);
2025 int n=rootItem->branchCount();
2027 emit (layoutAboutToBeChanged() );
2028 beginInsertRows (parix,n,n+1);
2030 QList<QVariant> cData;
2031 cData << "VM:addMapCenter" << "undef"<<"undef";
2032 BranchItem *newbi=new BranchItem (cData);
2033 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2034 rootItem->appendChild (newbi);
2037 emit (layoutChanged() );
2040 newbi->createMapObj(mapScene);
2045 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) //FIXME-4 simplify...
2047 // Depending on pos:
2048 // -3 insert in children of parent above selection
2049 // -2 add branch to selection
2050 // -1 insert in children of parent below selection
2051 // 0..n insert in children of parent at pos
2054 QList<QVariant> cData;
2055 cData << "new" << "undef"<<"undef";
2060 BranchItem *newbi=new BranchItem (cData);
2061 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2063 emit (layoutAboutToBeChanged() );
2069 n=parbi->childCount();
2070 beginInsertRows (parix,n,n+1);
2071 parbi->appendChild (newbi);
2073 }else if (num==-1 || num==-3)
2075 // insert below selection
2076 parbi=(BranchItem*)dst->parent();
2078 n=dst->childNumber()+ (3+num)/2; //-1 |-> 1;-3 |-> 0
2079 beginInsertRows (parix,n,n);
2080 parbi->insertBranch(n,newbi);
2083 emit (layoutChanged() );
2085 // save scroll state. If scrolled, automatically select
2086 // new branch in order to tmp unscroll parent...
2087 newbi->createMapObj(mapScene);
2093 BranchItem* VymModel::addNewBranch(int pos)
2095 // Different meaning than num in addNewBranchInt!
2099 BranchItem *newbi=NULL;
2100 BranchItem *selbi=getSelectedBranchItem();
2104 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2107 newbi=addNewBranchInt (selbi,pos-2);
2115 QString ("addBranch (%1)").arg(pos),
2116 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2119 // updateSelection(); FIXME-3
2120 latestAddedItem=newbi;
2121 // In Network mode, the client needs to know where the new branch is,
2122 // so we have to pass on this information via saveState.
2123 // TODO: Get rid of this positioning workaround
2124 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2125 sendData ("selectLatestAdded ()");
2126 sendData (QString("move %1").arg(ps));
2135 BranchItem* VymModel::addNewBranchBefore()
2137 BranchItem *newbi=NULL;
2138 BranchItem *selbi=getSelectedBranchItem();
2139 if (selbi && selbi->getType()==TreeItem::Branch)
2140 // We accept no MapCenter here, so we _have_ a parent
2142 //QPointF p=bo->getRelPos();
2145 // add below selection
2146 newbi=addNewBranchInt (selbi,-1);
2150 //newbi->move2RelPos (p);
2152 // Move selection to new branch
2153 relinkBranch (selbi,newbi,0);
2155 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2156 QString ("Add branch before %1").arg(getObjectName(selbi)));
2158 // FIXME-3 needed? reposition();
2159 // updateSelection(); FIXME-3
2162 //FIXME-3 needed? latestSelectionString=selection.getSelectString();
2166 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2170 if (branch->depth()==0)
2172 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2174 emit (layoutAboutToBeChanged() );
2175 BranchItem *branchpi=(BranchItem*)branch->parent();
2176 // Remove at current position
2177 int n=branch->childNum();
2178 beginRemoveRows (index(branchpi),n,n);
2179 branchpi->removeChild (n);
2182 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2184 // Append as last branch to dst
2185 if (dst->branchCount()==0)
2188 n=dst->getFirstBranch()->childNumber();
2189 beginInsertRows (index(dst),n+pos,n+pos);
2190 dst->insertBranch (pos,branch);
2193 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2194 branch->updateStyles();
2196 emit (layoutChanged() );
2197 reposition(); // both for moveUp/Down and relinking
2204 void VymModel::deleteSelection()
2206 BranchItem *selbi=getSelectedBranchItem();
2210 TreeItem *pi=selbi->parent();
2211 QModelIndex parentIndex=index(pi);
2213 if (selbi->isBranchLikeType() )
2216 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2218 emit (layoutAboutToBeChanged() );
2220 int n=selbi->childNum();
2221 beginRemoveRows (parentIndex,n,n);
2222 removeRows (n,1,parentIndex);
2225 emitShowSelection();
2228 emit (layoutChanged() );
2231 //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2236 BranchObj* par=(BranchObj*)fio->getParObj();
2237 saveStateChangingPart(
2241 QString("Delete %1").arg(getObjectName(fio))
2244 par->removeFloatImage(fio);
2247 emitShowSelection();
2253 void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
2257 BranchObj *bo=getSelectedBranch();
2261 par=(BranchObj*)(bo->getParObj());
2263 // Don't use this on mapcenter
2266 // Check if we have childs at all to keep
2267 if (bo->getTreeItem()->branchCount()==0)
2273 QPointF p=bo->getRelPos();
2274 saveStateChangingPart(
2277 "deleteKeepChildren ()",
2278 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2281 QString sel=getSelectString(bo);
2283 par->removeBranchHere(bo);
2286 getSelectedBranch()->move2RelPos (p);
2291 void VymModel::deleteChildren()
2294 BranchItem *selbi=getSelectedBranchItem();
2297 saveStateChangingPart(
2300 "deleteChildren ()",
2301 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2303 emit (layoutAboutToBeChanged() );
2305 QModelIndex ix=index (selbi);
2306 int n=selbi->branchCount()-1;
2307 beginRemoveRows (ix,0,n);
2308 removeRows (0,n+1,ix);
2310 emit (layoutChanged() );
2315 bool VymModel::scrollBranch(BranchItem *bi)
2319 if (bi->isScrolled()) return false;
2320 if (bi->branchCount()==0) return false;
2321 if (bi->depth()==0) return false;
2322 if (bi->toggleScroll())
2329 QString ("%1 ()").arg(u),
2331 QString ("%1 ()").arg(r),
2332 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2334 emitDataHasChanged(bi);
2336 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2343 bool VymModel::unscrollBranch(BranchItem *bi)
2347 if (!bi->isScrolled()) return false;
2348 if (bi->branchCount()==0) return false;
2349 if (bi->depth()==0) return false;
2356 QString ("%1 ()").arg(u),
2358 QString ("%1 ()").arg(r),
2359 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2362 emitDataHasChanged(bi);
2365 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2371 void VymModel::toggleScroll()
2373 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2374 if (bi && bi->isBranchLikeType() )
2376 if (bi->isScrolled())
2377 unscrollBranch (bi);
2381 // saveState is called in above functions
2384 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2388 BranchObj *bo=getSelectedBranch();
2394 if (bo->isScrolled()) unscrollBranch (bo);
2401 void VymModel::emitExpandAll()
2403 emit (expandAll() );
2406 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2408 BranchItem *bi=getSelectedBranchItem();
2412 if (bi->isActiveStandardFlag(name))
2424 QString("%1 (\"%2\")").arg(u).arg(name),
2426 QString("%1 (\"%2\")").arg(r).arg(name),
2427 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2428 bi->toggleStandardFlag (name, master);
2434 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
2437 BranchObj *bo=getSelectedBranch();
2440 FloatImageObj *fio=bo->addFloatImage();
2442 fio->setOriginalFilename("No original filename (image added by dropevent)");
2443 QString s=getSelectString(bo);
2444 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2445 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2447 // FIXME-3 VM needed? scene()->update();
2453 void VymModel::colorBranch (QColor c)
2455 BranchItem *selbi=getSelectedBranchItem();
2460 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2462 QString ("colorBranch (\"%1\")").arg(c.name()),
2463 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2465 selbi->setHeadingColor(c); // color branch
2469 void VymModel::colorSubtree (QColor c)
2471 BranchItem *selbi=getSelectedBranchItem();
2474 saveStateChangingPart(
2477 QString ("colorSubtree (\"%1\")").arg(c.name()),
2478 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2480 BranchItem *prev=NULL;
2481 BranchItem *cur=selbi;
2484 cur->setHeadingColor(c); // color links, color children
2485 cur=next (cur,prev,selbi);
2491 QColor VymModel::getCurrentHeadingColor()
2493 BranchItem *selbi=getSelectedBranchItem();
2494 if (selbi) return selbi->getHeadingColor();
2496 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2502 void VymModel::editURL()
2504 TreeItem *selti=getSelectedItem();
2508 QString text = QInputDialog::getText(
2509 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2510 selti->getURL(), &ok, NULL);
2512 // user entered something and pressed OK
2517 void VymModel::editLocalURL()
2519 TreeItem *selti=getSelectedItem();
2522 QStringList filters;
2523 filters <<"All files (*)";
2524 filters << tr("Text","Filedialog") + " (*.txt)";
2525 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2526 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2527 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2528 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2529 fd->setFilters (filters);
2530 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2531 fd->setDirectory (lastFileDir);
2532 if (! selti->getVymLink().isEmpty() )
2533 fd->selectFile( selti->getURL() );
2536 if ( fd->exec() == QDialog::Accepted )
2538 lastFileDir=QDir (fd->directory().path());
2539 setURL (fd->selectedFile() );
2545 void VymModel::editHeading2URL()
2547 TreeItem *selti=getSelectedItem();
2549 setURL (selti->getHeading());
2552 void VymModel::editBugzilla2URL()
2554 TreeItem *selti=getSelectedItem();
2557 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2562 void VymModel::editFATE2URL()
2564 TreeItem *selti=getSelectedItem();
2567 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2570 "setURL (\""+selti->getURL()+"\")",
2572 "setURL (\""+url+"\")",
2573 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2575 selti->setURL (url);
2576 // FIXME-4 updateActions();
2580 void VymModel::editVymLink()
2582 BranchItem *bi=getSelectedBranchItem();
2585 QStringList filters;
2586 filters <<"VYM map (*.vym)";
2587 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2588 fd->setFilters (filters);
2589 fd->setCaption(vymName+" - " +tr("Link to another map"));
2590 fd->setDirectory (lastFileDir);
2591 if (! bi->getVymLink().isEmpty() )
2592 fd->selectFile( bi->getVymLink() );
2596 if ( fd->exec() == QDialog::Accepted )
2598 lastFileDir=QDir (fd->directory().path());
2601 "setVymLink (\""+bi->getVymLink()+"\")",
2603 "setVymLink (\""+fd->selectedFile()+"\")",
2604 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2606 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2611 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2613 // Internal function, no saveState needed
2614 BranchItem *bi=getSelectedBranchItem();
2620 //updateSelection();
2624 void VymModel::deleteVymLink()
2626 BranchItem *bi=getSelectedBranchItem();
2631 "setVymLink (\""+bi->getVymLink()+"\")",
2633 "setVymLink (\"\")",
2634 QString("Unset vymlink of %1").arg(getObjectName(bi))
2636 bi->setVymLink ("" );
2642 QString VymModel::getVymLink()
2644 BranchItem *bi=getSelectedBranchItem();
2646 return bi->getVymLink();
2652 QStringList VymModel::getVymLinks()
2655 BranchItem *selbi=getSelectedBranchItem();
2656 BranchItem *cur=selbi;
2657 BranchItem *prev=NULL;
2660 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2661 cur=next (cur,prev,selbi);
2667 void VymModel::followXLink(int i) // FIXME-2
2671 BranchObj *bo=getSelectedBranch();
2674 bo=bo->XLinkTargetAt(i);
2677 selection.select(bo);
2678 emitShowSelection();
2684 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2688 BranchObj *bo=getSelectedBranch();
2691 XLinkObj *xlo=bo->XLinkAt(i);
2694 EditXLinkDialog dia;
2696 dia.setSelection(bo);
2697 if (dia.exec() == QDialog::Accepted)
2699 if (dia.useSettingsGlobal() )
2701 setMapDefXLinkColor (xlo->getColor() );
2702 setMapDefXLinkWidth (xlo->getWidth() );
2704 if (dia.deleteXLink())
2705 bo->deleteXLinkAt(i);
2716 //////////////////////////////////////////////
2718 //////////////////////////////////////////////
2720 void VymModel::parseAtom(const QString &atom)
2722 TreeItem* selti=getSelectedItem();
2723 BranchItem *selbi=getSelectedBranchItem();
2729 // Split string s into command and parameters
2730 parser.parseAtom (atom);
2731 QString com=parser.getCommand();
2733 // External commands
2734 /////////////////////////////////////////////////////////////////////
2735 if (com=="addBranch")
2739 parser.setError (Aborted,"Nothing selected");
2740 } else if (! selbi )
2742 parser.setError (Aborted,"Type of selection is not a branch");
2747 if (parser.checkParCount(pl))
2749 if (parser.parCount()==0)
2753 n=parser.parInt (ok,0);
2754 if (ok ) addNewBranch (n);
2758 /////////////////////////////////////////////////////////////////////
2759 } else if (com=="addBranchBefore")
2763 parser.setError (Aborted,"Nothing selected");
2764 } else if (! selbi )
2766 parser.setError (Aborted,"Type of selection is not a branch");
2769 if (parser.parCount()==0)
2771 addNewBranchBefore ();
2774 /////////////////////////////////////////////////////////////////////
2775 } else if (com==QString("addMapCenter"))
2777 if (parser.checkParCount(2))
2779 x=parser.parDouble (ok,0);
2782 y=parser.parDouble (ok,1);
2783 if (ok) addMapCenter (QPointF(x,y));
2786 /////////////////////////////////////////////////////////////////////
2787 } else if (com==QString("addMapReplace"))
2791 parser.setError (Aborted,"Nothing selected");
2792 } else if (! selbi )
2794 parser.setError (Aborted,"Type of selection is not a branch");
2795 } else if (parser.checkParCount(1))
2797 //s=parser.parString (ok,0); // selection
2798 t=parser.parString (ok,0); // path to map
2799 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2800 addMapReplaceInt(getSelectString(selbi),t);
2802 /////////////////////////////////////////////////////////////////////
2803 } else if (com==QString("addMapInsert"))
2807 parser.setError (Aborted,"Nothing selected");
2808 } else if (! selbi )
2810 parser.setError (Aborted,"Type of selection is not a branch");
2813 if (parser.checkParCount(2))
2815 t=parser.parString (ok,0); // path to map
2816 n=parser.parInt(ok,1); // position
2817 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2818 addMapInsertInt(t,n);
2821 /////////////////////////////////////////////////////////////////////
2822 } else if (com=="clearFlags")
2826 parser.setError (Aborted,"Nothing selected");
2827 } else if (! selbi )
2829 parser.setError (Aborted,"Type of selection is not a branch");
2830 } else if (parser.checkParCount(0))
2832 selbi->deactivateAllStandardFlags();
2834 /////////////////////////////////////////////////////////////////////
2835 } else if (com=="colorBranch")
2839 parser.setError (Aborted,"Nothing selected");
2840 } else if (! selbi )
2842 parser.setError (Aborted,"Type of selection is not a branch");
2843 } else if (parser.checkParCount(1))
2845 QColor c=parser.parColor (ok,0);
2846 if (ok) colorBranch (c);
2848 /////////////////////////////////////////////////////////////////////
2849 } else if (com=="colorSubtree")
2853 parser.setError (Aborted,"Nothing selected");
2854 } else if (! selbi )
2856 parser.setError (Aborted,"Type of selection is not a branch");
2857 } else if (parser.checkParCount(1))
2859 QColor c=parser.parColor (ok,0);
2860 if (ok) colorSubtree (c);
2862 /////////////////////////////////////////////////////////////////////
2863 } else if (com=="copy")
2867 parser.setError (Aborted,"Nothing selected");
2868 } else if ( selectionType()!=TreeItem::Branch &&
2869 selectionType()!=TreeItem::MapCenter &&
2870 selectionType()!=TreeItem::Image )
2872 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2873 } else if (parser.checkParCount(0))
2877 /////////////////////////////////////////////////////////////////////
2878 } else if (com=="cut")
2882 parser.setError (Aborted,"Nothing selected");
2883 } else if ( selectionType()!=TreeItem::Branch &&
2884 selectionType()!=TreeItem::MapCenter &&
2885 selectionType()!=TreeItem::Image )
2887 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2888 } else if (parser.checkParCount(0))
2892 /////////////////////////////////////////////////////////////////////
2893 } else if (com=="delete")
2897 parser.setError (Aborted,"Nothing selected");
2899 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2901 parser.setError (Aborted,"Type of selection is wrong.");
2904 else if (parser.checkParCount(0))
2908 /////////////////////////////////////////////////////////////////////
2909 } else if (com=="deleteKeepChildren")
2913 parser.setError (Aborted,"Nothing selected");
2914 } else if (! selbi )
2916 parser.setError (Aborted,"Type of selection is not a branch");
2917 } else if (parser.checkParCount(0))
2919 deleteKeepChildren();
2921 /////////////////////////////////////////////////////////////////////
2922 } else if (com=="deleteChildren")
2926 parser.setError (Aborted,"Nothing selected");
2929 parser.setError (Aborted,"Type of selection is not a branch");
2930 } else if (parser.checkParCount(0))
2934 /////////////////////////////////////////////////////////////////////
2935 } else if (com=="exportASCII")
2939 if (parser.parCount()>=1)
2940 // Hey, we even have a filename
2941 fname=parser.parString(ok,0);
2944 parser.setError (Aborted,"Could not read filename");
2947 exportASCII (fname,false);
2949 /////////////////////////////////////////////////////////////////////
2950 } else if (com=="exportImage")
2954 if (parser.parCount()>=2)
2955 // Hey, we even have a filename
2956 fname=parser.parString(ok,0);
2959 parser.setError (Aborted,"Could not read filename");
2962 QString format="PNG";
2963 if (parser.parCount()>=2)
2965 format=parser.parString(ok,1);
2967 exportImage (fname,false,format);
2969 /////////////////////////////////////////////////////////////////////
2970 } else if (com=="exportXHTML")
2974 if (parser.parCount()>=2)
2975 // Hey, we even have a filename
2976 fname=parser.parString(ok,1);
2979 parser.setError (Aborted,"Could not read filename");
2982 exportXHTML (fname,false);
2984 /////////////////////////////////////////////////////////////////////
2985 } else if (com=="exportXML")
2989 if (parser.parCount()>=2)
2990 // Hey, we even have a filename
2991 fname=parser.parString(ok,1);
2994 parser.setError (Aborted,"Could not read filename");
2997 exportXML (fname,false);
2999 /////////////////////////////////////////////////////////////////////
3000 } else if (com=="importDir")
3004 parser.setError (Aborted,"Nothing selected");
3005 } else if (! selbi )
3007 parser.setError (Aborted,"Type of selection is not a branch");
3008 } else if (parser.checkParCount(1))
3010 s=parser.parString(ok,0);
3011 if (ok) importDirInt(s);
3013 /////////////////////////////////////////////////////////////////////
3014 } else /* FIXME-2 if (com=="linkTo")
3018 parser.setError (Aborted,"Nothing selected");
3021 if (parser.checkParCount(4))
3023 // 0 selectstring of parent
3024 // 1 num in parent (for branches)
3025 // 2,3 x,y of mainbranch or mapcenter
3026 s=parser.parString(ok,0);
3027 LinkableMapObj *dst=findObjBySelect (s);
3030 if (typid(*dst) == typid(BranchObj) )
3032 // Get number in parent
3033 n=parser.parInt (ok,1);
3036 selb->linkTo ((BranchObj*)(dst),n);
3039 } else if (typid(*dst) == typid(MapCenterObj) )
3041 selb->linkTo ((BranchObj*)(dst),-1);
3042 // Get coordinates of mainbranch
3043 x=parser.parDouble(ok,2);
3046 y=parser.parDouble(ok,3);
3056 } else if ( selectionType() == TreeItem::Image)
3058 if (parser.checkParCount(1))
3060 // 0 selectstring of parent
3061 s=parser.parString(ok,0);
3062 LinkableMapObj *dst=findObjBySelect (s);
3065 if (typid(*dst) == typid(BranchObj) ||
3066 typid(*dst) == typid(MapCenterObj))
3067 linkFloatImageTo (getSelectString(dst));
3069 parser.setError (Aborted,"Destination is not a branch");
3072 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3073 /////////////////////////////////////////////////////////////////////
3074 } else */ if (com=="loadImage")
3078 parser.setError (Aborted,"Nothing selected");
3079 } else if (! selbi )
3081 parser.setError (Aborted,"Type of selection is not a branch");
3082 } else if (parser.checkParCount(1))
3084 s=parser.parString(ok,0);
3085 if (ok) loadFloatImageInt (s);
3087 /////////////////////////////////////////////////////////////////////
3088 } else if (com=="moveUp")
3092 parser.setError (Aborted,"Nothing selected");
3093 } else if (! selbi )
3095 parser.setError (Aborted,"Type of selection is not a branch");
3096 } else if (parser.checkParCount(0))
3100 /////////////////////////////////////////////////////////////////////
3101 } else if (com=="moveDown")
3105 parser.setError (Aborted,"Nothing selected");
3106 } else if (! selbi )
3108 parser.setError (Aborted,"Type of selection is not a branch");
3109 } else if (parser.checkParCount(0))
3113 /////////////////////////////////////////////////////////////////////
3114 } else if (com=="move")
3118 parser.setError (Aborted,"Nothing selected");
3119 } else if ( selectionType()!=TreeItem::Branch &&
3120 selectionType()!=TreeItem::MapCenter &&
3121 selectionType()!=TreeItem::Image )
3123 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3124 } else if (parser.checkParCount(2))
3126 x=parser.parDouble (ok,0);
3129 y=parser.parDouble (ok,1);
3133 /////////////////////////////////////////////////////////////////////
3134 } else if (com=="moveRel")
3138 parser.setError (Aborted,"Nothing selected");
3139 } else if ( selectionType()!=TreeItem::Branch &&
3140 selectionType()!=TreeItem::MapCenter &&
3141 selectionType()!=TreeItem::Image )
3143 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3144 } else if (parser.checkParCount(2))
3146 x=parser.parDouble (ok,0);
3149 y=parser.parDouble (ok,1);
3150 if (ok) moveRel (x,y);
3153 /////////////////////////////////////////////////////////////////////
3154 } else if (com=="nop")
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="paste")
3161 parser.setError (Aborted,"Nothing selected");
3162 } else if (! selbi )
3164 parser.setError (Aborted,"Type of selection is not a branch");
3165 } else if (parser.checkParCount(1))
3167 n=parser.parInt (ok,0);
3168 if (ok) pasteNoSave(n);
3170 /////////////////////////////////////////////////////////////////////
3171 } else if (com=="qa")
3175 parser.setError (Aborted,"Nothing selected");
3176 } else if (! selbi )
3178 parser.setError (Aborted,"Type of selection is not a branch");
3179 } else if (parser.checkParCount(4))
3182 c=parser.parString (ok,0);
3185 parser.setError (Aborted,"No comment given");
3188 s=parser.parString (ok,1);
3191 parser.setError (Aborted,"First parameter is not a string");
3194 t=parser.parString (ok,2);
3197 parser.setError (Aborted,"Condition is not a string");
3200 u=parser.parString (ok,3);
3203 parser.setError (Aborted,"Third parameter is not a string");
3208 parser.setError (Aborted,"Unknown type: "+s);
3213 parser.setError (Aborted,"Unknown operator: "+t);
3218 parser.setError (Aborted,"Type of selection is not a branch");
3221 if (selbi->getHeading() == u)
3223 cout << "PASSED: " << qPrintable (c) << endl;
3226 cout << "FAILED: " << qPrintable (c) << endl;
3236 /////////////////////////////////////////////////////////////////////
3237 } else if (com=="saveImage")
3239 //FIXME-2 FloatImageObj *fio=selection.getFloatImage();
3240 FloatImageObj* fio=NULL;
3243 parser.setError (Aborted,"Type of selection is not an image");
3244 } else if (parser.checkParCount(2))
3246 s=parser.parString(ok,0);
3249 t=parser.parString(ok,1);
3250 if (ok) saveFloatImageInt (fio,t,s);
3253 /////////////////////////////////////////////////////////////////////
3254 } else if (com=="scroll")
3258 parser.setError (Aborted,"Nothing selected");
3259 } else if (! selbi )
3261 parser.setError (Aborted,"Type of selection is not a branch");
3262 } else if (parser.checkParCount(0))
3264 if (!scrollBranch (selbi))
3265 parser.setError (Aborted,"Could not scroll branch");
3267 /////////////////////////////////////////////////////////////////////
3268 } else if (com=="select")
3270 if (parser.checkParCount(1))
3272 s=parser.parString(ok,0);
3275 /////////////////////////////////////////////////////////////////////
3276 } else if (com=="selectLastBranch")
3280 parser.setError (Aborted,"Nothing selected");
3281 } else if (! selbi )
3283 parser.setError (Aborted,"Type of selection is not a branch");
3284 } else if (parser.checkParCount(0))
3286 BranchItem *bi=selbi->getLastBranch();
3288 parser.setError (Aborted,"Could not select last branch");
3289 select (bi); // FIXME-3 was selectInt
3292 /////////////////////////////////////////////////////////////////////
3293 } else /* FIXME-2 if (com=="selectLastImage")
3297 parser.setError (Aborted,"Nothing selected");
3298 } else if (! selbi )
3300 parser.setError (Aborted,"Type of selection is not a branch");
3301 } else if (parser.checkParCount(0))
3303 FloatImageObj *fio=selb->getLastFloatImage();
3305 parser.setError (Aborted,"Could not select last image");
3306 select (fio); // FIXME-3 was selectInt
3309 /////////////////////////////////////////////////////////////////////
3310 } else */ if (com=="selectLatestAdded")
3312 if (!latestAddedItem)
3314 parser.setError (Aborted,"No latest added object");
3317 if (!select (latestAddedItem))
3318 parser.setError (Aborted,"Could not select latest added object ");
3320 /////////////////////////////////////////////////////////////////////
3321 } else if (com=="setFrameType")
3323 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3325 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3327 else if (parser.checkParCount(1))
3329 s=parser.parString(ok,0);
3330 if (ok) setFrameType (s);
3332 /////////////////////////////////////////////////////////////////////
3333 } else if (com=="setFramePenColor")
3335 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3337 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3339 else if (parser.checkParCount(1))
3341 QColor c=parser.parColor(ok,0);
3342 if (ok) setFramePenColor (c);
3344 /////////////////////////////////////////////////////////////////////
3345 } else if (com=="setFrameBrushColor")
3347 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3349 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3351 else if (parser.checkParCount(1))
3353 QColor c=parser.parColor(ok,0);
3354 if (ok) setFrameBrushColor (c);
3356 /////////////////////////////////////////////////////////////////////
3357 } else if (com=="setFramePadding")
3359 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3361 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3363 else if (parser.checkParCount(1))
3365 n=parser.parInt(ok,0);
3366 if (ok) setFramePadding(n);
3368 /////////////////////////////////////////////////////////////////////
3369 } else if (com=="setFrameBorderWidth")
3371 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3373 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3375 else if (parser.checkParCount(1))
3377 n=parser.parInt(ok,0);
3378 if (ok) setFrameBorderWidth (n);
3380 /////////////////////////////////////////////////////////////////////
3381 } else if (com=="setMapAuthor")
3383 if (parser.checkParCount(1))
3385 s=parser.parString(ok,0);
3386 if (ok) setAuthor (s);
3388 /////////////////////////////////////////////////////////////////////
3389 } else if (com=="setMapComment")
3391 if (parser.checkParCount(1))
3393 s=parser.parString(ok,0);
3394 if (ok) setComment(s);
3396 /////////////////////////////////////////////////////////////////////
3397 } else if (com=="setMapBackgroundColor")
3401 parser.setError (Aborted,"Nothing selected");
3402 } else if (! selbi )
3404 parser.setError (Aborted,"Type of selection is not a branch");
3405 } else if (parser.checkParCount(1))
3407 QColor c=parser.parColor (ok,0);
3408 if (ok) setMapBackgroundColor (c);
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="setMapDefLinkColor")
3415 parser.setError (Aborted,"Nothing selected");
3416 } else if (! selbi )
3418 parser.setError (Aborted,"Type of selection is not a branch");
3419 } else if (parser.checkParCount(1))
3421 QColor c=parser.parColor (ok,0);
3422 if (ok) setMapDefLinkColor (c);
3424 /////////////////////////////////////////////////////////////////////
3425 } else if (com=="setMapLinkStyle")
3427 if (parser.checkParCount(1))
3429 s=parser.parString (ok,0);
3430 if (ok) setMapLinkStyle(s);
3432 /////////////////////////////////////////////////////////////////////
3433 } else if (com=="setHeading")
3437 parser.setError (Aborted,"Nothing selected");
3438 } else if (! selbi )
3440 parser.setError (Aborted,"Type of selection is not a branch");
3441 } else if (parser.checkParCount(1))
3443 s=parser.parString (ok,0);
3447 /////////////////////////////////////////////////////////////////////
3448 } else if (com=="setHideExport")
3452 parser.setError (Aborted,"Nothing selected");
3453 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3455 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3456 } else if (parser.checkParCount(1))
3458 b=parser.parBool(ok,0);
3459 if (ok) setHideExport (b);
3461 /////////////////////////////////////////////////////////////////////
3462 } else if (com=="setIncludeImagesHorizontally")
3466 parser.setError (Aborted,"Nothing selected");
3469 parser.setError (Aborted,"Type of selection is not a branch");
3470 } else if (parser.checkParCount(1))
3472 b=parser.parBool(ok,0);
3473 if (ok) setIncludeImagesHor(b);
3475 /////////////////////////////////////////////////////////////////////
3476 } else if (com=="setIncludeImagesVertically")
3480 parser.setError (Aborted,"Nothing selected");
3483 parser.setError (Aborted,"Type of selection is not a branch");
3484 } else if (parser.checkParCount(1))
3486 b=parser.parBool(ok,0);
3487 if (ok) setIncludeImagesVer(b);
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="setHideLinkUnselected")
3494 parser.setError (Aborted,"Nothing selected");
3495 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3497 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3498 } else if (parser.checkParCount(1))
3500 b=parser.parBool(ok,0);
3501 if (ok) setHideLinkUnselected(b);
3503 /////////////////////////////////////////////////////////////////////
3504 } else if (com=="setSelectionColor")
3506 if (parser.checkParCount(1))
3508 QColor c=parser.parColor (ok,0);
3509 if (ok) setSelectionColorInt (c);
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="setURL")
3516 parser.setError (Aborted,"Nothing selected");
3517 } else if (! selbi )
3519 parser.setError (Aborted,"Type of selection is not a branch");
3520 } else if (parser.checkParCount(1))
3522 s=parser.parString (ok,0);
3525 /////////////////////////////////////////////////////////////////////
3526 } else if (com=="setVymLink")
3530 parser.setError (Aborted,"Nothing selected");
3531 } else if (! selbi )
3533 parser.setError (Aborted,"Type of selection is not a branch");
3534 } else if (parser.checkParCount(1))
3536 s=parser.parString (ok,0);
3537 if (ok) setVymLink(s);
3540 /////////////////////////////////////////////////////////////////////
3541 else if (com=="setFlag")
3545 parser.setError (Aborted,"Nothing selected");
3546 } else if (! selbi )
3548 parser.setError (Aborted,"Type of selection is not a branch");
3549 } else if (parser.checkParCount(1))
3551 s=parser.parString(ok,0);
3553 selbi->activateStandardFlag(s);
3555 /////////////////////////////////////////////////////////////////////
3556 } else /* FIXME-2 if (com=="setFrameType")
3560 parser.setError (Aborted,"Nothing selected");
3563 parser.setError (Aborted,"Type of selection is not a branch");
3564 } else if (parser.checkParCount(1))
3566 s=parser.parString(ok,0);
3570 /////////////////////////////////////////////////////////////////////
3571 } else*/ if (com=="sortChildren")
3575 parser.setError (Aborted,"Nothing selected");
3576 } else if (! selbi )
3578 parser.setError (Aborted,"Type of selection is not a branch");
3579 } else if (parser.checkParCount(0))
3583 /////////////////////////////////////////////////////////////////////
3584 } else if (com=="toggleFlag")
3588 parser.setError (Aborted,"Nothing selected");
3589 } else if (! selbi )
3591 parser.setError (Aborted,"Type of selection is not a branch");
3592 } else if (parser.checkParCount(1))
3594 s=parser.parString(ok,0);
3596 selbi->toggleStandardFlag(s);
3598 /////////////////////////////////////////////////////////////////////
3599 } else if (com=="unscroll")
3603 parser.setError (Aborted,"Nothing selected");
3604 } else if (! selbi )
3606 parser.setError (Aborted,"Type of selection is not a branch");
3607 } else if (parser.checkParCount(0))
3609 if (!unscrollBranch (selbi))
3610 parser.setError (Aborted,"Could not unscroll branch");
3612 /////////////////////////////////////////////////////////////////////
3613 } else if (com=="unscrollChildren")
3617 parser.setError (Aborted,"Nothing selected");
3618 } else if (! selbi )
3620 parser.setError (Aborted,"Type of selection is not a branch");
3621 } else if (parser.checkParCount(0))
3623 unscrollChildren ();
3625 /////////////////////////////////////////////////////////////////////
3626 } else if (com=="unsetFlag")
3630 parser.setError (Aborted,"Nothing selected");
3631 } else if (! selbi )
3633 parser.setError (Aborted,"Type of selection is not a branch");
3634 } else if (parser.checkParCount(1))
3636 s=parser.parString(ok,0);
3638 selbi->deactivateStandardFlag(s);
3641 parser.setError (Aborted,"Unknown command");
3644 if (parser.errorLevel()==NoError)
3646 // setChanged(); FIXME-2 should not be called e.g. for export?!
3651 // TODO Error handling
3652 qWarning("VymModel::parseAtom: Error!");
3653 qWarning(parser.errorMessage());
3657 void VymModel::runScript (QString script)
3659 parser.setScript (script);
3661 while (parser.next() )
3662 parseAtom(parser.getAtom());
3665 void VymModel::setExportMode (bool b)
3667 // should be called before and after exports
3668 // depending on the settings
3669 if (b && settings.value("/export/useHideExport","true")=="true")
3670 setHideTmpMode (TreeItem::HideExport);
3672 setHideTmpMode (TreeItem::HideNone);
3675 void VymModel::exportImage(QString fname, bool askName, QString format)
3679 fname=getMapName()+".png";
3686 QFileDialog *fd=new QFileDialog (NULL);
3687 fd->setCaption (tr("Export map as image"));
3688 fd->setDirectory (lastImageDir);
3689 fd->setFileMode(QFileDialog::AnyFile);
3690 fd->setFilters (imageIO.getFilters() );
3693 fl=fd->selectedFiles();
3695 format=imageIO.getType(fd->selectedFilter());
3699 setExportMode (true);
3700 QPixmap pix (getPixmap());
3701 pix.save(fname, format);
3702 setExportMode (false);
3706 void VymModel::exportXML(QString dir, bool askForName)
3710 dir=browseDirectory(NULL,tr("Export XML to directory"));
3711 if (dir =="" && !reallyWriteDirectory(dir) )
3715 // Hide stuff during export, if settings want this
3716 setExportMode (true);
3718 // Create subdirectories
3721 // write to directory
3722 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3725 file.setName ( dir + "/"+mapName+".xml");
3726 if ( !file.open( QIODevice::WriteOnly ) )
3728 // This should neverever happen
3729 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3733 // Write it finally, and write in UTF8, no matter what
3734 QTextStream ts( &file );
3735 ts.setEncoding (QTextStream::UnicodeUTF8);
3739 // Now write image, too
3740 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3742 setExportMode (false);
3745 void VymModel::exportASCII(QString fname,bool askName)
3750 ex.setFile (mapName+".txt");
3756 //ex.addFilter ("TXT (*.txt)");
3757 ex.setDir(lastImageDir);
3758 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3763 setExportMode(true);
3765 setExportMode(false);
3769 void VymModel::exportXHTML (const QString &dir, bool askForName)
3771 ExportXHTMLDialog dia(NULL);
3772 dia.setFilePath (filePath );
3773 dia.setMapName (mapName );
3775 if (dir!="") dia.setDir (dir);
3781 if (dia.exec()!=QDialog::Accepted)
3785 QDir d (dia.getDir());
3786 // Check, if warnings should be used before overwriting
3787 // the output directory
3788 if (d.exists() && d.count()>0)
3791 warn.showCancelButton (true);
3792 warn.setText(QString(
3793 "The directory %1 is not empty.\n"
3794 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3795 warn.setCaption("Warning: Directory not empty");
3796 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3798 if (warn.exec()!=QDialog::Accepted) ok=false;
3805 exportXML (dia.getDir(),false );
3806 dia.doExport(mapName );
3807 //if (dia.hasChanged()) setChanged();
3811 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3816 if (ex.setConfigFile(cf))
3818 setExportMode (true);
3819 ex.exportPresentation();
3820 setExportMode (false);
3827 //////////////////////////////////////////////
3829 //////////////////////////////////////////////
3831 void VymModel::registerEditor(QWidget *me)
3833 mapEditor=(MapEditor*)me;
3836 void VymModel::unregisterEditor(QWidget *)
3841 void VymModel::setContextPos(QPointF p)
3846 void VymModel::unsetContextPos()
3848 contextPos=QPointF();
3851 void VymModel::updateNoteFlag()
3854 TreeItem *selti=getSelectedItem();
3857 if (textEditor->isEmpty())
3860 selti->setNote (textEditor->getText());
3861 emitDataHasChanged(selti);
3867 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3869 //cout << "VM::updateRelPos...\n";
3870 for (int i=0; i<rootItem->branchCount(); i++)
3871 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3874 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3876 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3877 if (blockReposition) return;
3879 for (int i=0;i<rootItem->branchCount(); i++)
3880 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3884 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3886 return QPolygonF ();
3887 // Creating (arbitrary) shapes
3890 QRectF rb=bo->getBBox();
3891 if (bo->getDepth()==0)
3893 // Just take BBox of this mapCenter
3894 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3898 // Take union of BBox and TotalBBox
3900 QRectF ra=bo->getTotalBBox();
3901 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3904 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3907 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3909 p <<ra.bottomRight()
3911 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3914 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3920 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3924 // Move all branches and MapCenters away from lmo
3925 // to avoid collisions
3930 BranchObj *boA=(BranchObj*)lmo;
3932 for (int i=0; i<rootItem->branchCount(); i++)
3934 boB=rootItem->getBranchNum(i);
3937 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3940 <<" ("<<qPrintable(boA->getHeading() )<<")"
3941 <<" with ("<< qPrintable (boB->getHeading() )
3944 <<" minT="<<r.minTranslation<<endl<<endl;
3949 QPixmap VymModel::getPixmap()
3951 QRectF mapRect=getTotalBBox();
3952 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3955 pp.setRenderHints(mapEditor->renderHints());
3957 // Don't print the visualisation of selection
3960 mapScene->render ( &pp,
3961 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3962 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3964 // Restore selection
3971 void VymModel::setMapLinkStyle (const QString & s)
3976 case LinkableMapObj::Line :
3979 case LinkableMapObj::Parabel:
3980 snow="StyleParabel";
3982 case LinkableMapObj::PolyLine:
3983 snow="StylePolyLine";
3985 case LinkableMapObj::PolyParabel:
3986 snow="StylePolyParabel";
3989 snow="UndefinedStyle";
3994 QString("setMapLinkStyle (\"%1\")").arg(s),
3995 QString("setMapLinkStyle (\"%1\")").arg(snow),
3996 QString("Set map link style (\"%1\")").arg(s)
4000 linkstyle=LinkableMapObj::Line;
4001 else if (s=="StyleParabel")
4002 linkstyle=LinkableMapObj::Parabel;
4003 else if (s=="StylePolyLine")
4004 linkstyle=LinkableMapObj::PolyLine;
4005 else if (s=="StylePolyParabel")
4006 linkstyle=LinkableMapObj::PolyParabel;
4008 linkstyle=LinkableMapObj::UndefinedStyle;
4010 BranchItem *cur=NULL;
4011 BranchItem *prev=NULL;
4016 bo=(BranchObj*)(cur->getLMO() );
4017 bo->setLinkStyle(bo->getDefLinkStyle());
4023 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4028 void VymModel::setMapDefLinkColor(QColor col)
4030 if ( !col.isValid() ) return;
4032 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4033 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4034 QString("Set map link color to %1").arg(col.name())
4038 BranchItem *cur=NULL;
4039 BranchItem *prev=NULL;
4044 bo=(BranchObj*)(cur->getLMO() );
4051 void VymModel::setMapLinkColorHintInt()
4053 // called from setMapLinkColorHint(lch) or at end of parse
4054 BranchItem *cur=NULL;
4055 BranchItem *prev=NULL;
4060 bo=(BranchObj*)(cur->getLMO() );
4066 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4069 setMapLinkColorHintInt();
4072 void VymModel::toggleMapLinkColorHint()
4074 if (linkcolorhint==LinkableMapObj::HeadingColor)
4075 linkcolorhint=LinkableMapObj::DefaultColor;
4077 linkcolorhint=LinkableMapObj::HeadingColor;
4078 BranchItem *cur=NULL;
4079 BranchItem *prev=NULL;
4084 bo=(BranchObj*)(cur->getLMO() );
4090 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4092 Q3FileDialog *fd=new Q3FileDialog( NULL);
4093 fd->setMode (Q3FileDialog::ExistingFile);
4094 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4095 ImagePreview *p =new ImagePreview (fd);
4096 fd->setContentsPreviewEnabled( TRUE );
4097 fd->setContentsPreview( p, p );
4098 fd->setPreviewMode( Q3FileDialog::Contents );
4099 fd->setCaption(vymName+" - " +tr("Load background image"));
4100 fd->setDir (lastImageDir);
4103 if ( fd->exec() == QDialog::Accepted )
4105 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4106 lastImageDir=QDir (fd->dirPath());
4107 setMapBackgroundImage (fd->selectedFile());
4111 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4113 QColor oldcol=mapScene->backgroundBrush().color();
4117 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4119 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4120 QString("Set background color of map to %1").arg(col.name()));
4123 brush.setTextureImage (QPixmap (fn));
4124 mapScene->setBackgroundBrush(brush);
4127 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4129 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4130 if ( !col.isValid() ) return;
4131 setMapBackgroundColor( col );
4135 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4137 QColor oldcol=mapScene->backgroundBrush().color();
4139 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4140 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4141 QString("Set background color of map to %1").arg(col.name()));
4142 mapScene->setBackgroundBrush(col);
4145 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4147 return mapScene->backgroundBrush().color();
4151 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4153 return linkcolorhint;
4156 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4158 return defLinkColor;
4161 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4166 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4168 return defXLinkColor;
4171 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4176 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4178 return defXLinkWidth;
4181 void VymModel::move(const double &x, const double &y) // FIXME-3
4185 BranchObj *bo = getSelectedBranch();
4187 (selectionType()==TreeItem::Branch ||
4188 selectionType()==TreeItem::MapCenter ||
4189 selectionType()==TreeItem::Image
4192 QPointF ap(bo->getAbsPos());
4196 QString ps=qpointfToString(ap);
4197 QString s=getSelectString();
4200 s, "move "+qpointfToString(to),
4201 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4210 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4214 BranchObj *bo = getSelectedBranch();
4216 (selectionType()==TreeItem::Branch ||
4217 selectionType()==TreeItem::MapCenter ||
4218 selectionType()==TreeItem::Image
4222 QPointF rp(bo->getRelPos());
4226 QString ps=qpointfToString (bo->getRelPos());
4227 QString s=getSelectString(bo);
4230 s, "moveRel "+qpointfToString(to),
4231 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4232 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4242 void VymModel::animate()
4244 animationTimer->stop();
4247 while (i<animObjList.size() )
4249 bo=(BranchObj*)animObjList.at(i);
4254 animObjList.removeAt(i);
4261 QItemSelection sel=selModel->selection();
4262 emit (selectionChanged(sel,sel));
4265 if (!animObjList.isEmpty()) animationTimer->start();
4269 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4271 if (bo && bo->getTreeItem()->depth()>0)
4274 ap.setStart (start);
4276 ap.setTicks (animationTicks);
4277 ap.setAnimated (true);
4278 bo->setAnimation (ap);
4279 animObjList.append( bo );
4280 animationTimer->setSingleShot (true);
4281 animationTimer->start(animationInterval);
4285 void VymModel::stopAnimation (MapObj *mo)
4287 int i=animObjList.indexOf(mo);
4289 animObjList.removeAt (i);
4292 void VymModel::sendSelection()
4294 if (netstate!=Server) return;
4295 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4298 void VymModel::newServer()
4302 tcpServer = new QTcpServer(this);
4303 if (!tcpServer->listen(QHostAddress::Any,port)) {
4304 QMessageBox::critical(NULL, "vym server",
4305 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4306 //FIXME-3 needed? we are no widget any longer... close();
4309 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4311 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4314 void VymModel::connectToServer()
4317 server="salam.suse.de";
4319 clientSocket = new QTcpSocket (this);
4320 clientSocket->abort();
4321 clientSocket->connectToHost(server ,port);
4322 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4323 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4324 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4326 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4331 void VymModel::newClient()
4333 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4334 connect(newClient, SIGNAL(disconnected()),
4335 newClient, SLOT(deleteLater()));
4337 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4339 clientList.append (newClient);
4343 void VymModel::sendData(const QString &s)
4345 if (clientList.size()==0) return;
4347 // Create bytearray to send
4349 QDataStream out(&block, QIODevice::WriteOnly);
4350 out.setVersion(QDataStream::Qt_4_0);
4352 // Reserve some space for blocksize
4355 // Write sendCounter
4356 out << sendCounter++;
4361 // Go back and write blocksize so far
4362 out.device()->seek(0);
4363 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4367 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4369 for (int i=0; i<clientList.size(); ++i)
4371 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4372 clientList.at(i)->write (block);
4376 void VymModel::readData ()
4378 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4381 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4385 QDataStream in(clientSocket);
4386 in.setVersion(QDataStream::Qt_4_0);
4394 cout << " t="<<qPrintable (t)<<endl;
4400 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4402 switch (socketError) {
4403 case QAbstractSocket::RemoteHostClosedError:
4405 case QAbstractSocket::HostNotFoundError:
4406 QMessageBox::information(NULL, vymName +" Network client",
4407 "The host was not found. Please check the "
4408 "host name and port settings.");
4410 case QAbstractSocket::ConnectionRefusedError:
4411 QMessageBox::information(NULL, vymName + " Network client",
4412 "The connection was refused by the peer. "
4413 "Make sure the fortune server is running, "
4414 "and check that the host name and port "
4415 "settings are correct.");
4418 QMessageBox::information(NULL, vymName + " Network client",
4419 QString("The following error occurred: %1.")
4420 .arg(clientSocket->errorString()));
4427 void VymModel::selectMapSelectionColor()
4429 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4430 setSelectionColor (col);
4433 void VymModel::setSelectionColorInt (QColor col)
4435 if ( !col.isValid() ) return;
4437 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4438 QString("setSelectionColor (%1)").arg(col.name()),
4439 QString("Set color of selection box to %1").arg(col.name())
4442 mapEditor->setSelectionColor (col);
4446 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4448 cout << "VymModel::changeSelection (";
4449 if (!newsel.indexes().isEmpty() )
4450 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4452 if (!oldsel.indexes().isEmpty() )
4453 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4458 void VymModel::updateSelection(const QItemSelection &newsel)
4460 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4461 emitShowSelection();
4465 void VymModel::updateSelection()
4467 QItemSelection newsel=selModel->selection();
4468 updateSelection (newsel);
4471 void VymModel::setSelectionColor(QColor col)
4473 if ( !col.isValid() ) return;
4475 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4476 QString("setSelectionColor (%1)").arg(col.name()),
4477 QString("Set color of selection box to %1").arg(col.name())
4479 setSelectionColorInt (col);
4482 QColor VymModel::getSelectionColor()
4484 return mapEditor->getSelectionColor();
4487 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4490 for (int i=0;i<rootItem->childCount();i++)
4491 rootItem->child(i)->setHideTmp (mode);
4493 // FIXME-3 needed? scene()->update();
4497 QRectF VymModel::getTotalBBox() //FIXME-2
4501 for (int i=0;i<rootItem->branchCount(); i++)
4502 r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
4507 //////////////////////////////////////////////
4508 // Selection related
4509 //////////////////////////////////////////////
4511 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4516 QItemSelectionModel* VymModel::getSelectionModel()
4521 void VymModel::setSelectionBlocked (bool b)
4526 bool VymModel::isSelectionBlocked()
4528 return selectionBlocked;
4531 bool VymModel::select ()
4533 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4535 TreeItem *item = getItem (index);
4536 return select (item->getLMO() );
4539 bool VymModel::select (const QString &s)
4541 TreeItem *ti=findBySelectString(s);
4551 bool VymModel::select (LinkableMapObj *lmo)
4553 QItemSelection oldsel=selModel->selection();
4556 return select (lmo->getTreeItem() );
4561 bool VymModel::select (TreeItem *ti)
4563 if (ti) return select (index(ti));
4567 bool VymModel::select (const QModelIndex &index)
4569 if (index.isValid() )
4571 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4572 getSelectedItem()->setLastSelectedBranch();
4578 void VymModel::unselect()
4580 lastSelectString=getSelectString();
4581 selModel->clearSelection();
4584 void VymModel::reselect()
4586 select (lastSelectString);
4589 void VymModel::emitShowSelection()
4591 if (!blockReposition)
4592 emit (showSelection() );
4595 void VymModel::emitNoteHasChanged (TreeItem *ti)
4597 QModelIndex ix=index(ti);
4598 emit (noteHasChanged (ix) );
4601 void VymModel::emitDataHasChanged (TreeItem *ti)
4603 QModelIndex ix=index(ti);
4604 emit (dataChanged (ix,ix) );
4608 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4611 if (selection.select(lmo))
4613 //updateSelection();
4617 void VymModel::selectInt (TreeItem *ti)
4619 if (selection.select(lmo))
4621 //updateSelection();
4626 void VymModel::selectNextBranchInt()
4628 BranchItem *bi=getSelectedBranchItem();
4631 TreeItem *pi=bi->parent();
4635 if (i<pi->branchCount() )
4637 // select previous branch with same parent
4639 select (pi->getBranchNum(i));
4647 void VymModel::selectPrevBranchInt()
4650 BranchItem *bi=getSelectedBranchItem();
4653 BranchItem *pi=(BranchItem*)bi->parent();
4659 // select previous branch with same parent
4660 bi=pi->getBranchNum(i-1);
4665 while (bi->branchCount() >0)
4666 bi=bi->getLastBranch();
4669 // Try to select last branch in parent pi2 previous to own parent pi
4671 TreeItem *pi2=pi->parent();
4682 void VymModel::selectAboveBranchInt()
4684 BranchItem *bi=getSelectedBranchItem();
4687 BranchItem *newbi=NULL;
4688 BranchItem *pi=(BranchItem*)bi->parent();
4692 // goto previous branch with same parent
4693 newbi=pi->getBranchNum(i-1);
4694 while (newbi->branchCount() >0 )
4695 newbi=newbi->getLastBranch();
4699 if (newbi==rootItem)
4700 // already at top branch (resp. mapcenter)
4706 void VymModel::selectBelowBranchInt()
4708 BranchItem *bi=getSelectedBranchItem();
4711 BranchItem *newbi=NULL;
4713 if (bi->branchCount() >0)
4714 newbi=bi->getFirstBranch();
4721 pi=(BranchItem*)bi->parent();
4723 if (pi->branchCount()-1 > i)
4725 newbi=(BranchItem*)pi->getBranchNum(i+1);
4730 // look for siblings of myself
4731 // or parent, or parent of parent...
4742 void VymModel::selectUpperBranch()
4744 BranchItem *bi=getSelectedBranchItem();
4745 if (bi && bi->isBranchLikeType())
4746 selectAboveBranchInt();
4749 void VymModel::selectLowerBranch()
4751 BranchItem *bi=getSelectedBranchItem();
4752 if (bi && bi->isBranchLikeType())
4753 selectBelowBranchInt();
4757 void VymModel::selectLeftBranch()
4759 QItemSelection oldsel=selModel->selection();
4762 BranchItem *selbi=getSelectedBranchItem();
4763 TreeItem::Type type=selbi->getType();
4766 if (type == TreeItem::MapCenter)
4768 QModelIndex ix=index(selbi);
4769 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4772 par=(BranchItem*)selbi->parent();
4773 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4776 if (type == TreeItem::Branch ||
4777 type == TreeItem::Image)
4779 QModelIndex ix=index (selbi->parent());
4780 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4785 if (type == TreeItem::Branch )
4787 selectLastSelectedBranch();
4795 void VymModel::selectRightBranch()
4797 QItemSelection oldsel=selModel->selection();
4800 BranchItem *selbi=getSelectedBranchItem();
4801 TreeItem::Type type=selbi->getType();
4804 if (type==TreeItem::MapCenter)
4806 QModelIndex ix=index(selbi);
4807 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4810 par=(BranchItem*)selbi->parent();
4811 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4814 if ( type== TreeItem::Branch )
4816 selectLastSelectedBranch();
4822 if (type == TreeItem::Branch ||
4823 type == TreeItem::Image)
4825 QModelIndex ix=index(selbi->parent());
4826 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4833 void VymModel::selectFirstBranch()
4835 TreeItem *ti=getSelectedBranchItem();
4838 TreeItem *par=ti->parent();
4840 TreeItem *ti2=par->getFirstBranch();
4848 void VymModel::selectLastBranch()
4850 TreeItem *ti=getSelectedBranchItem();
4853 TreeItem *par=ti->parent();
4855 TreeItem *ti2=par->getLastBranch();
4863 void VymModel::selectLastSelectedBranch()
4865 TreeItem *ti=getSelectedBranchItem();
4868 ti=ti->getLastSelectedBranch();
4869 if (ti) select (ti);
4873 void VymModel::selectParent()
4875 TreeItem *ti=getSelectedItem();
4886 TreeItem::Type VymModel::selectionType()
4888 QModelIndexList list=selModel->selectedIndexes();
4889 if (list.isEmpty()) return TreeItem::Undefined;
4890 TreeItem *ti = getItem (list.first() );
4891 return ti->getType();
4895 LinkableMapObj* VymModel::getSelectedLMO()
4897 QModelIndexList list=selModel->selectedIndexes();
4898 if (!list.isEmpty() )
4900 TreeItem *ti = getItem (list.first() );
4901 TreeItem::Type type=ti->getType();
4902 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4904 return ti->getLMO();
4910 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4912 TreeItem *ti = getSelectedBranchItem();
4914 return (BranchObj*)ti->getLMO();
4919 BranchItem* VymModel::getSelectedBranchItem()
4921 QModelIndexList list=selModel->selectedIndexes();
4922 if (!list.isEmpty() )
4924 TreeItem *ti = getItem (list.first() );
4925 TreeItem::Type type=ti->getType();
4926 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4927 return (BranchItem*)ti;
4932 TreeItem* VymModel::getSelectedItem()
4934 QModelIndexList list=selModel->selectedIndexes();
4935 if (!list.isEmpty() )
4936 return getItem (list.first() );
4941 QModelIndex VymModel::getSelectedIndex()
4943 QModelIndexList list=selModel->selectedIndexes();
4944 if (list.isEmpty() )
4945 return QModelIndex();
4947 return list.first();
4950 FloatImageObj* VymModel::getSelectedFloatImage()
4952 //FIXME-2 return selection.getFloatImage();
4956 QString VymModel::getSelectString ()
4958 LinkableMapObj *lmo=getSelectedLMO();
4960 return getSelectString(lmo);
4965 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
4967 if (!lmo) return QString();
4968 return getSelectString (lmo->getTreeItem() );
4971 QString VymModel::getSelectString (TreeItem *ti)
4975 if (ti->getType() == TreeItem::Branch ||
4976 ti->getType() == TreeItem::MapCenter)
4978 TreeItem *par=ti->parent();
4981 if (ti->depth() ==1)
4982 // Mainbranch, return
4983 s= "bo:" + QString("%1").arg(ti->num() );
4985 // Branch, call myself recursively
4986 s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
4990 int i=rootItem->num(ti);
4991 if (i>=0) s=QString("mc:%1").arg(i);