1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
18 #include "warningdialog.h"
19 #include "xml-freemind.h"
25 extern Main *mainWindow;
26 extern QDBusConnection dbusConnection;
28 extern Settings settings;
29 extern QString tmpVymDir;
31 extern TextEditor *textEditor;
32 extern FlagRow *standardFlagsMaster;
34 extern QString clipboardDir;
35 extern QString clipboardFile;
36 extern bool clipboardEmpty;
38 extern ImageIO imageIO;
40 extern QString vymName;
41 extern QString vymVersion;
42 extern QDir vymBaseDir;
44 extern QDir lastImageDir;
45 extern QDir lastFileDir;
47 extern Settings settings;
51 int VymModel::mapNum=0; // make instance
55 // cout << "Const VymModel\n";
57 rootItem->setModel (this);
63 cout << "Destr VymModel\n";
64 autosaveTimer->stop();
65 fileChangedTimer->stop();
69 void VymModel::clear()
71 selModel->clearSelection();
73 //QModelIndex ri=index(rootItem);
74 //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
77 void VymModel::init ()
79 // We should have at least one map center to start with
80 // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
85 // Also no scene yet (should not be needed anyway) FIXME-3 VM
98 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
99 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
100 mainWindow->updateHistory (undoSet);
103 makeTmpDirectories();
108 fileName=tr("unnamed");
110 blockReposition=false;
111 blockSaveState=false;
113 autosaveTimer=new QTimer (this);
114 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
116 fileChangedTimer=new QTimer (this);
117 fileChangedTimer->start(3000);
118 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
123 selectionBlocked=false;
130 // animations // FIXME-3 switch to new animation system
131 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
132 animationTicks=settings.readNumEntry("/animation/ticks",10);
133 animationInterval=settings.readNumEntry("/animation/interval",50);
135 animationTimer=new QTimer (this);
136 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
139 defLinkColor=QColor (0,0,255);
140 defXLinkColor=QColor (180,180,180);
141 linkcolorhint=LinkableMapObj::DefaultColor;
142 linkstyle=LinkableMapObj::PolyParabel;
144 defXLinkColor=QColor (230,230,230);
146 hidemode=TreeItem::HideNone;
152 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
155 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
156 //adaptor->setModel (this);
157 //connection.registerObject("/Car", car);
158 dbusConnection.registerService("org.insilmaril.VymModel");
159 dbusConnection.sessionBus().registerObject ("/Object1",this);
162 void VymModel::makeTmpDirectories()
164 // Create unique temporary directories
165 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
166 histPath = tmpMapDir+"/history";
172 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
177 bool VymModel::isRepositionBlocked()
179 return blockReposition;
182 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
184 //cout << "VM::updateActions \n";
185 // Tell mainwindow to update states of actions
186 mainWindow->updateActions();
191 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
193 // tmpdir temporary directory to which data will be written
194 // prefix mapname, which will be appended to images etc.
195 // writeflags Only write flags for "real" save of map, not undo
196 // offset offset of bbox of whole map in scene.
197 // Needed for XML export
206 case LinkableMapObj::Line:
209 case LinkableMapObj::Parabel:
212 case LinkableMapObj::PolyLine:
216 ls="StylePolyParabel";
220 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
222 if (linkcolorhint==LinkableMapObj::HeadingColor)
223 colhint=xml.attribut("linkColorHint","HeadingColor");
225 QString mapAttr=xml.attribut("version",vymVersion);
227 mapAttr+= xml.attribut("author",author) +
228 xml.attribut("comment",comment) +
229 xml.attribut("date",getDate()) +
230 xml.attribut("branchCount", QString().number(branchCount())) +
231 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
232 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
233 xml.attribut("linkStyle", ls ) +
234 xml.attribut("linkColor", defLinkColor.name() ) +
235 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
236 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
238 s+=xml.beginElement("vymmap",mapAttr);
241 // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
242 standardFlagsMaster->resetUsedCounter();
244 // Reset the counters before saving
245 // TODO constr. of FIO creates lots of objects, better do this in some other way...
246 ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
248 // Build xml recursivly
249 if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
250 // Save all mapcenters as complete map, if saveSel not set
251 s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
254 if (saveSel->isBranchLikeType())
256 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
257 //FIXME-2 else if (saveSel->getType()==TreeItem::Image)
259 //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
262 // Save local settings
263 s+=settings.getDataXML (destPath);
266 if (getSelectedItem() && !saveSel )
267 s+=xml.valueElement("select",getSelectString());
270 s+=xml.endElement("vymmap");
272 //cout << s.toStdString() << endl;
274 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
278 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
282 for (int i=0; i<rootItem->branchCount(); i++)
283 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
287 void VymModel::setFilePath(QString fpath, QString destname)
289 if (fpath.isEmpty() || fpath=="")
296 filePath=fpath; // becomes absolute path
297 fileName=fpath; // gets stripped of path
298 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
300 // If fpath is not an absolute path, complete it
301 filePath=QDir(fpath).absPath();
302 fileDir=filePath.left (1+filePath.findRev ("/"));
304 // Set short name, too. Search from behind:
305 int i=fileName.findRev("/");
306 if (i>=0) fileName=fileName.remove (0,i+1);
308 // Forget the .vym (or .xml) for name of map
309 mapName=fileName.left(fileName.findRev(".",-1,true) );
313 void VymModel::setFilePath(QString fpath)
315 setFilePath (fpath,fpath);
318 QString VymModel::getFilePath()
323 QString VymModel::getFileName()
328 QString VymModel::getMapName()
333 QString VymModel::getDestPath()
338 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
340 ErrorCode err=success;
342 parseBaseHandler *handler;
346 case VymMap: handler=new parseVYMHandler; break;
347 case FreemindMap : handler=new parseFreemindHandler; break;
349 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
350 "Unknown FileType in VymModel::load()");
354 bool zipped_org=zipped;
358 selModel->clearSelection();
359 // FIXME-2 VM not needed??? model->setMapEditor(this);
360 // (map state is set later at end of load...)
363 BranchItem *bi=getSelectedBranch();
364 if (!bi) return aborted;
365 if (lmode==ImportAdd)
366 saveStateChangingPart(
369 QString("addMapInsert (%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 saveStateChangingPart(
375 QString("addMapReplace(%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
380 // Create temporary directory for packing
382 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
385 QMessageBox::critical( 0, tr( "Critical Load Error" ),
386 tr("Couldn't create temporary directory before load\n"));
391 err=unzipDir (tmpZipDir,fname);
401 // Look for mapname.xml
402 xmlfile= fname.left(fname.findRev(".",-1,true));
403 xmlfile=xmlfile.section( '/', -1 );
404 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
405 if (!mfile.exists() )
407 // mapname.xml does not exist, well,
408 // maybe someone renamed the mapname.vym file...
409 // Try to find any .xml in the toplevel
410 // directory of the .vym file
411 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
412 if (flist.count()==1)
414 // Only one entry, take this one
415 xmlfile=tmpZipDir + "/"+flist.first();
418 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
419 *it=tmpZipDir + "/" + *it;
420 // TODO Multiple entries, load all (but only the first one into this ME)
421 //mainWindow->fileLoadFromTmp (flist);
422 //returnCode=1; // Silently forget this attempt to load
423 qWarning ("MainWindow::load (fn) multimap found...");
426 if (flist.isEmpty() )
428 QMessageBox::critical( 0, tr( "Critical Load Error" ),
429 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
432 } //file doesn't exist
434 xmlfile=mfile.name();
437 QFile file( xmlfile);
439 // I am paranoid: file should exist anyway
440 // according to check in mainwindow.
443 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
444 tr(QString("Couldn't open map %1").arg(file.name())));
448 bool blockSaveStateOrg=blockSaveState;
449 blockReposition=true;
451 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
452 QXmlInputSource source( file);
453 QXmlSimpleReader reader;
454 reader.setContentHandler( handler );
455 reader.setErrorHandler( handler );
456 handler->setModel ( this);
459 // We need to set the tmpDir in order to load files with rel. path
464 tmpdir=fname.left(fname.findRev("/",-1));
465 handler->setTmpDir (tmpdir);
466 handler->setInputFile (file.name());
467 handler->setLoadMode (lmode);
468 bool ok = reader.parse( source );
469 blockReposition=false;
470 blockSaveState=blockSaveStateOrg;
471 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
475 reposition(); // FIXME-2 VM reposition the view instead...
476 emitSelectionChanged();
482 autosaveTimer->stop();
485 // Reset timestamp to check for later updates of file
486 fileChangedTime=QFileInfo (destPath).lastModified();
489 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
490 tr( handler->errorProtocol() ) );
492 // Still return "success": the map maybe at least
493 // partially read by the parser
498 removeDir (QDir(tmpZipDir));
500 // Restore original zip state
507 ErrorCode VymModel::save (const SaveMode &savemode)
511 QString safeFilePath;
513 ErrorCode err=success;
517 mapFileName=mapName+".xml";
519 // use name given by user, even if he chooses .doc
520 mapFileName=fileName;
522 // Look, if we should zip the data:
525 QMessageBox mb( vymName,
526 tr("The map %1\ndid not use the compressed "
527 "vym file format.\nWriting it uncompressed will also write images \n"
528 "and flags and thus may overwrite files in the "
529 "given directory\n\nDo you want to write the map").arg(filePath),
530 QMessageBox::Warning,
531 QMessageBox::Yes | QMessageBox::Default,
533 QMessageBox::Cancel | QMessageBox::Escape);
534 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
535 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
536 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
539 case QMessageBox::Yes:
540 // save compressed (default file format)
543 case QMessageBox::No:
547 case QMessageBox::Cancel:
554 // First backup existing file, we
555 // don't want to add to old zip archives
559 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
561 QString backupFileName(destPath + "~");
562 QFile backupFile(backupFileName);
563 if (backupFile.exists() && !backupFile.remove())
565 QMessageBox::warning(0, tr("Save Error"),
566 tr("%1\ncould not be removed before saving").arg(backupFileName));
568 else if (!f.rename(backupFileName))
570 QMessageBox::warning(0, tr("Save Error"),
571 tr("%1\ncould not be renamed before saving").arg(destPath));
578 // Create temporary directory for packing
580 tmpZipDir=makeTmpDir (ok,"vym-zip");
583 QMessageBox::critical( 0, tr( "Critical Load Error" ),
584 tr("Couldn't create temporary directory before save\n"));
588 safeFilePath=filePath;
589 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
592 // Create mapName and fileDir
593 makeSubDirs (fileDir);
596 if (savemode==CompleteMap || selModel->selection().isEmpty())
599 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
602 autosaveTimer->stop();
607 if (selectionType()==TreeItem::Image)
610 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
611 // TODO take care of multiselections
614 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
617 qWarning ("ME::saveStringToDisk failed!");
623 if (err==success) err=zipDir (tmpZipDir,destPath);
626 removeDir (QDir(tmpZipDir));
628 // Restore original filepath outside of tmp zip dir
629 setFilePath (safeFilePath);
633 fileChangedTime=QFileInfo (destPath).lastModified();
637 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree
639 QString pathDir=path.left(path.findRev("/"));
645 // We need to parse saved XML data
646 parseVYMHandler handler;
647 QXmlInputSource source( file);
648 QXmlSimpleReader reader;
649 reader.setContentHandler( &handler );
650 reader.setErrorHandler( &handler );
651 handler.setModel ( this);
652 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
653 if (undoSel.isEmpty())
657 handler.setLoadMode (NewMap);
661 handler.setLoadMode (ImportReplace);
663 blockReposition=true;
664 bool ok = reader.parse( source );
665 blockReposition=false;
668 // This should never ever happen
669 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
670 handler.errorProtocol());
673 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
676 void VymModel::addMapInsertInt (const QString &path, int pos)
678 /* FIXME-2 addMapInsertInt not ported yet
679 BranchObj *sel=getSelectedBranch();
682 QString pathDir=path.left(path.findRev("/"));
688 // We need to parse saved XML data
689 parseVYMHandler handler;
690 QXmlInputSource source( file);
691 QXmlSimpleReader reader;
692 reader.setContentHandler( &handler );
693 reader.setErrorHandler( &handler );
694 handler.setModel (this);
695 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
696 handler.setLoadMode (ImportAdd);
697 blockReposition=true;
698 bool ok = reader.parse( source );
699 blockReposition=false;
702 // This should never ever happen
703 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
704 handler.errorProtocol());
706 if (sel->getDepth()>0)
707 sel->getLastBranch()->linkTo (sel,pos);
709 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
714 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
716 ImageItem *ii=createImage(dst);
726 void VymModel::loadFloatImage ()
728 BranchItem *selbi=getSelectedBranch();
732 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
733 fd->setMode (Q3FileDialog::ExistingFiles);
734 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
735 ImagePreview *p =new ImagePreview (fd);
736 fd->setContentsPreviewEnabled( TRUE );
737 fd->setContentsPreview( p, p );
738 fd->setPreviewMode( Q3FileDialog::Contents );
739 fd->setCaption(vymName+" - " +tr("Load image"));
740 fd->setDir (lastImageDir);
743 if ( fd->exec() == QDialog::Accepted )
745 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
746 lastImageDir=QDir (fd->dirPath());
749 for (int j=0; j<fd->selectedFiles().count(); j++)
751 s=fd->selectedFiles().at(j);
752 ii=loadFloatImageInt (selbi,s);
753 //FIXME-3 check savestate for loadImage
759 QString ("loadImage (%1)").arg(s ),
760 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
763 // TODO loadFIO error handling
764 qWarning ("Failed to load "+s);
772 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
777 void VymModel::saveFloatImage ()
779 ImageItem *ii=getSelectedImage();
782 QFileDialog *fd=new QFileDialog( NULL);
783 fd->setFilters (imageIO.getFilters());
784 fd->setCaption(vymName+" - " +tr("Save image"));
785 fd->setFileMode( QFileDialog::AnyFile );
786 fd->setDirectory (lastImageDir);
787 // fd->setSelection (fio->getOriginalFilename());
791 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
793 fn=fd->selectedFiles().at(0);
794 if (QFile (fn).exists() )
796 QMessageBox mb( vymName,
797 tr("The file %1 exists already.\n"
798 "Do you want to overwrite it?").arg(fn),
799 QMessageBox::Warning,
800 QMessageBox::Yes | QMessageBox::Default,
801 QMessageBox::Cancel | QMessageBox::Escape,
802 QMessageBox::NoButton );
804 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
805 mb.setButtonText( QMessageBox::No, tr("Cancel"));
808 case QMessageBox::Yes:
811 case QMessageBox::Cancel:
818 saveFloatImageInt (ii,fd->selectedFilter(),fn );
825 void VymModel::importDirInt(BranchObj *dst, QDir d)
827 /* FIXME-2 importDirInt not ported yet
828 BranchObj *bo=getSelectedBranch();
831 // Traverse directories
832 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
833 QFileInfoList list = d.entryInfoList();
836 for (int i = 0; i < list.size(); ++i)
839 if (fi.fileName() != "." && fi.fileName() != ".." )
842 bo=dst->getLastBranch();
843 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
844 bi->setHeading (fi.fileName() ); // FIXME-3 check this
845 bo->setColor (QColor("blue"));
847 if ( !d.cd(fi.fileName()) )
848 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
851 // Recursively add subdirs
858 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
859 list = d.entryInfoList();
861 for (int i = 0; i < list.size(); ++i)
865 bo=dst->getLastBranch();
866 bo->setHeading (fi.fileName() );
867 bo->setColor (QColor("black"));
868 if (fi.fileName().right(4) == ".vym" )
869 bo->setVymLink (fi.filePath());
875 void VymModel::importDirInt (const QString &s) // FIXME-2
878 BranchObj *bo=getSelectedBranch();
881 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
889 void VymModel::importDir() //FIXME-2
892 BranchObj *bo=getSelectedBranch();
896 filters <<"VYM map (*.vym)";
897 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
898 fd->setMode (QFileDialog::DirectoryOnly);
899 fd->setFilters (filters);
900 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
904 if ( fd->exec() == QDialog::Accepted )
906 importDirInt (fd->selectedFile() );
908 //FIXME-3 VM needed? scene()->update();
915 void VymModel::autosave()
920 cout << "VymModel::autosave rejected due to missing filePath\n";
923 QDateTime now=QDateTime().currentDateTime();
925 // Disable autosave, while we have gone back in history
926 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
927 if (redosAvail>0) return;
929 // Also disable autosave for new map without filename
930 if (filePath.isEmpty()) return;
933 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
935 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
936 mainWindow->fileSave (this);
939 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
944 void VymModel::fileChanged()
946 // Check if file on disk has changed meanwhile
947 if (!filePath.isEmpty())
949 QDateTime tmod=QFileInfo (filePath).lastModified();
950 if (tmod>fileChangedTime)
952 // FIXME-2 VM switch to current mapeditor and finish lineedits...
953 QMessageBox mb( vymName,
954 tr("The file of the map on disk has changed:\n\n"
955 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
956 QMessageBox::Question,
958 QMessageBox::Cancel | QMessageBox::Default,
959 QMessageBox::NoButton );
961 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
962 mb.setButtonText( QMessageBox::No, tr("Ignore"));
965 case QMessageBox::Yes:
967 load (filePath,NewMap,fileType);
968 case QMessageBox::Cancel:
969 fileChangedTime=tmod; // allow autosave to overwrite newer file!
975 bool VymModel::isDefault()
980 void VymModel::makeDefault()
986 bool VymModel::hasChanged()
991 void VymModel::setChanged()
994 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
998 latestAddedItem=NULL;
1002 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1004 if (!lmo || !lmo->getTreeItem() ) return QString();
1005 return getObjectName (lmo->getTreeItem() );
1009 QString VymModel::getObjectName (TreeItem *ti)
1012 if (!ti) return QString("Error: NULL has no name!");
1014 if (s=="") s="unnamed";
1016 if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter??
1017 return QString("branch (%1)").arg(s);
1018 if (ti->getType()==TreeItem::Image)
1019 return QString ("image (%1)").arg(ti->getHeading());
1020 return QString("Unknown type has no name!");
1023 void VymModel::redo()
1025 // Can we undo at all?
1026 if (redosAvail<1) return;
1028 bool blockSaveStateOrg=blockSaveState;
1029 blockSaveState=true;
1033 if (undosAvail<stepsTotal) undosAvail++;
1035 if (curStep>stepsTotal) curStep=1;
1036 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1037 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1038 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1039 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1040 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1041 QString version=undoSet.readEntry ("/history/version");
1043 /* TODO Maybe check for version, if we save the history
1044 if (!checkVersion(version))
1045 QMessageBox::warning(0,tr("Warning"),
1046 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1049 // Find out current undo directory
1050 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1054 cout << "VymModel::redo() begin\n";
1055 cout << " undosAvail="<<undosAvail<<endl;
1056 cout << " redosAvail="<<redosAvail<<endl;
1057 cout << " curStep="<<curStep<<endl;
1058 cout << " ---------------------------"<<endl;
1059 cout << " comment="<<comment.toStdString()<<endl;
1060 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1061 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1062 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1063 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1064 cout << " ---------------------------"<<endl<<endl;
1067 // select object before redo
1068 if (!redoSelection.isEmpty())
1069 select (redoSelection);
1072 parseAtom (redoCommand);
1075 blockSaveState=blockSaveStateOrg;
1077 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1078 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1079 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1080 undoSet.writeSettings(histPath);
1082 mainWindow->updateHistory (undoSet);
1085 /* TODO remove testing
1086 cout << "ME::redo() end\n";
1087 cout << " undosAvail="<<undosAvail<<endl;
1088 cout << " redosAvail="<<redosAvail<<endl;
1089 cout << " curStep="<<curStep<<endl;
1090 cout << " ---------------------------"<<endl<<endl;
1096 bool VymModel::isRedoAvailable()
1098 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1104 void VymModel::undo()
1106 // Can we undo at all?
1107 if (undosAvail<1) return;
1109 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1111 bool blockSaveStateOrg=blockSaveState;
1112 blockSaveState=true;
1114 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1115 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1116 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1117 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1118 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1119 QString version=undoSet.readEntry ("/history/version");
1121 /* TODO Maybe check for version, if we save the history
1122 if (!checkVersion(version))
1123 QMessageBox::warning(0,tr("Warning"),
1124 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1127 // Find out current undo directory
1128 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1130 // select object before undo
1131 if (!undoSelection.isEmpty())
1132 select (undoSelection);
1136 cout << "VymModel::undo() begin\n";
1137 cout << " undosAvail="<<undosAvail<<endl;
1138 cout << " redosAvail="<<redosAvail<<endl;
1139 cout << " curStep="<<curStep<<endl;
1140 cout << " ---------------------------"<<endl;
1141 cout << " comment="<<comment.toStdString()<<endl;
1142 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1143 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1144 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1145 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1146 cout << " ---------------------------"<<endl<<endl;
1148 parseAtom (undoCommand);
1153 if (curStep<1) curStep=stepsTotal;
1157 blockSaveState=blockSaveStateOrg;
1158 /* TODO remove testing
1159 cout << "VymModel::undo() end\n";
1160 cout << " undosAvail="<<undosAvail<<endl;
1161 cout << " redosAvail="<<redosAvail<<endl;
1162 cout << " curStep="<<curStep<<endl;
1163 cout << " ---------------------------"<<endl<<endl;
1166 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1167 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1168 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1169 undoSet.writeSettings(histPath);
1171 mainWindow->updateHistory (undoSet);
1173 emitSelectionChanged();
1176 bool VymModel::isUndoAvailable()
1178 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1184 void VymModel::gotoHistoryStep (int i)
1186 // Restore variables
1187 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1188 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1190 if (i<0) i=undosAvail+redosAvail;
1192 // Clicking above current step makes us undo things
1195 for (int j=0; j<undosAvail-i; j++) undo();
1198 // Clicking below current step makes us redo things
1200 for (int j=undosAvail; j<i; j++)
1202 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1206 // And ignore clicking the current row ;-)
1210 QString VymModel::getHistoryPath()
1212 QString histName(QString("history-%1").arg(curStep));
1213 return (tmpMapDir+"/"+histName);
1216 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1218 sendData(redoCom); //FIXME-3 testing
1223 if (blockSaveState) return;
1225 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1227 // Find out current undo directory
1228 if (undosAvail<stepsTotal) undosAvail++;
1230 if (curStep>stepsTotal) curStep=1;
1232 QString backupXML="";
1233 QString histDir=getHistoryPath();
1234 QString bakMapPath=histDir+"/map.xml";
1236 // Create histDir if not available
1239 makeSubDirs (histDir);
1241 // Save depending on how much needs to be saved
1243 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1245 QString undoCommand="";
1246 if (savemode==UndoCommand)
1248 undoCommand=undoCom;
1250 else if (savemode==PartOfMap )
1252 undoCommand=undoCom;
1253 undoCommand.replace ("PATH",bakMapPath);
1257 if (!backupXML.isEmpty())
1258 // Write XML Data to disk
1259 saveStringToDisk (bakMapPath,backupXML);
1261 // We would have to save all actions in a tree, to keep track of
1262 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1265 // Write the current state to disk
1266 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1267 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1268 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1269 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1270 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1271 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1272 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1273 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1274 undoSet.setEntry (QString("/history/version"),vymVersion);
1275 undoSet.writeSettings(histPath);
1279 // TODO remove after testing
1280 //cout << " into="<< histPath.toStdString()<<endl;
1281 cout << " stepsTotal="<<stepsTotal<<
1282 ", undosAvail="<<undosAvail<<
1283 ", redosAvail="<<redosAvail<<
1284 ", curStep="<<curStep<<endl;
1285 cout << " ---------------------------"<<endl;
1286 cout << " comment="<<comment.toStdString()<<endl;
1287 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1288 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1289 cout << " redoCom="<<redoCom.toStdString()<<endl;
1290 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1291 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1292 cout << " ---------------------------"<<endl;
1295 mainWindow->updateHistory (undoSet);
1301 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1303 // save the selected part of the map, Undo will replace part of map
1304 QString undoSelection="";
1306 undoSelection=getSelectString(undoSel);
1308 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1309 QString redoSelection="";
1311 redoSelection=getSelectString(undoSel);
1313 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1316 saveState (PartOfMap,
1317 undoSelection, "addMapReplace (\"PATH\")",
1323 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1327 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1330 QString undoSelection=getSelectString (redoSel->parent() );
1331 QString redoSelection=getSelectString(redoSel);
1332 if (redoSel->getType()==TreeItem::Branch)
1334 // save the selected branch of the map, Undo will insert part of map
1335 saveState (PartOfMap,
1336 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1337 redoSelection, "delete ()",
1344 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1346 // "Normal" savestate: save commands, selections and comment
1347 // so just save commands for undo and redo
1348 // and use current selection
1350 QString redoSelection="";
1351 if (redoSel) redoSelection=getSelectString(redoSel);
1352 QString undoSelection="";
1353 if (undoSel) undoSelection=getSelectString(undoSel);
1355 saveState (UndoCommand,
1362 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1364 // "Normal" savestate: save commands, selections and comment
1365 // so just save commands for undo and redo
1366 // and use current selection
1367 saveState (UndoCommand,
1374 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1376 // "Normal" savestate applied to model (no selection needed):
1377 // save commands and comment
1378 saveState (UndoCommand,
1386 QGraphicsScene* VymModel::getScene ()
1391 TreeItem* VymModel::findBySelectString(QString s)
1393 if (s.isEmpty() ) return NULL;
1395 // Old maps don't have multiple mapcenters and don't save full path
1396 if (s.left(2) !="mc")
1399 QStringList parts=s.split (",");
1402 TreeItem *ti=rootItem;
1404 while (!parts.isEmpty() )
1406 typ=parts.first().left(2);
1407 n=parts.first().right(parts.first().length() - 3).toInt();
1408 parts.removeFirst();
1409 if (typ=="mc" || typ=="bo")
1410 ti=ti->getBranchNum (n);
1414 ti=ti->getImageNum (n);
1420 TreeItem* VymModel::findID (const QString &s)
1423 for (int i=0; i<rootItem->branchCount(); i++)
1425 ti=rootItem->getBranchNum(i)->findID (s);
1431 //////////////////////////////////////////////
1433 //////////////////////////////////////////////
1434 void VymModel::setVersion (const QString &s)
1439 void VymModel::setAuthor (const QString &s)
1442 QString ("setMapAuthor (\"%1\")").arg(author),
1443 QString ("setMapAuthor (\"%1\")").arg(s),
1444 QString ("Set author of map to \"%1\"").arg(s)
1449 QString VymModel::getAuthor()
1454 void VymModel::setComment (const QString &s)
1457 QString ("setMapComment (\"%1\")").arg(comment),
1458 QString ("setMapComment (\"%1\")").arg(s),
1459 QString ("Set comment of map")
1464 QString VymModel::getComment ()
1469 QString VymModel::getDate ()
1471 return QDate::currentDate().toString ("yyyy-MM-dd");
1474 int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time...
1477 BranchItem *cur=NULL;
1478 BranchItem *prev=NULL;
1488 void VymModel::setHeading(const QString &s)
1490 BranchItem *selbi=getSelectedBranch();
1495 "setHeading (\""+selbi->getHeading()+"\")",
1497 "setHeading (\""+s+"\")",
1498 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1499 selbi->setHeading(s );
1500 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 getSelectedBranch();
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=getSelectedBranch();
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=getSelectedBranch();
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=getSelectedBranch();
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=getSelectedBranch();
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=getSelectedBranch();
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=getSelectedBranch();
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=getSelectedBranch();
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)
1732 BranchItem *bi=getSelectedBranch();
1735 QString u= b ? "false" : "true";
1736 QString r=!b ? "false" : "true";
1740 QString("setIncludeImagesVertically (%1)").arg(u),
1742 QString("setIncludeImagesVertically (%1)").arg(r),
1743 QString("Include images vertically in %1").arg(getObjectName(bi))
1745 bi->setIncludeImagesVer(b);
1746 emitDataHasChanged ( bi);
1751 void VymModel::setIncludeImagesHor(bool b)
1753 BranchItem *bi=getSelectedBranch();
1756 QString u= b ? "false" : "true";
1757 QString r=!b ? "false" : "true";
1761 QString("setIncludeImagesHorizontally (%1)").arg(u),
1763 QString("setIncludeImagesHorizontally (%1)").arg(r),
1764 QString("Include images horizontally in %1").arg(getObjectName(bi))
1766 bi->setIncludeImagesHor(b);
1767 emitDataHasChanged ( bi);
1772 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1774 TreeItem *ti=getSelectedItem();
1775 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1777 QString u= b ? "false" : "true";
1778 QString r=!b ? "false" : "true";
1782 QString("setHideLinkUnselected (%1)").arg(u),
1784 QString("setHideLinkUnselected (%1)").arg(r),
1785 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1787 ((MapItem*)ti)->setHideLinkUnselected(b);
1791 void VymModel::setHideExport(bool b)
1793 TreeItem *ti=getSelectedItem();
1795 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1797 ti->setHideInExport (b);
1798 QString u= b ? "false" : "true";
1799 QString r=!b ? "false" : "true";
1803 QString ("setHideExport (%1)").arg(u),
1805 QString ("setHideExport (%1)").arg(r),
1806 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1808 emitDataHasChanged(ti);
1809 emitSelectionChanged();
1812 // emitSelectionChanged();
1813 // FIXME-3 VM needed? scene()->update();
1817 void VymModel::toggleHideExport()
1819 TreeItem *selti=getSelectedItem();
1821 setHideExport ( !selti->hideInExport() );
1825 void VymModel::copy()
1827 TreeItem *selti=getSelectedItem();
1829 (selti->getType() == TreeItem::Branch ||
1830 selti->getType() == TreeItem::MapCenter ||
1831 selti->getType() == TreeItem::Image ))
1833 if (redosAvail == 0)
1836 QString s=getSelectString(selti);
1837 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1838 curClipboard=curStep;
1841 // Copy also to global clipboard, because we are at last step in history
1842 QString bakMapName(QString("history-%1").arg(curStep));
1843 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1844 copyDir (bakMapDir,clipboardDir );
1846 clipboardEmpty=false;
1852 void VymModel::pasteNoSave(const int &n)
1854 bool old=blockSaveState;
1855 blockSaveState=true;
1856 bool zippedOrg=zipped;
1857 if (redosAvail > 0 || n!=0)
1859 // Use the "historical" buffer
1860 QString bakMapName(QString("history-%1").arg(n));
1861 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1862 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1864 // Use the global buffer
1865 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1870 void VymModel::paste()
1872 BranchItem *selbi=getSelectedBranch();
1875 saveStateChangingPart(
1878 QString ("paste (%1)").arg(curClipboard),
1879 QString("Paste to %1").arg( getObjectName(selbi))
1886 void VymModel::cut()
1888 TreeItem *selti=getSelectedItem();
1889 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
1897 void VymModel::moveUp()
1899 BranchItem *selbi=getSelectedBranch();
1902 if (!selbi->canMoveUp()) return;
1903 QString oldsel=getSelectString();
1904 if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
1906 saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
1910 void VymModel::moveDown()
1912 BranchItem *selbi=getSelectedBranch();
1915 if (!selbi->canMoveDown()) return;
1916 QString oldsel=getSelectString();
1917 if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
1919 saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
1923 void VymModel::sortChildren() // FIXME-2 not implemented yet
1926 BranchObj* bo=getSelectedBranch();
1929 if(treeItem->branchCount()>1)
1931 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1934 emitShowSelection();
1940 BranchItem* VymModel::createMapCenter()
1942 BranchItem *newbi=addMapCenter (QPointF (0,0) );
1946 BranchItem* VymModel::createBranch(BranchItem *dst)
1949 return addNewBranchInt (dst,-2);
1954 ImageItem* VymModel::createImage(BranchItem *dst)
1961 QList<QVariant> cData;
1962 cData << "new" << "undef"<<"undef";
1964 ImageItem *newii=new ImageItem(cData) ;
1965 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
1967 emit (layoutAboutToBeChanged() );
1970 n=dst->getRowNumAppend(newii);
1971 beginInsertRows (parix,n,n+1);
1972 dst->appendChild (newii);
1975 emit (layoutChanged() );
1977 // save scroll state. If scrolled, automatically select
1978 // new branch in order to tmp unscroll parent...
1979 newii->createMapObj(mapScene);
1986 AttributeItem* VymModel::addAttribute()
1988 TreeItem *selti=getSelectedItem();
1991 QList<QVariant> cData;
1992 cData << "new attribute" << "undef"<<"undef";
1993 AttributeItem *a=new AttributeItem (cData);
1995 emit (layoutAboutToBeChanged() );
1997 QModelIndex parix=index(selti);
1998 int n=selti->getRowNumAppend (a);
1999 beginInsertRows (parix,n,n+1);
2000 selti->appendChild (a);
2003 emit (layoutChanged() );
2011 BranchItem* VymModel::addMapCenter ()
2013 BranchItem *bi=addMapCenter (contextPos);
2015 emitShowSelection();
2020 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2021 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2026 BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
2027 // createMapCenter could then probably be merged with createBranch
2031 QModelIndex parix=index(rootItem);
2033 int n=rootItem->branchCount();
2035 emit (layoutAboutToBeChanged() );
2036 beginInsertRows (parix,n,n+1);
2038 QList<QVariant> cData;
2039 cData << "VM:addMapCenter" << "undef"<<"undef";
2040 BranchItem *newbi=new BranchItem (cData);
2041 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2042 rootItem->appendChild (newbi);
2045 emit (layoutChanged() );
2048 newbi->setPositionMode (MapItem::Absolute);
2049 newbi->createMapObj(mapScene);
2054 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2056 // Depending on pos:
2057 // -3 insert in children of parent above selection
2058 // -2 add branch to selection
2059 // -1 insert in children of parent below selection
2060 // 0..n insert in children of parent at pos
2063 QList<QVariant> cData;
2064 cData << "new" << "undef"<<"undef";
2069 BranchItem *newbi=new BranchItem (cData);
2070 newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2072 emit (layoutAboutToBeChanged() );
2078 n=parbi->getRowNumAppend (newbi);
2079 beginInsertRows (parix,n,n+1);
2080 parbi->appendChild (newbi);
2082 }else if (num==-1 || num==-3)
2084 // insert below selection
2085 parbi=(BranchItem*)dst->parent();
2088 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2089 beginInsertRows (parix,n,n);
2090 parbi->insertBranch(n,newbi);
2093 emit (layoutChanged() );
2095 // save scroll state. If scrolled, automatically select
2096 // new branch in order to tmp unscroll parent...
2097 newbi->createMapObj(mapScene);
2102 BranchItem* VymModel::addNewBranch(int pos)
2104 // Different meaning than num in addNewBranchInt!
2108 BranchItem *newbi=NULL;
2109 BranchItem *selbi=getSelectedBranch();
2113 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2115 newbi=addNewBranchInt (selbi,pos-2);
2123 QString ("addBranch (%1)").arg(pos),
2124 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2127 // emitSelectionChanged(); FIXME-3
2128 latestAddedItem=newbi;
2129 // In Network mode, the client needs to know where the new branch is,
2130 // so we have to pass on this information via saveState.
2131 // TODO: Get rid of this positioning workaround
2132 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2133 sendData ("selectLatestAdded ()");
2134 sendData (QString("move %1").arg(ps));
2143 BranchItem* VymModel::addNewBranchBefore()
2145 BranchItem *newbi=NULL;
2146 BranchItem *selbi=getSelectedBranch();
2147 if (selbi && selbi->getType()==TreeItem::Branch)
2148 // We accept no MapCenter here, so we _have_ a parent
2150 //QPointF p=bo->getRelPos();
2153 // add below selection
2154 newbi=addNewBranchInt (selbi,-1);
2158 //newbi->move2RelPos (p);
2160 // Move selection to new branch
2161 relinkBranch (selbi,newbi,0);
2163 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2164 QString ("Add branch before %1").arg(getObjectName(selbi)));
2166 // FIXME-3 needed? reposition();
2167 // emitSelectionChanged(); FIXME-3
2173 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2177 if (branch->depth()==0)
2179 cout <<"VM::relinkBranch d=0 for "<<branch->getHeadingStd()<<endl;
2181 emit (layoutAboutToBeChanged() );
2182 BranchItem *branchpi=(BranchItem*)branch->parent();
2183 // Remove at current position
2184 int n=branch->childNum();
2185 beginRemoveRows (index(branchpi),n,n);
2186 branchpi->removeChild (n);
2189 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2191 // Append as last branch to dst
2192 if (dst->branchCount()==0)
2195 n=dst->getFirstBranch()->childNumber();
2196 beginInsertRows (index(dst),n+pos,n+pos);
2197 dst->insertBranch (pos,branch);
2200 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2201 branch->updateStyles();
2203 emit (layoutChanged() );
2204 reposition(); // both for moveUp/Down and relinking
2205 if (dst->isScrolled() )
2208 branch->updateVisibility();
2217 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2221 emit (layoutAboutToBeChanged() );
2223 BranchItem *pi=(BranchItem*)(image->parent());
2224 QString oldParString=getSelectString (pi);
2225 // Remove at current position
2226 int n=image->childNum();
2227 beginRemoveRows (index(pi),n,n);
2228 pi->removeChild (n);
2232 QModelIndex dstix=index(dst);
2233 n=dst->getRowNumAppend (image);
2234 beginInsertRows (dstix,n,n+1);
2235 dst->appendChild (image);
2238 // Set new parent also for lmo
2239 if (image->getLMO() && dst->getLMO() )
2240 image->getLMO()->setParObj (dst->getLMO() );
2242 emit (layoutChanged() );
2245 QString("relinkTo (\"%1\")").arg(oldParString),
2247 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2248 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2254 void VymModel::deleteSelection() // FIXME-2 include fix for deleted mapcenters from 1.12.4
2256 BranchItem *selbi=getSelectedBranch();
2258 if (selbi && selbi->isBranchLikeType() )
2261 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2263 TreeItem *pi=deleteItem (selbi);
2267 emitShowSelection();
2271 TreeItem *ti=getSelectedImage();
2272 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2274 TreeItem *pi=ti->parent();
2275 saveStateChangingPart(
2279 QString("Delete %1").arg(getObjectName(ti))
2283 emitDataHasChanged (pi);
2286 emitShowSelection();
2291 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2294 BranchItem *selbi=getSelectedBranch();
2298 // Don't use this on mapcenter
2299 if (selbi->depth()<2) return;
2301 pi=(BranchItem*)(selbi->parent());
2302 // Check if we have childs at all to keep
2303 if (selbi->branchCount()==0)
2310 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2311 saveStateChangingPart(
2314 "deleteKeepChildren ()",
2315 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2318 QString sel=getSelectString(selbi);
2320 int pos=selbi->num();
2321 BranchItem *bi=selbi->getFirstBranch();
2324 relinkBranch (bi,pi,pos);
2325 bi=selbi->getFirstBranch();
2331 BranchObj *bo=getSelectedBranchObj();
2334 bo->move2RelPos (p);
2340 void VymModel::deleteChildren()
2343 BranchItem *selbi=getSelectedBranch();
2346 saveStateChangingPart(
2349 "deleteChildren ()",
2350 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2352 emit (layoutAboutToBeChanged() );
2354 QModelIndex ix=index (selbi);
2355 int n=selbi->branchCount()-1;
2356 beginRemoveRows (ix,0,n);
2357 removeRows (0,n+1,ix);
2359 if (selbi->isScrolled()) selbi->unScroll();
2360 emit (layoutChanged() );
2365 TreeItem* VymModel::deleteItem (TreeItem *ti)
2369 TreeItem *pi=ti->parent();
2370 QModelIndex parentIndex=index(pi);
2372 emit (layoutAboutToBeChanged() );
2374 int n=ti->childNum();
2375 beginRemoveRows (parentIndex,n,n);
2376 removeRows (n,1,parentIndex);
2380 emit (layoutChanged() );
2381 if (pi->depth()>0) return pi;
2386 bool VymModel::scrollBranch(BranchItem *bi)
2390 if (bi->isScrolled()) return false;
2391 if (bi->branchCount()==0) return false;
2392 if (bi->depth()==0) return false;
2393 if (bi->toggleScroll())
2400 QString ("%1 ()").arg(u),
2402 QString ("%1 ()").arg(r),
2403 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2405 emitDataHasChanged(bi);
2406 emitSelectionChanged();
2407 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2414 bool VymModel::unscrollBranch(BranchItem *bi)
2418 if (!bi->isScrolled()) return false;
2419 if (bi->branchCount()==0) return false;
2420 if (bi->depth()==0) return false;
2427 QString ("%1 ()").arg(u),
2429 QString ("%1 ()").arg(r),
2430 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2433 emitDataHasChanged(bi);
2434 emitSelectionChanged();
2436 mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal...
2442 void VymModel::toggleScroll()
2444 BranchItem *bi=(BranchItem*)getSelectedBranch();
2445 if (bi && bi->isBranchLikeType() )
2447 if (bi->isScrolled())
2448 unscrollBranch (bi);
2452 // saveState is called in above functions
2455 void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel
2459 BranchObj *bo=getSelectedBranch();
2465 if (bo->isScrolled()) unscrollBranch (bo);
2472 void VymModel::emitExpandAll()
2474 emit (expandAll() );
2477 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2479 BranchItem *bi=getSelectedBranch();
2483 if (bi->isActiveStandardFlag(name))
2495 QString("%1 (\"%2\")").arg(u).arg(name),
2497 QString("%1 (\"%2\")").arg(r).arg(name),
2498 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2499 bi->toggleStandardFlag (name, master);
2501 emitSelectionChanged();
2505 void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
2508 BranchObj *bo=getSelectedBranch();
2511 FloatImageObj *fio=bo->addFloatImage();
2513 fio->setOriginalFilename("No original filename (image added by dropevent)");
2514 QString s=getSelectString(bo);
2515 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2516 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2518 // FIXME-3 VM needed? scene()->update();
2524 void VymModel::colorBranch (QColor c)
2526 BranchItem *selbi=getSelectedBranch();
2531 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2533 QString ("colorBranch (\"%1\")").arg(c.name()),
2534 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2536 selbi->setHeadingColor(c); // color branch
2540 void VymModel::colorSubtree (QColor c)
2542 BranchItem *selbi=getSelectedBranch();
2545 saveStateChangingPart(
2548 QString ("colorSubtree (\"%1\")").arg(c.name()),
2549 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2551 BranchItem *prev=NULL;
2552 BranchItem *cur=selbi;
2555 cur->setHeadingColor(c); // color links, color children
2556 cur=next (cur,prev,selbi);
2562 QColor VymModel::getCurrentHeadingColor()
2564 BranchItem *selbi=getSelectedBranch();
2565 if (selbi) return selbi->getHeadingColor();
2567 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2573 void VymModel::editURL()
2575 TreeItem *selti=getSelectedItem();
2579 QString text = QInputDialog::getText(
2580 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2581 selti->getURL(), &ok, NULL);
2583 // user entered something and pressed OK
2588 void VymModel::editLocalURL()
2590 TreeItem *selti=getSelectedItem();
2593 QStringList filters;
2594 filters <<"All files (*)";
2595 filters << tr("Text","Filedialog") + " (*.txt)";
2596 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2597 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2598 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2599 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2600 fd->setFilters (filters);
2601 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2602 fd->setDirectory (lastFileDir);
2603 if (! selti->getVymLink().isEmpty() )
2604 fd->selectFile( selti->getURL() );
2607 if ( fd->exec() == QDialog::Accepted )
2609 lastFileDir=QDir (fd->directory().path());
2610 setURL (fd->selectedFile() );
2616 void VymModel::editHeading2URL()
2618 TreeItem *selti=getSelectedItem();
2620 setURL (selti->getHeading());
2623 void VymModel::editBugzilla2URL()
2625 TreeItem *selti=getSelectedItem();
2628 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+selti->getHeading();
2633 void VymModel::editFATE2URL()
2635 TreeItem *selti=getSelectedItem();
2638 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2641 "setURL (\""+selti->getURL()+"\")",
2643 "setURL (\""+url+"\")",
2644 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2646 selti->setURL (url);
2647 // FIXME-4 updateActions();
2651 void VymModel::editVymLink()
2653 BranchItem *bi=getSelectedBranch();
2656 QStringList filters;
2657 filters <<"VYM map (*.vym)";
2658 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2659 fd->setFilters (filters);
2660 fd->setCaption(vymName+" - " +tr("Link to another map"));
2661 fd->setDirectory (lastFileDir);
2662 if (! bi->getVymLink().isEmpty() )
2663 fd->selectFile( bi->getVymLink() );
2667 if ( fd->exec() == QDialog::Accepted )
2669 lastFileDir=QDir (fd->directory().path());
2672 "setVymLink (\""+bi->getVymLink()+"\")",
2674 "setVymLink (\""+fd->selectedFile()+"\")",
2675 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2677 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
2682 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
2684 // Internal function, no saveState needed
2685 TreeItem *selti=getSelectedItem();
2688 selti->setVymLink(s);
2690 emitDataHasChanged (selti);
2691 emitShowSelection();
2695 void VymModel::deleteVymLink()
2697 BranchItem *bi=getSelectedBranch();
2702 "setVymLink (\""+bi->getVymLink()+"\")",
2704 "setVymLink (\"\")",
2705 QString("Unset vymlink of %1").arg(getObjectName(bi))
2707 bi->setVymLink ("" );
2713 QString VymModel::getVymLink()
2715 BranchItem *bi=getSelectedBranch();
2717 return bi->getVymLink();
2723 QStringList VymModel::getVymLinks()
2726 BranchItem *selbi=getSelectedBranch();
2727 BranchItem *cur=selbi;
2728 BranchItem *prev=NULL;
2731 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
2732 cur=next (cur,prev,selbi);
2738 void VymModel::followXLink(int i) // FIXME-2
2742 BranchObj *bo=getSelectedBranch();
2745 bo=bo->XLinkTargetAt(i);
2748 selection.select(bo);
2749 emitShowSelection();
2755 void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
2759 BranchObj *bo=getSelectedBranch();
2762 XLinkObj *xlo=bo->XLinkAt(i);
2765 EditXLinkDialog dia;
2767 dia.setSelection(bo);
2768 if (dia.exec() == QDialog::Accepted)
2770 if (dia.useSettingsGlobal() )
2772 setMapDefXLinkColor (xlo->getColor() );
2773 setMapDefXLinkWidth (xlo->getWidth() );
2775 if (dia.deleteXLink())
2776 bo->deleteXLinkAt(i);
2787 //////////////////////////////////////////////
2789 //////////////////////////////////////////////
2791 void VymModel::parseAtom(const QString &atom)
2793 TreeItem* selti=getSelectedItem();
2794 BranchItem *selbi=getSelectedBranch();
2800 // Split string s into command and parameters
2801 parser.parseAtom (atom);
2802 QString com=parser.getCommand();
2804 // External commands
2805 /////////////////////////////////////////////////////////////////////
2806 if (com=="addBranch")
2810 parser.setError (Aborted,"Nothing selected");
2811 } else if (! selbi )
2813 parser.setError (Aborted,"Type of selection is not a branch");
2818 if (parser.checkParCount(pl))
2820 if (parser.parCount()==0)
2824 n=parser.parInt (ok,0);
2825 if (ok ) addNewBranch (n);
2829 /////////////////////////////////////////////////////////////////////
2830 } else if (com=="addBranchBefore")
2834 parser.setError (Aborted,"Nothing selected");
2835 } else if (! selbi )
2837 parser.setError (Aborted,"Type of selection is not a branch");
2840 if (parser.parCount()==0)
2842 addNewBranchBefore ();
2845 /////////////////////////////////////////////////////////////////////
2846 } else if (com==QString("addMapCenter"))
2848 if (parser.checkParCount(2))
2850 x=parser.parDouble (ok,0);
2853 y=parser.parDouble (ok,1);
2854 if (ok) addMapCenter (QPointF(x,y));
2857 /////////////////////////////////////////////////////////////////////
2858 } else if (com==QString("addMapReplace"))
2862 parser.setError (Aborted,"Nothing selected");
2863 } else if (! selbi )
2865 parser.setError (Aborted,"Type of selection is not a branch");
2866 } else if (parser.checkParCount(1))
2868 //s=parser.parString (ok,0); // selection
2869 t=parser.parString (ok,0); // path to map
2870 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2871 addMapReplaceInt(getSelectString(selbi),t);
2873 /////////////////////////////////////////////////////////////////////
2874 } else if (com==QString("addMapInsert"))
2878 parser.setError (Aborted,"Nothing selected");
2879 } else if (! selbi )
2881 parser.setError (Aborted,"Type of selection is not a branch");
2884 if (parser.checkParCount(2))
2886 t=parser.parString (ok,0); // path to map
2887 n=parser.parInt(ok,1); // position
2888 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2889 addMapInsertInt(t,n);
2892 /////////////////////////////////////////////////////////////////////
2893 } else if (com=="clearFlags")
2897 parser.setError (Aborted,"Nothing selected");
2898 } else if (! selbi )
2900 parser.setError (Aborted,"Type of selection is not a branch");
2901 } else if (parser.checkParCount(0))
2903 selbi->deactivateAllStandardFlags();
2905 /////////////////////////////////////////////////////////////////////
2906 } else if (com=="colorBranch")
2910 parser.setError (Aborted,"Nothing selected");
2911 } else if (! selbi )
2913 parser.setError (Aborted,"Type of selection is not a branch");
2914 } else if (parser.checkParCount(1))
2916 QColor c=parser.parColor (ok,0);
2917 if (ok) colorBranch (c);
2919 /////////////////////////////////////////////////////////////////////
2920 } else if (com=="colorSubtree")
2924 parser.setError (Aborted,"Nothing selected");
2925 } else if (! selbi )
2927 parser.setError (Aborted,"Type of selection is not a branch");
2928 } else if (parser.checkParCount(1))
2930 QColor c=parser.parColor (ok,0);
2931 if (ok) colorSubtree (c);
2933 /////////////////////////////////////////////////////////////////////
2934 } else if (com=="copy")
2938 parser.setError (Aborted,"Nothing selected");
2939 } else if ( selectionType()!=TreeItem::Branch &&
2940 selectionType()!=TreeItem::MapCenter &&
2941 selectionType()!=TreeItem::Image )
2943 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2944 } else if (parser.checkParCount(0))
2948 /////////////////////////////////////////////////////////////////////
2949 } else if (com=="cut")
2953 parser.setError (Aborted,"Nothing selected");
2954 } else if ( selectionType()!=TreeItem::Branch &&
2955 selectionType()!=TreeItem::MapCenter &&
2956 selectionType()!=TreeItem::Image )
2958 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2959 } else if (parser.checkParCount(0))
2963 /////////////////////////////////////////////////////////////////////
2964 } else if (com=="delete")
2968 parser.setError (Aborted,"Nothing selected");
2970 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2972 parser.setError (Aborted,"Type of selection is wrong.");
2975 else if (parser.checkParCount(0))
2979 /////////////////////////////////////////////////////////////////////
2980 } else if (com=="deleteKeepChildren")
2984 parser.setError (Aborted,"Nothing selected");
2985 } else if (! selbi )
2987 parser.setError (Aborted,"Type of selection is not a branch");
2988 } else if (parser.checkParCount(0))
2990 deleteKeepChildren();
2992 /////////////////////////////////////////////////////////////////////
2993 } else if (com=="deleteChildren")
2997 parser.setError (Aborted,"Nothing selected");
3000 parser.setError (Aborted,"Type of selection is not a branch");
3001 } else if (parser.checkParCount(0))
3005 /////////////////////////////////////////////////////////////////////
3006 } else if (com=="exportASCII")
3010 if (parser.parCount()>=1)
3011 // Hey, we even have a filename
3012 fname=parser.parString(ok,0);
3015 parser.setError (Aborted,"Could not read filename");
3018 exportASCII (fname,false);
3020 /////////////////////////////////////////////////////////////////////
3021 } else if (com=="exportImage")
3025 if (parser.parCount()>=2)
3026 // Hey, we even have a filename
3027 fname=parser.parString(ok,0);
3030 parser.setError (Aborted,"Could not read filename");
3033 QString format="PNG";
3034 if (parser.parCount()>=2)
3036 format=parser.parString(ok,1);
3038 exportImage (fname,false,format);
3040 /////////////////////////////////////////////////////////////////////
3041 } else if (com=="exportXHTML")
3045 if (parser.parCount()>=2)
3046 // Hey, we even have a filename
3047 fname=parser.parString(ok,1);
3050 parser.setError (Aborted,"Could not read filename");
3053 exportXHTML (fname,false);
3055 /////////////////////////////////////////////////////////////////////
3056 } else if (com=="exportXML")
3060 if (parser.parCount()>=2)
3061 // Hey, we even have a filename
3062 fname=parser.parString(ok,1);
3065 parser.setError (Aborted,"Could not read filename");
3068 exportXML (fname,false);
3070 /////////////////////////////////////////////////////////////////////
3071 } else if (com=="importDir")
3075 parser.setError (Aborted,"Nothing selected");
3076 } else if (! selbi )
3078 parser.setError (Aborted,"Type of selection is not a branch");
3079 } else if (parser.checkParCount(1))
3081 s=parser.parString(ok,0);
3082 if (ok) importDirInt(s);
3084 /////////////////////////////////////////////////////////////////////
3085 } else if (com=="relinkTo")
3089 parser.setError (Aborted,"Nothing selected");
3092 if (parser.checkParCount(4))
3094 // 0 selectstring of parent
3095 // 1 num in parent (for branches)
3096 // 2,3 x,y of mainbranch or mapcenter
3097 s=parser.parString(ok,0);
3098 TreeItem *dst=findBySelectString (s);
3101 if (dst->getType()==TreeItem::Branch)
3103 // Get number in parent
3104 n=parser.parInt (ok,1);
3107 relinkBranch (selbi,(BranchItem*)dst,n);
3108 emitSelectionChanged();
3110 } else if (dst->getType()==TreeItem::MapCenter)
3112 relinkBranch (selbi,(BranchItem*)dst);
3113 // Get coordinates of mainbranch
3114 x=parser.parDouble(ok,2);
3117 y=parser.parDouble(ok,3);
3120 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3121 emitSelectionChanged();
3127 } else if ( selti->getType() == TreeItem::Image)
3129 if (parser.checkParCount(1))
3131 // 0 selectstring of parent
3132 s=parser.parString(ok,0);
3133 TreeItem *dst=findBySelectString (s);
3136 if (dst->isBranchLikeType())
3137 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3139 parser.setError (Aborted,"Destination is not a branch");
3142 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3143 /////////////////////////////////////////////////////////////////////
3144 } else if (com=="loadImage")
3148 parser.setError (Aborted,"Nothing selected");
3149 } else if (! selbi )
3151 parser.setError (Aborted,"Type of selection is not a branch");
3152 } else if (parser.checkParCount(1))
3154 s=parser.parString(ok,0);
3155 if (ok) loadFloatImageInt (selbi,s);
3157 /////////////////////////////////////////////////////////////////////
3158 } else if (com=="moveUp")
3162 parser.setError (Aborted,"Nothing selected");
3163 } else if (! selbi )
3165 parser.setError (Aborted,"Type of selection is not a branch");
3166 } else if (parser.checkParCount(0))
3170 /////////////////////////////////////////////////////////////////////
3171 } else if (com=="moveDown")
3175 parser.setError (Aborted,"Nothing selected");
3176 } else if (! selbi )
3178 parser.setError (Aborted,"Type of selection is not a branch");
3179 } else if (parser.checkParCount(0))
3183 /////////////////////////////////////////////////////////////////////
3184 } else if (com=="move")
3188 parser.setError (Aborted,"Nothing selected");
3189 } else if ( selectionType()!=TreeItem::Branch &&
3190 selectionType()!=TreeItem::MapCenter &&
3191 selectionType()!=TreeItem::Image )
3193 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3194 } else if (parser.checkParCount(2))
3196 x=parser.parDouble (ok,0);
3199 y=parser.parDouble (ok,1);
3203 /////////////////////////////////////////////////////////////////////
3204 } else if (com=="moveRel")
3208 parser.setError (Aborted,"Nothing selected");
3209 } else if ( selectionType()!=TreeItem::Branch &&
3210 selectionType()!=TreeItem::MapCenter &&
3211 selectionType()!=TreeItem::Image )
3213 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3214 } else if (parser.checkParCount(2))
3216 x=parser.parDouble (ok,0);
3219 y=parser.parDouble (ok,1);
3220 if (ok) moveRel (x,y);
3223 /////////////////////////////////////////////////////////////////////
3224 } else if (com=="nop")
3226 /////////////////////////////////////////////////////////////////////
3227 } else if (com=="paste")
3231 parser.setError (Aborted,"Nothing selected");
3232 } else if (! selbi )
3234 parser.setError (Aborted,"Type of selection is not a branch");
3235 } else if (parser.checkParCount(1))
3237 n=parser.parInt (ok,0);
3238 if (ok) pasteNoSave(n);
3240 /////////////////////////////////////////////////////////////////////
3241 } else if (com=="qa")
3245 parser.setError (Aborted,"Nothing selected");
3246 } else if (! selbi )
3248 parser.setError (Aborted,"Type of selection is not a branch");
3249 } else if (parser.checkParCount(4))
3252 c=parser.parString (ok,0);
3255 parser.setError (Aborted,"No comment given");
3258 s=parser.parString (ok,1);
3261 parser.setError (Aborted,"First parameter is not a string");
3264 t=parser.parString (ok,2);
3267 parser.setError (Aborted,"Condition is not a string");
3270 u=parser.parString (ok,3);
3273 parser.setError (Aborted,"Third parameter is not a string");
3278 parser.setError (Aborted,"Unknown type: "+s);
3283 parser.setError (Aborted,"Unknown operator: "+t);
3288 parser.setError (Aborted,"Type of selection is not a branch");
3291 if (selbi->getHeading() == u)
3293 cout << "PASSED: " << qPrintable (c) << endl;
3296 cout << "FAILED: " << qPrintable (c) << endl;
3306 /////////////////////////////////////////////////////////////////////
3307 } else if (com=="saveImage")
3309 ImageItem *ii=getSelectedImage();
3312 parser.setError (Aborted,"No image selected");
3313 } else if (parser.checkParCount(2))
3315 s=parser.parString(ok,0);
3318 t=parser.parString(ok,1);
3319 if (ok) saveFloatImageInt (ii,t,s);
3322 /////////////////////////////////////////////////////////////////////
3323 } else if (com=="scroll")
3327 parser.setError (Aborted,"Nothing selected");
3328 } else if (! selbi )
3330 parser.setError (Aborted,"Type of selection is not a branch");
3331 } else if (parser.checkParCount(0))
3333 if (!scrollBranch (selbi))
3334 parser.setError (Aborted,"Could not scroll branch");
3336 /////////////////////////////////////////////////////////////////////
3337 } else if (com=="select")
3339 if (parser.checkParCount(1))
3341 s=parser.parString(ok,0);
3344 /////////////////////////////////////////////////////////////////////
3345 } else if (com=="selectLastBranch")
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 BranchItem *bi=selbi->getLastBranch();
3357 parser.setError (Aborted,"Could not select last branch");
3358 select (bi); // FIXME-3 was selectInt
3361 /////////////////////////////////////////////////////////////////////
3362 } else /* FIXME-2 if (com=="selectLastImage")
3366 parser.setError (Aborted,"Nothing selected");
3367 } else if (! selbi )
3369 parser.setError (Aborted,"Type of selection is not a branch");
3370 } else if (parser.checkParCount(0))
3372 FloatImageObj *fio=selb->getLastFloatImage();
3374 parser.setError (Aborted,"Could not select last image");
3375 select (fio); // FIXME-3 was selectInt
3378 /////////////////////////////////////////////////////////////////////
3379 } else */ if (com=="selectLatestAdded")
3381 if (!latestAddedItem)
3383 parser.setError (Aborted,"No latest added object");
3386 if (!select (latestAddedItem))
3387 parser.setError (Aborted,"Could not select latest added object ");
3389 /////////////////////////////////////////////////////////////////////
3390 } else if (com=="setFrameType")
3392 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3394 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3396 else if (parser.checkParCount(1))
3398 s=parser.parString(ok,0);
3399 if (ok) setFrameType (s);
3401 /////////////////////////////////////////////////////////////////////
3402 } else if (com=="setFramePenColor")
3404 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3406 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3408 else if (parser.checkParCount(1))
3410 QColor c=parser.parColor(ok,0);
3411 if (ok) setFramePenColor (c);
3413 /////////////////////////////////////////////////////////////////////
3414 } else if (com=="setFrameBrushColor")
3416 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3418 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3420 else if (parser.checkParCount(1))
3422 QColor c=parser.parColor(ok,0);
3423 if (ok) setFrameBrushColor (c);
3425 /////////////////////////////////////////////////////////////////////
3426 } else if (com=="setFramePadding")
3428 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3430 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3432 else if (parser.checkParCount(1))
3434 n=parser.parInt(ok,0);
3435 if (ok) setFramePadding(n);
3437 /////////////////////////////////////////////////////////////////////
3438 } else if (com=="setFrameBorderWidth")
3440 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3442 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3444 else if (parser.checkParCount(1))
3446 n=parser.parInt(ok,0);
3447 if (ok) setFrameBorderWidth (n);
3449 /////////////////////////////////////////////////////////////////////
3450 } else if (com=="setMapAuthor")
3452 if (parser.checkParCount(1))
3454 s=parser.parString(ok,0);
3455 if (ok) setAuthor (s);
3457 /////////////////////////////////////////////////////////////////////
3458 } else if (com=="setMapComment")
3460 if (parser.checkParCount(1))
3462 s=parser.parString(ok,0);
3463 if (ok) setComment(s);
3465 /////////////////////////////////////////////////////////////////////
3466 } else if (com=="setMapBackgroundColor")
3470 parser.setError (Aborted,"Nothing selected");
3471 } else if (! selbi )
3473 parser.setError (Aborted,"Type of selection is not a branch");
3474 } else if (parser.checkParCount(1))
3476 QColor c=parser.parColor (ok,0);
3477 if (ok) setMapBackgroundColor (c);
3479 /////////////////////////////////////////////////////////////////////
3480 } else if (com=="setMapDefLinkColor")
3484 parser.setError (Aborted,"Nothing selected");
3485 } else if (! selbi )
3487 parser.setError (Aborted,"Type of selection is not a branch");
3488 } else if (parser.checkParCount(1))
3490 QColor c=parser.parColor (ok,0);
3491 if (ok) setMapDefLinkColor (c);
3493 /////////////////////////////////////////////////////////////////////
3494 } else if (com=="setMapLinkStyle")
3496 if (parser.checkParCount(1))
3498 s=parser.parString (ok,0);
3499 if (ok) setMapLinkStyle(s);
3501 /////////////////////////////////////////////////////////////////////
3502 } else if (com=="setHeading")
3506 parser.setError (Aborted,"Nothing selected");
3507 } else if (! selbi )
3509 parser.setError (Aborted,"Type of selection is not a branch");
3510 } else if (parser.checkParCount(1))
3512 s=parser.parString (ok,0);
3516 /////////////////////////////////////////////////////////////////////
3517 } else if (com=="setHideExport")
3521 parser.setError (Aborted,"Nothing selected");
3522 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3524 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3525 } else if (parser.checkParCount(1))
3527 b=parser.parBool(ok,0);
3528 if (ok) setHideExport (b);
3530 /////////////////////////////////////////////////////////////////////
3531 } else if (com=="setIncludeImagesHorizontally")
3535 parser.setError (Aborted,"Nothing selected");
3538 parser.setError (Aborted,"Type of selection is not a branch");
3539 } else if (parser.checkParCount(1))
3541 b=parser.parBool(ok,0);
3542 if (ok) setIncludeImagesHor(b);
3544 /////////////////////////////////////////////////////////////////////
3545 } else if (com=="setIncludeImagesVertically")
3549 parser.setError (Aborted,"Nothing selected");
3552 parser.setError (Aborted,"Type of selection is not a branch");
3553 } else if (parser.checkParCount(1))
3555 b=parser.parBool(ok,0);
3556 if (ok) setIncludeImagesVer(b);
3558 /////////////////////////////////////////////////////////////////////
3559 } else if (com=="setHideLinkUnselected")
3563 parser.setError (Aborted,"Nothing selected");
3564 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3566 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3567 } else if (parser.checkParCount(1))
3569 b=parser.parBool(ok,0);
3570 if (ok) setHideLinkUnselected(b);
3572 /////////////////////////////////////////////////////////////////////
3573 } else if (com=="setSelectionColor")
3575 if (parser.checkParCount(1))
3577 QColor c=parser.parColor (ok,0);
3578 if (ok) setSelectionColorInt (c);
3580 /////////////////////////////////////////////////////////////////////
3581 } else if (com=="setURL")
3585 parser.setError (Aborted,"Nothing selected");
3586 } else if (! selbi )
3588 parser.setError (Aborted,"Type of selection is not a branch");
3589 } else if (parser.checkParCount(1))
3591 s=parser.parString (ok,0);
3594 /////////////////////////////////////////////////////////////////////
3595 } else if (com=="setVymLink")
3599 parser.setError (Aborted,"Nothing selected");
3600 } else if (! selbi )
3602 parser.setError (Aborted,"Type of selection is not a branch");
3603 } else if (parser.checkParCount(1))
3605 s=parser.parString (ok,0);
3606 if (ok) setVymLink(s);
3609 /////////////////////////////////////////////////////////////////////
3610 else if (com=="setFlag")
3614 parser.setError (Aborted,"Nothing selected");
3615 } else if (! selbi )
3617 parser.setError (Aborted,"Type of selection is not a branch");
3618 } else if (parser.checkParCount(1))
3620 s=parser.parString(ok,0);
3622 selbi->activateStandardFlag(s);
3624 /////////////////////////////////////////////////////////////////////
3625 } else /* FIXME-2 if (com=="setFrameType")
3629 parser.setError (Aborted,"Nothing selected");
3632 parser.setError (Aborted,"Type of selection is not a branch");
3633 } else if (parser.checkParCount(1))
3635 s=parser.parString(ok,0);
3639 /////////////////////////////////////////////////////////////////////
3640 } else*/ if (com=="sortChildren")
3644 parser.setError (Aborted,"Nothing selected");
3645 } else if (! selbi )
3647 parser.setError (Aborted,"Type of selection is not a branch");
3648 } else if (parser.checkParCount(0))
3652 /////////////////////////////////////////////////////////////////////
3653 } else if (com=="toggleFlag")
3657 parser.setError (Aborted,"Nothing selected");
3658 } else if (! selbi )
3660 parser.setError (Aborted,"Type of selection is not a branch");
3661 } else if (parser.checkParCount(1))
3663 s=parser.parString(ok,0);
3665 selbi->toggleStandardFlag(s);
3667 /////////////////////////////////////////////////////////////////////
3668 } else if (com=="unscroll")
3672 parser.setError (Aborted,"Nothing selected");
3673 } else if (! selbi )
3675 parser.setError (Aborted,"Type of selection is not a branch");
3676 } else if (parser.checkParCount(0))
3678 if (!unscrollBranch (selbi))
3679 parser.setError (Aborted,"Could not unscroll branch");
3681 /////////////////////////////////////////////////////////////////////
3682 } else if (com=="unscrollChildren")
3686 parser.setError (Aborted,"Nothing selected");
3687 } else if (! selbi )
3689 parser.setError (Aborted,"Type of selection is not a branch");
3690 } else if (parser.checkParCount(0))
3692 unscrollChildren ();
3694 /////////////////////////////////////////////////////////////////////
3695 } else if (com=="unsetFlag")
3699 parser.setError (Aborted,"Nothing selected");
3700 } else if (! selbi )
3702 parser.setError (Aborted,"Type of selection is not a branch");
3703 } else if (parser.checkParCount(1))
3705 s=parser.parString(ok,0);
3707 selbi->deactivateStandardFlag(s);
3710 parser.setError (Aborted,"Unknown command");
3713 if (parser.errorLevel()==NoError)
3715 // setChanged(); FIXME-2 should not be called e.g. for export?!
3720 // TODO Error handling
3721 qWarning("VymModel::parseAtom: Error!");
3722 qWarning(parser.errorMessage());
3726 void VymModel::runScript (QString script)
3728 parser.setScript (script);
3730 while (parser.next() )
3731 parseAtom(parser.getAtom());
3734 void VymModel::setExportMode (bool b)
3736 // should be called before and after exports
3737 // depending on the settings
3738 if (b && settings.value("/export/useHideExport","true")=="true")
3739 setHideTmpMode (TreeItem::HideExport);
3741 setHideTmpMode (TreeItem::HideNone);
3744 void VymModel::exportImage(QString fname, bool askName, QString format)
3746 /* FIXME-2 export as image, but directly from mapEditor?!
3749 fname=getMapName()+".png";
3756 QFileDialog *fd=new QFileDialog (NULL);
3757 fd->setCaption (tr("Export map as image"));
3758 fd->setDirectory (lastImageDir);
3759 fd->setFileMode(QFileDialog::AnyFile);
3760 fd->setFilters (imageIO.getFilters() );
3763 fl=fd->selectedFiles();
3765 format=imageIO.getType(fd->selectedFilter());
3769 setExportMode (true);
3770 QPixmap pix (mapEditor->getPixmap());
3771 pix.save(fname, format);
3772 setExportMode (false);
3777 void VymModel::exportXML(QString dir, bool askForName)
3781 dir=browseDirectory(NULL,tr("Export XML to directory"));
3782 if (dir =="" && !reallyWriteDirectory(dir) )
3786 // Hide stuff during export, if settings want this
3787 setExportMode (true);
3789 // Create subdirectories
3792 // write to directory //FIXME-4 check totalBBox here...
3793 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
3796 file.setName ( dir + "/"+mapName+".xml");
3797 if ( !file.open( QIODevice::WriteOnly ) )
3799 // This should neverever happen
3800 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3804 // Write it finally, and write in UTF8, no matter what
3805 QTextStream ts( &file );
3806 ts.setEncoding (QTextStream::UnicodeUTF8);
3810 // Now write image, too
3811 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3813 setExportMode (false);
3816 void VymModel::exportASCII(QString fname,bool askName)
3821 ex.setFile (mapName+".txt");
3827 //ex.addFilter ("TXT (*.txt)");
3828 ex.setDir(lastImageDir);
3829 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3834 setExportMode(true);
3836 setExportMode(false);
3840 void VymModel::exportXHTML (const QString &dir, bool askForName)
3842 ExportXHTMLDialog dia(NULL);
3843 dia.setFilePath (filePath );
3844 dia.setMapName (mapName );
3846 if (dir!="") dia.setDir (dir);
3852 if (dia.exec()!=QDialog::Accepted)
3856 QDir d (dia.getDir());
3857 // Check, if warnings should be used before overwriting
3858 // the output directory
3859 if (d.exists() && d.count()>0)
3862 warn.showCancelButton (true);
3863 warn.setText(QString(
3864 "The directory %1 is not empty.\n"
3865 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3866 warn.setCaption("Warning: Directory not empty");
3867 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3869 if (warn.exec()!=QDialog::Accepted) ok=false;
3876 exportXML (dia.getDir(),false );
3877 dia.doExport(mapName );
3878 //if (dia.hasChanged()) setChanged();
3882 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3887 if (ex.setConfigFile(cf))
3889 setExportMode (true);
3890 ex.exportPresentation();
3891 setExportMode (false);
3898 //////////////////////////////////////////////
3900 //////////////////////////////////////////////
3902 void VymModel::registerEditor(QWidget *me)
3904 mapEditor=(MapEditor*)me;
3907 void VymModel::unregisterEditor(QWidget *)
3912 void VymModel::setContextPos(QPointF p)
3917 void VymModel::unsetContextPos()
3919 contextPos=QPointF();
3922 void VymModel::updateNoteFlag()
3925 TreeItem *selti=getSelectedItem();
3928 if (textEditor->isEmpty())
3931 selti->setNote (textEditor->getText());
3932 emitDataHasChanged(selti);
3933 emitSelectionChanged();
3938 void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos
3941 for (int i=0; i<rootItem->branchCount(); i++)
3942 ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
3945 void MapCenterObj::updateRelPositions()
3947 if (repositionRequest) unsetAllRepositionRequests();
3949 // update relative Positions of branches and floats
3950 for (int i=0; i<treeItem->branchCount(); ++i)
3952 treeItem->getBranchObjNum(i)->setRelPos();
3953 treeItem->getBranchObjNum(i)->setOrientation();
3956 for (int i=0; i<floatimage.size(); ++i)
3957 floatimage.at(i)->setRelPos();
3959 if (repositionRequest) reposition();
3964 void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
3966 //cout << "VM::reposition blocked="<<blockReposition<<endl;
3967 if (blockReposition) return;
3969 for (int i=0;i<rootItem->branchCount(); i++)
3970 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
3974 QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
3976 return QPolygonF ();
3977 // Creating (arbitrary) shapes
3980 QRectF rb=bo->getBBox();
3981 if (bo->getDepth()==0)
3983 // Just take BBox of this mapCenter
3984 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3988 // Take union of BBox and TotalBBox
3990 QRectF ra=bo->getTotalBBox();
3991 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3994 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3997 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3999 p <<ra.bottomRight()
4001 <<QPointF (rb.topRight().x(), ra.topRight().y() )
4004 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
4010 void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
4014 // Move all branches and MapCenters away from lmo
4015 // to avoid collisions
4020 BranchObj *boA=(BranchObj*)lmo;
4022 for (int i=0; i<rootItem->branchCount(); i++)
4024 boB=rootItem->getBranchNum(i);
4027 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
4030 <<" ("<<qPrintable(boA->getHeading() )<<")"
4031 <<" with ("<< qPrintable (boB->getHeading() )
4034 <<" minT="<<r.minTranslation<<endl<<endl;
4040 void VymModel::setMapLinkStyle (const QString & s)
4045 case LinkableMapObj::Line :
4048 case LinkableMapObj::Parabel:
4049 snow="StyleParabel";
4051 case LinkableMapObj::PolyLine:
4052 snow="StylePolyLine";
4054 case LinkableMapObj::PolyParabel:
4055 snow="StylePolyParabel";
4058 snow="UndefinedStyle";
4063 QString("setMapLinkStyle (\"%1\")").arg(s),
4064 QString("setMapLinkStyle (\"%1\")").arg(snow),
4065 QString("Set map link style (\"%1\")").arg(s)
4069 linkstyle=LinkableMapObj::Line;
4070 else if (s=="StyleParabel")
4071 linkstyle=LinkableMapObj::Parabel;
4072 else if (s=="StylePolyLine")
4073 linkstyle=LinkableMapObj::PolyLine;
4074 else if (s=="StylePolyParabel")
4075 linkstyle=LinkableMapObj::PolyParabel;
4077 linkstyle=LinkableMapObj::UndefinedStyle;
4079 BranchItem *cur=NULL;
4080 BranchItem *prev=NULL;
4085 bo=(BranchObj*)(cur->getLMO() );
4086 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4092 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4097 void VymModel::setMapDefLinkColor(QColor col)
4099 if ( !col.isValid() ) return;
4101 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4102 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4103 QString("Set map link color to %1").arg(col.name())
4107 BranchItem *cur=NULL;
4108 BranchItem *prev=NULL;
4113 bo=(BranchObj*)(cur->getLMO() );
4120 void VymModel::setMapLinkColorHintInt()
4122 // called from setMapLinkColorHint(lch) or at end of parse
4123 BranchItem *cur=NULL;
4124 BranchItem *prev=NULL;
4129 bo=(BranchObj*)(cur->getLMO() );
4135 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4138 setMapLinkColorHintInt();
4141 void VymModel::toggleMapLinkColorHint()
4143 if (linkcolorhint==LinkableMapObj::HeadingColor)
4144 linkcolorhint=LinkableMapObj::DefaultColor;
4146 linkcolorhint=LinkableMapObj::HeadingColor;
4147 BranchItem *cur=NULL;
4148 BranchItem *prev=NULL;
4153 bo=(BranchObj*)(cur->getLMO() );
4159 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4161 Q3FileDialog *fd=new Q3FileDialog( NULL);
4162 fd->setMode (Q3FileDialog::ExistingFile);
4163 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4164 ImagePreview *p =new ImagePreview (fd);
4165 fd->setContentsPreviewEnabled( TRUE );
4166 fd->setContentsPreview( p, p );
4167 fd->setPreviewMode( Q3FileDialog::Contents );
4168 fd->setCaption(vymName+" - " +tr("Load background image"));
4169 fd->setDir (lastImageDir);
4172 if ( fd->exec() == QDialog::Accepted )
4174 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4175 lastImageDir=QDir (fd->dirPath());
4176 setMapBackgroundImage (fd->selectedFile());
4180 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate, move to ME
4182 QColor oldcol=mapScene->backgroundBrush().color();
4186 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4188 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4189 QString("Set background color of map to %1").arg(col.name()));
4192 brush.setTextureImage (QPixmap (fn));
4193 mapScene->setBackgroundBrush(brush);
4196 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4198 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4199 if ( !col.isValid() ) return;
4200 setMapBackgroundColor( col );
4204 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4206 QColor oldcol=mapScene->backgroundBrush().color();
4208 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4209 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4210 QString("Set background color of map to %1").arg(col.name()));
4211 mapScene->setBackgroundBrush(col);
4214 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4216 return mapScene->backgroundBrush().color();
4220 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4222 return linkcolorhint;
4225 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4227 return defLinkColor;
4230 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4235 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4237 return defXLinkColor;
4240 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4245 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4247 return defXLinkWidth;
4250 void VymModel::move(const double &x, const double &y) // FIXME-3
4254 BranchObj *bo = getSelectedBranch();
4256 (selectionType()==TreeItem::Branch ||
4257 selectionType()==TreeItem::MapCenter ||
4258 selectionType()==TreeItem::Image
4261 QPointF ap(bo->getAbsPos());
4265 QString ps=qpointfToString(ap);
4266 QString s=getSelectString();
4269 s, "move "+qpointfToString(to),
4270 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4273 emitSelectionChanged();
4279 void VymModel::moveRel (const double &x, const double &y) // FIXME-3
4283 BranchObj *bo = getSelectedBranch();
4285 (selectionType()==TreeItem::Branch ||
4286 selectionType()==TreeItem::MapCenter ||
4287 selectionType()==TreeItem::Image
4291 QPointF rp(bo->getRelPos());
4295 QString ps=qpointfToString (bo->getRelPos());
4296 QString s=getSelectString(bo);
4299 s, "moveRel "+qpointfToString(to),
4300 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4301 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4303 bo->updateLinkGeometry();
4304 emitSelectionChanged();
4311 void VymModel::animate()
4313 animationTimer->stop();
4316 while (i<animObjList.size() )
4318 bo=(BranchObj*)animObjList.at(i);
4323 animObjList.removeAt(i);
4330 QItemSelection sel=selModel->selection();
4331 emit (selectionChanged(sel,sel));
4334 if (!animObjList.isEmpty()) animationTimer->start();
4338 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4340 if (bo && bo->getTreeItem()->depth()>0)
4343 ap.setStart (start);
4345 ap.setTicks (animationTicks);
4346 ap.setAnimated (true);
4347 bo->setAnimation (ap);
4348 animObjList.append( bo );
4349 animationTimer->setSingleShot (true);
4350 animationTimer->start(animationInterval);
4354 void VymModel::stopAnimation (MapObj *mo)
4356 int i=animObjList.indexOf(mo);
4358 animObjList.removeAt (i);
4361 void VymModel::sendSelection()
4363 if (netstate!=Server) return;
4364 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4367 void VymModel::newServer()
4371 tcpServer = new QTcpServer(this);
4372 if (!tcpServer->listen(QHostAddress::Any,port)) {
4373 QMessageBox::critical(NULL, "vym server",
4374 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4375 //FIXME-3 needed? we are no widget any longer... close();
4378 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4380 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4383 void VymModel::connectToServer()
4386 server="salam.suse.de";
4388 clientSocket = new QTcpSocket (this);
4389 clientSocket->abort();
4390 clientSocket->connectToHost(server ,port);
4391 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4392 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4393 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4395 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4400 void VymModel::newClient()
4402 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4403 connect(newClient, SIGNAL(disconnected()),
4404 newClient, SLOT(deleteLater()));
4406 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4408 clientList.append (newClient);
4412 void VymModel::sendData(const QString &s)
4414 if (clientList.size()==0) return;
4416 // Create bytearray to send
4418 QDataStream out(&block, QIODevice::WriteOnly);
4419 out.setVersion(QDataStream::Qt_4_0);
4421 // Reserve some space for blocksize
4424 // Write sendCounter
4425 out << sendCounter++;
4430 // Go back and write blocksize so far
4431 out.device()->seek(0);
4432 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4436 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4438 for (int i=0; i<clientList.size(); ++i)
4440 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4441 clientList.at(i)->write (block);
4445 void VymModel::readData ()
4447 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4450 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4454 QDataStream in(clientSocket);
4455 in.setVersion(QDataStream::Qt_4_0);
4463 cout << " t="<<qPrintable (t)<<endl;
4469 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4471 switch (socketError) {
4472 case QAbstractSocket::RemoteHostClosedError:
4474 case QAbstractSocket::HostNotFoundError:
4475 QMessageBox::information(NULL, vymName +" Network client",
4476 "The host was not found. Please check the "
4477 "host name and port settings.");
4479 case QAbstractSocket::ConnectionRefusedError:
4480 QMessageBox::information(NULL, vymName + " Network client",
4481 "The connection was refused by the peer. "
4482 "Make sure the fortune server is running, "
4483 "and check that the host name and port "
4484 "settings are correct.");
4487 QMessageBox::information(NULL, vymName + " Network client",
4488 QString("The following error occurred: %1.")
4489 .arg(clientSocket->errorString()));
4493 /* FIXME-3 Playing with DBUS...
4494 QDBusVariant VymModel::query (const QString &query)
4496 TreeItem *selti=getSelectedItem();
4498 return QDBusVariant (selti->getHeading());
4500 return QDBusVariant ("Nothing selected.");
4504 void VymModel::testslot() //FIXME-3
4506 cout << "VM::testslot called\n";
4509 void VymModel::selectMapSelectionColor()
4511 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4512 setSelectionColor (col);
4515 void VymModel::setSelectionColorInt (QColor col)
4517 if ( !col.isValid() ) return;
4519 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4520 QString("setSelectionColor (%1)").arg(col.name()),
4521 QString("Set color of selection box to %1").arg(col.name())
4524 mapEditor->setSelectionColor (col);
4528 void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
4530 cout << "VymModel::changeSelection (";
4531 if (!newsel.indexes().isEmpty() )
4532 cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
4534 if (!oldsel.indexes().isEmpty() )
4535 cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
4540 void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
4544 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4546 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4547 emitShowSelection();
4551 void VymModel::emitSelectionChanged()
4553 QItemSelection newsel=selModel->selection();
4554 emitSelectionChanged (newsel);
4557 void VymModel::setSelectionColor(QColor col)
4559 if ( !col.isValid() ) return;
4561 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4562 QString("setSelectionColor (%1)").arg(col.name()),
4563 QString("Set color of selection box to %1").arg(col.name())
4565 setSelectionColorInt (col);
4568 QColor VymModel::getSelectionColor()
4570 return mapEditor->getSelectionColor();
4573 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4576 for (int i=0;i<rootItem->childCount();i++)
4577 rootItem->child(i)->setHideTmp (mode);
4579 // FIXME-3 needed? scene()->update();
4582 //////////////////////////////////////////////
4583 // Selection related
4584 //////////////////////////////////////////////
4586 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4591 QItemSelectionModel* VymModel::getSelectionModel()
4596 void VymModel::setSelectionBlocked (bool b)
4601 bool VymModel::isSelectionBlocked()
4603 return selectionBlocked;
4606 bool VymModel::select ()
4608 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4611 bool VymModel::select (const QString &s)
4613 TreeItem *ti=findBySelectString(s);
4614 if (ti) return select (index(ti));
4618 bool VymModel::select (LinkableMapObj *lmo)
4620 QItemSelection oldsel=selModel->selection();
4623 return select (index (lmo->getTreeItem()) );
4628 bool VymModel::select (TreeItem *ti)
4630 if (ti) return select (index(ti));
4634 bool VymModel::select (const QModelIndex &index)
4636 if (index.isValid() )
4638 selModel->select (index,QItemSelectionModel::ClearAndSelect );
4639 BranchItem *bi=getSelectedBranch();
4640 if (bi) bi->setLastSelectedBranch();
4646 void VymModel::unselect()
4648 lastSelectString=getSelectString();
4649 selModel->clearSelection();
4652 bool VymModel::reselect()
4654 return select (lastSelectString);
4657 void VymModel::emitShowSelection()
4659 if (!blockReposition)
4660 emit (showSelection() );
4663 void VymModel::emitNoteHasChanged (TreeItem *ti)
4665 QModelIndex ix=index(ti);
4666 emit (noteHasChanged (ix) );
4669 void VymModel::emitDataHasChanged (TreeItem *ti)
4671 QModelIndex ix=index(ti);
4672 emit (dataChanged (ix,ix) );
4676 //bool VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
4679 if (selection.select(lmo))
4681 //emitSelectionChanged();
4685 bool VymModel::selectInt (TreeItem *ti)
4687 if (selection.select(lmo))
4689 //emitSelectionChanged();
4694 bool VymModel::selectFirstBranch()
4696 TreeItem *ti=getSelectedBranch();
4699 TreeItem *par=ti->parent();
4702 TreeItem *ti2=par->getFirstBranch();
4703 if (ti2) return select(ti2);
4709 bool VymModel::selectLastBranch()
4711 TreeItem *ti=getSelectedBranch();
4714 TreeItem *par=ti->parent();
4717 TreeItem *ti2=par->getLastBranch();
4718 if (ti2) return select(ti2);
4724 bool VymModel::selectLastSelectedBranch()
4726 BranchItem *bi=getSelectedBranch();
4729 bi=bi->getLastSelectedBranch();
4730 if (bi) return select (bi);
4735 bool VymModel::selectParent()
4737 TreeItem *ti=getSelectedItem();
4748 TreeItem::Type VymModel::selectionType()
4750 QModelIndexList list=selModel->selectedIndexes();
4751 if (list.isEmpty()) return TreeItem::Undefined;
4752 TreeItem *ti = getItem (list.first() );
4753 return ti->getType();
4757 LinkableMapObj* VymModel::getSelectedLMO()
4759 QModelIndexList list=selModel->selectedIndexes();
4760 if (!list.isEmpty() )
4762 TreeItem *ti = getItem (list.first() );
4763 TreeItem::Type type=ti->getType();
4764 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4765 return ((MapItem*)ti)->getLMO();
4770 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
4772 TreeItem *ti = getSelectedBranch();
4774 return (BranchObj*)( ((MapItem*)ti)->getLMO());
4779 BranchItem* VymModel::getSelectedBranch()
4781 QModelIndexList list=selModel->selectedIndexes();
4782 if (!list.isEmpty() )
4784 TreeItem *ti = getItem (list.first() );
4785 TreeItem::Type type=ti->getType();
4786 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4787 return (BranchItem*)ti;
4792 ImageItem* VymModel::getSelectedImage()
4794 QModelIndexList list=selModel->selectedIndexes();
4795 if (!list.isEmpty())
4797 TreeItem *ti=getItem (list.first());
4798 if (ti && ti->getType()==TreeItem::Image)
4799 return (ImageItem*)ti;
4804 AttributeItem* VymModel::getSelectedAttribute()
4806 QModelIndexList list=selModel->selectedIndexes();
4807 if (!list.isEmpty() )
4809 TreeItem *ti = getItem (list.first() );
4810 TreeItem::Type type=ti->getType();
4811 if (type ==TreeItem::Attribute)
4812 return (AttributeItem*)ti;
4817 TreeItem* VymModel::getSelectedItem()
4819 QModelIndexList list=selModel->selectedIndexes();
4820 if (!list.isEmpty() )
4821 return getItem (list.first() );
4826 QModelIndex VymModel::getSelectedIndex()
4828 QModelIndexList list=selModel->selectedIndexes();
4829 if (list.isEmpty() )
4830 return QModelIndex();
4832 return list.first();
4835 QString VymModel::getSelectString ()
4837 return getSelectString (getSelectedItem());
4840 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
4842 if (!lmo) return QString();
4843 return getSelectString (lmo->getTreeItem() );
4846 QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
4850 switch (ti->getType())
4852 case TreeItem::MapCenter: s="mc:"; break;
4853 case TreeItem::Branch: s="bo:";break;
4854 case TreeItem::Image: s="fi:";break;
4855 case TreeItem::Attribute: s="ai:";break;
4858 s= s + QString("%1").arg(ti->num());
4860 // call myself recursively
4861 s= getSelectString(ti->parent()) +","+s;