1 #include <QApplication>
7 #include "branchitem.h"
8 #include "editxlinkdialog.h"
10 #include "exportxhtmldialog.h"
12 #include "geometry.h" // for addBBox
13 #include "mainwindow.h"
17 #include "warningdialog.h"
18 #include "xml-freemind.h"
24 extern Main *mainWindow;
25 extern QDBusConnection dbusConnection;
27 extern Settings settings;
28 extern QString tmpVymDir;
30 extern TextEditor *textEditor;
31 extern FlagRow *standardFlagsMaster;
33 extern QString clipboardDir;
34 extern QString clipboardFile;
35 extern bool clipboardEmpty;
37 extern ImageIO imageIO;
39 extern QString vymName;
40 extern QString vymVersion;
41 extern QDir vymBaseDir;
43 extern QDir lastImageDir;
44 extern QDir lastFileDir;
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();
72 //QModelIndex ri=index(rootItem);
73 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
76 void VymModel::init ()
78 // We should have at least one map center to start with
79 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
84 // Also no scene yet (should not be needed anyway) FIXME-3 VM
97 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
98 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
99 mainWindow->updateHistory (undoSet);
102 makeTmpDirectories();
107 fileName=tr("unnamed");
109 blockReposition=false;
110 blockSaveState=false;
112 autosaveTimer=new QTimer (this);
113 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
115 fileChangedTimer=new QTimer (this);
116 fileChangedTimer->start(3000);
117 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
122 selectionBlocked=false;
130 animationUse=settings.readBoolEntry("/animation/use",false);
131 animationTicks=settings.readNumEntry("/animation/ticks",10);
132 animationInterval=settings.readNumEntry("/animation/interval",50);
134 animationTimer=new QTimer (this);
135 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
138 defLinkColor=QColor (0,0,255);
139 defXLinkColor=QColor (180,180,180);
140 linkcolorhint=LinkableMapObj::DefaultColor;
141 linkstyle=LinkableMapObj::PolyParabel;
143 defXLinkColor=QColor (230,230,230);
145 hidemode=TreeItem::HideNone;
151 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
154 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
155 //adaptor->setModel (this);
156 //connection.registerObject("/Car", car);
157 dbusConnection.registerService("org.insilmaril.VymModel");
158 dbusConnection.sessionBus().registerObject ("/Object1",this);
161 void VymModel::makeTmpDirectories()
163 // Create unique temporary directories
164 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
165 histPath = tmpMapDir+"/history";
171 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
176 bool VymModel::isRepositionBlocked()
178 return blockReposition;
181 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
183 //cout << "VM::updateActions \n";
184 // Tell mainwindow to update states of actions
185 mainWindow->updateActions();
190 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
192 // tmpdir temporary directory to which data will be written
193 // prefix mapname, which will be appended to images etc.
194 // writeflags Only write flags for "real" save of map, not undo
195 // offset offset of bbox of whole map in scene.
196 // Needed for XML export
205 case LinkableMapObj::Line:
208 case LinkableMapObj::Parabel:
211 case LinkableMapObj::PolyLine:
215 ls="StylePolyParabel";
219 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
221 if (linkcolorhint==LinkableMapObj::HeadingColor)
222 colhint=xml.attribut("linkColorHint","HeadingColor");
224 QString mapAttr=xml.attribut("version",vymVersion);
226 mapAttr+= xml.attribut("author",author) +
227 xml.attribut("comment",comment) +
228 xml.attribut("date",getDate()) +
229 xml.attribut("branchCount", QString().number(branchCount())) +
230 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
231 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
232 xml.attribut("linkStyle", ls ) +
233 xml.attribut("linkColor", defLinkColor.name() ) +
234 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
235 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
237 s+=xml.beginElement("vymmap",mapAttr);
240 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
241 standardFlagsMaster->resetUsedCounter();
243 // Reset the counters before saving
244 // TODO constr. of FIO creates lots of objects, better do this in some other way...
245 ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
247 // Build xml recursivly
248 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
249 // Save all mapcenters as complete map, if saveSel not set
250 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
253 if (saveSel->isBranchLikeType())
255 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
256 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
258 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
261 // Save local settings
262 s+=settings.getDataXML (destPath);
265 if (getSelectedItem() && !saveSel )
266 s+=xml.valueElement("select",getSelectString());
269 s+=xml.endElement("vymmap");
271 //cout << s.toStdString() << endl;
273 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
277 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
281 for (int i=0; i<rootItem->branchCount(); i++)
282 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
286 void VymModel::setFilePath(QString fpath, QString destname)
288 if (fpath.isEmpty() || fpath=="")
295 filePath=fpath; // becomes absolute path
296 fileName=fpath; // gets stripped of path
297 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
299 // If fpath is not an absolute path, complete it
300 filePath=QDir(fpath).absPath();
301 fileDir=filePath.left (1+filePath.findRev ("/"));
303 // Set short name, too. Search from behind:
304 int i=fileName.findRev("/");
305 if (i>=0) fileName=fileName.remove (0,i+1);
307 // Forget the .vym (or .xml) for name of map
308 mapName=fileName.left(fileName.findRev(".",-1,true) );
312 void VymModel::setFilePath(QString fpath)
314 setFilePath (fpath,fpath);
317 QString VymModel::getFilePath()
322 QString VymModel::getFileName()
327 QString VymModel::getMapName()
332 QString VymModel::getDestPath()
337 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
339 ErrorCode err=success;
341 parseBaseHandler *handler;
345 case VymMap: handler=new parseVYMHandler; break;
346 case FreemindMap : handler=new parseFreemindHandler; break;
348 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
349 "Unknown FileType in VymModel::load()");
353 bool zipped_org=zipped;
357 selModel->clearSelection();
358 // FIXME-2 VM not needed??? model->setMapEditor(this);
359 // (map state is set later at end of load...)
362 BranchItem *bi=getSelectedBranchItem();
363 if (!bi) return aborted;
364 if (lmode==ImportAdd)
365 saveStateChangingPart(
368 QString("addMapInsert (%1)").arg(fname),
369 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
371 saveStateChangingPart(
374 QString("addMapReplace(%1)").arg(fname),
375 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
379 // Create temporary directory for packing
381 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
384 QMessageBox::critical( 0, tr( "Critical Load Error" ),
385 tr("Couldn't create temporary directory before load\n"));
390 err=unzipDir (tmpZipDir,fname);
400 // Look for mapname.xml
401 xmlfile= fname.left(fname.findRev(".",-1,true));
402 xmlfile=xmlfile.section( '/', -1 );
403 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
404 if (!mfile.exists() )
406 // mapname.xml does not exist, well,
407 // maybe someone renamed the mapname.vym file...
408 // Try to find any .xml in the toplevel
409 // directory of the .vym file
410 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
411 if (flist.count()==1)
413 // Only one entry, take this one
414 xmlfile=tmpZipDir + "/"+flist.first();
417 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
418 *it=tmpZipDir + "/" + *it;
419 // TODO Multiple entries, load all (but only the first one into this ME)
420 //mainWindow->fileLoadFromTmp (flist);
421 //returnCode=1; // Silently forget this attempt to load
422 qWarning ("MainWindow::load (fn) multimap found...");
425 if (flist.isEmpty() )
427 QMessageBox::critical( 0, tr( "Critical Load Error" ),
428 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
431 } //file doesn't exist
433 xmlfile=mfile.name();
436 QFile file( xmlfile);
438 // I am paranoid: file should exist anyway
439 // according to check in mainwindow.
442 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
443 tr(QString("Couldn't open map %1").arg(file.name())));
447 bool blockSaveStateOrg=blockSaveState;
448 blockReposition=true;
450 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
451 QXmlInputSource source( file);
452 QXmlSimpleReader reader;
453 reader.setContentHandler( handler );
454 reader.setErrorHandler( handler );
455 handler->setModel ( this);
458 // We need to set the tmpDir in order to load files with rel. path
463 tmpdir=fname.left(fname.findRev("/",-1));
464 handler->setTmpDir (tmpdir);
465 handler->setInputFile (file.name());
466 handler->setLoadMode (lmode);
467 bool ok = reader.parse( source );
468 blockReposition=false;
469 blockSaveState=blockSaveStateOrg;
470 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
474 reposition(); // FIXME-2 VM reposition the view instead...
475 emitSelectionChanged();
481 autosaveTimer->stop();
484 // Reset timestamp to check for later updates of file
485 fileChangedTime=QFileInfo (destPath).lastModified();
488 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
489 tr( handler->errorProtocol() ) );
491 // Still return "success": the map maybe at least
492 // partially read by the parser
497 removeDir (QDir(tmpZipDir));
499 // Restore original zip state
506 ErrorCode VymModel::save (const SaveMode &savemode)
510 QString safeFilePath;
512 ErrorCode err=success;
516 mapFileName=mapName+".xml";
518 // use name given by user, even if he chooses .doc
519 mapFileName=fileName;
521 // Look, if we should zip the data:
524 QMessageBox mb( vymName,
525 tr("The map %1\ndid not use the compressed "
526 "vym file format.\nWriting it uncompressed will also write images \n"
527 "and flags and thus may overwrite files in the "
528 "given directory\n\nDo you want to write the map").arg(filePath),
529 QMessageBox::Warning,
530 QMessageBox::Yes | QMessageBox::Default,
532 QMessageBox::Cancel | QMessageBox::Escape);
533 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
534 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
535 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
538 case QMessageBox::Yes:
539 // save compressed (default file format)
542 case QMessageBox::No:
546 case QMessageBox::Cancel:
553 // First backup existing file, we
554 // don't want to add to old zip archives
558 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
560 QString backupFileName(destPath + "~");
561 QFile backupFile(backupFileName);
562 if (backupFile.exists() && !backupFile.remove())
564 QMessageBox::warning(0, tr("Save Error"),
565 tr("%1\ncould not be removed before saving").arg(backupFileName));
567 else if (!f.rename(backupFileName))
569 QMessageBox::warning(0, tr("Save Error"),
570 tr("%1\ncould not be renamed before saving").arg(destPath));
577 // Create temporary directory for packing
579 tmpZipDir=makeTmpDir (ok,"vym-zip");
582 QMessageBox::critical( 0, tr( "Critical Load Error" ),
583 tr("Couldn't create temporary directory before save\n"));
587 safeFilePath=filePath;
588 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
591 // Create mapName and fileDir
592 makeSubDirs (fileDir);
595 if (savemode==CompleteMap || selModel->selection().isEmpty())
598 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
601 autosaveTimer->stop();
606 if (selectionType()==TreeItem::Image)
609 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
610 // TODO take care of multiselections
613 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
616 qWarning ("ME::saveStringToDisk failed!");
622 if (err==success) err=zipDir (tmpZipDir,destPath);
625 removeDir (QDir(tmpZipDir));
627 // Restore original filepath outside of tmp zip dir
628 setFilePath (safeFilePath);
632 fileChangedTime=QFileInfo (destPath).lastModified();
636 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree
638 QString pathDir=path.left(path.findRev("/"));
644 // We need to parse saved XML data
645 parseVYMHandler handler;
646 QXmlInputSource source( file);
647 QXmlSimpleReader reader;
648 reader.setContentHandler( &handler );
649 reader.setErrorHandler( &handler );
650 handler.setModel ( this);
651 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
652 if (undoSel.isEmpty())
656 handler.setLoadMode (NewMap);
660 handler.setLoadMode (ImportReplace);
662 blockReposition=true;
663 bool ok = reader.parse( source );
664 blockReposition=false;
667 // This should never ever happen
668 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
669 handler.errorProtocol());
672 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
675 void VymModel::addMapInsertInt (const QString &path, int pos)
677 /* FIXME-2 addMapInsertInt not ported yet
678 BranchObj *sel=getSelectedBranch();
681 QString pathDir=path.left(path.findRev("/"));
687 // We need to parse saved XML data
688 parseVYMHandler handler;
689 QXmlInputSource source( file);
690 QXmlSimpleReader reader;
691 reader.setContentHandler( &handler );
692 reader.setErrorHandler( &handler );
693 handler.setModel (this);
694 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
695 handler.setLoadMode (ImportAdd);
696 blockReposition=true;
697 bool ok = reader.parse( source );
698 blockReposition=false;
701 // This should never ever happen
702 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
703 handler.errorProtocol());
705 if (sel->getDepth()>0)
706 sel->getLastBranch()->linkTo (sel,pos);
708 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
713 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
715 ImageItem *ii=createImage(dst);
725 void VymModel::loadFloatImage ()
727 BranchItem *selbi=getSelectedBranchItem();
731 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
732 fd->setMode (Q3FileDialog::ExistingFiles);
733 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
734 ImagePreview *p =new ImagePreview (fd);
735 fd->setContentsPreviewEnabled( TRUE );
736 fd->setContentsPreview( p, p );
737 fd->setPreviewMode( Q3FileDialog::Contents );
738 fd->setCaption(vymName+" - " +tr("Load image"));
739 fd->setDir (lastImageDir);
742 if ( fd->exec() == QDialog::Accepted )
744 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
745 lastImageDir=QDir (fd->dirPath());
748 for (int j=0; j<fd->selectedFiles().count(); j++)
750 s=fd->selectedFiles().at(j);
751 ii=loadFloatImageInt (selbi,s);
752 //FIXME-3 check savestate for loadImage
758 QString ("loadImage (%1)").arg(s ),
759 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
762 // TODO loadFIO error handling
763 qWarning ("Failed to load "+s);
771 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
776 void VymModel::saveFloatImage ()
778 ImageItem *ii=getSelectedImageItem();
781 QFileDialog *fd=new QFileDialog( NULL);
782 fd->setFilters (imageIO.getFilters());
783 fd->setCaption(vymName+" - " +tr("Save image"));
784 fd->setFileMode( QFileDialog::AnyFile );
785 fd->setDirectory (lastImageDir);
786 // fd->setSelection (fio->getOriginalFilename());
790 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
792 fn=fd->selectedFiles().at(0);
793 if (QFile (fn).exists() )
795 QMessageBox mb( vymName,
796 tr("The file %1 exists already.\n"
797 "Do you want to overwrite it?").arg(fn),
798 QMessageBox::Warning,
799 QMessageBox::Yes | QMessageBox::Default,
800 QMessageBox::Cancel | QMessageBox::Escape,
801 QMessageBox::NoButton );
803 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
804 mb.setButtonText( QMessageBox::No, tr("Cancel"));
807 case QMessageBox::Yes:
810 case QMessageBox::Cancel:
817 saveFloatImageInt (ii,fd->selectedFilter(),fn );
824 void VymModel::importDirInt(BranchObj *dst, QDir d)
826 /* FIXME-2 importDirInt not ported yet
827 BranchObj *bo=getSelectedBranch();
830 // Traverse directories
831 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
832 QFileInfoList list = d.entryInfoList();
835 for (int i = 0; i < list.size(); ++i)
838 if (fi.fileName() != "." && fi.fileName() != ".." )
841 bo=dst->getLastBranch();
842 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
843 bi->setHeading (fi.fileName() ); // FIXME-3 check this
844 bo->setColor (QColor("blue"));
846 if ( !d.cd(fi.fileName()) )
847 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
850 // Recursively add subdirs
857 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
858 list = d.entryInfoList();
860 for (int i = 0; i < list.size(); ++i)
864 bo=dst->getLastBranch();
865 bo->setHeading (fi.fileName() );
866 bo->setColor (QColor("black"));
867 if (fi.fileName().right(4) == ".vym" )
868 bo->setVymLink (fi.filePath());
874 void VymModel::importDirInt (const QString &s) // FIXME-2
877 BranchObj *bo=getSelectedBranch();
880 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
888 void VymModel::importDir() //FIXME-2
891 BranchObj *bo=getSelectedBranch();
895 filters <<"VYM map (*.vym)";
896 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
897 fd->setMode (QFileDialog::DirectoryOnly);
898 fd->setFilters (filters);
899 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
903 if ( fd->exec() == QDialog::Accepted )
905 importDirInt (fd->selectedFile() );
907 //FIXME-3 VM needed? scene()->update();
914 void VymModel::autosave()
919 cout << "VymModel::autosave rejected due to missing filePath\n";
922 QDateTime now=QDateTime().currentDateTime();
924 // Disable autosave, while we have gone back in history
925 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
926 if (redosAvail>0) return;
928 // Also disable autosave for new map without filename
929 if (filePath.isEmpty()) return;
932 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
934 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
935 mainWindow->fileSave (this);
938 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
943 void VymModel::fileChanged()
945 // Check if file on disk has changed meanwhile
946 if (!filePath.isEmpty())
948 QDateTime tmod=QFileInfo (filePath).lastModified();
949 if (tmod>fileChangedTime)
951 // FIXME-2 VM switch to current mapeditor and finish lineedits...
952 QMessageBox mb( vymName,
953 tr("The file of the map on disk has changed:\n\n"
954 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
955 QMessageBox::Question,
957 QMessageBox::Cancel | QMessageBox::Default,
958 QMessageBox::NoButton );
960 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
961 mb.setButtonText( QMessageBox::No, tr("Ignore"));
964 case QMessageBox::Yes:
966 load (filePath,NewMap,fileType);
967 case QMessageBox::Cancel:
968 fileChangedTime=tmod; // allow autosave to overwrite newer file!
974 bool VymModel::isDefault()
979 void VymModel::makeDefault()
985 bool VymModel::hasChanged()
990 void VymModel::setChanged()
993 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
997 latestAddedItem=NULL;
1001 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1003 if (!lmo || !lmo->getTreeItem() ) return QString();
1004 return getObjectName (lmo->getTreeItem() );
1008 QString VymModel::getObjectName (TreeItem *ti)
1011 if (!ti) return QString("Error: NULL has no name!");
1013 if (s=="") s="unnamed";
1015 if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter??
1016 return QString("branch (%1)").arg(s);
1017 if (ti->getType()==TreeItem::Image)
1018 return QString ("image (%1)").arg(ti->getHeading());
1019 return QString("Unknown type has no name!");
1022 void VymModel::redo()
1024 // Can we undo at all?
1025 if (redosAvail<1) return;
1027 bool blockSaveStateOrg=blockSaveState;
1028 blockSaveState=true;
1032 if (undosAvail<stepsTotal) undosAvail++;
1034 if (curStep>stepsTotal) curStep=1;
1035 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1036 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1037 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1038 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1039 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1040 QString version=undoSet.readEntry ("/history/version");
1042 /* TODO Maybe check for version, if we save the history
1043 if (!checkVersion(version))
1044 QMessageBox::warning(0,tr("Warning"),
1045 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1048 // Find out current undo directory
1049 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1053 cout << "VymModel::redo() begin\n";
1054 cout << " undosAvail="<<undosAvail<<endl;
1055 cout << " redosAvail="<<redosAvail<<endl;
1056 cout << " curStep="<<curStep<<endl;
1057 cout << " ---------------------------"<<endl;
1058 cout << " comment="<<comment.toStdString()<<endl;
1059 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1060 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1061 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1062 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1063 cout << " ---------------------------"<<endl<<endl;
1066 // select object before redo
1067 if (!redoSelection.isEmpty())
1068 select (redoSelection);
1071 parseAtom (redoCommand);
1074 blockSaveState=blockSaveStateOrg;
1076 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1077 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1078 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1079 undoSet.writeSettings(histPath);
1081 mainWindow->updateHistory (undoSet);
1084 /* TODO remove testing
1085 cout << "ME::redo() end\n";
1086 cout << " undosAvail="<<undosAvail<<endl;
1087 cout << " redosAvail="<<redosAvail<<endl;
1088 cout << " curStep="<<curStep<<endl;
1089 cout << " ---------------------------"<<endl<<endl;
1095 bool VymModel::isRedoAvailable()
1097 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1103 void VymModel::undo()
1105 // Can we undo at all?
1106 if (undosAvail<1) return;
1108 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1110 bool blockSaveStateOrg=blockSaveState;
1111 blockSaveState=true;
1113 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1114 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1115 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1116 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1117 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1118 QString version=undoSet.readEntry ("/history/version");
1120 /* TODO Maybe check for version, if we save the history
1121 if (!checkVersion(version))
1122 QMessageBox::warning(0,tr("Warning"),
1123 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1126 // Find out current undo directory
1127 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1129 // select object before undo
1130 if (!undoSelection.isEmpty())
1131 select (undoSelection);
1135 cout << "VymModel::undo() begin\n";
1136 cout << " undosAvail="<<undosAvail<<endl;
1137 cout << " redosAvail="<<redosAvail<<endl;
1138 cout << " curStep="<<curStep<<endl;
1139 cout << " ---------------------------"<<endl;
1140 cout << " comment="<<comment.toStdString()<<endl;
1141 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1142 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1143 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1144 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1145 cout << " ---------------------------"<<endl<<endl;
1147 parseAtom (undoCommand);
1152 if (curStep<1) curStep=stepsTotal;
1156 blockSaveState=blockSaveStateOrg;
1157 /* TODO remove testing
1158 cout << "VymModel::undo() end\n";
1159 cout << " undosAvail="<<undosAvail<<endl;
1160 cout << " redosAvail="<<redosAvail<<endl;
1161 cout << " curStep="<<curStep<<endl;
1162 cout << " ---------------------------"<<endl<<endl;
1165 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1166 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1167 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1168 undoSet.writeSettings(histPath);
1170 mainWindow->updateHistory (undoSet);
1172 emitSelectionChanged();
1175 bool VymModel::isUndoAvailable()
1177 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1183 void VymModel::gotoHistoryStep (int i)
1185 // Restore variables
1186 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1187 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1189 if (i<0) i=undosAvail+redosAvail;
1191 // Clicking above current step makes us undo things
1194 for (int j=0; j<undosAvail-i; j++) undo();
1197 // Clicking below current step makes us redo things
1199 for (int j=undosAvail; j<i; j++)
1201 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1205 // And ignore clicking the current row ;-)
1209 QString VymModel::getHistoryPath()
1211 QString histName(QString("history-%1").arg(curStep));
1212 return (tmpMapDir+"/"+histName);
1215 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1217 sendData(redoCom); //FIXME-3 testing
1222 if (blockSaveState) return;
1224 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1226 // Find out current undo directory
1227 if (undosAvail<stepsTotal) undosAvail++;
1229 if (curStep>stepsTotal) curStep=1;
1231 QString backupXML="";
1232 QString histDir=getHistoryPath();
1233 QString bakMapPath=histDir+"/map.xml";
1235 // Create histDir if not available
1238 makeSubDirs (histDir);
1240 // Save depending on how much needs to be saved
1242 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1244 QString undoCommand="";
1245 if (savemode==UndoCommand)
1247 undoCommand=undoCom;
1249 else if (savemode==PartOfMap )
1251 undoCommand=undoCom;
1252 undoCommand.replace ("PATH",bakMapPath);
1256 if (!backupXML.isEmpty())
1257 // Write XML Data to disk
1258 saveStringToDisk (bakMapPath,backupXML);
1260 // We would have to save all actions in a tree, to keep track of
1261 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1264 // Write the current state to disk
1265 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1266 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1267 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1268 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1269 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1270 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1271 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1272 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1273 undoSet.setEntry (QString("/history/version"),vymVersion);
1274 undoSet.writeSettings(histPath);
1278 // TODO remove after testing
1279 //cout << " into="<< histPath.toStdString()<<endl;
1280 cout << " stepsTotal="<<stepsTotal<<
1281 ", undosAvail="<<undosAvail<<
1282 ", redosAvail="<<redosAvail<<
1283 ", curStep="<<curStep<<endl;
1284 cout << " ---------------------------"<<endl;
1285 cout << " comment="<<comment.toStdString()<<endl;
1286 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1287 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1288 cout << " redoCom="<<redoCom.toStdString()<<endl;
1289 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1290 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1291 cout << " ---------------------------"<<endl;
1294 mainWindow->updateHistory (undoSet);
1300 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1302 // save the selected part of the map, Undo will replace part of map
1303 QString undoSelection="";
1305 undoSelection=getSelectString(undoSel);
1307 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1308 QString redoSelection="";
1310 redoSelection=getSelectString(undoSel);
1312 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1315 saveState (PartOfMap,
1316 undoSelection, "addMapReplace (\"PATH\")",
1322 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1326 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1329 QString undoSelection=getSelectString (redoSel->parent() );
1330 QString redoSelection=getSelectString(redoSel);
1331 if (redoSel->getType()==TreeItem::Branch)
1333 // save the selected branch of the map, Undo will insert part of map
1334 saveState (PartOfMap,
1335 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1336 redoSelection, "delete ()",
1343 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1345 // "Normal" savestate: save commands, selections and comment
1346 // so just save commands for undo and redo
1347 // and use current selection
1349 QString redoSelection="";
1350 if (redoSel) redoSelection=getSelectString(redoSel);
1351 QString undoSelection="";
1352 if (undoSel) undoSelection=getSelectString(undoSel);
1354 saveState (UndoCommand,
1361 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1363 // "Normal" savestate: save commands, selections and comment
1364 // so just save commands for undo and redo
1365 // and use current selection
1366 saveState (UndoCommand,
1373 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1375 // "Normal" savestate applied to model (no selection needed):
1376 // save commands and comment
1377 saveState (UndoCommand,
1385 QGraphicsScene* VymModel::getScene ()
1390 TreeItem* VymModel::findBySelectString(QString s)
1392 if (s.isEmpty() ) return NULL;
1394 // Old maps don't have multiple mapcenters and don't save full path
1395 if (s.left(2) !="mc")
1398 QStringList parts=s.split (",");
1401 TreeItem *ti=rootItem;
1403 while (!parts.isEmpty() )
1405 typ=parts.first().left(2);
1406 n=parts.first().right(parts.first().length() - 3).toInt();
1407 parts.removeFirst();
1408 if (typ=="mc" || typ=="bo")
1409 ti=ti->getBranchNum (n);
1413 ti=ti->getImageNum (n);
1419 TreeItem* VymModel::findID (const QString &s)
1422 for (int i=0; i<rootItem->branchCount(); i++)
1424 ti=rootItem->getBranchNum(i)->findID (s);
1430 //////////////////////////////////////////////
1432 //////////////////////////////////////////////
1433 void VymModel::setVersion (const QString &s)
1438 void VymModel::setAuthor (const QString &s)
1441 QString ("setMapAuthor (\"%1\")").arg(author),
1442 QString ("setMapAuthor (\"%1\")").arg(s),
1443 QString ("Set author of map to \"%1\"").arg(s)
1448 QString VymModel::getAuthor()
1453 void VymModel::setComment (const QString &s)
1456 QString ("setMapComment (\"%1\")").arg(comment),
1457 QString ("setMapComment (\"%1\")").arg(s),
1458 QString ("Set comment of map")
1463 QString VymModel::getComment ()
1468 QString VymModel::getDate ()
1470 return QDate::currentDate().toString ("yyyy-MM-dd");
1473 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1476 BranchItem *cur=NULL;
1477 BranchItem *prev=NULL;
1487 void VymModel::setHeading(const QString &s)
1489 BranchItem *selbi=getSelectedBranchItem();
1494 "setHeading (\""+selbi->getHeading()+"\")",
1496 "setHeading (\""+s+"\")",
1497 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1498 selbi->setHeading(s );
1499 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1502 emitSelectionChanged();
1506 QString VymModel::getHeading()
1508 TreeItem *selti=getSelectedItem();
1510 return selti->getHeading();
1515 BranchItem* VymModel::findText (QString s, bool cs)
1517 QTextDocument::FindFlags flags=0;
1518 if (cs) flags=QTextDocument::FindCaseSensitively;
1521 { // Nothing found or new find process
1523 // nothing found, start again
1527 next (findCurrent,findPrevious);
1529 bool searching=true;
1530 bool foundNote=false;
1531 while (searching && !EOFind)
1535 // Searching in Note
1536 if (findCurrent->getNote().contains(s,cs))
1538 select (findCurrent);
1540 if (getSelectedBranch()!=itFind)
1543 emitShowSelection();
1546 if (textEditor->findText(s,flags))
1552 // Searching in Heading
1553 if (searching && findCurrent->getHeading().contains (s,cs) )
1555 select(findCurrent);
1561 if (!next(findCurrent,findPrevious) )
1564 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1567 return getSelectedBranchItem();
1572 void VymModel::findReset()
1573 { // Necessary if text to find changes during a find process
1579 void VymModel::setScene (QGraphicsScene *s)
1581 mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
1582 //init(); // Here we have a mapScene set,
1583 // which is (still) needed to create MapCenters
1586 void VymModel::setURL(const QString &url)
1588 TreeItem *selti=getSelectedItem();
1591 QString oldurl=selti->getURL();
1592 selti->setURL (url);
1595 QString ("setURL (\"%1\")").arg(oldurl),
1597 QString ("setURL (\"%1\")").arg(url),
1598 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1601 emitDataHasChanged (selti);
1602 emitShowSelection();
1606 QString VymModel::getURL()
1608 TreeItem *selti=getSelectedItem();
1610 return selti->getURL();
1615 QStringList VymModel::getURLs()
1618 BranchItem *selbi=getSelectedBranchItem();
1619 BranchItem *cur=selbi;
1620 BranchItem *prev=NULL;
1623 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1624 cur=next (cur,prev,selbi);
1630 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1632 BranchItem *bi=getSelectedBranchItem();
1635 BranchObj *bo=(BranchObj*)(bi->getLMO());
1638 QString s=bo->getFrameTypeName();
1639 bo->setFrameType (t);
1640 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1641 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1643 bo->updateLinkGeometry();
1648 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1650 BranchItem *bi=getSelectedBranchItem();
1653 BranchObj *bo=(BranchObj*)(bi->getLMO());
1656 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1657 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1658 bo->setFrameType (s);
1660 bo->updateLinkGeometry();
1665 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1668 BranchItem *bi=getSelectedBranchItem();
1671 BranchObj *bo=(BranchObj*)(bi->getLMO());
1674 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1675 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1676 bo->setFramePenColor (c);
1681 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1683 BranchItem *bi=getSelectedBranchItem();
1686 BranchObj *bo=(BranchObj*)(bi->getLMO());
1689 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1690 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1691 bo->setFrameBrushColor (c);
1696 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1698 BranchItem *bi=getSelectedBranchItem();
1701 BranchObj *bo=(BranchObj*)(bi->getLMO());
1704 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1705 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1706 bo->setFramePadding (i);
1708 bo->updateLinkGeometry();
1713 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1715 BranchItem *bi=getSelectedBranchItem();
1718 BranchObj *bo=(BranchObj*)(bi->getLMO());
1721 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1722 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1723 bo->setFrameBorderWidth (i);
1725 bo->updateLinkGeometry();
1730 void VymModel::setIncludeImagesVer(bool b) //FIXME-2
1733 BranchItem *bi=getSelectedBranchItem();
1736 BranchObj *bo=bi->getLMO();
1739 QString u= b ? "false" : "true";
1740 QString r=!b ? "false" : "true";
1744 QString("setIncludeImagesVertically (%1)").arg(u),
1746 QString("setIncludeImagesVertically (%1)").arg(r),
1747 QString("Include images vertically in %1").arg(getObjectName(bo))
1749 bo->setIncludeImagesVer(b);
1755 void VymModel::setIncludeImagesHor(bool b) //FIXME-2
1758 TreeItem *bi=getSelectedBranchItem();
1761 BranchObj *bo=bi->getLMO();
1764 QString u= b ? "false" : "true";
1765 QString r=!b ? "false" : "true";
1769 QString("setIncludeImagesHorizontally (%1)").arg(u),
1771 QString("setIncludeImagesHorizontally (%1)").arg(r),
1772 QString("Include images horizontally in %1").arg(getObjectName(bo))
1774 bo->setIncludeImagesHor(b);
1781 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1783 TreeItem *ti=getSelectedItem();
1784 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1786 QString u= b ? "false" : "true";
1787 QString r=!b ? "false" : "true";
1791 QString("setHideLinkUnselected (%1)").arg(u),
1793 QString("setHideLinkUnselected (%1)").arg(r),
1794 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1796 ((MapItem*)ti)->setHideLinkUnselected(b);
1800 void VymModel::setHideExport(bool b)
1802 TreeItem *ti=getSelectedItem();
1804 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1806 ti->setHideInExport (b);
1807 QString u= b ? "false" : "true";
1808 QString r=!b ? "false" : "true";
1812 QString ("setHideExport (%1)").arg(u),
1814 QString ("setHideExport (%1)").arg(r),
1815 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1817 emitDataHasChanged(ti);
1818 emitSelectionChanged();
1821 // emitSelectionChanged();
1822 // FIXME-3 VM needed? scene()->update();
1826 void VymModel::toggleHideExport()
1828 TreeItem *selti=getSelectedItem();
1830 setHideExport ( !selti->hideInExport() );
1834 void VymModel::copy()
1836 TreeItem *selti=getSelectedItem();
1838 (selti->getType() == TreeItem::Branch ||
1839 selti->getType() == TreeItem::MapCenter ||
1840 selti->getType() == TreeItem::Image ))
1842 if (redosAvail == 0)
1845 QString s=getSelectString(selti);
1846 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1847 curClipboard=curStep;
1850 // Copy also to global clipboard, because we are at last step in history
1851 QString bakMapName(QString("history-%1").arg(curStep));
1852 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1853 copyDir (bakMapDir,clipboardDir );
1855 clipboardEmpty=false;
1861 void VymModel::pasteNoSave(const int &n)
1863 bool old=blockSaveState;
1864 blockSaveState=true;
1865 bool zippedOrg=zipped;
1866 if (redosAvail > 0 || n!=0)
1868 // Use the "historical" buffer
1869 QString bakMapName(QString("history-%1").arg(n));
1870 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1871 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1873 // Use the global buffer
1874 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1879 void VymModel::paste()
1881 BranchItem *selbi=getSelectedBranchItem();
1884 saveStateChangingPart(
1887 QString ("paste (%1)").arg(curClipboard),
1888 QString("Paste to %1").arg( getObjectName(selbi))
1895 void VymModel::cut()
1897 TreeItem *selti=getSelectedItem();
1898 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1906 void VymModel::moveUp()
1908 BranchItem *selbi=getSelectedBranchItem();
1911 if (!selbi->canMoveUp()) return;
1912 QString oldsel=getSelectString();
1913 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1915 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1919 void VymModel::moveDown()
1921 BranchItem *selbi=getSelectedBranchItem();
1924 if (!selbi->canMoveDown()) return;
1925 QString oldsel=getSelectString();
1926 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1928 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1932 void VymModel::sortChildren() // FIXME-2 not implemented yet
1935 BranchObj* bo=getSelectedBranch();
1938 if(treeItem->branchCount()>1)
1940 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1943 emitShowSelection();
1949 BranchItem* VymModel::createMapCenter()
1951 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1955 BranchItem* VymModel::createBranch(BranchItem *dst)
1958 return addNewBranchInt (dst,-2);
1963 ImageItem* VymModel::createImage(BranchItem *dst)
1970 QList<QVariant> cData;
1971 cData << "new" << "undef"<<"undef";
1973 ImageItem *newii=new ImageItem(cData) ;
1974 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1976 emit (layoutAboutToBeChanged() );
1979 n=dst->getRowNumAppend(newii);
1980 beginInsertRows (parix,n,n+1);
1981 dst->appendChild (newii);
1984 emit (layoutChanged() );
1986 // save scroll state. If scrolled, automatically select
1987 // new branch in order to tmp unscroll parent...
1988 newii->createMapObj(mapScene);
1995 BranchItem* VymModel::addMapCenter ()
1997 BranchItem *bi=addMapCenter (contextPos);
1999 emitShowSelection();
2004 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2005 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2010 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2011 // createMapCenter could then probably be merged with createBranch
2015 QModelIndex parix=index(rootItem);
2017 int n=rootItem->branchCount();
2019 emit (layoutAboutToBeChanged() );
2020 beginInsertRows (parix,n,n+1);
2022 QList<QVariant> cData;
2023 cData << "VM:addMapCenter" << "undef"<<"undef";
2024 BranchItem *newbi=new BranchItem (cData);
2025 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2026 rootItem->appendChild (newbi);
2029 emit (layoutChanged() );
2032 newbi->setPositionMode (MapItem::Absolute);
2033 newbi->createMapObj(mapScene);
2038 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2040 // Depending on pos:
2041 // -3 insert in children of parent above selection
2042 // -2 add branch to selection
2043 // -1 insert in children of parent below selection
2044 // 0..n insert in children of parent at pos
2047 QList<QVariant> cData;
2048 cData << "new" << "undef"<<"undef";
2053 BranchItem *newbi=new BranchItem (cData);
2054 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2056 emit (layoutAboutToBeChanged() );
2062 n=parbi->getRowNumAppend (newbi);
2063 beginInsertRows (parix,n,n+1);
2064 parbi->appendChild (newbi);
2066 }else if (num==-1 || num==-3)
2068 // insert below selection
2069 parbi=(BranchItem*)dst->parent();
2072 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2073 beginInsertRows (parix,n,n);
2074 parbi->insertBranch(n,newbi);
2077 emit (layoutChanged() );
2079 // save scroll state. If scrolled, automatically select
2080 // new branch in order to tmp unscroll parent...
2081 newbi->createMapObj(mapScene);
2086 BranchItem* VymModel::addNewBranch(int pos)
2088 // Different meaning than num in addNewBranchInt!
2092 BranchItem *newbi=NULL;
2093 BranchItem *selbi=getSelectedBranchItem();
2097 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2099 newbi=addNewBranchInt (selbi,pos-2);
2107 QString ("addBranch (%1)").arg(pos),
2108 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2111 // emitSelectionChanged(); FIXME-3
2112 latestAddedItem=newbi;
2113 // In Network mode, the client needs to know where the new branch is,
2114 // so we have to pass on this information via saveState.
2115 // TODO: Get rid of this positioning workaround
2116 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2117 sendData ("selectLatestAdded ()");
2118 sendData (QString("move %1").arg(ps));
2127 BranchItem* VymModel::addNewBranchBefore()
2129 BranchItem *newbi=NULL;
2130 BranchItem *selbi=getSelectedBranchItem();
2131 if (selbi && selbi->getType()==TreeItem::Branch)
2132 // We accept no MapCenter here, so we _have_ a parent
2134 //QPointF p=bo->getRelPos();
2137 // add below selection
2138 newbi=addNewBranchInt (selbi,-1);
2142 //newbi->move2RelPos (p);
2144 // Move selection to new branch
2145 relinkBranch (selbi,newbi,0);
2147 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2148 QString ("Add branch before %1").arg(getObjectName(selbi)));
2150 // FIXME-3 needed? reposition();
2151 // emitSelectionChanged(); FIXME-3
2157 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2161 if (branch->depth()==0)
2163 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2165 emit (layoutAboutToBeChanged() );
2166 BranchItem *branchpi=(BranchItem*)branch->parent();
2167 // Remove at current position
2168 int n=branch->childNum();
2169 beginRemoveRows (index(branchpi),n,n);
2170 branchpi->removeChild (n);
2173 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2175 // Append as last branch to dst
2176 if (dst->branchCount()==0)
2179 n=dst->getFirstBranch()->childNumber();
2180 beginInsertRows (index(dst),n+pos,n+pos);
2181 dst->insertBranch (pos,branch);
2184 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2185 branch->updateStyles();
2187 emit (layoutChanged() );
2188 reposition(); // both for moveUp/Down and relinking
2189 if (dst->isScrolled() )
2192 branch->updateVisibility();
2201 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2205 emit (layoutAboutToBeChanged() );
2207 BranchItem *pi=(BranchItem*)(image->parent());
2208 QString oldParString=getSelectString (pi);
2209 // Remove at current position
2210 int n=image->childNum();
2211 beginRemoveRows (index(pi),n,n);
2212 pi->removeChild (n);
2216 QModelIndex dstix=index(dst);
2217 n=dst->getRowNumAppend (image);
2218 beginInsertRows (dstix,n,n+1);
2219 dst->appendChild (image);
2222 // Set new parent also for lmo
2223 if (image->getLMO() && dst->getLMO() )
2224 image->getLMO()->setParObj (dst->getLMO() );
2226 emit (layoutChanged() );
2229 QString("relinkTo (\"%1\")").arg(oldParString),
2231 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2232 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2238 void VymModel::deleteSelection()
2240 BranchItem *selbi=getSelectedBranchItem();
2242 if (selbi && selbi->isBranchLikeType() )
2245 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2247 TreeItem *pi=deleteItem (selbi);
2251 emitShowSelection();
2255 ImageItem *ii=getSelectedImageItem();
2258 BranchItem *pi=(BranchItem*)(ii->parent());
2259 saveStateChangingPart(
2263 QString("Delete %1").arg(getObjectName(ii))
2269 emitShowSelection();
2274 void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters
2277 BranchItem *selbi=getSelectedBranchItem();
2281 // Don't use this on mapcenter
2282 if (selbi->depth()<2) return;
2284 pi=(BranchItem*)(selbi->parent());
2285 // Check if we have childs at all to keep
2286 if (selbi->branchCount()==0)
2293 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2294 saveStateChangingPart(
2297 "deleteKeepChildren ()",
2298 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2301 QString sel=getSelectString(selbi);
2303 int pos=selbi->num();
2304 BranchItem *bi=selbi->getFirstBranch();
2307 relinkBranch (bi,pi,pos);
2308 bi=selbi->getFirstBranch();
2314 BranchObj *bo=getSelectedBranchObj();
2317 bo->move2RelPos (p);
2323 void VymModel::deleteChildren()
2326 BranchItem *selbi=getSelectedBranchItem();
2329 saveStateChangingPart(
2332 "deleteChildren ()",
2333 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2335 emit (layoutAboutToBeChanged() );
2337 QModelIndex ix=index (selbi);
2338 int n=selbi->branchCount()-1;
2339 beginRemoveRows (ix,0,n);
2340 removeRows (0,n+1,ix);
2342 if (selbi->isScrolled()) selbi->unScroll();
2343 emit (layoutChanged() );
2348 TreeItem* VymModel::deleteItem (TreeItem *ti)
2352 TreeItem *pi=ti->parent();
2353 QModelIndex parentIndex=index(pi);
2355 emit (layoutAboutToBeChanged() );
2357 int n=ti->childNum();
2358 beginRemoveRows (parentIndex,n,n);
2359 removeRows (n,1,parentIndex);
2363 emit (layoutChanged() );
2364 if (pi->depth()>0) return pi;
2369 bool VymModel::scrollBranch(BranchItem *bi)
2373 if (bi->isScrolled()) return false;
2374 if (bi->branchCount()==0) return false;
2375 if (bi->depth()==0) return false;
2376 if (bi->toggleScroll())
2383 QString ("%1 ()").arg(u),
2385 QString ("%1 ()").arg(r),
2386 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2388 emitDataHasChanged(bi);
2389 emitSelectionChanged();
2390 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2397 bool VymModel::unscrollBranch(BranchItem *bi)
2401 if (!bi->isScrolled()) return false;
2402 if (bi->branchCount()==0) return false;
2403 if (bi->depth()==0) return false;
2410 QString ("%1 ()").arg(u),
2412 QString ("%1 ()").arg(r),
2413 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2416 emitDataHasChanged(bi);
2417 emitSelectionChanged();
2419 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2425 void VymModel::toggleScroll()
2427 BranchItem *bi=(BranchItem*)getSelectedBranchItem();
2428 if (bi && bi->isBranchLikeType() )
2430 if (bi->isScrolled())
2431 unscrollBranch (bi);
2435 // saveState is called in above functions
2438 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2442 BranchObj *bo=getSelectedBranch();
2448 if (bo->isScrolled()) unscrollBranch (bo);
2455 void VymModel::emitExpandAll()
2457 emit (expandAll() );
2460 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2462 BranchItem *bi=getSelectedBranchItem();
2466 if (bi->isActiveStandardFlag(name))
2478 QString("%1 (\"%2\")").arg(u).arg(name),
2480 QString("%1 (\"%2\")").arg(r).arg(name),
2481 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2482 bi->toggleStandardFlag (name, master);
2484 emitSelectionChanged();
2488 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2491 BranchObj *bo=getSelectedBranch();
2494 FloatImageObj *fio=bo->addFloatImage();
2496 fio->setOriginalFilename("No original filename (image added by dropevent)");
2497 QString s=getSelectString(bo);
2498 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2499 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2501 // FIXME-3 VM needed? scene()->update();
2507 void VymModel::colorBranch (QColor c)
2509 BranchItem *selbi=getSelectedBranchItem();
2514 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2516 QString ("colorBranch (\"%1\")").arg(c.name()),
2517 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2519 selbi->setHeadingColor(c); // color branch
2523 void VymModel::colorSubtree (QColor c)
2525 BranchItem *selbi=getSelectedBranchItem();
2528 saveStateChangingPart(
2531 QString ("colorSubtree (\"%1\")").arg(c.name()),
2532 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2534 BranchItem *prev=NULL;
2535 BranchItem *cur=selbi;
2538 cur->setHeadingColor(c); // color links, color children
2539 cur=next (cur,prev,selbi);
2545 QColor VymModel::getCurrentHeadingColor()
2547 BranchItem *selbi=getSelectedBranchItem();
2548 if (selbi) return selbi->getHeadingColor();
2550 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2556 void VymModel::editURL()
2558 TreeItem *selti=getSelectedItem();
2562 QString text = QInputDialog::getText(
2563 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2564 selti->getURL(), &ok, NULL);
2566 // user entered something and pressed OK
2571 void VymModel::editLocalURL()
2573 TreeItem *selti=getSelectedItem();
2576 QStringList filters;
2577 filters <<"All files (*)";
2578 filters << tr("Text","Filedialog") + " (*.txt)";
2579 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2580 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2581 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2582 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2583 fd->setFilters (filters);
2584 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2585 fd->setDirectory (lastFileDir);
2586 if (! selti->getVymLink().isEmpty() )
2587 fd->selectFile( selti->getURL() );
2590 if ( fd->exec() == QDialog::Accepted )
2592 lastFileDir=QDir (fd->directory().path());
2593 setURL (fd->selectedFile() );
2599 void VymModel::editHeading2URL()
2601 TreeItem *selti=getSelectedItem();
2603 setURL (selti->getHeading());
2606 void VymModel::editBugzilla2URL()
2608 TreeItem *selti=getSelectedItem();
2611 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2616 void VymModel::editFATE2URL()
2618 TreeItem *selti=getSelectedItem();
2621 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2624 "setURL (\""+selti->getURL()+"\")",
2626 "setURL (\""+url+"\")",
2627 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2629 selti->setURL (url);
2630 // FIXME-4 updateActions();
2634 void VymModel::editVymLink()
2636 BranchItem *bi=getSelectedBranchItem();
2639 QStringList filters;
2640 filters <<"VYM map (*.vym)";
2641 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2642 fd->setFilters (filters);
2643 fd->setCaption(vymName+" - " +tr("Link to another map"));
2644 fd->setDirectory (lastFileDir);
2645 if (! bi->getVymLink().isEmpty() )
2646 fd->selectFile( bi->getVymLink() );
2650 if ( fd->exec() == QDialog::Accepted )
2652 lastFileDir=QDir (fd->directory().path());
2655 "setVymLink (\""+bi->getVymLink()+"\")",
2657 "setVymLink (\""+fd->selectedFile()+"\")",
2658 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2660 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2665 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2667 // Internal function, no saveState needed
2668 TreeItem *selti=getSelectedItem();
2671 selti->setVymLink(s);
2673 emitDataHasChanged (selti);
2674 emitShowSelection();
2678 void VymModel::deleteVymLink()
2680 BranchItem *bi=getSelectedBranchItem();
2685 "setVymLink (\""+bi->getVymLink()+"\")",
2687 "setVymLink (\"\")",
2688 QString("Unset vymlink of %1").arg(getObjectName(bi))
2690 bi->setVymLink ("" );
2696 QString VymModel::getVymLink()
2698 BranchItem *bi=getSelectedBranchItem();
2700 return bi->getVymLink();
2706 QStringList VymModel::getVymLinks()
2709 BranchItem *selbi=getSelectedBranchItem();
2710 BranchItem *cur=selbi;
2711 BranchItem *prev=NULL;
2714 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2715 cur=next (cur,prev,selbi);
2721 void VymModel::followXLink(int i) // FIXME-2
2725 BranchObj *bo=getSelectedBranch();
2728 bo=bo->XLinkTargetAt(i);
2731 selection.select(bo);
2732 emitShowSelection();
2738 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2742 BranchObj *bo=getSelectedBranch();
2745 XLinkObj *xlo=bo->XLinkAt(i);
2748 EditXLinkDialog dia;
2750 dia.setSelection(bo);
2751 if (dia.exec() == QDialog::Accepted)
2753 if (dia.useSettingsGlobal() )
2755 setMapDefXLinkColor (xlo->getColor() );
2756 setMapDefXLinkWidth (xlo->getWidth() );
2758 if (dia.deleteXLink())
2759 bo->deleteXLinkAt(i);
2770 //////////////////////////////////////////////
2772 //////////////////////////////////////////////
2774 void VymModel::parseAtom(const QString &atom)
2776 TreeItem* selti=getSelectedItem();
2777 BranchItem *selbi=getSelectedBranchItem();
2783 // Split string s into command and parameters
2784 parser.parseAtom (atom);
2785 QString com=parser.getCommand();
2787 // External commands
2788 /////////////////////////////////////////////////////////////////////
2789 if (com=="addBranch")
2793 parser.setError (Aborted,"Nothing selected");
2794 } else if (! selbi )
2796 parser.setError (Aborted,"Type of selection is not a branch");
2801 if (parser.checkParCount(pl))
2803 if (parser.parCount()==0)
2807 n=parser.parInt (ok,0);
2808 if (ok ) addNewBranch (n);
2812 /////////////////////////////////////////////////////////////////////
2813 } else if (com=="addBranchBefore")
2817 parser.setError (Aborted,"Nothing selected");
2818 } else if (! selbi )
2820 parser.setError (Aborted,"Type of selection is not a branch");
2823 if (parser.parCount()==0)
2825 addNewBranchBefore ();
2828 /////////////////////////////////////////////////////////////////////
2829 } else if (com==QString("addMapCenter"))
2831 if (parser.checkParCount(2))
2833 x=parser.parDouble (ok,0);
2836 y=parser.parDouble (ok,1);
2837 if (ok) addMapCenter (QPointF(x,y));
2840 /////////////////////////////////////////////////////////////////////
2841 } else if (com==QString("addMapReplace"))
2845 parser.setError (Aborted,"Nothing selected");
2846 } else if (! selbi )
2848 parser.setError (Aborted,"Type of selection is not a branch");
2849 } else if (parser.checkParCount(1))
2851 //s=parser.parString (ok,0); // selection
2852 t=parser.parString (ok,0); // path to map
2853 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2854 addMapReplaceInt(getSelectString(selbi),t);
2856 /////////////////////////////////////////////////////////////////////
2857 } else if (com==QString("addMapInsert"))
2861 parser.setError (Aborted,"Nothing selected");
2862 } else if (! selbi )
2864 parser.setError (Aborted,"Type of selection is not a branch");
2867 if (parser.checkParCount(2))
2869 t=parser.parString (ok,0); // path to map
2870 n=parser.parInt(ok,1); // position
2871 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2872 addMapInsertInt(t,n);
2875 /////////////////////////////////////////////////////////////////////
2876 } else if (com=="clearFlags")
2880 parser.setError (Aborted,"Nothing selected");
2881 } else if (! selbi )
2883 parser.setError (Aborted,"Type of selection is not a branch");
2884 } else if (parser.checkParCount(0))
2886 selbi->deactivateAllStandardFlags();
2888 /////////////////////////////////////////////////////////////////////
2889 } else if (com=="colorBranch")
2893 parser.setError (Aborted,"Nothing selected");
2894 } else if (! selbi )
2896 parser.setError (Aborted,"Type of selection is not a branch");
2897 } else if (parser.checkParCount(1))
2899 QColor c=parser.parColor (ok,0);
2900 if (ok) colorBranch (c);
2902 /////////////////////////////////////////////////////////////////////
2903 } else if (com=="colorSubtree")
2907 parser.setError (Aborted,"Nothing selected");
2908 } else if (! selbi )
2910 parser.setError (Aborted,"Type of selection is not a branch");
2911 } else if (parser.checkParCount(1))
2913 QColor c=parser.parColor (ok,0);
2914 if (ok) colorSubtree (c);
2916 /////////////////////////////////////////////////////////////////////
2917 } else if (com=="copy")
2921 parser.setError (Aborted,"Nothing selected");
2922 } else if ( selectionType()!=TreeItem::Branch &&
2923 selectionType()!=TreeItem::MapCenter &&
2924 selectionType()!=TreeItem::Image )
2926 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2927 } else if (parser.checkParCount(0))
2931 /////////////////////////////////////////////////////////////////////
2932 } else if (com=="cut")
2936 parser.setError (Aborted,"Nothing selected");
2937 } else if ( selectionType()!=TreeItem::Branch &&
2938 selectionType()!=TreeItem::MapCenter &&
2939 selectionType()!=TreeItem::Image )
2941 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2942 } else if (parser.checkParCount(0))
2946 /////////////////////////////////////////////////////////////////////
2947 } else if (com=="delete")
2951 parser.setError (Aborted,"Nothing selected");
2953 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2955 parser.setError (Aborted,"Type of selection is wrong.");
2958 else if (parser.checkParCount(0))
2962 /////////////////////////////////////////////////////////////////////
2963 } else if (com=="deleteKeepChildren")
2967 parser.setError (Aborted,"Nothing selected");
2968 } else if (! selbi )
2970 parser.setError (Aborted,"Type of selection is not a branch");
2971 } else if (parser.checkParCount(0))
2973 deleteKeepChildren();
2975 /////////////////////////////////////////////////////////////////////
2976 } else if (com=="deleteChildren")
2980 parser.setError (Aborted,"Nothing selected");
2983 parser.setError (Aborted,"Type of selection is not a branch");
2984 } else if (parser.checkParCount(0))
2988 /////////////////////////////////////////////////////////////////////
2989 } else if (com=="exportASCII")
2993 if (parser.parCount()>=1)
2994 // Hey, we even have a filename
2995 fname=parser.parString(ok,0);
2998 parser.setError (Aborted,"Could not read filename");
3001 exportASCII (fname,false);
3003 /////////////////////////////////////////////////////////////////////
3004 } else if (com=="exportImage")
3008 if (parser.parCount()>=2)
3009 // Hey, we even have a filename
3010 fname=parser.parString(ok,0);
3013 parser.setError (Aborted,"Could not read filename");
3016 QString format="PNG";
3017 if (parser.parCount()>=2)
3019 format=parser.parString(ok,1);
3021 exportImage (fname,false,format);
3023 /////////////////////////////////////////////////////////////////////
3024 } else if (com=="exportXHTML")
3028 if (parser.parCount()>=2)
3029 // Hey, we even have a filename
3030 fname=parser.parString(ok,1);
3033 parser.setError (Aborted,"Could not read filename");
3036 exportXHTML (fname,false);
3038 /////////////////////////////////////////////////////////////////////
3039 } else if (com=="exportXML")
3043 if (parser.parCount()>=2)
3044 // Hey, we even have a filename
3045 fname=parser.parString(ok,1);
3048 parser.setError (Aborted,"Could not read filename");
3051 exportXML (fname,false);
3053 /////////////////////////////////////////////////////////////////////
3054 } else if (com=="importDir")
3058 parser.setError (Aborted,"Nothing selected");
3059 } else if (! selbi )
3061 parser.setError (Aborted,"Type of selection is not a branch");
3062 } else if (parser.checkParCount(1))
3064 s=parser.parString(ok,0);
3065 if (ok) importDirInt(s);
3067 /////////////////////////////////////////////////////////////////////
3068 } else if (com=="relinkTo")
3072 parser.setError (Aborted,"Nothing selected");
3075 if (parser.checkParCount(4))
3077 // 0 selectstring of parent
3078 // 1 num in parent (for branches)
3079 // 2,3 x,y of mainbranch or mapcenter
3080 s=parser.parString(ok,0);
3081 TreeItem *dst=findBySelectString (s);
3084 if (dst->getType()==TreeItem::Branch)
3086 // Get number in parent
3087 n=parser.parInt (ok,1);
3090 relinkBranch (selbi,(BranchItem*)dst,n);
3091 emitSelectionChanged();
3093 } else if (dst->getType()==TreeItem::MapCenter)
3095 relinkBranch (selbi,(BranchItem*)dst);
3096 // Get coordinates of mainbranch
3097 x=parser.parDouble(ok,2);
3100 y=parser.parDouble(ok,3);
3103 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3104 emitSelectionChanged();
3110 } else if ( selti->getType() == TreeItem::Image)
3112 if (parser.checkParCount(1))
3114 // 0 selectstring of parent
3115 s=parser.parString(ok,0);
3116 TreeItem *dst=findBySelectString (s);
3119 if (dst->isBranchLikeType())
3120 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3122 parser.setError (Aborted,"Destination is not a branch");
3125 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3126 /////////////////////////////////////////////////////////////////////
3127 } else if (com=="loadImage")
3131 parser.setError (Aborted,"Nothing selected");
3132 } else if (! selbi )
3134 parser.setError (Aborted,"Type of selection is not a branch");
3135 } else if (parser.checkParCount(1))
3137 s=parser.parString(ok,0);
3138 if (ok) loadFloatImageInt (selbi,s);
3140 /////////////////////////////////////////////////////////////////////
3141 } else if (com=="moveUp")
3145 parser.setError (Aborted,"Nothing selected");
3146 } else if (! selbi )
3148 parser.setError (Aborted,"Type of selection is not a branch");
3149 } else if (parser.checkParCount(0))
3153 /////////////////////////////////////////////////////////////////////
3154 } else if (com=="moveDown")
3158 parser.setError (Aborted,"Nothing selected");
3159 } else if (! selbi )
3161 parser.setError (Aborted,"Type of selection is not a branch");
3162 } else if (parser.checkParCount(0))
3166 /////////////////////////////////////////////////////////////////////
3167 } else if (com=="move")
3171 parser.setError (Aborted,"Nothing selected");
3172 } else if ( selectionType()!=TreeItem::Branch &&
3173 selectionType()!=TreeItem::MapCenter &&
3174 selectionType()!=TreeItem::Image )
3176 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3177 } else if (parser.checkParCount(2))
3179 x=parser.parDouble (ok,0);
3182 y=parser.parDouble (ok,1);
3186 /////////////////////////////////////////////////////////////////////
3187 } else if (com=="moveRel")
3191 parser.setError (Aborted,"Nothing selected");
3192 } else if ( selectionType()!=TreeItem::Branch &&
3193 selectionType()!=TreeItem::MapCenter &&
3194 selectionType()!=TreeItem::Image )
3196 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3197 } else if (parser.checkParCount(2))
3199 x=parser.parDouble (ok,0);
3202 y=parser.parDouble (ok,1);
3203 if (ok) moveRel (x,y);
3206 /////////////////////////////////////////////////////////////////////
3207 } else if (com=="nop")
3209 /////////////////////////////////////////////////////////////////////
3210 } else if (com=="paste")
3214 parser.setError (Aborted,"Nothing selected");
3215 } else if (! selbi )
3217 parser.setError (Aborted,"Type of selection is not a branch");
3218 } else if (parser.checkParCount(1))
3220 n=parser.parInt (ok,0);
3221 if (ok) pasteNoSave(n);
3223 /////////////////////////////////////////////////////////////////////
3224 } else if (com=="qa")
3228 parser.setError (Aborted,"Nothing selected");
3229 } else if (! selbi )
3231 parser.setError (Aborted,"Type of selection is not a branch");
3232 } else if (parser.checkParCount(4))
3235 c=parser.parString (ok,0);
3238 parser.setError (Aborted,"No comment given");
3241 s=parser.parString (ok,1);
3244 parser.setError (Aborted,"First parameter is not a string");
3247 t=parser.parString (ok,2);
3250 parser.setError (Aborted,"Condition is not a string");
3253 u=parser.parString (ok,3);
3256 parser.setError (Aborted,"Third parameter is not a string");
3261 parser.setError (Aborted,"Unknown type: "+s);
3266 parser.setError (Aborted,"Unknown operator: "+t);
3271 parser.setError (Aborted,"Type of selection is not a branch");
3274 if (selbi->getHeading() == u)
3276 cout << "PASSED: " << qPrintable (c) << endl;
3279 cout << "FAILED: " << qPrintable (c) << endl;
3289 /////////////////////////////////////////////////////////////////////
3290 } else if (com=="saveImage")
3292 ImageItem *ii=getSelectedImageItem();
3295 parser.setError (Aborted,"No image selected");
3296 } else if (parser.checkParCount(2))
3298 s=parser.parString(ok,0);
3301 t=parser.parString(ok,1);
3302 if (ok) saveFloatImageInt (ii,t,s);
3305 /////////////////////////////////////////////////////////////////////
3306 } else if (com=="scroll")
3310 parser.setError (Aborted,"Nothing selected");
3311 } else if (! selbi )
3313 parser.setError (Aborted,"Type of selection is not a branch");
3314 } else if (parser.checkParCount(0))
3316 if (!scrollBranch (selbi))
3317 parser.setError (Aborted,"Could not scroll branch");
3319 /////////////////////////////////////////////////////////////////////
3320 } else if (com=="select")
3322 if (parser.checkParCount(1))
3324 s=parser.parString(ok,0);
3327 /////////////////////////////////////////////////////////////////////
3328 } else if (com=="selectLastBranch")
3332 parser.setError (Aborted,"Nothing selected");
3333 } else if (! selbi )
3335 parser.setError (Aborted,"Type of selection is not a branch");
3336 } else if (parser.checkParCount(0))
3338 BranchItem *bi=selbi->getLastBranch();
3340 parser.setError (Aborted,"Could not select last branch");
3341 select (bi); // FIXME-3 was selectInt
3344 /////////////////////////////////////////////////////////////////////
3345 } else /* FIXME-2 if (com=="selectLastImage")
3349 parser.setError (Aborted,"Nothing selected");
3350 } else if (! selbi )
3352 parser.setError (Aborted,"Type of selection is not a branch");
3353 } else if (parser.checkParCount(0))
3355 FloatImageObj *fio=selb->getLastFloatImage();
3357 parser.setError (Aborted,"Could not select last image");
3358 select (fio); // FIXME-3 was selectInt
3361 /////////////////////////////////////////////////////////////////////
3362 } else */ if (com=="selectLatestAdded")
3364 if (!latestAddedItem)
3366 parser.setError (Aborted,"No latest added object");
3369 if (!select (latestAddedItem))
3370 parser.setError (Aborted,"Could not select latest added object ");
3372 /////////////////////////////////////////////////////////////////////
3373 } else if (com=="setFrameType")
3375 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3377 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3379 else if (parser.checkParCount(1))
3381 s=parser.parString(ok,0);
3382 if (ok) setFrameType (s);
3384 /////////////////////////////////////////////////////////////////////
3385 } else if (com=="setFramePenColor")
3387 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3389 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3391 else if (parser.checkParCount(1))
3393 QColor c=parser.parColor(ok,0);
3394 if (ok) setFramePenColor (c);
3396 /////////////////////////////////////////////////////////////////////
3397 } else if (com=="setFrameBrushColor")
3399 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3401 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3403 else if (parser.checkParCount(1))
3405 QColor c=parser.parColor(ok,0);
3406 if (ok) setFrameBrushColor (c);
3408 /////////////////////////////////////////////////////////////////////
3409 } else if (com=="setFramePadding")
3411 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3413 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3415 else if (parser.checkParCount(1))
3417 n=parser.parInt(ok,0);
3418 if (ok) setFramePadding(n);
3420 /////////////////////////////////////////////////////////////////////
3421 } else if (com=="setFrameBorderWidth")
3423 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3425 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3427 else if (parser.checkParCount(1))
3429 n=parser.parInt(ok,0);
3430 if (ok) setFrameBorderWidth (n);
3432 /////////////////////////////////////////////////////////////////////
3433 } else if (com=="setMapAuthor")
3435 if (parser.checkParCount(1))
3437 s=parser.parString(ok,0);
3438 if (ok) setAuthor (s);
3440 /////////////////////////////////////////////////////////////////////
3441 } else if (com=="setMapComment")
3443 if (parser.checkParCount(1))
3445 s=parser.parString(ok,0);
3446 if (ok) setComment(s);
3448 /////////////////////////////////////////////////////////////////////
3449 } else if (com=="setMapBackgroundColor")
3453 parser.setError (Aborted,"Nothing selected");
3454 } else if (! selbi )
3456 parser.setError (Aborted,"Type of selection is not a branch");
3457 } else if (parser.checkParCount(1))
3459 QColor c=parser.parColor (ok,0);
3460 if (ok) setMapBackgroundColor (c);
3462 /////////////////////////////////////////////////////////////////////
3463 } else if (com=="setMapDefLinkColor")
3467 parser.setError (Aborted,"Nothing selected");
3468 } else if (! selbi )
3470 parser.setError (Aborted,"Type of selection is not a branch");
3471 } else if (parser.checkParCount(1))
3473 QColor c=parser.parColor (ok,0);
3474 if (ok) setMapDefLinkColor (c);
3476 /////////////////////////////////////////////////////////////////////
3477 } else if (com=="setMapLinkStyle")
3479 if (parser.checkParCount(1))
3481 s=parser.parString (ok,0);
3482 if (ok) setMapLinkStyle(s);
3484 /////////////////////////////////////////////////////////////////////
3485 } else if (com=="setHeading")
3489 parser.setError (Aborted,"Nothing selected");
3490 } else if (! selbi )
3492 parser.setError (Aborted,"Type of selection is not a branch");
3493 } else if (parser.checkParCount(1))
3495 s=parser.parString (ok,0);
3499 /////////////////////////////////////////////////////////////////////
3500 } else if (com=="setHideExport")
3504 parser.setError (Aborted,"Nothing selected");
3505 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3507 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3508 } else if (parser.checkParCount(1))
3510 b=parser.parBool(ok,0);
3511 if (ok) setHideExport (b);
3513 /////////////////////////////////////////////////////////////////////
3514 } else if (com=="setIncludeImagesHorizontally")
3518 parser.setError (Aborted,"Nothing selected");
3521 parser.setError (Aborted,"Type of selection is not a branch");
3522 } else if (parser.checkParCount(1))
3524 b=parser.parBool(ok,0);
3525 if (ok) setIncludeImagesHor(b);
3527 /////////////////////////////////////////////////////////////////////
3528 } else if (com=="setIncludeImagesVertically")
3532 parser.setError (Aborted,"Nothing selected");
3535 parser.setError (Aborted,"Type of selection is not a branch");
3536 } else if (parser.checkParCount(1))
3538 b=parser.parBool(ok,0);
3539 if (ok) setIncludeImagesVer(b);
3541 /////////////////////////////////////////////////////////////////////
3542 } else if (com=="setHideLinkUnselected")
3546 parser.setError (Aborted,"Nothing selected");
3547 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3549 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3550 } else if (parser.checkParCount(1))
3552 b=parser.parBool(ok,0);
3553 if (ok) setHideLinkUnselected(b);
3555 /////////////////////////////////////////////////////////////////////
3556 } else if (com=="setSelectionColor")
3558 if (parser.checkParCount(1))
3560 QColor c=parser.parColor (ok,0);
3561 if (ok) setSelectionColorInt (c);
3563 /////////////////////////////////////////////////////////////////////
3564 } else if (com=="setURL")
3568 parser.setError (Aborted,"Nothing selected");
3569 } else if (! selbi )
3571 parser.setError (Aborted,"Type of selection is not a branch");
3572 } else if (parser.checkParCount(1))
3574 s=parser.parString (ok,0);
3577 /////////////////////////////////////////////////////////////////////
3578 } else if (com=="setVymLink")
3582 parser.setError (Aborted,"Nothing selected");
3583 } else if (! selbi )
3585 parser.setError (Aborted,"Type of selection is not a branch");
3586 } else if (parser.checkParCount(1))
3588 s=parser.parString (ok,0);
3589 if (ok) setVymLink(s);
3592 /////////////////////////////////////////////////////////////////////
3593 else if (com=="setFlag")
3597 parser.setError (Aborted,"Nothing selected");
3598 } else if (! selbi )
3600 parser.setError (Aborted,"Type of selection is not a branch");
3601 } else if (parser.checkParCount(1))
3603 s=parser.parString(ok,0);
3605 selbi->activateStandardFlag(s);
3607 /////////////////////////////////////////////////////////////////////
3608 } else /* FIXME-2 if (com=="setFrameType")
3612 parser.setError (Aborted,"Nothing selected");
3615 parser.setError (Aborted,"Type of selection is not a branch");
3616 } else if (parser.checkParCount(1))
3618 s=parser.parString(ok,0);
3622 /////////////////////////////////////////////////////////////////////
3623 } else*/ if (com=="sortChildren")
3627 parser.setError (Aborted,"Nothing selected");
3628 } else if (! selbi )
3630 parser.setError (Aborted,"Type of selection is not a branch");
3631 } else if (parser.checkParCount(0))
3635 /////////////////////////////////////////////////////////////////////
3636 } else if (com=="toggleFlag")
3640 parser.setError (Aborted,"Nothing selected");
3641 } else if (! selbi )
3643 parser.setError (Aborted,"Type of selection is not a branch");
3644 } else if (parser.checkParCount(1))
3646 s=parser.parString(ok,0);
3648 selbi->toggleStandardFlag(s);
3650 /////////////////////////////////////////////////////////////////////
3651 } else if (com=="unscroll")
3655 parser.setError (Aborted,"Nothing selected");
3656 } else if (! selbi )
3658 parser.setError (Aborted,"Type of selection is not a branch");
3659 } else if (parser.checkParCount(0))
3661 if (!unscrollBranch (selbi))
3662 parser.setError (Aborted,"Could not unscroll branch");
3664 /////////////////////////////////////////////////////////////////////
3665 } else if (com=="unscrollChildren")
3669 parser.setError (Aborted,"Nothing selected");
3670 } else if (! selbi )
3672 parser.setError (Aborted,"Type of selection is not a branch");
3673 } else if (parser.checkParCount(0))
3675 unscrollChildren ();
3677 /////////////////////////////////////////////////////////////////////
3678 } else if (com=="unsetFlag")
3682 parser.setError (Aborted,"Nothing selected");
3683 } else if (! selbi )
3685 parser.setError (Aborted,"Type of selection is not a branch");
3686 } else if (parser.checkParCount(1))
3688 s=parser.parString(ok,0);
3690 selbi->deactivateStandardFlag(s);
3693 parser.setError (Aborted,"Unknown command");
3696 if (parser.errorLevel()==NoError)
3698 // setChanged(); FIXME-2 should not be called e.g. for export?!
3703 // TODO Error handling
3704 qWarning("VymModel::parseAtom: Error!");
3705 qWarning(parser.errorMessage());
3709 void VymModel::runScript (QString script)
3711 parser.setScript (script);
3713 while (parser.next() )
3714 parseAtom(parser.getAtom());
3717 void VymModel::setExportMode (bool b)
3719 // should be called before and after exports
3720 // depending on the settings
3721 if (b && settings.value("/export/useHideExport","true")=="true")
3722 setHideTmpMode (TreeItem::HideExport);
3724 setHideTmpMode (TreeItem::HideNone);
3727 void VymModel::exportImage(QString fname, bool askName, QString format)
3729 /* FIXME-2 export as image, but directly from mapEditor?!
3732 fname=getMapName()+".png";
3739 QFileDialog *fd=new QFileDialog (NULL);
3740 fd->setCaption (tr("Export map as image"));
3741 fd->setDirectory (lastImageDir);
3742 fd->setFileMode(QFileDialog::AnyFile);
3743 fd->setFilters (imageIO.getFilters() );
3746 fl=fd->selectedFiles();
3748 format=imageIO.getType(fd->selectedFilter());
3752 setExportMode (true);
3753 QPixmap pix (mapEditor->getPixmap());
3754 pix.save(fname, format);
3755 setExportMode (false);
3760 void VymModel::exportXML(QString dir, bool askForName)
3764 dir=browseDirectory(NULL,tr("Export XML to directory"));
3765 if (dir =="" && !reallyWriteDirectory(dir) )
3769 // Hide stuff during export, if settings want this
3770 setExportMode (true);
3772 // Create subdirectories
3775 // write to directory //FIXME-4 check totalBBox here...
3776 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3779 file.setName ( dir + "/"+mapName+".xml");
3780 if ( !file.open( QIODevice::WriteOnly ) )
3782 // This should neverever happen
3783 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3787 // Write it finally, and write in UTF8, no matter what
3788 QTextStream ts( &file );
3789 ts.setEncoding (QTextStream::UnicodeUTF8);
3793 // Now write image, too
3794 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3796 setExportMode (false);
3799 void VymModel::exportASCII(QString fname,bool askName)
3804 ex.setFile (mapName+".txt");
3810 //ex.addFilter ("TXT (*.txt)");
3811 ex.setDir(lastImageDir);
3812 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3817 setExportMode(true);
3819 setExportMode(false);
3823 void VymModel::exportXHTML (const QString &dir, bool askForName)
3825 ExportXHTMLDialog dia(NULL);
3826 dia.setFilePath (filePath );
3827 dia.setMapName (mapName );
3829 if (dir!="") dia.setDir (dir);
3835 if (dia.exec()!=QDialog::Accepted)
3839 QDir d (dia.getDir());
3840 // Check, if warnings should be used before overwriting
3841 // the output directory
3842 if (d.exists() && d.count()>0)
3845 warn.showCancelButton (true);
3846 warn.setText(QString(
3847 "The directory %1 is not empty.\n"
3848 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3849 warn.setCaption("Warning: Directory not empty");
3850 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3852 if (warn.exec()!=QDialog::Accepted) ok=false;
3859 exportXML (dia.getDir(),false );
3860 dia.doExport(mapName );
3861 //if (dia.hasChanged()) setChanged();
3865 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3870 if (ex.setConfigFile(cf))
3872 setExportMode (true);
3873 ex.exportPresentation();
3874 setExportMode (false);
3881 //////////////////////////////////////////////
3883 //////////////////////////////////////////////
3885 void VymModel::registerEditor(QWidget *me)
3887 mapEditor=(MapEditor*)me;
3890 void VymModel::unregisterEditor(QWidget *)
3895 void VymModel::setContextPos(QPointF p)
3900 void VymModel::unsetContextPos()
3902 contextPos=QPointF();
3905 void VymModel::updateNoteFlag()
3908 TreeItem *selti=getSelectedItem();
3911 if (textEditor->isEmpty())
3914 selti->setNote (textEditor->getText());
3915 emitDataHasChanged(selti);
3916 emitSelectionChanged();
3921 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3924 for (int i=0; i<rootItem->branchCount(); i++)
3925 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3928 void MapCenterObj::updateRelPositions()
3930 if (repositionRequest) unsetAllRepositionRequests();
3932 // update relative Positions of branches and floats
3933 for (int i=0; i<treeItem->branchCount(); ++i)
3935 treeItem->getBranchObjNum(i)->setRelPos();
3936 treeItem->getBranchObjNum(i)->setOrientation();
3939 for (int i=0; i<floatimage.size(); ++i)
3940 floatimage.at(i)->setRelPos();
3942 if (repositionRequest) reposition();
3947 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3949 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3950 if (blockReposition) return;
3952 for (int i=0;i<rootItem->branchCount(); i++)
3953 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3957 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3959 return QPolygonF ();
3960 // Creating (arbitrary) shapes
3963 QRectF rb=bo->getBBox();
3964 if (bo->getDepth()==0)
3966 // Just take BBox of this mapCenter
3967 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3971 // Take union of BBox and TotalBBox
3973 QRectF ra=bo->getTotalBBox();
3974 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3977 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3980 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3982 p <<ra.bottomRight()
3984 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3987 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3993 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
3997 // Move all branches and MapCenters away from lmo
3998 // to avoid collisions
4003 BranchObj *boA=(BranchObj*)lmo;
4005 for (int i=0; i<rootItem->branchCount(); i++)
4007 boB=rootItem->getBranchNum(i);
4010 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4013 <<" ("<<qPrintable(boA->getHeading() )<<")"
4014 <<" with ("<< qPrintable (boB->getHeading() )
4017 <<" minT="<<r.minTranslation<<endl<<endl;
4023 void VymModel::setMapLinkStyle (const QString & s)
4028 case LinkableMapObj::Line :
4031 case LinkableMapObj::Parabel:
4032 snow="StyleParabel";
4034 case LinkableMapObj::PolyLine:
4035 snow="StylePolyLine";
4037 case LinkableMapObj::PolyParabel:
4038 snow="StylePolyParabel";
4041 snow="UndefinedStyle";
4046 QString("setMapLinkStyle (\"%1\")").arg(s),
4047 QString("setMapLinkStyle (\"%1\")").arg(snow),
4048 QString("Set map link style (\"%1\")").arg(s)
4052 linkstyle=LinkableMapObj::Line;
4053 else if (s=="StyleParabel")
4054 linkstyle=LinkableMapObj::Parabel;
4055 else if (s=="StylePolyLine")
4056 linkstyle=LinkableMapObj::PolyLine;
4057 else if (s=="StylePolyParabel")
4058 linkstyle=LinkableMapObj::PolyParabel;
4060 linkstyle=LinkableMapObj::UndefinedStyle;
4062 BranchItem *cur=NULL;
4063 BranchItem *prev=NULL;
4068 bo=(BranchObj*)(cur->getLMO() );
4069 bo->setLinkStyle(bo->getDefLinkStyle());
4075 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4080 void VymModel::setMapDefLinkColor(QColor col)
4082 if ( !col.isValid() ) return;
4084 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4085 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4086 QString("Set map link color to %1").arg(col.name())
4090 BranchItem *cur=NULL;
4091 BranchItem *prev=NULL;
4096 bo=(BranchObj*)(cur->getLMO() );
4103 void VymModel::setMapLinkColorHintInt()
4105 // called from setMapLinkColorHint(lch) or at end of parse
4106 BranchItem *cur=NULL;
4107 BranchItem *prev=NULL;
4112 bo=(BranchObj*)(cur->getLMO() );
4118 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4121 setMapLinkColorHintInt();
4124 void VymModel::toggleMapLinkColorHint()
4126 if (linkcolorhint==LinkableMapObj::HeadingColor)
4127 linkcolorhint=LinkableMapObj::DefaultColor;
4129 linkcolorhint=LinkableMapObj::HeadingColor;
4130 BranchItem *cur=NULL;
4131 BranchItem *prev=NULL;
4136 bo=(BranchObj*)(cur->getLMO() );
4142 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4144 Q3FileDialog *fd=new Q3FileDialog( NULL);
4145 fd->setMode (Q3FileDialog::ExistingFile);
4146 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4147 ImagePreview *p =new ImagePreview (fd);
4148 fd->setContentsPreviewEnabled( TRUE );
4149 fd->setContentsPreview( p, p );
4150 fd->setPreviewMode( Q3FileDialog::Contents );
4151 fd->setCaption(vymName+" - " +tr("Load background image"));
4152 fd->setDir (lastImageDir);
4155 if ( fd->exec() == QDialog::Accepted )
4157 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4158 lastImageDir=QDir (fd->dirPath());
4159 setMapBackgroundImage (fd->selectedFile());
4163 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
4165 QColor oldcol=mapScene->backgroundBrush().color();
4169 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4171 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4172 QString("Set background color of map to %1").arg(col.name()));
4175 brush.setTextureImage (QPixmap (fn));
4176 mapScene->setBackgroundBrush(brush);
4179 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4181 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4182 if ( !col.isValid() ) return;
4183 setMapBackgroundColor( col );
4187 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4189 QColor oldcol=mapScene->backgroundBrush().color();
4191 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4192 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4193 QString("Set background color of map to %1").arg(col.name()));
4194 mapScene->setBackgroundBrush(col);
4197 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4199 return mapScene->backgroundBrush().color();
4203 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4205 return linkcolorhint;
4208 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4210 return defLinkColor;
4213 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4218 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4220 return defXLinkColor;
4223 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4228 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4230 return defXLinkWidth;
4233 void VymModel::move(const double &x, const double &y) // FIXME-3
4237 BranchObj *bo = getSelectedBranch();
4239 (selectionType()==TreeItem::Branch ||
4240 selectionType()==TreeItem::MapCenter ||
4241 selectionType()==TreeItem::Image
4244 QPointF ap(bo->getAbsPos());
4248 QString ps=qpointfToString(ap);
4249 QString s=getSelectString();
4252 s, "move "+qpointfToString(to),
4253 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4256 emitSelectionChanged();
4262 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4266 BranchObj *bo = getSelectedBranch();
4268 (selectionType()==TreeItem::Branch ||
4269 selectionType()==TreeItem::MapCenter ||
4270 selectionType()==TreeItem::Image
4274 QPointF rp(bo->getRelPos());
4278 QString ps=qpointfToString (bo->getRelPos());
4279 QString s=getSelectString(bo);
4282 s, "moveRel "+qpointfToString(to),
4283 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4284 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4286 bo->updateLinkGeometry();
4287 emitSelectionChanged();
4294 void VymModel::animate()
4296 animationTimer->stop();
4299 while (i<animObjList.size() )
4301 bo=(BranchObj*)animObjList.at(i);
4306 animObjList.removeAt(i);
4313 QItemSelection sel=selModel->selection();
4314 emit (selectionChanged(sel,sel));
4317 if (!animObjList.isEmpty()) animationTimer->start();
4321 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4323 if (bo && bo->getTreeItem()->depth()>0)
4326 ap.setStart (start);
4328 ap.setTicks (animationTicks);
4329 ap.setAnimated (true);
4330 bo->setAnimation (ap);
4331 animObjList.append( bo );
4332 animationTimer->setSingleShot (true);
4333 animationTimer->start(animationInterval);
4337 void VymModel::stopAnimation (MapObj *mo)
4339 int i=animObjList.indexOf(mo);
4341 animObjList.removeAt (i);
4344 void VymModel::sendSelection()
4346 if (netstate!=Server) return;
4347 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4350 void VymModel::newServer()
4354 tcpServer = new QTcpServer(this);
4355 if (!tcpServer->listen(QHostAddress::Any,port)) {
4356 QMessageBox::critical(NULL, "vym server",
4357 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4358 //FIXME-3 needed? we are no widget any longer... close();
4361 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4363 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4366 void VymModel::connectToServer()
4369 server="salam.suse.de";
4371 clientSocket = new QTcpSocket (this);
4372 clientSocket->abort();
4373 clientSocket->connectToHost(server ,port);
4374 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4375 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4376 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4378 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4383 void VymModel::newClient()
4385 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4386 connect(newClient, SIGNAL(disconnected()),
4387 newClient, SLOT(deleteLater()));
4389 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4391 clientList.append (newClient);
4395 void VymModel::sendData(const QString &s)
4397 if (clientList.size()==0) return;
4399 // Create bytearray to send
4401 QDataStream out(&block, QIODevice::WriteOnly);
4402 out.setVersion(QDataStream::Qt_4_0);
4404 // Reserve some space for blocksize
4407 // Write sendCounter
4408 out << sendCounter++;
4413 // Go back and write blocksize so far
4414 out.device()->seek(0);
4415 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4419 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4421 for (int i=0; i<clientList.size(); ++i)
4423 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4424 clientList.at(i)->write (block);
4428 void VymModel::readData ()
4430 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4433 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4437 QDataStream in(clientSocket);
4438 in.setVersion(QDataStream::Qt_4_0);
4446 cout << " t="<<qPrintable (t)<<endl;
4452 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4454 switch (socketError) {
4455 case QAbstractSocket::RemoteHostClosedError:
4457 case QAbstractSocket::HostNotFoundError:
4458 QMessageBox::information(NULL, vymName +" Network client",
4459 "The host was not found. Please check the "
4460 "host name and port settings.");
4462 case QAbstractSocket::ConnectionRefusedError:
4463 QMessageBox::information(NULL, vymName + " Network client",
4464 "The connection was refused by the peer. "
4465 "Make sure the fortune server is running, "
4466 "and check that the host name and port "
4467 "settings are correct.");
4470 QMessageBox::information(NULL, vymName + " Network client",
4471 QString("The following error occurred: %1.")
4472 .arg(clientSocket->errorString()));
4477 QDBusVariant VymModel::query (const QString &query)
4479 TreeItem *selti=getSelectedItem();
4481 return QDBusVariant (selti->getHeading());
4483 return QDBusVariant ("Nothing selected.");
4487 void VymModel::selectMapSelectionColor()
4489 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4490 setSelectionColor (col);
4493 void VymModel::setSelectionColorInt (QColor col)
4495 if ( !col.isValid() ) return;
4497 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4498 QString("setSelectionColor (%1)").arg(col.name()),
4499 QString("Set color of selection box to %1").arg(col.name())
4502 mapEditor->setSelectionColor (col);
4506 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4508 cout << "VymModel::changeSelection (";
4509 if (!newsel.indexes().isEmpty() )
4510 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4512 if (!oldsel.indexes().isEmpty() )
4513 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4518 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4522 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4524 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4525 emitShowSelection();
4529 void VymModel::emitSelectionChanged()
4531 QItemSelection newsel=selModel->selection();
4532 emitSelectionChanged (newsel);
4535 void VymModel::setSelectionColor(QColor col)
4537 if ( !col.isValid() ) return;
4539 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4540 QString("setSelectionColor (%1)").arg(col.name()),
4541 QString("Set color of selection box to %1").arg(col.name())
4543 setSelectionColorInt (col);
4546 QColor VymModel::getSelectionColor()
4548 return mapEditor->getSelectionColor();
4551 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4554 for (int i=0;i<rootItem->childCount();i++)
4555 rootItem->child(i)->setHideTmp (mode);
4557 // FIXME-3 needed? scene()->update();
4560 //////////////////////////////////////////////
4561 // Selection related
4562 //////////////////////////////////////////////
4564 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4569 QItemSelectionModel* VymModel::getSelectionModel()
4574 void VymModel::setSelectionBlocked (bool b)
4579 bool VymModel::isSelectionBlocked()
4581 return selectionBlocked;
4584 bool VymModel::select ()
4586 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4589 bool VymModel::select (const QString &s)
4591 TreeItem *ti=findBySelectString(s);
4601 bool VymModel::select (LinkableMapObj *lmo)
4603 QItemSelection oldsel=selModel->selection();
4606 return select (lmo->getTreeItem() );
4611 bool VymModel::select (TreeItem *ti)
4613 if (ti) return select (index(ti));
4617 bool VymModel::select (const QModelIndex &index)
4619 if (index.isValid() )
4621 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4622 getSelectedItem()->setLastSelectedBranch();
4628 void VymModel::unselect()
4630 lastSelectString=getSelectString();
4631 selModel->clearSelection();
4634 void VymModel::reselect()
4636 select (lastSelectString);
4639 void VymModel::emitShowSelection()
4641 if (!blockReposition)
4642 emit (showSelection() );
4645 void VymModel::emitNoteHasChanged (TreeItem *ti)
4647 QModelIndex ix=index(ti);
4648 emit (noteHasChanged (ix) );
4651 void VymModel::emitDataHasChanged (TreeItem *ti)
4653 QModelIndex ix=index(ti);
4654 emit (dataChanged (ix,ix) );
4658 //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4661 if (selection.select(lmo))
4663 //emitSelectionChanged();
4667 void VymModel::selectInt (TreeItem *ti)
4669 if (selection.select(lmo))
4671 //emitSelectionChanged();
4676 void VymModel::selectNextBranchInt()
4678 BranchItem *bi=getSelectedBranchItem();
4681 TreeItem *pi=bi->parent();
4685 if (i<pi->branchCount() )
4687 // select previous branch with same parent
4689 select (pi->getBranchNum(i));
4697 void VymModel::selectPrevBranchInt()
4700 BranchItem *bi=getSelectedBranchItem();
4703 BranchItem *pi=(BranchItem*)bi->parent();
4709 // select previous branch with same parent
4710 bi=pi->getBranchNum(i-1);
4715 while (bi->branchCount() >0)
4716 bi=bi->getLastBranch();
4719 // Try to select last branch in parent pi2 previous to own parent pi
4721 TreeItem *pi2=pi->parent();
4732 void VymModel::selectAboveBranchInt()
4734 BranchItem *bi=getSelectedBranchItem();
4737 BranchItem *newbi=NULL;
4738 BranchItem *pi=(BranchItem*)bi->parent();
4742 // goto previous branch with same parent
4743 newbi=pi->getBranchNum(i-1);
4744 while (newbi->branchCount() >0 )
4745 newbi=newbi->getLastBranch();
4749 if (newbi==rootItem)
4750 // already at top branch (resp. mapcenter)
4756 void VymModel::selectBelowBranchInt()
4758 BranchItem *bi=getSelectedBranchItem();
4761 BranchItem *newbi=NULL;
4763 if (bi->branchCount() >0)
4764 newbi=bi->getFirstBranch();
4771 pi=(BranchItem*)bi->parent();
4773 if (pi->branchCount()-1 > i)
4775 newbi=(BranchItem*)pi->getBranchNum(i+1);
4780 // look for siblings of myself
4781 // or parent, or parent of parent...
4792 void VymModel::selectUpperBranch()
4794 BranchItem *bi=getSelectedBranchItem();
4795 if (bi && bi->isBranchLikeType())
4796 selectAboveBranchInt();
4799 void VymModel::selectLowerBranch()
4801 BranchItem *bi=getSelectedBranchItem();
4802 if (bi && bi->isBranchLikeType())
4803 selectBelowBranchInt();
4807 void VymModel::selectLeftBranch()
4809 QItemSelection oldsel=selModel->selection();
4812 BranchItem *selbi=getSelectedBranchItem();
4813 TreeItem::Type type=selbi->getType();
4816 if (type == TreeItem::MapCenter)
4818 QModelIndex ix=index(selbi);
4819 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4822 par=(BranchItem*)selbi->parent();
4823 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
4826 if (type == TreeItem::Branch ||
4827 type == TreeItem::Image)
4829 QModelIndex ix=index (selbi->parent());
4830 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4835 if (type == TreeItem::Branch )
4837 selectLastSelectedBranch();
4845 void VymModel::selectRightBranch()
4847 QItemSelection oldsel=selModel->selection();
4850 BranchItem *selbi=getSelectedBranchItem();
4851 TreeItem::Type type=selbi->getType();
4854 if (type==TreeItem::MapCenter)
4856 QModelIndex ix=index(selbi);
4857 selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
4860 par=(BranchItem*)selbi->parent();
4861 if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
4864 if ( type== TreeItem::Branch )
4866 selectLastSelectedBranch();
4872 if (type == TreeItem::Branch ||
4873 type == TreeItem::Image)
4875 QModelIndex ix=index(selbi->parent());
4876 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4883 void VymModel::selectFirstBranch()
4885 TreeItem *ti=getSelectedBranchItem();
4888 TreeItem *par=ti->parent();
4890 TreeItem *ti2=par->getFirstBranch();
4893 emitSelectionChanged();
4898 void VymModel::selectLastBranch()
4900 TreeItem *ti=getSelectedBranchItem();
4903 TreeItem *par=ti->parent();
4905 TreeItem *ti2=par->getLastBranch();
4908 emitSelectionChanged();
4913 void VymModel::selectLastSelectedBranch()
4915 TreeItem *ti=getSelectedBranchItem();
4918 ti=ti->getLastSelectedBranch();
4919 if (ti) select (ti);
4923 void VymModel::selectParent()
4925 TreeItem *ti=getSelectedItem();
4932 emitSelectionChanged();
4936 TreeItem::Type VymModel::selectionType()
4938 QModelIndexList list=selModel->selectedIndexes();
4939 if (list.isEmpty()) return TreeItem::Undefined;
4940 TreeItem *ti = getItem (list.first() );
4941 return ti->getType();
4945 LinkableMapObj* VymModel::getSelectedLMO()
4947 QModelIndexList list=selModel->selectedIndexes();
4948 if (!list.isEmpty() )
4950 TreeItem *ti = getItem (list.first() );
4951 TreeItem::Type type=ti->getType();
4952 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4953 return ((MapItem*)ti)->getLMO();
4958 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4960 TreeItem *ti = getSelectedBranchItem();
4962 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4967 BranchItem* VymModel::getSelectedBranchItem()
4969 QModelIndexList list=selModel->selectedIndexes();
4970 if (!list.isEmpty() )
4972 TreeItem *ti = getItem (list.first() );
4973 TreeItem::Type type=ti->getType();
4974 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4975 return (BranchItem*)ti;
4980 TreeItem* VymModel::getSelectedItem()
4982 QModelIndexList list=selModel->selectedIndexes();
4983 if (!list.isEmpty() )
4984 return getItem (list.first() );
4989 QModelIndex VymModel::getSelectedIndex()
4991 QModelIndexList list=selModel->selectedIndexes();
4992 if (list.isEmpty() )
4993 return QModelIndex();
4995 return list.first();
4998 ImageItem* VymModel::getSelectedImageItem()
5000 QModelIndexList list=selModel->selectedIndexes();
5001 if (!list.isEmpty())
5003 TreeItem *ti=getItem (list.first());
5004 if (ti && ti->getType()==TreeItem::Image)
5005 return (ImageItem*)ti;
5010 QString VymModel::getSelectString ()
5012 return getSelectString (getSelectedItem());
5015 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
5017 if (!lmo) return QString();
5018 return getSelectString (lmo->getTreeItem() );
5021 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
5025 switch (ti->getType())
5027 case TreeItem::MapCenter: s="mc:"; break;
5028 case TreeItem::Branch: s="bo:";break;
5029 case TreeItem::Image: s="fi:";break;
5032 s= s + QString("%1").arg(ti->num());
5034 // call myself recursively
5035 s= getSelectString(ti->parent()) +","+s;