Added dialog for HTML export. Grouping in Switchboard shortcuts
1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
13 #include "exportxhtmldialog.h"
15 #include "geometry.h" // for addBBox
16 #include "mainwindow.h"
21 #include "warningdialog.h"
22 #include "xlinkitem.h"
23 #include "xml-freemind.h"
29 extern Main *mainWindow;
30 extern QDBusConnection dbusConnection;
32 extern Settings settings;
33 extern QString tmpVymDir;
35 extern TextEditor *textEditor;
36 extern FlagRow *standardFlagsMaster;
38 extern QString clipboardDir;
39 extern QString clipboardFile;
40 extern bool clipboardEmpty;
42 extern ImageIO imageIO;
44 extern QString vymName;
45 extern QString vymVersion;
46 extern QDir vymBaseDir;
48 extern QDir lastImageDir;
49 extern QDir lastFileDir;
51 extern Settings settings;
53 uint VymModel::idLast=0; // make instance
57 //cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 //cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
71 void VymModel::clear()
73 while (rootItem->childCount() >0)
74 deleteItem (rootItem->getChildNum(0) );
77 void VymModel::init ()
82 // Also no scene yet (should not be needed anyway) FIXME-3 VM
96 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
97 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
98 mainWindow->updateHistory (undoSet);
101 makeTmpDirectories();
106 fileName=tr("unnamed");
108 blockReposition=false;
109 blockSaveState=false;
111 autosaveTimer=new QTimer (this);
112 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
114 fileChangedTimer=new QTimer (this);
115 fileChangedTimer->start(3000);
116 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
121 selectionBlocked=false;
126 // animations // FIXME-3 switch to new animation system
127 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
128 animationTicks=settings.readNumEntry("/animation/ticks",10);
129 animationInterval=settings.readNumEntry("/animation/interval",50);
131 animationTimer=new QTimer (this);
132 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
135 defLinkColor=QColor (0,0,255);
136 defXLinkColor=QColor (180,180,180);
137 linkcolorhint=LinkableMapObj::DefaultColor;
138 linkstyle=LinkableMapObj::PolyParabel;
140 defXLinkColor=QColor (230,230,230);
142 hidemode=TreeItem::HideNone;
147 //Initialize DBUS object
148 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
149 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
150 qWarning ("VymModel: Couldn't register DBUS object!");
153 void VymModel::makeTmpDirectories()
155 // Create unique temporary directories
156 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
157 histPath = tmpMapDir+"/history";
163 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
168 bool VymModel::isRepositionBlocked()
170 return blockReposition;
173 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
175 //cout << "VM::updateActions \n";
176 // Tell mainwindow to update states of actions
177 mainWindow->updateActions();
182 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
184 // tmpdir temporary directory to which data will be written
185 // prefix mapname, which will be appended to images etc.
186 // writeflags Only write flags for "real" save of map, not undo
187 // offset offset of bbox of whole map in scene.
188 // Needed for XML export
197 case LinkableMapObj::Line:
200 case LinkableMapObj::Parabel:
203 case LinkableMapObj::PolyLine:
207 ls="StylePolyParabel";
211 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
213 if (linkcolorhint==LinkableMapObj::HeadingColor)
214 colhint=xml.attribut("linkColorHint","HeadingColor");
216 QString mapAttr=xml.attribut("version",vymVersion);
218 mapAttr+= xml.attribut("author",author) +
219 xml.attribut("comment",comment) +
220 xml.attribut("date",getDate()) +
221 xml.attribut("branchCount", QString().number(branchCount())) +
222 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
223 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
224 xml.attribut("linkStyle", ls ) +
225 xml.attribut("linkColor", defLinkColor.name() ) +
226 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
227 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
229 s+=xml.beginElement("vymmap",mapAttr);
232 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
233 standardFlagsMaster->resetUsedCounter();
235 // Build xml recursivly
237 // Save all mapcenters as complete map, if saveSel not set
238 s+=saveTreeToDir(tmpdir,prefix,offset);
241 switch (saveSel->getType())
243 case TreeItem::Branch:
245 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
247 case TreeItem::MapCenter:
249 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
251 case TreeItem::Image:
253 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
256 // other types shouldn't be safed directly...
261 // Save local settings
262 s+=settings.getDataXML (destPath);
265 if (getSelectedItem() && !saveSel )
266 s+=xml.valueElement("select",getSelectString());
269 s+=xml.endElement("vymmap");
271 //cout << s.toStdString() << endl;
273 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
277 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
281 for (int i=0; i<rootItem->branchCount(); i++)
282 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
286 void VymModel::setFilePath(QString fpath, QString destname)
288 if (fpath.isEmpty() || fpath=="")
295 filePath=fpath; // becomes absolute path
296 fileName=fpath; // gets stripped of path
297 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
299 // If fpath is not an absolute path, complete it
300 filePath=QDir(fpath).absPath();
301 fileDir=filePath.left (1+filePath.findRev ("/"));
303 // Set short name, too. Search from behind:
304 int i=fileName.findRev("/");
305 if (i>=0) fileName=fileName.remove (0,i+1);
307 // Forget the .vym (or .xml) for name of map
308 mapName=fileName.left(fileName.findRev(".",-1,true) );
312 void VymModel::setFilePath(QString fpath)
314 setFilePath (fpath,fpath);
317 QString VymModel::getFilePath()
322 QString VymModel::getFileName()
327 QString VymModel::getMapName()
332 QString VymModel::getDestPath()
337 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
339 ErrorCode err=success;
341 parseBaseHandler *handler;
345 case VymMap: handler=new parseVYMHandler; break;
346 case FreemindMap : handler=new parseFreemindHandler; break;
348 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
349 "Unknown FileType in VymModel::load()");
353 bool zipped_org=zipped;
357 selModel->clearSelection();
360 BranchItem *bi=getSelectedBranch();
361 if (!bi) return aborted;
362 if (lmode==ImportAdd)
363 saveStateChangingPart(
366 QString("addMapInsert (%1)").arg(fname),
367 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
369 saveStateChangingPart(
372 QString("addMapReplace(%1)").arg(fname),
373 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
377 // Create temporary directory for packing
379 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
382 QMessageBox::critical( 0, tr( "Critical Load Error" ),
383 tr("Couldn't create temporary directory before load\n"));
388 err=unzipDir (tmpZipDir,fname);
398 // Look for mapname.xml
399 xmlfile= fname.left(fname.findRev(".",-1,true));
400 xmlfile=xmlfile.section( '/', -1 );
401 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
402 if (!mfile.exists() )
404 // mapname.xml does not exist, well,
405 // maybe someone renamed the mapname.vym file...
406 // Try to find any .xml in the toplevel
407 // directory of the .vym file
408 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
409 if (flist.count()==1)
411 // Only one entry, take this one
412 xmlfile=tmpZipDir + "/"+flist.first();
415 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
416 *it=tmpZipDir + "/" + *it;
417 // TODO Multiple entries, load all (but only the first one into this ME)
418 //mainWindow->fileLoadFromTmp (flist);
419 //returnCode=1; // Silently forget this attempt to load
420 qWarning ("MainWindow::load (fn) multimap found...");
423 if (flist.isEmpty() )
425 QMessageBox::critical( 0, tr( "Critical Load Error" ),
426 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
429 } //file doesn't exist
431 xmlfile=mfile.name();
434 QFile file( xmlfile);
436 // I am paranoid: file should exist anyway
437 // according to check in mainwindow.
440 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
441 tr(QString("Couldn't open map %1").arg(file.name())));
445 bool blockSaveStateOrg=blockSaveState;
446 blockReposition=true;
448 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
449 QXmlInputSource source( file);
450 QXmlSimpleReader reader;
451 reader.setContentHandler( handler );
452 reader.setErrorHandler( handler );
453 handler->setModel ( this);
456 // We need to set the tmpDir in order to load files with rel. path
461 tmpdir=fname.left(fname.findRev("/",-1));
462 handler->setTmpDir (tmpdir);
463 handler->setInputFile (file.name());
464 handler->setLoadMode (lmode);
465 bool ok = reader.parse( source );
466 blockReposition=false;
467 blockSaveState=blockSaveStateOrg;
468 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
473 emitSelectionChanged();
479 autosaveTimer->stop();
482 // Reset timestamp to check for later updates of file
483 fileChangedTime=QFileInfo (destPath).lastModified();
486 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
487 tr( handler->errorProtocol() ) );
489 // Still return "success": the map maybe at least
490 // partially read by the parser
495 removeDir (QDir(tmpZipDir));
497 // Restore original zip state
504 ErrorCode VymModel::save (const SaveMode &savemode)
508 QString safeFilePath;
510 ErrorCode err=success;
514 mapFileName=mapName+".xml";
516 // use name given by user, even if he chooses .doc
517 mapFileName=fileName;
519 // Look, if we should zip the data:
522 QMessageBox mb( vymName,
523 tr("The map %1\ndid not use the compressed "
524 "vym file format.\nWriting it uncompressed will also write images \n"
525 "and flags and thus may overwrite files in the "
526 "given directory\n\nDo you want to write the map").arg(filePath),
527 QMessageBox::Warning,
528 QMessageBox::Yes | QMessageBox::Default,
530 QMessageBox::Cancel | QMessageBox::Escape);
531 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
532 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
533 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
536 case QMessageBox::Yes:
537 // save compressed (default file format)
540 case QMessageBox::No:
544 case QMessageBox::Cancel:
551 // First backup existing file, we
552 // don't want to add to old zip archives
556 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
558 QString backupFileName(destPath + "~");
559 QFile backupFile(backupFileName);
560 if (backupFile.exists() && !backupFile.remove())
562 QMessageBox::warning(0, tr("Save Error"),
563 tr("%1\ncould not be removed before saving").arg(backupFileName));
565 else if (!f.rename(backupFileName))
567 QMessageBox::warning(0, tr("Save Error"),
568 tr("%1\ncould not be renamed before saving").arg(destPath));
575 // Create temporary directory for packing
577 tmpZipDir=makeTmpDir (ok,"vym-zip");
580 QMessageBox::critical( 0, tr( "Critical Load Error" ),
581 tr("Couldn't create temporary directory before save\n"));
585 safeFilePath=filePath;
586 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
589 // Create mapName and fileDir
590 makeSubDirs (fileDir);
593 if (savemode==CompleteMap || selModel->selection().isEmpty())
596 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
599 autosaveTimer->stop();
604 if (selectionType()==TreeItem::Image)
607 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
608 // TODO take care of multiselections
611 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
614 qWarning ("ME::saveStringToDisk failed!");
620 if (err==success) err=zipDir (tmpZipDir,destPath);
623 removeDir (QDir(tmpZipDir));
625 // Restore original filepath outside of tmp zip dir
626 setFilePath (safeFilePath);
630 fileChangedTime=QFileInfo (destPath).lastModified();
634 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
636 QString pathDir=path.left(path.findRev("/"));
642 // We need to parse saved XML data
643 parseVYMHandler handler;
644 QXmlInputSource source( file);
645 QXmlSimpleReader reader;
646 reader.setContentHandler( &handler );
647 reader.setErrorHandler( &handler );
648 handler.setModel ( this);
649 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
650 if (undoSel.isEmpty())
654 handler.setLoadMode (NewMap);
658 handler.setLoadMode (ImportReplace);
660 blockReposition=true;
661 bool ok = reader.parse( source );
662 blockReposition=false;
665 // This should never ever happen
666 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
667 handler.errorProtocol());
670 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
673 bool VymModel::addMapInsertInt (const QString &path)
675 QString pathDir=path.left(path.findRev("/"));
681 // We need to parse saved XML data
682 parseVYMHandler handler;
683 QXmlInputSource source( file);
684 QXmlSimpleReader reader;
685 reader.setContentHandler( &handler );
686 reader.setErrorHandler( &handler );
687 handler.setModel (this);
688 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
689 handler.setLoadMode (ImportAdd);
690 blockReposition=true;
691 bool ok = reader.parse( source );
692 blockReposition=false;
693 if ( ok ) return true;
695 // This should never ever happen
696 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
697 handler.errorProtocol());
700 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
704 bool VymModel::addMapInsertInt (const QString &path, int pos)
706 BranchItem *selbi=getSelectedBranch();
709 if (addMapInsertInt (path))
711 if (selbi->depth()>0)
712 relinkBranch (selbi->getLastBranch(), selbi,pos);
716 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
720 qWarning ("ME::addMapInsertInt nothing selected");
724 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
726 ImageItem *ii=createImage(dst);
736 void VymModel::loadFloatImage ()
738 BranchItem *selbi=getSelectedBranch();
742 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
743 fd->setMode (Q3FileDialog::ExistingFiles);
744 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
745 ImagePreview *p =new ImagePreview (fd);
746 fd->setContentsPreviewEnabled( TRUE );
747 fd->setContentsPreview( p, p );
748 fd->setPreviewMode( Q3FileDialog::Contents );
749 fd->setCaption(vymName+" - " +tr("Load image"));
750 fd->setDir (lastImageDir);
753 if ( fd->exec() == QDialog::Accepted )
755 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
756 lastImageDir=QDir (fd->dirPath());
759 for (int j=0; j<fd->selectedFiles().count(); j++)
761 s=fd->selectedFiles().at(j);
762 ii=loadFloatImageInt (selbi,s);
763 //FIXME-3 check savestate for loadImage
769 QString ("loadImage (%1)").arg(s ),
770 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
773 // TODO loadFIO error handling
774 qWarning ("Failed to load "+s);
782 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
787 void VymModel::saveFloatImage ()
789 ImageItem *ii=getSelectedImage();
792 QFileDialog *fd=new QFileDialog( NULL);
793 fd->setFilters (imageIO.getFilters());
794 fd->setCaption(vymName+" - " +tr("Save image"));
795 fd->setFileMode( QFileDialog::AnyFile );
796 fd->setDirectory (lastImageDir);
797 // fd->setSelection (fio->getOriginalFilename());
801 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
803 fn=fd->selectedFiles().at(0);
804 if (QFile (fn).exists() )
806 QMessageBox mb( vymName,
807 tr("The file %1 exists already.\n"
808 "Do you want to overwrite it?").arg(fn),
809 QMessageBox::Warning,
810 QMessageBox::Yes | QMessageBox::Default,
811 QMessageBox::Cancel | QMessageBox::Escape,
812 QMessageBox::NoButton );
814 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
815 mb.setButtonText( QMessageBox::No, tr("Cancel"));
818 case QMessageBox::Yes:
821 case QMessageBox::Cancel:
828 saveFloatImageInt (ii,fd->selectedFilter(),fn );
835 void VymModel::importDirInt(BranchItem *dst, QDir d)
837 BranchItem *selbi=getSelectedBranch();
841 // Traverse directories
842 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
843 QFileInfoList list = d.entryInfoList();
846 for (int i = 0; i < list.size(); ++i)
849 if (fi.fileName() != "." && fi.fileName() != ".." )
851 bi=addNewBranchInt(dst,-2);
852 bi->setHeading (fi.fileName() ); // FIXME-3 check this
853 bi->setHeadingColor (QColor("blue"));
855 if ( !d.cd(fi.fileName()) )
856 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
859 // Recursively add subdirs
866 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
867 list = d.entryInfoList();
869 for (int i = 0; i < list.size(); ++i)
872 bi=addNewBranchInt (dst,-2);
873 bi->setHeading (fi.fileName() );
874 bi->setHeadingColor (QColor("black"));
875 if (fi.fileName().right(4) == ".vym" )
876 bi->setVymLink (fi.filePath());
881 void VymModel::importDirInt (const QString &s)
883 BranchItem *selbi=getSelectedBranch();
886 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
889 importDirInt (selbi,d);
893 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
895 BranchItem *selbi=getSelectedBranch();
899 filters <<"VYM map (*.vym)";
900 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
901 fd->setMode (QFileDialog::DirectoryOnly);
902 fd->setFilters (filters);
903 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
907 if ( fd->exec() == QDialog::Accepted )
909 importDirInt (fd->selectedFile() );
911 //FIXME-3 VM needed? scene()->update();
917 void VymModel::autosave()
922 cout << "VymModel::autosave rejected due to missing filePath\n";
925 QDateTime now=QDateTime().currentDateTime();
927 // Disable autosave, while we have gone back in history
928 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
929 if (redosAvail>0) return;
931 // Also disable autosave for new map without filename
932 if (filePath.isEmpty()) return;
935 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
937 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
938 mainWindow->fileSave (this);
941 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
946 void VymModel::fileChanged()
948 // Check if file on disk has changed meanwhile
949 if (!filePath.isEmpty())
951 QDateTime tmod=QFileInfo (filePath).lastModified();
952 if (tmod>fileChangedTime)
954 // FIXME-3 VM switch to current mapeditor and finish lineedits...
955 QMessageBox mb( vymName,
956 tr("The file of the map on disk has changed:\n\n"
957 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
958 QMessageBox::Question,
960 QMessageBox::Cancel | QMessageBox::Default,
961 QMessageBox::NoButton );
963 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
964 mb.setButtonText( QMessageBox::No, tr("Ignore"));
967 case QMessageBox::Yes:
969 load (filePath,NewMap,fileType);
970 case QMessageBox::Cancel:
971 fileChangedTime=tmod; // allow autosave to overwrite newer file!
977 bool VymModel::isDefault()
982 void VymModel::makeDefault()
988 bool VymModel::hasChanged()
993 void VymModel::setChanged()
996 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1000 latestAddedItem=NULL;
1004 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1006 if (!lmo || !lmo->getTreeItem() ) return QString();
1007 return getObjectName (lmo->getTreeItem() );
1011 QString VymModel::getObjectName (TreeItem *ti)
1014 if (!ti) return QString("Error: NULL has no name!");
1016 if (s=="") s="unnamed";
1018 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1021 void VymModel::redo()
1023 // Can we undo at all?
1024 if (redosAvail<1) return;
1026 bool blockSaveStateOrg=blockSaveState;
1027 blockSaveState=true;
1031 if (undosAvail<stepsTotal) undosAvail++;
1033 if (curStep>stepsTotal) curStep=1;
1034 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1035 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1036 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1037 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1038 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1039 QString version=undoSet.readEntry ("/history/version");
1041 /* TODO Maybe check for version, if we save the history
1042 if (!checkVersion(version))
1043 QMessageBox::warning(0,tr("Warning"),
1044 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1047 // Find out current undo directory
1048 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1052 cout << "VymModel::redo() begin\n";
1053 cout << " undosAvail="<<undosAvail<<endl;
1054 cout << " redosAvail="<<redosAvail<<endl;
1055 cout << " curStep="<<curStep<<endl;
1056 cout << " ---------------------------"<<endl;
1057 cout << " comment="<<comment.toStdString()<<endl;
1058 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1059 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1060 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1061 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1062 cout << " ---------------------------"<<endl<<endl;
1065 // select object before redo
1066 if (!redoSelection.isEmpty())
1067 select (redoSelection);
1072 parseAtom (redoCommand,noErr,errMsg);
1074 blockSaveState=blockSaveStateOrg;
1076 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1077 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1078 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1079 undoSet.writeSettings(histPath);
1081 mainWindow->updateHistory (undoSet);
1084 /* TODO remove testing
1085 cout << "ME::redo() end\n";
1086 cout << " undosAvail="<<undosAvail<<endl;
1087 cout << " redosAvail="<<redosAvail<<endl;
1088 cout << " curStep="<<curStep<<endl;
1089 cout << " ---------------------------"<<endl<<endl;
1095 bool VymModel::isRedoAvailable()
1097 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1103 void VymModel::undo()
1105 // Can we undo at all?
1106 if (undosAvail<1) return;
1108 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1110 bool blockSaveStateOrg=blockSaveState;
1111 blockSaveState=true;
1113 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1114 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1115 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1116 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1117 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1118 QString version=undoSet.readEntry ("/history/version");
1120 /* TODO Maybe check for version, if we save the history
1121 if (!checkVersion(version))
1122 QMessageBox::warning(0,tr("Warning"),
1123 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1126 // Find out current undo directory
1127 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1129 // select object before undo
1130 if (!select (undoSelection))
1132 qWarning ("VymModel::undo() Could not select object for undo");
1139 cout << "VymModel::undo() begin\n";
1140 cout << " undosAvail="<<undosAvail<<endl;
1141 cout << " redosAvail="<<redosAvail<<endl;
1142 cout << " curStep="<<curStep<<endl;
1143 cout << " ---------------------------"<<endl;
1144 cout << " comment="<<comment.toStdString()<<endl;
1145 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1146 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1147 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1148 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1149 cout << " ---------------------------"<<endl<<endl;
1154 parseAtom (undoCommand,noErr,errMsg);
1158 if (curStep<1) curStep=stepsTotal;
1162 blockSaveState=blockSaveStateOrg;
1164 cout << "VymModel::undo() end\n";
1165 cout << " undosAvail="<<undosAvail<<endl;
1166 cout << " redosAvail="<<redosAvail<<endl;
1167 cout << " curStep="<<curStep<<endl;
1168 cout << " ---------------------------"<<endl<<endl;
1171 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1172 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1173 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1174 undoSet.writeSettings(histPath);
1176 mainWindow->updateHistory (undoSet);
1178 //emitSelectionChanged();
1181 bool VymModel::isUndoAvailable()
1183 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1189 void VymModel::gotoHistoryStep (int i)
1191 // Restore variables
1192 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1193 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1195 if (i<0) i=undosAvail+redosAvail;
1197 // Clicking above current step makes us undo things
1200 for (int j=0; j<undosAvail-i; j++) undo();
1203 // Clicking below current step makes us redo things
1205 for (int j=undosAvail; j<i; j++)
1207 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1211 // And ignore clicking the current row ;-)
1215 QString VymModel::getHistoryPath()
1217 QString histName(QString("history-%1").arg(curStep));
1218 return (tmpMapDir+"/"+histName);
1221 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1223 sendData(redoCom); //FIXME-3 testing
1228 if (blockSaveState) return;
1230 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1232 // Find out current undo directory
1233 if (undosAvail<stepsTotal) undosAvail++;
1235 if (curStep>stepsTotal) curStep=1;
1237 QString backupXML="";
1238 QString histDir=getHistoryPath();
1239 QString bakMapPath=histDir+"/map.xml";
1241 // Create histDir if not available
1244 makeSubDirs (histDir);
1246 // Save depending on how much needs to be saved
1248 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1250 QString undoCommand="";
1251 if (savemode==UndoCommand)
1253 undoCommand=undoCom;
1255 else if (savemode==PartOfMap )
1257 undoCommand=undoCom;
1258 undoCommand.replace ("PATH",bakMapPath);
1262 if (!backupXML.isEmpty())
1263 // Write XML Data to disk
1264 saveStringToDisk (bakMapPath,backupXML);
1266 // We would have to save all actions in a tree, to keep track of
1267 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1270 // Write the current state to disk
1271 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1272 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1273 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1274 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1275 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1276 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1277 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1278 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1279 undoSet.setEntry (QString("/history/version"),vymVersion);
1280 undoSet.writeSettings(histPath);
1284 // TODO remove after testing
1285 //cout << " into="<< histPath.toStdString()<<endl;
1286 cout << " stepsTotal="<<stepsTotal<<
1287 ", undosAvail="<<undosAvail<<
1288 ", redosAvail="<<redosAvail<<
1289 ", curStep="<<curStep<<endl;
1290 cout << " ---------------------------"<<endl;
1291 cout << " comment="<<comment.toStdString()<<endl;
1292 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1293 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1294 cout << " redoCom="<<redoCom.toStdString()<<endl;
1295 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1296 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1297 cout << " ---------------------------"<<endl;
1300 mainWindow->updateHistory (undoSet);
1306 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1308 // save the selected part of the map, Undo will replace part of map
1309 QString undoSelection="";
1311 undoSelection=getSelectString(undoSel);
1313 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1314 QString redoSelection="";
1316 redoSelection=getSelectString(undoSel);
1318 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1321 saveState (PartOfMap,
1322 undoSelection, "addMapReplace (\"PATH\")",
1328 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1332 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1335 QString undoSelection;
1336 QString redoSelection=getSelectString(redoSel);
1337 if (redoSel->getType()==TreeItem::Branch)
1339 undoSelection=getSelectString (redoSel->parent());
1340 // save the selected branch of the map, Undo will insert part of map
1341 saveState (PartOfMap,
1342 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1343 redoSelection, "delete ()",
1347 if (redoSel->getType()==TreeItem::MapCenter)
1349 // save the selected branch of the map, Undo will insert part of map
1350 saveState (PartOfMap,
1351 undoSelection, QString("addMapInsert (\"PATH\")"),
1352 redoSelection, "delete ()",
1359 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1361 // "Normal" savestate: save commands, selections and comment
1362 // so just save commands for undo and redo
1363 // and use current selection
1365 QString redoSelection="";
1366 if (redoSel) redoSelection=getSelectString(redoSel);
1367 QString undoSelection="";
1368 if (undoSel) undoSelection=getSelectString(undoSel);
1370 saveState (UndoCommand,
1377 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1379 // "Normal" savestate: save commands, selections and comment
1380 // so just save commands for undo and redo
1381 // and use current selection
1382 saveState (UndoCommand,
1389 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1391 // "Normal" savestate applied to model (no selection needed):
1392 // save commands and comment
1393 saveState (UndoCommand,
1401 QGraphicsScene* VymModel::getScene ()
1406 TreeItem* VymModel::findBySelectString(QString s)
1408 if (s.isEmpty() ) return NULL;
1410 // Old maps don't have multiple mapcenters and don't save full path
1411 if (s.left(2) !="mc")
1414 QStringList parts=s.split (",");
1417 TreeItem *ti=rootItem;
1419 while (!parts.isEmpty() )
1421 typ=parts.first().left(2);
1422 n=parts.first().right(parts.first().length() - 3).toInt();
1423 parts.removeFirst();
1424 if (typ=="mc" || typ=="bo")
1425 ti=ti->getBranchNum (n);
1427 ti=ti->getImageNum (n);
1429 ti=ti->getAttributeNum (n);
1431 ti=ti->getXLinkNum (n);
1432 if(!ti) return NULL;
1437 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1439 BranchItem *cur=NULL;
1440 BranchItem *prev=NULL;
1441 nextBranch(cur,prev);
1444 if (i==cur->getID() ) return cur;
1445 nextBranch(cur,prev);
1450 //////////////////////////////////////////////
1452 //////////////////////////////////////////////
1453 void VymModel::setVersion (const QString &s)
1458 QString VymModel::getVersion()
1463 void VymModel::setAuthor (const QString &s)
1466 QString ("setMapAuthor (\"%1\")").arg(author),
1467 QString ("setMapAuthor (\"%1\")").arg(s),
1468 QString ("Set author of map to \"%1\"").arg(s)
1473 QString VymModel::getAuthor()
1478 void VymModel::setComment (const QString &s)
1481 QString ("setMapComment (\"%1\")").arg(comment),
1482 QString ("setMapComment (\"%1\")").arg(s),
1483 QString ("Set comment of map")
1488 QString VymModel::getComment ()
1493 QString VymModel::getDate ()
1495 return QDate::currentDate().toString ("yyyy-MM-dd");
1498 int VymModel::branchCount()
1501 BranchItem *cur=NULL;
1502 BranchItem *prev=NULL;
1503 nextBranch(cur,prev);
1507 nextBranch(cur,prev);
1512 void VymModel::setSortFilter (const QString &s)
1515 emit (sortFilterChanged (sortFilter));
1518 QString VymModel::getSortFilter ()
1523 void VymModel::setHeading(const QString &s)
1525 BranchItem *selbi=getSelectedBranch();
1530 "setHeading (\""+selbi->getHeading()+"\")",
1532 "setHeading (\""+s+"\")",
1533 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1534 selbi->setHeading(s );
1535 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1537 emitSelectionChanged();
1541 QString VymModel::getHeading()
1543 TreeItem *selti=getSelectedItem();
1545 return selti->getHeading();
1550 void VymModel::setNote(const QString &s)
1552 TreeItem *selti=getSelectedItem();
1555 emitNoteHasChanged(selti);
1558 "setNote (\""+selti->getNote()+"\")",
1560 "setNote (\""+s+"\")",
1561 QString("Set note of %1 ").arg(getObjectName(selti)) );
1566 QString VymModel::getNote()
1568 TreeItem *selti=getSelectedItem();
1570 return selti->getNote();
1575 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1577 // Generate map containing _all_ URLs and branches
1579 QMap <QString,BranchItem*> map;
1580 BranchItem *cur=NULL;
1581 BranchItem *prev=NULL;
1582 nextBranch(cur,prev);
1587 map.insertMulti (u,cur);
1588 nextBranch(cur,prev);
1591 // Extract duplicate URLs
1592 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1593 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1594 while (i != map.constEnd())
1596 if (i!=map.constBegin() && i.key()==firstdup.key())
1598 if ( i-1==firstdup )
1600 cout << firstdup.key().toStdString() << endl;
1601 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1603 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1611 BranchItem* VymModel::findText (QString s, bool cs)
1613 if (!s.isEmpty() && s!=findString)
1619 QTextDocument::FindFlags flags=0;
1620 if (cs) flags=QTextDocument::FindCaseSensitively;
1623 { // Nothing found or new find process
1625 // nothing found, start again
1629 nextBranch (findCurrent,findPrevious);
1631 bool searching=true;
1632 bool foundNote=false;
1633 while (searching && !EOFind)
1637 // Searching in Note
1638 if (findCurrent->getNote().contains(findString,cs))
1640 select (findCurrent);
1642 if (getSelectedBranch()!=itFind)
1645 emitShowSelection();
1648 if (textEditor->findText(findString,flags))
1654 // Searching in Heading
1655 if (searching && findCurrent->getHeading().contains (findString,cs) )
1657 select(findCurrent);
1663 if (!nextBranch(findCurrent,findPrevious) )
1666 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1669 return getSelectedBranch();
1674 void VymModel::findReset()
1675 { // Necessary if text to find changes during a find process
1682 void VymModel::emitShowFindWidget()
1684 emit (showFindWidget());
1687 void VymModel::setScene (QGraphicsScene *s)
1692 void VymModel::setURL(const QString &url)
1694 TreeItem *selti=getSelectedItem();
1697 QString oldurl=selti->getURL();
1698 selti->setURL (url);
1701 QString ("setURL (\"%1\")").arg(oldurl),
1703 QString ("setURL (\"%1\")").arg(url),
1704 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1707 emitDataHasChanged (selti);
1708 emitShowSelection();
1712 QString VymModel::getURL()
1714 TreeItem *selti=getSelectedItem();
1716 return selti->getURL();
1721 QStringList VymModel::getURLs(bool ignoreScrolled)
1724 BranchItem *selbi=getSelectedBranch();
1725 BranchItem *cur=selbi;
1726 BranchItem *prev=NULL;
1729 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1730 urls.append( cur->getURL());
1731 cur=nextBranch (cur,prev,true,selbi);
1737 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1739 BranchItem *bi=getSelectedBranch();
1742 BranchObj *bo=(BranchObj*)(bi->getLMO());
1745 QString s=bo->getFrameTypeName();
1746 bo->setFrameType (t);
1747 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1748 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1750 bo->updateLinkGeometry();
1755 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1757 BranchItem *bi=getSelectedBranch();
1760 BranchObj *bo=(BranchObj*)(bi->getLMO());
1763 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1764 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1765 bo->setFrameType (s);
1767 bo->updateLinkGeometry();
1772 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1775 BranchItem *bi=getSelectedBranch();
1778 BranchObj *bo=(BranchObj*)(bi->getLMO());
1781 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1782 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1783 bo->setFramePenColor (c);
1788 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1790 BranchItem *bi=getSelectedBranch();
1793 BranchObj *bo=(BranchObj*)(bi->getLMO());
1796 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1797 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1798 bo->setFrameBrushColor (c);
1803 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1805 BranchItem *bi=getSelectedBranch();
1808 BranchObj *bo=(BranchObj*)(bi->getLMO());
1811 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1812 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1813 bo->setFramePadding (i);
1815 bo->updateLinkGeometry();
1820 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1822 BranchItem *bi=getSelectedBranch();
1825 BranchObj *bo=(BranchObj*)(bi->getLMO());
1828 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1829 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1830 bo->setFrameBorderWidth (i);
1832 bo->updateLinkGeometry();
1837 void VymModel::setIncludeImagesVer(bool b)
1839 BranchItem *bi=getSelectedBranch();
1842 QString u= b ? "false" : "true";
1843 QString r=!b ? "false" : "true";
1847 QString("setIncludeImagesVertically (%1)").arg(u),
1849 QString("setIncludeImagesVertically (%1)").arg(r),
1850 QString("Include images vertically in %1").arg(getObjectName(bi))
1852 bi->setIncludeImagesVer(b);
1853 emitDataHasChanged ( bi);
1858 void VymModel::setIncludeImagesHor(bool b)
1860 BranchItem *bi=getSelectedBranch();
1863 QString u= b ? "false" : "true";
1864 QString r=!b ? "false" : "true";
1868 QString("setIncludeImagesHorizontally (%1)").arg(u),
1870 QString("setIncludeImagesHorizontally (%1)").arg(r),
1871 QString("Include images horizontally in %1").arg(getObjectName(bi))
1873 bi->setIncludeImagesHor(b);
1874 emitDataHasChanged ( bi);
1879 void VymModel::setHideLinkUnselected (bool b)
1881 TreeItem *ti=getSelectedItem();
1882 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1884 QString u= b ? "false" : "true";
1885 QString r=!b ? "false" : "true";
1889 QString("setHideLinkUnselected (%1)").arg(u),
1891 QString("setHideLinkUnselected (%1)").arg(r),
1892 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1894 ((MapItem*)ti)->setHideLinkUnselected(b);
1898 void VymModel::setHideExport(bool b)
1900 TreeItem *ti=getSelectedItem();
1902 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1904 ti->setHideInExport (b);
1905 QString u= b ? "false" : "true";
1906 QString r=!b ? "false" : "true";
1910 QString ("setHideExport (%1)").arg(u),
1912 QString ("setHideExport (%1)").arg(r),
1913 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1915 emitDataHasChanged(ti);
1916 emitSelectionChanged();
1919 // emitSelectionChanged();
1920 // FIXME-3 VM needed? scene()->update();
1924 void VymModel::toggleHideExport()
1926 TreeItem *selti=getSelectedItem();
1928 setHideExport ( !selti->hideInExport() );
1931 void VymModel::addTimestamp() //FIXME-3 new function, localize
1933 BranchItem *selbi=addNewBranch();
1936 QDate today=QDate::currentDate();
1938 selbi->setHeading (QString ("%1-%2-%3")
1939 .arg(today.year(),4,10,c)
1940 .arg(today.month(),2,10,c)
1941 .arg(today.day(),2,10,c));
1942 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1949 void VymModel::copy()
1951 TreeItem *selti=getSelectedItem();
1953 (selti->getType() == TreeItem::Branch ||
1954 selti->getType() == TreeItem::MapCenter ||
1955 selti->getType() == TreeItem::Image ))
1957 if (redosAvail == 0)
1960 QString s=getSelectString(selti);
1961 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1962 curClipboard=curStep;
1965 // Copy also to global clipboard, because we are at last step in history
1966 QString bakMapName(QString("history-%1").arg(curStep));
1967 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1968 copyDir (bakMapDir,clipboardDir );
1970 clipboardEmpty=false;
1976 void VymModel::pasteNoSave(const int &n)
1978 bool old=blockSaveState;
1979 blockSaveState=true;
1980 bool zippedOrg=zipped;
1981 if (redosAvail > 0 || n!=0)
1983 // Use the "historical" buffer
1984 QString bakMapName(QString("history-%1").arg(n));
1985 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1986 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1988 // Use the global buffer
1989 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1994 void VymModel::paste()
1996 BranchItem *selbi=getSelectedBranch();
1999 saveStateChangingPart(
2002 QString ("paste (%1)").arg(curClipboard),
2003 QString("Paste to %1").arg( getObjectName(selbi))
2010 void VymModel::cut()
2012 TreeItem *selti=getSelectedItem();
2013 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2021 bool VymModel::moveUp(BranchItem *bi)
2023 if (bi && bi->canMoveUp())
2024 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2029 void VymModel::moveUp()
2031 BranchItem *selbi=getSelectedBranch();
2034 QString oldsel=getSelectString();
2037 getSelectString(),"moveDown ()",
2039 QString("Move up %1").arg(getObjectName(selbi)));
2043 bool VymModel::moveDown(BranchItem *bi)
2045 if (bi && bi->canMoveDown())
2046 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2051 void VymModel::moveDown()
2053 BranchItem *selbi=getSelectedBranch();
2056 QString oldsel=getSelectString();
2057 if ( moveDown(selbi))
2059 getSelectString(),"moveUp ()",
2060 oldsel,"moveDown ()",
2061 QString("Move down %1").arg(getObjectName(selbi)));
2065 void VymModel::detach()
2067 BranchItem *selbi=getSelectedBranch();
2068 if (selbi && selbi->depth()>0)
2070 // if no relPos have been set before, try to use current rel positions
2071 if (selbi->getLMO())
2072 for (int i=0; i<selbi->branchCount();++i)
2073 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2075 QString oldsel=getSelectString();
2078 BranchObj *bo=selbi->getBranchObj();
2079 if (bo) p=bo->getAbsPos();
2080 QString parsel=getSelectString(selbi->parent());
2081 if ( relinkBranch (selbi,rootItem,-1) )
2083 getSelectString (selbi),
2084 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2087 QString("Detach %1").arg(getObjectName(selbi))
2092 void VymModel::sortChildren(bool inverse)
2094 BranchItem* selbi=getSelectedBranch();
2097 if(selbi->branchCount()>1)
2101 saveStateChangingPart(
2102 selbi,selbi, "sortChildren ()",
2103 QString("Sort children of %1").arg(getObjectName(selbi)));
2105 selbi->sortChildren(inverse);
2107 emitShowSelection();
2112 BranchItem* VymModel::createMapCenter()
2114 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2118 BranchItem* VymModel::createBranch(BranchItem *dst)
2121 return addNewBranchInt (dst,-2);
2126 ImageItem* VymModel::createImage(BranchItem *dst)
2133 QList<QVariant> cData;
2134 cData << "new" << "undef";
2136 ImageItem *newii=new ImageItem(cData) ;
2137 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2139 emit (layoutAboutToBeChanged() );
2142 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2143 n=dst->getRowNumAppend(newii);
2144 beginInsertRows (parix,n,n);
2145 dst->appendChild (newii);
2148 emit (layoutChanged() );
2150 // save scroll state. If scrolled, automatically select
2151 // new branch in order to tmp unscroll parent...
2152 newii->createMapObj(mapScene);
2159 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2166 QList<QVariant> cData;
2167 cData << "new xLink"<<"undef";
2169 XLinkItem *newxli=new XLinkItem(cData) ;
2170 newxli->setBegin (bi);
2172 emit (layoutAboutToBeChanged() );
2175 n=bi->getRowNumAppend(newxli);
2176 beginInsertRows (parix,n,n);
2177 bi->appendChild (newxli);
2180 emit (layoutChanged() );
2182 // save scroll state. If scrolled, automatically select
2183 // new branch in order to tmp unscroll parent...
2186 newxli->createMapObj(mapScene);
2194 AttributeItem* VymModel::addAttribute()
2196 BranchItem *selbi=getSelectedBranch();
2199 QList<QVariant> cData;
2200 cData << "new attribute" << "undef";
2201 AttributeItem *a=new AttributeItem (cData);
2202 if (addAttribute (a)) return a;
2207 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2209 BranchItem *selbi=getSelectedBranch();
2212 emit (layoutAboutToBeChanged() );
2214 QModelIndex parix=index(selbi);
2215 int n=selbi->getRowNumAppend (ai);
2216 beginInsertRows (parix,n,n);
2217 selbi->appendChild (ai);
2220 emit (layoutChanged() );
2222 ai->createMapObj(mapScene); //FIXME-2 check that...
2229 BranchItem* VymModel::addMapCenter ()
2231 BranchItem *bi=addMapCenter (contextPos);
2233 emitShowSelection();
2238 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2239 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2244 BranchItem* VymModel::addMapCenter(QPointF absPos)
2245 // createMapCenter could then probably be merged with createBranch
2249 QModelIndex parix=index(rootItem);
2251 QList<QVariant> cData;
2252 cData << "VM:addMapCenter" << "undef";
2253 BranchItem *newbi=new BranchItem (cData,rootItem);
2254 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2255 int n=rootItem->getRowNumAppend (newbi);
2257 emit (layoutAboutToBeChanged() );
2258 beginInsertRows (parix,n,n);
2260 rootItem->appendChild (newbi);
2263 emit (layoutChanged() );
2266 newbi->setPositionMode (MapItem::Absolute);
2267 BranchObj *bo=newbi->createMapObj(mapScene);
2268 if (bo) bo->move (absPos);
2273 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2275 // Depending on pos:
2276 // -3 insert in children of parent above selection
2277 // -2 add branch to selection
2278 // -1 insert in children of parent below selection
2279 // 0..n insert in children of parent at pos
2282 QList<QVariant> cData;
2283 cData << "" << "undef";
2288 BranchItem *newbi=new BranchItem (cData);
2289 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2291 emit (layoutAboutToBeChanged() );
2297 n=parbi->getRowNumAppend (newbi);
2298 beginInsertRows (parix,n,n);
2299 parbi->appendChild (newbi);
2301 }else if (num==-1 || num==-3)
2303 // insert below selection
2304 parbi=(BranchItem*)dst->parent();
2307 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2308 beginInsertRows (parix,n,n);
2309 parbi->insertBranch(n,newbi);
2312 emit (layoutChanged() );
2314 // Set color of heading to that of parent
2315 newbi->setHeadingColor (parbi->getHeadingColor());
2317 // save scroll state. If scrolled, automatically select
2318 // new branch in order to tmp unscroll parent...
2319 newbi->createMapObj(mapScene);
2324 BranchItem* VymModel::addNewBranch(int pos)
2326 // Different meaning than num in addNewBranchInt!
2330 BranchItem *newbi=NULL;
2331 BranchItem *selbi=getSelectedBranch();
2335 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2337 newbi=addNewBranchInt (selbi,pos-2);
2345 QString ("addBranch (%1)").arg(pos),
2346 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2349 // emitSelectionChanged(); FIXME-3
2350 latestAddedItem=newbi;
2351 // In Network mode, the client needs to know where the new branch is,
2352 // so we have to pass on this information via saveState.
2353 // TODO: Get rid of this positioning workaround
2354 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2355 sendData ("selectLatestAdded ()");
2356 sendData (QString("move %1").arg(ps));
2365 BranchItem* VymModel::addNewBranchBefore()
2367 BranchItem *newbi=NULL;
2368 BranchItem *selbi=getSelectedBranch();
2369 if (selbi && selbi->getType()==TreeItem::Branch)
2370 // We accept no MapCenter here, so we _have_ a parent
2372 //QPointF p=bo->getRelPos();
2375 // add below selection
2376 newbi=addNewBranchInt (selbi,-1);
2380 //newbi->move2RelPos (p);
2382 // Move selection to new branch
2383 relinkBranch (selbi,newbi,0);
2385 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2386 QString ("Add branch before %1").arg(getObjectName(selbi)));
2388 // FIXME-3 needed? reposition();
2389 // emitSelectionChanged(); FIXME-3
2395 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2401 // Do we need to update frame type?
2402 bool keepFrame=false;
2405 emit (layoutAboutToBeChanged() );
2406 BranchItem *branchpi=(BranchItem*)branch->parent();
2407 // Remove at current position
2408 int n=branch->childNum();
2410 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2411 // error occured if relinking branch to empty mainbranch
2412 cout<<"VM::relinkBranch:\n";
2413 cout<<" b="<<branch->getHeadingStd()<<endl;
2414 cout<<" dst="<<dst->getHeadingStd()<<endl;
2415 cout<<" pos="<<pos<<endl;
2416 cout<<" n1="<<n<<endl;
2418 beginRemoveRows (index(branchpi),n,n);
2419 branchpi->removeChild (n);
2422 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2424 // Append as last branch to dst
2425 if (dst->branchCount()==0)
2428 n=dst->getFirstBranch()->childNumber();
2429 beginInsertRows (index(dst),n+pos,n+pos);
2430 dst->insertBranch (pos,branch);
2433 // Correct type if necessesary
2434 if (branch->getType()==TreeItem::MapCenter)
2435 branch->setType(TreeItem::Branch);
2437 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2438 branch->updateStyles(keepFrame);
2440 emit (layoutChanged() );
2441 reposition(); // both for moveUp/Down and relinking
2442 if (dst->isScrolled() )
2445 branch->updateVisibility();
2454 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2458 emit (layoutAboutToBeChanged() );
2460 BranchItem *pi=(BranchItem*)(image->parent());
2461 QString oldParString=getSelectString (pi);
2462 // Remove at current position
2463 int n=image->childNum();
2464 beginRemoveRows (index(pi),n,n);
2465 pi->removeChild (n);
2469 QModelIndex dstix=index(dst);
2470 n=dst->getRowNumAppend (image);
2471 beginInsertRows (dstix,n,n+1);
2472 dst->appendChild (image);
2475 // Set new parent also for lmo
2476 if (image->getLMO() && dst->getLMO() )
2477 image->getLMO()->setParObj (dst->getLMO() );
2479 emit (layoutChanged() );
2482 QString("relinkTo (\"%1\")").arg(oldParString),
2484 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2485 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2491 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2493 BranchItem *selbi=getSelectedBranch();
2498 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2500 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2503 if (pi->isScrolled() && pi->branchCount()==0)
2506 emitDataHasChanged(pi);
2509 emitShowSelection();
2513 TreeItem *ti=getSelectedItem();
2515 { // Delete other item
2516 TreeItem *pi=ti->parent();
2518 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2520 saveStateChangingPart(
2524 QString("Delete %1").arg(getObjectName(ti))
2528 emitDataHasChanged (pi);
2531 emitShowSelection();
2532 } else if (ti->getType()==TreeItem::XLink)
2534 //FIXME-2 savestate for deleting xlink missing
2537 qWarning ("VymmModel::deleteSelection() unknown type?!");
2541 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2544 BranchItem *selbi=getSelectedBranch();
2548 // Don't use this on mapcenter
2549 if (selbi->depth()<2) return;
2551 pi=(BranchItem*)(selbi->parent());
2552 // Check if we have childs at all to keep
2553 if (selbi->branchCount()==0)
2560 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2561 saveStateChangingPart(
2564 "deleteKeepChildren ()",
2565 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2568 QString sel=getSelectString(selbi);
2570 int pos=selbi->num();
2571 BranchItem *bi=selbi->getFirstBranch();
2574 relinkBranch (bi,pi,pos);
2575 bi=selbi->getFirstBranch();
2581 BranchObj *bo=getSelectedBranchObj();
2584 bo->move2RelPos (p);
2590 void VymModel::deleteChildren()
2593 BranchItem *selbi=getSelectedBranch();
2596 saveStateChangingPart(
2599 "deleteChildren ()",
2600 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2602 emit (layoutAboutToBeChanged() );
2604 QModelIndex ix=index (selbi);
2605 int n=selbi->branchCount()-1;
2606 beginRemoveRows (ix,0,n);
2607 removeRows (0,n+1,ix);
2609 if (selbi->isScrolled()) selbi->unScroll();
2610 emit (layoutChanged() );
2615 TreeItem* VymModel::deleteItem (TreeItem *ti)
2619 TreeItem *pi=ti->parent();
2620 QModelIndex parentIndex=index(pi);
2622 emit (layoutAboutToBeChanged() );
2624 int n=ti->childNum();
2625 beginRemoveRows (parentIndex,n,n);
2626 removeRows (n,1,parentIndex);
2630 emit (layoutChanged() );
2631 if (pi->depth()>=0) return pi;
2636 void VymModel::clearItem (TreeItem *ti)
2640 QModelIndex parentIndex=index(ti);
2641 if (!parentIndex.isValid()) return;
2643 int n=ti->childCount();
2646 emit (layoutAboutToBeChanged() );
2648 beginRemoveRows (parentIndex,0,n-1);
2649 removeRows (0,n,parentIndex);
2653 emit (layoutChanged() );
2659 bool VymModel::scrollBranch(BranchItem *bi)
2663 if (bi->isScrolled()) return false;
2664 if (bi->branchCount()==0) return false;
2665 if (bi->depth()==0) return false;
2666 if (bi->toggleScroll())
2674 QString ("%1 ()").arg(u),
2676 QString ("%1 ()").arg(r),
2677 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2679 emitDataHasChanged(bi);
2680 emitSelectionChanged();
2681 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2688 bool VymModel::unscrollBranch(BranchItem *bi)
2692 if (!bi->isScrolled()) return false;
2693 if (bi->branchCount()==0) return false;
2694 if (bi->depth()==0) return false;
2695 if (bi->toggleScroll())
2703 QString ("%1 ()").arg(u),
2705 QString ("%1 ()").arg(r),
2706 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2708 emitDataHasChanged(bi);
2709 emitSelectionChanged();
2710 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2717 void VymModel::toggleScroll()
2719 BranchItem *bi=(BranchItem*)getSelectedBranch();
2720 if (bi && bi->isBranchLikeType() )
2722 if (bi->isScrolled())
2723 unscrollBranch (bi);
2727 // saveState & reposition are called in above functions
2730 void VymModel::unscrollChildren()
2732 BranchItem *selbi=getSelectedBranch();
2733 BranchItem *prev=NULL;
2734 BranchItem *cur=selbi;
2737 saveStateChangingPart(
2740 QString ("unscrollChildren ()"),
2741 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2745 if (cur->isScrolled())
2747 cur->toggleScroll();
2748 emitDataHasChanged (cur);
2750 cur=nextBranch (cur,prev,true,selbi);
2757 void VymModel::emitExpandAll()
2759 emit (expandAll() );
2762 void VymModel::emitExpandOneLevel()
2764 emit (expandOneLevel () );
2767 void VymModel::emitCollapseOneLevel()
2769 emit (collapseOneLevel () );
2772 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2774 BranchItem *bi=getSelectedBranch();
2778 if (bi->isActiveStandardFlag(name))
2790 QString("%1 (\"%2\")").arg(u).arg(name),
2792 QString("%1 (\"%2\")").arg(r).arg(name),
2793 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2794 bi->toggleStandardFlag (name, master);
2796 emitSelectionChanged();
2800 void VymModel::addFloatImage (const QPixmap &img)
2802 BranchItem *selbi=getSelectedBranch();
2805 ImageItem *ii=createImage (selbi);
2807 ii->setOriginalFilename("No original filename (image added by dropevent)");
2808 QString s=getSelectString(selbi);
2809 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2810 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2812 // FIXME-3 VM needed? scene()->update();
2817 void VymModel::colorBranch (QColor c)
2819 BranchItem *selbi=getSelectedBranch();
2824 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2826 QString ("colorBranch (\"%1\")").arg(c.name()),
2827 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2829 selbi->setHeadingColor(c); // color branch
2834 void VymModel::colorSubtree (QColor c)
2836 BranchItem *selbi=getSelectedBranch();
2839 saveStateChangingPart(
2842 QString ("colorSubtree (\"%1\")").arg(c.name()),
2843 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2845 BranchItem *prev=NULL;
2846 BranchItem *cur=selbi;
2849 cur->setHeadingColor(c); // color links, color children
2850 cur=nextBranch (cur,prev,true,selbi);
2856 QColor VymModel::getCurrentHeadingColor()
2858 BranchItem *selbi=getSelectedBranch();
2859 if (selbi) return selbi->getHeadingColor();
2861 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2867 void VymModel::editURL()
2869 TreeItem *selti=getSelectedItem();
2873 QString text = QInputDialog::getText(
2874 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2875 selti->getURL(), &ok, NULL);
2877 // user entered something and pressed OK
2882 void VymModel::editLocalURL()
2884 TreeItem *selti=getSelectedItem();
2887 QStringList filters;
2888 filters <<"All files (*)";
2889 filters << tr("Text","Filedialog") + " (*.txt)";
2890 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2891 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2892 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2893 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2894 fd->setFilters (filters);
2895 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2896 fd->setDirectory (lastFileDir);
2897 if (! selti->getVymLink().isEmpty() )
2898 fd->selectFile( selti->getURL() );
2901 if ( fd->exec() == QDialog::Accepted )
2903 lastFileDir=QDir (fd->directory().path());
2904 setURL (fd->selectedFile() );
2910 void VymModel::editHeading2URL()
2912 TreeItem *selti=getSelectedItem();
2914 setURL (selti->getHeading());
2917 void VymModel::editBugzilla2URL()
2919 TreeItem *selti=getSelectedItem();
2922 QString h=selti->getHeading();
2923 QRegExp rx("^(\\d+)");
2924 if (rx.indexIn(h) !=-1)
2925 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2929 void VymModel::getBugzillaData()
2931 BranchItem *selbi=getSelectedBranch();
2934 QString url=selbi->getURL();
2937 QRegExp rx("(\\d+)");
2938 if (rx.indexIn(url) !=-1)
2940 QString bugID=rx.cap(1);
2941 qDebug()<< "VM::getBugzillaData bug="<<bugID;
2943 new BugAgent (selbi,bugID);
2949 void VymModel::editFATE2URL()
2951 TreeItem *selti=getSelectedItem();
2954 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2957 "setURL (\""+selti->getURL()+"\")",
2959 "setURL (\""+url+"\")",
2960 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2962 selti->setURL (url);
2963 // FIXME-4 updateActions();
2967 void VymModel::editVymLink()
2969 BranchItem *bi=getSelectedBranch();
2972 QStringList filters;
2973 filters <<"VYM map (*.vym)";
2974 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2975 fd->setFilters (filters);
2976 fd->setCaption(vymName+" - " +tr("Link to another map"));
2977 fd->setDirectory (lastFileDir);
2978 if (! bi->getVymLink().isEmpty() )
2979 fd->selectFile( bi->getVymLink() );
2983 if ( fd->exec() == QDialog::Accepted )
2985 lastFileDir=QDir (fd->directory().path());
2988 "setVymLink (\""+bi->getVymLink()+"\")",
2990 "setVymLink (\""+fd->selectedFile()+"\")",
2991 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2993 setVymLink (fd->selectedFile() );
2998 void VymModel::setVymLink (const QString &s)
3000 // Internal function, no saveState needed
3001 TreeItem *selti=getSelectedItem();
3004 selti->setVymLink(s);
3006 emitDataHasChanged (selti);
3007 emitShowSelection();
3011 void VymModel::deleteVymLink()
3013 BranchItem *bi=getSelectedBranch();
3018 "setVymLink (\""+bi->getVymLink()+"\")",
3020 "setVymLink (\"\")",
3021 QString("Unset vymlink of %1").arg(getObjectName(bi))
3023 bi->setVymLink ("" );
3029 QString VymModel::getVymLink()
3031 BranchItem *bi=getSelectedBranch();
3033 return bi->getVymLink();
3039 QStringList VymModel::getVymLinks()
3042 BranchItem *selbi=getSelectedBranch();
3043 BranchItem *cur=selbi;
3044 BranchItem *prev=NULL;
3047 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3048 cur=nextBranch (cur,prev,true,selbi);
3054 void VymModel::followXLink(int i)
3057 BranchItem *selbi=getSelectedBranch();
3060 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3061 if (selbi) select (selbi);
3065 void VymModel::editXLink(int i)
3068 BranchItem *selbi=getSelectedBranch();
3071 XLinkItem *xli=selbi->getXLinkNum(i);
3074 EditXLinkDialog dia;
3076 dia.setSelection(selbi);
3077 if (dia.exec() == QDialog::Accepted)
3079 if (dia.useSettingsGlobal() )
3081 setMapDefXLinkColor (xli->getColor() );
3082 setMapDefXLinkWidth (xli->getWidth() );
3084 if (dia.deleteXLink()) deleteItem (xli);
3094 //////////////////////////////////////////////
3096 //////////////////////////////////////////////
3098 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3100 TreeItem* selti=getSelectedItem();
3101 BranchItem *selbi=getSelectedBranch();
3106 QVariant returnValue;
3108 // Split string s into command and parameters
3109 parser.parseAtom (atom);
3110 QString com=parser.getCommand();
3112 // External commands
3113 /////////////////////////////////////////////////////////////////////
3114 if (com=="addBranch")
3118 parser.setError (Aborted,"Nothing selected");
3119 } else if (! selbi )
3121 parser.setError (Aborted,"Type of selection is not a branch");
3126 if (parser.checkParCount(pl))
3128 if (parser.parCount()==0)
3132 n=parser.parInt (ok,0);
3133 if (ok ) addNewBranch (n);
3137 /////////////////////////////////////////////////////////////////////
3138 } else if (com=="addBranchBefore")
3142 parser.setError (Aborted,"Nothing selected");
3143 } else if (! selbi )
3145 parser.setError (Aborted,"Type of selection is not a branch");
3148 if (parser.parCount()==0)
3150 addNewBranchBefore ();
3153 /////////////////////////////////////////////////////////////////////
3154 } else if (com==QString("addMapCenter"))
3156 if (parser.checkParCount(2))
3158 x=parser.parDouble (ok,0);
3161 y=parser.parDouble (ok,1);
3162 if (ok) addMapCenter (QPointF(x,y));
3165 /////////////////////////////////////////////////////////////////////
3166 } else if (com==QString("addMapReplace"))
3170 parser.setError (Aborted,"Nothing selected");
3171 } else if (! selbi )
3173 parser.setError (Aborted,"Type of selection is not a branch");
3174 } else if (parser.checkParCount(1))
3176 //s=parser.parString (ok,0); // selection
3177 t=parser.parString (ok,0); // path to map
3178 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3179 addMapReplaceInt(getSelectString(selbi),t);
3181 /////////////////////////////////////////////////////////////////////
3182 } else if (com==QString("addMapInsert"))
3184 if (parser.parCount()==2)
3189 parser.setError (Aborted,"Nothing selected");
3190 } else if (! selbi )
3192 parser.setError (Aborted,"Type of selection is not a branch");
3195 t=parser.parString (ok,0); // path to map
3196 n=parser.parInt(ok,1); // position
3197 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3198 addMapInsertInt(t,n);
3200 } else if (parser.parCount()==1)
3202 t=parser.parString (ok,0); // path to map
3203 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3206 parser.setError (Aborted,"Wrong number of parameters");
3207 /////////////////////////////////////////////////////////////////////
3208 } else if (com==QString("addXLink"))
3210 if (parser.parCount()>1)
3212 s=parser.parString (ok,0); // begin
3213 t=parser.parString (ok,1); // end
3214 BranchItem *begin=(BranchItem*)findBySelectString(s);
3215 BranchItem *end=(BranchItem*)findBySelectString(t);
3218 if (begin->isBranchLikeType() && end->isBranchLikeType())
3220 XLinkItem *xl=createXLink (begin,true);
3226 parser.setError (Aborted,"Failed to create xLink");
3229 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3232 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3234 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3235 /////////////////////////////////////////////////////////////////////
3236 } else if (com=="clearFlags")
3240 parser.setError (Aborted,"Nothing selected");
3241 } else if (! selbi )
3243 parser.setError (Aborted,"Type of selection is not a branch");
3244 } else if (parser.checkParCount(0))
3246 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3248 /////////////////////////////////////////////////////////////////////
3249 } else if (com=="colorBranch")
3253 parser.setError (Aborted,"Nothing selected");
3254 } else if (! selbi )
3256 parser.setError (Aborted,"Type of selection is not a branch");
3257 } else if (parser.checkParCount(1))
3259 QColor c=parser.parColor (ok,0);
3260 if (ok) colorBranch (c);
3262 /////////////////////////////////////////////////////////////////////
3263 } else if (com=="colorSubtree")
3267 parser.setError (Aborted,"Nothing selected");
3268 } else if (! selbi )
3270 parser.setError (Aborted,"Type of selection is not a branch");
3271 } else if (parser.checkParCount(1))
3273 QColor c=parser.parColor (ok,0);
3274 if (ok) colorSubtree (c);
3276 /////////////////////////////////////////////////////////////////////
3277 } else if (com=="copy")
3281 parser.setError (Aborted,"Nothing selected");
3282 } else if ( selectionType()!=TreeItem::Branch &&
3283 selectionType()!=TreeItem::MapCenter &&
3284 selectionType()!=TreeItem::Image )
3286 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3287 } else if (parser.checkParCount(0))
3291 /////////////////////////////////////////////////////////////////////
3292 } else if (com=="cut")
3296 parser.setError (Aborted,"Nothing selected");
3297 } else if ( selectionType()!=TreeItem::Branch &&
3298 selectionType()!=TreeItem::MapCenter &&
3299 selectionType()!=TreeItem::Image )
3301 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3302 } else if (parser.checkParCount(0))
3306 /////////////////////////////////////////////////////////////////////
3307 } else if (com=="delete")
3311 parser.setError (Aborted,"Nothing selected");
3313 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3315 parser.setError (Aborted,"Type of selection is wrong.");
3318 else if (parser.checkParCount(0))
3322 /////////////////////////////////////////////////////////////////////
3323 } else if (com=="deleteKeepChildren")
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 deleteKeepChildren();
3335 /////////////////////////////////////////////////////////////////////
3336 } else if (com=="deleteChildren")
3340 parser.setError (Aborted,"Nothing selected");
3343 parser.setError (Aborted,"Type of selection is not a branch");
3344 } else if (parser.checkParCount(0))
3348 /////////////////////////////////////////////////////////////////////
3349 } else if (com=="exportAO")
3353 if (parser.parCount()>=1)
3354 // Hey, we even have a filename
3355 fname=parser.parString(ok,0);
3358 parser.setError (Aborted,"Could not read filename");
3361 exportAO (fname,false);
3363 /////////////////////////////////////////////////////////////////////
3364 } else if (com=="exportASCII")
3368 if (parser.parCount()>=1)
3369 // Hey, we even have a filename
3370 fname=parser.parString(ok,0);
3373 parser.setError (Aborted,"Could not read filename");
3376 exportASCII (fname,false);
3378 /////////////////////////////////////////////////////////////////////
3379 } else if (com=="exportImage")
3383 if (parser.parCount()>=2)
3384 // Hey, we even have a filename
3385 fname=parser.parString(ok,0);
3388 parser.setError (Aborted,"Could not read filename");
3391 QString format="PNG";
3392 if (parser.parCount()>=2)
3394 format=parser.parString(ok,1);
3396 exportImage (fname,false,format);
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="exportXHTML")
3403 if (parser.parCount()>=2)
3404 // Hey, we even have a filename
3405 fname=parser.parString(ok,1);
3408 parser.setError (Aborted,"Could not read filename");
3411 exportXHTML (fname,false);
3413 /////////////////////////////////////////////////////////////////////
3414 } else if (com=="exportXML")
3418 if (parser.parCount()>=2)
3419 // Hey, we even have a filename
3420 fname=parser.parString(ok,1);
3423 parser.setError (Aborted,"Could not read filename");
3426 exportXML (fname,false);
3428 /////////////////////////////////////////////////////////////////////
3429 } else if (com=="getHeading")
3433 parser.setError (Aborted,"Nothing selected");
3434 } else if (parser.checkParCount(0))
3435 returnValue=selti->getHeading();
3436 /////////////////////////////////////////////////////////////////////
3437 } else if (com=="importDir")
3441 parser.setError (Aborted,"Nothing selected");
3442 } else if (! selbi )
3444 parser.setError (Aborted,"Type of selection is not a branch");
3445 } else if (parser.checkParCount(1))
3447 s=parser.parString(ok,0);
3448 if (ok) importDirInt(s);
3450 /////////////////////////////////////////////////////////////////////
3451 } else if (com=="relinkTo")
3455 parser.setError (Aborted,"Nothing selected");
3458 if (parser.checkParCount(4))
3460 // 0 selectstring of parent
3461 // 1 num in parent (for branches)
3462 // 2,3 x,y of mainbranch or mapcenter
3463 s=parser.parString(ok,0);
3464 TreeItem *dst=findBySelectString (s);
3467 if (dst->getType()==TreeItem::Branch)
3469 // Get number in parent
3470 n=parser.parInt (ok,1);
3473 relinkBranch (selbi,(BranchItem*)dst,n);
3474 emitSelectionChanged();
3476 } else if (dst->getType()==TreeItem::MapCenter)
3478 relinkBranch (selbi,(BranchItem*)dst);
3479 // Get coordinates of mainbranch
3480 x=parser.parDouble(ok,2);
3483 y=parser.parDouble(ok,3);
3486 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3487 emitSelectionChanged();
3493 } else if ( selti->getType() == TreeItem::Image)
3495 if (parser.checkParCount(1))
3497 // 0 selectstring of parent
3498 s=parser.parString(ok,0);
3499 TreeItem *dst=findBySelectString (s);
3502 if (dst->isBranchLikeType())
3503 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3505 parser.setError (Aborted,"Destination is not a branch");
3508 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3509 /////////////////////////////////////////////////////////////////////
3510 } else if (com=="loadImage")
3514 parser.setError (Aborted,"Nothing selected");
3515 } else if (! selbi )
3517 parser.setError (Aborted,"Type of selection is not a branch");
3518 } else if (parser.checkParCount(1))
3520 s=parser.parString(ok,0);
3521 if (ok) loadFloatImageInt (selbi,s);
3523 /////////////////////////////////////////////////////////////////////
3524 } else if (com=="moveUp")
3528 parser.setError (Aborted,"Nothing selected");
3529 } else if (! selbi )
3531 parser.setError (Aborted,"Type of selection is not a branch");
3532 } else if (parser.checkParCount(0))
3536 /////////////////////////////////////////////////////////////////////
3537 } else if (com=="moveDown")
3541 parser.setError (Aborted,"Nothing selected");
3542 } else if (! selbi )
3544 parser.setError (Aborted,"Type of selection is not a branch");
3545 } else if (parser.checkParCount(0))
3549 /////////////////////////////////////////////////////////////////////
3550 } else if (com=="move")
3554 parser.setError (Aborted,"Nothing selected");
3555 } else if ( selectionType()!=TreeItem::Branch &&
3556 selectionType()!=TreeItem::MapCenter &&
3557 selectionType()!=TreeItem::Image )
3559 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3560 } else if (parser.checkParCount(2))
3562 x=parser.parDouble (ok,0);
3565 y=parser.parDouble (ok,1);
3569 /////////////////////////////////////////////////////////////////////
3570 } else if (com=="moveRel")
3574 parser.setError (Aborted,"Nothing selected");
3575 } else if ( selectionType()!=TreeItem::Branch &&
3576 selectionType()!=TreeItem::MapCenter &&
3577 selectionType()!=TreeItem::Image )
3579 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3580 } else if (parser.checkParCount(2))
3582 x=parser.parDouble (ok,0);
3585 y=parser.parDouble (ok,1);
3586 if (ok) moveRel (x,y);
3589 /////////////////////////////////////////////////////////////////////
3590 } else if (com=="nop")
3592 /////////////////////////////////////////////////////////////////////
3593 } else if (com=="paste")
3597 parser.setError (Aborted,"Nothing selected");
3598 } else if (! selbi )
3600 parser.setError (Aborted,"Type of selection is not a branch");
3601 } else if (parser.checkParCount(1))
3603 n=parser.parInt (ok,0);
3604 if (ok) pasteNoSave(n);
3606 /////////////////////////////////////////////////////////////////////
3607 } else if (com=="qa")
3611 parser.setError (Aborted,"Nothing selected");
3612 } else if (! selbi )
3614 parser.setError (Aborted,"Type of selection is not a branch");
3615 } else if (parser.checkParCount(4))
3618 c=parser.parString (ok,0);
3621 parser.setError (Aborted,"No comment given");
3624 s=parser.parString (ok,1);
3627 parser.setError (Aborted,"First parameter is not a string");
3630 t=parser.parString (ok,2);
3633 parser.setError (Aborted,"Condition is not a string");
3636 u=parser.parString (ok,3);
3639 parser.setError (Aborted,"Third parameter is not a string");
3644 parser.setError (Aborted,"Unknown type: "+s);
3649 parser.setError (Aborted,"Unknown operator: "+t);
3654 parser.setError (Aborted,"Type of selection is not a branch");
3657 if (selbi->getHeading() == u)
3659 cout << "PASSED: " << qPrintable (c) << endl;
3662 cout << "FAILED: " << qPrintable (c) << endl;
3672 /////////////////////////////////////////////////////////////////////
3673 } else if (com=="saveImage")
3675 ImageItem *ii=getSelectedImage();
3678 parser.setError (Aborted,"No image selected");
3679 } else if (parser.checkParCount(2))
3681 s=parser.parString(ok,0);
3684 t=parser.parString(ok,1);
3685 if (ok) saveFloatImageInt (ii,t,s);
3688 /////////////////////////////////////////////////////////////////////
3689 } else if (com=="scroll")
3693 parser.setError (Aborted,"Nothing selected");
3694 } else if (! selbi )
3696 parser.setError (Aborted,"Type of selection is not a branch");
3697 } else if (parser.checkParCount(0))
3699 if (!scrollBranch (selbi))
3700 parser.setError (Aborted,"Could not scroll branch");
3702 /////////////////////////////////////////////////////////////////////
3703 } else if (com=="select")
3705 if (parser.checkParCount(1))
3707 s=parser.parString(ok,0);
3710 /////////////////////////////////////////////////////////////////////
3711 } else if (com=="selectLastBranch")
3715 parser.setError (Aborted,"Nothing selected");
3716 } else if (! selbi )
3718 parser.setError (Aborted,"Type of selection is not a branch");
3719 } else if (parser.checkParCount(0))
3721 BranchItem *bi=selbi->getLastBranch();
3723 parser.setError (Aborted,"Could not select last branch");
3724 select (bi); // FIXME-3 was selectInt
3727 /////////////////////////////////////////////////////////////////////
3728 } else /* FIXME-2 if (com=="selectLastImage")
3732 parser.setError (Aborted,"Nothing selected");
3733 } else if (! selbi )
3735 parser.setError (Aborted,"Type of selection is not a branch");
3736 } else if (parser.checkParCount(0))
3738 FloatImageObj *fio=selb->getLastFloatImage();
3740 parser.setError (Aborted,"Could not select last image");
3741 select (fio); // FIXME-3 was selectInt
3744 /////////////////////////////////////////////////////////////////////
3745 } else */ if (com=="selectLatestAdded")
3747 if (!latestAddedItem)
3749 parser.setError (Aborted,"No latest added object");
3752 if (!select (latestAddedItem))
3753 parser.setError (Aborted,"Could not select latest added object ");
3755 /////////////////////////////////////////////////////////////////////
3756 } else if (com=="setFlag")
3760 parser.setError (Aborted,"Nothing selected");
3761 } else if (! selbi )
3763 parser.setError (Aborted,"Type of selection is not a branch");
3764 } else if (parser.checkParCount(1))
3766 s=parser.parString(ok,0);
3768 selbi->activateStandardFlag(s);
3770 /////////////////////////////////////////////////////////////////////
3771 } else if (com=="setFrameType")
3773 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3775 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3777 else if (parser.checkParCount(1))
3779 s=parser.parString(ok,0);
3780 if (ok) setFrameType (s);
3782 /////////////////////////////////////////////////////////////////////
3783 } else if (com=="setFramePenColor")
3785 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3787 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3789 else if (parser.checkParCount(1))
3791 QColor c=parser.parColor(ok,0);
3792 if (ok) setFramePenColor (c);
3794 /////////////////////////////////////////////////////////////////////
3795 } else if (com=="setFrameBrushColor")
3797 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3799 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3801 else if (parser.checkParCount(1))
3803 QColor c=parser.parColor(ok,0);
3804 if (ok) setFrameBrushColor (c);
3806 /////////////////////////////////////////////////////////////////////
3807 } else if (com=="setFramePadding")
3809 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3811 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3813 else if (parser.checkParCount(1))
3815 n=parser.parInt(ok,0);
3816 if (ok) setFramePadding(n);
3818 /////////////////////////////////////////////////////////////////////
3819 } else if (com=="setFrameBorderWidth")
3821 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3823 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3825 else if (parser.checkParCount(1))
3827 n=parser.parInt(ok,0);
3828 if (ok) setFrameBorderWidth (n);
3830 /////////////////////////////////////////////////////////////////////
3831 /* FIXME-2 else if (com=="setFrameType")
3835 parser.setError (Aborted,"Nothing selected");
3838 parser.setError (Aborted,"Type of selection is not a branch");
3839 } else if (parser.checkParCount(1))
3841 s=parser.parString(ok,0);
3845 /////////////////////////////////////////////////////////////////////
3847 /////////////////////////////////////////////////////////////////////
3848 } else if (com=="setHeading")
3852 parser.setError (Aborted,"Nothing selected");
3853 } else if (! selbi )
3855 parser.setError (Aborted,"Type of selection is not a branch");
3856 } else if (parser.checkParCount(1))
3858 s=parser.parString (ok,0);
3862 /////////////////////////////////////////////////////////////////////
3863 } else if (com=="setHideExport")
3867 parser.setError (Aborted,"Nothing selected");
3868 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3870 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3871 } else if (parser.checkParCount(1))
3873 b=parser.parBool(ok,0);
3874 if (ok) setHideExport (b);
3876 /////////////////////////////////////////////////////////////////////
3877 } else if (com=="setIncludeImagesHorizontally")
3881 parser.setError (Aborted,"Nothing selected");
3884 parser.setError (Aborted,"Type of selection is not a branch");
3885 } else if (parser.checkParCount(1))
3887 b=parser.parBool(ok,0);
3888 if (ok) setIncludeImagesHor(b);
3890 /////////////////////////////////////////////////////////////////////
3891 } else if (com=="setIncludeImagesVertically")
3895 parser.setError (Aborted,"Nothing selected");
3898 parser.setError (Aborted,"Type of selection is not a branch");
3899 } else if (parser.checkParCount(1))
3901 b=parser.parBool(ok,0);
3902 if (ok) setIncludeImagesVer(b);
3904 /////////////////////////////////////////////////////////////////////
3905 } else if (com=="setHideLinkUnselected")
3909 parser.setError (Aborted,"Nothing selected");
3910 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3912 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3913 } else if (parser.checkParCount(1))
3915 b=parser.parBool(ok,0);
3916 if (ok) setHideLinkUnselected(b);
3918 /////////////////////////////////////////////////////////////////////
3919 } else if (com=="setMapAuthor")
3921 if (parser.checkParCount(1))
3923 s=parser.parString(ok,0);
3924 if (ok) setAuthor (s);
3926 /////////////////////////////////////////////////////////////////////
3927 } else if (com=="setMapComment")
3929 if (parser.checkParCount(1))
3931 s=parser.parString(ok,0);
3932 if (ok) setComment(s);
3934 /////////////////////////////////////////////////////////////////////
3935 } else if (com=="setMapBackgroundColor")
3939 parser.setError (Aborted,"Nothing selected");
3940 } else if (! selbi )
3942 parser.setError (Aborted,"Type of selection is not a branch");
3943 } else if (parser.checkParCount(1))
3945 QColor c=parser.parColor (ok,0);
3946 if (ok) setMapBackgroundColor (c);
3948 /////////////////////////////////////////////////////////////////////
3949 } else if (com=="setMapDefLinkColor")
3953 parser.setError (Aborted,"Nothing selected");
3954 } else if (! selbi )
3956 parser.setError (Aborted,"Type of selection is not a branch");
3957 } else if (parser.checkParCount(1))
3959 QColor c=parser.parColor (ok,0);
3960 if (ok) setMapDefLinkColor (c);
3962 /////////////////////////////////////////////////////////////////////
3963 } else if (com=="setMapLinkStyle")
3965 if (parser.checkParCount(1))
3967 s=parser.parString (ok,0);
3968 if (ok) setMapLinkStyle(s);
3970 /////////////////////////////////////////////////////////////////////
3971 } else if (com=="setNote")
3975 parser.setError (Aborted,"Nothing selected");
3976 } else if (! selbi )
3978 parser.setError (Aborted,"Type of selection is not a branch");
3979 } else if (parser.checkParCount(1))
3981 s=parser.parString (ok,0);
3985 /////////////////////////////////////////////////////////////////////
3986 } else if (com=="setSelectionColor")
3988 if (parser.checkParCount(1))
3990 QColor c=parser.parColor (ok,0);
3991 if (ok) setSelectionColorInt (c);
3993 /////////////////////////////////////////////////////////////////////
3994 } else if (com=="setURL")
3998 parser.setError (Aborted,"Nothing selected");
3999 } else if (! selbi )
4001 parser.setError (Aborted,"Type of selection is not a branch");
4002 } else if (parser.checkParCount(1))
4004 s=parser.parString (ok,0);
4007 /////////////////////////////////////////////////////////////////////
4008 } else if (com=="setVymLink")
4012 parser.setError (Aborted,"Nothing selected");
4013 } else if (! selbi )
4015 parser.setError (Aborted,"Type of selection is not a branch");
4016 } else if (parser.checkParCount(1))
4018 s=parser.parString (ok,0);
4019 if (ok) setVymLink(s);
4021 } else if (com=="sortChildren")
4025 parser.setError (Aborted,"Nothing selected");
4026 } else if (! selbi )
4028 parser.setError (Aborted,"Type of selection is not a branch");
4029 } else if (parser.checkParCount(0))
4032 } else if (parser.checkParCount(1))
4034 b=parser.parBool(ok,0);
4035 if (ok) sortChildren(b);
4037 /////////////////////////////////////////////////////////////////////
4038 } else if (com=="toggleFlag")
4042 parser.setError (Aborted,"Nothing selected");
4043 } else if (! selbi )
4045 parser.setError (Aborted,"Type of selection is not a branch");
4046 } else if (parser.checkParCount(1))
4048 s=parser.parString(ok,0);
4050 selbi->toggleStandardFlag(s);
4052 /////////////////////////////////////////////////////////////////////
4053 } else if (com=="unscroll")
4057 parser.setError (Aborted,"Nothing selected");
4058 } else if (! selbi )
4060 parser.setError (Aborted,"Type of selection is not a branch");
4061 } else if (parser.checkParCount(0))
4063 if (!unscrollBranch (selbi))
4064 parser.setError (Aborted,"Could not unscroll branch");
4066 /////////////////////////////////////////////////////////////////////
4067 } else if (com=="unscrollChildren")
4071 parser.setError (Aborted,"Nothing selected");
4072 } else if (! selbi )
4074 parser.setError (Aborted,"Type of selection is not a branch");
4075 } else if (parser.checkParCount(0))
4077 unscrollChildren ();
4079 /////////////////////////////////////////////////////////////////////
4080 } else if (com=="unsetFlag")
4084 parser.setError (Aborted,"Nothing selected");
4085 } else if (! selbi )
4087 parser.setError (Aborted,"Type of selection is not a branch");
4088 } else if (parser.checkParCount(1))
4090 s=parser.parString(ok,0);
4092 selbi->deactivateStandardFlag(s);
4095 parser.setError (Aborted,"Unknown command");
4098 if (parser.errorLevel()==NoError)
4106 // TODO Error handling
4107 qWarning("VymModel::parseAtom: Error!");
4109 qWarning(parser.errorMessage());
4111 errorMsg=parser.errorMessage();
4116 QVariant VymModel::runScript (const QString &script)
4118 parser.setScript (script);
4123 while (parser.next() && noErr)
4125 r=parseAtom(parser.getAtom(),noErr,errMsg);
4126 if (!noErr) //FIXME-3 need dialog box here
4127 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4132 void VymModel::setExportMode (bool b)
4134 // should be called before and after exports
4135 // depending on the settings
4136 if (b && settings.value("/export/useHideExport","true")=="true")
4137 setHideTmpMode (TreeItem::HideExport);
4139 setHideTmpMode (TreeItem::HideNone);
4142 void VymModel::exportImage(QString fname, bool askName, QString format)
4146 fname=getMapName()+".png";
4153 QFileDialog *fd=new QFileDialog (NULL);
4154 fd->setCaption (tr("Export map as image"));
4155 fd->setDirectory (lastImageDir);
4156 fd->setFileMode(QFileDialog::AnyFile);
4157 fd->setFilters (imageIO.getFilters() );
4160 fl=fd->selectedFiles();
4162 format=imageIO.getType(fd->selectedFilter());
4166 setExportMode (true);
4167 mapEditor->getScene()->update(); // FIXME-3 check this...
4168 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4169 img.save(fname, format);
4170 setExportMode (false);
4174 void VymModel::exportXML(QString dir, bool askForName)
4178 dir=browseDirectory(NULL,tr("Export XML to directory"));
4179 if (dir =="" && !reallyWriteDirectory(dir) )
4183 // Hide stuff during export, if settings want this
4184 setExportMode (true);
4186 // Create subdirectories
4189 // write to directory //FIXME-4 check totalBBox here...
4190 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4193 file.setName ( dir + "/"+mapName+".xml");
4194 if ( !file.open( QIODevice::WriteOnly ) )
4196 // This should neverever happen
4197 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4201 // Write it finally, and write in UTF8, no matter what
4202 QTextStream ts( &file );
4203 ts.setEncoding (QTextStream::UnicodeUTF8);
4207 // Now write image, too
4208 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4210 setExportMode (false);
4213 void VymModel::exportAO (QString fname,bool askName)
4218 ex.setFile (mapName+".txt");
4224 //ex.addFilter ("TXT (*.txt)");
4225 ex.setDir(lastImageDir);
4226 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4231 setExportMode(true);
4233 setExportMode(false);
4237 void VymModel::exportASCII(QString fname,bool askName)
4242 ex.setFile (mapName+".txt");
4248 //ex.addFilter ("TXT (*.txt)");
4249 ex.setDir(lastImageDir);
4250 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4255 setExportMode(true);
4257 setExportMode(false);
4261 void VymModel::exportHTML (const QString &dir, bool askForName) //FIXME-2 own dialogue missing and also option to save settings in map
4263 ExportHTMLDialog dia(NULL);
4264 dia.setFilePath (filePath );
4265 dia.setMapName (mapName );
4267 if (dir!="") dia.setDir (dir);
4273 if (dia.exec()!=QDialog::Accepted)
4278 // Check, if warnings should be used before overwriting
4279 // the output directory
4280 if (d.exists() && d.count()>0)
4283 warn.showCancelButton (true);
4284 warn.setText(QString(
4285 "The directory %1 is not empty.\n"
4286 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4287 warn.setCaption("Warning: Directory not empty");
4288 warn.setShowAgainName("mainwindow/export-XML-overwrite-dir");
4290 if (warn.exec()!=QDialog::Accepted) ok=false;
4296 // Hide stuff during export, if settings want this
4297 setExportMode (true);
4299 ExportHTML ex (this);
4300 ex.setFile (d.path()+"/"+mapName+".html");
4301 //qDebug()<< "VM::exportHTML writing "<<ex.getFile();
4302 ex.setCSSPath(dia.getCSSPath() );
4304 setExportMode (false);
4306 //dia.doExport(mapName );
4307 //if (dia.hasChanged()) setChanged();
4310 exportImage (d.path()+"/"+mapName+".png",false,"PNG");
4315 void VymModel::exportXHTML (const QString &dir, bool askForName)
4317 ExportXHTMLDialog dia(NULL);
4318 dia.setFilePath (filePath );
4319 dia.setMapName (mapName );
4321 if (dir!="") dia.setDir (dir);
4327 if (dia.exec()!=QDialog::Accepted)
4331 QDir d (dia.getDir());
4332 // Check, if warnings should be used before overwriting
4333 // the output directory
4334 if (d.exists() && d.count()>0)
4337 warn.showCancelButton (true);
4338 warn.setText(QString(
4339 "The directory %1 is not empty.\n"
4340 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4341 warn.setCaption("Warning: Directory not empty");
4342 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4344 if (warn.exec()!=QDialog::Accepted) ok=false;
4351 exportXML (dia.getDir(),false );
4352 dia.doExport(mapName );
4353 //if (dia.hasChanged()) setChanged();
4357 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4362 if (ex.setConfigFile(cf))
4364 setExportMode (true);
4365 ex.exportPresentation();
4366 setExportMode (false);
4373 //////////////////////////////////////////////
4375 //////////////////////////////////////////////
4377 void VymModel::registerEditor(QWidget *me)
4379 mapEditor=(MapEditor*)me;
4382 void VymModel::unregisterEditor(QWidget *)
4387 void VymModel::setContextPos(QPointF p)
4392 void VymModel::unsetContextPos()
4394 contextPos=QPointF();
4397 void VymModel::updateNoteFlag()
4399 TreeItem *selti=getSelectedItem();
4408 if (textEditor->isEmpty())
4411 selti->setNote (textEditor->getText());
4412 emitDataHasChanged(selti);
4416 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4418 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4419 if (blockReposition) return;
4421 for (int i=0;i<rootItem->branchCount(); i++)
4422 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4423 //emitSelectionChanged();
4427 void VymModel::setMapLinkStyle (const QString & s)
4432 case LinkableMapObj::Line :
4435 case LinkableMapObj::Parabel:
4436 snow="StyleParabel";
4438 case LinkableMapObj::PolyLine:
4439 snow="StylePolyLine";
4441 case LinkableMapObj::PolyParabel:
4442 snow="StylePolyParabel";
4445 snow="UndefinedStyle";
4450 QString("setMapLinkStyle (\"%1\")").arg(s),
4451 QString("setMapLinkStyle (\"%1\")").arg(snow),
4452 QString("Set map link style (\"%1\")").arg(s)
4456 linkstyle=LinkableMapObj::Line;
4457 else if (s=="StyleParabel")
4458 linkstyle=LinkableMapObj::Parabel;
4459 else if (s=="StylePolyLine")
4460 linkstyle=LinkableMapObj::PolyLine;
4461 else if (s=="StylePolyParabel")
4462 linkstyle=LinkableMapObj::PolyParabel;
4464 linkstyle=LinkableMapObj::UndefinedStyle;
4466 BranchItem *cur=NULL;
4467 BranchItem *prev=NULL;
4469 nextBranch (cur,prev);
4472 bo=(BranchObj*)(cur->getLMO() );
4473 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4474 cur=nextBranch(cur,prev);
4479 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4484 uint VymModel::getID()
4489 void VymModel::setMapDefLinkColor(QColor col)
4491 if ( !col.isValid() ) return;
4493 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4494 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4495 QString("Set map link color to %1").arg(col.name())
4499 BranchItem *cur=NULL;
4500 BranchItem *prev=NULL;
4502 cur=nextBranch(cur,prev);
4505 bo=(BranchObj*)(cur->getLMO() );
4507 nextBranch(cur,prev);
4512 void VymModel::setMapLinkColorHintInt()
4514 // called from setMapLinkColorHint(lch) or at end of parse
4515 BranchItem *cur=NULL;
4516 BranchItem *prev=NULL;
4518 cur=nextBranch(cur,prev);
4521 bo=(BranchObj*)(cur->getLMO() );
4523 cur=nextBranch(cur,prev);
4527 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4530 setMapLinkColorHintInt();
4533 void VymModel::toggleMapLinkColorHint()
4535 if (linkcolorhint==LinkableMapObj::HeadingColor)
4536 linkcolorhint=LinkableMapObj::DefaultColor;
4538 linkcolorhint=LinkableMapObj::HeadingColor;
4539 BranchItem *cur=NULL;
4540 BranchItem *prev=NULL;
4542 cur=nextBranch(cur,prev);
4545 bo=(BranchObj*)(cur->getLMO() );
4547 nextBranch(cur,prev);
4551 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4553 Q3FileDialog *fd=new Q3FileDialog( NULL);
4554 fd->setMode (Q3FileDialog::ExistingFile);
4555 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4556 ImagePreview *p =new ImagePreview (fd);
4557 fd->setContentsPreviewEnabled( TRUE );
4558 fd->setContentsPreview( p, p );
4559 fd->setPreviewMode( Q3FileDialog::Contents );
4560 fd->setCaption(vymName+" - " +tr("Load background image"));
4561 fd->setDir (lastImageDir);
4564 if ( fd->exec() == QDialog::Accepted )
4566 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4567 lastImageDir=QDir (fd->dirPath());
4568 setMapBackgroundImage (fd->selectedFile());
4572 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4574 QColor oldcol=mapScene->backgroundBrush().color();
4578 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4580 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4581 QString("Set background color of map to %1").arg(col.name()));
4584 brush.setTextureImage (QPixmap (fn));
4585 mapScene->setBackgroundBrush(brush);
4588 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4590 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4591 if ( !col.isValid() ) return;
4592 setMapBackgroundColor( col );
4596 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4598 QColor oldcol=mapScene->backgroundBrush().color();
4600 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4601 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4602 QString("Set background color of map to %1").arg(col.name()));
4603 mapScene->setBackgroundBrush(col);
4606 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4608 return mapScene->backgroundBrush().color();
4612 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4614 return linkcolorhint;
4617 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4619 return defLinkColor;
4622 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4627 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4629 return defXLinkColor;
4632 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4637 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4639 return defXLinkWidth;
4642 void VymModel::move(const double &x, const double &y)
4645 MapItem *seli = (MapItem*)getSelectedItem();
4646 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4648 LinkableMapObj *lmo=seli->getLMO();
4651 QPointF ap(lmo->getAbsPos());
4655 QString ps=qpointFToString(ap);
4656 QString s=getSelectString(seli);
4659 s, "move "+qpointFToString(to),
4660 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4663 emitSelectionChanged();
4669 void VymModel::moveRel (const double &x, const double &y)
4672 MapItem *seli = (MapItem*)getSelectedItem();
4673 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4675 LinkableMapObj *lmo=seli->getLMO();
4678 QPointF rp(lmo->getRelPos());
4682 QString ps=qpointFToString (lmo->getRelPos());
4683 QString s=getSelectString(seli);
4686 s, "moveRel "+qpointFToString(to),
4687 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4688 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4690 lmo->updateLinkGeometry();
4691 emitSelectionChanged();
4698 void VymModel::animate() //FIXME-2 animation causes flicker after cut/undo cut ?!?
4700 animationTimer->stop();
4703 while (i<animObjList.size() )
4705 bo=(BranchObj*)animObjList.at(i);
4710 animObjList.removeAt(i);
4717 QItemSelection sel=selModel->selection();
4718 emit (selectionChanged(sel,sel));
4721 if (!animObjList.isEmpty()) animationTimer->start();
4725 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4727 qDebug()<<"Start animation for "<<bo->getTreeItem()<<getHeading();
4728 if (start==dest) return;
4729 if (bo && bo->getTreeItem()->depth()>0)
4732 ap.setStart (start);
4734 ap.setTicks (animationTicks);
4735 ap.setAnimated (true);
4736 bo->setAnimation (ap);
4737 animObjList.append( bo );
4738 animationTimer->setSingleShot (true);
4739 animationTimer->start(animationInterval);
4743 void VymModel::stopAnimation (MapObj *mo)
4745 int i=animObjList.indexOf(mo);
4747 animObjList.removeAt (i);
4750 void VymModel::sendSelection()
4752 if (netstate!=Server) return;
4753 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4756 void VymModel::newServer()
4760 tcpServer = new QTcpServer(this);
4761 if (!tcpServer->listen(QHostAddress::Any,port)) {
4762 QMessageBox::critical(NULL, "vym server",
4763 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4764 //FIXME-3 needed? we are no widget any longer... close();
4767 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4769 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4772 void VymModel::connectToServer()
4775 server="salam.suse.de";
4777 clientSocket = new QTcpSocket (this);
4778 clientSocket->abort();
4779 clientSocket->connectToHost(server ,port);
4780 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4781 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4782 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4784 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4789 void VymModel::newClient()
4791 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4792 connect(newClient, SIGNAL(disconnected()),
4793 newClient, SLOT(deleteLater()));
4795 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4797 clientList.append (newClient);
4801 void VymModel::sendData(const QString &s)
4803 if (clientList.size()==0) return;
4805 // Create bytearray to send
4807 QDataStream out(&block, QIODevice::WriteOnly);
4808 out.setVersion(QDataStream::Qt_4_0);
4810 // Reserve some space for blocksize
4813 // Write sendCounter
4814 out << sendCounter++;
4819 // Go back and write blocksize so far
4820 out.device()->seek(0);
4821 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4825 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4827 for (int i=0; i<clientList.size(); ++i)
4829 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4830 clientList.at(i)->write (block);
4834 void VymModel::readData ()
4836 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4839 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4843 QDataStream in(clientSocket);
4844 in.setVersion(QDataStream::Qt_4_0);
4852 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4855 parseAtom (t,noErr,errMsg);
4861 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4863 switch (socketError) {
4864 case QAbstractSocket::RemoteHostClosedError:
4866 case QAbstractSocket::HostNotFoundError:
4867 QMessageBox::information(NULL, vymName +" Network client",
4868 "The host was not found. Please check the "
4869 "host name and port settings.");
4871 case QAbstractSocket::ConnectionRefusedError:
4872 QMessageBox::information(NULL, vymName + " Network client",
4873 "The connection was refused by the peer. "
4874 "Make sure the fortune server is running, "
4875 "and check that the host name and port "
4876 "settings are correct.");
4879 QMessageBox::information(NULL, vymName + " Network client",
4880 QString("The following error occurred: %1.")
4881 .arg(clientSocket->errorString()));
4885 /* FIXME-3 Playing with DBUS...
4886 QDBusVariant VymModel::query (const QString &query)
4888 TreeItem *selti=getSelectedItem();
4890 return QDBusVariant (selti->getHeading());
4892 return QDBusVariant ("Nothing selected.");
4896 void VymModel::testslot() //FIXME-3 Playing with DBUS
4898 cout << "VM::testslot called\n";
4901 void VymModel::selectMapSelectionColor()
4903 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4904 setSelectionColor (col);
4907 void VymModel::setSelectionColorInt (QColor col)
4909 if ( !col.isValid() ) return;
4911 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4912 QString("setSelectionColor (%1)").arg(col.name()),
4913 QString("Set color of selection box to %1").arg(col.name())
4916 mapEditor->setSelectionColor (col);
4919 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4921 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4922 //FIXME-3 emitShowSelection();
4926 void VymModel::emitSelectionChanged()
4928 QItemSelection newsel=selModel->selection();
4929 emitSelectionChanged (newsel);
4932 void VymModel::setSelectionColor(QColor col)
4934 if ( !col.isValid() ) return;
4936 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4937 QString("setSelectionColor (%1)").arg(col.name()),
4938 QString("Set color of selection box to %1").arg(col.name())
4940 setSelectionColorInt (col);
4943 QColor VymModel::getSelectionColor()
4945 return mapEditor->getSelectionColor();
4948 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4951 for (int i=0;i<rootItem->branchCount();i++)
4952 rootItem->getBranchNum(i)->setHideTmp (mode);
4954 if (mode==TreeItem::HideExport)
4960 //////////////////////////////////////////////
4961 // Selection related
4962 //////////////////////////////////////////////
4964 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4969 QItemSelectionModel* VymModel::getSelectionModel()
4974 void VymModel::setSelectionBlocked (bool b)
4979 bool VymModel::isSelectionBlocked()
4981 return selectionBlocked;
4984 bool VymModel::select ()
4986 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4989 bool VymModel::select (const QString &s)
4996 TreeItem *ti=findBySelectString(s);
4997 if (ti) return select (index(ti));
5001 bool VymModel::select (LinkableMapObj *lmo)
5003 QItemSelection oldsel=selModel->selection();
5006 return select (index (lmo->getTreeItem()) );
5011 bool VymModel::select (TreeItem *ti)
5013 if (ti) return select (index(ti));
5017 bool VymModel::select (const QModelIndex &index)
5019 if (index.isValid() )
5021 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5022 BranchItem *bi=getSelectedBranch();
5023 if (bi) bi->setLastSelectedBranch();
5029 void VymModel::unselect()
5031 if (!selModel->selectedIndexes().isEmpty())
5033 lastSelectString=getSelectString();
5034 selModel->clearSelection();
5038 bool VymModel::reselect()
5040 return select (lastSelectString);
5043 void VymModel::emitShowSelection()
5045 if (!blockReposition)
5046 emit (showSelection() );
5049 void VymModel::emitNoteHasChanged (TreeItem *ti)
5051 QModelIndex ix=index(ti);
5052 emit (noteHasChanged (ix) );
5055 void VymModel::emitDataHasChanged (TreeItem *ti)
5057 QModelIndex ix=index(ti);
5058 emit (dataChanged (ix,ix) );
5062 bool VymModel::selectFirstBranch()
5064 TreeItem *ti=getSelectedBranch();
5067 TreeItem *par=ti->parent();
5070 TreeItem *ti2=par->getFirstBranch();
5071 if (ti2) return select(ti2);
5077 bool VymModel::selectLastBranch()
5079 TreeItem *ti=getSelectedBranch();
5082 TreeItem *par=ti->parent();
5085 TreeItem *ti2=par->getLastBranch();
5086 if (ti2) return select(ti2);
5092 bool VymModel::selectLastSelectedBranch()
5094 BranchItem *bi=getSelectedBranch();
5097 bi=bi->getLastSelectedBranch();
5098 if (bi) return select (bi);
5103 bool VymModel::selectParent()
5105 TreeItem *ti=getSelectedItem();
5116 TreeItem::Type VymModel::selectionType()
5118 QModelIndexList list=selModel->selectedIndexes();
5119 if (list.isEmpty()) return TreeItem::Undefined;
5120 TreeItem *ti = getItem (list.first() );
5121 return ti->getType();
5125 LinkableMapObj* VymModel::getSelectedLMO()
5127 QModelIndexList list=selModel->selectedIndexes();
5128 if (!list.isEmpty() )
5130 TreeItem *ti = getItem (list.first() );
5131 TreeItem::Type type=ti->getType();
5132 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5133 return ((MapItem*)ti)->getLMO();
5138 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5140 TreeItem *ti = getSelectedBranch();
5142 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5147 BranchItem* VymModel::getSelectedBranch()
5149 QModelIndexList list=selModel->selectedIndexes();
5150 if (!list.isEmpty() )
5152 TreeItem *ti = getItem (list.first() );
5153 TreeItem::Type type=ti->getType();
5154 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5155 return (BranchItem*)ti;
5160 ImageItem* VymModel::getSelectedImage()
5162 QModelIndexList list=selModel->selectedIndexes();
5163 if (!list.isEmpty())
5165 TreeItem *ti=getItem (list.first());
5166 if (ti && ti->getType()==TreeItem::Image)
5167 return (ImageItem*)ti;
5172 AttributeItem* VymModel::getSelectedAttribute()
5174 QModelIndexList list=selModel->selectedIndexes();
5175 if (!list.isEmpty() )
5177 TreeItem *ti = getItem (list.first() );
5178 TreeItem::Type type=ti->getType();
5179 if (type ==TreeItem::Attribute)
5180 return (AttributeItem*)ti;
5185 TreeItem* VymModel::getSelectedItem()
5187 QModelIndexList list=selModel->selectedIndexes();
5188 if (!list.isEmpty() )
5189 return getItem (list.first() );
5194 QModelIndex VymModel::getSelectedIndex()
5196 QModelIndexList list=selModel->selectedIndexes();
5197 if (list.isEmpty() )
5198 return QModelIndex();
5200 return list.first();
5203 QString VymModel::getSelectString ()
5205 return getSelectString (getSelectedItem());
5208 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5210 if (!lmo) return QString();
5211 return getSelectString (lmo->getTreeItem() );
5214 QString VymModel::getSelectString (TreeItem *ti)
5218 switch (ti->getType())
5220 case TreeItem::MapCenter: s="mc:"; break;
5221 case TreeItem::Branch: s="bo:";break;
5222 case TreeItem::Image: s="fi:";break;
5223 case TreeItem::Attribute: s="ai:";break;
5224 case TreeItem::XLink: s="xl:";break;
5226 s="unknown type in VymModel::getSelectString()";
5229 s= s + QString("%1").arg(ti->num());
5231 // call myself recursively
5232 s= getSelectString(ti->parent()) +","+s;