1 #include <QApplication>
6 #include "editxlinkdialog.h"
8 #include "exportxhtmldialog.h"
10 #include "geometry.h" // for addBBox
11 #include "mainwindow.h"
12 #include "mapcenterobj.h"
15 #include "selection.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;
31 extern QString clipboardDir;
32 extern QString clipboardFile;
33 extern bool clipboardEmpty;
35 extern ImageIO imageIO;
37 extern QString vymName;
38 extern QString vymVersion;
39 extern QDir vymBaseDir;
41 extern QDir lastImageDir;
42 extern QDir lastFileDir;
44 extern FlagRowObj *standardFlagsDefault;
46 extern Settings settings;
50 int VymModel::mapNum=0; // make instance
54 // cout << "Const VymModel\n";
56 rootItem->setModel (this);
62 // cout << "Destr VymModel\n";
63 autosaveTimer->stop();
64 fileChangedTimer->stop();
68 void VymModel::clear()
70 selModel->clearSelection();
73 while (!mapCenters.isEmpty()) // FIXME-2 VM needs to be in treemodel only...
74 delete mapCenters.takeFirst();
76 QModelIndex ri=index(rootItem);
77 //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
80 void VymModel::init ()
82 // We should have at least one map center to start with
83 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
88 // Also no scene yet (should not be needed anyway) FIXME-3 VM
101 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
102 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
103 mainWindow->updateHistory (undoSet);
106 makeTmpDirectories();
111 fileName=tr("unnamed");
113 blockReposition=false;
114 blockSaveState=false;
116 autosaveTimer=new QTimer (this);
117 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
119 fileChangedTimer=new QTimer (this);
120 fileChangedTimer->start(3000);
121 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
133 animationUse=settings.readBoolEntry("/animation/use",false);
134 animationTicks=settings.readNumEntry("/animation/ticks",10);
135 animationInterval=settings.readNumEntry("/animation/interval",50);
137 animationTimer=new QTimer (this);
138 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
141 defLinkColor=QColor (0,0,255);
142 defXLinkColor=QColor (180,180,180);
143 linkcolorhint=LinkableMapObj::DefaultColor;
144 linkstyle=LinkableMapObj::PolyParabel;
146 defXLinkColor=QColor (230,230,230);
154 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
158 void VymModel::makeTmpDirectories()
160 // Create unique temporary directories
161 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
162 histPath = tmpMapDir+"/history";
168 MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
173 bool VymModel::isRepositionBlocked()
175 return blockReposition;
178 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
180 cout << "VymModel::updateActions \n";
181 // Tell mainwindow to update states of actions
182 mainWindow->updateActions();
187 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
189 // tmpdir temporary directory to which data will be written
190 // prefix mapname, which will be appended to images etc.
191 // writeflags Only write flags for "real" save of map, not undo
192 // offset offset of bbox of whole map in scene.
193 // Needed for XML export
202 case LinkableMapObj::Line:
205 case LinkableMapObj::Parabel:
208 case LinkableMapObj::PolyLine:
212 ls="StylePolyParabel";
216 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
218 if (linkcolorhint==LinkableMapObj::HeadingColor)
219 colhint=xml.attribut("linkColorHint","HeadingColor");
221 QString mapAttr=xml.attribut("version",vymVersion);
223 mapAttr+= xml.attribut("author",author) +
224 xml.attribut("comment",comment) +
225 xml.attribut("date",getDate()) +
226 xml.attribut("countBranches", QString().number(countBranches())) +
227 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
228 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
229 xml.attribut("linkStyle", ls ) +
230 xml.attribut("linkColor", defLinkColor.name() ) +
231 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
232 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
234 s+=xml.beginElement("vymmap",mapAttr);
237 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
238 standardFlagsDefault->resetUsedCounter();
240 // Reset the counters before saving
241 // TODO constr. of FIO creates lots of objects, better do this in some other way...
242 FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
244 // Build xml recursivly
245 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
246 // Save all mapcenters as complete map, if saveSel not set
247 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
250 if ( typeid(*saveSel) == typeid(BranchObj) )
252 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
253 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
255 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
258 // Save local settings
259 s+=settings.getDataXML (destPath);
262 if (!selection.isEmpty() && !saveSel )
263 s+=xml.valueElement("select",selection.getSelectString());
266 s+=xml.endElement("vymmap");
269 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
273 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
277 for (int i=0; i<mapCenters.count(); i++)
278 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
282 void VymModel::setFilePath(QString fpath, QString destname)
284 if (fpath.isEmpty() || fpath=="")
291 filePath=fpath; // becomes absolute path
292 fileName=fpath; // gets stripped of path
293 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
295 // If fpath is not an absolute path, complete it
296 filePath=QDir(fpath).absPath();
297 fileDir=filePath.left (1+filePath.findRev ("/"));
299 // Set short name, too. Search from behind:
300 int i=fileName.findRev("/");
301 if (i>=0) fileName=fileName.remove (0,i+1);
303 // Forget the .vym (or .xml) for name of map
304 mapName=fileName.left(fileName.findRev(".",-1,true) );
308 void VymModel::setFilePath(QString fpath)
310 setFilePath (fpath,fpath);
313 QString VymModel::getFilePath()
318 QString VymModel::getFileName()
323 QString VymModel::getMapName()
328 QString VymModel::getDestPath()
333 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
335 ErrorCode err=success;
337 parseBaseHandler *handler;
341 case VymMap: handler=new parseVYMHandler; break;
342 case FreemindMap : handler=new parseFreemindHandler; break;
344 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
345 "Unknown FileType in VymModel::load()");
349 bool zipped_org=zipped;
353 selModel->clearSelection();
354 // FIXME-2 VM not needed??? model->setMapEditor(this);
355 // (map state is set later at end of load...)
358 BranchObj *bo=getSelectedBranch();
359 if (!bo) return aborted;
360 if (lmode==ImportAdd)
361 saveStateChangingPart(
364 QString("addMapInsert (%1)").arg(fname),
365 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
367 saveStateChangingPart(
370 QString("addMapReplace(%1)").arg(fname),
371 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
375 // Create temporary directory for packing
377 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
380 QMessageBox::critical( 0, tr( "Critical Load Error" ),
381 tr("Couldn't create temporary directory before load\n"));
386 err=unzipDir (tmpZipDir,fname);
396 // Look for mapname.xml
397 xmlfile= fname.left(fname.findRev(".",-1,true));
398 xmlfile=xmlfile.section( '/', -1 );
399 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
400 if (!mfile.exists() )
402 // mapname.xml does not exist, well,
403 // maybe someone renamed the mapname.vym file...
404 // Try to find any .xml in the toplevel
405 // directory of the .vym file
406 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
407 if (flist.count()==1)
409 // Only one entry, take this one
410 xmlfile=tmpZipDir + "/"+flist.first();
413 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
414 *it=tmpZipDir + "/" + *it;
415 // TODO Multiple entries, load all (but only the first one into this ME)
416 //mainWindow->fileLoadFromTmp (flist);
417 //returnCode=1; // Silently forget this attempt to load
418 qWarning ("MainWindow::load (fn) multimap found...");
421 if (flist.isEmpty() )
423 QMessageBox::critical( 0, tr( "Critical Load Error" ),
424 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
427 } //file doesn't exist
429 xmlfile=mfile.name();
432 QFile file( xmlfile);
434 // I am paranoid: file should exist anyway
435 // according to check in mainwindow.
438 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
439 tr(QString("Couldn't open map %1").arg(file.name())));
443 bool blockSaveStateOrg=blockSaveState;
444 blockReposition=true;
446 QXmlInputSource source( file);
447 QXmlSimpleReader reader;
448 reader.setContentHandler( handler );
449 reader.setErrorHandler( handler );
450 handler->setModel ( this);
453 // We need to set the tmpDir in order to load files with rel. path
458 tmpdir=fname.left(fname.findRev("/",-1));
459 handler->setTmpDir (tmpdir);
460 handler->setInputFile (file.name());
461 handler->setLoadMode (lmode);
462 bool ok = reader.parse( source );
463 blockReposition=false;
464 blockSaveState=blockSaveStateOrg;
468 reposition(); // FIXME-2 VM reposition the view instead...
475 autosaveTimer->stop();
478 // Reset timestamp to check for later updates of file
479 fileChangedTime=QFileInfo (destPath).lastModified();
482 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
483 tr( handler->errorProtocol() ) );
485 // Still return "success": the map maybe at least
486 // partially read by the parser
491 removeDir (QDir(tmpZipDir));
493 // Restore original zip state
500 ErrorCode VymModel::save (const SaveMode &savemode)
504 QString safeFilePath;
506 ErrorCode err=success;
510 mapFileName=mapName+".xml";
512 // use name given by user, even if he chooses .doc
513 mapFileName=fileName;
515 // Look, if we should zip the data:
518 QMessageBox mb( vymName,
519 tr("The map %1\ndid not use the compressed "
520 "vym file format.\nWriting it uncompressed will also write images \n"
521 "and flags and thus may overwrite files in the "
522 "given directory\n\nDo you want to write the map").arg(filePath),
523 QMessageBox::Warning,
524 QMessageBox::Yes | QMessageBox::Default,
526 QMessageBox::Cancel | QMessageBox::Escape);
527 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
528 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
529 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
532 case QMessageBox::Yes:
533 // save compressed (default file format)
536 case QMessageBox::No:
540 case QMessageBox::Cancel:
547 // First backup existing file, we
548 // don't want to add to old zip archives
552 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
554 QString backupFileName(destPath + "~");
555 QFile backupFile(backupFileName);
556 if (backupFile.exists() && !backupFile.remove())
558 QMessageBox::warning(0, tr("Save Error"),
559 tr("%1\ncould not be removed before saving").arg(backupFileName));
561 else if (!f.rename(backupFileName))
563 QMessageBox::warning(0, tr("Save Error"),
564 tr("%1\ncould not be renamed before saving").arg(destPath));
571 // Create temporary directory for packing
573 tmpZipDir=makeTmpDir (ok,"vym-zip");
576 QMessageBox::critical( 0, tr( "Critical Load Error" ),
577 tr("Couldn't create temporary directory before save\n"));
581 safeFilePath=filePath;
582 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
585 // Create mapName and fileDir
586 makeSubDirs (fileDir);
589 if (savemode==CompleteMap || selection.isEmpty())
592 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
595 autosaveTimer->stop();
600 if (selectionType()==TreeItem::Image)
603 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
604 // TODO take care of multiselections
607 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
610 qWarning ("ME::saveStringToDisk failed!");
616 if (err==success) err=zipDir (tmpZipDir,destPath);
619 removeDir (QDir(tmpZipDir));
621 // Restore original filepath outside of tmp zip dir
622 setFilePath (safeFilePath);
626 fileChangedTime=QFileInfo (destPath).lastModified();
630 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
632 QString pathDir=path.left(path.findRev("/"));
638 // We need to parse saved XML data
639 parseVYMHandler handler;
640 QXmlInputSource source( file);
641 QXmlSimpleReader reader;
642 reader.setContentHandler( &handler );
643 reader.setErrorHandler( &handler );
644 handler.setModel ( this);
645 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
646 if (undoSel.isEmpty())
650 handler.setLoadMode (NewMap);
654 handler.setLoadMode (ImportReplace);
656 blockReposition=true;
657 bool ok = reader.parse( source );
658 blockReposition=false;
661 // This should never ever happen
662 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
663 handler.errorProtocol());
666 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
669 void VymModel::addMapInsertInt (const QString &path, int pos)
671 BranchObj *sel=getSelectedBranch();
674 QString pathDir=path.left(path.findRev("/"));
680 // We need to parse saved XML data
681 parseVYMHandler handler;
682 QXmlInputSource source( file);
683 QXmlSimpleReader reader;
684 reader.setContentHandler( &handler );
685 reader.setErrorHandler( &handler );
686 handler.setModel (this);
687 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
688 handler.setLoadMode (ImportAdd);
689 blockReposition=true;
690 bool ok = reader.parse( source );
691 blockReposition=false;
694 // This should never ever happen
695 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
696 handler.errorProtocol());
698 if (sel->getDepth()>0)
699 sel->getLastBranch()->linkTo (sel,pos);
701 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
705 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
707 TreeItem *fi=createImage();
710 FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
718 void VymModel::loadFloatImage ()
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);
763 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
768 void VymModel::saveFloatImage ()
770 FloatImageObj *fio=selection.getFloatImage();
773 QFileDialog *fd=new QFileDialog( NULL);
774 fd->setFilters (imageIO.getFilters());
775 fd->setCaption(vymName+" - " +tr("Save image"));
776 fd->setFileMode( QFileDialog::AnyFile );
777 fd->setDirectory (lastImageDir);
778 // fd->setSelection (fio->getOriginalFilename());
782 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
784 fn=fd->selectedFiles().at(0);
785 if (QFile (fn).exists() )
787 QMessageBox mb( vymName,
788 tr("The file %1 exists already.\n"
789 "Do you want to overwrite it?").arg(fn),
790 QMessageBox::Warning,
791 QMessageBox::Yes | QMessageBox::Default,
792 QMessageBox::Cancel | QMessageBox::Escape,
793 QMessageBox::NoButton );
795 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
796 mb.setButtonText( QMessageBox::No, tr("Cancel"));
799 case QMessageBox::Yes:
802 case QMessageBox::Cancel:
809 saveFloatImageInt (fio,fd->selectedFilter(),fn );
816 void VymModel::importDirInt(BranchObj *dst, QDir d)
818 BranchObj *bo=getSelectedBranch();
821 // Traverse directories
822 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
823 QFileInfoList list = d.entryInfoList();
826 for (int i = 0; i < list.size(); ++i)
829 if (fi.fileName() != "." && fi.fileName() != ".." )
832 bo=dst->getLastBranch();
833 bo->setHeading (fi.fileName() );
834 bo->setColor (QColor("blue"));
836 if ( !d.cd(fi.fileName()) )
837 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
840 // Recursively add subdirs
847 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
848 list = d.entryInfoList();
850 for (int i = 0; i < list.size(); ++i)
854 bo=dst->getLastBranch();
855 bo->setHeading (fi.fileName() );
856 bo->setColor (QColor("black"));
857 if (fi.fileName().right(4) == ".vym" )
858 bo->setVymLink (fi.filePath());
863 void VymModel::importDirInt (const QString &s)
865 BranchObj *bo=getSelectedBranch();
868 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
875 void VymModel::importDir()
877 BranchObj *bo=getSelectedBranch();
881 filters <<"VYM map (*.vym)";
882 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
883 fd->setMode (QFileDialog::DirectoryOnly);
884 fd->setFilters (filters);
885 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
889 if ( fd->exec() == QDialog::Accepted )
891 importDirInt (fd->selectedFile() );
893 //FIXME-3 VM needed? scene()->update();
899 void VymModel::autosave()
904 cout << "VymModel::autosave rejected due to missing filePath\n";
907 QDateTime now=QDateTime().currentDateTime();
909 // Disable autosave, while we have gone back in history
910 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
911 if (redosAvail>0) return;
913 // Also disable autosave for new map without filename
914 if (filePath.isEmpty()) return;
917 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
919 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
920 mainWindow->fileSave (this);
923 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
928 void VymModel::fileChanged()
930 // Check if file on disk has changed meanwhile
931 if (!filePath.isEmpty())
933 QDateTime tmod=QFileInfo (filePath).lastModified();
934 if (tmod>fileChangedTime)
936 // FIXME-2 VM switch to current mapeditor and finish lineedits...
937 QMessageBox mb( vymName,
938 tr("The file of the map on disk has changed:\n\n"
939 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
940 QMessageBox::Question,
942 QMessageBox::Cancel | QMessageBox::Default,
943 QMessageBox::NoButton );
945 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
946 mb.setButtonText( QMessageBox::No, tr("Ignore"));
949 case QMessageBox::Yes:
951 load (filePath,NewMap,fileType);
952 case QMessageBox::Cancel:
953 fileChangedTime=tmod; // allow autosave to overwrite newer file!
959 bool VymModel::isDefault()
964 void VymModel::makeDefault()
970 bool VymModel::hasChanged()
975 void VymModel::setChanged()
977 cout << "VM::setChanged()\n";
980 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
981 cout <<" timer started with "<<settings.value("/mainwindow/autosave/ms/",300000).toInt()<<endl;
990 QString VymModel::getObjectName (const LinkableMapObj *lmo)
993 if (!lmo) return QString("Error: NULL has no name!");
995 if ((typeid(*lmo) == typeid(BranchObj) ||
996 typeid(*lmo) == typeid(MapCenterObj)))
999 s=(((BranchObj*)lmo)->getHeading());
1000 if (s=="") s="unnamed";
1001 return QString("branch (%1)").arg(s);
1003 if ((typeid(*lmo) == typeid(FloatImageObj) ))
1004 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
1005 return QString("Unknown type has no name!");
1008 void VymModel::redo()
1010 // Can we undo at all?
1011 if (redosAvail<1) return;
1013 bool blockSaveStateOrg=blockSaveState;
1014 blockSaveState=true;
1018 if (undosAvail<stepsTotal) undosAvail++;
1020 if (curStep>stepsTotal) curStep=1;
1021 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1022 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1023 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1024 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1025 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1026 QString version=undoSet.readEntry ("/history/version");
1028 /* TODO Maybe check for version, if we save the history
1029 if (!checkVersion(version))
1030 QMessageBox::warning(0,tr("Warning"),
1031 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1034 // Find out current undo directory
1035 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1039 cout << "VymModel::redo() begin\n";
1040 cout << " undosAvail="<<undosAvail<<endl;
1041 cout << " redosAvail="<<redosAvail<<endl;
1042 cout << " curStep="<<curStep<<endl;
1043 cout << " ---------------------------"<<endl;
1044 cout << " comment="<<comment.toStdString()<<endl;
1045 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1046 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1047 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1048 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1049 cout << " ---------------------------"<<endl<<endl;
1052 // select object before redo
1053 if (!redoSelection.isEmpty())
1054 select (redoSelection);
1057 parseAtom (redoCommand);
1060 blockSaveState=blockSaveStateOrg;
1062 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1063 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1064 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1065 undoSet.writeSettings(histPath);
1067 mainWindow->updateHistory (undoSet);
1070 /* TODO remove testing
1071 cout << "ME::redo() end\n";
1072 cout << " undosAvail="<<undosAvail<<endl;
1073 cout << " redosAvail="<<redosAvail<<endl;
1074 cout << " curStep="<<curStep<<endl;
1075 cout << " ---------------------------"<<endl<<endl;
1081 bool VymModel::isRedoAvailable()
1083 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1089 void VymModel::undo()
1091 // Can we undo at all?
1092 if (undosAvail<1) return;
1094 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1096 bool blockSaveStateOrg=blockSaveState;
1097 blockSaveState=true;
1099 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1100 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1101 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1102 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1103 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1104 QString version=undoSet.readEntry ("/history/version");
1106 /* TODO Maybe check for version, if we save the history
1107 if (!checkVersion(version))
1108 QMessageBox::warning(0,tr("Warning"),
1109 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1112 // Find out current undo directory
1113 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1115 // select object before undo
1116 if (!undoSelection.isEmpty())
1117 select (undoSelection);
1121 cout << "VymModel::undo() begin\n";
1122 cout << " undosAvail="<<undosAvail<<endl;
1123 cout << " redosAvail="<<redosAvail<<endl;
1124 cout << " curStep="<<curStep<<endl;
1125 cout << " ---------------------------"<<endl;
1126 cout << " comment="<<comment.toStdString()<<endl;
1127 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1128 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1129 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1130 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1131 cout << " ---------------------------"<<endl<<endl;
1133 parseAtom (undoCommand);
1138 if (curStep<1) curStep=stepsTotal;
1142 blockSaveState=blockSaveStateOrg;
1143 /* TODO remove testing
1144 cout << "VymModel::undo() end\n";
1145 cout << " undosAvail="<<undosAvail<<endl;
1146 cout << " redosAvail="<<redosAvail<<endl;
1147 cout << " curStep="<<curStep<<endl;
1148 cout << " ---------------------------"<<endl<<endl;
1151 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1152 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1153 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1154 undoSet.writeSettings(histPath);
1156 mainWindow->updateHistory (undoSet);
1159 ensureSelectionVisible();
1162 bool VymModel::isUndoAvailable()
1164 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1170 void VymModel::gotoHistoryStep (int i)
1172 // Restore variables
1173 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1174 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1176 if (i<0) i=undosAvail+redosAvail;
1178 // Clicking above current step makes us undo things
1181 for (int j=0; j<undosAvail-i; j++) undo();
1184 // Clicking below current step makes us redo things
1186 for (int j=undosAvail; j<i; j++)
1188 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1192 // And ignore clicking the current row ;-)
1196 QString VymModel::getHistoryPath()
1198 QString histName(QString("history-%1").arg(curStep));
1199 return (tmpMapDir+"/"+histName);
1202 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
1204 sendData(redoCom); //FIXME-3 testing
1209 if (blockSaveState) return;
1211 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1213 // Find out current undo directory
1214 if (undosAvail<stepsTotal) undosAvail++;
1216 if (curStep>stepsTotal) curStep=1;
1218 QString backupXML="";
1219 QString histDir=getHistoryPath();
1220 QString bakMapPath=histDir+"/map.xml";
1222 // Create histDir if not available
1225 makeSubDirs (histDir);
1227 // Save depending on how much needs to be saved
1229 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1231 QString undoCommand="";
1232 if (savemode==UndoCommand)
1234 undoCommand=undoCom;
1236 else if (savemode==PartOfMap )
1238 undoCommand=undoCom;
1239 undoCommand.replace ("PATH",bakMapPath);
1242 if (!backupXML.isEmpty())
1243 // Write XML Data to disk
1244 saveStringToDisk (bakMapPath,backupXML);
1246 // We would have to save all actions in a tree, to keep track of
1247 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1250 // Write the current state to disk
1251 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1252 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1253 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1254 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1255 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1256 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1257 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1258 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1259 undoSet.setEntry (QString("/history/version"),vymVersion);
1260 undoSet.writeSettings(histPath);
1264 // TODO remove after testing
1265 //cout << " into="<< histPath.toStdString()<<endl;
1266 cout << " stepsTotal="<<stepsTotal<<
1267 ", undosAvail="<<undosAvail<<
1268 ", redosAvail="<<redosAvail<<
1269 ", curStep="<<curStep<<endl;
1270 cout << " ---------------------------"<<endl;
1271 cout << " comment="<<comment.toStdString()<<endl;
1272 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1273 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1274 cout << " redoCom="<<redoCom.toStdString()<<endl;
1275 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1276 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1277 cout << " ---------------------------"<<endl;
1280 mainWindow->updateHistory (undoSet);
1286 void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
1288 // save the selected part of the map, Undo will replace part of map
1289 QString undoSelection="";
1291 undoSelection=getSelectString(undoSel);
1293 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1294 QString redoSelection="";
1296 redoSelection=getSelectString(undoSel);
1298 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1301 saveState (PartOfMap,
1302 undoSelection, "addMapReplace (\"PATH\")",
1308 void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
1312 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1315 QString undoSelection=getSelectString (redoSel->getParObj());
1316 QString redoSelection=getSelectString(redoSel);
1317 if (typeid(*redoSel) == typeid(BranchObj) )
1319 // save the selected branch of the map, Undo will insert part of map
1320 saveState (PartOfMap,
1321 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
1322 redoSelection, "delete ()",
1329 void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
1331 // "Normal" savestate: save commands, selections and comment
1332 // so just save commands for undo and redo
1333 // and use current selection
1335 QString redoSelection="";
1336 if (redoSel) redoSelection=getSelectString(redoSel);
1337 QString undoSelection="";
1338 if (undoSel) undoSelection=getSelectString(undoSel);
1340 saveState (UndoCommand,
1347 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1349 // "Normal" savestate: save commands, selections and comment
1350 // so just save commands for undo and redo
1351 // and use current selection
1352 saveState (UndoCommand,
1359 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1361 // "Normal" savestate applied to model (no selection needed):
1362 // save commands and comment
1363 saveState (UndoCommand,
1371 QGraphicsScene* VymModel::getScene ()
1376 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1378 LinkableMapObj *lmo;
1380 for (int i=0;i<mapCenters.count(); i++)
1382 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1383 if (lmo) return lmo;
1388 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1390 LinkableMapObj *lmo;
1396 part=s.section(",",0,0);
1398 num=part.right(part.length() - 3);
1399 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1400 return mapCenters.at(num.toInt() );
1403 for (int i=0; i<mapCenters.count(); i++)
1405 lmo=mapCenters.at(i)->findObjBySelect(s);
1406 if (lmo) return lmo;
1411 LinkableMapObj* VymModel::findID (const QString &s)
1413 LinkableMapObj *lmo;
1414 for (int i=0; i<mapCenters.count(); i++)
1416 lmo=mapCenters.at(i)->findID (s);
1417 if (lmo) return lmo;
1422 //////////////////////////////////////////////
1424 //////////////////////////////////////////////
1425 void VymModel::setVersion (const QString &s)
1430 void VymModel::setAuthor (const QString &s)
1433 QString ("setMapAuthor (\"%1\")").arg(author),
1434 QString ("setMapAuthor (\"%1\")").arg(s),
1435 QString ("Set author of map to \"%1\"").arg(s)
1441 QString VymModel::getAuthor()
1446 void VymModel::setComment (const QString &s)
1449 QString ("setMapComment (\"%1\")").arg(comment),
1450 QString ("setMapComment (\"%1\")").arg(s),
1451 QString ("Set comment of map")
1457 QString VymModel::getComment ()
1462 QString VymModel::getDate ()
1464 return QDate::currentDate().toString ("yyyy-MM-dd");
1467 int VymModel::countBranches() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1471 TreeItem *prev=NULL;
1483 void VymModel::setHeading(const QString &s)
1485 BranchObj *sel=getSelectedBranch();
1490 "setHeading (\""+sel->getHeading()+"\")",
1492 "setHeading (\""+s+"\")",
1493 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1494 sel->setHeading(s );
1495 /* FIXME-3 testing only
1497 TreeItem *ti=getSelectedItem();
1501 //FIXME-3 VM ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1502 //QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1503 //FIXME-3 VM testing only cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1504 QModelIndex ix2=index (ti);
1505 emit (dataChanged ( ix2,ix2));
1509 cout << "Warning: VM::setHeading ti==NULL\n";
1512 //cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1516 ensureSelectionVisible();
1520 BranchObj* VymModel::findText (QString s, bool cs)
1523 QTextDocument::FindFlags flags=0;
1524 if (cs) flags=QTextDocument::FindCaseSensitively;
1527 { // Nothing found or new find process
1529 // nothing found, start again
1533 next (findCurrent,findPrevious,d);
1535 bool searching=true;
1536 bool foundNote=false;
1537 while (searching && !EOFind)
1541 // Searching in Note
1542 if (findCurrent->getNote().contains(s,cs))
1544 select (findCurrent);
1546 if (getSelectedBranch()!=itFind)
1549 ensureSelectionVisible();
1552 if (textEditor->findText(s,flags))
1558 // Searching in Heading
1559 if (searching && findCurrent->getHeading().contains (s,cs) )
1561 select(findCurrent);
1567 if (!next(findCurrent,findPrevious,d) )
1570 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1573 return getSelectedBranch();
1578 void VymModel::findReset()
1579 { // Necessary if text to find changes during a find process
1587 void VymModel::setScene (QGraphicsScene *s)
1589 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1590 //init(); // Here we have a mapScene set,
1591 // which is (still) needed to create MapCenters
1594 void VymModel::setURL(const QString &url)
1596 BranchObj *bo=getSelectedBranch();
1599 QString oldurl=bo->getURL();
1603 QString ("setURL (\"%1\")").arg(oldurl),
1605 QString ("setURL (\"%1\")").arg(url),
1606 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1611 ensureSelectionVisible();
1615 QString VymModel::getURL()
1617 BranchObj *bo=getSelectedBranch();
1619 return bo->getURL();
1624 QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
1626 return QStringList();
1629 BranchObj *bo=getSelectedBranch();
1635 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1643 void VymModel::linkFloatImageTo(const QString &dstString)
1645 FloatImageObj *fio=selection.getFloatImage();
1648 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1649 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1650 typeid(*dst)==typeid (MapCenterObj)))
1652 LinkableMapObj *dstPar=dst->getParObj();
1653 QString parString=getSelectString(dstPar);
1654 QString fioPreSelectString=getSelectString(fio);
1655 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1656 ((BranchObj*)dst)->addFloatImage (fio);
1657 selection.unselect();
1658 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1659 fio=((BranchObj*)dst)->getLastFloatImage();
1662 selection.select(fio);
1664 getSelectString(fio),
1665 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1667 QString ("linkTo (\"%1\")").arg(dstString),
1668 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1674 void VymModel::setFrameType(const FrameObj::FrameType &t)
1676 BranchObj *bo=getSelectedBranch();
1679 QString s=bo->getFrameTypeName();
1680 bo->setFrameType (t);
1681 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1682 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1688 void VymModel::setFrameType(const QString &s)
1690 BranchObj *bo=getSelectedBranch();
1693 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1694 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1695 bo->setFrameType (s);
1701 void VymModel::setFramePenColor(const QColor &c)
1703 BranchObj *bo=getSelectedBranch();
1706 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1707 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1708 bo->setFramePenColor (c);
1712 void VymModel::setFrameBrushColor(const QColor &c)
1714 BranchObj *bo=getSelectedBranch();
1717 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1718 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1719 bo->setFrameBrushColor (c);
1723 void VymModel::setFramePadding (const int &i)
1725 BranchObj *bo=getSelectedBranch();
1728 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1729 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1730 bo->setFramePadding (i);
1736 void VymModel::setFrameBorderWidth(const int &i)
1738 BranchObj *bo=getSelectedBranch();
1741 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1742 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1743 bo->setFrameBorderWidth (i);
1749 void VymModel::setIncludeImagesVer(bool b)
1751 BranchObj *bo=getSelectedBranch();
1754 QString u= b ? "false" : "true";
1755 QString r=!b ? "false" : "true";
1759 QString("setIncludeImagesVertically (%1)").arg(u),
1761 QString("setIncludeImagesVertically (%1)").arg(r),
1762 QString("Include images vertically in %1").arg(getObjectName(bo))
1764 bo->setIncludeImagesVer(b);
1769 void VymModel::setIncludeImagesHor(bool b)
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);
1789 void VymModel::setHideLinkUnselected (bool b)
1791 LinkableMapObj *sel=getSelectedLMO();
1793 (selectionType() == TreeItem::Branch ||
1794 selectionType() == TreeItem::MapCenter ||
1795 selectionType() == TreeItem::Image ))
1797 QString u= b ? "false" : "true";
1798 QString r=!b ? "false" : "true";
1802 QString("setHideLinkUnselected (%1)").arg(u),
1804 QString("setHideLinkUnselected (%1)").arg(r),
1805 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1807 sel->setHideLinkUnselected(b);
1811 void VymModel::setHideExport(bool b)
1813 BranchObj *bo=getSelectedBranch();
1816 bo->setHideInExport (b);
1817 QString u= b ? "false" : "true";
1818 QString r=!b ? "false" : "true";
1822 QString ("setHideExport (%1)").arg(u),
1824 QString ("setHideExport (%1)").arg(r),
1825 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1830 // FIXME-3 VM needed? scene()->update();
1834 void VymModel::toggleHideExport()
1836 BranchObj *bo=getSelectedBranch();
1838 setHideExport ( !bo->hideInExport() );
1842 void VymModel::copy()
1844 LinkableMapObj *sel=getSelectedLMO();
1846 (selectionType() == TreeItem::Branch ||
1847 selectionType() == TreeItem::MapCenter ||
1848 selectionType() == TreeItem::Image ))
1850 if (redosAvail == 0)
1853 QString s=getSelectString(sel);
1854 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1855 curClipboard=curStep;
1858 // Copy also to global clipboard, because we are at last step in history
1859 QString bakMapName(QString("history-%1").arg(curStep));
1860 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1861 copyDir (bakMapDir,clipboardDir );
1863 clipboardEmpty=false;
1869 void VymModel::pasteNoSave(const int &n)
1871 bool old=blockSaveState;
1872 blockSaveState=true;
1873 bool zippedOrg=zipped;
1874 if (redosAvail > 0 || n!=0)
1876 // Use the "historical" buffer
1877 QString bakMapName(QString("history-%1").arg(n));
1878 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1879 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1881 // Use the global buffer
1882 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1887 void VymModel::paste()
1889 BranchObj *sel=getSelectedBranch();
1892 saveStateChangingPart(
1895 QString ("paste (%1)").arg(curClipboard),
1896 QString("Paste to %1").arg( getObjectName(sel))
1903 void VymModel::cut()
1905 LinkableMapObj *sel=getSelectedLMO();
1906 if ( sel && (selectionType() == TreeItem::Branch ||
1907 selectionType()==TreeItem::MapCenter ||
1908 selectionType()==TreeItem::Image))
1910 /* No savestate! savestate is called in cutNoSave
1911 saveStateChangingPart(
1915 QString("Cut %1").arg(getObjectName(sel ))
1924 void VymModel::moveBranchUp()
1926 BranchObj* bo=getSelectedBranch();
1930 if (!bo->canMoveBranchUp()) return;
1931 par=(BranchObj*)(bo->getParObj());
1932 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1933 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1935 //FIXME-3 VM needed? scene()->update();
1937 ensureSelectionVisible();
1941 void VymModel::moveBranchDown()
1943 BranchObj* bo=getSelectedBranch();
1947 if (!bo->canMoveBranchDown()) return;
1948 par=(BranchObj*)(bo->getParObj());
1949 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1950 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1952 //FIXME-3 VM needed? scene()->update();
1954 ensureSelectionVisible();
1958 void VymModel::sortChildren()
1960 BranchObj* bo=getSelectedBranch();
1963 if(bo->countBranches()>1)
1965 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1968 ensureSelectionVisible();
1973 void VymModel::createMapCenter()
1975 MapCenterObj *mco=addMapCenter (QPointF (0,0) );
1979 void VymModel::createBranch()
1981 addNewBranchInt (-2);
1985 TreeItem* VymModel::createImage()
1987 BranchObj *bo=getSelectedBranch();
1990 FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
1993 QList<QVariant> cData;
1994 cData << "VM:createImage" << "undef"<<"undef";
1995 TreeItem *parti=bo->getTreeItem();
1996 TreeItem *ti=new TreeItem (cData,parti);
1997 ti->setLMO (newfio);
1998 ti->setType (TreeItem::Image);
1999 parti->appendChild (ti);
2003 newfio->setTreeItem (ti);
2004 select (newfio); // FIXME-2 VM really needed here?
2011 MapCenterObj* VymModel::addMapCenter ()
2013 MapCenterObj *mco=addMapCenter (contextPos);
2014 //FIXME-3 selection.select (mco);
2016 ensureSelectionVisible();
2021 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2022 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2027 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
2029 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
2030 mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2031 mapCenter->move (absPos);
2032 mapCenter->setVisibility (true);
2033 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2034 mapCenters.append(mapCenter);
2037 QModelIndex parix=index(rootItem);
2039 int n=rootItem->branchCount();
2041 emit (layoutAboutToBeChanged() );
2042 beginInsertRows (parix,n,n+1);
2044 QList<QVariant> cData;
2045 cData << "VM:addMapCenter" << "undef"<<"undef";
2046 TreeItem *ti=new TreeItem (cData,rootItem);
2047 ti->setLMO (mapCenter);
2048 ti->setType (TreeItem::MapCenter);
2049 mapCenter->setTreeItem (ti);
2050 rootItem->appendChild (ti);
2053 emit (newChildObject (parix));
2054 emit (layoutChanged() );
2058 qWarning ("MW::insertRow a");
2059 if (!insertRow(0, parix))
2061 std::cout << " war nix...\n";
2063 qWarning ("MW::insertRow b");
2069 MapCenterObj* VymModel::removeMapCenter(MapCenterObj* mco)
2071 int i=mapCenters.indexOf (mco);
2074 mapCenters.removeAt (i);
2076 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2081 MapCenterObj* VymModel::getLastMapCenter()
2083 if (mapCenters.size()>0)
2084 return mapCenters.last();
2091 BranchObj* VymModel::addNewBranchInt(int num)
2093 // Depending on pos:
2094 // -3 insert in children of parent above selection
2095 // -2 add branch to selection
2096 // -1 insert in children of parent below selection
2097 // 0..n insert in children of parent at pos
2098 BranchObj *newbo=NULL;
2099 BranchObj *bo=getSelectedBranch();
2104 // save scroll state. If scrolled, automatically select
2105 // new branch in order to tmp unscroll parent...
2106 newbo=bo->addBranch();
2109 QList<QVariant> cData;
2110 cData << "new" << "undef"<<"undef";
2112 TreeItem *parti=bo->getTreeItem();
2113 QModelIndex parix=index(parti);
2114 int n=parti->branchCount();
2116 emit (layoutAboutToBeChanged() );
2117 beginInsertRows (parix,n,n+1);
2118 TreeItem *ti=new TreeItem (cData,parti);
2120 ti->setType (TreeItem::Branch);
2122 parti->appendChild (ti);
2124 emit (newChildObject (parix));
2125 emit (layoutChanged() );
2129 newbo->setTreeItem (ti);
2130 select (newbo); // FIXME-2 VM really needed here?
2136 bo=(BranchObj*)bo->getParObj();
2137 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2141 bo=(BranchObj*)bo->getParObj();
2142 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
2148 BranchObj* VymModel::addNewBranch(int pos)
2150 // Different meaning than num in addNewBranchInt!
2154 BranchObj *bo = getSelectedBranch();
2155 BranchObj *newbo=NULL;
2159 // FIXME-1 VM do we still need this in model? setCursor (Qt::ArrowCursor);
2161 newbo=addNewBranchInt (pos-2);
2169 QString ("addBranch (%1)").arg(pos),
2170 QString ("Add new branch to %1").arg(getObjectName(bo)));
2173 // selection.update(); FIXME-3
2174 latestSelectionString=getSelectString(newbo);
2175 // In Network mode, the client needs to know where the new branch is,
2176 // so we have to pass on this information via saveState.
2177 // TODO: Get rid of this positioning workaround
2178 QString ps=qpointfToString (newbo->getAbsPos());
2179 sendData ("selectLatestAdded ()");
2180 sendData (QString("move %1").arg(ps));
2188 BranchObj* VymModel::addNewBranchBefore()
2190 BranchObj *newbo=NULL;
2191 BranchObj *bo = getSelectedBranch();
2192 if (bo && selectionType()==TreeItem::Branch)
2193 // We accept no MapCenterObj here, so we _have_ a parent
2195 QPointF p=bo->getRelPos();
2198 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2200 // add below selection
2201 newbo=parbo->insertBranch(bo->getNum()+1); //FIXME-1 VM still missing
2205 newbo->move2RelPos (p);
2207 // Move selection to new branch
2208 bo->linkTo (newbo,-1);
2210 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2211 QString ("Add branch before %1").arg(getObjectName(bo)));
2214 // selection.update(); FIXME-3
2217 latestSelectionString=selection.getSelectString();
2221 void VymModel::deleteSelection()
2223 BranchObj *bo = getSelectedBranch(); // FIXME-2 VM should not be necessary
2226 QModelIndex ix=getSelectedIndex();
2227 if (!ix.isValid() ) return;
2229 QModelIndex parentIndex=parent(ix);
2231 if (!parentIndex.isValid())
2233 cout << "VM::delete no valid parent ix\n";
2237 TreeItem *ti=bo->getTreeItem();
2239 if (selectionType()==TreeItem::MapCenter)
2241 // BranchObj* par=(BranchObj*)(bo->getParObj());
2242 //selection.unselect();
2243 /* FIXME-1 VM Note: does saveStateRemovingPart work for MCO? (No parent!)
2244 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2246 emit (layoutAboutToBeChanged() );
2248 parentIndex=parent(index(ti));
2249 cout << "VM::delete ti="<<ti<<" row="<<ix.row()<<" parIndex.valid="<<parentIndex.isValid()<<endl;
2251 beginRemoveRows (parentIndex,n,n);
2252 removeRows (n,1,parentIndex);
2253 bo=removeMapCenter ((MapCenterObj*)bo);
2258 ensureSelectionVisible();
2259 ensureSelectionVisible();
2263 emit (layoutChanged() );
2265 if (selectionType()==TreeItem::Branch)
2268 BranchObj* par=(BranchObj*)bo->getParObj();
2270 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2272 emit (layoutAboutToBeChanged() );
2274 cout << "VM::delete ti="<<ti<<" row="<<ix.row()<<endl;
2275 parentIndex=parent(index(ti));
2277 beginRemoveRows (parentIndex,n,n);
2278 removeRows (n,1,parentIndex);
2279 par->removeBranch(bo); // remove from BranchObj lists...
2282 ensureSelectionVisible();
2285 emit (layoutChanged() );
2288 FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
2293 BranchObj* par=(BranchObj*)fio->getParObj();
2294 saveStateChangingPart(
2298 QString("Delete %1").arg(getObjectName(fio))
2301 par->removeFloatImage(fio);
2304 ensureSelectionVisible();
2310 void VymModel::deleteKeepChildren() //FIXME-1 VM still missing
2313 BranchObj *bo=getSelectedBranch();
2317 par=(BranchObj*)(bo->getParObj());
2319 // Don't use this on mapcenter
2322 // Check if we have childs at all to keep
2323 if (bo->countBranches()==0)
2329 QPointF p=bo->getRelPos();
2330 saveStateChangingPart(
2333 "deleteKeepChildren ()",
2334 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2337 QString sel=getSelectString(bo);
2339 par->removeBranchHere(bo);
2342 getSelectedBranch()->move2RelPos (p);
2347 void VymModel::deleteChildren() //FIXME-1 VM still missing
2350 BranchObj *bo=getSelectedBranch();
2353 saveStateChangingPart(
2356 "deleteChildren ()",
2357 QString( "Remove children of branch %1").arg(getObjectName(bo))
2359 bo->removeChildren();
2365 bool VymModel::scrollBranch(BranchObj *bo)
2369 if (bo->isScrolled()) return false;
2370 if (bo->countBranches()==0) return false;
2371 if (bo->getDepth()==0) return false;
2377 QString ("%1 ()").arg(u),
2379 QString ("%1 ()").arg(r),
2380 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2384 // FIXME-3 VM needed? scene()->update();
2390 bool VymModel::unscrollBranch(BranchObj *bo)
2394 if (!bo->isScrolled()) return false;
2395 if (bo->countBranches()==0) return false;
2396 if (bo->getDepth()==0) return false;
2402 QString ("%1 ()").arg(u),
2404 QString ("%1 ()").arg(r),
2405 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2409 // FIXME-3 VM needed? scene()->update();
2415 void VymModel::toggleScroll()
2417 BranchObj *bo=getSelectedBranch();
2418 if (selectionType()==TreeItem::Branch )
2420 if (bo->isScrolled())
2421 unscrollBranch (bo);
2427 void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
2431 BranchObj *bo=getSelectedBranch();
2437 if (bo->isScrolled()) unscrollBranch (bo);
2444 void VymModel::addFloatImage (const QPixmap &img)
2446 BranchObj *bo=getSelectedBranch();
2449 FloatImageObj *fio=bo->addFloatImage();
2451 fio->setOriginalFilename("No original filename (image added by dropevent)");
2452 QString s=getSelectString(bo);
2453 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2454 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2456 // FIXME-3 VM needed? scene()->update();
2461 void VymModel::colorBranch (QColor c)
2463 BranchObj *bo=getSelectedBranch();
2468 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2470 QString ("colorBranch (\"%1\")").arg(c.name()),
2471 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2473 bo->setColor(c); // color branch
2477 void VymModel::colorSubtree (QColor c)
2479 BranchObj *bo=getSelectedBranch();
2482 saveStateChangingPart(
2485 QString ("colorSubtree (\"%1\")").arg(c.name()),
2486 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2488 bo->setColorSubtree (c); // color links, color children
2492 QColor VymModel::getCurrentHeadingColor()
2494 BranchObj *bo=getSelectedBranch();
2495 if (bo) return bo->getColor();
2497 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2503 void VymModel::editURL()
2505 BranchObj *bo=getSelectedBranch();
2509 QString text = QInputDialog::getText(
2510 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2511 bo->getURL(), &ok, NULL);
2513 // user entered something and pressed OK
2518 void VymModel::editLocalURL()
2520 BranchObj *bo=getSelectedBranch();
2523 QStringList filters;
2524 filters <<"All files (*)";
2525 filters << tr("Text","Filedialog") + " (*.txt)";
2526 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2527 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2528 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2529 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2530 fd->setFilters (filters);
2531 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2532 fd->setDirectory (lastFileDir);
2533 if (! bo->getVymLink().isEmpty() )
2534 fd->selectFile( bo->getURL() );
2537 if ( fd->exec() == QDialog::Accepted )
2539 lastFileDir=QDir (fd->directory().path());
2540 setURL (fd->selectedFile() );
2546 void VymModel::editHeading2URL()
2548 BranchObj *bo=getSelectedBranch();
2550 setURL (bo->getHeading());
2553 void VymModel::editBugzilla2URL()
2555 BranchObj *bo=getSelectedBranch();
2558 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2563 void VymModel::editFATE2URL()
2565 BranchObj *bo=getSelectedBranch();
2568 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2571 "setURL (\""+bo->getURL()+"\")",
2573 "setURL (\""+url+"\")",
2574 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2581 void VymModel::editVymLink()
2583 BranchObj *bo=getSelectedBranch();
2586 QStringList filters;
2587 filters <<"VYM map (*.vym)";
2588 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2589 fd->setFilters (filters);
2590 fd->setCaption(vymName+" - " +tr("Link to another map"));
2591 fd->setDirectory (lastFileDir);
2592 if (! bo->getVymLink().isEmpty() )
2593 fd->selectFile( bo->getVymLink() );
2597 if ( fd->exec() == QDialog::Accepted )
2599 lastFileDir=QDir (fd->directory().path());
2602 "setVymLink (\""+bo->getVymLink()+"\")",
2604 "setVymLink (\""+fd->selectedFile()+"\")",
2605 QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile())
2607 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2612 void VymModel::setVymLink (const QString &s)
2614 // Internal function, no saveState needed
2615 BranchObj *bo=getSelectedBranch();
2622 ensureSelectionVisible();
2626 void VymModel::deleteVymLink()
2628 BranchObj *bo=getSelectedBranch();
2633 "setVymLink (\""+bo->getVymLink()+"\")",
2635 "setVymLink (\"\")",
2636 QString("Unset vymlink of %1").arg(getObjectName(bo))
2638 bo->setVymLink ("" );
2641 // FIXME-3 VM needed? scene()->update();
2645 QString VymModel::getVymLink()
2647 BranchObj *bo=getSelectedBranch();
2649 return bo->getVymLink();
2655 QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
2657 return QStringList();
2660 BranchObj *bo=getSelectedBranch();
2666 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2675 void VymModel::followXLink(int i)
2677 BranchObj *bo=getSelectedBranch();
2680 bo=bo->XLinkTargetAt(i);
2683 selection.select(bo);
2684 ensureSelectionVisible();
2689 void VymModel::editXLink(int i) // FIXME-1 VM missing saveState
2691 BranchObj *bo=getSelectedBranch();
2694 XLinkObj *xlo=bo->XLinkAt(i);
2697 EditXLinkDialog dia;
2699 dia.setSelection(bo);
2700 if (dia.exec() == QDialog::Accepted)
2702 if (dia.useSettingsGlobal() )
2704 setMapDefXLinkColor (xlo->getColor() );
2705 setMapDefXLinkWidth (xlo->getWidth() );
2707 if (dia.deleteXLink())
2708 bo->deleteXLinkAt(i);
2718 //////////////////////////////////////////////
2720 //////////////////////////////////////////////
2722 void VymModel::parseAtom(const QString &atom)
2724 BranchObj *selb=getSelectedBranch();
2730 // Split string s into command and parameters
2731 parser.parseAtom (atom);
2732 QString com=parser.getCommand();
2734 // External commands
2735 /////////////////////////////////////////////////////////////////////
2736 if (com=="addBranch")
2738 if (selection.isEmpty())
2740 parser.setError (Aborted,"Nothing selected");
2743 parser.setError (Aborted,"Type of selection is not a branch");
2748 if (parser.checkParCount(pl))
2750 if (parser.parCount()==0)
2754 n=parser.parInt (ok,0);
2755 if (ok ) addNewBranch (n);
2759 /////////////////////////////////////////////////////////////////////
2760 } else if (com=="addBranchBefore")
2762 if (selection.isEmpty())
2764 parser.setError (Aborted,"Nothing selected");
2767 parser.setError (Aborted,"Type of selection is not a branch");
2770 if (parser.parCount()==0)
2772 addNewBranchBefore ();
2775 /////////////////////////////////////////////////////////////////////
2776 } else if (com==QString("addMapCenter"))
2778 if (parser.checkParCount(2))
2780 x=parser.parDouble (ok,0);
2783 y=parser.parDouble (ok,1);
2784 if (ok) addMapCenter (QPointF(x,y));
2787 /////////////////////////////////////////////////////////////////////
2788 } else if (com==QString("addMapReplace"))
2790 if (selection.isEmpty())
2792 parser.setError (Aborted,"Nothing selected");
2795 parser.setError (Aborted,"Type of selection is not a branch");
2796 } else if (parser.checkParCount(1))
2798 //s=parser.parString (ok,0); // selection
2799 t=parser.parString (ok,0); // path to map
2800 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2801 addMapReplaceInt(getSelectString(selb),t);
2803 /////////////////////////////////////////////////////////////////////
2804 } else if (com==QString("addMapInsert"))
2806 if (selection.isEmpty())
2808 parser.setError (Aborted,"Nothing selected");
2811 parser.setError (Aborted,"Type of selection is not a branch");
2814 if (parser.checkParCount(2))
2816 t=parser.parString (ok,0); // path to map
2817 n=parser.parInt(ok,1); // position
2818 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2819 addMapInsertInt(t,n);
2822 /////////////////////////////////////////////////////////////////////
2823 } else if (com=="clearFlags")
2825 if (selection.isEmpty() )
2827 parser.setError (Aborted,"Nothing selected");
2830 parser.setError (Aborted,"Type of selection is not a branch");
2831 } else if (parser.checkParCount(0))
2833 selb->clearStandardFlags();
2834 selb->updateFlagsToolbar();
2836 /////////////////////////////////////////////////////////////////////
2837 } else if (com=="colorBranch")
2839 if (selection.isEmpty())
2841 parser.setError (Aborted,"Nothing selected");
2844 parser.setError (Aborted,"Type of selection is not a branch");
2845 } else if (parser.checkParCount(1))
2847 QColor c=parser.parColor (ok,0);
2848 if (ok) colorBranch (c);
2850 /////////////////////////////////////////////////////////////////////
2851 } else if (com=="colorSubtree")
2853 if (selection.isEmpty())
2855 parser.setError (Aborted,"Nothing selected");
2858 parser.setError (Aborted,"Type of selection is not a branch");
2859 } else if (parser.checkParCount(1))
2861 QColor c=parser.parColor (ok,0);
2862 if (ok) colorSubtree (c);
2864 /////////////////////////////////////////////////////////////////////
2865 } else if (com=="copy")
2867 if (selection.isEmpty())
2869 parser.setError (Aborted,"Nothing selected");
2872 parser.setError (Aborted,"Type of selection is not a branch");
2873 } else if (parser.checkParCount(0))
2875 //FIXME-1 missing action for copy
2877 /////////////////////////////////////////////////////////////////////
2878 } else if (com=="cut")
2880 if (selection.isEmpty())
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")
2895 if (selection.isEmpty())
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")
2911 if (selection.isEmpty())
2913 parser.setError (Aborted,"Nothing selected");
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")
2924 if (selection.isEmpty())
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")
3002 if (selection.isEmpty())
3004 parser.setError (Aborted,"Nothing selected");
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 if (com=="linkTo")
3016 if (selection.isEmpty())
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 (typeid(*dst) == typeid(BranchObj) )
3032 // Get number in parent
3033 n=parser.parInt (ok,1);
3036 selb->linkTo ((BranchObj*)(dst),n);
3039 } else if (typeid(*dst) == typeid(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 (typeid(*dst) == typeid(BranchObj) ||
3066 typeid(*dst) == typeid(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")
3076 if (selection.isEmpty())
3078 parser.setError (Aborted,"Nothing selected");
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=="moveBranchUp")
3090 if (selection.isEmpty() )
3092 parser.setError (Aborted,"Nothing selected");
3095 parser.setError (Aborted,"Type of selection is not a branch");
3096 } else if (parser.checkParCount(0))
3100 /////////////////////////////////////////////////////////////////////
3101 } else if (com=="moveBranchDown")
3103 if (selection.isEmpty() )
3105 parser.setError (Aborted,"Nothing selected");
3108 parser.setError (Aborted,"Type of selection is not a branch");
3109 } else if (parser.checkParCount(0))
3113 /////////////////////////////////////////////////////////////////////
3114 } else if (com=="move")
3116 if (selection.isEmpty() )
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")
3136 if (selection.isEmpty() )
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")
3159 if (selection.isEmpty() )
3161 parser.setError (Aborted,"Nothing selected");
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")
3173 if (selection.isEmpty() )
3175 parser.setError (Aborted,"Nothing selected");
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 (selb->getHeading() == u)
3223 cout << "PASSED: " << qPrintable (c) << endl;
3226 cout << "FAILED: " << qPrintable (c) << endl;
3236 /////////////////////////////////////////////////////////////////////
3237 } else if (com=="saveImage")
3239 FloatImageObj *fio=selection.getFloatImage();
3242 parser.setError (Aborted,"Type of selection is not an image");
3243 } else if (parser.checkParCount(2))
3245 s=parser.parString(ok,0);
3248 t=parser.parString(ok,1);
3249 if (ok) saveFloatImageInt (fio,t,s);
3252 /////////////////////////////////////////////////////////////////////
3253 } else if (com=="scroll")
3255 if (selection.isEmpty() )
3257 parser.setError (Aborted,"Nothing selected");
3260 parser.setError (Aborted,"Type of selection is not a branch");
3261 } else if (parser.checkParCount(0))
3263 if (!scrollBranch (selb))
3264 parser.setError (Aborted,"Could not scroll branch");
3266 /////////////////////////////////////////////////////////////////////
3267 } else if (com=="select")
3269 if (parser.checkParCount(1))
3271 s=parser.parString(ok,0);
3274 /////////////////////////////////////////////////////////////////////
3275 } else if (com=="selectLastBranch")
3277 if (selection.isEmpty() )
3279 parser.setError (Aborted,"Nothing selected");
3282 parser.setError (Aborted,"Type of selection is not a branch");
3283 } else if (parser.checkParCount(0))
3285 BranchObj *bo=selb->getLastBranch();
3287 parser.setError (Aborted,"Could not select last branch");
3291 /////////////////////////////////////////////////////////////////////
3292 } else if (com=="selectLastImage")
3294 if (selection.isEmpty() )
3296 parser.setError (Aborted,"Nothing selected");
3299 parser.setError (Aborted,"Type of selection is not a branch");
3300 } else if (parser.checkParCount(0))
3302 FloatImageObj *fio=selb->getLastFloatImage();
3304 parser.setError (Aborted,"Could not select last image");
3308 /////////////////////////////////////////////////////////////////////
3309 } else if (com=="selectLatestAdded")
3311 if (latestSelectionString.isEmpty() )
3313 parser.setError (Aborted,"No latest added object");
3316 if (!select (latestSelectionString))
3317 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3319 /////////////////////////////////////////////////////////////////////
3320 } else if (com=="setFrameType")
3322 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3324 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3326 else if (parser.checkParCount(1))
3328 s=parser.parString(ok,0);
3329 if (ok) setFrameType (s);
3331 /////////////////////////////////////////////////////////////////////
3332 } else if (com=="setFramePenColor")
3334 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3336 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3338 else if (parser.checkParCount(1))
3340 QColor c=parser.parColor(ok,0);
3341 if (ok) setFramePenColor (c);
3343 /////////////////////////////////////////////////////////////////////
3344 } else if (com=="setFrameBrushColor")
3346 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3348 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3350 else if (parser.checkParCount(1))
3352 QColor c=parser.parColor(ok,0);
3353 if (ok) setFrameBrushColor (c);
3355 /////////////////////////////////////////////////////////////////////
3356 } else if (com=="setFramePadding")
3358 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3360 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3362 else if (parser.checkParCount(1))
3364 n=parser.parInt(ok,0);
3365 if (ok) setFramePadding(n);
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="setFrameBorderWidth")
3370 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3372 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3374 else if (parser.checkParCount(1))
3376 n=parser.parInt(ok,0);
3377 if (ok) setFrameBorderWidth (n);
3379 /////////////////////////////////////////////////////////////////////
3380 } else if (com=="setMapAuthor")
3382 if (parser.checkParCount(1))
3384 s=parser.parString(ok,0);
3385 if (ok) setAuthor (s);
3387 /////////////////////////////////////////////////////////////////////
3388 } else if (com=="setMapComment")
3390 if (parser.checkParCount(1))
3392 s=parser.parString(ok,0);
3393 if (ok) setComment(s);
3395 /////////////////////////////////////////////////////////////////////
3396 } else if (com=="setMapBackgroundColor")
3398 if (selection.isEmpty() )
3400 parser.setError (Aborted,"Nothing selected");
3401 } else if (! getSelectedBranch() )
3403 parser.setError (Aborted,"Type of selection is not a branch");
3404 } else if (parser.checkParCount(1))
3406 QColor c=parser.parColor (ok,0);
3407 if (ok) setMapBackgroundColor (c);
3409 /////////////////////////////////////////////////////////////////////
3410 } else if (com=="setMapDefLinkColor")
3412 if (selection.isEmpty() )
3414 parser.setError (Aborted,"Nothing selected");
3417 parser.setError (Aborted,"Type of selection is not a branch");
3418 } else if (parser.checkParCount(1))
3420 QColor c=parser.parColor (ok,0);
3421 if (ok) setMapDefLinkColor (c);
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="setMapLinkStyle")
3426 if (parser.checkParCount(1))
3428 s=parser.parString (ok,0);
3429 if (ok) setMapLinkStyle(s);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="setHeading")
3434 if (selection.isEmpty() )
3436 parser.setError (Aborted,"Nothing selected");
3439 parser.setError (Aborted,"Type of selection is not a branch");
3440 } else if (parser.checkParCount(1))
3442 s=parser.parString (ok,0);
3446 /////////////////////////////////////////////////////////////////////
3447 } else if (com=="setHideExport")
3449 if (selection.isEmpty() )
3451 parser.setError (Aborted,"Nothing selected");
3452 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3454 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3455 } else if (parser.checkParCount(1))
3457 b=parser.parBool(ok,0);
3458 if (ok) setHideExport (b);
3460 /////////////////////////////////////////////////////////////////////
3461 } else if (com=="setIncludeImagesHorizontally")
3463 if (selection.isEmpty() )
3465 parser.setError (Aborted,"Nothing selected");
3468 parser.setError (Aborted,"Type of selection is not a branch");
3469 } else if (parser.checkParCount(1))
3471 b=parser.parBool(ok,0);
3472 if (ok) setIncludeImagesHor(b);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="setIncludeImagesVertically")
3477 if (selection.isEmpty() )
3479 parser.setError (Aborted,"Nothing selected");
3482 parser.setError (Aborted,"Type of selection is not a branch");
3483 } else if (parser.checkParCount(1))
3485 b=parser.parBool(ok,0);
3486 if (ok) setIncludeImagesVer(b);
3488 /////////////////////////////////////////////////////////////////////
3489 } else if (com=="setHideLinkUnselected")
3491 if (selection.isEmpty() )
3493 parser.setError (Aborted,"Nothing selected");
3494 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3496 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3497 } else if (parser.checkParCount(1))
3499 b=parser.parBool(ok,0);
3500 if (ok) setHideLinkUnselected(b);
3502 /////////////////////////////////////////////////////////////////////
3503 } else if (com=="setSelectionColor")
3505 if (parser.checkParCount(1))
3507 QColor c=parser.parColor (ok,0);
3508 if (ok) setSelectionColorInt (c);
3510 /////////////////////////////////////////////////////////////////////
3511 } else if (com=="setURL")
3513 if (selection.isEmpty() )
3515 parser.setError (Aborted,"Nothing selected");
3518 parser.setError (Aborted,"Type of selection is not a branch");
3519 } else if (parser.checkParCount(1))
3521 s=parser.parString (ok,0);
3524 /////////////////////////////////////////////////////////////////////
3525 } else if (com=="setVymLink")
3527 if (selection.isEmpty() )
3529 parser.setError (Aborted,"Nothing selected");
3532 parser.setError (Aborted,"Type of selection is not a branch");
3533 } else if (parser.checkParCount(1))
3535 s=parser.parString (ok,0);
3536 if (ok) setVymLink(s);
3539 /////////////////////////////////////////////////////////////////////
3540 else if (com=="setFlag")
3542 if (selection.isEmpty() )
3544 parser.setError (Aborted,"Nothing selected");
3547 parser.setError (Aborted,"Type of selection is not a branch");
3548 } else if (parser.checkParCount(1))
3550 s=parser.parString(ok,0);
3553 selb->activateStandardFlag(s);
3554 selb->updateFlagsToolbar();
3557 /////////////////////////////////////////////////////////////////////
3558 } else if (com=="setFrameType")
3560 if (selection.isEmpty() )
3562 parser.setError (Aborted,"Nothing selected");
3565 parser.setError (Aborted,"Type of selection is not a branch");
3566 } else if (parser.checkParCount(1))
3568 s=parser.parString(ok,0);
3572 /////////////////////////////////////////////////////////////////////
3573 } else if (com=="sortChildren")
3575 if (selection.isEmpty() )
3577 parser.setError (Aborted,"Nothing selected");
3580 parser.setError (Aborted,"Type of selection is not a branch");
3581 } else if (parser.checkParCount(0))
3585 /////////////////////////////////////////////////////////////////////
3586 } else if (com=="toggleFlag")
3588 if (selection.isEmpty() )
3590 parser.setError (Aborted,"Nothing selected");
3593 parser.setError (Aborted,"Type of selection is not a branch");
3594 } else if (parser.checkParCount(1))
3596 s=parser.parString(ok,0);
3599 selb->toggleStandardFlag(s);
3600 selb->updateFlagsToolbar();
3603 /////////////////////////////////////////////////////////////////////
3604 } else if (com=="unscroll")
3606 if (selection.isEmpty() )
3608 parser.setError (Aborted,"Nothing selected");
3611 parser.setError (Aborted,"Type of selection is not a branch");
3612 } else if (parser.checkParCount(0))
3614 if (!unscrollBranch (selb))
3615 parser.setError (Aborted,"Could not unscroll branch");
3617 /////////////////////////////////////////////////////////////////////
3618 } else if (com=="unscrollChildren")
3620 if (selection.isEmpty() )
3622 parser.setError (Aborted,"Nothing selected");
3625 parser.setError (Aborted,"Type of selection is not a branch");
3626 } else if (parser.checkParCount(0))
3628 unscrollChildren ();
3630 /////////////////////////////////////////////////////////////////////
3631 } else if (com=="unsetFlag")
3633 if (selection.isEmpty() )
3635 parser.setError (Aborted,"Nothing selected");
3638 parser.setError (Aborted,"Type of selection is not a branch");
3639 } else if (parser.checkParCount(1))
3641 s=parser.parString(ok,0);
3644 selb->deactivateStandardFlag(s);
3645 selb->updateFlagsToolbar();
3649 parser.setError (Aborted,"Unknown command");
3652 if (parser.errorLevel()==NoError)
3654 // setChanged(); FIXME-2 should not be called e.g. for export?!
3659 // TODO Error handling
3660 qWarning("VymModel::parseAtom: Error!");
3661 qWarning(parser.errorMessage());
3665 void VymModel::runScript (QString script)
3667 parser.setScript (script);
3669 while (parser.next() )
3670 parseAtom(parser.getAtom());
3673 void VymModel::setExportMode (bool b)
3675 // should be called before and after exports
3676 // depending on the settings
3677 if (b && settings.value("/export/useHideExport","true")=="true")
3678 setHideTmpMode (HideExport);
3680 setHideTmpMode (HideNone);
3683 void VymModel::exportImage(QString fname, bool askName, QString format)
3687 fname=getMapName()+".png";
3694 QFileDialog *fd=new QFileDialog (NULL);
3695 fd->setCaption (tr("Export map as image"));
3696 fd->setDirectory (lastImageDir);
3697 fd->setFileMode(QFileDialog::AnyFile);
3698 fd->setFilters (imageIO.getFilters() );
3701 fl=fd->selectedFiles();
3703 format=imageIO.getType(fd->selectedFilter());
3707 setExportMode (true);
3708 QPixmap pix (getPixmap());
3709 pix.save(fname, format);
3710 setExportMode (false);
3714 void VymModel::exportXML(QString dir, bool askForName)
3718 dir=browseDirectory(NULL,tr("Export XML to directory"));
3719 if (dir =="" && !reallyWriteDirectory(dir) )
3723 // Hide stuff during export, if settings want this
3724 setExportMode (true);
3726 // Create subdirectories
3729 // write to directory
3730 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3733 file.setName ( dir + "/"+mapName+".xml");
3734 if ( !file.open( QIODevice::WriteOnly ) )
3736 // This should neverever happen
3737 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3741 // Write it finally, and write in UTF8, no matter what
3742 QTextStream ts( &file );
3743 ts.setEncoding (QTextStream::UnicodeUTF8);
3747 // Now write image, too
3748 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3750 setExportMode (false);
3753 void VymModel::exportASCII(QString fname,bool askName)
3758 ex.setFile (mapName+".txt");
3764 //ex.addFilter ("TXT (*.txt)");
3765 ex.setDir(lastImageDir);
3766 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3771 setExportMode(true);
3773 setExportMode(false);
3777 void VymModel::exportXHTML (const QString &dir, bool askForName)
3779 ExportXHTMLDialog dia(NULL);
3780 dia.setFilePath (filePath );
3781 dia.setMapName (mapName );
3783 if (dir!="") dia.setDir (dir);
3789 if (dia.exec()!=QDialog::Accepted)
3793 QDir d (dia.getDir());
3794 // Check, if warnings should be used before overwriting
3795 // the output directory
3796 if (d.exists() && d.count()>0)
3799 warn.showCancelButton (true);
3800 warn.setText(QString(
3801 "The directory %1 is not empty.\n"
3802 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3803 warn.setCaption("Warning: Directory not empty");
3804 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3806 if (warn.exec()!=QDialog::Accepted) ok=false;
3813 exportXML (dia.getDir(),false );
3814 dia.doExport(mapName );
3815 //if (dia.hasChanged()) setChanged();
3819 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3824 if (ex.setConfigFile(cf))
3826 setExportMode (true);
3827 ex.exportPresentation();
3828 setExportMode (false);
3835 //////////////////////////////////////////////
3837 //////////////////////////////////////////////
3839 void VymModel::registerEditor(QWidget *me)
3841 mapEditor=(MapEditor*)me;
3842 for (int i=0; i<mapCenters.count(); i++)
3843 mapCenters.at(i)->setMapEditor(mapEditor);
3846 void VymModel::unregisterEditor(QWidget *)
3851 void VymModel::setContextPos(QPointF p)
3856 void VymModel::unsetContextPos()
3858 contextPos=QPointF();
3861 void VymModel::updateNoteFlag()
3864 cout << "VM::updateNoteFlag()\n";
3865 /* FIXME-1 modify note flag
3866 BranchObj *bo=getSelectedBranch();
3869 bo->updateNoteFlag();
3870 mainWindow->updateActions();
3875 void VymModel::updateRelPositions()
3877 for (int i=0; i<mapCenters.count(); i++)
3878 mapCenters.at(i)->updateRelPositions();
3881 void VymModel::reposition()
3883 for (int i=0;i<mapCenters.count(); i++)
3884 mapCenters.at(i)->reposition(); // for positioning heading
3887 QPolygonF VymModel::shape(BranchObj *bo)
3889 // Creating (arbitrary) shapes
3892 QRectF rb=bo->getBBox();
3893 if (bo->getDepth()==0)
3895 // Just take BBox of this mapCenter
3896 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3900 // Take union of BBox and TotalBBox
3902 QRectF ra=bo->getTotalBBox();
3903 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3906 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3909 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3911 p <<ra.bottomRight()
3913 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3916 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3921 void VymModel::moveAway(LinkableMapObj *lmo)
3925 // Move all branches and MapCenters away from lmo
3926 // to avoid collisions
3931 BranchObj *boA=(BranchObj*)lmo;
3933 for (int i=0; i<mapCenters.count(); i++)
3935 boB=mapCenters.at(i);
3938 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3941 <<" ("<<qPrintable(boA->getHeading() )<<")"
3942 <<" with ("<< qPrintable (boB->getHeading() )
3945 <<" 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
3958 selection.unselect();
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
3965 selection.reselect();
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;
4011 TreeItem *prev=NULL;
4017 bo=(BranchObj*)(cur->getLMO() );
4018 bo->setLinkStyle(bo->getDefLinkStyle());
4019 cur=next(cur,prev,d);
4024 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4029 void VymModel::setMapDefLinkColor(QColor col)
4031 if ( !col.isValid() ) return;
4033 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4034 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4035 QString("Set map link color to %1").arg(col.name())
4040 TreeItem *prev=NULL;
4043 cur=next(cur,prev,d);
4046 bo=(BranchObj*)(cur->getLMO() );
4053 void VymModel::setMapLinkColorHintInt()
4055 // called from setMapLinkColorHint(lch) or at end of parse
4057 TreeItem *prev=NULL;
4060 cur=next(cur,prev,d);
4063 bo=(BranchObj*)(cur->getLMO() );
4065 cur=next(cur,prev,d);
4069 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4072 setMapLinkColorHintInt();
4075 void VymModel::toggleMapLinkColorHint()
4077 if (linkcolorhint==LinkableMapObj::HeadingColor)
4078 linkcolorhint=LinkableMapObj::DefaultColor;
4080 linkcolorhint=LinkableMapObj::HeadingColor;
4082 TreeItem *prev=NULL;
4085 cur=next(cur,prev,d);
4088 bo=(BranchObj*)(cur->getLMO() );
4094 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4096 Q3FileDialog *fd=new Q3FileDialog( NULL);
4097 fd->setMode (Q3FileDialog::ExistingFile);
4098 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4099 ImagePreview *p =new ImagePreview (fd);
4100 fd->setContentsPreviewEnabled( TRUE );
4101 fd->setContentsPreview( p, p );
4102 fd->setPreviewMode( Q3FileDialog::Contents );
4103 fd->setCaption(vymName+" - " +tr("Load background image"));
4104 fd->setDir (lastImageDir);
4107 if ( fd->exec() == QDialog::Accepted )
4109 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4110 lastImageDir=QDir (fd->dirPath());
4111 setMapBackgroundImage (fd->selectedFile());
4115 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4117 QColor oldcol=mapScene->backgroundBrush().color();
4121 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4123 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4124 QString("Set background color of map to %1").arg(col.name()));
4127 brush.setTextureImage (QPixmap (fn));
4128 mapScene->setBackgroundBrush(brush);
4131 void VymModel::selectMapBackgroundColor() // FIXME-1 move to ME
4133 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4134 if ( !col.isValid() ) return;
4135 setMapBackgroundColor( col );
4139 void VymModel::setMapBackgroundColor(QColor col) // FIXME-1 move to ME
4141 QColor oldcol=mapScene->backgroundBrush().color();
4143 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4144 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4145 QString("Set background color of map to %1").arg(col.name()));
4146 mapScene->setBackgroundBrush(col);
4149 QColor VymModel::getMapBackgroundColor() // FIXME-1 move to ME
4151 return mapScene->backgroundBrush().color();
4155 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-1 move to ME
4157 return linkcolorhint;
4160 QColor VymModel::getMapDefLinkColor() // FIXME-1 move to ME
4162 return defLinkColor;
4165 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-1 move to ME
4170 QColor VymModel::getMapDefXLinkColor() // FIXME-1 move to ME
4172 return defXLinkColor;
4175 void VymModel::setMapDefXLinkWidth (int w) // FIXME-1 move to ME
4180 int VymModel::getMapDefXLinkWidth() // FIXME-1 move to ME
4182 return defXLinkWidth;
4185 void VymModel::move(const double &x, const double &y)
4187 BranchObj *bo = getSelectedBranch();
4189 (selectionType()==TreeItem::Branch ||
4190 selectionType()==TreeItem::MapCenter ||
4191 selectionType()==TreeItem::Image
4194 QPointF ap(bo->getAbsPos());
4198 QString ps=qpointfToString(ap);
4199 QString s=getSelectString();
4202 s, "move "+qpointfToString(to),
4203 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4211 void VymModel::moveRel (const double &x, const double &y)
4213 BranchObj *bo = getSelectedBranch();
4215 (selectionType()==TreeItem::Branch ||
4216 selectionType()==TreeItem::MapCenter ||
4217 selectionType()==TreeItem::Image
4221 QPointF rp(bo->getRelPos());
4225 QString ps=qpointfToString (bo->getRelPos());
4226 QString s=getSelectString(bo);
4229 s, "moveRel "+qpointfToString(to),
4230 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4231 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4240 void VymModel::animate()
4242 animationTimer->stop();
4245 while (i<animObjList.size() )
4247 bo=(BranchObj*)animObjList.at(i);
4252 animObjList.removeAt(i);
4259 QItemSelection sel=selModel->selection();
4260 emit (selectionChanged(sel,sel));
4263 if (!animObjList.isEmpty()) animationTimer->start();
4267 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4269 if (bo && bo->getDepth()>0)
4272 ap.setStart (start);
4274 ap.setTicks (animationTicks);
4275 ap.setAnimated (true);
4276 bo->setAnimation (ap);
4277 animObjList.append( bo );
4278 animationTimer->setSingleShot (true);
4279 animationTimer->start(animationInterval);
4283 void VymModel::stopAnimation (MapObj *mo)
4285 int i=animObjList.indexOf(mo);
4287 animObjList.removeAt (i);
4290 void VymModel::sendSelection()
4292 if (netstate!=Server) return;
4293 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4296 void VymModel::newServer()
4300 tcpServer = new QTcpServer(this);
4301 if (!tcpServer->listen(QHostAddress::Any,port)) {
4302 QMessageBox::critical(NULL, "vym server",
4303 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4304 //FIXME-3 needed? we are no widget any longer... close();
4307 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4309 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4312 void VymModel::connectToServer()
4315 server="salam.suse.de";
4317 clientSocket = new QTcpSocket (this);
4318 clientSocket->abort();
4319 clientSocket->connectToHost(server ,port);
4320 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4321 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4322 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4324 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4329 void VymModel::newClient()
4331 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4332 connect(newClient, SIGNAL(disconnected()),
4333 newClient, SLOT(deleteLater()));
4335 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4337 clientList.append (newClient);
4341 void VymModel::sendData(const QString &s)
4343 if (clientList.size()==0) return;
4345 // Create bytearray to send
4347 QDataStream out(&block, QIODevice::WriteOnly);
4348 out.setVersion(QDataStream::Qt_4_0);
4350 // Reserve some space for blocksize
4353 // Write sendCounter
4354 out << sendCounter++;
4359 // Go back and write blocksize so far
4360 out.device()->seek(0);
4361 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4365 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4367 for (int i=0; i<clientList.size(); ++i)
4369 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4370 clientList.at(i)->write (block);
4374 void VymModel::readData ()
4376 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4379 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4383 QDataStream in(clientSocket);
4384 in.setVersion(QDataStream::Qt_4_0);
4392 cout << " t="<<qPrintable (t)<<endl;
4398 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4400 switch (socketError) {
4401 case QAbstractSocket::RemoteHostClosedError:
4403 case QAbstractSocket::HostNotFoundError:
4404 QMessageBox::information(NULL, vymName +" Network client",
4405 "The host was not found. Please check the "
4406 "host name and port settings.");
4408 case QAbstractSocket::ConnectionRefusedError:
4409 QMessageBox::information(NULL, vymName + " Network client",
4410 "The connection was refused by the peer. "
4411 "Make sure the fortune server is running, "
4412 "and check that the host name and port "
4413 "settings are correct.");
4416 QMessageBox::information(NULL, vymName + " Network client",
4417 QString("The following error occurred: %1.")
4418 .arg(clientSocket->errorString()));
4425 void VymModel::selectMapSelectionColor()
4427 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4428 setSelectionColor (col);
4431 void VymModel::setSelectionColorInt (QColor col)
4433 if ( !col.isValid() ) return;
4435 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4436 QString("setSelectionColor (%1)").arg(col.name()),
4437 QString("Set color of selection box to %1").arg(col.name())
4440 mapEditor->setSelectionColor (col);
4444 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4446 cout << "VymModel::changeSelection (";
4447 if (!newsel.indexes().isEmpty() )
4448 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4450 if (!oldsel.indexes().isEmpty() )
4451 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4456 void VymModel::updateSelection(const QItemSelection &newsel)
4458 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4459 ensureSelectionVisible();
4463 void VymModel::updateSelection()
4465 QItemSelection newsel=selModel->selection();
4466 updateSelection (newsel);
4469 void VymModel::setSelectionColor(QColor col)
4471 if ( !col.isValid() ) return;
4473 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4474 QString("setSelectionColor (%1)").arg(col.name()),
4475 QString("Set color of selection box to %1").arg(col.name())
4477 setSelectionColorInt (col);
4480 QColor VymModel::getSelectionColor()
4482 return mapEditor->getSelectionColor();
4485 void VymModel::setHideTmpMode (HideTmpMode mode)
4488 for (int i=0;i<mapCenters.count(); i++)
4489 mapCenters.at(i)->setHideTmp (mode);
4491 // FIXME-3 needed? scene()->update();
4495 QRectF VymModel::getTotalBBox()
4498 for (int i=0;i<mapCenters.count(); i++)
4499 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4503 //////////////////////////////////////////////
4504 // Selection related
4505 //////////////////////////////////////////////
4507 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4512 QItemSelectionModel* VymModel::getSelectionModel()
4517 void VymModel::setSelectionBlocked (bool b)
4522 selection.unblock();
4525 bool VymModel::isSelectionBlocked()
4527 return selection.isBlocked();
4530 bool VymModel::select ()
4532 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4534 TreeItem *item = getItem (index);
4535 return select (item->getLMO() );
4538 bool VymModel::select (const QString &s)
4540 LinkableMapObj *lmo=findObjBySelect(s);
4542 // Finally select the found object
4552 bool VymModel::select (LinkableMapObj *lmo)
4554 QItemSelection oldsel=selModel->selection();
4557 return select (lmo->getTreeItem() );
4562 bool VymModel::select (TreeItem *ti)
4566 QModelIndex ix=index(ti);
4567 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4568 ti->setLastSelectedBranch();
4569 //updateSelection(oldsel); //FIXME-3 needed?
4575 void VymModel::unselect()
4577 selModel->clearSelection();
4580 void VymModel::reselect()
4582 selection.reselect();
4585 void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
4587 LinkableMapObj *lmo=getSelectedLMO();
4588 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4591 void VymModel::emitContentHasChanged (TreeItem *ti)
4593 QModelIndex ix=index(ti);
4594 emit (contentHasChanged (ix) );
4597 void VymModel::selectInt (LinkableMapObj *lmo)
4599 if (selection.select(lmo))
4601 //selection.update();
4602 sendSelection (); // FIXME-4 VM use signal
4607 void VymModel::selectNextBranchInt()
4609 // Increase number of branch
4610 LinkableMapObj *sel=getSelectedBranch();
4613 QString s=getSelectString();
4619 part=s.section(",",-1);
4621 num=part.right(part.length() - 3);
4623 s=s.left (s.length() -num.length());
4626 num=QString ("%1").arg(num.toUInt()+1);
4630 // Try to select this one
4631 if (select (s)) return;
4633 // We have no direct successor,
4634 // try to increase the parental number in order to
4635 // find a successor with same depth
4637 int d=getSelectedLMO()->getDepth();
4642 while (!found && d>0)
4644 s=s.section (",",0,d-1);
4645 // replace substring of current depth in s with "1"
4646 part=s.section(",",-1);
4648 num=part.right(part.length() - 3);
4652 // increase number of parent
4653 num=QString ("%1").arg(num.toUInt()+1);
4654 s=s.section (",",0,d-2) + ","+ typ+num;
4657 // Special case, look at orientation
4658 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)
4659 num=QString ("%1").arg(num.toUInt()+1);
4661 num=QString ("%1").arg(num.toUInt()-1);
4666 // pad to oldDepth, select the first branch for each depth
4667 for (i=d;i<oldDepth;i++)
4672 if ( getSelectedBranch()->countBranches()>0)
4680 // try to select the freshly built string
4688 void VymModel::selectPrevBranchInt()
4690 // Decrease number of branch
4691 if (selectionType()==TreeItem::Branch)
4693 QString s=getSelectString();
4699 part=s.section(",",-1);
4701 num=part.right(part.length() - 3);
4703 s=s.left (s.length() -num.length());
4705 int n=num.toInt()-1;
4708 num=QString ("%1").arg(n);
4711 // Try to select this one
4712 if (n>=0 && select (s)) return;
4714 // We have no direct precessor,
4715 // try to decrease the parental number in order to
4716 // find a precessor with same depth
4718 int d=getSelectedLMO()->getDepth();
4723 while (!found && d>0)
4725 s=s.section (",",0,d-1);
4726 // replace substring of current depth in s with "1"
4727 part=s.section(",",-1);
4729 num=part.right(part.length() - 3);
4733 // decrease number of parent
4734 num=QString ("%1").arg(num.toInt()-1);
4735 s=s.section (",",0,d-2) + ","+ typ+num;
4738 // Special case, look at orientation
4739 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)
4740 num=QString ("%1").arg(num.toInt()-1);
4742 num=QString ("%1").arg(num.toInt()+1);
4747 // pad to oldDepth, select the last branch for each depth
4748 for (i=d;i<oldDepth;i++)
4752 if ( getSelectedBranch()->countBranches()>0)
4753 s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 );
4760 // try to select the freshly built string
4768 void VymModel::selectUpperBranch()
4770 if (selection.isBlocked() ) return;
4772 BranchObj *bo=getSelectedBranch();
4773 if (bo && selectionType()==TreeItem::Branch)
4775 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4776 selectPrevBranchInt();
4778 if (bo->getDepth()==1)
4779 selectNextBranchInt();
4781 selectPrevBranchInt();
4785 void VymModel::selectLowerBranch()
4787 if (selection.isBlocked() ) return;
4789 BranchObj *bo=getSelectedBranch();
4790 if (bo && selectionType()==TreeItem::Branch)
4792 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4793 selectNextBranchInt();
4795 if (bo->getDepth()==1)
4796 selectPrevBranchInt();
4798 selectNextBranchInt();
4803 void VymModel::selectLeftBranch()
4805 if (selection.isBlocked() ) return;
4807 QItemSelection oldsel=selModel->selection();
4810 LinkableMapObj *sel=getSelectedBranch();
4813 if (selectionType()== TreeItem::MapCenter)
4815 QModelIndex ix=getSelectedIndex();
4816 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4819 par=(BranchObj*)(sel->getParObj());
4820 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4823 if (selectionType() == TreeItem::Branch ||
4824 selectionType() == TreeItem::Image)
4826 QModelIndex ix=getSelectedIndex();
4828 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4833 if (selectionType() == TreeItem::Branch )
4835 selectLastSelectedBranch();
4840 updateSelection (oldsel);
4844 void VymModel::selectRightBranch()
4846 if (selection.isBlocked() ) return;
4848 QItemSelection oldsel=selModel->selection();
4851 LinkableMapObj *sel=getSelectedBranch();
4854 if (selectionType()== TreeItem::MapCenter)
4856 QModelIndex ix=getSelectedIndex();
4857 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4860 par=(BranchObj*)(sel->getParObj());
4861 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4864 if (selectionType() == TreeItem::Branch )
4866 selectLastSelectedBranch();
4872 if (selectionType() == TreeItem::Branch ||
4873 selectionType() == TreeItem::Image)
4875 QModelIndex ix=getSelectedIndex();
4877 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4881 updateSelection (oldsel);
4885 void VymModel::selectFirstBranch()
4887 TreeItem *ti=getSelectedBranchItem();
4890 TreeItem *par=ti->parent();
4892 TreeItem *ti2=par->getFirstBranch();
4896 ensureSelectionVisible();
4902 void VymModel::selectLastBranch()
4904 TreeItem *ti=getSelectedBranchItem();
4907 TreeItem *par=ti->parent();
4909 TreeItem *ti2=par->getLastBranch();
4913 ensureSelectionVisible();
4919 void VymModel::selectLastSelectedBranch()
4921 TreeItem *ti=getSelectedBranchItem();
4924 ti=ti->getLastSelectedBranch();
4925 if (ti) select (ti);
4929 void VymModel::selectParent()
4931 TreeItem *ti=getSelectedItem();
4939 ensureSelectionVisible();
4944 TreeItem::Type VymModel::selectionType()
4946 QModelIndexList list=selModel->selectedIndexes();
4947 if (list.isEmpty()) return TreeItem::Undefined;
4948 TreeItem *ti = getItem (list.first() );
4949 return ti->getType();
4953 LinkableMapObj* VymModel::getSelectedLMO()
4955 QModelIndexList list=selModel->selectedIndexes();
4956 if (!list.isEmpty() )
4958 TreeItem *ti = getItem (list.first() );
4959 TreeItem::Type type=ti->getType();
4960 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4962 return ti->getLMO();
4968 BranchObj* VymModel::getSelectedBranch()
4970 TreeItem *ti = getSelectedBranchItem();
4972 return (BranchObj*)ti->getLMO();
4977 TreeItem* VymModel::getSelectedBranchItem()
4979 QModelIndexList list=selModel->selectedIndexes();
4980 if (!list.isEmpty() )
4982 TreeItem *ti = getItem (list.first() );
4983 TreeItem::Type type=ti->getType();
4984 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4990 TreeItem* VymModel::getSelectedItem()
4992 QModelIndexList list=selModel->selectedIndexes();
4993 if (!list.isEmpty() )
4994 return getItem (list.first() );
4999 QModelIndex VymModel::getSelectedIndex()
5001 QModelIndexList list=selModel->selectedIndexes();
5002 if (list.isEmpty() )
5003 return QModelIndex();
5005 return list.first();
5008 FloatImageObj* VymModel::getSelectedFloatImage()
5010 return selection.getFloatImage();
5013 QString VymModel::getSelectString ()
5015 LinkableMapObj *lmo=getSelectedLMO();
5017 return getSelectString(lmo);
5022 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel
5026 if (typeid(*lmo)==typeid(BranchObj) ||
5027 typeid(*lmo)==typeid(MapCenterObj) )
5029 LinkableMapObj *par=lmo->getParObj();
5032 if (lmo->getDepth() ==1)
5033 // Mainbranch, return
5034 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
5036 // Branch, call myself recursively
5037 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
5041 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
5042 if (i>=0) s=QString("mc:%1").arg(i);